summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-03 06:08:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-03 06:08:34 +0000
commit6b7b853dff4cb7e72d76bd501d75708111c95585 (patch)
tree48333f6e505903dc2443f2e3ad397c18b76b3b6a /app
parent2ead415d7a2bd739837057a778187189e63ceb8d (diff)
downloadgitlab-ce-6b7b853dff4cb7e72d76bd501d75708111c95585.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/group_links_controller.rb3
-rw-r--r--app/models/design_management/design.rb2
-rw-r--r--app/models/project_group_link.rb6
-rw-r--r--app/services/projects/group_links/create_service.rb1
-rw-r--r--app/services/projects/group_links/destroy_service.rb4
-rw-r--r--app/services/projects/group_links/update_service.rb29
-rw-r--r--app/views/projects/wikis/_main_links.html.haml6
-rw-r--r--app/views/projects/wikis/_sidebar.html.haml2
-rw-r--r--app/views/projects/wikis/show.html.haml2
-rw-r--r--app/workers/all_queues.yml16
-rw-r--r--app/workers/metrics/dashboard/prune_old_annotations_worker.rb23
-rw-r--r--app/workers/metrics/dashboard/schedule_annotations_prune_worker.rb23
-rw-r--r--app/workers/remove_expired_group_links_worker.rb4
13 files changed, 105 insertions, 16 deletions
diff --git a/app/controllers/projects/group_links_controller.rb b/app/controllers/projects/group_links_controller.rb
index 83b509bcae2..a30c455a7e4 100644
--- a/app/controllers/projects/group_links_controller.rb
+++ b/app/controllers/projects/group_links_controller.rb
@@ -22,8 +22,7 @@ class Projects::GroupLinksController < Projects::ApplicationController
def update
@group_link = @project.project_group_links.find(params[:id])
-
- @group_link.update(group_link_params)
+ Projects::GroupLinks::UpdateService.new(@group_link).execute(group_link_params)
end
def destroy
diff --git a/app/models/design_management/design.rb b/app/models/design_management/design.rb
index 6434d7cfa57..057bbab1c83 100644
--- a/app/models/design_management/design.rb
+++ b/app/models/design_management/design.rb
@@ -22,7 +22,7 @@ module DesignManagement
validates :project, :filename, presence: true
validates :issue, presence: true, unless: :importing?
- validates :filename, uniqueness: { scope: :issue_id }
+ validates :filename, uniqueness: { scope: :issue_id }, length: { maximum: 255 }
validate :validate_file_is_image
alias_attribute :title, :filename
diff --git a/app/models/project_group_link.rb b/app/models/project_group_link.rb
index f1c491d1a05..f065246e8af 100644
--- a/app/models/project_group_link.rb
+++ b/app/models/project_group_link.rb
@@ -15,8 +15,6 @@ class ProjectGroupLink < ApplicationRecord
scope :non_guests, -> { where('group_access > ?', Gitlab::Access::GUEST) }
- after_commit :refresh_group_members_authorized_projects
-
alias_method :shared_with_group, :group
def self.access_options
@@ -49,10 +47,6 @@ class ProjectGroupLink < ApplicationRecord
errors.add(:base, _("Project cannot be shared with the group it is in or one of its ancestors."))
end
end
-
- def refresh_group_members_authorized_projects
- group.refresh_members_authorized_projects
- end
end
ProjectGroupLink.prepend_if_ee('EE::ProjectGroupLink')
diff --git a/app/services/projects/group_links/create_service.rb b/app/services/projects/group_links/create_service.rb
index 241948b335b..2ba3cd6694f 100644
--- a/app/services/projects/group_links/create_service.rb
+++ b/app/services/projects/group_links/create_service.rb
@@ -13,6 +13,7 @@ module Projects
)
if link.save
+ group.refresh_members_authorized_projects
success(link: link)
else
error(link.errors.full_messages.to_sentence, 409)
diff --git a/app/services/projects/group_links/destroy_service.rb b/app/services/projects/group_links/destroy_service.rb
index ea7d05551fd..229191e41f6 100644
--- a/app/services/projects/group_links/destroy_service.rb
+++ b/app/services/projects/group_links/destroy_service.rb
@@ -12,7 +12,9 @@ module Projects
TodosDestroyer::ConfidentialIssueWorker.perform_in(Todo::WAIT_FOR_DELETE, nil, project.id)
end
- group_link.destroy
+ group_link.destroy.tap do |link|
+ link.group.refresh_members_authorized_projects
+ end
end
end
end
diff --git a/app/services/projects/group_links/update_service.rb b/app/services/projects/group_links/update_service.rb
new file mode 100644
index 00000000000..7de4b7a211d
--- /dev/null
+++ b/app/services/projects/group_links/update_service.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Projects
+ module GroupLinks
+ class UpdateService < BaseService
+ def initialize(group_link, user = nil)
+ super(group_link.project, user)
+
+ @group_link = group_link
+ end
+
+ def execute(group_link_params)
+ group_link.update!(group_link_params)
+
+ if requires_authorization_refresh?(group_link_params)
+ group_link.group.refresh_members_authorized_projects
+ end
+ end
+
+ private
+
+ attr_reader :group_link
+
+ def requires_authorization_refresh?(params)
+ params.include?(:group_access)
+ end
+ end
+ end
+end
diff --git a/app/views/projects/wikis/_main_links.html.haml b/app/views/projects/wikis/_main_links.html.haml
index 2e1e176c42a..8419fb00608 100644
--- a/app/views/projects/wikis/_main_links.html.haml
+++ b/app/views/projects/wikis/_main_links.html.haml
@@ -1,9 +1,9 @@
- if (@page && @page.persisted?)
- if can?(current_user, :create_wiki, @project)
- = link_to project_wikis_new_path(@project), class: "add-new-wiki btn btn-success", role: "button" do
+ = link_to project_wikis_new_path(@project), class: "add-new-wiki btn btn-success", role: "button", data: { qa_selector: 'new_page_button' } do
= s_("Wiki|New page")
- = link_to project_wiki_history_path(@project, @page), class: "btn", role: "button" do
+ = link_to project_wiki_history_path(@project, @page), class: "btn", role: "button", data: { qa_selector: 'page_history_button' } do
= s_("Wiki|Page history")
- if can?(current_user, :create_wiki, @project) && @page.latest? && @valid_encoding
- = link_to project_wiki_edit_path(@project, @page), class: "btn js-wiki-edit", role: "button" do
+ = link_to project_wiki_edit_path(@project, @page), class: "btn js-wiki-edit", role: "button", data: { qa_selector: 'edit_page_button' } do
= _("Edit")
diff --git a/app/views/projects/wikis/_sidebar.html.haml b/app/views/projects/wikis/_sidebar.html.haml
index 2b8da83b126..6069fad6a99 100644
--- a/app/views/projects/wikis/_sidebar.html.haml
+++ b/app/views/projects/wikis/_sidebar.html.haml
@@ -5,7 +5,7 @@
= icon('angle-double-right')
- git_access_url = project_wikis_git_access_path(@project)
- = link_to git_access_url, class: active_nav_link?(path: 'wikis#git_access') ? 'active' : '' do
+ = link_to git_access_url, class: active_nav_link?(path: 'wikis#git_access') ? 'active' : '', data: { qa_selector: 'clone_repository_link' } do
= icon('cloud-download', class: 'append-right-5')
%span= _("Clone repository")
diff --git a/app/views/projects/wikis/show.html.haml b/app/views/projects/wikis/show.html.haml
index 74798311c2e..ae32f43785d 100644
--- a/app/views/projects/wikis/show.html.haml
+++ b/app/views/projects/wikis/show.html.haml
@@ -9,7 +9,7 @@
= icon('angle-double-left')
.nav-text.flex-fill
- %h2.wiki-page-title= @page.human_title
+ %h2.wiki-page-title{ data: { qa_selector: 'wiki_page_title' } }= @page.human_title
%span.wiki-last-edit-by
- if @page.last_version
= (_("Last edited by %{name}") % { name: "<strong>#{@page.last_version.author_name}</strong>" }).html_safe
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml
index 8f3f14c75f0..bcb3679a8c5 100644
--- a/app/workers/all_queues.yml
+++ b/app/workers/all_queues.yml
@@ -163,6 +163,14 @@
:weight: 1
:idempotent:
:tags: []
+- :name: cronjob:metrics_dashboard_schedule_annotations_prune
+ :feature_category: :metrics
+ :has_external_dependencies:
+ :urgency: :low
+ :resource_boundary: :unknown
+ :weight: 1
+ :idempotent: true
+ :tags: []
- :name: cronjob:namespaces_prune_aggregation_schedules
:feature_category: :source_code_management
:has_external_dependencies:
@@ -1355,6 +1363,14 @@
:weight: 1
:idempotent: true
:tags: []
+- :name: metrics_dashboard_prune_old_annotations
+ :feature_category: :metrics
+ :has_external_dependencies:
+ :urgency: :low
+ :resource_boundary: :unknown
+ :weight: 1
+ :idempotent: true
+ :tags: []
- :name: migrate_external_diffs
:feature_category: :source_code_management
:has_external_dependencies:
diff --git a/app/workers/metrics/dashboard/prune_old_annotations_worker.rb b/app/workers/metrics/dashboard/prune_old_annotations_worker.rb
new file mode 100644
index 00000000000..2a9ce3bb8e6
--- /dev/null
+++ b/app/workers/metrics/dashboard/prune_old_annotations_worker.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Metrics
+ module Dashboard
+ class PruneOldAnnotationsWorker
+ include ApplicationWorker
+
+ DELETE_LIMIT = 10_000
+ DEFAULT_CUT_OFF_PERIOD = 2.weeks
+
+ feature_category :metrics
+
+ idempotent! # in the scope of 24 hours
+
+ def perform
+ stale_annotations = ::Metrics::Dashboard::Annotation.ending_before(DEFAULT_CUT_OFF_PERIOD.ago.beginning_of_day)
+ stale_annotations.delete_with_limit(DELETE_LIMIT)
+
+ self.class.perform_async if stale_annotations.exists?
+ end
+ end
+ end
+end
diff --git a/app/workers/metrics/dashboard/schedule_annotations_prune_worker.rb b/app/workers/metrics/dashboard/schedule_annotations_prune_worker.rb
new file mode 100644
index 00000000000..cbdd69c6e8c
--- /dev/null
+++ b/app/workers/metrics/dashboard/schedule_annotations_prune_worker.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Metrics
+ module Dashboard
+ class ScheduleAnnotationsPruneWorker
+ include ApplicationWorker
+ # rubocop:disable Scalability/CronWorkerContext
+ # This worker does not perform work scoped to a context
+ include CronjobQueue
+ # rubocop:enable Scalability/CronWorkerContext
+
+ feature_category :metrics
+
+ idempotent! # PruneOldAnnotationsWorker worker is idempotent in the scope of 24 hours
+
+ def perform
+ # Process is split into two jobs to avoid long running jobs, which are more prone to be disrupted
+ # mid work, which may cause some data not be delete, especially because cronjobs has retry option disabled
+ PruneOldAnnotationsWorker.perform_async
+ end
+ end
+ end
+end
diff --git a/app/workers/remove_expired_group_links_worker.rb b/app/workers/remove_expired_group_links_worker.rb
index 0dc46cd2b9b..4c6eb821dfe 100644
--- a/app/workers/remove_expired_group_links_worker.rb
+++ b/app/workers/remove_expired_group_links_worker.rb
@@ -7,7 +7,9 @@ class RemoveExpiredGroupLinksWorker # rubocop:disable Scalability/IdempotentWork
feature_category :authentication_and_authorization
def perform
- ProjectGroupLink.expired.destroy_all # rubocop: disable Cop/DestroyAll
+ ProjectGroupLink.expired.find_each do |link|
+ Projects::GroupLinks::DestroyService.new(link.project, nil).execute(link)
+ end
GroupGroupLink.expired.find_in_batches do |link_batch|
Groups::GroupLinks::DestroyService.new(nil, nil).execute(link_batch)