예제 #1
0
파일: user.py 프로젝트: okfn/ckanext-ngds
class UserController(NGDSBaseController):
    def manage_users(self, group_name='public', data_dict=None):

        """
        Renders the user management page and lists users along with their roles.
        """
        context = {'model': model, 'session': model.Session, 'user': c.user or c.author}

        try:
            check_access('manage_users', context, data_dict)
        except NotAuthorized, error:
            abort(401, error.__str__())

        group_name = helpers.get_default_group()
        group_members = self.member_list(group_name)

        q = model.Session.query(model.User). \
            filter(~ model.User.name.in_((model.PSEUDO_USER__LOGGED_IN, model.PSEUDO_USER__VISITOR)))

        def role_lookup(userid, group_members):

            for user_id, role in group_members:
                if user_id == userid:
                    return role
            return ""

        roles = get_action('member_roles_list')(context, {})

        c.roles = [{'text': u'', 'value': 'default'}]
        c.roles.extend(roles)
        g.group_name = group_name

        c.members = [(m.id, m.name, m.email, role_lookup(m.id, group_members),) for m in q.all()]

        return render('user/manage_users.html')
예제 #2
0
def publish_dataset(context, data_dict):
    """
    This method got to check whether user has access to publish dataset based on his role.
    """

    model = context['model']
    user = context.get('user','')
    print "User Logged: ",user
    #Change the group to be coming from global setting...
    check1 = new_authz.has_user_permission_for_group_or_org(helpers.get_default_group(), user, 'publish_dataset')
    if not check1:
        return {'success': False, 'msg': _('User %s not authorized to publish dataset') % (str(user))}
    return {'success': True}
예제 #3
0
파일: user.py 프로젝트: okfn/ckanext-ngds
        redirect(url)


    def member_new(self, data_dict=None):
        """
        Accepts a request to change the role or assign a role to a user and performs the operation.
        """
        context = {'model': model, 'session': model.Session, 'user': c.user}
        data_dict = clean_dict(unflatten(tuplize_dict(parse_params(request.params))))

        try:
            check_access('manage_users', context, data_dict)
        except NotAuthorized, error:
            abort(401, error.__str__())

        group = model.Group.get(helpers.get_default_group())

        data_dict['id'] = group.id

        role = data_dict['role']

        if role == 'default':
            get_action('group_member_delete')(context, data_dict)
            h.flash_notice(_('User rights are removed.'), allow_html=True)
        else:
            get_action('group_member_create')(context, data_dict)
            h.flash_success(_('User Role is Updated Successfully.'), allow_html=True)

        url = h.url_for(controller='ckanext.ngds.ngdsui.controllers.user:UserController', action='manage_users')
        redirect(url)
예제 #4
0
                 'relationships',
                 'license',
                 'ratings_average', 'ratings_count',
                 'ckan_url',
                 'metadata_modified',
                 'metadata_created',
                 'notes_rendered')

referenced_keys = ('data_type', 'status', 'protocol')

responsible_party_keys = ('authors', 'maintainer', 'distributor')

date_keys = ('publication_date')


DEFAULT_GROUP = ui_helper.get_default_group()


class BulkUploader(object):

    def __init__(self,client_config=None):

        if client_config is None:
            client_config_file = config.get('ngds.client_config_file')
        else:
            client_config_file = client_config
        #print "client_config_file: ",client_config_file
        self._loadclientconfig(client_config_file)
        self.ckanclient = self._get_ckanclient()

예제 #5
0
from ckanext.ngds.ngdsui.misc import helpers as ui_helper

log = __import__("logging").getLogger(__name__)

#Need to decide our own Read only keys
readonly_keys = ('id', 'revision_id', 'relationships', 'license',
                 'ratings_average', 'ratings_count', 'ckan_url',
                 'metadata_modified', 'metadata_created', 'notes_rendered')

referenced_keys = ('data_type', 'status', 'protocol')

responsible_party_keys = ('authors', 'maintainer', 'distributor')

date_keys = ('publication_date')

DEFAULT_GROUP = ui_helper.get_default_group()


class BulkUploader(object):
    def __init__(self, client_config=None):

        if client_config is None:
            client_config_file = config.get('ngds.client_config_file')
        else:
            client_config_file = client_config
        #print "client_config_file: ",client_config_file
        self._loadclientconfig(client_config_file)
        self.ckanclient = self._get_ckanclient()

    def _loadclientconfig(self, config_path):
        """