Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete participant and host feature #2781

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2575bb4
delete_member_and_host_feature_added
Kajol-Kumari Feb 7, 2020
a3d95c9
delete_host_participant_feature_added
Kajol-Kumari Feb 10, 2020
6f84e8d
delete_host_participant_feature_added
Kajol-Kumari Feb 10, 2020
319e844
delete_host_participant_feature_added
Kajol-Kumari Feb 10, 2020
1ce9d49
delete_host_participant_feature_added
Kajol-Kumari Feb 10, 2020
40a203e
delete_host_participant_feature_added
Kajol-Kumari Feb 10, 2020
b4792e5
delete_host_participant_feature_added
Kajol-Kumari Feb 10, 2020
58c3332
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
8bdeade
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
5e500b6
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
f34cc59
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
c5b4888
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
3c22c42
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
81895c2
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
d01cd3e
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
ce61e4c
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
1a74f46
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
6548f5f
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
32d6385
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
61b9405
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
1411ee3
fixed_bug_host_deletion
Kajol-Kumari Feb 12, 2020
01fc688
improved_code_organisation
Kajol-Kumari Feb 13, 2020
5220991
improved_code_organisation
Kajol-Kumari Feb 13, 2020
9e05ed5
improved_code_organisation
Kajol-Kumari Feb 13, 2020
4aa29f2
improved_code_organisation
Kajol-Kumari Feb 13, 2020
02bcad1
improved_code_organisation
Kajol-Kumari Feb 13, 2020
a73a7be
Improved_code_structure
Kajol-Kumari Feb 13, 2020
548e1d2
Merge branch 'master' of https://github.com/Cloud-CV/EvalAI into dele…
Kajol-Kumari May 6, 2020
5a9ae45
Made suggested changes
Kajol-Kumari Jul 15, 2020
9e26eff
Merge branch 'master' of https://github.com/Cloud-CV/EvalAI into dele…
Kajol-Kumari Jul 15, 2020
be6aac2
Modified Test Files
Kajol-Kumari Jul 16, 2020
4dedb00
Edited Test
Kajol-Kumari Jul 16, 2020
55f6901
Made suggested changes
Kajol-Kumari Jul 16, 2020
f878b9f
Modified test file
Kajol-Kumari Jul 16, 2020
9189b27
Modified test file
Kajol-Kumari Jul 16, 2020
ece8fd6
Modified view test file
Kajol-Kumari Jul 16, 2020
ccb1032
Modified test file
Kajol-Kumari Jul 16, 2020
bad2e11
Modified test file
Kajol-Kumari Jul 16, 2020
b00dd07
Modified test file
Kajol-Kumari Jul 16, 2020
6a65537
Fix Build
Kajol-Kumari Jul 17, 2020
3d20a1c
Fixed build
Kajol-Kumari Jul 17, 2020
f4df6a0
Fixed build
Kajol-Kumari Jul 17, 2020
9402a0b
Made suggested changes
Kajol-Kumari Jul 19, 2020
40ffb7e
Merge branch 'master' of https://github.com/Cloud-CV/EvalAI into dele…
Kajol-Kumari Jul 19, 2020
82e3d6f
Fix build
Kajol-Kumari Jul 19, 2020
b6265ec
Minor change
Kajol-Kumari Jul 19, 2020
da731fe
Fix tests
Kajol-Kumari Jul 20, 2020
bff8dc3
Merge branch 'master' of https://github.com/Cloud-CV/EvalAI into dele…
Kajol-Kumari Jul 20, 2020
ef81271
Merge branch 'master' of https://github.com/Cloud-CV/EvalAI into dele…
Kajol-Kumari Jul 30, 2020
8abdfad
Resolve conflict
Kajol-Kumari Jul 31, 2020
2911e24
Merge branch 'master' of https://github.com/Cloud-CV/EvalAI into dele…
Kajol-Kumari Aug 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions apps/hosts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from .models import ChallengeHost, ChallengeHostTeam

get_challenge_host_team_model = get_model_object(ChallengeHostTeam)


def get_challenge_host_teams_for_user(user):
"""Returns challenge host team ids for a particular user"""
Expand All @@ -26,6 +28,3 @@ def is_user_part_of_host_team(user, host_team):
return ChallengeHost.objects.filter(
user=user, team_name=host_team
).exists()


get_challenge_host_team_model = get_model_object(ChallengeHostTeam)
31 changes: 18 additions & 13 deletions apps/hosts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from accounts.permissions import HasVerifiedEmail
from base.utils import get_model_object, team_paginated_queryset
from hosts.utils import get_challenge_host_team_model
from .filters import HostTeamsFilter
from .models import ChallengeHost, ChallengeHostTeam
from .serializers import (
Expand Down Expand Up @@ -161,14 +162,7 @@ def challenge_host_list(request, challenge_host_team_pk):
@permission_classes((permissions.IsAuthenticated, HasVerifiedEmail))
@authentication_classes((ExpiringTokenAuthentication,))
def challenge_host_detail(request, challenge_host_team_pk, pk):
try:
challenge_host_team = ChallengeHostTeam.objects.get(
pk=challenge_host_team_pk
)
except ChallengeHostTeam.DoesNotExist:
response_data = {"error": "ChallengeHostTeam does not exist"}
return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)

challenge_host_team = get_challenge_host_team_model(challenge_host_team_pk)
challenge_host = get_challenge_host_model(pk)

if request.method == "GET":
Expand Down Expand Up @@ -201,13 +195,24 @@ def challenge_host_detail(request, challenge_host_team_pk, pk):
response_data = serializer.data
return Response(response_data, status=status.HTTP_200_OK)
else:
return Response(
serializer.errors, status=status.HTTP_400_BAD_REQUEST
)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

elif request.method == "DELETE":
challenge_host.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
if challenge_host_team.created_by == request.user:

if (challenge_host.user == request.user): # when the user tries to remove himself
response_data = {
"error": "You are not allowed to remove yourself since you are the team admin. Please delete the team if you want to do so!"
}
return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
else:
challenge_host.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
else:
response_data = {
"error": "Sorry, you do not have permissions to remove this challenge host"
}
return Response(response_data, status=status.HTTP_401_UNAUTHORIZED)


@api_view(["POST"])
Expand Down
2 changes: 1 addition & 1 deletion apps/participants/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ParticipantSerializer(serializers.ModelSerializer):

class Meta:
model = Participant
fields = ("member_name", "status", "member_id")
fields = ("member_name", "status", "member_id", "id")

def get_member_name(self, obj):
return obj.user.username
Expand Down
2 changes: 1 addition & 1 deletion apps/participants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def delete_participant_from_team(request, participant_team_pk, participant_pk):
): # when the user tries to remove himself
response_data = {
"error": "You are not allowed to remove yourself since you are admin. Please delete the team if you want to do so!"
} # noqa: ignore=E501
}
return Response(
response_data, status=status.HTTP_406_NOT_ACCEPTABLE
)
Expand Down
76 changes: 76 additions & 0 deletions frontend/src/js/controllers/challengeHostTeamsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,82 @@
}, function() {});
};

// Delete a particular host
vm.confirmMemberDelete = function (ev, hostTeamId, hostId) {
ev.stopPropagation();
// Appending dialog to document.body to cover sidenav in docs app
var confirm = $mdDialog.confirm()
.title('Would you like to remove this member?')
.textContent('Note: This action will remove the member from team.')
.ariaLabel('Lucky day')
.targetEvent(ev)
.ok('Yes')
.cancel("No");

$mdDialog.show(confirm).then(function () {
vm.startLoader();
var parameters = {};
parameters.url = 'hosts/challenge_host_team/' + hostTeamId + '/challenge_host/' + hostId;
parameters.method = 'DELETE';
parameters.data = {};
parameters.token = userKey;
parameters.callback = {
onSuccess: function () {
vm.team.error = false;
$rootScope.notify("info", "Member removed successfully");
var parameters = {};
parameters.url = 'hosts/challenge_host_team';
parameters.method = 'GET';
parameters.token = userKey;
parameters.callback = {
onSuccess: function (response) {
var status = response.status;
var details = response.data;
if (status == 200) {
vm.existTeam = details;

// condition for pagination
if (vm.existTeam.next === null) {
vm.isNext = 'disabled';
vm.currentPage = vm.existTeam.count / 10;
} else {
vm.isNext = '';
vm.currentPage = parseInt(vm.existTeam.next.split('page=')[1] - 1);
}

if (vm.existTeam.previous === null) {
vm.isPrev = 'disabled';
} else {
vm.isPrev = '';
}

Kajol-Kumari marked this conversation as resolved.
Show resolved Hide resolved
if (vm.existTeam.count === 0) {
vm.showPagination = false;
vm.paginationMsg = "No team exists for now. Start by creating a new team!";
} else {
vm.showPagination = true;
vm.paginationMsg = "";
}
}

Kajol-Kumari marked this conversation as resolved.
Show resolved Hide resolved
vm.stopLoader();
}
};
utilities.sendRequest(parameters);
},
onError: function (response) {
var error = response.data['error'];
vm.stopLoader();
$rootScope.notify("error", error);
}
};

utilities.sendRequest(parameters);

}, function () {
});
};

vm.inviteOthers = function(ev, hostTeamId) {
ev.stopPropagation();
// Appending dialog to document.body
Expand Down
79 changes: 79 additions & 0 deletions frontend/src/js/controllers/teamsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@

};

// Delete participant along with members
vm.confirmDelete = function(ev, participantTeamId) {
ev.stopPropagation();
// Appending dialog to document.body to cover sidenav in docs app
Expand Down Expand Up @@ -324,6 +325,84 @@
});
};

// Delete only a particular member
vm.confirmMemberDelete = function (ev, participantTeamId, participantId) {
ev.stopPropagation();
// Appending dialog to document.body to cover sidenav in docs app
var confirm = $mdDialog.confirm()
.title('Would you like to remove this member?')
.textContent('Note: This action will remove the member from team.')
.ariaLabel('Lucky day')
.targetEvent(ev)
.ok('Yes')
.cancel("No");

$mdDialog.show(confirm).then(function () {
vm.startLoader();
var parameters = {};
parameters.url = 'participants/participant_team/' + participantTeamId + '/participant/' + participantId;
parameters.method = 'DELETE';
parameters.data = {};
parameters.token = userKey;
parameters.callback = {
onSuccess: function () {

vm.team.error = false;
$rootScope.notify("info", "Member removed successfully");

var parameters = {};
parameters.url = 'participants/participant_team';
parameters.method = 'GET';
parameters.token = userKey;
parameters.callback = {
onSuccess: function (response) {
var status = response.status;
var details = response.data;
if (status == 200) {
vm.existTeam = details;

Kajol-Kumari marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra newlines

// condition for pagination
if (vm.existTeam.next === null) {
vm.isNext = 'disabled';
vm.currentPage = vm.existTeam.count / 10;
} else {
vm.isNext = '';
vm.currentPage = parseInt(vm.existTeam.next.split('page=')[1] - 1);
}

if (vm.existTeam.previous === null) {
vm.isPrev = 'disabled';
} else {
vm.isPrev = '';
}

if (vm.existTeam.count === 0) {
vm.showPagination = false;
vm.paginationMsg = "No team exists for now. Start by creating a new team!";
} else {
vm.showPagination = true;
vm.paginationMsg = "";
}
}

vm.stopLoader();
}
};
utilities.sendRequest(parameters);
},
onError: function (response) {
var error = response.data['error'];
vm.stopLoader();
$rootScope.notify("error", error);
}
};

utilities.sendRequest(parameters);

}, function () {
});
};
// End of delete member

vm.inviteOthers = function(ev, participantTeamId) {
ev.stopPropagation();
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/views/web/challenge-host-teams.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
</div>
<div class="collapsible-body">
<h6><b>Team Members:</b></h6>
<p ng-repeat="member in value.members">{{member.user}}</p>
<p ng-repeat="member in value.members">{{member.user}}
<a class="show-member-title pointer" ng-if="value.created_by == web.name" ng-click="challengeHostTeams.confirmMemberDelete($event, value.id, member.id)"><i class="fa fa-trash list-icon text-highlight w-300 right"></i></a>
</p>
</div>
</li>
</ul>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/views/web/teams.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
</div>
<div class="collapsible-body">
<h6><b>Team Members:</b></h6>
<p ng-repeat="member in value.members">{{member.member_name}}</p>
<p ng-repeat="member in value.members">{{member.member_name}}
<a class="show-member-title pointer" ng-if="value.created_by == web.name" ng-click="teams.confirmMemberDelete($event, value.id, member.id)"><i class="fa fa-trash list-icon text-highlight w-300 right"></i></a>
</p>
</div>
</li>
</ul>
Expand Down
25 changes: 25 additions & 0 deletions frontend/tests/controllers-test/challengeHostTeamsCtrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,31 @@ describe('Unit tests for challenge host team controller', function () {
});
});

describe('Unit tests for confirmMemberDelete function', function () {
beforeEach(function () {
spyOn($mdDialog, 'show').and.callFake(function () {
var deferred = $injector.get('$q').defer();
return deferred.promise;
});
});

it('open dialog to confirm delete', function () {
var hostTeamId = 1;
var hostId = 1;
var ev = new Event('$click');
var confirm = $mdDialog.confirm()
.title('Would you like to remove this member?')
.textContent('Note: This action will remove the member from team.')
.ariaLabel('Lucky day')
.targetEvent(ev)
.ok('Yes')
.cancel("No");
vm.confirmMemberDelete(ev, hostTeamId, hostId);
expect($mdDialog.show).toHaveBeenCalledWith(confirm);
});
});


describe('Unit tests for inviteOthers function', function () {
beforeEach(function () {
spyOn($mdDialog, 'show').and.callFake(function () {
Expand Down
25 changes: 25 additions & 0 deletions frontend/tests/controllers-test/teamsCtrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,31 @@ describe('Unit tests for teams controller', function () {
});
});

describe('Unit tests for confirmMemberDelete function', function () {
beforeEach(function () {
spyOn($mdDialog, 'show').and.callFake(function () {
var deferred = $injector.get('$q').defer();
return deferred.promise;
});
});

it('open dialog to confirm delete', function () {
var participantTeamId = 1;
var participantId = 1;
var ev = new Event('$click');
var confirm = $mdDialog.confirm()
.title('Would you like to remove this member?')
.textContent('Note: This action will remove the member from team.')
.ariaLabel('Lucky day')
.targetEvent(ev)
.ok('Yes')
.cancel("No");
vm.confirmMemberDelete(ev, participantTeamId, participantId);
expect($mdDialog.show).toHaveBeenCalledWith(confirm);
});
});


describe('Unit tests for inviteOthers function', function () {
beforeEach(function () {
spyOn($mdDialog, 'show').and.callFake(function () {
Expand Down
Loading