def delete(self, user_group_id, user_id): """ Remove a user from a UserGroup """ user_group = user_group_api.get_user_group(user_group_id) user = user_api.get_user(user_id) user_group_api.remove_user_from_user_group(self.user, user, user_group) return '', HTTP_STATUS.DELETED
def get(self, user_group_id): no_access = request.args.get('not_in_group') user_group = user_group_api.get_user_group(user_group_id) if no_access: all_users = set(user_api.get_all_users()) access = set(user_group.get_users()) return list(all_users.difference(access)) return list(user_group.user_list)
def post(self, user_group_id): """ Add a user to a UserGroup """ args = user_group_user_parser.parse_args() user = user_api.get_user(args.get('user_id')) user_group = user_group_api.get_user_group(user_group_id) user_group_api.add_user_to_user_group(self.user, user, user_group) return marshal(user_group, user_group_fields), HTTP_STATUS.CREATED
def post(self, server_group_id): """ Add UserGroup access to a ServerGroup :param server_group_id: The ServerGroup id supplied in the URL """ server_group = server_group_api.get_server_group(server_group_id) args = server_group_user_group_parser.parse_args() user_group = user_group_api.get_user_group(args.get('user_group_id')) server_group_api.add_user_group_access_to_server_group(self.user, user_group, server_group) return marshal(server_group, server_group_fields), HTTP_STATUS.CREATED
def add_group_to_server(operator, server, group_id, save_server=True): """ Add a single user group to a server :param server: Server object to add group to :param group_id: Id of UserGroup to add to server :param save_server: Whether or not to call .save() on the server :return: True if group was added, otherwise False """ group = get_user_group(group_id) if group not in server.group_list: server.group_list.append(group) activity_log.log_user_group_added_to_server(group, server, operator) if save_server: server.save() return True return False
def remove_group_from_server(operator, server, group_id, save_server=True): """ Remove a single UserGroup's access from a single server :param operator: User performing this action :param server: Sever object to remove user from :param group_id: Id of UserGroup to remove :param save_server: Whether or not to call .save() on the server :return: True if user was removed, otherwise False """ group = get_user_group(group_id) if group in server.group_list: server.group_list.remove(group) activity_log.log_user_group_removed_from_server(group, server, operator) if save_server: server.save() return True return False
def delete(self, server_group_id, user_group_id): server_group = server_group_api.get_server_group(server_group_id) user_group = user_group_api.get_user_group(user_group_id) server_group_api.remove_user_group_access_from_server_group(self.user, user_group, server_group) return '', HTTP_STATUS.DELETED
def get(self, user_group_id): return user_group_api.get_user_group(user_group_id)
def get(self, user_group_id): user_group = user_group_api.get_user_group(user_group_id) return list(user_group.user_list)
def add_group_to_server(server, group_id, save_server=True): group = get_user_group(group_id) server.group_list.append(group) if save_server: server.save() return server