def test_unit__get_all_manageable(self): admin = DBSession.query(User) \ .filter(User.email == '*****@*****.**').one() uapi = UserApi(admin) # Checks a case without workspaces. wapi = WorkspaceApi(current_user=admin) eq_([], wapi.get_all_manageable()) # Checks an admin gets all workspaces. w4 = wapi.create_workspace(label='w4') w3 = wapi.create_workspace(label='w3') w2 = wapi.create_workspace(label='w2') w1 = wapi.create_workspace(label='w1') eq_([w1, w2, w3, w4], wapi.get_all_manageable()) # Checks a regular user gets none workspace. gapi = GroupApi(None) u = uapi.create_user('[email protected]', [gapi.get_one(Group.TIM_USER)], True) wapi = WorkspaceApi(current_user=u) rapi = RoleApi(current_user=u) off = 'off' rapi.create_one(u, w4, UserRoleInWorkspace.READER, off) rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, off) rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, off) rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, off) eq_([], wapi.get_all_manageable()) # Checks a manager gets only its own workspaces. u.groups.append(gapi.get_one(Group.TIM_MANAGER)) rapi.delete_one(u.user_id, w2.workspace_id) rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, off) eq_([w1, w2], wapi.get_all_manageable())
def test_unit__get_all_manageable(self): admin = DBSession.query(User) \ .filter(User.email == '*****@*****.**').one() uapi = UserApi(admin) # Checks a case without workspaces. wapi = WorkspaceApi(current_user=admin) eq_([], wapi.get_all_manageable()) # Checks an admin gets all workspaces. w4 = wapi.create_workspace(label='w4') w3 = wapi.create_workspace(label='w3') w2 = wapi.create_workspace(label='w2') w1 = wapi.create_workspace(label='w1') eq_([w1, w2, w3, w4], wapi.get_all_manageable()) # Checks a regular user gets none workspace. gapi = GroupApi(None) u = uapi.create_user('[email protected]', [gapi.get_one(Group.TIM_USER)], True) wapi = WorkspaceApi(current_user=u) rapi = RoleApi(current_user=u) rapi.create_one(u, w4, UserRoleInWorkspace.READER, False) rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, False) rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, False) rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, False) eq_([], wapi.get_all_manageable()) # Checks a manager gets only its own workspaces. u.groups.append(gapi.get_one(Group.TIM_MANAGER)) rapi.delete_one(u.user_id, w2.workspace_id) rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, False) eq_([w1, w2], wapi.get_all_manageable())
def post_delete(self, user_id): user_id = int(user_id) role_api = RoleApi(tg.tmpl_context.current_user) role = role_api.get_one(user_id, tg.tmpl_context.workspace_id) username = role.user.get_display_name() undo_url = self.url(user_id, 'undelete', dict(old_role=role.role)) if tmpl_context.current_user.profile.id<Group.TIM_ADMIN and tmpl_context.current_user.user_id==user_id: tg.flash(_('You can\'t remove yourself from this workgroup'), CST.STATUS_ERROR) tg.redirect(self.parent_controller.url(tg.tmpl_context.workspace_id)) role_api.delete_one(user_id, tg.tmpl_context.workspace_id, True) tg.flash(_('User {} removed. You can <a class="alert-link" href="{}">restore it</a>').format(username, undo_url), CST.STATUS_OK, no_escape=True) tg.redirect(self.parent_controller.url(tg.tmpl_context.workspace_id))