X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b3a016e9a47d453b5ae4d287d8b6eaafd69971df..80b2655dbb69a4ceacce0a7f58845b3ee7fb5853:/apps/workbench/app/controllers/application_controller.rb diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb index ccd0abdc33..c2636bf5d7 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -29,7 +29,6 @@ class ApplicationController < ActionController::Base begin rescue_from(ActiveRecord::RecordNotFound, ActionController::RoutingError, - ActionController::UnknownController, AbstractController::ActionNotFound, with: :render_not_found) rescue_from(Exception, @@ -62,6 +61,7 @@ class ApplicationController < ActionController::Base # the browser can't. f.json { render opts.merge(json: {success: false, errors: @errors}) } f.html { render({action: 'error'}.merge(opts)) } + f.all { render({action: 'error', formats: 'text'}.merge(opts)) } end end @@ -95,7 +95,7 @@ class ApplicationController < ActionController::Base # exception here than in a template.) unless current_user.nil? begin - my_starred_projects current_user + my_starred_projects current_user, 'project' build_my_wanted_projects_tree current_user rescue ArvadosApiClient::ApiError # Fall back to the default-setting code later. @@ -152,12 +152,12 @@ class ApplicationController < ActionController::Base if params[:filters] filters = params[:filters] if filters.is_a? String - filters = Oj.load filters + filters = Oj.safe_load filters elsif filters.is_a? Array filters = filters.collect do |filter| if filter.is_a? String # Accept filters[]=["foo","=","bar"] - Oj.load filter + Oj.safe_load filter else # Accept filters=[["foo","=","bar"]] filter @@ -172,7 +172,7 @@ class ApplicationController < ActionController::Base def find_objects_for_index @objects ||= model_class - @objects = @objects.filter(@filters).limit(@limit).offset(@offset) + @objects = @objects.filter(@filters).limit(@limit).offset(@offset).order(@order) @objects.fetch_multiple_pages(false) end @@ -239,7 +239,7 @@ class ApplicationController < ActionController::Base if objects.respond_to?(:result_offset) and objects.respond_to?(:result_limit) next_offset = objects.result_offset + objects.result_limit - if objects.respond_to?(:items_available) and (next_offset < objects.items_available) + if objects.respond_to?(:items_available) and (objects.items_available != nil) and (next_offset < objects.items_available) next_offset elsif @objects.results.size > 0 and (params[:count] == 'none' or (params[:controller] == 'search' and params[:action] == 'choose')) @@ -361,7 +361,7 @@ class ApplicationController < ActionController::Base @updates.keys.each do |attr| if @object.send(attr).is_a? Hash if @updates[attr].is_a? String - @updates[attr] = Oj.load @updates[attr] + @updates[attr] = Oj.safe_load @updates[attr] end if params[:merge] || params["merge_#{attr}".to_sym] # Merge provided Hash with current Hash, instead of @@ -417,7 +417,11 @@ class ApplicationController < ActionController::Base respond_to do |f| f.json { render json: @object } f.html { - redirect_to(params[:return_to] || :back) + if params[:return_to] + redirect_to(params[:return_to]) + else + redirect_back(fallback_location: root_path) + end } f.js { render } end @@ -499,7 +503,7 @@ class ApplicationController < ActionController::Base def is_starred links = Link.where(tail_uuid: current_user.uuid, head_uuid: @object.uuid, - link_class: 'star') + link_class: 'star').with_count("none") return links.andand.any? end @@ -519,7 +523,7 @@ class ApplicationController < ActionController::Base redirect_to arvados_api_client.arvados_login_url(return_to: strip_token_from_path(request.url)) else 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." - redirect_to :back + redirect_back(fallback_location: root_path) end false # For convenience to return from callbacks end @@ -760,7 +764,7 @@ class ApplicationController < ActionController::Base if current_user && !profile_config.empty? current_user_profile = current_user.prefs[:profile] profile_config.each do |k, entry| - if entry['Required'] + if entry[:Required] if !current_user_profile || !current_user_profile[k] || current_user_profile[k].empty? @@ -782,7 +786,7 @@ class ApplicationController < ActionController::Base @@notification_tests.push lambda { |controller, current_user| return nil if Rails.configuration.Services.WebShell.ExternalURL != URI("") - AuthorizedKey.limit(1).where(authorized_user_uuid: current_user.uuid).each do + AuthorizedKey.limit(1).with_count('none').where(authorized_user_uuid: current_user.uuid).each do return nil end return lambda { |view| @@ -791,7 +795,7 @@ class ApplicationController < ActionController::Base } @@notification_tests.push lambda { |controller, current_user| - Collection.limit(1).where(created_by: current_user.uuid).each do + Collection.limit(1).with_count('none').where(created_by: current_user.uuid).each do return nil end return lambda { |view| @@ -801,7 +805,7 @@ class ApplicationController < ActionController::Base @@notification_tests.push lambda { |controller, current_user| if PipelineInstance.api_exists?(:index) - PipelineInstance.limit(1).where(created_by: current_user.uuid).each do + PipelineInstance.limit(1).with_count('none').where(created_by: current_user.uuid).each do return nil end else @@ -824,7 +828,7 @@ class ApplicationController < ActionController::Base helper_method :all_projects def all_projects @all_projects ||= Group. - filter([['group_class','=','project']]).order('name') + filter([['group_class','IN',['project','filter']]]).order('name') end helper_method :my_projects @@ -862,7 +866,7 @@ class ApplicationController < ActionController::Base helper_method :recent_jobs_and_pipelines def recent_jobs_and_pipelines (Job.limit(10) | - PipelineInstance.limit(10)). + PipelineInstance.limit(10).with_count("none")). sort_by do |x| (x.finished_at || x.started_at rescue nil) || x.modified_at || x.created_at end.reverse @@ -870,7 +874,7 @@ class ApplicationController < ActionController::Base helper_method :running_pipelines def running_pipelines - pi = PipelineInstance.order(["started_at asc", "created_at asc"]).filter([["state", "in", ["RunningOnServer", "RunningOnClient"]]]) + pi = PipelineInstance.order(["started_at asc", "created_at asc"]).with_count("none").filter([["state", "in", ["RunningOnServer", "RunningOnClient"]]]) jobs = {} pi.each do |pl| pl.components.each do |k,v| @@ -881,7 +885,7 @@ class ApplicationController < ActionController::Base end if jobs.keys.any? - Job.filter([["uuid", "in", jobs.keys]]).each do |j| + Job.filter([["uuid", "in", jobs.keys]]).with_count("none").each do |j| jobs[j[:uuid]] = j end @@ -904,11 +908,12 @@ class ApplicationController < ActionController::Base procs = {} if PipelineInstance.api_exists?(:index) cols = %w(uuid owner_uuid created_at modified_at pipeline_template_uuid name state started_at finished_at) - pipelines = PipelineInstance.select(cols).limit(lim).order(["created_at desc"]) + pipelines = PipelineInstance.select(cols).limit(lim).order(["created_at desc"]).with_count("none") pipelines.results.each { |pi| procs[pi] = pi.created_at } end - crs = ContainerRequest.limit(lim).order(["created_at desc"]).filter([["requesting_container_uuid", "=", nil]]) + crs = ContainerRequest.limit(lim).with_count("none").order(["created_at desc"]).filter([["requesting_container_uuid", "=", nil]]).select( + ["uuid", "name", "container_uuid", "output_uuid", "state", "created_at", "modified_at"]) crs.results.each { |c| procs[c] = c.created_at } Hash[procs.sort_by {|key, value| value}].keys.reverse.first(lim) @@ -916,22 +921,26 @@ class ApplicationController < ActionController::Base helper_method :recent_collections def recent_collections lim - c = Collection.limit(lim).order(["modified_at desc"]).results + c = Collection.limit(lim).with_count("none").order(["modified_at desc"]).results own = {} - Group.filter([["uuid", "in", c.map(&:owner_uuid)]]).each do |g| + Group.filter([["uuid", "in", c.map(&:owner_uuid)]]).with_count("none").each do |g| own[g[:uuid]] = g end {collections: c, owners: own} end helper_method :my_starred_projects - def my_starred_projects user + def my_starred_projects user, group_class return if defined?(@starred_projects) && @starred_projects - links = Link.filter([['tail_uuid', '=', user.uuid], + links = Link.filter([['owner_uuid', 'in', ["#{Rails.configuration.ClusterID}-j7d0g-publicfavorites", user.uuid]], ['link_class', '=', 'star'], - ['head_uuid', 'is_a', 'arvados#group']]).select(%w(head_uuid)) + ['head_uuid', 'is_a', 'arvados#group']]).with_count("none").select(%w(head_uuid)) uuids = links.collect { |x| x.head_uuid } - starred_projects = Group.filter([['uuid', 'in', uuids]]).order('name') + if group_class == "" + starred_projects = Group.filter([['uuid', 'in', uuids]]).order('name').with_count("none") + else + starred_projects = Group.filter([['uuid', 'in', uuids],['group_class', '=', group_class]]).order('name').with_count("none") + end @starred_projects = starred_projects.results end @@ -949,7 +958,7 @@ class ApplicationController < ActionController::Base @too_many_projects = false @reached_level_limit = false while from_top.size <= page_size*2 - current_level = Group.filter([['group_class','=','project'], + current_level = Group.filter([['group_class','IN',['project','filter']], ['owner_uuid', 'in', uuids]]) .order('name').limit(page_size*2) break if current_level.results.size == 0 @@ -1084,7 +1093,7 @@ class ApplicationController < ActionController::Base end # TODO: make sure we get every page of results from API server - Link.filter([['head_uuid', 'in', uuids]]).each do |link| + Link.filter([['head_uuid', 'in', uuids]]).with_count("none").each do |link| @all_links_for[link.head_uuid] << link end @all_links_for @@ -1137,7 +1146,7 @@ class ApplicationController < ActionController::Base end # TODO: make sure we get every page of results from API server - Collection.where(uuid: uuids).each do |collection| + Collection.where(uuid: uuids).with_count("none").each do |collection| @all_collections_for[collection.uuid] << collection end @all_collections_for @@ -1187,7 +1196,7 @@ class ApplicationController < ActionController::Base end # TODO: make sure we get every page of results from API server - Collection.where(uuid: uuids).each do |collection| + Collection.where(uuid: uuids).with_count("none").each do |collection| @all_log_collections_for[collection.uuid] << collection end @all_log_collections_for @@ -1220,7 +1229,7 @@ class ApplicationController < ActionController::Base @all_pdhs_for[x] = [] end - Collection.select(%w(portable_data_hash)).where(portable_data_hash: pdhs).distinct().each do |collection| + Collection.select(%w(portable_data_hash)).where(portable_data_hash: pdhs).distinct().with_count("none").each do |collection| @all_pdhs_for[collection.portable_data_hash] << collection end @all_pdhs_for @@ -1236,7 +1245,7 @@ class ApplicationController < ActionController::Base # helper method to preload objects for given dataclass and uuids helper_method :preload_objects_for_dataclass - def preload_objects_for_dataclass dataclass, uuids, by_attr=nil + def preload_objects_for_dataclass dataclass, uuids, by_attr=nil, select_fields=nil @objects_for ||= {} raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? Class @@ -1261,7 +1270,7 @@ class ApplicationController < ActionController::Base end else key_prefix = "request_#{Thread.current.object_id}_#{dataclass.to_s}_" - dataclass.where(uuid: uuids).each do |obj| + dataclass.where(uuid: uuids).select(select_fields).each do |obj| @objects_for[obj.uuid] = obj if dataclass == Collection # The collecions#index defaults to "all attributes except manifest_text" @@ -1291,7 +1300,7 @@ class ApplicationController < ActionController::Base end unless link_uuids.empty? - Link.select([:head_uuid]).where(uuid: link_uuids).each do |link| + Link.select([:head_uuid]).where(uuid: link_uuids).with_count("none").each do |link| if ArvadosBase::resource_class_for_uuid(link.head_uuid) == Collection coll_ids << link.head_uuid end @@ -1314,7 +1323,7 @@ class ApplicationController < ActionController::Base end unless pdhs.empty? - Collection.where(portable_data_hash: pdhs.uniq). + Collection.where(portable_data_hash: pdhs.uniq).with_count("none"). select([:uuid, :portable_data_hash]).each do |coll| unless source_paths[coll.portable_data_hash].empty? uuids << coll.uuid