From 729f05f0e3c4835c91e20ccd1ddb630eb7ef4379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=99=88=20=20jacopo=20beschi=20=F0=9F=99=89?= Date: Thu, 11 Jan 2018 16:34:01 +0000 Subject: Adds Rubocop rule for line break around conditionals --- app/controllers/concerns/group_tree.rb | 1 + app/controllers/concerns/routable_actions.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'app/controllers/concerns') diff --git a/app/controllers/concerns/group_tree.rb b/app/controllers/concerns/group_tree.rb index b10147835f3..b569029283f 100644 --- a/app/controllers/concerns/group_tree.rb +++ b/app/controllers/concerns/group_tree.rb @@ -8,6 +8,7 @@ module GroupTree # Only show root groups if no parent-id is given groups.where(parent_id: params[:parent_id]) end + @groups = @groups.with_selects_for_list(archived: params[:archived]) .sort(@sort = params[:sort]) .page(params[:page]) diff --git a/app/controllers/concerns/routable_actions.rb b/app/controllers/concerns/routable_actions.rb index 4199da9cdf5..f745deb083c 100644 --- a/app/controllers/concerns/routable_actions.rb +++ b/app/controllers/concerns/routable_actions.rb @@ -32,6 +32,7 @@ module RoutableActions if canonical_path.casecmp(requested_full_path) != 0 flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_full_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path." end + redirect_to build_canonical_path(routable) end end -- cgit v1.2.3 From 28d39447c39981565cd0cdfad63dab5e5126e524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 16 Jan 2018 19:13:31 +0100 Subject: In development, allow the toggling of the performance bar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The performance bar is still displayed by default in development. Signed-off-by: Rémy Coutable --- app/controllers/concerns/with_performance_bar.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'app/controllers/concerns') diff --git a/app/controllers/concerns/with_performance_bar.rb b/app/controllers/concerns/with_performance_bar.rb index 230bbe4b1aa..6a8b1a4de7b 100644 --- a/app/controllers/concerns/with_performance_bar.rb +++ b/app/controllers/concerns/with_performance_bar.rb @@ -6,13 +6,22 @@ module WithPerformanceBar end def peek_enabled? - return true if Rails.env.development? return false unless Gitlab::PerformanceBar.enabled?(current_user) if RequestStore.active? - RequestStore.fetch(:peek_enabled) { cookies[:perf_bar_enabled].present? } + RequestStore.fetch(:peek_enabled) { cookie_or_default_value } else - cookies[:perf_bar_enabled].present? + cookie_or_default_value + end + end + + private + + def cookie_or_default_value + if cookies[:perf_bar_enabled].present? + cookies[:perf_bar_enabled] == 'true' + else + cookies[:perf_bar_enabled] = 'true' if Rails.env.development? end end end -- cgit v1.2.3 From 4b6b8eccedb49014d4cd329a336015fb8d7bcff9 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Thu, 11 Jan 2018 17:22:00 +0100 Subject: Return last edited time instead of update time For issuable models we keep two timestamps: updated_at which is updated whenever any model attribute is changed, last_edited_at which is changed when only title or description is changed. In UI bellow description we display who and when updated the item. But last_edited_by (used for 'who') is mistakenly combined with updated_at (when), last_edited_at should be used instead. Closes #41247 --- app/controllers/concerns/issuable_actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/concerns') diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb index 74a4f437dc8..337957c366d 100644 --- a/app/controllers/concerns/issuable_actions.rb +++ b/app/controllers/concerns/issuable_actions.rb @@ -45,7 +45,7 @@ module IssuableActions } if issuable.edited? - response[:updated_at] = issuable.updated_at + response[:updated_at] = issuable.last_edited_at.to_time.iso8601 response[:updated_by_name] = issuable.last_edited_by.name response[:updated_by_path] = user_path(issuable.last_edited_by) end -- cgit v1.2.3 From c56326fc3ef75767abf324f614a4be46153efbb3 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Fri, 19 Jan 2018 16:10:27 +0100 Subject: Fix filter on `dashboard/groups` & `explore/groups When searching we would limit the scope of ancestors to load because the filter would be applied to the ancestors. Instead, we need to load _all_ ancestors for matching projects. --- app/controllers/concerns/group_tree.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/controllers/concerns') diff --git a/app/controllers/concerns/group_tree.rb b/app/controllers/concerns/group_tree.rb index b569029283f..fafb10090ca 100644 --- a/app/controllers/concerns/group_tree.rb +++ b/app/controllers/concerns/group_tree.rb @@ -2,7 +2,11 @@ module GroupTree # rubocop:disable Gitlab/ModuleWithInstanceVariables def render_group_tree(groups) @groups = if params[:filter].present? - Gitlab::GroupHierarchy.new(groups.search(params[:filter])) + # We find the ancestors by ID of the search results here. + # Otherwise the ancestors would also have filters applied, + # which would cause them not to be preloaded. + group_ids = groups.search(params[:filter]).select(:id) + Gitlab::GroupHierarchy.new(Group.where(id: group_ids)) .base_and_ancestors else # Only show root groups if no parent-id is given -- cgit v1.2.3 From b02a6bed85000db63189b68fe8ce6154c283bc39 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Mon, 29 Jan 2018 16:22:58 +0100 Subject: Make pagination optional for issuables On epics roadmap page we list all epics in the given time frame without pagination (at least for the first iteration), in this case it would be nice to use the existing issuables index logic except pagination (see MR gitlab-ee!4281). For this reason this patch allows to easily disable pagination. Related gitlab-ee!4281 --- app/controllers/concerns/issuable_collections.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'app/controllers/concerns') diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index b25e753a5ad..2fa0f98e344 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -12,11 +12,9 @@ module IssuableCollections # rubocop:disable Gitlab/ModuleWithInstanceVariables def set_issuables_index - @issuables = issuables_collection - @issuables = @issuables.page(params[:page]) - @issuable_meta_data = issuable_meta_data(@issuables, collection_type) - @total_pages = issuable_page_count + @issuables = issuables_collection + set_pagination return if redirect_out_of_range(@total_pages) if params[:label_name].present? @@ -35,14 +33,26 @@ module IssuableCollections @users.push(author) if author end end + + def set_pagination + return if pagination_disabled? + + @issuables = @issuables.page(params[:page]) + @issuable_meta_data = issuable_meta_data(@issuables, collection_type) + @total_pages = issuable_page_count + end # rubocop:enable Gitlab/ModuleWithInstanceVariables + def pagination_disabled? + false + end + def issuables_collection finder.execute.preload(preload_for_collection) end def redirect_out_of_range(total_pages) - return false if total_pages.zero? + return false if total_pages.nil? || total_pages.zero? out_of_range = @issuables.current_page > total_pages # rubocop:disable Gitlab/ModuleWithInstanceVariables -- cgit v1.2.3 From 7f0ebeff1affcd4f5155790cc5a5884b052695af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarka=20Kadlecova=CC=81?= Date: Wed, 24 Jan 2018 07:06:24 +0100 Subject: Include subgroup issuables on the group page --- app/controllers/concerns/issuable_collections.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/controllers/concerns') diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index b25e753a5ad..755e324a53f 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -84,6 +84,7 @@ module IssuableCollections @filter_params[:project_id] = @project.id elsif @group @filter_params[:group_id] = @group.id + @filter_params[:include_subgroups] = true else # TODO: this filter ignore issues/mr created in public or # internal repos where you are not a member. Enable this filter -- cgit v1.2.3 From 2057a6acdee7c1f6824ff6289b0d979e8cb15f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mica=C3=ABl=20Bergeron?= Date: Mon, 29 Jan 2018 12:57:34 -0500 Subject: port of 594e6a0a625^..f74c90f68c6 --- app/controllers/concerns/uploads_actions.rb | 61 +++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 11 deletions(-) (limited to 'app/controllers/concerns') diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb index a6fb1f40001..61554029d09 100644 --- a/app/controllers/concerns/uploads_actions.rb +++ b/app/controllers/concerns/uploads_actions.rb @@ -1,6 +1,8 @@ module UploadsActions include Gitlab::Utils::StrongMemoize + UPLOAD_MOUNTS = %w(avatar attachment file logo header_logo).freeze + def create link_to_file = UploadService.new(model, params[:file], uploader_class).execute @@ -17,34 +19,71 @@ module UploadsActions end end + # This should either + # - send the file directly + # - or redirect to its URL + # def show return render_404 unless uploader.exists? - disposition = uploader.image_or_video? ? 'inline' : 'attachment' - - expires_in 0.seconds, must_revalidate: true, private: true + if uploader.file_storage? + disposition = uploader.image_or_video? ? 'inline' : 'attachment' + expires_in 0.seconds, must_revalidate: true, private: true - send_file uploader.file.path, disposition: disposition + send_file uploader.file.path, disposition: disposition + else + redirect_to uploader.url + end end private + def uploader_class + raise NotImplementedError + end + + def upload_mount + mounted_as = params[:mounted_as] + mounted_as if UPLOAD_MOUNTS.include?(mounted_as) + end + + def uploader_mounted? + upload_model_class < CarrierWave::Mount::Extension && !upload_mount.nil? + end + def uploader strong_memoize(:uploader) do - return if show_model.nil? + if uploader_mounted? + model.public_send(upload_mount) # rubocop:disable GitlabSecurity/PublicSend + else + build_uploader_from_upload || build_uploader_from_params + end + end + end - file_uploader = FileUploader.new(show_model, params[:secret]) - file_uploader.retrieve_from_store!(params[:filename]) + def build_uploader_from_upload + return nil unless params[:secret] && params[:filename] - file_uploader - end + upload_path = uploader_class.upload_path(params[:secret], params[:filename]) + upload = Upload.find_by(uploader: uploader_class.to_s, path: upload_path) + upload&.build_uploader + end + + def build_uploader_from_params + uploader = uploader_class.new(model, params[:secret]) + uploader.retrieve_from_store!(params[:filename]) + uploader end def image_or_video? uploader && uploader.exists? && uploader.image_or_video? end - def uploader_class - FileUploader + def find_model + nil + end + + def model + strong_memoize(:model) { find_model } end end -- cgit v1.2.3 From 8af23def1d6450420d06b8de54d23311a978de20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Wed, 28 Feb 2018 21:09:34 +0100 Subject: Revert "Merge branch '3867-port-to-ce' into 'master'" This reverts commit 54a575f1bbba44573ab92dc58a4242f1ee734c5d, reversing changes made to c63af942e5baf7849a94fa99da8494bcba28e3f8. --- app/controllers/concerns/uploads_actions.rb | 61 ++++++----------------------- 1 file changed, 11 insertions(+), 50 deletions(-) (limited to 'app/controllers/concerns') diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb index 61554029d09..a6fb1f40001 100644 --- a/app/controllers/concerns/uploads_actions.rb +++ b/app/controllers/concerns/uploads_actions.rb @@ -1,8 +1,6 @@ module UploadsActions include Gitlab::Utils::StrongMemoize - UPLOAD_MOUNTS = %w(avatar attachment file logo header_logo).freeze - def create link_to_file = UploadService.new(model, params[:file], uploader_class).execute @@ -19,71 +17,34 @@ module UploadsActions end end - # This should either - # - send the file directly - # - or redirect to its URL - # def show return render_404 unless uploader.exists? - if uploader.file_storage? - disposition = uploader.image_or_video? ? 'inline' : 'attachment' - expires_in 0.seconds, must_revalidate: true, private: true - - send_file uploader.file.path, disposition: disposition - else - redirect_to uploader.url - end - end - - private + disposition = uploader.image_or_video? ? 'inline' : 'attachment' - def uploader_class - raise NotImplementedError - end + expires_in 0.seconds, must_revalidate: true, private: true - def upload_mount - mounted_as = params[:mounted_as] - mounted_as if UPLOAD_MOUNTS.include?(mounted_as) + send_file uploader.file.path, disposition: disposition end - def uploader_mounted? - upload_model_class < CarrierWave::Mount::Extension && !upload_mount.nil? - end + private def uploader strong_memoize(:uploader) do - if uploader_mounted? - model.public_send(upload_mount) # rubocop:disable GitlabSecurity/PublicSend - else - build_uploader_from_upload || build_uploader_from_params - end - end - end - - def build_uploader_from_upload - return nil unless params[:secret] && params[:filename] + return if show_model.nil? - upload_path = uploader_class.upload_path(params[:secret], params[:filename]) - upload = Upload.find_by(uploader: uploader_class.to_s, path: upload_path) - upload&.build_uploader - end + file_uploader = FileUploader.new(show_model, params[:secret]) + file_uploader.retrieve_from_store!(params[:filename]) - def build_uploader_from_params - uploader = uploader_class.new(model, params[:secret]) - uploader.retrieve_from_store!(params[:filename]) - uploader + file_uploader + end end def image_or_video? uploader && uploader.exists? && uploader.image_or_video? end - def find_model - nil - end - - def model - strong_memoize(:model) { find_model } + def uploader_class + FileUploader end end -- cgit v1.2.3