Skip to content

Commit

Permalink
New option to disable user creation via web
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelbabu committed Sep 5, 2013
1 parent b26147e commit 910ca29
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions ckan/config/deployment.ini_tmpl
Expand Up @@ -66,6 +66,7 @@ ckan.auth.user_create_organizations = true
ckan.auth.user_delete_groups = true
ckan.auth.user_delete_organizations = true
ckan.auth.create_user_via_api = false
ckan.auth.create_user_via_web = true


## Search Settings
Expand Down
22 changes: 15 additions & 7 deletions ckan/logic/auth/create.py
Expand Up @@ -103,14 +103,22 @@ def rating_create(context, data_dict):
# No authz check in the logic function
return {'success': True}

def user_create(context, data_dict=None):
user = context['user']

if ('api_version' in context
and not new_authz.check_config_permission('create_user_via_api')):
return {'success': False, 'msg': _('User %s not authorized to create users') % user}
else:
return {'success': True}
def user_create(context, data_dict=None):
# create_user_via_api is deprecated
using_api = 'api_version' in context
create_user_via_api = new_authz.check_config_permission(
'create_user_via_api')
create_user_via_web = new_authz.check_config_permission(
'create_user_via_web')

if using_api and not create_user_via_api:
return {'success': False, 'msg': _('User {user} not authorized to '
'create users via the API').format(user=context.get('user'))}
if not using_api and not create_user_via_web:
return {'success': False, 'msg': _('Not authorized to '
'create users')}
return {'success': True}


def _check_group_auth(context, data_dict):
Expand Down
2 changes: 2 additions & 0 deletions ckan/new_authz.py
Expand Up @@ -86,6 +86,7 @@ def _build(self):

def clear_auth_functions_cache():
_AuthFunctions.clear()
CONFIG_PERMISSIONS.clear()


def auth_functions_list():
Expand Down Expand Up @@ -319,6 +320,7 @@ def get_user_id_for_username(user_name, allow_none=False):
'user_delete_groups': True,
'user_delete_organizations': True,
'create_user_via_api': False,
'create_user_via_web': True,
}

CONFIG_PERMISSIONS = {}
Expand Down
4 changes: 3 additions & 1 deletion ckan/templates/header.html
Expand Up @@ -49,7 +49,9 @@
<ul class="unstyled">
{% block header_account_notlogged %}
<li>{% link_for _('Log in'), controller='user', action='login' %}</li>
<li>{% link_for _('Register'), controller='user', action='register', class_='sub' %}</li>
{% if h.check_access('user_create') %}
<li>{% link_for _('Register'), controller='user', action='register', class_='sub' %}</li>
{% endif %}
{% endblock %}
</ul>
</nav>
Expand Down
20 changes: 11 additions & 9 deletions ckan/templates/user/login.html
Expand Up @@ -18,15 +18,17 @@ <h1 class="page-heading">{% block page_heading %}{{ _('Login') }}{% endblock %}<
{% endblock %}

{% block secondary_content %}
<section class="module module-narrow module-shallow">
<h2 class="module-heading">{{ _('Need an Account?') }}</h2>
<div class="module-content">
<p>{% trans %}Then sign right up, it only takes a minute.{% endtrans %}</p>
<p class="action">
<a class="btn" href="{{ h.url_for(controller='user', action='register') }}">{{ _('Create an Account') }}</a>
</p>
</div>
</section>
{% if h.check_access('user_create') %}
<section class="module module-narrow module-shallow">
<h2 class="module-heading">{{ _('Need an Account?') }}</h2>
<div class="module-content">
<p>{% trans %}Then sign right up, it only takes a minute.{% endtrans %}</p>
<p class="action">
<a class="btn" href="{{ h.url_for(controller='user', action='register') }}">{{ _('Create an Account') }}</a>
</p>
</div>
</section>
{% endif %}

<section class="module module-narrow module-shallow">
<h2 class="module-heading">{{ _('Forgotten your details?') }}</h2>
Expand Down
3 changes: 2 additions & 1 deletion test-core.ini
Expand Up @@ -31,6 +31,7 @@ solr_url = http://127.0.0.1:8983/solr
ckan.auth.user_create_organizations = true
ckan.auth.user_create_groups = true
ckan.auth.create_user_via_api = false
ckan.auth.create_user_via_web = true
ckan.auth.create_dataset_if_not_in_organization = true
ckan.auth.anon_create_dataset = false
ckan.auth.user_delete_groups=true
Expand Down Expand Up @@ -80,7 +81,7 @@ smtp.mail_from = info@test.ckan.net

ckan.locale_default = en
ckan.locale_order = en pt_BR ja it cs_CZ ca es fr el sv sr sr@latin no sk fi ru de pl nl bg ko_KR hu sa sl lv
ckan.locales_filtered_out =
ckan.locales_filtered_out =

ckan.datastore.enabled = 1

Expand Down

0 comments on commit 910ca29

Please sign in to comment.