示例#1
0
    def _add_users( self, group, parameters  ):
        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=action.error_summary(errors))

        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
        l = data_dict['users']
        for d in l:
            d['capacity'] = d.get('capacity','editor')

        context = {
            "group" : group,
            "schema": schema.default_group_schema(),
            "model": model,
            "session": model.Session
        }

        # Temporary cleanup of a capacity being sent without a name
        users = [d for d in data_dict['users'] if len(d) == 2]
        data_dict['users'] = users

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

        h.redirect_to( controller='group', action='edit', id=group.name)
示例#2
0
    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))

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

        # Temporary fix for strange caching during dev
        l = data_dict['users']
        for d in l:
            # Form javascript creates d['capacity'] == 'undefined' for
            # newly added users.
            # If javascript in users form is not working (such as in tests)
            # it will not create a capacity value.
            if 'capacity' not in d or d['capacity'] == 'undefined':
                # default to 'editor'
                d['capacity'] = 'editor'

        context = {
            "group" : group,
            "schema": default_group_schema(),
            "model": model,
            "session": model.Session
        }

        # Temporary cleanup of a capacity being sent without a name
        users = [d for d in data_dict['users'] if len(d) == 2]
        data_dict['users'] = users

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

        h.redirect_to('/publisher/%s' % str(group.name))
示例#3
0
    def _add_users(self, group, parameters):
        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=action.error_summary(errors))

        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
        l = data_dict['users']
        for d in l:
            d['capacity'] = d.get('capacity', 'editor')

        context = {
            "group": group,
            "schema": schema.default_group_schema(),
            "model": model,
            "session": model.Session
        }

        # Temporary cleanup of a capacity being sent without a name
        users = [d for d in data_dict['users'] if len(d) == 2]
        data_dict['users'] = users

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

        h.redirect_to(controller='group', action='edit', id=group.name)
    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.users(group.name,
                              errors=errors,
                              error_summary=error_summary(errors))

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

        # Check that the user being added, if they are a Drupal user, has
        # verified their email address
        new_users = [user['name'] for user in data_dict['users'] \
                     if not 'capacity' in user or user['capacity'] == 'undefined']

        # Removed Drupal auth stuff.
        # for user_name in new_users:
        # drupal_id = DrupalUserMapping.ckan_user_name_to_drupal_id(user_name)
        # if drupal_id:
        #     if not is_drupal_auth_activated():
        #         # joint auth with Drupal is not activated, so cannot
        #         # check with Drupal
        #         log.warning('Drupal user made editor/admin but without checking email is verified.')
        #         break
        #     if 'drupal_client' not in dir(self):
        #         self.drupal_client = DrupalClient()
        #     user_properties = self.drupal_client.get_user_properties(drupal_id)
        #     roles = user_properties['roles'].values()
        #     if 'unverified user' in roles:
        #         user = model.User.by_name(user_name)
        #         h.flash_error("There was a problem with your submission - see the error message below.")
        #         errors = {"reason": ['User "%s" has not verified their email address yet. '
        #                              'Please ask them to do this and then try again. ' % \
        #                               user.fullname]}
        #         log.warning('Trying to add user (%r %s) who is not verified to group %s',
        #                     user.fullname, user_name, group.name)
        #         # NB Other values in the form are lost, but that is probably ok
        #         return self.users(group.name, errors=errors,
        #                           error_summary=error_summary(errors))

        # Temporary fix for strange caching during dev
        l = data_dict['users']
        for d in l:
            # Form javascript creates d['capacity'] == 'undefined' for
            # newly added users.
            # If javascript in users form is not working (such as in tests)
            # it will not create a capacity value.
            if 'capacity' not in d or d['capacity'] == 'undefined':
                # default to 'editor'
                d['capacity'] = 'editor'

        context = {
            "group": group,
            "schema": default_group_schema(),
            "model": model,
            "session": model.Session
        }

        # Temporary cleanup of a capacity being sent without a name
        users = [d for d in data_dict['users'] if len(d) == 2]
        data_dict['users'] = users

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

        h.redirect_to('/organisation/%s' % str(group.name))