def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None, user_name=None, **kw): """ Import a GitHub repo into a new Git Allura tool. """ project_name = "%s/%s" % (user_name, project_name) extractor = GitHubProjectExtractor(project_name, user=user) repo_url = extractor.get_repo_url() app = project.install_app( "Git", mount_point=mount_point or 'code', mount_label=mount_label or 'Code', init_from_url=repo_url, import_id={ 'source': self.source, 'project_name': project_name, } ) M.AuditLog.log( 'import tool %s from %s on %s' % ( app.config.options.mount_point, project_name, self.source, ), project=project, user=user, url=app.url) g.post_event('project_updated') return app
def success(self, app): with h.push_config(c, project=self.project, app=app): g.post_event( 'import_tool_task_succeeded', self.importer.source, self.importer.tool_label, )
def import_project_info(project_name): extractor = GoogleCodeProjectExtractor(project_name, 'project_info') extractor.get_short_description(c.project) extractor.get_icon(c.project) extractor.get_license(c.project) ThreadLocalORMSession.flush_all() g.post_event('project_updated')
def edit_screenshot(self, id=None, caption=None, **kw): require_access(c.project, 'update') if id is not None and id != '': M.ProjectFile.query.get(project_id=c.project._id, _id=ObjectId(id)).caption = caption g.post_event('project_updated') redirect('screenshots')
def _update_mounts(self, subproject=None, tool=None, new=None, **kw): if subproject is None: subproject = [] if tool is None: tool = [] for sp in subproject: p = M.Project.query.get(shortname=sp['shortname'], neighborhood_id=c.project.neighborhood_id) if sp.get('delete'): require_access(c.project, 'admin') M.AuditLog.log('delete subproject %s', sp['shortname']) h.log_action(log, 'delete subproject').info( 'delete subproject %s', sp['shortname'], meta=dict(name=sp['shortname'])) p.removal = 'deleted' plugin.ProjectRegistrationProvider.get().delete_project( p, c.user) elif not new: M.AuditLog.log('update subproject %s', sp['shortname']) p.name = sp['name'] p.ordinal = int(sp['ordinal']) for p in tool: if p.get('delete'): require_access(c.project, 'admin') M.AuditLog.log('uninstall tool %s', p['mount_point']) h.log_action(log, 'uninstall tool').info( 'uninstall tool %s', p['mount_point'], meta=dict(mount_point=p['mount_point'])) c.project.uninstall_app(p['mount_point']) elif not new: M.AuditLog.log('update tool %s', p['mount_point']) options = c.project.app_config(p['mount_point']).options options.mount_label = p['mount_label'] options.ordinal = int(p['ordinal']) if new and new.get('install'): ep_name = new.get('ep_name', None) if not ep_name: require_access(c.project, 'create') mount_point = new['mount_point'].lower() or h.nonce() M.AuditLog.log('create subproject %s', mount_point) h.log_action(log, 'create subproject').info( 'create subproject %s', mount_point, meta=dict(mount_point=mount_point, name=new['mount_label'])) sp = c.project.new_subproject(mount_point) sp.name = new['mount_label'] sp.ordinal = int(new['ordinal']) else: require_access(c.project, 'admin') installable_tools = AdminApp.installable_tools_for(c.project) if not ep_name.lower() in [t['name'].lower() for t in installable_tools]: flash('Installation limit exceeded.', 'error') return mount_point = new['mount_point'] or ep_name M.AuditLog.log('install tool %s', mount_point) h.log_action(log, 'install tool').info( 'install tool %s', mount_point, meta=dict(tool_type=ep_name, mount_point=mount_point, mount_label=new['mount_label'])) c.project.install_app( ep_name, mount_point, mount_label=new['mount_label'], ordinal=new['ordinal']) g.post_event('project_updated')
def edit_screenshot(self, id=None, caption=None, **kw): require_access(c.project, 'update') if id is not None and id != '': M.ProjectFile.query.get( project_id=c.project._id, _id=ObjectId(id)).caption = caption g.post_event('project_updated') redirect('screenshots')
def delete_screenshot(self, id=None, **kw): require_access(c.project, 'update') if id is not None and id != '': M.AuditLog.log('remove screenshot') M.ProjectFile.query.remove(dict(project_id=c.project._id, _id=ObjectId(id))) g.post_event('project_updated') redirect('screenshots')
def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None, **kw): """ Import a Google Code repo into a new SVN, Git, or Hg Allura tool. """ extractor = GoogleCodeProjectExtractor(project_name, 'source_browse') repo_type = extractor.get_repo_type() repo_url = get_repo_url(project_name, repo_type) app = project.install_app(REPO_ENTRY_POINTS[repo_type], mount_point=mount_point or 'code', mount_label=mount_label or 'Code', init_from_url=repo_url, import_id={ 'source': self.source, 'project_name': project_name, }) M.AuditLog.log('import tool %s from %s on %s' % ( app.config.options.mount_point, project_name, self.source, ), project=project, user=user, url=app.url) g.post_event('project_updated') return app
def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None, **kw): """ Import a Google Code repo into a new SVN, Git, or Hg Allura tool. """ extractor = GoogleCodeProjectExtractor(project_name, 'source_browse') repo_type = extractor.get_repo_type() repo_url = get_repo_url(project_name, repo_type) app = project.install_app( REPO_ENTRY_POINTS[repo_type], mount_point=mount_point or 'code', mount_label=mount_label or 'Code', init_from_url=repo_url, import_id={ 'source': self.source, 'project_name': project_name, } ) M.AuditLog.log( 'import tool %s from %s on %s' % ( app.config.options.mount_point, project_name, self.source, ), project=project, user=user, url=app.url) g.post_event('project_updated') return app
def update(self, card=None, **kw): permissions = self._index_permissions() old_permissions = dict(permissions) for args in card: perm = args['id'] new_group_ids = args.get('new', []) group_ids = args.get('value', []) if isinstance(new_group_ids, basestring): new_group_ids = [ new_group_ids ] if isinstance(group_ids, basestring): group_ids = [ group_ids ] # make sure the admin group has the admin permission if perm == 'admin': if c.project.is_root: pid = c.project._id else: pid = c.project.parent_id admin_group_id = str(M.ProjectRole.query.get(project_id=pid, name='Admin')._id) if admin_group_id not in group_ids + new_group_ids: flash('You cannot remove the admin group from the admin permission.','warning') group_ids.append(admin_group_id) permissions[perm] = [] role_ids = map(ObjectId, group_ids + new_group_ids) permissions[perm] = role_ids c.project.acl = [] for perm, role_ids in permissions.iteritems(): role_names = lambda ids: ','.join(sorted( pr.name for pr in M.ProjectRole.query.find(dict(_id={'$in':ids})))) old_role_ids = old_permissions.get(perm, []) if old_role_ids != role_ids: M.AuditLog.log('updated "%s" permissions: "%s" => "%s"', perm,role_names(old_role_ids), role_names(role_ids)) c.project.acl += [M.ACE.allow(rid, perm) for rid in role_ids] g.post_event('project_updated') redirect('.')
def import_tool( self, project, user, project_name=None, mount_point=None, mount_label=None, user_name=None, tool_option=None, **kw): """ Import a GitHub wiki into a new Wiki Allura tool. """ project_name = "%s/%s" % (user_name, project_name) extractor = GitHubProjectExtractor(project_name, user=user) wiki_avail = extractor.has_wiki() if not wiki_avail: return self.github_wiki_url = extractor.get_page_url( 'wiki_url').replace('.wiki', '/wiki') self.app = project.install_app( "Wiki", mount_point=mount_point or 'wiki', mount_label=mount_label or 'Wiki', import_id={ 'source': self.source, 'project_name': project_name, } ) with_history = tool_option == 'import_history' ThreadLocalORMSession.flush_all() self.github_markdown_converter = GitHubMarkdownConverter( user_name, project_name) try: M.session.artifact_orm_session._get().skip_mod_date = True with h.push_config(c, app=self.app): try: wiki_url = extractor.get_page_url('wiki_url') self.import_pages(wiki_url, history=with_history) except git.GitCommandError: log.error( 'Unable to clone GitHub wiki: ' 'wiki_url=%s; ' 'wiki_avail=%s; ' 'avail_url=%s', wiki_url, wiki_avail, extractor.get_page_url('project_info'), exc_info=True) raise ThreadLocalORMSession.flush_all() M.AuditLog.log( 'import tool %s from %s on %s' % ( self.app.config.options.mount_point, project_name, self.source), project=project, user=user, url=self.app.url) g.post_event('project_updated') return self.app except Exception: h.make_app_admin_only(self.app) raise finally: M.session.artifact_orm_session._get().skip_mod_date = False
def create(self, name=None, **kw): if M.ProjectRole.by_name(name): flash('%s already exists' % name, 'error') else: M.ProjectRole(project_id=c.project._id, name=name) M.AuditLog.log('create group %s', name) g.post_event('project_updated') redirect('.')
def update_label(self, mount_label): """Handles POST to update the Application's ``mount_label``. """ require_access(self.app, 'configure') self.app.config.options['mount_label'] = mount_label g.post_event('project_menu_updated') redirect(request.referer)
def update_label(self, mount_label): """Handles POST to update the Application's ``mount_label``. """ require_access(self.app, "configure") self.app.config.options["mount_label"] = mount_label g.post_event("project_menu_updated") redirect(request.referer)
def import_tool(self, project, user, project_name, mount_point=None, mount_label=None, **kw): import_id_converter = ImportIdConverter.get() app = project.install_app( 'tickets', mount_point, mount_label, EnableVoting=True, open_status_names='New Accepted Started', closed_status_names='Fixed Verified Invalid Duplicate WontFix Done', import_id={ 'source': self.source, 'project_name': project_name, }, ) ThreadLocalORMSession.flush_all() try: M.session.artifact_orm_session._get().skip_mod_date = True with h.push_config(c, user=M.User.anonymous(), app=app): for ticket_num, issue in GoogleCodeProjectExtractor.iter_issues( project_name): self.max_ticket_num = max(ticket_num, self.max_ticket_num) ticket = TM.Ticket(app_config_id=app.config._id, custom_fields=dict(), ticket_num=ticket_num, import_id=import_id_converter.expand( ticket_num, app)) self.process_fields(ticket, issue) self.process_labels(ticket, issue) self.process_comments(ticket, issue) session(ticket).flush(ticket) session(ticket).expunge(ticket) app.globals.custom_fields = self.postprocess_custom_fields() app.globals.last_ticket_num = self.max_ticket_num ThreadLocalORMSession.flush_all() M.AuditLog.log( 'import tool %s from %s on %s' % ( app.config.options.mount_point, project_name, self.source, ), project=project, user=user, url=app.url, ) g.post_event('project_updated') app.globals.invalidate_bin_counts() return app except Exception as e: h.make_app_admin_only(app) raise finally: M.session.artifact_orm_session._get().skip_mod_date = False
def import_project_info(project_name): from forgeimporters.github.project import GitHubProjectImporter importer = GitHubProjectImporter(None) with ImportErrorHandler(importer, project_name, c.project) as handler: extractor = GitHubProjectExtractor(project_name, user=c.user) c.project.summary = extractor.get_summary() c.project.external_homepage = extractor.get_homepage() ThreadLocalORMSession.flush_all() g.post_event('project_updated')
def init_as_clone(self, source_path, source_name, source_url): self.upstream_repo.name = source_name self.upstream_repo.url = source_url session(self).flush(self) source = source_path if source_path else source_url self._impl.clone_from(source) log.info('... %r cloned', self) g.post_event('repo_cloned', source_url, source_path) self.refresh(notify=False, new_clone=True)
def delete_group(self, group_name, **kw): role = M.ProjectRole.by_name(group_name) if not role: flash('Group "%s" does not exist.' % group_name, 'error') else: role.delete() M.AuditLog.log('delete group %s', group_name) flash('Group "%s" deleted successfully.' % group_name) g.post_event('project_updated') redirect('.')
def __exit__(self, exc_type, exc_val, exc_tb): self.importer.clear_pending(self.project) if exc_type: g.post_event('import_tool_task_failed', error=str(exc_val), traceback=traceback.format_exc(), importer_source=self.importer.source, importer_tool_label=self.importer.tool_label, project_name=self.project_name, )
def delete_trove(self, type, trove, **kw): require_access(c.project, 'update') trove_obj = M.TroveCategory.query.get(trove_cat_id=int(trove)) current_troves = getattr(c.project,'trove_%s'%type) if trove_obj is not None and trove_obj._id in current_troves: M.AuditLog.log('remove trove %s: %s', type, trove_obj.fullpath) current_troves.remove(trove_obj._id) ThreadLocalORMSession.flush_all() # just in case the event handling is super fast g.post_event('project_updated') redirect('trove')
def import_project_info(project_name): from forgeimporters.google.project import GoogleCodeProjectImporter importer = GoogleCodeProjectImporter(None) with ImportErrorHandler(importer, project_name, c.project) as handler: extractor = GoogleCodeProjectExtractor(project_name, 'project_info') extractor.get_short_description(c.project) extractor.get_icon(c.project) extractor.get_license(c.project) ThreadLocalORMSession.flush_all() g.post_event('project_updated')
def delete(self): require_access(self.neighborhood, 'admin') if self.award: grants = M.AwardGrant.query.find(dict(award_id=self.award._id)) for grant in grants: grant.delete() with h.push_context(grant.granted_to_project_id): g.post_event('project_updated') M.AwardFile.query.remove(dict(award_id=self.award._id)) self.award.delete() redirect(request.referer)
def __exit__(self, exc_type, exc_val, exc_tb): if hasattr(self.importer, 'clear_pending'): self.importer.clear_pending(self.project) if exc_type: g.post_event('import_tool_task_failed', error=str(exc_val), traceback=traceback.format_exc(), importer_source=self.importer.source, importer_tool_label=self.importer.tool_label, project_name=self.project_name, )
def change_perm(self, role_id, permission, allow="true", **kw): if allow=="true": M.AuditLog.log('granted permission %s to group %s', permission, M.ProjectRole.query.get(_id=ObjectId(role_id)).name) c.project.acl.append(M.ACE.allow(ObjectId(role_id), permission)) else: admin_group_id = str(M.ProjectRole.by_name('Admin')._id) if admin_group_id == role_id and permission == 'admin': return dict(error='You cannot remove the admin permission from the admin group.') M.AuditLog.log('revoked permission %s from group %s', permission, M.ProjectRole.query.get(_id=ObjectId(role_id)).name) c.project.acl.remove(M.ACE.allow(ObjectId(role_id), permission)) g.post_event('project_updated') return self._map_group_permissions()
def sort_screenshots(self, **kw): """Sort project screenshots. Called via ajax when screenshots are reordered via drag/drop on the Screenshots admin page. ``kw`` is a mapping of (screenshot._id, sort_order) pairs. """ for s in c.project.get_screenshots(): if str(s._id) in kw: s.sort = int(kw[str(s._id)]) g.post_event('project_updated')
def clone(cloned_from_path, cloned_from_name, cloned_from_url): from allura import model as M try: c.app.repo.init_as_clone( cloned_from_path, cloned_from_name, cloned_from_url) M.Notification.post_user( c.user, c.app.repo, 'created', text='Repository %s/%s created' % ( c.project.shortname, c.app.config.options.mount_point)) except Exception, e: g.post_event('repo_clone_task_failed', cloned_from_url, cloned_from_path, traceback.format_exc())
def clone(cloned_from_path, cloned_from_name, cloned_from_url): from allura import model as M try: c.app.repo.init_as_clone(cloned_from_path, cloned_from_name, cloned_from_url) M.Notification.post_user( c.user, c.app.repo, "created", text="Repository %s/%s created" % (c.project.shortname, c.app.config.options.mount_point), ) except Exception, e: g.post_event("repo_clone_task_failed", cloned_from_url, cloned_from_path, traceback.format_exc())
def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None, trac_url=None, user_map=None, **kw): """ Import Trac tickets into a new Allura Tracker tool. """ mount_point = mount_point or 'tickets' app = project.install_app( 'Tickets', mount_point=mount_point, mount_label=mount_label or 'Tickets', open_status_names='new assigned accepted reopened', closed_status_names='closed', import_id={ 'source': self.source, 'trac_url': trac_url, }, ) session(app.config).flush(app.config) session(app.globals).flush(app.globals) try: with h.push_config(c, app=app): TracImportSupport().perform_import( json.dumps(export(trac_url), cls=DateJSONEncoder), json.dumps({ 'user_map': json.loads(user_map) if user_map else {}, 'usernames_match': self.usernames_match(trac_url), }), ) AuditLog.log( 'import tool %s from %s' % ( app.config.options.mount_point, trac_url, ), project=project, user=user, url=app.url, ) g.post_event('project_updated') return app except Exception: h.make_app_admin_only(app) raise
def add_screenshot(self, screenshot=None, caption=None, **kw): require_access(c.project, 'update') if len(c.project.get_screenshots()) >= 6: flash('You may not have more than 6 screenshots per project.','error') elif screenshot is not None and screenshot != '': M.AuditLog.log('add screenshot') M.ProjectFile.save_image( screenshot.filename, screenshot.file, content_type=screenshot.type, save_original=True, original_meta=dict(project_id=c.project._id,category='screenshot',caption=caption), square=True, thumbnail_size=(150,150), thumbnail_meta=dict(project_id=c.project._id,category='screenshot_thumb')) g.post_event('project_updated') redirect('screenshots')
def import_tool(self, project, user, project_name, mount_point=None, mount_label=None, **kw): import_id_converter = ImportIdConverter.get() project_name = '%s/%s' % (kw['user_name'], project_name) extractor = GitHubProjectExtractor(project_name, user=user) if not extractor.has_tracker(): return app = project.install_app('tickets', mount_point, mount_label, EnableVoting=False, open_status_names='open', closed_status_names='closed', import_id={ 'source': self.source, 'project_name': project_name, } ) self.github_markdown_converter = GitHubMarkdownConverter( kw['user_name'], project_name) ThreadLocalORMSession.flush_all() try: M.session.artifact_orm_session._get().skip_mod_date = True with h.push_config(c, user=M.User.anonymous(), app=app): for ticket_num, issue in extractor.iter_issues(): self.max_ticket_num = max(ticket_num, self.max_ticket_num) ticket = TM.Ticket( app_config_id=app.config._id, custom_fields=dict(), ticket_num=ticket_num, import_id=import_id_converter.expand(ticket_num, app) ) self.process_fields(extractor, ticket, issue) self.process_comments(extractor, ticket, issue) self.process_events(extractor, ticket, issue) self.process_milestones(ticket, issue) session(ticket).flush(ticket) session(ticket).expunge(ticket) app.globals.custom_fields = self.postprocess_milestones() app.globals.last_ticket_num = self.max_ticket_num ThreadLocalORMSession.flush_all() M.AuditLog.log( 'import tool %s from %s on %s' % ( app.config.options.mount_point, project_name, self.source), project=project, user=user, url=app.url) g.post_event('project_updated') app.globals.invalidate_bin_counts() return app finally: M.session.artifact_orm_session._get().skip_mod_date = False
def remove_user(self, role_id, username, **kw): group = M.ProjectRole.query.get(_id=ObjectId(role_id)) user = M.User.by_username(username.strip()) if group.name == 'Admin' and len(group.users_with_role()) == 1: return dict(error='You must have at least one user with the Admin role.') if not group: return dict(error='Could not find group with id %s' % role_id) if not user: return dict(error='User %s not found' % username) if group._id not in user.project_role().roles: return dict(error='%s (%s) is not in the group %s.' % (user.display_name, username, group.name)) M.AuditLog.log('remove user %s from %s', username, group.name) user.project_role().roles.remove(group._id) g.post_event('project_updated') return dict()
def reclone_repo(*args, **kwargs): from allura import model as M try: nbhd = M.Neighborhood.query.get(url_prefix='/%s/' % kwargs['prefix']) c.project = M.Project.query.get(shortname=kwargs['shortname'], neighborhood_id=nbhd._id) c.app = c.project.app_instance(kwargs['mount_point']) source_url = c.app.config.options.get('init_from_url') source_path = c.app.config.options.get('init_from_path') c.app.repo.init_as_clone(source_path, None, source_url) M.Notification.post_user( c.user, c.app.repo, 'created', text='Repository %s/%s created' % ( c.project.shortname, c.app.config.options.mount_point)) except Exception, e: g.post_event('repo_clone_task_failed', source_url, source_path, traceback.format_exc())
def import_tool(self, project, user, project_name, mount_point=None, mount_label=None, **kw): import_id_converter = ImportIdConverter.get() app = project.install_app('tickets', mount_point, mount_label, EnableVoting=True, open_status_names='New Accepted Started', closed_status_names='Fixed Verified Invalid Duplicate WontFix Done', import_id={ 'source': self.source, 'project_name': project_name, }, ) ThreadLocalORMSession.flush_all() try: M.session.artifact_orm_session._get().skip_mod_date = True with h.push_config(c, user=M.User.anonymous(), app=app): for ticket_num, issue in GoogleCodeProjectExtractor.iter_issues(project_name): self.max_ticket_num = max(ticket_num, self.max_ticket_num) ticket = TM.Ticket( app_config_id=app.config._id, custom_fields=dict(), ticket_num=ticket_num, import_id=import_id_converter.expand(ticket_num, app)) self.process_fields(ticket, issue) self.process_labels(ticket, issue) self.process_comments(ticket, issue) session(ticket).flush(ticket) session(ticket).expunge(ticket) app.globals.custom_fields = self.postprocess_custom_fields() app.globals.last_ticket_num = self.max_ticket_num ThreadLocalORMSession.flush_all() M.AuditLog.log( 'import tool %s from %s on %s' % ( app.config.options.mount_point, project_name, self.source, ), project=project, user=user, url=app.url, ) g.post_event('project_updated') app.globals.invalidate_bin_counts() return app except Exception: h.make_app_admin_only(app) raise finally: M.session.artifact_orm_session._get().skip_mod_date = False
def update(self, icon=None, short=None, full=None): require_access(self.neighborhood, 'admin') self.award.short = short self.award.full = full if hasattr(icon, 'filename'): if self.award.icon: self.award.icon.delete() M.AwardFile.save_image( icon.filename, icon.file, content_type=icon.type, square=True, thumbnail_size=(48, 48), thumbnail_meta=dict(award_id=self.award._id)) for grant in M.AwardGrant.query.find(dict(award_id=self.award._id)): with h.push_context(grant.granted_to_project_id): g.post_event('project_updated') flash('Award updated.') redirect(self.award.longurl())
def grant(self, grant=None, recipient=None): require_access(self.neighborhood, 'admin') grant_q = M.Award.query.find(dict(short=grant, created_by_neighborhood_id=self.neighborhood._id)).first() recipient_q = M.Project.query.find(dict( neighborhood_id=self.neighborhood._id, shortname=recipient, deleted=False)).first() if grant_q and recipient_q: app_config_id = ObjectId() award = M.AwardGrant(app_config_id=app_config_id) award.award_id = grant_q._id award.granted_to_project_id = recipient_q._id award.granted_by_neighborhood_id = self.neighborhood._id with h.push_context(recipient_q._id): g.post_event('project_updated') redirect(request.referer)
def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None, user_name=None, tool_option=None, **kw): """ Import a GitHub wiki into a new Wiki Allura tool. """ project_name = "%s/%s" % (user_name, project_name) extractor = GitHubProjectExtractor(project_name) if not extractor.has_wiki(): return self.github_wiki_url = extractor.get_page_url('wiki_url').replace( '.wiki', '/wiki') self.app = project.install_app("Wiki", mount_point=mount_point or 'wiki', mount_label=mount_label or 'Wiki', import_id={ 'source': self.source, 'project_name': project_name, }) with_history = tool_option == 'import_history' ThreadLocalORMSession.flush_all() try: M.session.artifact_orm_session._get().skip_mod_date = True with h.push_config(c, app=self.app): self.import_pages(extractor.get_page_url('wiki_url'), history=with_history) ThreadLocalORMSession.flush_all() M.AuditLog.log('import tool %s from %s on %s' % (self.app.config.options.mount_point, project_name, self.source), project=project, user=user, url=self.app.url) g.post_event('project_updated') return self.app except Exception as e: h.make_app_admin_only(self.app) raise finally: M.session.artifact_orm_session._get().skip_mod_date = False
def import_tool( self, project, user, project_name=None, mount_point=None, mount_label=None, user_name=None, tool_option=None, **kw ): """ Import a GitHub wiki into a new Wiki Allura tool. """ project_name = "%s/%s" % (user_name, project_name) extractor = GitHubProjectExtractor(project_name, user=user) if not extractor.has_wiki(): return self.github_wiki_url = extractor.get_page_url("wiki_url").replace(".wiki", "/wiki") self.app = project.install_app( "Wiki", mount_point=mount_point or "wiki", mount_label=mount_label or "Wiki", import_id={"source": self.source, "project_name": project_name}, ) with_history = tool_option == "import_history" ThreadLocalORMSession.flush_all() self.github_markdown_converter = GitHubMarkdownConverter(user_name, project_name) try: M.session.artifact_orm_session._get().skip_mod_date = True with h.push_config(c, app=self.app): self.import_pages(extractor.get_page_url("wiki_url"), history=with_history) ThreadLocalORMSession.flush_all() M.AuditLog.log( "import tool %s from %s on %s" % (self.app.config.options.mount_point, project_name, self.source), project=project, user=user, url=self.app.url, ) g.post_event("project_updated") return self.app except Exception as e: h.make_app_admin_only(self.app) raise finally: M.session.artifact_orm_session._get().skip_mod_date = False
def _add_trove(self, type, new_trove): current_troves = getattr(c.project,'trove_%s'%type) trove_obj = M.TroveCategory.query.get(trove_cat_id=int(new_trove)) error_msg = None if type in ['license','audience','developmentstatus','language'] and len(current_troves) >= 6: error_msg = 'You may not have more than 6 of this category.' elif type in ['topic'] and len(current_troves) >= 3: error_msg = 'You may not have more than 3 of this category.' elif trove_obj is not None: if trove_obj._id not in current_troves: current_troves.append(trove_obj._id) M.AuditLog.log('add trove %s: %s', type, trove_obj.fullpath) ThreadLocalORMSession.flush_all() # just in case the event handling is super fast g.post_event('project_updated') else: error_msg = 'This category has already been assigned to the project.' return (trove_obj, error_msg)
def grant(self, grant=None, recipient=None): require_access(self.neighborhood, 'admin') grant_q = M.Award.query.find( dict(short=grant, created_by_neighborhood_id=self.neighborhood._id)).first() recipient_q = M.Project.query.find( dict(neighborhood_id=self.neighborhood._id, shortname=recipient, deleted=False)).first() if grant_q and recipient_q: app_config_id = ObjectId() award = M.AwardGrant(app_config_id=app_config_id) award.award_id = grant_q._id award.granted_to_project_id = recipient_q._id award.granted_by_neighborhood_id = self.neighborhood._id with h.push_context(recipient_q._id): g.post_event('project_updated') redirect(request.referer)
def add_user(self, role_id, username, **kw): if not username or username=='*anonymous': return dict(error='You must choose a user to add.') group = M.ProjectRole.query.get(_id=ObjectId(role_id)) user = M.User.by_username(username.strip()) if not group: return dict(error='Could not find group with id %s' % role_id) if not user: return dict(error='User %s not found' % username) if group._id in user.project_role().roles: return dict(error='%s (%s) is already in the group %s.' % (user.display_name, username, group.name)) M.AuditLog.log('add user %s to %s', username, group.name) user.project_role().roles.append(group._id) if group.name == 'Admin': for ac in c.project.app_configs: c.project.app_instance(ac).subscribe(user) g.post_event('project_updated') return dict(username=username, displayname=user.display_name)