1 class ApplicationController < ActionController::Base
2 include ArvadosApiClientHelper
3 include ApplicationHelper
5 respond_to :html, :json, :js
8 ERROR_ACTIONS = [:render_error, :render_not_found]
10 around_filter :thread_clear
11 before_filter :permit_anonymous_browsing_for_public_data
12 around_filter :set_thread_api_token
13 # Methods that don't require login should
14 # skip_around_filter :require_thread_api_token
15 around_filter :require_thread_api_token, except: ERROR_ACTIONS
16 before_filter :set_cache_buster
17 before_filter :accept_uuid_as_id_param, except: ERROR_ACTIONS
18 before_filter :check_user_agreements, except: ERROR_ACTIONS
19 before_filter :check_user_profile, except: ERROR_ACTIONS
20 before_filter :load_filters_and_paging_params, except: ERROR_ACTIONS
21 before_filter :find_object_by_uuid, except: [:create, :index, :choose] + ERROR_ACTIONS
25 rescue_from(ActiveRecord::RecordNotFound,
26 ActionController::RoutingError,
27 ActionController::UnknownController,
28 AbstractController::ActionNotFound,
29 with: :render_not_found)
30 rescue_from(Exception,
31 ActionController::UrlGenerationError,
32 with: :render_exception)
36 response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
37 response.headers["Pragma"] = "no-cache"
38 response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
41 def unprocessable(message=nil)
44 @errors << message if message
45 render_error status: 422
48 def render_error(opts={})
49 # Helpers can rely on the presence of @errors to know they're
50 # being used in an error page.
54 # json must come before html here, so it gets used as the
55 # default format when js is requested by the client. This lets
56 # ajax:error callback parse the response correctly, even though
58 f.json { render opts.merge(json: {success: false, errors: @errors}) }
59 f.html { render({action: 'error'}.merge(opts)) }
63 def render_exception(e)
64 logger.error e.inspect
65 logger.error e.backtrace.collect { |x| x + "\n" }.join('') if e.backtrace
66 err_opts = {status: 422}
67 if e.is_a?(ArvadosApiClient::ApiError)
68 err_opts.merge!(action: 'api_error', locals: {api_error: e})
69 @errors = e.api_response[:errors]
70 elsif @object.andand.errors.andand.full_messages.andand.any?
71 @errors = @object.errors.full_messages
75 # Make user information available on the error page, falling back to the
76 # session cache if the API server is unavailable.
78 load_api_token(session[:arvados_api_token])
79 rescue ArvadosApiClient::ApiError
80 unless session[:user].nil?
82 Thread.current[:user] = User.new(session[:user])
83 rescue ArvadosApiClient::ApiError
84 # This can happen if User's columns are unavailable. Nothing to do.
88 # Preload projects trees for the template. If that's not doable, set empty
89 # trees so error page rendering can proceed. (It's easier to rescue the
90 # exception here than in a template.)
91 unless current_user.nil?
94 rescue ArvadosApiClient::ApiError
95 # Fall back to the default-setting code later.
98 @my_project_tree ||= []
99 @shared_project_tree ||= []
100 render_error(err_opts)
103 def render_not_found(e=ActionController::RoutingError.new("Path not found"))
104 logger.error e.inspect
105 @errors = ["Path not found"]
106 set_thread_api_token do
107 self.render_error(action: '404', status: 404)
113 # The order can be left empty to allow it to default.
114 # Or it can be a comma separated list of real database column names, one per model.
115 # Column names should always be qualified by a table name and a direction is optional, defaulting to asc
116 # (e.g. "collections.name" or "collections.name desc").
117 # If a column name is specified, that table will be sorted by that column.
118 # If there are objects from different models that will be shown (such as in Jobs and Pipelines tab),
119 # then a sort column name can optionally be specified for each model, passed as an comma-separated list (e.g. "jobs.script, pipeline_instances.name")
120 # Currently only one sort column name and direction can be specified for each model.
121 def load_filters_and_paging_params
122 if params[:order].blank?
123 @order = 'created_at desc'
124 elsif params[:order].is_a? Array
125 @order = params[:order]
128 @order = JSON.load(params[:order])
130 @order = params[:order].split(',')
133 @order = [@order] unless @order.is_a? Array
137 @limit = params[:limit].to_i
142 @offset = params[:offset].to_i
147 filters = params[:filters]
148 if filters.is_a? String
149 filters = Oj.load filters
150 elsif filters.is_a? Array
151 filters = filters.collect do |filter|
152 if filter.is_a? String
153 # Accept filters[]=["foo","=","bar"]
156 # Accept filters=[["foo","=","bar"]]
161 # After this, params[:filters] can be trusted to be an array of arrays:
162 params[:filters] = filters
167 def find_objects_for_index
168 @objects ||= model_class
169 @objects = @objects.filter(@filters).limit(@limit).offset(@offset)
170 @objects.fetch_multiple_pages(false)
177 @next_page_href = next_page_href(partial: params[:partial], filters: @filters.to_json)
179 content: render_to_string(partial: "show_#{params[:partial]}",
181 next_page_href: @next_page_href
184 render json: @objects
189 render_pane params[:tab_pane]
198 helper_method :render_pane
199 def render_pane tab_pane, opts={}
201 partial: 'show_' + tab_pane.downcase,
203 comparable: self.respond_to?(:compare),
206 }.merge(opts[:locals] || {})
209 render_to_string render_opts
216 find_objects_for_index if !@objects
220 helper_method :next_page_offset
221 def next_page_offset objects=nil
225 if objects.respond_to?(:result_offset) and
226 objects.respond_to?(:result_limit) and
227 objects.respond_to?(:items_available)
228 next_offset = objects.result_offset + objects.result_limit
229 if next_offset < objects.items_available
237 helper_method :next_page_href
238 def next_page_href with_params={}
240 url_for with_params.merge(offset: next_page_offset)
246 return render_not_found("object not found")
250 extra_attrs = { href: url_for(action: :show, id: @object) }
251 @object.textile_attributes.each do |textile_attr|
252 extra_attrs.merge!({ "#{textile_attr}Textile" => view_context.render_markup(@object.attributes[textile_attr]) })
254 render json: @object.attributes.merge(extra_attrs)
257 if params['tab_pane']
258 render_pane(if params['tab_pane'].is_a? Hash then params['tab_pane']["name"] else params['tab_pane'] end)
259 elsif request.request_method.in? ['GET', 'HEAD']
262 redirect_to (params[:return_to] ||
263 polymorphic_url(@object,
264 anchor: params[:redirect_to_anchor]))
272 params[:limit] ||= 40
276 find_objects_for_index if !@objects
278 content: render_to_string(partial: "choose_rows.html",
280 next_page_href: next_page_href(partial: params[:partial])
285 find_objects_for_index if !@objects
286 render partial: 'choose', locals: {multiple: params[:multiple]}
293 return render_not_found("object not found")
298 @object = model_class.new
302 @updates ||= params[@object.resource_param_name.to_sym]
303 @updates.keys.each do |attr|
304 if @object.send(attr).is_a? Hash
305 if @updates[attr].is_a? String
306 @updates[attr] = Oj.load @updates[attr]
308 if params[:merge] || params["merge_#{attr}".to_sym]
309 # Merge provided Hash with current Hash, instead of
311 @updates[attr] = @object.send(attr).with_indifferent_access.
312 deep_merge(@updates[attr].with_indifferent_access)
316 if @object.update_attributes @updates
319 self.render_error status: 422
324 @new_resource_attrs ||= params[model_class.to_s.underscore.singularize]
325 @new_resource_attrs ||= {}
326 @new_resource_attrs.reject! { |k,v| k.to_s == 'uuid' }
327 @object ||= model_class.new @new_resource_attrs, params["options"]
332 render_error status: 422
336 # Clone the given object, merging any attribute values supplied as
337 # with a create action.
339 @new_resource_attrs ||= params[model_class.to_s.underscore.singularize]
340 @new_resource_attrs ||= {}
341 @object = @object.dup
342 @object.update_attributes @new_resource_attrs
343 if not @new_resource_attrs[:name] and @object.respond_to? :name
344 if @object.name and @object.name != ''
345 @object.name = "Copy of #{@object.name}"
357 f.json { render json: @object }
359 redirect_to(params[:return_to] || :back)
364 self.render_error status: 422
369 Thread.current[:user]
373 controller_name.classify.constantize
376 def breadcrumb_page_name
377 (@breadcrumb_page_name ||
378 (@object.friendly_link_name if @object.respond_to? :friendly_link_name) ||
387 %w(Attributes Advanced)
391 @user_is_manager = false
394 if @object.uuid != current_user.uuid
396 @share_links = Link.permissions_for(@object)
397 @user_is_manager = true
398 rescue ArvadosApiClient::AccessForbiddenException,
399 ArvadosApiClient::NotFoundException
405 if not params[:uuids].andand.any?
406 @errors = ["No user/group UUIDs specified to share with."]
407 return render_error(status: 422)
409 results = {"success" => [], "errors" => []}
410 params[:uuids].each do |shared_uuid|
412 Link.create(tail_uuid: shared_uuid, link_class: "permission",
413 name: "can_read", head_uuid: @object.uuid)
414 rescue ArvadosApiClient::ApiError => error
415 error_list = error.api_response.andand[:errors]
416 if error_list.andand.any?
417 results["errors"] += error_list.map { |e| "#{shared_uuid}: #{e}" }
419 error_code = error.api_status || "Bad status"
420 results["errors"] << "#{shared_uuid}: #{error_code} response"
423 results["success"] << shared_uuid
426 if results["errors"].empty?
427 results.delete("errors")
433 f.json { render(json: results, status: status) }
439 def strip_token_from_path(path)
440 path.sub(/([\?&;])api_token=[^&;]*[&;]?/, '\1')
443 def redirect_to_login
446 if request.method.in? ['GET', 'HEAD']
447 redirect_to arvados_api_client.arvados_login_url(return_to: strip_token_from_path(request.url))
449 flash[:error] = "Either you are not logged in, or your session has timed out. I can't automatically log you in and re-attempt this request."
454 @errors = ['You do not seem to be logged in. You did not supply an API token with this request, and your session (if any) has timed out.']
455 self.render_error status: 422
458 false # For convenience to return from callbacks
461 def using_specific_api_token(api_token, opts={})
463 [:arvados_api_token, :user].each do |key|
464 start_values[key] = Thread.current[key]
466 if opts.fetch(:load_user, true)
467 load_api_token(api_token)
469 Thread.current[:arvados_api_token] = api_token
470 Thread.current[:user] = nil
475 start_values.each_key { |key| Thread.current[key] = start_values[key] }
480 def accept_uuid_as_id_param
481 if params[:id] and params[:id].match /\D/
482 params[:uuid] = params.delete :id
486 def find_object_by_uuid
490 elsif not params[:uuid].is_a?(String)
491 @object = model_class.where(uuid: params[:uuid]).first
492 elsif params[:uuid].empty?
494 elsif (model_class != Link and
495 resource_class_for_uuid(params[:uuid]) == Link)
496 @name_link = Link.find(params[:uuid])
497 @object = model_class.find(@name_link.head_uuid)
499 @object = model_class.find(params[:uuid])
501 rescue ArvadosApiClient::NotFoundException, RuntimeError => error
502 if error.is_a?(RuntimeError) and (error.message !~ /^argument to find\(/)
505 render_not_found(error)
512 Rails.cache.delete_matched(/^request_#{Thread.current.object_id}_/)
514 Rails.cache.delete_matched(/^request_#{Thread.current.object_id}_/)
517 # Set up the thread with the given API token and associated user object.
518 def load_api_token(new_token)
519 Thread.current[:arvados_api_token] = new_token
521 Thread.current[:user] = nil
523 Thread.current[:user] = User.current
527 # If there's a valid api_token parameter, set up the session with that
528 # user's information. Return true if the method redirects the request
529 # (usually a post-login redirect); false otherwise.
530 def setup_user_session
531 return false unless params[:api_token]
532 Thread.current[:arvados_api_token] = params[:api_token]
535 rescue ArvadosApiClient::NotLoggedInException
536 false # We may redirect to login, or not, based on the current action.
538 session[:arvados_api_token] = params[:api_token]
539 # If we later have trouble contacting the API server, we still want
540 # to be able to render basic user information in the UI--see
541 # render_exception above. We store that in the session here. This is
542 # not intended to be used as a general-purpose cache. See #2891.
546 first_name: user.first_name,
547 last_name: user.last_name,
548 is_active: user.is_active,
549 is_admin: user.is_admin,
553 if !request.format.json? and request.method.in? ['GET', 'HEAD']
554 # Repeat this request with api_token in the (new) session
555 # cookie instead of the query string. This prevents API
556 # tokens from appearing in (and being inadvisedly copied
557 # and pasted from) browser Location bars.
558 redirect_to strip_token_from_path(request.fullpath)
564 Thread.current[:arvados_api_token] = nil
568 # Anonymous allowed paths:
569 # /projects/#{uuid}?public_data=true
570 def permit_anonymous_browsing_for_public_data
571 if !Thread.current[:arvados_api_token] && !params[:api_token] && !session[:arvados_api_token]
572 public_project_accessed = /\/projects\/([0-9a-z]{5}-j7d0g-[0-9a-z]{15})(.*)public_data\=true/.match(request.fullpath)
573 if public_project_accessed
574 params[:api_token] = Rails.configuration.anonymous_user_token
579 # Save the session API token in thread-local storage, and yield.
580 # This method also takes care of session setup if the request
581 # provides a valid api_token parameter.
582 # If a token is unavailable or expired, the block is still run, with
584 def set_thread_api_token
585 if Thread.current[:arvados_api_token]
586 yield # An API token has already been found - pass it through.
588 elsif setup_user_session
589 return # A new session was set up and received a response.
593 load_api_token(session[:arvados_api_token])
595 rescue ArvadosApiClient::NotLoggedInException
596 # If we got this error with a token, it must've expired.
597 # Retry the request without a token.
598 unless Thread.current[:arvados_api_token].nil?
603 # Remove token in case this Thread is used for anything else.
608 # Redirect to login/welcome if client provided expired API token (or none at all)
609 def require_thread_api_token
610 if Thread.current[:arvados_api_token]
612 elsif session[:arvados_api_token]
613 # Expired session. Clear it before refreshing login so that,
614 # if this login procedure fails, we end up showing the "please
615 # log in" page instead of getting stuck in a redirect loop.
616 session.delete :arvados_api_token
619 redirect_to welcome_users_path(return_to: request.fullpath)
623 def ensure_current_user_is_admin
624 unless current_user and current_user.is_admin
625 @errors = ['Permission denied']
626 self.render_error status: 401
630 helper_method :unsigned_user_agreements
631 def unsigned_user_agreements
632 @signed_ua_uuids ||= UserAgreement.signatures.map &:head_uuid
633 @unsigned_user_agreements ||= UserAgreement.all.map do |ua|
634 if not @signed_ua_uuids.index ua.uuid
635 Collection.find(ua.uuid)
640 def check_user_agreements
641 if current_user && !current_user.is_active
642 return true if is_anonymous
644 if not current_user.is_invited
645 return redirect_to inactive_users_path(return_to: request.fullpath)
647 if unsigned_user_agreements.empty?
648 # No agreements to sign. Perhaps we just need to ask?
649 current_user.activate
650 if !current_user.is_active
651 logger.warn "#{current_user.uuid.inspect}: " +
652 "No user agreements to sign, but activate failed!"
655 if !current_user.is_active
656 redirect_to user_agreements_path(return_to: request.fullpath)
662 def check_user_profile
663 if request.method.downcase != 'get' || params[:partial] ||
664 params[:tab_pane] || params[:action_method] ||
665 params[:action] == 'setup_popup' || is_anonymous
669 if missing_required_profile?
670 redirect_to profile_user_path(current_user.uuid, return_to: request.fullpath)
675 helper_method :missing_required_profile?
676 def missing_required_profile?
677 missing_required = false
679 profile_config = Rails.configuration.user_profile_form_fields
680 if current_user && profile_config
681 current_user_profile = current_user.prefs[:profile]
682 profile_config.kind_of?(Array) && profile_config.andand.each do |entry|
684 if !current_user_profile ||
685 !current_user_profile[entry['key'].to_sym] ||
686 current_user_profile[entry['key'].to_sym].empty?
687 missing_required = true
698 return Rails.configuration.arvados_theme
701 @@notification_tests = []
703 @@notification_tests.push lambda { |controller, current_user|
704 AuthorizedKey.limit(1).where(authorized_user_uuid: current_user.uuid).each do
707 return lambda { |view|
708 view.render partial: 'notifications/ssh_key_notification'
712 @@notification_tests.push lambda { |controller, current_user|
713 Collection.limit(1).where(created_by: current_user.uuid).each do
716 return lambda { |view|
717 view.render partial: 'notifications/collections_notification'
721 @@notification_tests.push lambda { |controller, current_user|
722 PipelineInstance.limit(1).where(created_by: current_user.uuid).each do
725 return lambda { |view|
726 view.render partial: 'notifications/pipelines_notification'
730 helper_method :user_notifications
731 def user_notifications
732 return [] if @errors or not current_user.andand.is_active
733 @notifications ||= @@notification_tests.map do |t|
734 t.call(self, current_user)
738 helper_method :all_projects
740 @all_projects ||= Group.
741 filter([['group_class','=','project']]).order('name')
744 helper_method :my_projects
746 return @my_projects if @my_projects
749 all_projects.each do |g|
750 root_of[g.uuid] = g.owner_uuid
756 root_of = root_of.each_with_object({}) do |(child, parent), h|
758 h[child] = root_of[parent]
765 @my_projects = @my_projects.select do |g|
766 root_of[g.uuid] == current_user.uuid
770 helper_method :projects_shared_with_me
771 def projects_shared_with_me
772 my_project_uuids = my_projects.collect &:uuid
773 all_projects.reject { |x| x.uuid.in? my_project_uuids }
776 helper_method :recent_jobs_and_pipelines
777 def recent_jobs_and_pipelines
779 PipelineInstance.limit(10)).
781 (x.finished_at || x.started_at rescue nil) || x.modified_at || x.created_at
785 helper_method :running_pipelines
786 def running_pipelines
787 pi = PipelineInstance.order(["started_at asc", "created_at asc"]).filter([["state", "in", ["RunningOnServer", "RunningOnClient"]]])
790 pl.components.each do |k,v|
791 if v.is_a? Hash and v[:job]
792 jobs[v[:job][:uuid]] = {}
798 Job.filter([["uuid", "in", jobs.keys]]).each do |j|
803 pl.components.each do |k,v|
804 if v.is_a? Hash and v[:job]
805 v[:job] = jobs[v[:job][:uuid]]
814 helper_method :finished_pipelines
815 def finished_pipelines lim
816 PipelineInstance.limit(lim).order(["finished_at desc"]).filter([["state", "in", ["Complete", "Failed", "Paused"]], ["finished_at", "!=", nil]])
819 helper_method :recent_collections
820 def recent_collections lim
821 c = Collection.limit(lim).order(["modified_at desc"]).filter([["owner_uuid", "is_a", "arvados#group"]])
823 Group.filter([["uuid", "in", c.map(&:owner_uuid)]]).each do |g|
826 {collections: c, owners: own}
829 helper_method :my_project_tree
835 helper_method :shared_project_tree
836 def shared_project_tree
841 def build_project_trees
842 return if @my_project_tree and @shared_project_tree
843 parent_of = {current_user.uuid => 'me'}
844 all_projects.each do |ob|
845 parent_of[ob.uuid] = ob.owner_uuid
847 children_of = {false => [], 'me' => [current_user]}
848 all_projects.each do |ob|
849 if ob.owner_uuid != current_user.uuid and
850 not parent_of.has_key? ob.owner_uuid
851 parent_of[ob.uuid] = false
853 children_of[parent_of[ob.uuid]] ||= []
854 children_of[parent_of[ob.uuid]] << ob
856 buildtree = lambda do |children_of, root_uuid=false|
858 children_of[root_uuid].andand.each do |ob|
859 tree[ob] = buildtree.call(children_of, ob.uuid)
863 sorted_paths = lambda do |tree, depth=0|
865 tree.keys.sort_by { |ob|
866 ob.is_a?(String) ? ob : ob.friendly_link_name
868 paths << {object: ob, depth: depth}
869 paths += sorted_paths.call tree[ob], depth+1
874 sorted_paths.call buildtree.call(children_of, 'me')
875 @shared_project_tree =
876 sorted_paths.call({'Projects shared with me' =>
877 buildtree.call(children_of, false)})
880 helper_method :get_object
882 if @get_object.nil? and @objects
883 @get_object = @objects.each_with_object({}) do |object, h|
884 h[object.uuid] = object
891 helper_method :project_breadcrumbs
892 def project_breadcrumbs
894 current = @name_link || @object
896 # Halt if a group ownership loop is detected. API should refuse
897 # to produce this state, but it could still arise from a race
898 # condition when group ownership changes between our find()
900 break if crumbs.collect(&:uuid).include? current.uuid
902 if current.is_a?(Group) and current.group_class == 'project'
903 crumbs.prepend current
905 if current.is_a? Link
906 current = Group.find?(current.tail_uuid)
908 current = Group.find?(current.owner_uuid)
914 helper_method :current_project_uuid
915 def current_project_uuid
916 if @object.is_a? Group and @object.group_class == 'project'
918 elsif @name_link.andand.tail_uuid
920 elsif @object and resource_class_for_uuid(@object.owner_uuid) == Group
927 # helper method to get links for given object or uuid
928 helper_method :links_for_object
929 def links_for_object object_or_uuid
930 raise ArgumentError, 'No input argument' unless object_or_uuid
931 preload_links_for_objects([object_or_uuid])
932 uuid = object_or_uuid.is_a?(String) ? object_or_uuid : object_or_uuid.uuid
933 @all_links_for[uuid] ||= []
936 # helper method to preload links for given objects and uuids
937 helper_method :preload_links_for_objects
938 def preload_links_for_objects objects_and_uuids
939 @all_links_for ||= {}
941 raise ArgumentError, 'Argument is not an array' unless objects_and_uuids.is_a? Array
942 return @all_links_for if objects_and_uuids.empty?
944 uuids = objects_and_uuids.collect { |x| x.is_a?(String) ? x : x.uuid }
946 # if already preloaded for all of these uuids, return
947 if not uuids.select { |x| @all_links_for[x].nil? }.any?
948 return @all_links_for
952 @all_links_for[x] = []
955 # TODO: make sure we get every page of results from API server
956 Link.filter([['head_uuid', 'in', uuids]]).each do |link|
957 @all_links_for[link.head_uuid] << link
962 # helper method to get a certain number of objects of a specific type
963 # this can be used to replace any uses of: "dataclass.limit(n)"
964 helper_method :get_n_objects_of_class
965 def get_n_objects_of_class dataclass, size
966 @objects_map_for ||= {}
968 raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? Class and dataclass < ArvadosBase
969 raise ArgumentError, 'Argument is not a valid limit size' unless (size && size>0)
971 # if the objects_map_for has a value for this dataclass, and the
972 # size used to retrieve those objects is equal, return it
973 size_key = "#{dataclass.name}_size"
974 if @objects_map_for[dataclass.name] && @objects_map_for[size_key] &&
975 (@objects_map_for[size_key] == size)
976 return @objects_map_for[dataclass.name]
979 @objects_map_for[size_key] = size
980 @objects_map_for[dataclass.name] = dataclass.limit(size)
983 # helper method to get collections for the given uuid
984 helper_method :collections_for_object
985 def collections_for_object uuid
986 raise ArgumentError, 'No input argument' unless uuid
987 preload_collections_for_objects([uuid])
988 @all_collections_for[uuid] ||= []
991 # helper method to preload collections for the given uuids
992 helper_method :preload_collections_for_objects
993 def preload_collections_for_objects uuids
994 @all_collections_for ||= {}
996 raise ArgumentError, 'Argument is not an array' unless uuids.is_a? Array
997 return @all_collections_for if uuids.empty?
999 # if already preloaded for all of these uuids, return
1000 if not uuids.select { |x| @all_collections_for[x].nil? }.any?
1001 return @all_collections_for
1005 @all_collections_for[x] = []
1008 # TODO: make sure we get every page of results from API server
1009 Collection.where(uuid: uuids).each do |collection|
1010 @all_collections_for[collection.uuid] << collection
1012 @all_collections_for
1015 # helper method to get log collections for the given log
1016 helper_method :log_collections_for_object
1017 def log_collections_for_object log
1018 raise ArgumentError, 'No input argument' unless log
1020 preload_log_collections_for_objects([log])
1023 fixup = /([a-f0-9]{32}\+\d+)(\+?.*)/.match(log)
1024 if fixup && fixup.size>1
1028 @all_log_collections_for[uuid] ||= []
1031 # helper method to preload collections for the given uuids
1032 helper_method :preload_log_collections_for_objects
1033 def preload_log_collections_for_objects logs
1034 @all_log_collections_for ||= {}
1036 raise ArgumentError, 'Argument is not an array' unless logs.is_a? Array
1037 return @all_log_collections_for if logs.empty?
1041 fixup = /([a-f0-9]{32}\+\d+)(\+?.*)/.match(log)
1042 if fixup && fixup.size>1
1049 # if already preloaded for all of these uuids, return
1050 if not uuids.select { |x| @all_log_collections_for[x].nil? }.any?
1051 return @all_log_collections_for
1055 @all_log_collections_for[x] = []
1058 # TODO: make sure we get every page of results from API server
1059 Collection.where(uuid: uuids).each do |collection|
1060 @all_log_collections_for[collection.uuid] << collection
1062 @all_log_collections_for
1065 # helper method to get object of a given dataclass and uuid
1066 helper_method :object_for_dataclass
1067 def object_for_dataclass dataclass, uuid
1068 raise ArgumentError, 'No input argument dataclass' unless (dataclass && uuid)
1069 preload_objects_for_dataclass(dataclass, [uuid])
1073 # helper method to preload objects for given dataclass and uuids
1074 helper_method :preload_objects_for_dataclass
1075 def preload_objects_for_dataclass dataclass, uuids
1078 raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? Class
1079 raise ArgumentError, 'Argument is not an array' unless uuids.is_a? Array
1081 return @objects_for if uuids.empty?
1083 # if already preloaded for all of these uuids, return
1084 if not uuids.select { |x| @objects_for[x].nil? }.any?
1088 dataclass.where(uuid: uuids).each do |obj|
1089 @objects_for[obj.uuid] = obj
1094 def wiselinks_layout
1098 helper_method :is_anonymous
1100 return Rails.configuration.anonymous_user_token &&
1101 (Thread.current[:arvados_api_token] == Rails.configuration.anonymous_user_token)