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)) # look for publisher admins up the tree recipients = [] recipient_publisher = None for publisher in go_up_tree(group): admins = publisher.members_of_type(model.User, 'admin').all() if admins: recipients = [(u.fullname,u.email) for u in admins] recipient_publisher = publisher.title break if not recipients: if not config.get('dgu.admin.email'): log.error('User "%s" prevented from applying for publisher access for "%s" ' 'because: dgu.admin.email is not setup in CKAN config.', c.user, group.name) h.flash_error(_("There is a problem with the system configuration")) errors = {"reason": ["%s does not have an administrator user to contact" % group.name]} return self.apply(group.id, data=data, errors=errors, error_summary=error_summary(errors)) recipients = [(config.get('dgu.admin.name', "DGU Admin"), config['dgu.admin.email'])] recipient_publisher = 'data.gov.uk admin' log.debug('User "%s" requested publisher access for "%s" which was sent to admin %s (%r) with reason: %r', c.user, group.name, recipient_publisher, recipients, reason) extra_vars = { 'group' : group, 'requester': c.userobj, 'reason' : reason } email_msg = render("email/join_publisher_request.txt", extra_vars=extra_vars, loader_class=NewTextTemplate) try: for (name,recipient) in recipients: mail_recipient(name, recipient, "Publisher request", email_msg) except Exception, e: h.flash_error(_("There is a problem with the system configuration")) errors = {"reason": ["No mail server was found"]} log.error('User "%s" prevented from applying for publisher access for "%s" because of mail configuration error: %s', c.user, group.name, e) return self.apply(group.id, errors=errors, error_summary=error_summary(errors))
def _send_application(self, group, reason): from genshi.template.text import NewTextTemplate if not reason: base.h.flash_error( toolkit._("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)) admins = group.members_of_type(base.model.User, 'admin').all() recipients = [(u.fullname, u.email) for u in admins] if admins else [( config.get('ckan.admin.name', "CKAN Administrator"), config.get('ckan.admin.email', None), )] if not recipients: base.h.flash_error( toolkit._("There is a problem with the system " "configuration")) errors = {"reason": ["No group administrator exists"]} return self.apply(group.id, errors=errors, error_summary=action.error_summary(errors)) extra_vars = { 'group': group, 'requester': base.c.userobj, 'reason': reason } email_msg = base.render("email/join_publisher_request.txt", extra_vars=extra_vars, loader_class=NewTextTemplate) try: for (name, recipient) in recipients: mailer.mail_recipient(name, recipient, "Publisher request", email_msg) except: base.h.flash_error( toolkit._("There is a problem with the system " "configuration")) errors = {"reason": ["No mail server was found"]} return self.apply(group.id, errors=errors, error_summary=action.error_summary(errors)) base.h.flash_success(toolkit._("Your application has been submitted")) base.h.redirect_to('publisher_read', id=group.name)
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 create_feed(data_dict): """ Creates a new feed after validating the information provided, and then validates the data held at the specified URL is in fact a feed """ data, errors = df.validate(data_dict, fs.feed_schema()) if errors: raise logic.ValidationError(errors, action.error_summary(errors)) ok,format,content = util.validate_feed(data.get('url')) if not ok: raise feedmodels.FeedException(_("Unable to fetch feed")) feed = feedmodels.Feed( name = _generate_name(data.get('title')), title = data.get('title'), url = data.get('url'), format = format, updated = data.get('updated'), content = content, template = data.get('template'), html_entries = data.get('html_entries') ) feed.save() return feed
def _send_application( self, group, reason ): from genshi.template.text import NewTextTemplate 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=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('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=action.error_summary(errors)) extra_vars = { 'group' : group, 'requester': c.userobj, 'reason' : reason } email_msg = render("organizations/email/join_publisher_request.txt", extra_vars=extra_vars, loader_class=NewTextTemplate) try: for (name,recipient) in recipients: 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=action.error_summary(errors)) h.flash_success(_("Your application has been submitted")) h.redirect_to( 'publisher_read', 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.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))
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 _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)) recipients, recipient_organisation = find_group_admins(group) if not recipients: if not config.get('dgu.admin.email'): log.error( 'User "%s" prevented from applying for organisation access for "%s" ' 'because: dgu.admin.email is not setup in CKAN config.', c.user, group.name) h.flash_error( _("There is a problem with the system configuration")) errors = {"reason": ["data.gov.uk error"]} return self.apply(group.id, errors=errors, error_summary=error_summary(errors)) recipients = [(config.get('dgu.admin.name', "DGU Admin"), config['dgu.admin.email'])] recipient_organisation = 'data.gov.uk admin team' url = urljoin( g.site_url, h.url_for( controller= 'ckanext.dgu_orgs.controllers.organisation:OrganisationController', action='users', id=group.name)) log.debug( 'User "%s" requested organisation access for "%s" which was sent to admin %s (%r) with reason: %r', c.user, group.name, recipient_organisation, recipients, reason) extra_vars = { 'group': group, 'requester': c.userobj, 'reason': reason, 'accept_url': url } email_msg = render("email/join_publisher_request.txt", extra_vars=extra_vars, loader_class=NewTextTemplate) try: for (name, recipient) in recipients: mail_recipient( name, recipient, subject= 'DGUKOrganisationRequest: Please add me as a data.gov.uk organisation', body=email_msg) except Exception, e: h.flash_error( 'There is a problem with the system configuration. Please instead <a href="http://data.gov.uk/contact">contact the data.gov.uk team</a>', allow_html=True) errors = {"reason": ["data.gov.uk error"]} log.error( 'User "%s" prevented from applying for organisation access for "%s" because of mail configuration error: %s', c.user, group.name, e) return self.apply(group.id, errors=errors, error_summary=error_summary(errors))
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))