Use flags

This commit is contained in:
Erik Johnston 2019-03-20 17:39:29 +00:00
parent 7d47cc1305
commit aa959a6c07
5 changed files with 17 additions and 15 deletions

View File

@ -165,6 +165,7 @@ class BaseHandler(object):
member_event.room_id, member_event.room_id,
"leave", "leave",
ratelimit=False, ratelimit=False,
require_consent=False,
) )
except Exception as e: except Exception as e:
logger.exception("Error kicking guest user: %s" % (e,)) logger.exception("Error kicking guest user: %s" % (e,))

View File

@ -164,6 +164,7 @@ class DeactivateAccountHandler(BaseHandler):
room_id, room_id,
"leave", "leave",
ratelimit=False, ratelimit=False,
require_consent=False,
) )
except Exception: except Exception:
logger.exception( logger.exception(

View File

@ -255,7 +255,7 @@ class EventCreationHandler(object):
@defer.inlineCallbacks @defer.inlineCallbacks
def create_event(self, requester, event_dict, token_id=None, txn_id=None, def create_event(self, requester, event_dict, token_id=None, txn_id=None,
prev_events_and_hashes=None): prev_events_and_hashes=None, require_consent=True):
""" """
Given a dict from a client, create a new event. Given a dict from a client, create a new event.
@ -276,6 +276,9 @@ class EventCreationHandler(object):
where *hashes* is a map from algorithm to hash. where *hashes* is a map from algorithm to hash.
If None, they will be requested from the database. If None, they will be requested from the database.
require_consent (bool): Whether to check if the requester has
consented to privacy policy.
Raises: Raises:
ResourceLimitError if server is blocked to some resource being ResourceLimitError if server is blocked to some resource being
exceeded exceeded
@ -317,7 +320,7 @@ class EventCreationHandler(object):
) )
is_exempt = yield self._is_exempt_from_privacy_policy(builder, requester) is_exempt = yield self._is_exempt_from_privacy_policy(builder, requester)
if not is_exempt: if require_consent and not is_exempt:
yield self.assert_accepted_privacy_policy(requester) yield self.assert_accepted_privacy_policy(requester)
if token_id is not None: if token_id is not None:
@ -388,17 +391,6 @@ class EventCreationHandler(object):
if self._block_events_without_consent_error is None: if self._block_events_without_consent_error is None:
return return
# exempt AS users from needing consent
if requester.app_service is not None:
return
# Check if the user has accepted the privacy policy. We only do this if
# the requester has an associated access_token_id, which indicates that
# this action came from a user request rather than an automatice server
# or admin action.
if requester.access_token_id is None:
return
user_id = requester.user.to_string() user_id = requester.user.to_string()
# exempt the system notices user # exempt the system notices user

View File

@ -160,6 +160,7 @@ class RoomMemberHandler(object):
txn_id=None, txn_id=None,
ratelimit=True, ratelimit=True,
content=None, content=None,
require_consent=True,
): ):
user_id = target.to_string() user_id = target.to_string()
@ -185,6 +186,7 @@ class RoomMemberHandler(object):
token_id=requester.access_token_id, token_id=requester.access_token_id,
txn_id=txn_id, txn_id=txn_id,
prev_events_and_hashes=prev_events_and_hashes, prev_events_and_hashes=prev_events_and_hashes,
require_consent=require_consent,
) )
# Check if this event matches the previous membership event for the user. # Check if this event matches the previous membership event for the user.
@ -305,6 +307,7 @@ class RoomMemberHandler(object):
third_party_signed=None, third_party_signed=None,
ratelimit=True, ratelimit=True,
content=None, content=None,
require_consent=True,
): ):
key = (room_id,) key = (room_id,)
@ -319,6 +322,7 @@ class RoomMemberHandler(object):
third_party_signed=third_party_signed, third_party_signed=third_party_signed,
ratelimit=ratelimit, ratelimit=ratelimit,
content=content, content=content,
require_consent=require_consent,
) )
defer.returnValue(result) defer.returnValue(result)
@ -335,6 +339,7 @@ class RoomMemberHandler(object):
third_party_signed=None, third_party_signed=None,
ratelimit=True, ratelimit=True,
content=None, content=None,
require_consent=True,
): ):
content_specified = bool(content) content_specified = bool(content)
if content is None: if content is None:
@ -516,6 +521,7 @@ class RoomMemberHandler(object):
ratelimit=ratelimit, ratelimit=ratelimit,
prev_events_and_hashes=prev_events_and_hashes, prev_events_and_hashes=prev_events_and_hashes,
content=content, content=content,
require_consent=require_consent,
) )
defer.returnValue(res) defer.returnValue(res)

View File

@ -516,7 +516,8 @@ class ShutdownRoomRestServlet(ClientV1RestServlet):
room_id=room_id, room_id=room_id,
action=Membership.LEAVE, action=Membership.LEAVE,
content={}, content={},
ratelimit=False ratelimit=False,
require_consent=False,
) )
yield self.room_member_handler.forget(target_requester.user, room_id) yield self.room_member_handler.forget(target_requester.user, room_id)
@ -527,7 +528,8 @@ class ShutdownRoomRestServlet(ClientV1RestServlet):
room_id=new_room_id, room_id=new_room_id,
action=Membership.JOIN, action=Membership.JOIN,
content={}, content={},
ratelimit=False ratelimit=False,
require_consent=False,
) )
kicked_users.append(user_id) kicked_users.append(user_id)