def wrapper(project_url, *args, **kwargs): if isinstance(project_url, pillarsdk.Resource): # This is already a resource, so this call probably is from one # view to another. Assume the caller knows what he's doing and # just pass everything along. return wrapped(project_url, *args, **kwargs) api = pillar_api() project = pillarsdk.Project.find_by_url( project_url, {'projection': projections}, api=api) is_flamenco = current_flamenco.is_flamenco_project(project) if not is_flamenco: return error_project_not_setup_for_flamenco() session['flamenco_last_project'] = project.to_dict() project_id = bson.ObjectId(project['_id']) auth = current_flamenco.auth if not auth.current_user_may(action, project_id): log.info('Denying user %s access %s to Flamenco on project %s', flask_login.current_user, action, project_id) return error_project_not_available() if extension_props: pprops = project.extension_props.flamenco return wrapped(project, pprops, *args, **kwargs) return wrapped(project, *args, **kwargs)
def wrapper(project_url, *args, **kwargs): if isinstance(project_url, pillarsdk.Resource): # This is already a resource, so this call probably is from one # view to another. Assume the caller knows what he's doing and # just pass everything along. return wrapped(project_url, *args, **kwargs) api = pillar_api() project = pillarsdk.Project.find_by_url( project_url, {'projection': projections}, api=api) is_flamenco = current_flamenco.is_flamenco_project(project) if not is_flamenco: return error_project_not_setup_for_flamenco(project) session['flamenco_last_project'] = project.to_dict() project_id = bson.ObjectId(project['_id']) auth = current_flamenco.auth if not auth.current_user_may(action, project_id): if current_user.is_anonymous: raise wz_exceptions.Forbidden('Login required for this URL') log.info('Denying user %s access %s to Flamenco on project %s', flask_login.current_user, action, project_id) return error_project_not_available() if extension_props: pprops = project.extension_props.flamenco return wrapped(project, pprops, *args, **kwargs) return wrapped(project, *args, **kwargs)
def project_settings(project: pillarsdk.Project, **template_args: dict): """Renders the project settings page for Flamenco projects.""" from pillar.api.utils import str2id from pillar.web.system_util import pillar_api from .managers.sdk import Manager if not current_flamenco.auth.current_user_is_flamenco_user(): raise wz_exceptions.Forbidden() # Based on the project state, we can render a different template. if not current_flamenco.is_flamenco_project(project): return render_template('flamenco/project_settings/offer_setup.html', project=project, **template_args) project_id = str2id(project['_id']) flauth = current_flamenco.auth may_use = flauth.current_user_may(flauth.Actions.USE, project_id) # Use the API for querying for Managers, because it implements access control. api = pillar_api() managers = Manager.all(api=api) linked_managers = Manager.all({ 'where': { 'projects': project['_id'], }, }, api=api) try: first_manager = managers['_items'][0] except (KeyError, IndexError): first_manager = None try: first_linked_manager = linked_managers['_items'][0] except (KeyError, IndexError): first_linked_manager = None return render_template('flamenco/project_settings/settings.html', project=project, managers=managers, first_manager=first_manager, linked_managers=linked_managers, first_linked_manager=first_linked_manager, may_use_flamenco=may_use, **template_args)
def wrapper(project_url, *args, **kwargs): if isinstance(project_url, pillarsdk.Resource): # This is already a resource, so this call probably is from one # view to another. Assume the caller knows what he's doing and # just pass everything along. return wrapped(project_url, *args, **kwargs) api = pillar_api() project = pillarsdk.Project.find_by_url( project_url, {'projection': projections}, api=api) is_flamenco = current_flamenco.is_flamenco_project( project, test_extension_props=extension_props) if not is_flamenco: return error_project_not_setup_for_flamenco() if extension_props: pprops = project.extension_props.flamenco return wrapped(project, pprops, *args, **kwargs) return wrapped(project, *args, **kwargs)