Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan into 2750-add-docs-and-…
Browse files Browse the repository at this point in the history
…examples-for-idatasetform-and-igroupform
  • Loading branch information
Sean Hammond committed Sep 11, 2012
2 parents 025c1eb + 8996a68 commit 1090ead
Show file tree
Hide file tree
Showing 176 changed files with 60,544 additions and 33,890 deletions.
2 changes: 1 addition & 1 deletion .tx/config
@@ -1,7 +1,7 @@
[main]
host = http://www.transifex.net

[ckan.1-7]
[ckan.1-8]
file_filter = ckan/i18n/<lang>/LC_MESSAGES/ckan.po
source_file = ckan/i18n/ckan.pot
source_lang = en
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -30,6 +30,7 @@ v1.8
available by `setting ckan.restrict_template_vars = false` in your
.ini config file. Only restricted functions will be allowed in
future versions of CKAN.
* [#2842] Allow sort ordering of dataset listings on group pages

API changes and deprecation:
* [#2313] Deprecated functions related to the old faceting data structure have
Expand Down
2 changes: 1 addition & 1 deletion ckan/__init__.py
@@ -1,4 +1,4 @@
__version__ = '1.9a'
__version__ = '1.8b'
__description__ = 'Comprehensive Knowledge Archive Network (CKAN) Software'
__long_description__ = \
'''CKAN software provides a hub for datasets. The flagship site running CKAN
Expand Down
61 changes: 15 additions & 46 deletions ckan/authz.py
Expand Up @@ -27,7 +27,7 @@ class Authorizer(object):
'''
blacklister = Blacklister
extensions = PluginImplementations(IAuthorizer)

@classmethod
def am_authorized(cls, c, action, domain_object):
username = c.user or c.author
Expand All @@ -36,7 +36,7 @@ def am_authorized(cls, c, action, domain_object):
@classmethod
def is_authorized(cls, username, action, domain_object):
'''Authorize `action` by `username` on `domain_object`.
:param username: a user identifier (may be e.g. an IP address).
:param action: a ckan.model.authz.Action enumeration.
:param domain_object: the domain object instance (or class/type in the
Expand All @@ -47,7 +47,7 @@ def is_authorized(cls, username, action, domain_object):
if isinstance(username, str):
username = username.decode('utf8')
assert isinstance(username, unicode), type(username)

for extension in cls.extensions:
authorized = extension.is_authorized(username,
action,
Expand Down Expand Up @@ -92,7 +92,7 @@ def get_domain_object_roles_printable(cls, domain_obj):
printable_prs = []
for user, role in prs:
printable_prs.append('%s - \t%s' % (user.name, role))
return '%s roles:\n' % domain_obj.name + '\n'.join(printable_prs)
return '%s roles:\n' % domain_obj.name + '\n'.join(printable_prs)

@classmethod
def get_domain_object_roles(cls, domain_obj):
Expand All @@ -102,29 +102,9 @@ def get_domain_object_roles(cls, domain_obj):
q = model.Session.query(model.PackageRole).filter_by(package=domain_obj)
elif isinstance(domain_obj, model.Group):
q = model.Session.query(model.GroupRole).filter_by(group=domain_obj)
elif isinstance(domain_obj, model.AuthorizationGroup):
q = model.Session.query(model.AuthorizationGroupRole).filter_by(authorization_group=domain_obj)
prs = [ (pr.user, pr.role) for pr in q.all() ]
return prs

@classmethod
def get_authorization_groups(cls, username):
q = model.Session.query(model.AuthorizationGroup)
q = q.autoflush(False)
user = model.User.by_name(username, autoflush=False)
if username == model.PSEUDO_USER__VISITOR or not user:
q = q.filter(model.AuthorizationGroup.users.any(name=model.PSEUDO_USER__VISITOR))
else:
q = q.filter(model.AuthorizationGroup.users.any(
sa.or_(model.User.name==model.PSEUDO_USER__VISITOR,
model.User.name==model.PSEUDO_USER__LOGGED_IN,
model.User.name==username)))

groups = q.all()
for extension in cls.extensions:
extra_groups = extension.get_authorization_groups(username)
groups.extend(extra_groups)
return groups

@classmethod
def get_roles(cls, username, domain_obj):
Expand All @@ -134,25 +114,22 @@ def get_roles(cls, username, domain_obj):
assert isinstance(username, unicode), repr(username)

# filter by user and pseudo-users
# TODO: these can be made into subqueries/joins!
# TODO: these can be made into subqueries/joins!
user = model.User.by_name(username, autoflush=False)
visitor = model.User.by_name(model.PSEUDO_USER__VISITOR, autoflush=False)
q = cls._get_roles_query(domain_obj)
q = q.autoflush(False)

filters = [model.UserObjectRole.user==visitor]
# check for groups:
for authz_group in cls.get_authorization_groups(username):
filters.append(model.UserObjectRole.authorized_group==authz_group)


if (username != model.PSEUDO_USER__VISITOR) and (user is not None):
logged_in = model.User.by_name(model.PSEUDO_USER__LOGGED_IN)
filters.append(model.UserObjectRole.user==user)
filters.append(model.UserObjectRole.user==logged_in)

q = q.filter(sa.or_(*filters))
return [pr.role for pr in q]

@classmethod
def is_sysadmin(cls, user):
'''Returns whether the given user a sys-admin?
Expand Down Expand Up @@ -180,9 +157,6 @@ def get_admins(cls, domain_obj):
elif isinstance(domain_obj, model.Group):
q = model.Session.query(model.GroupRole).filter_by(group=domain_obj,
role=model.Role.ADMIN)
elif isinstance(domain_obj, model.AuthorizationGroup):
q = model.Session.query(model.AuthorizationGroupRole).filter_by(authorization_group=domain_obj,
role=model.Role.ADMIN)
q = q.autoflush(False)
admins = [do_role.user for do_role in q.all() if do_role.user]
return admins
Expand All @@ -202,24 +176,22 @@ def authorized_query(cls, username, entity, action=model.Action.READ):
# This gets the role table the entity is joined to. we
# need to use this in the queries below as if we use
# model.UserObjectRole a cross join happens always
# returning all the roles.
# returning all the roles.
if hasattr(entity, 'continuity'):
q = q.filter_by(current=True)
q = q.outerjoin('continuity', 'roles')
continuity = entity.continuity.property.mapper.class_
role_cls = continuity.roles.property.mapper.class_
role_cls = continuity.roles.property.mapper.class_
else:
role_cls = entity.roles.property.mapper.class_
role_cls = entity.roles.property.mapper.class_
q = q.outerjoin('roles')

if hasattr(entity, 'state'):
state = entity.state
else:
state = None

filters = [model.UserObjectRole.user==visitor]
for authz_group in cls.get_authorization_groups(username):
filters.append(role_cls.authorized_group==authz_group)
if user:
filters.append(role_cls.user==user)
filters.append(role_cls.user==logged_in)
Expand All @@ -234,7 +206,7 @@ def authorized_query(cls, username, entity, action=model.Action.READ):
model.RoleAction.action==action,
state and state!=model.State.DELETED),
)
q = q.filter(sa.or_(*filters))
q = q.filter(sa.or_(*filters))
q = q.distinct()

return q
Expand Down Expand Up @@ -282,9 +254,6 @@ def _get_roles_query(cls, domain_obj):
elif isinstance(domain_obj, model.Group):
q = q.with_polymorphic(model.GroupRole)
q = q.filter(model.GroupRole.group==domain_obj)
elif isinstance(domain_obj, model.AuthorizationGroup):
q = q.with_polymorphic(model.AuthorizationGroupRole)
q = q.filter(model.AuthorizationGroupRole.authorization_group==domain_obj)
elif isinstance(domain_obj, model.System):
q = q.with_polymorphic(model.SystemRole)
q = q.filter(model.SystemRole.context==unicode(model.System.__name__))
Expand All @@ -295,4 +264,4 @@ def _get_roles_query(cls, domain_obj):
q = q.filter_by(context=unicode(context))
return q


38 changes: 34 additions & 4 deletions ckan/config/deployment.ini_tmpl
Expand Up @@ -158,10 +158,12 @@ ckan.backup_dir = %(here)s/backup
# Locale/languages
ckan.locale_default = en
#ckan.locales_offered =
# Default order is roughly by number of people speaking it in Europe:
# http://en.wikipedia.org/wiki/Languages_of_the_European_Union#Knowledge
ckan.locale_order = en de fr it es pl ru nl sv no cs_CZ hu pt_BR fi bg ca sq sr sr_Latn
ckan.locales_filtered_out = el ro lt sl
# Languages are grouped by percentage of strings in CKAN 1.8 translated
# (those with 100% first, then those with >=80%, then >=50%, then <50%) and
# within these groups roughly sorted by number of worldwide native speakers
# according to Wikipedia.
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 =

## Atom Feeds
#
Expand Down Expand Up @@ -196,6 +198,34 @@ ckan.feeds.author_name =
# If not set, then the value in `ckan.site_url` is used.
ckan.feeds.author_link =

## File Store
#
# CKAN allows users to upload files directly to file storage either on the local
# file system or to online ‘cloud’ storage like Amazon S3 or Google Storage.
#
# If you are using local file storage, remember to set ckan.site_url.
#
# To enable cloud storage (Google or S3), first run: pip install boto
#
# @see http://docs.ckan.org/en/latest/filestore.html

# 'Bucket' to use for file storage
#ckan.storage.bucket = my-bucket-name

# To enable local file storage:
#ofs.impl = pairtree
#ofs.storage_dir = /my/path/to/storage/root/directory

# To enable Google cloud storage:
#ofs.impl = google
#ofs.gs_access_key_id =
#ofs.gs_secret_access_key =

# To enable S3 cloud storage:
#ofs.impl = s3
#ofs.aws_access_key_id = ....
#ofs.aws_secret_access_key = ....

## Webstore
## Uncommment to enable datastore
# ckan.datastore.enabled = 1
Expand Down
4 changes: 3 additions & 1 deletion ckan/config/environment.py
Expand Up @@ -16,7 +16,6 @@
import ckan.model as model
import ckan.plugins as p
import ckan.lib.helpers as h
import ckan.lib.search as search
import ckan.lib.app_globals as app_globals

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -161,6 +160,9 @@ def find_controller(self, controller):

# Init SOLR settings and check if the schema is compatible
#from ckan.lib.search import SolrSettings, check_solr_schema_version

# lib.search is imported here as we need the config enabled and parsed
import ckan.lib.search as search
search.SolrSettings.init(config.get('solr_url'),
config.get('solr_user'),
config.get('solr_password'))
Expand Down
14 changes: 0 additions & 14 deletions ckan/config/routing.py
Expand Up @@ -58,7 +58,6 @@ def make_map():
'tag',
'group',
'related',
'authorizationgroup',
'revision',
'licenses',
'rating',
Expand Down Expand Up @@ -119,8 +118,6 @@ def make_map():
action='format_autocomplete', conditions=GET)
m.connect('/util/resource/format_icon',
action='format_icon', conditions=GET)
m.connect('/util/authorizationgroup/autocomplete',
action='authorizationgroup_autocomplete')
m.connect('/util/group/autocomplete', action='group_autocomplete')
m.connect('/util/markdown', action='markdown')
m.connect('/util/dataset/munge_name', action='munge_package_name')
Expand Down Expand Up @@ -229,17 +226,6 @@ def make_map():
register_package_plugins(map)
register_group_plugins(map)

# authz group
map.redirect('/authorizationgroups', '/authorizationgroup')
map.redirect('/authorizationgroups/{url:.*}', '/authorizationgroup/{url}')
with SubMapper(map, controller='authorization_group') as m:
m.connect('/authorizationgroup', action='index')
m.connect('/authorizationgroup/list', action='list')
m.connect('/authorizationgroup/new', action='new')
m.connect('/authorizationgroup/edit/{id}', action='edit')
m.connect('/authorizationgroup/authz/{id}', action='authz')
m.connect('/authorizationgroup/{id}', action='read')

# tags
map.redirect('/tags', '/tag')
map.redirect('/tags/{url:.*}', '/tag/{url}')
Expand Down

0 comments on commit 1090ead

Please sign in to comment.