diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-02 18:06:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-02 18:06:36 +0300 |
commit | 556c79d6cc3d7b24ecbba3a79f8432eb3fcf5c7e (patch) | |
tree | 93c84c603316cdee73ce85949ba70e29ef78af32 /app | |
parent | bffcdf9bca11a4d43cc40e3f382f03088d36f7c6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/broadcast_messages_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/admin/identities_controller.rb | 6 | ||||
-rw-r--r-- | app/helpers/broadcast_messages_helper.rb | 4 | ||||
-rw-r--r-- | app/models/broadcast_message.rb | 10 | ||||
-rw-r--r-- | app/models/merge_request/pipelines.rb | 60 | ||||
-rw-r--r-- | app/services/repair_ldap_blocked_user_service.rb | 19 | ||||
-rw-r--r-- | app/services/users/repair_ldap_blocked_service.rb | 21 | ||||
-rw-r--r-- | app/views/admin/broadcast_messages/_form.html.haml | 7 | ||||
-rw-r--r-- | app/views/admin/broadcast_messages/index.html.haml | 3 | ||||
-rw-r--r-- | app/views/layouts/_broadcast.html.haml | 2 |
10 files changed, 89 insertions, 44 deletions
diff --git a/app/controllers/admin/broadcast_messages_controller.rb b/app/controllers/admin/broadcast_messages_controller.rb index 6e5dd1a1f55..63fff821871 100644 --- a/app/controllers/admin/broadcast_messages_controller.rb +++ b/app/controllers/admin/broadcast_messages_controller.rb @@ -60,6 +60,7 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController font message starts_at + target_path )) end end diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb index 8f2e34a6294..327538f1e93 100644 --- a/app/controllers/admin/identities_controller.rb +++ b/app/controllers/admin/identities_controller.rb @@ -28,7 +28,8 @@ class Admin::IdentitiesController < Admin::ApplicationController def update if @identity.update(identity_params) - RepairLdapBlockedUserService.new(@user).execute + ::Users::RepairLdapBlockedService.new(@user).execute + redirect_to admin_user_identities_path(@user), notice: _('User identity was successfully updated.') else render :edit @@ -37,7 +38,8 @@ class Admin::IdentitiesController < Admin::ApplicationController def destroy if @identity.destroy - RepairLdapBlockedUserService.new(@user).execute + ::Users::RepairLdapBlockedService.new(@user).execute + redirect_to admin_user_identities_path(@user), status: :found, notice: _('User identity was successfully removed.') else redirect_to admin_user_identities_path(@user), status: :found, alert: _('Failed to remove user identity.') diff --git a/app/helpers/broadcast_messages_helper.rb b/app/helpers/broadcast_messages_helper.rb index 495c29d3e24..ec653aed91b 100644 --- a/app/helpers/broadcast_messages_helper.rb +++ b/app/helpers/broadcast_messages_helper.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true module BroadcastMessagesHelper + def current_broadcast_messages + BroadcastMessage.current(request.path) + end + def broadcast_message(message) return unless message.present? diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb index dfcf28763ee..9c2ae92071d 100644 --- a/app/models/broadcast_message.rb +++ b/app/models/broadcast_message.rb @@ -20,7 +20,7 @@ class BroadcastMessage < ApplicationRecord after_commit :flush_redis_cache - def self.current + def self.current(current_path = nil) messages = cache.fetch(CACHE_KEY, as: BroadcastMessage, expires_in: cache_expires_in) do current_and_future_messages end @@ -33,7 +33,7 @@ class BroadcastMessage < ApplicationRecord # cache so we don't keep running this code all the time. cache.expire(CACHE_KEY) if now_or_future.empty? - now_or_future.select(&:now?) + now_or_future.select(&:now?).select { |message| message.matches_current_path(current_path) } end def self.current_and_future_messages @@ -72,6 +72,12 @@ class BroadcastMessage < ApplicationRecord now? || future? end + def matches_current_path(current_path) + return true if current_path.blank? || target_path.blank? + + current_path.match(Regexp.escape(target_path).gsub('\\*', '.*')) + end + def flush_redis_cache self.class.cache.expire(CACHE_KEY) end diff --git a/app/models/merge_request/pipelines.rb b/app/models/merge_request/pipelines.rb index cba38f781a6..c32f29a9304 100644 --- a/app/models/merge_request/pipelines.rb +++ b/app/models/merge_request/pipelines.rb @@ -12,15 +12,18 @@ class MergeRequest::Pipelines attr_reader :merge_request - delegate :all_commit_shas, :source_project, :source_branch, to: :merge_request + delegate :commit_shas, :source_project, :source_branch, to: :merge_request def all - return Ci::Pipeline.none unless source_project - strong_memoize(:all_pipelines) do - pipelines = Ci::Pipeline.from_union( - [source_pipelines, detached_pipelines, triggered_for_branch], - remove_duplicates: false) + next Ci::Pipeline.none unless source_project + + pipelines = + if merge_request.persisted? + pipelines_using_cte + else + triggered_for_branch.for_sha(commit_shas) + end sort(pipelines) end @@ -28,38 +31,55 @@ class MergeRequest::Pipelines private - def triggered_by_merge_request - source_project.ci_pipelines - .where(source: :merge_request_event, merge_request: merge_request) + def pipelines_using_cte + cte = Gitlab::SQL::CTE.new(:shas, merge_request.all_commits.select(:sha)) + + source_pipelines_join = cte.table[:sha].eq(Ci::Pipeline.arel_table[:source_sha]) + source_pipelines = filter_by(triggered_by_merge_request, cte, source_pipelines_join) + detached_pipelines = filter_by_sha(triggered_by_merge_request, cte) + pipelines_for_branch = filter_by_sha(triggered_for_branch, cte) + + Ci::Pipeline.with(cte.to_arel) + .from_union([source_pipelines, detached_pipelines, pipelines_for_branch]) + end + + def filter_by_sha(pipelines, cte) + hex = Arel::Nodes::SqlLiteral.new("'hex'") + string_sha = Arel::Nodes::NamedFunction.new('encode', [cte.table[:sha], hex]) + join_condition = string_sha.eq(Ci::Pipeline.arel_table[:sha]) + + filter_by(pipelines, cte, join_condition) end - def detached_pipelines - triggered_by_merge_request.for_sha(all_commit_shas) + def filter_by(pipelines, cte, join_condition) + shas_table = + Ci::Pipeline.arel_table + .join(cte.table, Arel::Nodes::InnerJoin) + .on(join_condition) + .join_sources + + pipelines.joins(shas_table) end - def source_pipelines - triggered_by_merge_request.for_source_sha(all_commit_shas) + def triggered_by_merge_request + source_project.ci_pipelines + .where(source: :merge_request_event, merge_request: merge_request) end def triggered_for_branch source_project.ci_pipelines .where(source: branch_pipeline_sources, ref: source_branch, tag: false) - .for_sha(all_commit_shas) - end - - def sources - ::Ci::Pipeline.sources end def branch_pipeline_sources strong_memoize(:branch_pipeline_sources) do - sources.reject { |source| source == EVENT }.values + Ci::Pipeline.sources.reject { |source| source == EVENT }.values end end def sort(pipelines) sql = 'CASE ci_pipelines.source WHEN (?) THEN 0 ELSE 1 END, ci_pipelines.id DESC' - query = ApplicationRecord.send(:sanitize_sql_array, [sql, sources[:merge_request_event]]) # rubocop:disable GitlabSecurity/PublicSend + query = ApplicationRecord.send(:sanitize_sql_array, [sql, Ci::Pipeline.sources[:merge_request_event]]) # rubocop:disable GitlabSecurity/PublicSend pipelines.order(Arel.sql(query)) end diff --git a/app/services/repair_ldap_blocked_user_service.rb b/app/services/repair_ldap_blocked_user_service.rb deleted file mode 100644 index 6ed42054ac3..00000000000 --- a/app/services/repair_ldap_blocked_user_service.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RepairLdapBlockedUserService - attr_accessor :user - - def initialize(user) - @user = user - end - - def execute - user.block if ldap_hard_blocked? - end - - private - - def ldap_hard_blocked? - user.ldap_blocked? && !user.ldap_user? - end -end diff --git a/app/services/users/repair_ldap_blocked_service.rb b/app/services/users/repair_ldap_blocked_service.rb new file mode 100644 index 00000000000..378145a65b3 --- /dev/null +++ b/app/services/users/repair_ldap_blocked_service.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Users + class RepairLdapBlockedService + attr_accessor :user + + def initialize(user) + @user = user + end + + def execute + user.block if ldap_hard_blocked? + end + + private + + def ldap_hard_blocked? + user.ldap_blocked? && !user.ldap_user? + end + end +end diff --git a/app/views/admin/broadcast_messages/_form.html.haml b/app/views/admin/broadcast_messages/_form.html.haml index 962234d3aea..03b7ae76de9 100644 --- a/app/views/admin/broadcast_messages/_form.html.haml +++ b/app/views/admin/broadcast_messages/_form.html.haml @@ -40,6 +40,13 @@ = f.color_field :font, class: "form-control text-font-color" .form-group.row .col-sm-2.col-form-label + = f.label :target_path, _('Target Path') + .col-sm-10 + = f.text_field :target_path, class: "form-control" + .form-text.text-muted + = _('Paths can contain wildcards, like */welcome') + .form-group.row + .col-sm-2.col-form-label = f.label :starts_at, _("Starts at (UTC)") .col-sm-10.datetime-controls = f.datetime_select :starts_at, {}, class: 'form-control form-control-inline' diff --git a/app/views/admin/broadcast_messages/index.html.haml b/app/views/admin/broadcast_messages/index.html.haml index eb4dfdf2858..4731421fd9e 100644 --- a/app/views/admin/broadcast_messages/index.html.haml +++ b/app/views/admin/broadcast_messages/index.html.haml @@ -19,6 +19,7 @@ %th Preview %th Starts %th Ends + %th Target Path %th %tbody - @broadcast_messages.each do |message| @@ -32,6 +33,8 @@ %td = message.ends_at %td + = message.target_path + %td = link_to sprite_icon('pencil-square'), edit_admin_broadcast_message_path(message), title: 'Edit', class: 'btn' = link_to sprite_icon('remove'), admin_broadcast_message_path(message), method: :delete, remote: true, title: 'Remove', class: 'js-remove-tr btn btn-danger' diff --git a/app/views/layouts/_broadcast.html.haml b/app/views/layouts/_broadcast.html.haml index e2dbdcbb939..ee3ca824342 100644 --- a/app/views/layouts/_broadcast.html.haml +++ b/app/views/layouts/_broadcast.html.haml @@ -1,2 +1,2 @@ -- BroadcastMessage.current&.each do |message| +- current_broadcast_messages&.each do |message| = broadcast_message(message) |