def __init__(self, wf_input, current_user): if wf_input['id'] in ('omics_url', 'omics_auth_token'): self.editable = False self.value = 'Set by Omics Dashboard' else: self.editable = True self.value = wf_input['default'] if 'default' in wf_input else '' self.id = wf_input['id'] if wf_input['type'].endswith('[]'): self.input_type = wf_input['type'][:-2] self.select_multiple = True else: self.input_type = wf_input['type'] self.select_multiple = False self.label = wf_input['label'] if 'label' in wf_input else wf_input[ 'id'] self.doc = wf_input['doc'] if 'doc' in wf_input else '' self.select_options = [] if wf_input['type'].startswith('File'): for collection in get_all_read_permitted_records( current_user, Collection): self.select_options.append( SelectOption( collection.filename, f'Collection {collection.id}: {collection.name}')) for external_file in get_all_read_permitted_records( current_user, ExternalFile): if external_file.file_exists(): self.select_options.append( SelectOption( external_file.filename, f'External File {external_file.id}: {external_file.name}' ))
def render_create_user_group(): try: current_user = get_current_user() if request.method == 'POST': data = { 'admin_ids': [int(val) for val in request.form.getlist('admin_ids')], 'member_ids': [int(val) for val in request.form.getlist('member_ids')], 'name': request.form.get('name'), 'description': request.form.get('description') } user_group = create_user_group(current_user, data) return redirect( url_for('user_groups.render_user_group', user_group_id=user_group.id)) if request.method == 'GET': selected_user_ids = {int(token) for token in request.args.get('sample_ids').strip('"').split(',')} \ if request.args.get('user_ids', '') else {} selected_users = get_all_read_permitted_records(current_user, User) return render_template('pages/create.html', page_data=UserGroupCreateFormData( current_user, selected_users)) except Exception as e: return handle_exception_browser(e)
def get_samples(user: User, filter_by: Dict[str, Any] = None) -> List[Sample]: """ Get the attributes and dataset paths of all the samples to which the user with user_id has read access :param user: :return: """ return get_all_read_permitted_records(user, Sample, filter_by)
def get_workflows(user: User, filter_by: Dict[str, Any] = None) -> List[Workflow]: """ Get a list of available saved workflows. :param user: :return: """ return get_all_read_permitted_records(user, Workflow, filter_by)
def get_all_collection_metadata(user: User) -> List[Dict[str, Any]]: """ Get the attributes of all collections a user is allowed to read. :param user: :return: """ return [get_collection_metadata(user, collection) for collection in get_all_read_permitted_records(user, Collection)]
def get_collections(user: User, filter_by: Dict[str, Any] = None) -> List[Collection]: """ Get the attributes and dataset information of all collections a user is allowed to read. :param user: :param filter_by: :return: """ return get_all_read_permitted_records(user, Collection, filter_by)
def get_sample_groups(user: User, filter_by: Dict[str, Any] = None) -> List[SampleGroup]: """ Get all sample groups visible to a user. :param user: :param filter_by: :return: """ return get_all_read_permitted_records(user, SampleGroup, filter_by)
def get_analyses(user: User, filter_by: Dict[str, Any] = None) -> List[Analysis]: """ Get all the analyses the user is allowed to view :param user: :param filter_by: :return: """ return get_all_read_permitted_records(user, Analysis, filter_by)
def get_external_files(user: User, filter_by: Dict[str, Any] = None) -> List[ExternalFile]: """ Get all the external files a user is permitted to read :param user: A user (usually the currently authenticated user) :param filter_by: :return: All the external files the user is permitted to read """ return get_all_read_permitted_records(user, ExternalFile, filter_by)
def get_all_sample_metadata(user: User) -> List[Dict]: """ Get the attributes of all the samples to which the user with user_id has read access :param user: :return: """ return [ get_sample_metadata(user, sample) for sample in get_all_read_permitted_records(user, Sample) ]
def get_attached_analyses(user: User, collection: Collection) -> List[Analysis]: """ Get all analysis that a collection belongs to :param user: :param collection: :return: """ if is_read_permitted(user, collection): return get_all_read_permitted_records(user, collection.analyses) raise AuthException( f'User {user.email} not permitted to access collection {collection.id}' )
def get_user_groups(user: User, filter_by: Dict[str, Any] = None) -> List[UserGroup]: """ Get a list of all user groups readable by user. :return: """ return get_all_read_permitted_records(user, UserGroup, filter_by)