Skip to content

Commit

Permalink
override user_create for network authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
RabiaSajjad committed May 17, 2024
1 parent 694e316 commit 9ca0473
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 13 additions & 1 deletion ckanext/canada/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ckan.plugins.toolkit import chained_auth_function, config
from ckan.plugins.toolkit import chained_auth_function, config, request
from ckan.authz import has_user_permission_for_group_or_org, is_sysadmin
from ckanext.canada.helpers import registry_network_access


def _is_reporting_user(context):
Expand Down Expand Up @@ -27,6 +28,17 @@ def datastore_upsert(up_func, context, data_dict):
return up_func(context, data_dict)


@chained_auth_function
def user_create(up_func, context, data_dict=None):
if 'canada_internal' in config.get('ckan.plugins'):
# additional check to ensure user can access the Request an Account page
# only possible if accessing from GOC network
remote_addr = request.headers.get('X-Forwarded-For') or \
request.environ.get('REMOTE_ADDR')
if not registry_network_access(remote_addr):
return {'success': False}
return up_func(context, data_dict)

def view_org_members(context, data_dict):
user = context.get('user')
can_view = has_user_permission_for_group_or_org(data_dict.get(u'id'), user, 'manage_group')
Expand Down
9 changes: 0 additions & 9 deletions ckanext/canada/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,6 @@ def post(self, package_type, id):


class CanadaUserRegisterView(UserRegisterView):
def get(self, data=None, errors=None, error_summary=None):
# additional check to ensure user can access the Request an Account page
# only possible if accessing from GOC network
remote_addr = request.headers.get('X-Forwarded-For') or \
request.environ.get('REMOTE_ADDR')
if not h.registry_network_access(remote_addr):
abort(403, _('Not authorized to see this page'))
return super(CanadaUserRegisterView, self).get()

def post(self):
params = parse_params(request.form)
email=params.get('email', '')
Expand Down

0 comments on commit 9ca0473

Please sign in to comment.