Skip to content

Commit

Permalink
Merge branch 'master' into 1208-dictize-changes-2
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Dec 11, 2013
2 parents efdfc03 + 27b903b commit 05c5c2c
Show file tree
Hide file tree
Showing 71 changed files with 3,841 additions and 518 deletions.
1 change: 1 addition & 0 deletions ckan/config/deployment.ini_tmpl
Expand Up @@ -67,6 +67,7 @@ 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
ckan.auth.roles_that_cascade_to_sub_groups = admin


## Search Settings
Expand Down
6 changes: 4 additions & 2 deletions ckan/config/environment.py
Expand Up @@ -367,8 +367,10 @@ def template_loaded(template):
# Here we create the site user if they are not already in the database
try:
logic.get_action('get_site_user')({'ignore_auth': True}, None)
except sqlalchemy.exc.ProgrammingError:
# The database is not initialised. This is a bit dirty.
except (sqlalchemy.exc.ProgrammingError, sqlalchemy.exc.OperationalError):
# (ProgrammingError for Postgres, OperationalError for SQLite)
# The database is not initialised. This is a bit dirty. This occurs
# when running tests.
pass
except sqlalchemy.exc.InternalError:
# The database is not initialised. Travis hits this
Expand Down
3 changes: 3 additions & 0 deletions ckan/config/routing.py
Expand Up @@ -229,6 +229,7 @@ def make_map():
'history_ajax',
'follow',
'activity',
'groups',
'unfollow',
'delete',
'api_data',
Expand All @@ -240,6 +241,8 @@ def make_map():
m.connect('dataset_activity', '/dataset/activity/{id}',
action='activity', ckan_icon='time')
m.connect('/dataset/activity/{id}/{offset}', action='activity')
m.connect('dataset_groups', '/dataset/groups/{id}',
action='groups', ckan_icon='group')
m.connect('/dataset/{id}.{format}', action='read')
m.connect('dataset_resources', '/dataset/resources/{id}',
action='resources', ckan_icon='reorder')
Expand Down
5 changes: 4 additions & 1 deletion ckan/controllers/group.py
Expand Up @@ -168,6 +168,9 @@ def index(self):

def read(self, id, limit=20):
group_type = self._get_group_type(id.split('@')[0])
if group_type != self.group_type:
abort(404, _('Incorrect group type'))

context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'schema': self._db_to_form_schema(group_type=group_type),
Expand Down Expand Up @@ -650,7 +653,7 @@ def member_new(self, id):
else:
c.user_role = 'member'
c.group_dict = self._action('group_show')(context, {'id': id})
c.roles = self._action('member_roles_list')(context, {})
c.roles = self._action('member_roles_list')(context, {'group_type': 'group'})
except NotAuthorized:
abort(401, _('Unauthorized to add member to group %s') % '')
except NotFound:
Expand Down
58 changes: 57 additions & 1 deletion ckan/controllers/package.py
Expand Up @@ -315,7 +315,7 @@ def resources(self, id):
data_dict = {'id': id}

try:
check_access('package_update', context)
check_access('package_update', context, data_dict)
except NotAuthorized, e:
abort(401, _('User %r not authorized to edit %s') % (c.user, id))
# check if package exists
Expand Down Expand Up @@ -1302,6 +1302,62 @@ def followers(self, id=None):

return render('package/followers.html')

def groups(self, id):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True,
'auth_user_obj': c.userobj, 'use_cache': False}
data_dict = {'id': id}
try:
c.pkg_dict = get_action('package_show')(context, data_dict)
except NotFound:
abort(404, _('Dataset not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read dataset %s') % id)

if request.method == 'POST':
new_group = request.POST.get('group_added')
if new_group:
data_dict = {"id": new_group,
"object": id,
"object_type": 'package',
"capacity": 'public'}
try:
get_action('member_create')(context, data_dict)
except NotFound:
abort(404, _('Group not found'))

removed_group = request.POST.get('group_removed')
if removed_group:
data_dict = {"id": removed_group,
"object": id,
"object_type": 'package'}

try:
get_action('member_delete')(context, data_dict)
except NotFound:
abort(404, _('Group not found'))
redirect(h.url_for(controller='package',
action='groups', id=id))



context['is_member'] = True
users_groups = get_action('group_list_authz')(context, data_dict)

pkg_group_ids = set(group['id'] for group
in c.pkg_dict.get('groups', []))
user_group_ids = set(group['id'] for group
in users_groups)

c.group_dropdown = [[group['id'], group['display_name']]
for group in users_groups if
group['id'] not in pkg_group_ids]

for group in c.pkg_dict.get('groups', []):
group['user_member'] = (group['id'] in user_group_ids)

return render('package/group_list.html')

def activity(self, id):
'''Render this package's public activity stream page.'''

Expand Down
6 changes: 1 addition & 5 deletions ckan/controllers/user.py
Expand Up @@ -451,7 +451,7 @@ def perform_reset(self, id):
# reuse of the url
context = {'model': model, 'session': model.Session,
'user': id,
'keep_sensitive_data': True}
'keep_email': True}

try:
check_access('user_reset', context)
Expand All @@ -462,10 +462,6 @@ def perform_reset(self, id):
data_dict = {'id': id}
user_dict = get_action('user_show')(context, data_dict)

# Be a little paranoid, and get rid of sensitive data that's
# not needed.
user_dict.pop('apikey', None)
user_dict.pop('reset_key', None)
user_obj = context['user_obj']
except NotFound, e:
abort(404, _('User not found'))
Expand Down
1 change: 0 additions & 1 deletion ckan/lib/accept.py
Expand Up @@ -12,7 +12,6 @@
# Name : ContentType, Is Markup?, Extension
"text/html": ("text/html; charset=utf-8", True, 'html'),
"text/n3": ("text/n3; charset=utf-8", False, 'n3'),
"text/plain": ("text/plain; charset=utf-8", False, 'txt'),
"application/rdf+xml": ("application/rdf+xml; charset=utf-8", True, 'rdf'),
}
accept_by_extension = {
Expand Down
5 changes: 4 additions & 1 deletion ckan/lib/cli.py
Expand Up @@ -1322,7 +1322,7 @@ class CreateTestDataCommand(CkanCommand):
translations of terms
create-test-data vocabs - annakerenina, warandpeace, and some test
vocabularies
create-test-data hierarchy - hierarchy of groups
'''
summary = __doc__.split('\n')[0]
usage = __doc__
Expand All @@ -1332,6 +1332,7 @@ class CreateTestDataCommand(CkanCommand):
def command(self):
self._load_config()
self._setup_app()
from ckan import plugins
from create_test_data import CreateTestData

if self.args:
Expand All @@ -1356,6 +1357,8 @@ def command(self):
CreateTestData.create_translations_test_data()
elif cmd == 'vocabs':
CreateTestData.create_vocabs_test_data()
elif cmd == 'hierarchy':
CreateTestData.create_group_hierarchy_test_data()
else:
print 'Command %s not recognized' % cmd
raise NotImplementedError
Expand Down

0 comments on commit 05c5c2c

Please sign in to comment.