本文整理汇总了Python中zerver.lib.actions.do_change_is_admin函数的典型用法代码示例。如果您正苦于以下问题:Python do_change_is_admin函数的具体用法?Python do_change_is_admin怎么用?Python do_change_is_admin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_change_is_admin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_create_realm_domain
def test_create_realm_domain(self):
# type: () -> None
self.login(self.example_email("iago"))
data = {'domain': ujson.dumps(''),
'allow_subdomains': ujson.dumps(True)}
result = self.client_post("/json/realm/domains", info=data)
self.assert_json_error(result, 'Invalid domain: Domain can\'t be empty.')
data['domain'] = ujson.dumps('acme.com')
result = self.client_post("/json/realm/domains", info=data)
self.assert_json_success(result)
realm = get_realm('zulip')
self.assertTrue(RealmDomain.objects.filter(realm=realm, domain='acme.com',
allow_subdomains=True).exists())
result = self.client_post("/json/realm/domains", info=data)
self.assert_json_error(result, 'The domain acme.com is already a part of your organization.')
mit_user_profile = self.mit_user("sipbtest")
self.login(mit_user_profile.email)
do_change_is_admin(mit_user_profile, True)
result = self.client_post("/json/realm/domains", info=data,
HTTP_HOST=mit_user_profile.realm.host)
self.assert_json_success(result)
开发者ID:brockwhittaker,项目名称:zulip,代码行数:26,代码来源:test_realm_domains.py
示例2: test_api_with_nonexistent_user
def test_api_with_nonexistent_user(self) -> None:
admin = self.example_user('othello')
do_change_is_admin(admin, True)
self.login(self.example_email("othello"))
# Cannot deactivate a user with the bot api
result = self.client_delete('/json/bots/{}'.format(self.example_user("hamlet").id))
self.assert_json_error(result, 'No such bot')
# Cannot deactivate a nonexistent user.
invalid_user_id = 1000
result = self.client_delete('/json/users/{}'.format(invalid_user_id))
self.assert_json_error(result, 'No such user')
result = self.client_delete('/json/users/{}'.format(self.example_user("webhook_bot").id))
self.assert_json_error(result, 'No such user')
result = self.client_delete('/json/users/{}'.format(self.example_user("iago").id))
self.assert_json_success(result)
result = self.client_delete('/json/users/{}'.format(admin.id))
self.assert_json_error(result, 'Cannot deactivate the only organization administrator')
# Cannot reactivate a nonexistent user.
invalid_user_id = 1000
result = self.client_post('/json/users/{}/reactivate'.format(invalid_user_id))
self.assert_json_error(result, 'No such user')
开发者ID:rishig,项目名称:zulip,代码行数:27,代码来源:test_users.py
示例3: handle
def handle(self, *args, **options):
email = options['email']
try:
profile = UserProfile.objects.get(email=email)
except ValidationError:
raise CommandError("No such user.")
if options['grant']:
if profile.has_perm(options['permission'], profile.realm):
raise CommandError("User already has permission for this realm.")
else:
if options['ack']:
do_change_is_admin(profile, True, permission=options['permission'])
print("Done!")
else:
print("Would have granted %s %s rights for %s" % (email, options['permission'], profile.realm.domain))
else:
if profile.has_perm(options['permission'], profile.realm):
if options['ack']:
do_change_is_admin(profile, False, permission=options['permission'])
print("Done!")
else:
print("Would have removed %s's %s rights on %s" % (email, options['permission'],
profile.realm.domain))
else:
raise CommandError("User did not have permission for this realm!")
开发者ID:8trust,项目名称:zulip,代码行数:26,代码来源:knight.py
示例4: test_updating_non_existent_user
def test_updating_non_existent_user(self) -> None:
self.login(self.example_email("hamlet"))
admin = self.example_user('hamlet')
do_change_is_admin(admin, True)
result = self.client_patch('/json/users/[email protected]', {})
self.assert_json_error(result, 'No such user')
开发者ID:joydeep1701,项目名称:zulip,代码行数:7,代码来源:test_users.py
示例5: test_change_admin_to_guest
def test_change_admin_to_guest(self) -> None:
iago = self.example_user("iago")
self.login(iago.email)
hamlet = self.example_user("hamlet")
do_change_is_admin(hamlet, True)
self.assertFalse(hamlet.is_guest)
self.assertTrue(hamlet.is_realm_admin)
# Test failure of making a admin to guest without revoking admin status
req = dict(is_guest=ujson.dumps(True))
result = self.client_patch('/json/users/{}'.format(hamlet.id), req)
self.assert_json_error(result, 'Guests cannot be organization administrators')
# Test changing a user from admin to guest and revoking admin status
hamlet = self.example_user("hamlet")
self.assertFalse(hamlet.is_guest)
req = dict(is_admin=ujson.dumps(False), is_guest=ujson.dumps(True))
events = [] # type: List[Mapping[str, Any]]
with tornado_redirected_to_list(events):
result = self.client_patch('/json/users/{}'.format(hamlet.id), req)
self.assert_json_success(result)
hamlet = self.example_user("hamlet")
self.assertTrue(hamlet.is_guest)
self.assertFalse(hamlet.is_realm_admin)
person = events[0]['event']['person']
self.assertEqual(person['email'], hamlet.email)
self.assertFalse(person['is_admin'])
person = events[1]['event']['person']
self.assertEqual(person['email'], hamlet.email)
self.assertTrue(person['is_guest'])
开发者ID:rishig,项目名称:zulip,代码行数:33,代码来源:test_users.py
示例6: handle
def handle(self, *args, **options):
# type: (*Any, **Any) -> None
email = options['email']
realm = self.get_realm(options)
profile = self.get_user(email, realm)
if options['grant']:
if profile.has_perm(options['permission'], profile.realm):
raise CommandError("User already has permission for this realm.")
else:
if options['ack']:
do_change_is_admin(profile, True, permission=options['permission'])
print("Done!")
else:
print("Would have granted %s %s rights for %s" % (
email, options['permission'], profile.realm.string_id))
else:
if profile.has_perm(options['permission'], profile.realm):
if options['ack']:
do_change_is_admin(profile, False, permission=options['permission'])
print("Done!")
else:
print("Would have removed %s's %s rights on %s" % (email, options['permission'],
profile.realm.string_id))
else:
raise CommandError("User did not have permission for this realm!")
开发者ID:yhl-python,项目名称:zulip,代码行数:27,代码来源:knight.py
示例7: update_user_backend
def update_user_backend(request, user_profile, email,
full_name=REQ(default="", validator=check_string),
is_admin=REQ(default=None, validator=check_bool)):
# type: (HttpRequest, UserProfile, text_type, Optional[text_type], Optional[bool]) -> HttpResponse
try:
target = get_user_profile_by_email(email)
except UserProfile.DoesNotExist:
return json_error(_('No such user'))
if not user_profile.can_admin_user(target):
return json_error(_('Insufficient permission'))
if is_admin is not None:
if not is_admin and check_last_admin(user_profile):
return json_error(_('Cannot remove the only organization administrator'))
do_change_is_admin(target, is_admin)
if (full_name is not None and target.full_name != full_name and
full_name.strip() != ""):
# We don't respect `name_changes_disabled` here because the request
# is on behalf of the administrator.
new_full_name = full_name.strip()
if len(new_full_name) > UserProfile.MAX_NAME_LENGTH:
return json_error(_("Name too long!"))
do_change_full_name(target, new_full_name)
return json_success()
开发者ID:zulip,项目名称:zulip,代码行数:27,代码来源:users.py
示例8: test_get_admin_users
def test_get_admin_users(self) -> None:
user_profile = self.example_user('hamlet')
do_change_is_admin(user_profile, False)
admin_users = user_profile.realm.get_admin_users()
self.assertFalse(user_profile in admin_users)
do_change_is_admin(user_profile, True)
admin_users = user_profile.realm.get_admin_users()
self.assertTrue(user_profile in admin_users)
开发者ID:rishig,项目名称:zulip,代码行数:8,代码来源:test_users.py
示例9: test_updating_non_existent_user
def test_updating_non_existent_user(self) -> None:
self.login(self.example_email("hamlet"))
admin = self.example_user('hamlet')
do_change_is_admin(admin, True)
invalid_user_id = 1000
result = self.client_patch('/json/users/{}'.format(invalid_user_id), {})
self.assert_json_error(result, 'No such user')
开发者ID:rishig,项目名称:zulip,代码行数:8,代码来源:test_users.py
示例10: test_admin_restrictions_for_changing_realm_name
def test_admin_restrictions_for_changing_realm_name(self) -> None:
new_name = 'Mice will play while the cat is away'
user_profile = self.example_user('othello')
email = user_profile.email
self.login(email)
do_change_is_admin(user_profile, False)
req = dict(name=ujson.dumps(new_name))
result = self.client_patch('/json/realm', req)
self.assert_json_error(result, 'Must be an organization administrator')
开发者ID:284928489,项目名称:zulip,代码行数:11,代码来源:test_realm.py
示例11: test_api_with_insufficient_permissions
def test_api_with_insufficient_permissions(self) -> None:
non_admin = self.example_user('othello')
do_change_is_admin(non_admin, False)
self.login(self.example_email("othello"))
# Cannot deactivate a user with the users api
result = self.client_delete('/json/users/{}'.format(self.example_user("hamlet").id))
self.assert_json_error(result, 'Insufficient permission')
# Cannot reactivate a user
result = self.client_post('/json/users/{}/reactivate'.format(self.example_user("hamlet").id))
self.assert_json_error(result, 'Insufficient permission')
开发者ID:rishig,项目名称:zulip,代码行数:12,代码来源:test_users.py
示例12: update_user_backend
def update_user_backend(request, user_profile, email,
is_admin=REQ(default=None, validator=check_bool)):
try:
target = get_user_profile_by_email(email)
except UserProfile.DoesNotExist:
return json_error('No such user')
if not user_profile.can_admin_user(target):
return json_error('Insufficient permission')
if is_admin is not None:
do_change_is_admin(target, is_admin)
return json_success({})
开发者ID:8trust,项目名称:zulip,代码行数:13,代码来源:users.py
示例13: update_user_backend
def update_user_backend(request, user_profile, email, is_admin=REQ(default=None, validator=check_bool)):
# type: (HttpRequest, UserProfile, text_type, Optional[bool]) -> HttpResponse
try:
target = get_user_profile_by_email(email)
except UserProfile.DoesNotExist:
return json_error(_("No such user"))
if not user_profile.can_admin_user(target):
return json_error(_("Insufficient permission"))
if is_admin is not None:
do_change_is_admin(target, is_admin)
return json_success({})
开发者ID:rlugojr,项目名称:zulip,代码行数:13,代码来源:users.py
示例14: update_user_backend
def update_user_backend(request: HttpRequest, user_profile: UserProfile, user_id: int,
full_name: Optional[str]=REQ(default="", validator=check_string),
is_admin: Optional[bool]=REQ(default=None, validator=check_bool)) -> HttpResponse:
target = access_user_by_id(user_profile, user_id, allow_deactivated=True, allow_bots=True)
if is_admin is not None:
if not is_admin and check_last_admin(user_profile):
return json_error(_('Cannot remove the only organization administrator'))
do_change_is_admin(target, is_admin)
if (full_name is not None and target.full_name != full_name and
full_name.strip() != ""):
# We don't respect `name_changes_disabled` here because the request
# is on behalf of the administrator.
check_change_full_name(target, full_name, user_profile)
return json_success()
开发者ID:284928489,项目名称:zulip,代码行数:17,代码来源:users.py
示例15: test_api
def test_api(self) -> None:
admin = self.example_user('othello')
do_change_is_admin(admin, True)
self.login(self.example_email("othello"))
user = self.example_user('hamlet')
self.assertTrue(user.is_active)
result = self.client_delete('/json/users/{}'.format(user.id))
self.assert_json_success(result)
user = self.example_user('hamlet')
self.assertFalse(user.is_active)
result = self.client_post('/json/users/{}/reactivate'.format(user.id))
self.assert_json_success(result)
user = self.example_user('hamlet')
self.assertTrue(user.is_active)
开发者ID:rishig,项目名称:zulip,代码行数:17,代码来源:test_users.py
示例16: update_user_backend
def update_user_backend(request: HttpRequest, user_profile: UserProfile, user_id: int,
full_name: Optional[str]=REQ(default="", validator=check_string),
is_admin: Optional[bool]=REQ(default=None, validator=check_bool),
is_guest: Optional[bool]=REQ(default=None, validator=check_bool),
profile_data: List[Dict[str, Union[int, str, List[int]]]]=
REQ(default=None,
validator=check_list(check_dict([('id', check_int)])))) -> HttpResponse:
target = access_user_by_id(user_profile, user_id, allow_deactivated=True, allow_bots=True)
# This condition is a bit complicated, because the user could
# already be a guest/admin, or the request could be to make the
# user a guest/admin. In any case, the point is that we outright
# reject requests that would result in a user who is both an admin
# and a guest.
if (((is_guest is None and target.is_guest) or is_guest) and
((is_admin is None and target.is_realm_admin) or is_admin)):
return json_error(_("Guests cannot be organization administrators"))
if is_admin is not None and target.is_realm_admin != is_admin:
if not is_admin and check_last_admin(user_profile):
return json_error(_('Cannot remove the only organization administrator'))
do_change_is_admin(target, is_admin)
if is_guest is not None and target.is_guest != is_guest:
do_change_is_guest(target, is_guest)
if (full_name is not None and target.full_name != full_name and
full_name.strip() != ""):
# We don't respect `name_changes_disabled` here because the request
# is on behalf of the administrator.
check_change_full_name(target, full_name, user_profile)
if profile_data is not None:
clean_profile_data = []
for entry in profile_data:
if not entry["value"]:
field_id = entry["id"]
check_remove_custom_profile_field_value(target, field_id)
else:
clean_profile_data.append(entry)
validate_user_custom_profile_data(target.realm.id, clean_profile_data)
do_update_user_custom_profile_data(target, clean_profile_data)
return json_success()
开发者ID:BakerWang,项目名称:zulip,代码行数:44,代码来源:users.py
示例17: test_api_with_nonexistent_user
def test_api_with_nonexistent_user(self) -> None:
admin = self.example_user('othello')
do_change_is_admin(admin, True)
self.login(self.example_email("othello"))
# Can not deactivate a user with the bot api
result = self.client_delete('/json/bots/[email protected]')
self.assert_json_error(result, 'No such bot')
# Can not deactivate a nonexistent user.
result = self.client_delete('/json/users/[email protected]')
self.assert_json_error(result, 'No such user')
result = self.client_delete('/json/users/[email protected]')
self.assert_json_success(result)
result = self.client_delete('/json/users/[email protected]')
self.assert_json_error(result, 'Cannot deactivate the only organization administrator')
# Can not reactivate a nonexistent user.
result = self.client_post('/json/users/[email protected]/reactivate')
self.assert_json_error(result, 'No such user')
开发者ID:joydeep1701,项目名称:zulip,代码行数:22,代码来源:test_users.py
示例18: test_change_is_admin
def test_change_is_admin(self):
schema_checker = check_dict([
('type', equals('realm_user')),
('op', equals('update')),
('person', check_dict([
('email', check_string),
('is_admin', check_bool),
])),
])
# The first False is probably a noop, then we get transitions in both directions.
for is_admin in [False, True, False]:
events = self.do_test(lambda: do_change_is_admin(self.user_profile, is_admin))
error = schema_checker('events[0]', events[0])
self.assert_on_error(error)
开发者ID:seanly,项目名称:zulip,代码行数:14,代码来源:test_events.py
示例19: update_user_backend
def update_user_backend(request: HttpRequest, user_profile: UserProfile, email: Text,
full_name: Optional[Text]=REQ(default="", validator=check_string),
is_admin: Optional[bool]=REQ(default=None, validator=check_bool)) -> HttpResponse:
try:
target = get_user(email, user_profile.realm)
except UserProfile.DoesNotExist:
return json_error(_('No such user'))
if not user_profile.can_admin_user(target):
return json_error(_('Insufficient permission'))
if is_admin is not None:
if not is_admin and check_last_admin(user_profile):
return json_error(_('Cannot remove the only organization administrator'))
do_change_is_admin(target, is_admin)
if (full_name is not None and target.full_name != full_name and
full_name.strip() != ""):
# We don't respect `name_changes_disabled` here because the request
# is on behalf of the administrator.
check_change_full_name(target, full_name, user_profile)
return json_success()
开发者ID:joydeep1701,项目名称:zulip,代码行数:23,代码来源:users.py
示例20: test_do_change_is_admin
def test_do_change_is_admin(self) -> None:
"""
Ensures change_is_admin raises an AssertionError when invalid permissions
are provided to it.
"""
# this should work fine
user_profile = self.example_user('hamlet')
do_change_is_admin(user_profile, True)
# this should work a-ok as well
do_change_is_admin(user_profile, True, permission='administer')
# this should "fail" with an AssertionError
with self.assertRaises(AssertionError):
do_change_is_admin(user_profile, True, permission='totally-not-valid-perm')
开发者ID:rishig,项目名称:zulip,代码行数:16,代码来源:test_users.py
注:本文中的zerver.lib.actions.do_change_is_admin函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论