X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/67e5d42cccb652e4200a6c97164d492225394305..cc527a74c89f44267c50a52194ec0560484a72a0:/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 5b8276a9e0..27a4f79c42 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -1,8 +1,11 @@ class ApplicationController < ActionController::Base + respond_to :html, :json, :js protect_from_forgery around_filter :thread_clear around_filter :thread_with_api_token, :except => [:render_exception, :render_not_found] before_filter :find_object_by_uuid, :except => [:index, :render_exception, :render_not_found] + before_filter :check_user_agreements, :except => [:render_exception, :render_not_found] + theme :select_theme begin rescue_from Exception, @@ -25,8 +28,12 @@ class ApplicationController < ActionController::Base def render_error(opts) respond_to do |f| - f.html { render opts.merge(controller: 'application', action: 'error') } + # json must come before html here, so it gets used as the + # default format when js is requested by the client. This lets + # ajax:error callback parse the response correctly, even though + # the browser can't. f.json { render opts.merge(json: {success: false, errors: @errors}) } + f.html { render opts.merge(controller: 'application', action: 'error') } end end @@ -36,7 +43,7 @@ class ApplicationController < ActionController::Base if @object.andand.errors.andand.full_messages.andand.any? @errors = @object.errors.full_messages else - @errors = [e.inspect] + @errors = [e.to_s] end self.render_error status: 422 end @@ -47,12 +54,12 @@ class ApplicationController < ActionController::Base self.render_error status: 404 end - def index - @objects ||= model_class.all + @objects ||= model_class.limit(1000).all respond_to do |f| f.json { render json: @objects } f.html { render } + f.js { render } end end @@ -69,6 +76,7 @@ class ApplicationController < ActionController::Base redirect_to params[:return_to] || @object end } + f.js { render } end end @@ -104,7 +112,12 @@ class ApplicationController < ActionController::Base def destroy if @object.destroy - redirect_to(params[:return_to] || :back) + respond_to do |f| + f.html { + redirect_to(params[:return_to] || :back) + } + f.js { render } + end else self.render_error status: 422 end @@ -123,6 +136,11 @@ class ApplicationController < ActionController::Base controller_name.classify.constantize end + def breadcrumb_page_name + (@breadcrumb_page_name || + (@object.friendly_link_name if @object.respond_to? :friendly_link_name)) + end + protected def find_object_by_uuid @@ -139,7 +157,9 @@ class ApplicationController < ActionController::Base def thread_clear Thread.current[:arvados_api_token] = nil Thread.current[:user] = nil + Rails.cache.delete_matched(/^request_#{Thread.current.object_id}_/) yield + Rails.cache.delete_matched(/^request_#{Thread.current.object_id}_/) end def thread_with_api_token(login_optional = false) @@ -228,4 +248,32 @@ class ApplicationController < ActionController::Base self.render_error status: 401 end end + + def check_user_agreements + if current_user && !current_user.is_active && current_user.is_invited + signatures = UserAgreement.signatures + @signed_ua_uuids = UserAgreement.signatures.map &:head_uuid + @required_user_agreements = UserAgreement.all.map do |ua| + if not @signed_ua_uuids.index ua.uuid + Collection.find(ua.uuid) + end + end.compact + if @required_user_agreements.empty? + # No agreements to sign. Perhaps we just need to ask? + current_user.activate + if !current_user.is_active + logger.warn "#{current_user.uuid.inspect}: " + + "No user agreements to sign, but activate failed!" + end + end + if !current_user.is_active + render 'user_agreements/index' + end + end + true + end + + def select_theme + return Rails.configuration.arvados_theme + end end