Skip to content

Commit

Permalink
[2255] Cleanup of application process and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Mar 29, 2012
1 parent 41cce2b commit a466a88
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
2 changes: 0 additions & 2 deletions ckan/controllers/group.py
Expand Up @@ -37,11 +37,9 @@ def _setup_template_variables(self, context, data_dict, group_type=None):
return lookup_group_plugin(group_type).setup_template_variables(context,data_dict)

def _new_template(self,group_type):
from ckan.lib.helpers import default_group_type
return lookup_group_plugin(group_type).new_template()

def _index_template(self,group_type):
from ckan.lib.helpers import default_group_type
return lookup_group_plugin(group_type).index_template()

def _read_template(self, group_type):
Expand Down
50 changes: 23 additions & 27 deletions ckanext/organizations/controllers.py
@@ -1,19 +1,22 @@
import logging
from urllib import urlencode

from ckan.lib.base import BaseController, c, model, request, render, h, g
from ckan.lib.base import ValidationException, abort, gettext
from pylons.i18n import get_lang, _
import ckan.authz as authz
from ckan.lib.alphabet_paginate import AlphaPage
from ckan.lib.navl.dictization_functions import DataError, unflatten, validate
from ckan.authz import Authorizer
from ckan.logic import NotFound, NotAuthorized, ValidationError
from ckan.logic import check_access, get_action
from ckan.logic import tuplize_dict, clean_dict, parse_params
from ckan.lib.dictization.model_dictize import package_dictize

import ckan.forms
import ckan.authz as authz
import ckan.lib.dictization.model_save as model_save
import ckan.lib.mailer as mailer
import ckan.lib.navl.dictization_functions as dict_func
import ckan.logic as logic
import ckan.logic.action as action
import ckan.logic.schema as schema
import ckan.model as model

import pylons.config as config
from ckan.lib.navl.validators import (ignore_missing,
not_empty,
empty,
Expand All @@ -23,28 +26,25 @@
class OrganizationController(BaseController):

def _send_application( self, group, reason ):
from ckan.logic.action import error_summary
from ckan.lib.mailer import mail_recipient
from genshi.template.text import NewTextTemplate
from pylons import config

if not reason:
h.flash_error(_("There was a problem with your submission, \
please correct it and try again"))
errors = {"reason": ["No reason was supplied"]}
return self.apply(group.id, errors=errors,
error_summary=error_summary(errors))
error_summary=action.error_summary(errors))

admins = group.members_of_type( model.User, 'admin' ).all()
recipients = [(u.fullname,u.email) for u in admins] if admins else \
[(config.get('dgu.admin.name', "DGU Admin"),
config.get('dgu.admin.email', None), )]
[(config.get('ckan.admin.name', "CKAN Administrator"),
config.get('ckan.admin.email', None), )]

if not recipients:
h.flash_error(_("There is a problem with the system configuration"))
errors = {"reason": ["No group administrator exists"]}
return self.apply(group.id, data=data, errors=errors,
error_summary=error_summary(errors))
error_summary=action.error_summary(errors))

extra_vars = {
'group' : group,
Expand All @@ -56,15 +56,15 @@ def _send_application( self, group, reason ):

try:
for (name,recipient) in recipients:
mail_recipient(name,
mailer.mail_recipient(name,
recipient,
"Publisher request",
email_msg)
except:
h.flash_error(_("There is a problem with the system configuration"))
errors = {"reason": ["No mail server was found"]}
return self.apply(group.id, errors=errors,
error_summary=error_summary(errors))
error_summary=action.error_summary(errors))

h.flash_success(_("Your application has been submitted"))
h.redirect_to( 'publisher_read', id=group.name)
Expand Down Expand Up @@ -94,19 +94,15 @@ def apply(self, id=None, data=None, errors=None, error_summary=None):
return render('organization_apply.html')

def _add_users( self, group, parameters ):
from ckan.logic.schema import default_group_schema
from ckan.logic.action import error_summary
from ckan.lib.dictization.model_save import group_member_save

if not group:
h.flash_error(_("There was a problem with your submission, \
please correct it and try again"))
errors = {"reason": ["No reason was supplied"]}
return self.apply(group.id, errors=errors,
error_summary=error_summary(errors))
error_summary=action.error_summary(errors))

data_dict = clean_dict(unflatten(
tuplize_dict(parse_params(request.params))))
data_dict = logic.clean_dict(dict_func.unflatten(
logic.tuplize_dict(logic.parse_params(request.params))))
data_dict['id'] = group.id

# Temporary fix for strange caching during dev
Expand All @@ -116,7 +112,7 @@ def _add_users( self, group, parameters ):

context = {
"group" : group,
"schema": default_group_schema(),
"schema": schema.default_group_schema(),
"model": model,
"session": model.Session
}
Expand All @@ -126,7 +122,7 @@ def _add_users( self, group, parameters ):
data_dict['users'] = users

model.repo.new_revision()
group_member_save(context, data_dict, 'users')
model_save.group_member_save(context, data_dict, 'users')
model.Session.commit()

h.redirect_to( controller='group', action='edit', id=group.name)
Expand All @@ -145,8 +141,8 @@ def users(self, id, data=None, errors=None, error_summary=None):
'group': c.group }

try:
check_access('group_update',context)
except NotAuthorized, e:
logic.check_access('group_update',context)
except logic.NotAuthorized, e:
abort(401, _('User %r not authorized to edit %s') % (c.user, id))

if 'save' in request.params and not errors:
Expand Down
4 changes: 3 additions & 1 deletion ckanext/organizations/forms.py
Expand Up @@ -36,8 +36,10 @@ def before_map(self, map):
map.connect('/organization/apply/{id}', controller='ckanext.organizations.controllers:OrganizationController', action='apply')
map.connect('/organization/apply', controller='ckanext.organizations.controllers:OrganizationController', action='apply')
map.connect('/organization/edit/{id}', controller='group', action='edit')
map.connect('/organization/new', controller='group', action='new')
map.connect('/organization/{id}', controller='group', action='read')

map.connect('/organization', controller='group', action='index')
map.redirect('/organizations', '/organization')
return map

def after_map(self, map):
Expand Down
2 changes: 1 addition & 1 deletion ckanext/organizations/templates/organization_layout.html
Expand Up @@ -18,7 +18,7 @@
<li class="${'active' if c.action=='edit' else ''}" py:if="can_update">
${h.subnav_named_route( c,h.icon('group_edit') + _('Edit'), 'organization_action', action='edit', id=c.group.name )}
</li>
<li class="${'active' if c.action=='apply' else ''}">
<li class="${'active' if c.action=='apply' else ''} ckan-logged-in" py:if="c.userobj and not c.userobj.is_in_group(c.group)">
<a href="${h.url_for(controller='ckanext.organizations.controllers:OrganizationController', action='apply')}?parent=${c.group.name}">${h.icon('group_edit') + _('Join')}</a>
</li>

Expand Down
8 changes: 7 additions & 1 deletion doc/publisher-profile.rst
Expand Up @@ -11,7 +11,13 @@ to.

Specifically, the workflow looks like:

* A User is added to an Organization by an Organization administrator
* A User joins or creates an Organization

* If the user is the creator of the Organization then they become administrator of the Organization.

* Otherwise they become a Member.

* New Members must be added by the Organization Administrator, although anyone can request to join an Organization

* User creates a dataset. On creation User must assign this dataset to a
specific organization (and can only assign to a organization of which User is a
Expand Down

0 comments on commit a466a88

Please sign in to comment.