Example #1
0
    def delete(self, id):
        if 'cancel' in request.params:
            self._redirect_to(controller='group', action='edit', id=id)

        context = {'model': model, 'session': model.Session,
                   'user': c.user or c.author}

        try:
            self._check_access('group_delete', context, {'id': id})
        except NotAuthorized:
            abort(401, _('Unauthorized to delete group %s') % '')

        try:
            if request.method == 'POST':
                self._action('group_delete')(context, {'id': id})
                if self.group_type == 'organization':
                    h.flash_notice(_('Organization has been deleted.'))
                else:
                    h.flash_notice(_('Group has been deleted.'))
                self._redirect_to(controller='group', action='index')
            c.group_dict = self._action('group_show')(context, {'id': id})
        except NotAuthorized:
            abort(401, _('Unauthorized to delete group %s') % '')
        except NotFound:
            abort(404, _('Group not found'))
        return self._render_template('group/confirm_delete.html')
Example #2
0
    def member_delete(self, id):
        if 'cancel' in request.params:
            self._redirect_to(controller='group', action='members', id=id)

        context = {'model': model, 'session': model.Session,
                   'user': c.user or c.author}

        try:
            self._check_access('group_member_delete', context, {'id': id})
        except NotAuthorized:
            abort(401, _('Unauthorized to delete group %s members') % '')

        try:
            user_id = request.params.get('user')
            if request.method == 'POST':
                self._action('group_member_delete')(context, {'id': id, 'user_id': user_id})
                h.flash_notice(_('Group member has been deleted.'))
                self._redirect_to(controller='group', action='members', id=id)
            c.user_dict = self._action('user_show')(context, {'id': user_id})
            c.user_id = user_id
            c.group_id = id
        except NotAuthorized:
            abort(401, _('Unauthorized to delete group %s') % '')
        except NotFound:
            abort(404, _('Group not found'))
        return self._render_template('group/confirm_delete_member.html')
Example #3
0
    def delete(self, id):
        if 'cancel' in request.params:
            h.redirect_to(controller='group', action='edit', id=id)

        context = {
            'model': model,
            'session': model.Session,
            'user': c.user or c.author
        }

        try:
            check_access('group_delete', context, {'id': id})
        except NotAuthorized:
            abort(401, _('Unauthorized to delete group %s') % '')

        try:
            if request.method == 'POST':
                get_action('group_delete')(context, {'id': id})
                h.flash_notice(_('Group has been deleted.'))
                h.redirect_to(controller='group', action='index')
            c.group_dict = get_action('group_show')(context, {'id': id})
        except NotAuthorized:
            abort(401, _('Unauthorized to delete group %s') % '')
        except NotFound:
            abort(404, _('Group not found'))
        return render('group/confirm_delete.html')
Example #4
0
 def send(self, pkg_id):
     package = Package.get(pkg_id)
     url = h.url_for(controller='package',
             action="read",
             id=package.id)
     if c.user:
             userid = None
             for role in package.roles:
                 if role.role == "admin":
                     userid = role.user_id
                     break
             if userid:
                 owner = User.get(userid)
                 msg = request.params.get('msg', '')
                 if msg:
                     send_contact_email(owner, c.userobj, package,\
                                    msg)
                 else:
                     h.flash_error(_("No message"))
                     return redirect(url)
             else:
                 h.flash_error(_("No owner found"))
                 return redirect(url)
             h.flash_notice(_("Message sent"))
     else:
         h.flash_error(_("Please login"))
     return redirect(url)
Example #5
0
 def logged_out_page(self):
     """
     This renders a page that informs the user of a successful logout.
     """
     url = h.url_for(controller='ckanext.ngds.ngdsui.controllers.home:HomeController', action='render_index')
     h.flash_notice(_('You are now Logged out'), allow_html=True)
     redirect(url)
Example #6
0
    def member_delete(self, id):
        if 'cancel' in request.params:
            self._redirect_to(controller='group', action='members', id=id)

        context = {'model': model, 'session': model.Session,
                   'user': c.user or c.author}

        try:
            self._check_access('group_member_delete', context, {'id': id})
        except NotAuthorized:
            abort(401, _('Unauthorized to delete group %s members') % '')

        try:
            user_id = request.params.get('user')
            if request.method == 'POST':
                self._action('group_member_delete')(context, {'id': id, 'user_id': user_id})
                h.flash_notice(_('Group member has been deleted.'))
                self._redirect_to(controller='group', action='members', id=id)
            c.user_dict = self._action('user_show')(context, {'id': user_id})
            c.user_id = user_id
            c.group_id = id
        except NotAuthorized:
            abort(401, _('Unauthorized to delete group %s') % '')
        except NotFound:
            abort(404, _('Group not found'))
        return self._render_template('group/confirm_delete_member.html')
Example #7
0
    def index(self):
        group_type = None
        context = {'model': model, 'session': model.Session,
                   'user': c.user or c.author, 'for_view': True,
                   'with_private': False}

        q = c.q = request.params.get('q', '')
        data_dict = {'all_fields': True, 'q': q}
        sort_by = c.sort_by_selected = request.params.get('sort')
        if sort_by:
            data_dict['sort'] = sort_by
        try:
            self._check_access('site_read', context)
        except NotAuthorized:
            abort(401, _('Not authorized to see this page'))
        if c.userobj:
            context['user_id'] = c.userobj.id
            context['user_is_admin'] = c.userobj.sysadmin



        c.group_package_stuff = caching.cached_get_group_package_stuff()

        ##Removing groups without geojson for the map
        c.group_map = []
        for gp in c.group_package_stuff:
            '''
                Removed check for geojson data because in the new version this information 
                does not come from the group_list action and for now we are not using the map.
                If we'll need this we should implement some caching functionality for this too.
            '''
            c.group_map.append(gp)

        #print c.group_package_stuff

        if c.userobj is not None:
            msg = None
            url = h.url_for(controller='user', action='edit')
            is_google_id = \
                c.userobj.name.startswith('https://www.google.com/accounts/o8/id')
            if not c.userobj.email and (is_google_id and not c.userobj.fullname):
                msg = _(u'Please <a href="{link}">update your profile</a>'
                        u' and add your email address and your full name. '
                        u'{site} uses your email address'
                        u' if you need to reset your password.'.format(
                            link=url, site=g.site_title))
            elif not c.userobj.email:
                msg = _('Please <a href="%s">update your profile</a>'
                        ' and add your email address. ') % url + \
                    _('%s uses your email address'
                        ' if you need to reset your password.') \
                    % g.site_title
            elif is_google_id and not c.userobj.fullname:
                msg = _('Please <a href="%s">update your profile</a>'
                        ' and add your full name.') % (url)
            if msg:
                h.flash_notice(msg, allow_html=True)

        return base.render('home/index.html', cache_force=True)
Example #8
0
 def _validate_uploadfile(self, data_file, resource_path, resource_list):
     """
     This function is responsible for validating a bulk upload.
     """
     err_msg = ""
     try:
         validator = ngdsvalidator.NGDSValidator(filepath=data_file, resource_path=resource_path,
                                                 resource_list=resource_list)
         validator.validate()
         status = "VALID"
         h.flash_notice(toolkit._('Files Uploaded Successfully.'), allow_html=True)
     except Exception, e:
         err_msg = e.__str__()
         h.flash_error(toolkit._('Uploaded files are invalid.: %s ') % err_msg, allow_html=True)
         status = "INVALID"
Example #9
0
 def _validate_uploadfile(self, data_file, resource_path, resource_list):
     """
     This function is responsible for validating a bulk upload.
     """
     err_msg = ""
     try:
         validator = ngdsvalidator.NGDSValidator(
             filepath=data_file,
             resource_path=resource_path,
             resource_list=resource_list)
         validator.validate()
         status = "VALID"
         h.flash_notice(toolkit._('Files Uploaded Successfully.'),
                        allow_html=True)
     except Exception, e:
         err_msg = e.__str__()
         h.flash_error(toolkit._('Uploaded files are invalid.: %s ') %
                       err_msg,
                       allow_html=True)
         status = "INVALID"
def notice_no_access():
    '''flash_notice if logged-in user can't actually do anything yet'''
    if h.check_access('package_create'):
        return

    h.flash_notice(
        '<strong>' + _('Account Created') +
        '</strong><br>' +
        _('Thank you for creating your account for the Open '
          'Government registry. Although your account is active, '
          'it has not yet been linked to your department. Until '
          'the account is linked to your department you will not '
          'be able to create or modify datasets in the '
          'registry.') +
        '<br><br>' +
        _('You should receive an email within the next business '
          'day once the account activation process has been '
          'completed. If you require faster processing of the '
          'account, please send the request directly to: '
          '<a href="mailto:[email protected]">'
          '[email protected]</a>'), True)
Example #11
0
        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)


    def member_list(self, group_name):
        """
        Accepts a group name, which is configured in the site configuration file and returns users that are associated with the group.
        """

        group = model.Group.get(group_name)
Example #12
0
            'session': model.Session,
            'user': c.user or c.author
        }

        try:
            check_access('execute_bulkupload', context, None)
        except NotAuthorized, error:
            abort(401, error.__str__())

        from ckanext.ngds.importer.importer import BulkUploader

        bulkLoader = BulkUploader()
        bulkLoader.execute_bulk_upload()

        h.flash_notice(toolkit._(
            'Initiated Bulk Upload process and it is running in the background.'
        ),
                       allow_html=True)
        url = h.url_for(
            controller=
            'ckanext.ngds.ngdsui.controllers.contribute:ContributeController',
            action='bulkupload_list')
        redirect(url)

    @jsonify
    def validate_resource(self):
        """
        Validate a resource to ensure that it conforms to NGDS standards. For ex: if a resource specifies that it conforms to a content model, that validation occurs here.
        """
        data = clean_dict(unflatten(tuplize_dict(parse_params(
            request.params))))
Example #13
0
 def logged_out_page(self):
     """ Redirect user to front page and inform user. """
     if not c.user:
         h.flash_notice(_("Successfully logged out."))
     h.redirect_to(controller='home', action='index')
Example #14
0
            get_action('comment_update_moderation')(context, {'id': id})
            email = config.get('ckan.comments.email', False)
            if email:
                message = 'A comment on the dataset "' + dataset_name + '" has been flagged as offensive / needing moderation. Please visit ' + h.url_for(
                    '/moderation/comments'
                ) + ' to approve or delete this comment'
                mailer.mail_recipient(
                    'Site Administrator',
                    config.get('ckan.comments.admin', 'root@localhost'),
                    'Dataset Comment Flagged for Moderation', message)
        except Exception, ee:
            abort(401, _('Unauthorized'))

        # Flag the package
        h.flash_notice(
            "Thank you for flagging the comment as inappropriate. It has been marked for moderation."
        )
        h.redirect_to(str('/dataset/%s' % (c.pkg.name, )))

    def approve(self, id):
        context = {'model': model, 'user': c.user}
        try:
            check_access('comment_update', context, {'id': id})
            get_action('comment_update_approve')(context, {'id': id})
        except Exception, ee:
            abort(401, _('Unauthorized'))

        # Flag the package
        h.flash_notice("Comment Approved.")
        h.redirect_to('/moderation/comments')
Example #15
0
 def logged_out_page(self):
     """ Redirect user to front page and inform user. """
     if not c.user:
         h.flash_notice(_("Successfully logged out."))
     h.redirect_to(controller='home', action='index')
Example #16
0
            c.pkg = context['package']
        except Exception, e:
            abort(401, _('Unauthorized'))

        try:
            get_action('comment_update_moderation')(context, {'id': id})
            email = config.get('ckan.comments.email', False)
            if email:
                message = 'A comment on the dataset "' + dataset_name + '" has been flagged as offensive / needing moderation. Please visit ' + h.url_for('/moderation/comments') + ' to approve or delete this comment'
                mailer.mail_recipient('Site Administrator', config.get('ckan.comments.admin', 'root@localhost'), 'Dataset Comment Flagged for Moderation',
                                      message)
        except Exception, ee:
            abort(401, _('Unauthorized'))

        # Flag the package
        h.flash_notice("Thank you for flagging the comment as inappropriate. It has been marked for moderation.")
        h.redirect_to(str('/dataset/%s' % (c.pkg.name,)))

    def approve(self, id):
        context = {'model': model, 'user': c.user}
        try:
            check_access('comment_update', context, {'id': id})
            get_action('comment_update_approve')(context, {'id': id})
        except Exception, ee:
            abort(401, _('Unauthorized'))

        # Flag the package
        h.flash_notice("Comment Approved.")
        h.redirect_to('/moderation/comments')

    def delete(self, id):
Example #17
0
    def index(self):
        group_type = None
        context = {
            'model': model,
            'session': model.Session,
            'user': c.user or c.author,
            'for_view': True,
            'with_private': False
        }

        q = c.q = request.params.get('q', '')
        data_dict = {'all_fields': True, 'q': q}
        sort_by = c.sort_by_selected = request.params.get('sort')
        if sort_by:
            data_dict['sort'] = sort_by
        try:
            self._check_access('site_read', context)
        except NotAuthorized:
            abort(403, _('Not authorized to see this page'))
        if c.userobj:
            context['user_id'] = c.userobj.id
            context['user_is_admin'] = c.userobj.sysadmin

        # c.group_package_stuff = caching.cached_get_group_package_stuff()
        #
        # ##Removing groups without geojson for the map
        # c.group_map = []
        # for gp in c.group_package_stuff:
        #     '''
        #         Removed check for geojson data because in the new version this information
        #         does not come from the group_list action and for now we are not using the map.
        #         If we'll need this we should implement some caching functionality for this too.
        #     '''
        #     c.group_map.append(gp)

        if c.userobj is not None:
            site_title = config.get('ckan.site_title', 'CKAN')
            msg = None
            url = h.url_for(controller='user', action='edit')
            is_google_id = \
                c.userobj.name.startswith('https://www.google.com/accounts/o8/id')
            if not c.userobj.email and (is_google_id
                                        and not c.userobj.fullname):
                msg = _(u'Please <a href="{link}">update your profile</a>'
                        u' and add your email address and your full name. '
                        u'{site} uses your email address'
                        u' if you need to reset your password.'.format(
                            link=url, site=site_title))
            elif not c.userobj.email:
                msg = _('Please <a href="%s">update your profile</a>'
                        ' and add your email address. ') % url + \
                      _('%s uses your email address'
                        ' if you need to reset your password.') \
                      % site_title
            elif is_google_id and not c.userobj.fullname:
                msg = _('Please <a href="%s">update your profile</a>'
                        ' and add your full name.') % (url)
            if msg:
                h.flash_notice(msg, allow_html=True)

        # template_data = {
        #     'data': {
        #         'hdx.carousel.config': logic.get_action('hdx_carousel_settings_show')({}, {})
        #     }
        # }
        c.structured_data = structured_data
        return base.render('home/index.html')
Example #18
0
        """
        Executes a bulk upload job. This function can only be triggered by an admin via the bulk upload page.
        """
        context = {'model': model, 'session': model.Session, 'user': c.user or c.author}

        try:
            check_access('execute_bulkupload', context, None)
        except NotAuthorized, error:
            abort(401, error.__str__())

        from ckanext.ngds.importer.importer import BulkUploader

        bulkLoader = BulkUploader()
        bulkLoader.execute_bulk_upload()

        h.flash_notice(toolkit._('Initiated Bulk Upload process and it is running in the background.'), allow_html=True)
        url = h.url_for(controller='ckanext.ngds.ngdsui.controllers.contribute:ContributeController',
                        action='bulkupload_list')
        redirect(url)

    @jsonify
    def validate_resource(self):
        """
        Validate a resource to ensure that it conforms to NGDS standards. For ex: if a resource specifies that it conforms to a content model, that validation occurs here.
        """
        data = clean_dict(unflatten(tuplize_dict(parse_params(
            request.params))))

        return toolkit.get_action("validate_resource")(None, data)