Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move decorators and add validating form for starting reviews
[Finishes #131669611] Closes gh-392
- Loading branch information
Showing
10 changed files
with
174 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.contrib.auth import REDIRECT_FIELD_NAME | ||
from django.contrib.auth.decorators import user_passes_test | ||
from django.core.exceptions import PermissionDenied | ||
|
||
|
||
def content_reviewer(user, include_staff=True): | ||
""" | ||
Tests that user is content reviewer (or superuser) | ||
Args: | ||
user: the User object | ||
include_staff: boolean for whether to also allow non-reviewer staff | ||
Returns: | ||
Boolean | ||
Raises: | ||
PermissionDenied | ||
""" | ||
if not user.is_authenticated(): | ||
return False | ||
|
||
is_staff = user.is_staff if include_staff else False | ||
|
||
if user.is_active and (user.userprofile.is_reviewer or is_staff): | ||
return True | ||
|
||
raise PermissionDenied | ||
|
||
|
||
def reviewer_required(function=None, include_staff=True, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None): | ||
""" | ||
Decorator for views that checks that the user is logged in and either a | ||
staff member or a content reviewer. | ||
""" | ||
actual_decorator = user_passes_test( | ||
lambda u: content_reviewer(u, include_staff=include_staff), | ||
login_url=login_url, | ||
redirect_field_name=redirect_field_name | ||
) | ||
if function: | ||
return actual_decorator(function) | ||
return actual_decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('review', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name='contentreview', | ||
unique_together=set([('resource', 'role')]), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters