def test_RemoveMemberFromShed(self):
     """
     """
     shedUtils.removeMemberFromShed(self.getShed,
                                    profUtils.getAllProfiles()[2])
     self.getShed = Shed.objects.get(name="Lightsaber Tools")
     self.assertNotIn(profUtils.getAllProfiles()[2],
                      shedUtils.getAllMembersOfShed(self.getShed)
                      )  #taking him out and then making sure he's not there
Exemple #2
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('/')
Exemple #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('/')
Exemple #4
0
def leave_shed(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        if shedObj.owner == userProfile:
            return HttpResponseRedirect('/')
        else:
            admins = shedUtil.getAllAdminsOfShed(shedObj)
            for admin in admins:
                if admin == userProfile:
                    shedUtil.removeAdminFromShed(shedObj, userProfile)
            shedUtil.removeMemberFromShed(shedObj, userProfile)
            shedTools = toolUtil.getAllToolsInShed(shedObj)
            for tool in shedTools:
                if tool.owner == userProfile:
                    shedUtil.removeToolFromShed(shedObj, tool)
                    shedUtil.addToolToShed(userProfile.personalShed, tool)
            return HttpResponseRedirect('/sheds/' + str(shedObj.id) + '/leave/success')
Exemple #5
0
def leave_shed(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        if shedObj.owner == userProfile:
            return HttpResponseRedirect('/')
        else:
            admins = shedUtil.getAllAdminsOfShed(shedObj)
            for admin in admins:
                if admin == userProfile:
                    shedUtil.removeAdminFromShed(shedObj, userProfile)
            shedUtil.removeMemberFromShed(shedObj, userProfile)
            shedTools = toolUtil.getAllToolsInShed(shedObj)
            for tool in shedTools:
                if tool.owner == userProfile:
                    shedUtil.removeToolFromShed(shedObj, tool)
                    shedUtil.addToolToShed(userProfile.personalShed, tool)
            return HttpResponseRedirect('/sheds/' + str(shedObj.id) +
                                        '/leave/success')
 def test_RemoveMemberFromShed(self):
     """
     """
     shedUtils.removeMemberFromShed (self.getShed, profUtils.getAllProfiles()[2])
     self.getShed = Shed.objects.get (name = "Lightsaber Tools")
     self.assertNotIn (profUtils.getAllProfiles()[2], shedUtils.getAllMembersOfShed(self.getShed)) #taking him out and then making sure he's not there