-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added chained auth functions for `group_create`, `organization_create` and `user_create` - Moved `disallow_non_image_uploads` into `logic/auth/helpers.py`
- Loading branch information
1 parent
a7a73a8
commit d841c54
Showing
4 changed files
with
60 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import ckan.plugins.toolkit as toolkit | ||
|
||
from ckanext.fortify.logic.auth import helpers | ||
|
||
|
||
@toolkit.chained_auth_function | ||
def fortify_group_create(next_auth, context, data_dict): | ||
return helpers.disallow_non_image_uploads(next_auth, context, data_dict) | ||
|
||
|
||
@toolkit.chained_auth_function | ||
def fortify_organization_create(next_auth, context, data_dict): | ||
return helpers.disallow_non_image_uploads(next_auth, context, data_dict) | ||
|
||
|
||
@toolkit.chained_auth_function | ||
def fortify_user_create(next_auth, context, data_dict): | ||
return helpers.disallow_non_image_uploads(next_auth, context, data_dict) |
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,23 @@ | ||
import logging | ||
|
||
from ckan.common import _, request | ||
|
||
log = logging.getLogger(__name__) | ||
invalid_filetype_response = {'success': False, 'msg': _('Invalid filetype')} | ||
|
||
|
||
def disallow_non_image_uploads(next_auth, context, data_dict): | ||
try: | ||
if request.files: | ||
files_dict = dict(request.files) | ||
image_upload = files_dict.get('image_upload') | ||
if image_upload and image_upload.mimetype and 'image' not in image_upload.mimetype: | ||
log.error('User {0} upload attempt blocked - file: {1}'.format( | ||
context['user'], | ||
image_upload | ||
)) | ||
return invalid_filetype_response | ||
except Exception as e: | ||
log.error(str(e)) | ||
|
||
return next_auth(context, data_dict) |
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 |
---|---|---|
@@ -1,38 +1,18 @@ | ||
import ckan.plugins.toolkit as toolkit | ||
import logging | ||
|
||
from ckan.common import _, request | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def disallow_non_image_uploads(next_auth, context, data_dict): | ||
try: | ||
if request.files: | ||
files_dict = dict(request.files) | ||
image_upload = files_dict.get('image_upload') | ||
if image_upload and image_upload.mimetype and 'image' not in image_upload.mimetype: | ||
log.error('User {0} upload attempt blocked - file: {1}'.format( | ||
context['user'], | ||
image_upload | ||
)) | ||
return {'success': False, 'msg': _('Invalid filetype')} | ||
except Exception as e: | ||
log.error(str(e)) | ||
|
||
return next_auth(context, data_dict) | ||
from ckanext.fortify.logic.auth import helpers | ||
|
||
|
||
@toolkit.chained_auth_function | ||
def user_update(next_auth, context, data_dict): | ||
return disallow_non_image_uploads(next_auth, context, data_dict) | ||
def fortify_group_update(next_auth, context, data_dict): | ||
return helpers.disallow_non_image_uploads(next_auth, context, data_dict) | ||
|
||
|
||
@toolkit.chained_auth_function | ||
def organization_update(next_auth, context, data_dict): | ||
return disallow_non_image_uploads(next_auth, context, data_dict) | ||
def fortify_organization_update(next_auth, context, data_dict): | ||
return helpers.disallow_non_image_uploads(next_auth, context, data_dict) | ||
|
||
|
||
@toolkit.chained_auth_function | ||
def group_update(next_auth, context, data_dict): | ||
return disallow_non_image_uploads(next_auth, context, data_dict) | ||
def fortify_user_update(next_auth, context, data_dict): | ||
return helpers.disallow_non_image_uploads(next_auth, context, data_dict) |
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