def index(): api = pillar_api() # FIXME Sybren: add permission check. # TODO: add projections. projects = current_flamenco.flamenco_projects() for project in projects['_items']: attach_project_pictures(project, api) projs_with_summaries = [ (proj, current_flamenco.job_manager.job_status_summary(proj['_id'])) for proj in projects['_items'] ] last_project = session.get('flamenco_last_project') if last_project: project = Project(last_project) navigation_links = project_navigation_links(project, pillar_api()) extension_sidebar_links = current_app.extension_sidebar_links(project) else: project = None navigation_links = [] extension_sidebar_links = [] return render_template('flamenco/index.html', projs_with_summaries=projs_with_summaries, project=project, navigation_links=navigation_links, extension_sidebar_links=extension_sidebar_links)
def comments_for_node(node_id): """Shows the comments attached to the given node.""" api = system_util.pillar_api() node = Node.find(node_id, api=api) project = Project({'_id': node.project}) can_post_comments = project.node_type_has_method('comment', 'POST', api=api) can_comment_override = request.args.get('can_comment', 'True') == 'True' can_post_comments = can_post_comments and can_comment_override # Query for all children, i.e. comments on the node. comments = Node.all( { 'where': { 'node_type': 'comment', 'parent': node_id }, }, api=api) def enrich(some_comment): some_comment['_user'] = subquery.get_user_info(some_comment['user']) some_comment['_is_own'] = some_comment['user'] == current_user.objectid some_comment['_current_user_rating'] = None # tri-state boolean some_comment[ '_rating'] = some_comment.properties.rating_positive - some_comment.properties.rating_negative if current_user.is_authenticated: for rating in some_comment.properties.ratings or (): if rating.user != current_user.objectid: continue some_comment['_current_user_rating'] = rating.is_positive for comment in comments['_items']: # Query for all grandchildren, i.e. replies to comments on the node. comment['_replies'] = Node.all( { 'where': { 'node_type': 'comment', 'parent': comment['_id'] }, }, api=api) enrich(comment) for reply in comment['_replies']['_items']: enrich(reply) nr_of_comments = sum(1 + comment['_replies']['_meta']['total'] for comment in comments['_items']) return render_template('nodes/custom/comment/list_embed.html', node_id=node_id, comments=comments, nr_of_comments=nr_of_comments, show_comments=True, can_post_comments=can_post_comments)
def comments_for_node(node_id): """Shows the comments attached to the given node. The URL can be overridden in order to define can_post_comments in a different way """ api = system_util.pillar_api() node = Node.find(node_id, api=api) project = Project({'_id': node.project}) can_post_comments = project.node_type_has_method('comment', 'POST', api=api) can_comment_override = request.args.get('can_comment', 'True') == 'True' can_post_comments = can_post_comments and can_comment_override return render_comments_for_node(node_id, can_post_comments=can_post_comments)
def create(): """Create a new project. This is a multi step operation that involves: - initialize basic node types - initialize basic permissions - create and connect storage space """ api = system_util.pillar_api() project_properties = dict(name='My project', user=current_user.objectid, category='assets', status='pending') project = Project(project_properties) project.create(api=api) return redirect( url_for('projects.edit', project_url="p-{}".format(project['_id'])))
def commentform_for_node(node_id): """Shows only the comment for for comments attached to the given node. i.e. does not show the comments themselves, just the form to post a new comment. """ api = system_util.pillar_api() node = Node.find(node_id, api=api) project = Project({'_id': node.project}) can_post_comments = project.node_type_has_method('comment', 'POST', api=api) return render_template('nodes/custom/comment/list_embed.html', node_id=node_id, show_comments=False, can_post_comments=can_post_comments)
def index(manager_id: str = None): api = pillar_api() if current_user.is_authenticated: params = {'where': {'owner': {'$in': current_user.groups}}} else: params = None managers = Manager.all(params=params, api=api) if not manager_id and managers['_items']: manager_id = managers['_items'][0]._id manager_limit_reached = managers['_meta'][ 'total'] >= flamenco.auth.MAX_MANAGERS_PER_USER # TODO Sybren: move this to a utility function + check on endpoint to create manager may_use_flamenco = current_user.has_cap('flamenco-use') can_create_manager = may_use_flamenco and (not manager_limit_reached or current_user.has_cap('admin')) if session.get('flamenco_last_project'): project = Project(session.get('flamenco_last_project')) navigation_links = project_navigation_links(project, pillar_api()) extension_sidebar_links = current_app.extension_sidebar_links(project) else: project = None navigation_links = [] extension_sidebar_links = [] return render_template('flamenco/managers/index.html', manager_limit_reached=manager_limit_reached, may_use_flamenco=may_use_flamenco, can_create_manager=can_create_manager, max_managers=flamenco.auth.MAX_MANAGERS_PER_USER, managers=managers, open_manager_id=manager_id, project=project, navigation_links=navigation_links, extension_sidebar_links=extension_sidebar_links)