def _edit_contributors(userids, collection, add_user=True, level="contributor"): '''a general function to add a single (or list) of users to a collection, given that each user exists. Parameters ========== userids: a string list, or single string of a user id add_user: if True, perform add on the collection. If False, remove. level: one of contributor or owner. ''' from shub.apps.users.utils import get_user if not isinstance(userids, list): userids = [userids] for userid in userids: user = get_user(userid) if user is not None: # Are we adding an owner or a contributor? func = collection.owners if level == "contributor": func = collection.contributors # Are we adding or removing? if add_user is True: func.add(user) else: func.remove(user) collection.save() return collection
def remove_owner(request, tid, uid): '''remove a member from a team. Parameters ========== tid: the team id to remove the individual from uid: the user id to remove ''' team = get_team(tid) member = get_user(uid) if request.user in team.owners.all(): team = _remove_owner(team, user) else: message = "You are not allowed to perform this action." return JsonResponse({"message": message})
def remove_member(request, tid, uid): '''remove a member from a team. Parameters ========== team: the team to remove the individual from user: the user to remove ''' team = get_team(tid) member = get_user(uid) if request.user in team.owners.all(): team = _remove_member(team, member) message = "%s has been removed from %s" %(member, team) else: message = "You are not allowed to perform this action." return JsonResponse({"message":message})
def add_owner(request, tid, uid): '''promote a user to be owner of a team Parameters ========== tid: the team id to remove the individual from uid: the user id to remove ''' team = get_team(tid) member = get_user(uid) if request.user in team.owners.all(): team.owners.add(member) team.save() else: message = "You are not allowed to perform this action." return JsonResponse({"message": message})