Beispiel #1
0
def remove_shed_admin(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        removeAdmin = profileUtil.getProfileFromUser(User.objects.get(username=username))
        if shedObj.owner == removeAdmin:
            return HttpResponseRedirect('/')
        else:
            if shedObj.owner == userProfile:
                shedUtil.removeAdminFromShed(shedObj, removeAdmin)
                notifUtil.createBadInfoNotif(shedObj, removeAdmin, "You have been removed as an admin from the shed " + shedObj.name + ". ")
                return HttpResponseRedirect('/sheds/' + str(shedObj.id) + '/remove_admin/removed/success')
            else:
                return HttpResponseRedirect('/')
Beispiel #2
0
def remove_shed_admin(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        removeAdmin = profileUtil.getProfileFromUser(
            User.objects.get(username=username))
        if shedObj.owner == removeAdmin:
            return HttpResponseRedirect('/')
        else:
            if shedObj.owner == userProfile:
                shedUtil.removeAdminFromShed(shedObj, removeAdmin)
                notifUtil.createBadInfoNotif(
                    shedObj, removeAdmin,
                    "You have been removed as an admin from the shed " +
                    shedObj.name + ". ")
                return HttpResponseRedirect('/sheds/' + str(shedObj.id) +
                                            '/remove_admin/removed/success')
            else:
                return HttpResponseRedirect('/')
Beispiel #3
0
def remove_shed_member(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        banUser = profileUtil.getProfileFromUser(
            User.objects.get(username=username))
        admins = shedUtil.getAllAdminsOfShed(shedObj)
        userIsAdmin = False
        banUserIsAdmin = False
        for admin in admins:
            if admin == userProfile:
                userIsAdmin = True
            elif admin == banUser:
                banUserIsAdmin = True
        if userIsAdmin:
            if banUserIsAdmin:
                if shedObj.owner == userProfile:
                    shedUtil.removeAdminFromShed(shedObj, banUser)
                    notifUtil.createBadInfoNotif(
                        shedObj, banUser,
                        "You have been removed as an admin from the shed " +
                        shedObj.name + ". ")
                    shedUtil.removeMemberFromShed(shedObj, banUser)
                    notifUtil.createBadInfoNotif(
                        shedObj, banUser,
                        "You have been kicked from the shed " + shedObj.name +
                        ". ")
                    shedTools = toolUtil.getAllToolsInShed(shedObj)
                    for tool in shedTools:
                        if tool.owner == banUser:
                            shedUtil.removeToolFromShed(shedObj, tool)
                            shedUtil.addToolToShed(banUser.personalShed, tool)
                    return HttpResponseRedirect(
                        "/sheds/" + str(shedObj.id) +
                        "/remove_member/kicked/success")
                else:
                    return HttpResponseRedirect('/')
            else:
                shedUtil.removeMemberFromShed(shedObj, banUser)
                shedObj.bannedUsers.add(banUser)
                notifUtil.createBadInfoNotif(
                    shedObj, banUser, "You have been kicked from the shed " +
                    shedObj.name + ". ")
                shedTools = toolUtil.getAllToolsInShed(shedObj)
                for tool in shedTools:
                    if tool.owner == banUser:
                        shedUtil.removeToolFromShed(shedObj, tool)
                        shedUtil.addToolToShed(banUser.personalShed, tool)
                return HttpResponseRedirect("/sheds/" + str(shedObj.id) +
                                            "/remove_member/kicked/success")
        else:
            return HttpResponseRedirect('/')
Beispiel #4
0
def remove_shed_member(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        banUser = profileUtil.getProfileFromUser(User.objects.get(username=username))
        admins = shedUtil.getAllAdminsOfShed(shedObj)
        userIsAdmin = False
        banUserIsAdmin = False
        for admin in admins:
            if admin == userProfile:
                userIsAdmin = True
            elif admin == banUser:
                banUserIsAdmin = True
        if userIsAdmin:
            if banUserIsAdmin:
                if shedObj.owner == userProfile:
                    shedUtil.removeAdminFromShed(shedObj, banUser)
                    notifUtil.createBadInfoNotif(shedObj, banUser, "You have been removed as an admin from the shed " + shedObj.name + ". ")
                    shedUtil.removeMemberFromShed(shedObj, banUser)
                    notifUtil.createBadInfoNotif(shedObj, banUser, "You have been kicked from the shed " + shedObj.name + ". ")
                    shedTools = toolUtil.getAllToolsInShed(shedObj)
                    for tool in shedTools:
                        if tool.owner == banUser:
                            shedUtil.removeToolFromShed(shedObj, tool)
                            shedUtil.addToolToShed(banUser.personalShed, tool)
                    return HttpResponseRedirect("/sheds/" + str(shedObj.id) + "/remove_member/kicked/success")
                else:
                    return HttpResponseRedirect('/')
            else:
                shedUtil.removeMemberFromShed(shedObj, banUser)
                shedObj.bannedUsers.add(banUser)
                notifUtil.createBadInfoNotif(shedObj, banUser, "You have been kicked from the shed " + shedObj.name + ". ")
                shedTools = toolUtil.getAllToolsInShed(shedObj)
                for tool in shedTools:
                    if tool.owner == banUser:
                        shedUtil.removeToolFromShed(shedObj, tool)
                        shedUtil.addToolToShed(banUser.personalShed, tool)
                return HttpResponseRedirect("/sheds/" + str(shedObj.id) + "/remove_member/kicked/success")
        else:
            return HttpResponseRedirect('/')