Skip to content

Commit

Permalink
fix: permission error on staging (#968)
Browse files Browse the repository at this point in the history
* added brackets

* added print to debug

* added print

* added print

* changed ajax

* printing userprofile

* changed print

* ajax fix

* removed print

* took preview user field out

* Added permission class

* ajax change

* tried to print the error, added data method

* unified delete permission class

* Merge branch 'master' into test_permissions_on_dev
  • Loading branch information
MMFernando authored Jun 20, 2019
1 parent 42f4701 commit 41949f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions portal/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@
},
"RAPID_ROUTER_EARLY_ACCESS_FUNCTION_NAME": "portal.beta.has_beta_access",
"PREVIEW_USER_AIMMO_DECORATOR": "portal.permissions.preview_user",
"IS_PREVIEW_USER_AIMMO_CLASS": "portal.permissions.IsPreviewUser",
"IS_TEACHER_CLASS": "portal.permissions.IsTeacher",
"CAN_DELETE_GAME_CLASS": "portal.permissions.CanDeleteGame",
"USERS_FOR_NEW_AIMMO_GAME": "portal.aimmo_game.get_users_for_new_game",
}

Expand Down
19 changes: 7 additions & 12 deletions portal/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


def has_completed_auth_setup(u):
return not using_two_factor(u) or (u.is_verified() and using_two_factor(u))
return (not using_two_factor(u)) or (u.is_verified() and using_two_factor(u))


def logged_in_as_teacher(u):
Expand Down Expand Up @@ -103,19 +103,14 @@ def wrapped(request, *args, **kwargs):
return wrapped


class IsPreviewUser(permissions.BasePermission):
class CanDeleteGame(permissions.BasePermission):
def has_permission(self, request, view):
u = request.user
try:
return u.userprofile.preview_user and has_completed_auth_setup(u)
except AttributeError:
return False


class IsTeacher(permissions.BasePermission):
def has_permission(self, request, view):
u = request.user
try:
return u.userprofile.teacher and has_completed_auth_setup(u)
return (
u.userprofile.teacher
and u.userprofile.preview_user
and has_completed_auth_setup(u)
)
except AttributeError:
return False
3 changes: 2 additions & 1 deletion portal/static/portal/js/delete_aimmo_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function deleteGame() {
var game_id = $("#popup").attr("data-game-id");
$.ajax({
url: '/aimmo/api/games/' + game_id + '/',
type: 'delete',
type: 'DELETE',
data: { _method: 'delete' },
headers: {
"X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val()
}
Expand Down

0 comments on commit 41949f3

Please sign in to comment.