client.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from twisted.internet import defer
  16. from synapse.api.constants import Membership
  17. from synapse.api.urls import FEDERATION_PREFIX as PREFIX
  18. from synapse.util.logutils import log_function
  19. import logging
  20. logger = logging.getLogger(__name__)
  21. class TransportLayerClient(object):
  22. """Sends federation HTTP requests to other servers"""
  23. def __init__(self, hs):
  24. self.server_name = hs.hostname
  25. self.client = hs.get_http_client()
  26. @log_function
  27. def get_room_state(self, destination, room_id, event_id):
  28. """ Requests all state for a given room from the given server at the
  29. given event.
  30. Args:
  31. destination (str): The host name of the remote home server we want
  32. to get the state from.
  33. context (str): The name of the context we want the state of
  34. event_id (str): The event we want the context at.
  35. Returns:
  36. Deferred: Results in a dict received from the remote homeserver.
  37. """
  38. logger.debug("get_room_state dest=%s, room=%s",
  39. destination, room_id)
  40. path = PREFIX + "/state/%s/" % room_id
  41. return self.client.get_json(
  42. destination, path=path, args={"event_id": event_id},
  43. )
  44. @log_function
  45. def get_room_state_ids(self, destination, room_id, event_id):
  46. """ Requests all state for a given room from the given server at the
  47. given event. Returns the state's event_id's
  48. Args:
  49. destination (str): The host name of the remote home server we want
  50. to get the state from.
  51. context (str): The name of the context we want the state of
  52. event_id (str): The event we want the context at.
  53. Returns:
  54. Deferred: Results in a dict received from the remote homeserver.
  55. """
  56. logger.debug("get_room_state_ids dest=%s, room=%s",
  57. destination, room_id)
  58. path = PREFIX + "/state_ids/%s/" % room_id
  59. return self.client.get_json(
  60. destination, path=path, args={"event_id": event_id},
  61. )
  62. @log_function
  63. def get_event(self, destination, event_id, timeout=None):
  64. """ Requests the pdu with give id and origin from the given server.
  65. Args:
  66. destination (str): The host name of the remote home server we want
  67. to get the state from.
  68. event_id (str): The id of the event being requested.
  69. timeout (int): How long to try (in ms) the destination for before
  70. giving up. None indicates no timeout.
  71. Returns:
  72. Deferred: Results in a dict received from the remote homeserver.
  73. """
  74. logger.debug("get_pdu dest=%s, event_id=%s",
  75. destination, event_id)
  76. path = PREFIX + "/event/%s/" % (event_id, )
  77. return self.client.get_json(destination, path=path, timeout=timeout)
  78. @log_function
  79. def backfill(self, destination, room_id, event_tuples, limit):
  80. """ Requests `limit` previous PDUs in a given context before list of
  81. PDUs.
  82. Args:
  83. dest (str)
  84. room_id (str)
  85. event_tuples (list)
  86. limt (int)
  87. Returns:
  88. Deferred: Results in a dict received from the remote homeserver.
  89. """
  90. logger.debug(
  91. "backfill dest=%s, room_id=%s, event_tuples=%s, limit=%s",
  92. destination, room_id, repr(event_tuples), str(limit)
  93. )
  94. if not event_tuples:
  95. # TODO: raise?
  96. return
  97. path = PREFIX + "/backfill/%s/" % (room_id,)
  98. args = {
  99. "v": event_tuples,
  100. "limit": [str(limit)],
  101. }
  102. return self.client.get_json(
  103. destination,
  104. path=path,
  105. args=args,
  106. )
  107. @defer.inlineCallbacks
  108. @log_function
  109. def send_transaction(self, transaction, json_data_callback=None):
  110. """ Sends the given Transaction to its destination
  111. Args:
  112. transaction (Transaction)
  113. Returns:
  114. Deferred: Results of the deferred is a tuple in the form of
  115. (response_code, response_body) where the response_body is a
  116. python dict decoded from json
  117. """
  118. logger.debug(
  119. "send_data dest=%s, txid=%s",
  120. transaction.destination, transaction.transaction_id
  121. )
  122. if transaction.destination == self.server_name:
  123. raise RuntimeError("Transport layer cannot send to itself!")
  124. # FIXME: This is only used by the tests. The actual json sent is
  125. # generated by the json_data_callback.
  126. json_data = transaction.get_dict()
  127. response = yield self.client.put_json(
  128. transaction.destination,
  129. path=PREFIX + "/send/%s/" % transaction.transaction_id,
  130. data=json_data,
  131. json_data_callback=json_data_callback,
  132. long_retries=True,
  133. backoff_on_404=True, # If we get a 404 the other side has gone
  134. )
  135. logger.debug(
  136. "send_data dest=%s, txid=%s, got response: 200",
  137. transaction.destination, transaction.transaction_id,
  138. )
  139. defer.returnValue(response)
  140. @defer.inlineCallbacks
  141. @log_function
  142. def make_query(self, destination, query_type, args, retry_on_dns_fail,
  143. ignore_backoff=False):
  144. path = PREFIX + "/query/%s" % query_type
  145. content = yield self.client.get_json(
  146. destination=destination,
  147. path=path,
  148. args=args,
  149. retry_on_dns_fail=retry_on_dns_fail,
  150. timeout=10000,
  151. ignore_backoff=ignore_backoff,
  152. )
  153. defer.returnValue(content)
  154. @defer.inlineCallbacks
  155. @log_function
  156. def make_membership_event(self, destination, room_id, user_id, membership):
  157. """Asks a remote server to build and sign us a membership event
  158. Note that this does not append any events to any graphs.
  159. Args:
  160. destination (str): address of remote homeserver
  161. room_id (str): room to join/leave
  162. user_id (str): user to be joined/left
  163. membership (str): one of join/leave
  164. Returns:
  165. Deferred: Succeeds when we get a 2xx HTTP response. The result
  166. will be the decoded JSON body (ie, the new event).
  167. Fails with ``HTTPRequestException`` if we get an HTTP response
  168. code >= 300.
  169. Fails with ``NotRetryingDestination`` if we are not yet ready
  170. to retry this server.
  171. """
  172. valid_memberships = {Membership.JOIN, Membership.LEAVE}
  173. if membership not in valid_memberships:
  174. raise RuntimeError(
  175. "make_membership_event called with membership='%s', must be one of %s" %
  176. (membership, ",".join(valid_memberships))
  177. )
  178. path = PREFIX + "/make_%s/%s/%s" % (membership, room_id, user_id)
  179. ignore_backoff = False
  180. retry_on_dns_fail = False
  181. if membership == Membership.LEAVE:
  182. # we particularly want to do our best to send leave events. The
  183. # problem is that if it fails, we won't retry it later, so if the
  184. # remote server was just having a momentary blip, the room will be
  185. # out of sync.
  186. ignore_backoff = True
  187. retry_on_dns_fail = True
  188. content = yield self.client.get_json(
  189. destination=destination,
  190. path=path,
  191. retry_on_dns_fail=retry_on_dns_fail,
  192. timeout=20000,
  193. ignore_backoff=ignore_backoff,
  194. )
  195. defer.returnValue(content)
  196. @defer.inlineCallbacks
  197. @log_function
  198. def send_join(self, destination, room_id, event_id, content):
  199. path = PREFIX + "/send_join/%s/%s" % (room_id, event_id)
  200. response = yield self.client.put_json(
  201. destination=destination,
  202. path=path,
  203. data=content,
  204. )
  205. defer.returnValue(response)
  206. @defer.inlineCallbacks
  207. @log_function
  208. def send_leave(self, destination, room_id, event_id, content):
  209. path = PREFIX + "/send_leave/%s/%s" % (room_id, event_id)
  210. response = yield self.client.put_json(
  211. destination=destination,
  212. path=path,
  213. data=content,
  214. # we want to do our best to send this through. The problem is
  215. # that if it fails, we won't retry it later, so if the remote
  216. # server was just having a momentary blip, the room will be out of
  217. # sync.
  218. ignore_backoff=True,
  219. )
  220. defer.returnValue(response)
  221. @defer.inlineCallbacks
  222. @log_function
  223. def send_invite(self, destination, room_id, event_id, content):
  224. path = PREFIX + "/invite/%s/%s" % (room_id, event_id)
  225. response = yield self.client.put_json(
  226. destination=destination,
  227. path=path,
  228. data=content,
  229. ignore_backoff=True,
  230. )
  231. defer.returnValue(response)
  232. @defer.inlineCallbacks
  233. @log_function
  234. def get_public_rooms(self, remote_server, limit, since_token,
  235. search_filter=None, include_all_networks=False,
  236. third_party_instance_id=None):
  237. path = PREFIX + "/publicRooms"
  238. args = {
  239. "include_all_networks": "true" if include_all_networks else "false",
  240. }
  241. if third_party_instance_id:
  242. args["third_party_instance_id"] = third_party_instance_id,
  243. if limit:
  244. args["limit"] = [str(limit)]
  245. if since_token:
  246. args["since"] = [since_token]
  247. # TODO(erikj): Actually send the search_filter across federation.
  248. response = yield self.client.get_json(
  249. destination=remote_server,
  250. path=path,
  251. args=args,
  252. ignore_backoff=True,
  253. )
  254. defer.returnValue(response)
  255. @defer.inlineCallbacks
  256. @log_function
  257. def exchange_third_party_invite(self, destination, room_id, event_dict):
  258. path = PREFIX + "/exchange_third_party_invite/%s" % (room_id,)
  259. response = yield self.client.put_json(
  260. destination=destination,
  261. path=path,
  262. data=event_dict,
  263. )
  264. defer.returnValue(response)
  265. @defer.inlineCallbacks
  266. @log_function
  267. def get_event_auth(self, destination, room_id, event_id):
  268. path = PREFIX + "/event_auth/%s/%s" % (room_id, event_id)
  269. content = yield self.client.get_json(
  270. destination=destination,
  271. path=path,
  272. )
  273. defer.returnValue(content)
  274. @defer.inlineCallbacks
  275. @log_function
  276. def send_query_auth(self, destination, room_id, event_id, content):
  277. path = PREFIX + "/query_auth/%s/%s" % (room_id, event_id)
  278. content = yield self.client.post_json(
  279. destination=destination,
  280. path=path,
  281. data=content,
  282. )
  283. defer.returnValue(content)
  284. @defer.inlineCallbacks
  285. @log_function
  286. def query_client_keys(self, destination, query_content, timeout):
  287. """Query the device keys for a list of user ids hosted on a remote
  288. server.
  289. Request:
  290. {
  291. "device_keys": {
  292. "<user_id>": ["<device_id>"]
  293. } }
  294. Response:
  295. {
  296. "device_keys": {
  297. "<user_id>": {
  298. "<device_id>": {...}
  299. } } }
  300. Args:
  301. destination(str): The server to query.
  302. query_content(dict): The user ids to query.
  303. Returns:
  304. A dict containg the device keys.
  305. """
  306. path = PREFIX + "/user/keys/query"
  307. content = yield self.client.post_json(
  308. destination=destination,
  309. path=path,
  310. data=query_content,
  311. timeout=timeout,
  312. )
  313. defer.returnValue(content)
  314. @defer.inlineCallbacks
  315. @log_function
  316. def query_user_devices(self, destination, user_id, timeout):
  317. """Query the devices for a user id hosted on a remote server.
  318. Response:
  319. {
  320. "stream_id": "...",
  321. "devices": [ { ... } ]
  322. }
  323. Args:
  324. destination(str): The server to query.
  325. query_content(dict): The user ids to query.
  326. Returns:
  327. A dict containg the device keys.
  328. """
  329. path = PREFIX + "/user/devices/" + user_id
  330. content = yield self.client.get_json(
  331. destination=destination,
  332. path=path,
  333. timeout=timeout,
  334. )
  335. defer.returnValue(content)
  336. @defer.inlineCallbacks
  337. @log_function
  338. def claim_client_keys(self, destination, query_content, timeout):
  339. """Claim one-time keys for a list of devices hosted on a remote server.
  340. Request:
  341. {
  342. "one_time_keys": {
  343. "<user_id>": {
  344. "<device_id>": "<algorithm>"
  345. } } }
  346. Response:
  347. {
  348. "device_keys": {
  349. "<user_id>": {
  350. "<device_id>": {
  351. "<algorithm>:<key_id>": "<key_base64>"
  352. } } } }
  353. Args:
  354. destination(str): The server to query.
  355. query_content(dict): The user ids to query.
  356. Returns:
  357. A dict containg the one-time keys.
  358. """
  359. path = PREFIX + "/user/keys/claim"
  360. content = yield self.client.post_json(
  361. destination=destination,
  362. path=path,
  363. data=query_content,
  364. timeout=timeout,
  365. )
  366. defer.returnValue(content)
  367. @defer.inlineCallbacks
  368. @log_function
  369. def get_missing_events(self, destination, room_id, earliest_events,
  370. latest_events, limit, min_depth, timeout):
  371. path = PREFIX + "/get_missing_events/%s" % (room_id,)
  372. content = yield self.client.post_json(
  373. destination=destination,
  374. path=path,
  375. data={
  376. "limit": int(limit),
  377. "min_depth": int(min_depth),
  378. "earliest_events": earliest_events,
  379. "latest_events": latest_events,
  380. },
  381. timeout=timeout,
  382. )
  383. defer.returnValue(content)
  384. @log_function
  385. def get_group_profile(self, destination, group_id, requester_user_id):
  386. """Get a group profile
  387. """
  388. path = PREFIX + "/groups/%s/profile" % (group_id,)
  389. return self.client.get_json(
  390. destination=destination,
  391. path=path,
  392. args={"requester_user_id": requester_user_id},
  393. ignore_backoff=True,
  394. )
  395. @log_function
  396. def get_group_summary(self, destination, group_id, requester_user_id):
  397. """Get a group summary
  398. """
  399. path = PREFIX + "/groups/%s/summary" % (group_id,)
  400. return self.client.get_json(
  401. destination=destination,
  402. path=path,
  403. args={"requester_user_id": requester_user_id},
  404. ignore_backoff=True,
  405. )
  406. @log_function
  407. def get_rooms_in_group(self, destination, group_id, requester_user_id):
  408. """Get all rooms in a group
  409. """
  410. path = PREFIX + "/groups/%s/rooms" % (group_id,)
  411. return self.client.get_json(
  412. destination=destination,
  413. path=path,
  414. args={"requester_user_id": requester_user_id},
  415. ignore_backoff=True,
  416. )
  417. def add_room_to_group(self, destination, group_id, requester_user_id, room_id,
  418. content):
  419. """Add a room to a group
  420. """
  421. path = PREFIX + "/groups/%s/room/%s" % (group_id, room_id,)
  422. return self.client.post_json(
  423. destination=destination,
  424. path=path,
  425. args={"requester_user_id": requester_user_id},
  426. data=content,
  427. ignore_backoff=True,
  428. )
  429. def remove_room_from_group(self, destination, group_id, requester_user_id, room_id):
  430. """Remove a room from a group
  431. """
  432. path = PREFIX + "/groups/%s/room/%s" % (group_id, room_id,)
  433. return self.client.delete_json(
  434. destination=destination,
  435. path=path,
  436. args={"requester_user_id": requester_user_id},
  437. ignore_backoff=True,
  438. )
  439. @log_function
  440. def get_users_in_group(self, destination, group_id, requester_user_id):
  441. """Get users in a group
  442. """
  443. path = PREFIX + "/groups/%s/users" % (group_id,)
  444. return self.client.get_json(
  445. destination=destination,
  446. path=path,
  447. args={"requester_user_id": requester_user_id},
  448. ignore_backoff=True,
  449. )
  450. @log_function
  451. def get_invited_users_in_group(self, destination, group_id, requester_user_id):
  452. """Get users that have been invited to a group
  453. """
  454. path = PREFIX + "/groups/%s/invited_users" % (group_id,)
  455. return self.client.get_json(
  456. destination=destination,
  457. path=path,
  458. args={"requester_user_id": requester_user_id},
  459. ignore_backoff=True,
  460. )
  461. @log_function
  462. def accept_group_invite(self, destination, group_id, user_id, content):
  463. """Accept a group invite
  464. """
  465. path = PREFIX + "/groups/%s/users/%s/accept_invite" % (group_id, user_id)
  466. return self.client.post_json(
  467. destination=destination,
  468. path=path,
  469. data=content,
  470. ignore_backoff=True,
  471. )
  472. @log_function
  473. def invite_to_group(self, destination, group_id, user_id, requester_user_id, content):
  474. """Invite a user to a group
  475. """
  476. path = PREFIX + "/groups/%s/users/%s/invite" % (group_id, user_id)
  477. return self.client.post_json(
  478. destination=destination,
  479. path=path,
  480. args={"requester_user_id": requester_user_id},
  481. data=content,
  482. ignore_backoff=True,
  483. )
  484. @log_function
  485. def invite_to_group_notification(self, destination, group_id, user_id, content):
  486. """Sent by group server to inform a user's server that they have been
  487. invited.
  488. """
  489. path = PREFIX + "/groups/local/%s/users/%s/invite" % (group_id, user_id)
  490. return self.client.post_json(
  491. destination=destination,
  492. path=path,
  493. data=content,
  494. ignore_backoff=True,
  495. )
  496. @log_function
  497. def remove_user_from_group(self, destination, group_id, requester_user_id,
  498. user_id, content):
  499. """Remove a user fron a group
  500. """
  501. path = PREFIX + "/groups/%s/users/%s/remove" % (group_id, user_id)
  502. return self.client.post_json(
  503. destination=destination,
  504. path=path,
  505. args={"requester_user_id": requester_user_id},
  506. data=content,
  507. ignore_backoff=True,
  508. )
  509. @log_function
  510. def remove_user_from_group_notification(self, destination, group_id, user_id,
  511. content):
  512. """Sent by group server to inform a user's server that they have been
  513. kicked from the group.
  514. """
  515. path = PREFIX + "/groups/local/%s/users/%s/remove" % (group_id, user_id)
  516. return self.client.post_json(
  517. destination=destination,
  518. path=path,
  519. data=content,
  520. ignore_backoff=True,
  521. )
  522. @log_function
  523. def renew_group_attestation(self, destination, group_id, user_id, content):
  524. """Sent by either a group server or a user's server to periodically update
  525. the attestations
  526. """
  527. path = PREFIX + "/groups/%s/renew_attestation/%s" % (group_id, user_id)
  528. return self.client.post_json(
  529. destination=destination,
  530. path=path,
  531. data=content,
  532. ignore_backoff=True,
  533. )
  534. @log_function
  535. def update_group_summary_room(self, destination, group_id, user_id, room_id,
  536. category_id, content):
  537. """Update a room entry in a group summary
  538. """
  539. if category_id:
  540. path = PREFIX + "/groups/%s/summary/categories/%s/rooms/%s" % (
  541. group_id, category_id, room_id,
  542. )
  543. else:
  544. path = PREFIX + "/groups/%s/summary/rooms/%s" % (group_id, room_id,)
  545. return self.client.post_json(
  546. destination=destination,
  547. path=path,
  548. args={"requester_user_id": user_id},
  549. data=content,
  550. ignore_backoff=True,
  551. )
  552. @log_function
  553. def delete_group_summary_room(self, destination, group_id, user_id, room_id,
  554. category_id):
  555. """Delete a room entry in a group summary
  556. """
  557. if category_id:
  558. path = PREFIX + "/groups/%s/summary/categories/%s/rooms/%s" % (
  559. group_id, category_id, room_id,
  560. )
  561. else:
  562. path = PREFIX + "/groups/%s/summary/rooms/%s" % (group_id, room_id,)
  563. return self.client.delete_json(
  564. destination=destination,
  565. path=path,
  566. args={"requester_user_id": user_id},
  567. ignore_backoff=True,
  568. )
  569. @log_function
  570. def get_group_categories(self, destination, group_id, requester_user_id):
  571. """Get all categories in a group
  572. """
  573. path = PREFIX + "/groups/%s/categories" % (group_id,)
  574. return self.client.get_json(
  575. destination=destination,
  576. path=path,
  577. args={"requester_user_id": requester_user_id},
  578. ignore_backoff=True,
  579. )
  580. @log_function
  581. def get_group_category(self, destination, group_id, requester_user_id, category_id):
  582. """Get category info in a group
  583. """
  584. path = PREFIX + "/groups/%s/categories/%s" % (group_id, category_id,)
  585. return self.client.get_json(
  586. destination=destination,
  587. path=path,
  588. args={"requester_user_id": requester_user_id},
  589. ignore_backoff=True,
  590. )
  591. @log_function
  592. def update_group_category(self, destination, group_id, requester_user_id, category_id,
  593. content):
  594. """Update a category in a group
  595. """
  596. path = PREFIX + "/groups/%s/categories/%s" % (group_id, category_id,)
  597. return self.client.post_json(
  598. destination=destination,
  599. path=path,
  600. args={"requester_user_id": requester_user_id},
  601. data=content,
  602. ignore_backoff=True,
  603. )
  604. @log_function
  605. def delete_group_category(self, destination, group_id, requester_user_id,
  606. category_id):
  607. """Delete a category in a group
  608. """
  609. path = PREFIX + "/groups/%s/categories/%s" % (group_id, category_id,)
  610. return self.client.delete_json(
  611. destination=destination,
  612. path=path,
  613. args={"requester_user_id": requester_user_id},
  614. ignore_backoff=True,
  615. )
  616. @log_function
  617. def get_group_roles(self, destination, group_id, requester_user_id):
  618. """Get all roles in a group
  619. """
  620. path = PREFIX + "/groups/%s/roles" % (group_id,)
  621. return self.client.get_json(
  622. destination=destination,
  623. path=path,
  624. args={"requester_user_id": requester_user_id},
  625. ignore_backoff=True,
  626. )
  627. @log_function
  628. def get_group_role(self, destination, group_id, requester_user_id, role_id):
  629. """Get a roles info
  630. """
  631. path = PREFIX + "/groups/%s/roles/%s" % (group_id, role_id,)
  632. return self.client.get_json(
  633. destination=destination,
  634. path=path,
  635. args={"requester_user_id": requester_user_id},
  636. ignore_backoff=True,
  637. )
  638. @log_function
  639. def update_group_role(self, destination, group_id, requester_user_id, role_id,
  640. content):
  641. """Update a role in a group
  642. """
  643. path = PREFIX + "/groups/%s/roles/%s" % (group_id, role_id,)
  644. return self.client.post_json(
  645. destination=destination,
  646. path=path,
  647. args={"requester_user_id": requester_user_id},
  648. data=content,
  649. ignore_backoff=True,
  650. )
  651. @log_function
  652. def delete_group_role(self, destination, group_id, requester_user_id, role_id):
  653. """Delete a role in a group
  654. """
  655. path = PREFIX + "/groups/%s/roles/%s" % (group_id, role_id,)
  656. return self.client.delete_json(
  657. destination=destination,
  658. path=path,
  659. args={"requester_user_id": requester_user_id},
  660. ignore_backoff=True,
  661. )
  662. @log_function
  663. def update_group_summary_user(self, destination, group_id, requester_user_id,
  664. user_id, role_id, content):
  665. """Update a users entry in a group
  666. """
  667. if role_id:
  668. path = PREFIX + "/groups/%s/summary/roles/%s/users/%s" % (
  669. group_id, role_id, user_id,
  670. )
  671. else:
  672. path = PREFIX + "/groups/%s/summary/users/%s" % (group_id, user_id,)
  673. return self.client.post_json(
  674. destination=destination,
  675. path=path,
  676. args={"requester_user_id": requester_user_id},
  677. data=content,
  678. ignore_backoff=True,
  679. )
  680. @log_function
  681. def delete_group_summary_user(self, destination, group_id, requester_user_id,
  682. user_id, role_id):
  683. """Delete a users entry in a group
  684. """
  685. if role_id:
  686. path = PREFIX + "/groups/%s/summary/roles/%s/users/%s" % (
  687. group_id, role_id, user_id,
  688. )
  689. else:
  690. path = PREFIX + "/groups/%s/summary/users/%s" % (group_id, user_id,)
  691. return self.client.delete_json(
  692. destination=destination,
  693. path=path,
  694. args={"requester_user_id": requester_user_id},
  695. ignore_backoff=True,
  696. )
  697. def bulk_get_publicised_groups(self, destination, user_ids):
  698. """Get the groups a list of users are publicising
  699. """
  700. path = PREFIX + "/get_groups_publicised"
  701. content = {"user_ids": user_ids}
  702. return self.client.post_json(
  703. destination=destination,
  704. path=path,
  705. data=content,
  706. ignore_backoff=True,
  707. )