Commit 3771be00 authored by Nick Thomas's avatar Nick Thomas

Merge remote-tracking branch 'ce/master' into ce-to-ee-2017-08-03

parents 2670b34f 990feb9f
...@@ -326,11 +326,11 @@ group :development, :test do ...@@ -326,11 +326,11 @@ group :development, :test do
gem 'pry-rails', '~> 0.3.4' gem 'pry-rails', '~> 0.3.4'
gem 'awesome_print', '~> 1.2.0', require: false gem 'awesome_print', '~> 1.2.0', require: false
gem 'fuubar', '~> 2.0.0' gem 'fuubar', '~> 2.2.0'
gem 'database_cleaner', '~> 1.5.0' gem 'database_cleaner', '~> 1.5.0'
gem 'factory_girl_rails', '~> 4.7.0' gem 'factory_girl_rails', '~> 4.7.0'
gem 'rspec-rails', '~> 3.5.0' gem 'rspec-rails', '~> 3.6.0'
gem 'rspec-retry', '~> 0.4.5' gem 'rspec-retry', '~> 0.4.5'
gem 'spinach-rails', '~> 0.2.1' gem 'spinach-rails', '~> 0.2.1'
gem 'spinach-rerun-reporter', '~> 0.0.2' gem 'spinach-rerun-reporter', '~> 0.0.2'
......
...@@ -164,7 +164,7 @@ GEM ...@@ -164,7 +164,7 @@ GEM
devise (~> 4.0) devise (~> 4.0)
railties railties
rotp (~> 2.0) rotp (~> 2.0)
diff-lcs (1.2.5) diff-lcs (1.3)
diffy (3.1.0) diffy (3.1.0)
docile (1.1.5) docile (1.1.5)
domain_name (0.5.20161021) domain_name (0.5.20161021)
...@@ -274,8 +274,8 @@ GEM ...@@ -274,8 +274,8 @@ GEM
foreman (0.78.0) foreman (0.78.0)
thor (~> 0.19.1) thor (~> 0.19.1)
formatador (0.2.5) formatador (0.2.5)
fuubar (2.0.0) fuubar (2.2.0)
rspec (~> 3.0) rspec-core (~> 3.0)
ruby-progressbar (~> 1.4) ruby-progressbar (~> 1.4)
gemnasium-gitlab-service (0.2.6) gemnasium-gitlab-service (0.2.6)
rugged (~> 0.21) rugged (~> 0.21)
...@@ -420,7 +420,7 @@ GEM ...@@ -420,7 +420,7 @@ GEM
json (~> 1.8) json (~> 1.8)
multi_xml (>= 0.5.2) multi_xml (>= 0.5.2)
httpclient (2.8.2) httpclient (2.8.2)
i18n (0.8.1) i18n (0.8.6)
ice_nine (0.11.2) ice_nine (0.11.2)
influxdb (0.2.3) influxdb (0.2.3)
cause cause
...@@ -639,7 +639,7 @@ GEM ...@@ -639,7 +639,7 @@ GEM
pry-rails (0.3.5) pry-rails (0.3.5)
pry (>= 0.9.10) pry (>= 0.9.10)
pyu-ruby-sasl (0.0.3.3) pyu-ruby-sasl (0.0.3.3)
rack (1.6.5) rack (1.6.8)
rack-accept (0.4.5) rack-accept (0.4.5)
rack (>= 0.4) rack (>= 0.4)
rack-attack (4.4.1) rack-attack (4.4.1)
...@@ -687,7 +687,7 @@ GEM ...@@ -687,7 +687,7 @@ GEM
rainbow (2.2.2) rainbow (2.2.2)
rake rake
raindrops (0.18.0) raindrops (0.18.0)
rake (10.5.0) rake (12.0.0)
rblineprof (0.3.6) rblineprof (0.3.6)
debugger-ruby_core_source (~> 1.3) debugger-ruby_core_source (~> 1.3)
rdoc (4.2.2) rdoc (4.2.2)
...@@ -731,30 +731,26 @@ GEM ...@@ -731,30 +731,26 @@ GEM
chunky_png chunky_png
rqrcode-rails3 (0.1.7) rqrcode-rails3 (0.1.7)
rqrcode (>= 0.4.2) rqrcode (>= 0.4.2)
rspec (3.5.0) rspec-core (3.6.0)
rspec-core (~> 3.5.0) rspec-support (~> 3.6.0)
rspec-expectations (~> 3.5.0) rspec-expectations (3.6.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.0)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0) rspec-support (~> 3.6.0)
rspec-mocks (3.5.0) rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0) rspec-support (~> 3.6.0)
rspec-rails (3.5.0) rspec-rails (3.6.0)
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
railties (>= 3.0) railties (>= 3.0)
rspec-core (~> 3.5.0) rspec-core (~> 3.6.0)
rspec-expectations (~> 3.5.0) rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.5.0) rspec-mocks (~> 3.6.0)
rspec-support (~> 3.5.0) rspec-support (~> 3.6.0)
rspec-retry (0.4.5) rspec-retry (0.4.5)
rspec-core rspec-core
rspec-set (0.1.3) rspec-set (0.1.3)
rspec-support (3.5.0) rspec-support (3.6.0)
rspec_profiling (0.0.5) rspec_profiling (0.0.5)
activerecord activerecord
pg pg
...@@ -889,7 +885,7 @@ GEM ...@@ -889,7 +885,7 @@ GEM
truncato (0.7.8) truncato (0.7.8)
htmlentities (~> 4.3.1) htmlentities (~> 4.3.1)
nokogiri (~> 1.6.1) nokogiri (~> 1.6.1)
tzinfo (1.2.2) tzinfo (1.2.3)
thread_safe (~> 0.1) thread_safe (~> 0.1)
u2f (0.2.1) u2f (0.2.1)
uglifier (2.7.2) uglifier (2.7.2)
...@@ -1006,7 +1002,7 @@ DEPENDENCIES ...@@ -1006,7 +1002,7 @@ DEPENDENCIES
fog-rackspace (~> 0.1.1) fog-rackspace (~> 0.1.1)
font-awesome-rails (~> 4.7) font-awesome-rails (~> 4.7)
foreman (~> 0.78.0) foreman (~> 0.78.0)
fuubar (~> 2.0.0) fuubar (~> 2.2.0)
gemnasium-gitlab-service (~> 0.2) gemnasium-gitlab-service (~> 0.2)
gemojione (~> 3.0) gemojione (~> 3.0)
gettext (~> 3.2.2) gettext (~> 3.2.2)
...@@ -1113,7 +1109,7 @@ DEPENDENCIES ...@@ -1113,7 +1109,7 @@ DEPENDENCIES
responders (~> 2.0) responders (~> 2.0)
rouge (~> 2.0) rouge (~> 2.0)
rqrcode-rails3 (~> 0.1.7) rqrcode-rails3 (~> 0.1.7)
rspec-rails (~> 3.5.0) rspec-rails (~> 3.6.0)
rspec-retry (~> 0.4.5) rspec-retry (~> 0.4.5)
rspec-set (~> 0.1.3) rspec-set (~> 0.1.3)
rspec_profiling (~> 0.0.5) rspec_profiling (~> 0.0.5)
...@@ -1167,4 +1163,4 @@ DEPENDENCIES ...@@ -1167,4 +1163,4 @@ DEPENDENCIES
wikicloth (= 0.8.1) wikicloth (= 0.8.1)
BUNDLED WITH BUNDLED WITH
1.15.1 1.15.3
...@@ -10,7 +10,7 @@ class AjaxLoadingSpinner { ...@@ -10,7 +10,7 @@ class AjaxLoadingSpinner {
e.target.setAttribute('disabled', ''); e.target.setAttribute('disabled', '');
const iconElement = e.target.querySelector('i'); const iconElement = e.target.querySelector('i');
// get first fa- icon // get first fa- icon
const originalIcon = iconElement.className.match(/(fa-)([^\s]+)/g).first(); const originalIcon = iconElement.className.match(/(fa-)([^\s]+)/g)[0];
iconElement.dataset.icon = originalIcon; iconElement.dataset.icon = originalIcon;
AjaxLoadingSpinner.toggleLoadingIcon(iconElement); AjaxLoadingSpinner.toggleLoadingIcon(iconElement);
$(e.target).off('ajax:beforeSend', AjaxLoadingSpinner.ajaxBeforeSend); $(e.target).off('ajax:beforeSend', AjaxLoadingSpinner.ajaxBeforeSend);
......
...@@ -92,7 +92,7 @@ $(() => { ...@@ -92,7 +92,7 @@ $(() => {
}); });
}, },
selectDefaultStage() { selectDefaultStage() {
const stage = this.state.stages.first(); const stage = this.state.stages[0];
this.selectStage(stage); this.selectStage(stage);
}, },
selectStage(stage) { selectStage(stage) {
......
...@@ -575,7 +575,7 @@ import initGroupAnalytics from './init_group_analytics'; ...@@ -575,7 +575,7 @@ import initGroupAnalytics from './init_group_analytics';
initGroupAnalytics(); initGroupAnalytics();
break; break;
} }
switch (path.first()) { switch (path[0]) {
case 'sessions': case 'sessions':
case 'omniauth_callbacks': case 'omniauth_callbacks':
if (!gon.u2f) break; if (!gon.u2f) break;
......
...@@ -217,7 +217,7 @@ window.DropzoneInput = (function() { ...@@ -217,7 +217,7 @@ window.DropzoneInput = (function() {
value = e.clipboardData.getData('text/plain'); value = e.clipboardData.getData('text/plain');
} }
value = value.split("\r"); value = value.split("\r");
return value.first(); return value[0];
}; };
const showSpinner = function(e) { const showSpinner = function(e) {
......
// TODO: remove this
// eslint-disable-next-line no-extend-native
Array.prototype.first = function first() {
return this[0];
};
// eslint-disable-next-line no-extend-native
Array.prototype.last = function last() {
return this[this.length - 1];
};
...@@ -123,11 +123,11 @@ class DropdownUtils { ...@@ -123,11 +123,11 @@ class DropdownUtils {
if (!allowMultiple && itemInExistingTokens) { if (!allowMultiple && itemInExistingTokens) {
updatedItem.droplab_hidden = true; updatedItem.droplab_hidden = true;
} else if (!lastKey || searchInput.split('').last() === ' ') { } else if (!lastKey || _.last(searchInput.split('')) === ' ') {
updatedItem.droplab_hidden = false; updatedItem.droplab_hidden = false;
} else if (lastKey) { } else if (lastKey) {
const split = lastKey.split(':'); const split = lastKey.split(':');
const tokenName = split[0].split(' ').last(); const tokenName = _.last(split[0].split(' '));
const match = updatedItem.hint.indexOf(tokenName.toLowerCase()) === -1; const match = updatedItem.hint.indexOf(tokenName.toLowerCase()) === -1;
updatedItem.droplab_hidden = tokenName ? match : false; updatedItem.droplab_hidden = tokenName ? match : false;
......
...@@ -179,7 +179,7 @@ class FilteredSearchDropdownManager { ...@@ -179,7 +179,7 @@ class FilteredSearchDropdownManager {
// Eg. token = 'label:' // Eg. token = 'label:'
const split = lastToken.split(':'); const split = lastToken.split(':');
const dropdownName = split[0].split(' ').last(); const dropdownName = _.last(split[0].split(' '));
this.loadDropdown(split.length > 1 ? dropdownName : ''); this.loadDropdown(split.length > 1 ? dropdownName : '');
} else if (lastToken) { } else if (lastToken) {
// Token has been initialized into an object because it has a value // Token has been initialized into an object because it has a value
......
...@@ -375,7 +375,7 @@ class FilteredSearchManager { ...@@ -375,7 +375,7 @@ class FilteredSearchManager {
const fragments = searchToken.split(':'); const fragments = searchToken.split(':');
if (fragments.length > 1) { if (fragments.length > 1) {
const inputValues = fragments[0].split(' '); const inputValues = fragments[0].split(' ');
const tokenKey = inputValues.last(); const tokenKey = _.last(inputValues);
if (inputValues.length > 1) { if (inputValues.length > 1) {
inputValues.pop(); inputValues.pop();
......
...@@ -16,9 +16,6 @@ import 'mousetrap'; ...@@ -16,9 +16,6 @@ import 'mousetrap';
import 'mousetrap/plugins/pause/mousetrap-pause'; import 'mousetrap/plugins/pause/mousetrap-pause';
import 'vendor/fuzzaldrin-plus'; import 'vendor/fuzzaldrin-plus';
// extensions
import './extensions/array';
// expose common libraries as globals (TODO: remove these) // expose common libraries as globals (TODO: remove these)
window.jQuery = jQuery; window.jQuery = jQuery;
window.$ = jQuery; window.$ = jQuery;
......
class NotificationRecipient
attr_reader :user, :type
def initialize(
user, type,
custom_action: nil,
target: nil,
acting_user: nil,
project: nil
)
@custom_action = custom_action
@acting_user = acting_user
@target = target
@project = project || @target&.project
@user = user
@type = type
end
def notification_setting
@notification_setting ||= find_notification_setting
end
def raw_notification_level
notification_setting&.level&.to_sym
end
def notification_level
# custom is treated the same as watch if it's enabled - otherwise it's
# set to :custom, meaning to send exactly when our type is :participating
# or :mention.
@notification_level ||=
case raw_notification_level
when :custom
if @custom_action && notification_setting&.event_enabled?(@custom_action)
:watch
else
:custom
end
else
raw_notification_level
end
end
def notifiable?
return false unless has_access?
return false if own_activity?
return true if @type == :subscription
return false if notification_level.nil? || notification_level == :disabled
return %i[participating mention].include?(@type) if notification_level == :custom
return false if %i[watch participating].include?(notification_level) && excluded_watcher_action?
return false unless NotificationSetting.levels[notification_level] <= NotificationSetting.levels[@type]
return false if unsubscribed?
true
end
def unsubscribed?
return false unless @target
return false unless @target.respond_to?(:subscriptions)
subscription = @target.subscriptions.find_by_user_id(@user.id)
subscription && !subscription.subscribed
end
def own_activity?
return false unless @acting_user
return false if @acting_user.notified_of_own_activity?
user == @acting_user
end
def has_access?
DeclarativePolicy.subject_scope do
return false unless user.can?(:receive_notifications)
return false if @project && !user.can?(:read_project, @project)
return true unless read_ability
return true unless DeclarativePolicy.has_policy?(@target)
user.can?(read_ability, @target)
end
end
def excluded_watcher_action?
return false unless @custom_action
return false if raw_notification_level == :custom
NotificationSetting::EXCLUDED_WATCHER_EVENTS.include?(@custom_action)
end
private
def read_ability
return @read_ability if instance_variable_defined?(:@read_ability)
@read_ability =
case @target
when Issuable
:"read_#{@target.to_ability_name}"
when Ci::Pipeline
:read_build # We have build trace in pipeline emails
when ActiveRecord::Base
:"read_#{@target.class.model_name.name.underscore}"
else
nil
end
end
def find_notification_setting
project_setting = @project && user.notification_settings_for(@project)
return project_setting unless project_setting.nil? || project_setting.global?
group_setting = @project&.group && user.notification_settings_for(@project.group)
return group_setting unless group_setting.nil? || group_setting.global?
user.global_notification_setting
end
end
...@@ -104,7 +104,7 @@ class JiraService < IssueTrackerService ...@@ -104,7 +104,7 @@ class JiraService < IssueTrackerService
def close_issue(entity, external_issue) def close_issue(entity, external_issue)
issue = jira_request { client.Issue.find(external_issue.iid) } issue = jira_request { client.Issue.find(external_issue.iid) }
return if issue.nil? || issue.resolution.present? || !jira_issue_transition_id.present? return if issue.nil? || has_resolution?(issue) || !jira_issue_transition_id.present?
commit_id = if entity.is_a?(Commit) commit_id = if entity.is_a?(Commit)
entity.id entity.id
...@@ -118,7 +118,7 @@ class JiraService < IssueTrackerService ...@@ -118,7 +118,7 @@ class JiraService < IssueTrackerService
# may or may not be allowed. Refresh the issue after transition and check # may or may not be allowed. Refresh the issue after transition and check
# if it is closed, so we don't have one comment for every commit. # if it is closed, so we don't have one comment for every commit.
issue = jira_request { client.Issue.find(issue.key) } if transition_issue(issue) issue = jira_request { client.Issue.find(issue.key) } if transition_issue(issue)
add_issue_solved_comment(issue, commit_id, commit_url) if issue.resolution add_issue_solved_comment(issue, commit_id, commit_url) if has_resolution?(issue)
end end
def create_cross_reference_note(mentioned, noteable, author) def create_cross_reference_note(mentioned, noteable, author)
...@@ -216,6 +216,10 @@ class JiraService < IssueTrackerService ...@@ -216,6 +216,10 @@ class JiraService < IssueTrackerService
end end
end end
def has_resolution?(issue)
issue.respond_to?(:resolution) && issue.resolution.present?
end
def comment_exists?(issue, message) def comment_exists?(issue, message)
comments = jira_request { issue.comments } comments = jira_request { issue.comments }
......
# #
# Used by NotificationService to determine who should receive notification # Used by NotificationService to determine who should receive notification
# #
class NotificationRecipientService module NotificationRecipientService
attr_reader :project def self.notifiable_users(users, *args)
users.compact.map { |u| NotificationRecipient.new(u, *args) }.select(&:notifiable?).map(&:user)
def initialize(project)
@project = project
end end
def build_recipients(target, current_user, action:, previous_assignee: nil, skip_current_user: true) def self.notifiable?(user, *args)
custom_action = build_custom_key(action, target) NotificationRecipient.new(user, *args).notifiable?
end
recipients = participants(target, current_user)
recipients = add_project_watchers(recipients)
recipients = add_custom_notifications(recipients, custom_action)
recipients = reject_mention_users(recipients)
# Re-assign is considered as a mention of the new assignee so we add the
# new assignee to the list of recipients after we rejected users with
# the "on mention" notification level
case custom_action
when :reassign_merge_request
recipients << previous_assignee if previous_assignee
recipients << target.assignee
when :reassign_issue
previous_assignees = Array(previous_assignee)
recipients.concat(previous_assignees)
recipients.concat(target.assignees)
end
recipients = reject_muted_users(recipients)
recipients = add_subscribed_users(recipients, target)
if [:new_issue, :new_merge_request].include?(custom_action)
recipients = add_labels_subscribers(recipients, target)
end
recipients = reject_unsubscribed_users(recipients, target)
recipients = reject_users_without_access(recipients, target)
recipients.delete(current_user) if skip_current_user && !current_user.notified_of_own_activity? def self.build_recipients(*a)
Builder::Default.new(*a).recipient_users
end
recipients.uniq def self.build_new_note_recipients(*a)
Builder::NewNote.new(*a).recipient_users
end end
def build_pipeline_recipients(target, current_user, action:) module Builder
return [] unless current_user class Base
def initialize(*)
raise 'abstract'
end
custom_action = def build!
case action.to_s raise 'abstract'
when 'failed'
:failed_pipeline
when 'success'
:success_pipeline
end end
notification_setting = notification_setting_for_user_project(current_user, target.project) def filter!
recipients.select!(&:notifiable?)
end
return [] if notification_setting.mention? || notification_setting.disabled? def acting_user
current_user
end
return [] if notification_setting.custom? && !notification_setting.event_enabled?(custom_action) def target
raise 'abstract'
end
return [] if (notification_setting.watch? || notification_setting.participating?) && NotificationSetting::EXCLUDED_WATCHER_EVENTS.include?(custom_action) # rubocop:disable Rails/Delegate
def project
target.project
end
reject_users_without_access([current_user], target) def recipients
end @recipients ||= []
end
def build_relabeled_recipients(target, current_user, labels:) def <<(pair)
recipients = add_labels_subscribers([], target, labels: labels) users, type = pair
recipients = reject_unsubscribed_users(recipients, target)
recipients = reject_users_without_access(recipients, target)
recipients.delete(current_user) unless current_user.notified_of_own_activity?
recipients.uniq
end
def build_new_note_recipients(note) if users.is_a?(ActiveRecord::Relation)
target = note.noteable users = users.includes(:notification_settings)
end
ability, subject = if note.for_personal_snippet? users = Array(users)
[:read_personal_snippet, note.noteable] users.compact!
else recipients.concat(users.map { |u| make_recipient(u, type) })
[:read_project, note.project] end
end
mentioned_users = note.mentioned_users.select { |user| user.can?(ability, subject) } def user_scope
User.includes(:notification_settings)
end
# Add all users participating in the thread (author, assignee, comment authors) def make_recipient(user, type)
recipients = participants(target, note.author) || mentioned_users NotificationRecipient.new(
user, type,
project: project,
custom_action: custom_action,
target: target,
acting_user: acting_user
)
end
unless note.for_personal_snippet? def recipient_users
# Merge project watchers @recipient_users ||=
recipients = add_project_watchers(recipients) begin
build!
filter!
users = recipients.map(&:user)
users.uniq!
users.freeze
end
end
# Merge project with custom notification def custom_action
recipients = add_custom_notifications(recipients, :new_note) nil
end end
# Reject users with Mention notification level, except those mentioned in _this_ note. protected
recipients = reject_mention_users(recipients - mentioned_users)
recipients = recipients + mentioned_users
recipients = reject_muted_users(recipients) def add_participants(user)
return unless target.respond_to?(:participants)
recipients = add_subscribed_users(recipients, note.noteable) self << [target.participants(user), :watch]
recipients = reject_unsubscribed_users(recipients, note.noteable) end
recipients = reject_users_without_access(recipients, note.noteable)
recipients.delete(note.author) unless note.author.notified_of_own_activity? # Get project/group users with CUSTOM notification level
recipients.uniq def add_custom_notifications
end user_ids = []
# Remove users with disabled notifications from array # Users with a notification setting on group or project
# Also remove duplications and nil recipients user_ids += user_ids_notifiable_on(project, :custom)
def reject_muted_users(users) user_ids += user_ids_notifiable_on(project.group, :custom)
reject_users(users, :disabled)
end
protected # Users with global level custom
user_ids_with_project_level_global = user_ids_notifiable_on(project, :global)
user_ids_with_group_level_global = user_ids_notifiable_on(project.group, :global)
# Ensure that if we modify this array, we aren't modifying the memoised global_users_ids = user_ids_with_project_level_global.concat(user_ids_with_group_level_global)
# participants on the target. user_ids += user_ids_with_global_level_custom(global_users_ids, custom_action)
def participants(target, user)
return unless target.respond_to?(:participants)
target.participants(user).dup self << [user_scope.where(id: user_ids), :watch]
end end
# Get project/group users with CUSTOM notification level def add_project_watchers
def add_custom_notifications(recipients, action) self << [project_watchers, :watch]
user_ids = [] end
# Users with a notification setting on group or project # Get project users with WATCH notification level
user_ids += user_ids_notifiable_on(project, :custom, action) def project_watchers
user_ids += user_ids_notifiable_on(project.group, :custom, action) project_members_ids = user_ids_notifiable_on(project)
# Users with global level custom user_ids_with_project_global = user_ids_notifiable_on(project, :global)
user_ids_with_project_level_global = user_ids_notifiable_on(project, :global) user_ids_with_group_global = user_ids_notifiable_on(project.group, :global)
user_ids_with_group_level_global = user_ids_notifiable_on(project.group, :global)
global_users_ids = user_ids_with_project_level_global.concat(user_ids_with_group_level_global) user_ids = user_ids_with_global_level_watch((user_ids_with_project_global + user_ids_with_group_global).uniq)
user_ids += user_ids_with_global_level_custom(global_users_ids, action)
recipients.concat(User.find(user_ids)) user_ids_with_project_setting = select_project_members_ids(user_ids_with_project_global, user_ids)
end user_ids_with_group_setting = select_group_members_ids(project.group, project_members_ids, user_ids_with_group_global, user_ids)
def add_project_watchers(recipients) user_scope.where(id: user_ids_with_project_setting.concat(user_ids_with_group_setting).uniq)
recipients.concat(project_watchers).compact end
end
# Get project users with WATCH notification level def add_subscribed_users
def project_watchers return unless target.respond_to? :subscribers
project_members_ids = user_ids_notifiable_on(project)
user_ids_with_project_global = user_ids_notifiable_on(project, :global) self << [target.subscribers(project), :subscription]
user_ids_with_group_global = user_ids_notifiable_on(project.group, :global) end
user_ids = user_ids_with_global_level_watch((user_ids_with_project_global + user_ids_with_group_global).uniq) def user_ids_notifiable_on(resource, notification_level = nil)
return [] unless resource
user_ids_with_project_setting = select_project_members_ids(project, user_ids_with_project_global, user_ids) scope = resource.notification_settings
user_ids_with_group_setting = select_group_members_ids(project.group, project_members_ids, user_ids_with_group_global, user_ids)
User.where(id: user_ids_with_project_setting.concat(user_ids_with_group_setting).uniq).to_a if notification_level
end scope = scope.where(level: NotificationSetting.levels[notification_level])
end
# Remove users with notification level 'Mentioned' scope.pluck(:user_id)
def reject_mention_users(users) end
reject_users(users, :mention)
end
def add_subscribed_users(recipients, target) # Build a list of user_ids based on project notification settings
return recipients unless target.respond_to? :subscribers def select_project_members_ids(global_setting, user_ids_global_level_watch)
user_ids = user_ids_notifiable_on(project, :watch)
recipients + target.subscribers(project) # If project setting is global, add to watch list if global setting is watch
end user_ids + (global_setting & user_ids_global_level_watch)
end
def user_ids_notifiable_on(resource, notification_level = nil, action = nil) # Build a list of user_ids based on group notification settings
return [] unless resource def select_group_members_ids(group, project_members, global_setting, user_ids_global_level_watch)
uids = user_ids_notifiable_on(group, :watch)
if notification_level # Group setting is global, add to user_ids list if global setting is watch
settings = resource.notification_settings.where(level: NotificationSetting.levels[notification_level]) uids + (global_setting & user_ids_global_level_watch) - project_members
settings = settings.select { |setting| setting.event_enabled?(action) } if action.present? end
settings.map(&:user_id)
else
resource.notification_settings.pluck(:user_id)
end
end
# Build a list of user_ids based on project notification settings def user_ids_with_global_level_watch(ids)
def select_project_members_ids(project, global_setting, user_ids_global_level_watch) settings_with_global_level_of(:watch, ids).pluck(:user_id)
user_ids = user_ids_notifiable_on(project, :watch) end
# If project setting is global, add to watch list if global setting is watch def user_ids_with_global_level_custom(ids, action)
global_setting.each do |user_id| settings_with_global_level_of(:custom, ids).pluck(:user_id)
if user_ids_global_level_watch.include?(user_id)
user_ids << user_id
end end
end
user_ids def settings_with_global_level_of(level, ids)
end NotificationSetting.where(
user_id: ids,
source_type: nil,
level: NotificationSetting.levels[level]
)
end
# Build a list of user_ids based on group notification settings def add_labels_subscribers(labels: nil)
def select_group_members_ids(group, project_members, global_setting, user_ids_global_level_watch) return unless target.respond_to? :labels
uids = user_ids_notifiable_on(group, :watch)
# Group setting is watch, add to user_ids list if user is not project member (labels || target.labels).each do |label|
user_ids = [] self << [label.subscribers(project), :subscription]
uids.each do |user_id| end
if project_members.exclude?(user_id)
user_ids << user_id
end end
end end
# Group setting is global, add to user_ids list if global setting is watch class Default < Base
global_setting.each do |user_id| attr_reader :target
if project_members.exclude?(user_id) && user_ids_global_level_watch.include?(user_id) attr_reader :current_user
user_ids << user_id attr_reader :action
attr_reader :previous_assignee
attr_reader :skip_current_user
def initialize(target, current_user, action:, previous_assignee: nil, skip_current_user: true)
@target = target
@current_user = current_user
@action = action
@previous_assignee = previous_assignee
@skip_current_user = skip_current_user
end end
end
user_ids
end
def user_ids_with_global_level_watch(ids)
settings_with_global_level_of(:watch, ids).pluck(:user_id)
end
def user_ids_with_global_level_custom(ids, action)
settings = settings_with_global_level_of(:custom, ids)
settings = settings.select { |setting| setting.event_enabled?(action) }
settings.map(&:user_id)
end
def settings_with_global_level_of(level, ids) def build!
NotificationSetting.where( add_participants(current_user)
user_id: ids, add_project_watchers
source_type: nil, add_custom_notifications
level: NotificationSetting.levels[level]
) # Re-assign is considered as a mention of the new assignee
end case custom_action
when :reassign_merge_request
self << [previous_assignee, :mention]
self << [target.assignee, :mention]
when :reassign_issue
previous_assignees = Array(previous_assignee)
self << [previous_assignees, :mention]
self << [target.assignees, :mention]
end
add_subscribed_users
if [:new_issue, :new_merge_request].include?(custom_action)
add_labels_subscribers
end
end
# Reject users which has certain notification level def acting_user
# current_user if skip_current_user
# Example: end
# reject_users(users, :watch, project)
#
def reject_users(users, level)
level = level.to_s
unless NotificationSetting.levels.keys.include?(level) # Build event key to search on custom notification level
raise 'Invalid notification level' # Check NotificationSetting::EMAIL_EVENTS
def custom_action
@custom_action ||= "#{action}_#{target.class.model_name.name.underscore}".to_sym
end
end end
users = users.to_a.compact.uniq class NewNote < Base
users = users.select { |u| u.can?(:receive_notifications) } attr_reader :note
def initialize(note)
users.reject do |user| @note = note
global_notification_setting = user.global_notification_setting
next global_notification_setting.level == level unless project
setting = user.notification_settings_for(project)
if project.group && (setting.nil? || setting.global?)
setting = user.notification_settings_for(project.group)
end end
# reject users who globally set mention notification and has no setting per project/group def target
next global_notification_setting.level == level unless setting note.noteable
end
# reject users who set mention notification in project
next true if setting.level == level
# reject users who have mention level in project and disabled in global settings
setting.global? && global_notification_setting.level == level
end
end
def reject_unsubscribed_users(recipients, target) # NOTE: may be nil, in the case of a PersonalSnippet
return recipients unless target.respond_to? :subscriptions #
# (this is okay because NotificationRecipient is written
# to handle nil projects)
def project
note.project
end
recipients.reject do |user| def build!
subscription = target.subscriptions.find_by_user_id(user.id) # Add all users participating in the thread (author, assignee, comment authors)
subscription && !subscription.subscribed add_participants(note.author)
end self << [note.mentioned_users, :mention]
end
def reject_users_without_access(recipients, target) unless note.for_personal_snippet?
ability = case target # Merge project watchers
when Issuable add_project_watchers
:"read_#{target.to_ability_name}"
when Ci::Pipeline
:read_build # We have build trace in pipeline emails
end
return recipients unless ability # Merge project with custom notification
add_custom_notifications
end
recipients.select do |user| add_subscribed_users
user.can?(ability, target) end
end
end
def add_labels_subscribers(recipients, target, labels: nil) def custom_action
return recipients unless target.respond_to? :labels :new_note
end
(labels || target.labels).each do |label| def acting_user
recipients += label.subscribers(project) note.author
end
end end
recipients
end
# Build event key to search on custom notification level
# Check NotificationSetting::EMAIL_EVENTS
def build_custom_key(action, object)
"#{action}_#{object.class.model_name.name.underscore}".to_sym
end
def notification_setting_for_user_project(user, project)
project_setting = user.notification_settings_for(project)
return project_setting unless project_setting.global?
group_setting = user.notification_settings_for(project.group)
return group_setting unless group_setting.global?
user.global_notification_setting
end end
end end
...@@ -44,7 +44,7 @@ class NotificationService ...@@ -44,7 +44,7 @@ class NotificationService
# * users with custom level checked with "new issue" # * users with custom level checked with "new issue"
# #
def new_issue(issue, current_user) def new_issue(issue, current_user)
new_resource_email(issue, issue.project, :new_issue_email) new_resource_email(issue, :new_issue_email)
end end
# When issue text is updated, we should send an email to: # When issue text is updated, we should send an email to:
...@@ -54,7 +54,6 @@ class NotificationService ...@@ -54,7 +54,6 @@ class NotificationService
def new_mentions_in_issue(issue, new_mentioned_users, current_user) def new_mentions_in_issue(issue, new_mentioned_users, current_user)
new_mentions_in_resource_email( new_mentions_in_resource_email(
issue, issue,
issue.project,
new_mentioned_users, new_mentioned_users,
current_user, current_user,
:new_mention_in_issue_email :new_mention_in_issue_email
...@@ -69,7 +68,7 @@ class NotificationService ...@@ -69,7 +68,7 @@ class NotificationService
# * users with custom level checked with "close issue" # * users with custom level checked with "close issue"
# #
def close_issue(issue, current_user) def close_issue(issue, current_user)
close_resource_email(issue, issue.project, current_user, :closed_issue_email) close_resource_email(issue, current_user, :closed_issue_email)
end end
# When we reassign an issue we should send an email to: # When we reassign an issue we should send an email to:
...@@ -79,7 +78,7 @@ class NotificationService ...@@ -79,7 +78,7 @@ class NotificationService
# * users with custom level checked with "reassign issue" # * users with custom level checked with "reassign issue"
# #
def reassigned_issue(issue, current_user, previous_assignees = []) def reassigned_issue(issue, current_user, previous_assignees = [])
recipients = NotificationRecipientService.new(issue.project).build_recipients( recipients = NotificationRecipientService.build_recipients(
issue, issue,
current_user, current_user,
action: "reassign", action: "reassign",
...@@ -104,7 +103,7 @@ class NotificationService ...@@ -104,7 +103,7 @@ class NotificationService
# * watchers of the issue's labels # * watchers of the issue's labels
# #
def relabeled_issue(issue, added_labels, current_user) def relabeled_issue(issue, added_labels, current_user)
relabeled_resource_email(issue, issue.project, added_labels, current_user, :relabeled_issue_email) relabeled_resource_email(issue, added_labels, current_user, :relabeled_issue_email)
end end
# When create a merge request we should send an email to: # When create a merge request we should send an email to:
...@@ -116,7 +115,7 @@ class NotificationService ...@@ -116,7 +115,7 @@ class NotificationService
# * approvers of the merge request # * approvers of the merge request
# #
def new_merge_request(merge_request, current_user) def new_merge_request(merge_request, current_user)
new_resource_email(merge_request, merge_request.target_project, :new_merge_request_email) new_resource_email(merge_request, :new_merge_request_email)
end end
# When merge request text is updated, we should send an email to: # When merge request text is updated, we should send an email to:
...@@ -126,7 +125,6 @@ class NotificationService ...@@ -126,7 +125,6 @@ class NotificationService
def new_mentions_in_merge_request(merge_request, new_mentioned_users, current_user) def new_mentions_in_merge_request(merge_request, new_mentioned_users, current_user)
new_mentions_in_resource_email( new_mentions_in_resource_email(
merge_request, merge_request,
merge_request.target_project,
new_mentioned_users, new_mentioned_users,
current_user, current_user,
:new_mention_in_merge_request_email :new_mention_in_merge_request_email
...@@ -140,7 +138,7 @@ class NotificationService ...@@ -140,7 +138,7 @@ class NotificationService
# * users with custom level checked with "reassign merge request" # * users with custom level checked with "reassign merge request"
# #
def reassigned_merge_request(merge_request, current_user) def reassigned_merge_request(merge_request, current_user)
reassign_resource_email(merge_request, merge_request.target_project, current_user, :reassigned_merge_request_email) reassign_resource_email(merge_request, current_user, :reassigned_merge_request_email)
end end
# When we add labels to a merge request we should send an email to: # When we add labels to a merge request we should send an email to:
...@@ -148,15 +146,15 @@ class NotificationService ...@@ -148,15 +146,15 @@ class NotificationService
# * watchers of the mr's labels # * watchers of the mr's labels
# #
def relabeled_merge_request(merge_request, added_labels, current_user) def relabeled_merge_request(merge_request, added_labels, current_user)
relabeled_resource_email(merge_request, merge_request.target_project, added_labels, current_user, :relabeled_merge_request_email) relabeled_resource_email(merge_request, added_labels, current_user, :relabeled_merge_request_email)
end end
def close_mr(merge_request, current_user) def close_mr(merge_request, current_user)
close_resource_email(merge_request, merge_request.target_project, current_user, :closed_merge_request_email) close_resource_email(merge_request, current_user, :closed_merge_request_email)
end end
def reopen_issue(issue, current_user) def reopen_issue(issue, current_user)
reopen_resource_email(issue, issue.project, current_user, :issue_status_changed_email, 'reopened') reopen_resource_email(issue, current_user, :issue_status_changed_email, 'reopened')
end end
# When we add approvers to a merge request we should send an email to: # When we add approvers to a merge request we should send an email to:
...@@ -170,7 +168,6 @@ class NotificationService ...@@ -170,7 +168,6 @@ class NotificationService
def merge_mr(merge_request, current_user) def merge_mr(merge_request, current_user)
close_resource_email( close_resource_email(
merge_request, merge_request,
merge_request.target_project,
current_user, current_user,
:merged_merge_request_email, :merged_merge_request_email,
skip_current_user: !merge_request.merge_when_pipeline_succeeds? skip_current_user: !merge_request.merge_when_pipeline_succeeds?
...@@ -180,7 +177,6 @@ class NotificationService ...@@ -180,7 +177,6 @@ class NotificationService
def reopen_mr(merge_request, current_user) def reopen_mr(merge_request, current_user)
reopen_resource_email( reopen_resource_email(
merge_request, merge_request,
merge_request.target_project,
current_user, current_user,
:merge_request_status_email, :merge_request_status_email,
'reopened' 'reopened'
...@@ -196,7 +192,7 @@ class NotificationService ...@@ -196,7 +192,7 @@ class NotificationService
end end
def resolve_all_discussions(merge_request, current_user) def resolve_all_discussions(merge_request, current_user)
recipients = NotificationRecipientService.new(merge_request.target_project).build_recipients( recipients = NotificationRecipientService.build_recipients(
merge_request, merge_request,
current_user, current_user,
action: "resolve_all_discussions") action: "resolve_all_discussions")
...@@ -225,7 +221,7 @@ class NotificationService ...@@ -225,7 +221,7 @@ class NotificationService
def send_new_note_notifications(note) def send_new_note_notifications(note)
notify_method = "note_#{note.to_ability_name}_email".to_sym notify_method = "note_#{note.to_ability_name}_email".to_sym
recipients = NotificationRecipientService.new(note.project).build_new_note_recipients(note) recipients = NotificationRecipientService.build_new_note_recipients(note)
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(notify_method, recipient.id, note.id).deliver_later mailer.send(notify_method, recipient.id, note.id).deliver_later
end end
...@@ -293,8 +289,7 @@ class NotificationService ...@@ -293,8 +289,7 @@ class NotificationService
end end
def project_was_moved(project, old_path_with_namespace) def project_was_moved(project, old_path_with_namespace)
recipients = project.team.members recipients = NotificationRecipientService.notifiable_users(project.team.members, :mention, project: project)
recipients = NotificationRecipientService.new(project).reject_muted_users(recipients)
recipients.each do |recipient| recipients.each do |recipient|
mailer.project_was_moved_email( mailer.project_was_moved_email(
...@@ -306,7 +301,7 @@ class NotificationService ...@@ -306,7 +301,7 @@ class NotificationService
end end
def issue_moved(issue, new_issue, current_user) def issue_moved(issue, new_issue, current_user)
recipients = NotificationRecipientService.new(issue.project).build_recipients(issue, current_user, action: 'moved') recipients = NotificationRecipientService.build_recipients(issue, current_user, action: 'moved')
recipients.map do |recipient| recipients.map do |recipient|
email = mailer.issue_moved_email(recipient, issue, new_issue, current_user) email = mailer.issue_moved_email(recipient, issue, new_issue, current_user)
...@@ -328,10 +323,10 @@ class NotificationService ...@@ -328,10 +323,10 @@ class NotificationService
return unless mailer.respond_to?(email_template) return unless mailer.respond_to?(email_template)
recipients ||= NotificationRecipientService.new(pipeline.project).build_pipeline_recipients( recipients ||= NotificationRecipientService.notifiable_users(
pipeline, [pipeline.user], :watch,
pipeline.user, custom_action: :"#{pipeline.status}_pipeline",
action: pipeline.status target: pipeline
).map(&:notification_email) ).map(&:notification_email)
if recipients.any? if recipients.any?
...@@ -341,16 +336,16 @@ class NotificationService ...@@ -341,16 +336,16 @@ class NotificationService
protected protected
def new_resource_email(target, project, method) def new_resource_email(target, method)
recipients = NotificationRecipientService.new(project).build_recipients(target, target.author, action: "new") recipients = NotificationRecipientService.build_recipients(target, target.author, action: "new")
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id).deliver_later mailer.send(method, recipient.id, target.id).deliver_later
end end
end end
def new_mentions_in_resource_email(target, project, new_mentioned_users, current_user, method) def new_mentions_in_resource_email(target, new_mentioned_users, current_user, method)
recipients = NotificationRecipientService.new(project).build_recipients(target, current_user, action: "new") recipients = NotificationRecipientService.build_recipients(target, current_user, action: "new")
recipients = recipients & new_mentioned_users recipients = recipients & new_mentioned_users
recipients.each do |recipient| recipients.each do |recipient|
...@@ -358,10 +353,10 @@ class NotificationService ...@@ -358,10 +353,10 @@ class NotificationService
end end
end end
def close_resource_email(target, project, current_user, method, skip_current_user: true) def close_resource_email(target, current_user, method, skip_current_user: true)
action = method == :merged_merge_request_email ? "merge" : "close" action = method == :merged_merge_request_email ? "merge" : "close"
recipients = NotificationRecipientService.new(project).build_recipients( recipients = NotificationRecipientService.build_recipients(
target, target,
current_user, current_user,
action: action, action: action,
...@@ -373,11 +368,11 @@ class NotificationService ...@@ -373,11 +368,11 @@ class NotificationService
end end
end end
def reassign_resource_email(target, project, current_user, method) def reassign_resource_email(target, current_user, method)
previous_assignee_id = previous_record(target, 'assignee_id') previous_assignee_id = previous_record(target, 'assignee_id')
previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
recipients = NotificationRecipientService.new(project).build_recipients( recipients = NotificationRecipientService.build_recipients(
target, target,
current_user, current_user,
action: "reassign", action: "reassign",
...@@ -395,8 +390,14 @@ class NotificationService ...@@ -395,8 +390,14 @@ class NotificationService
end end
end end
def relabeled_resource_email(target, project, labels, current_user, method) def relabeled_resource_email(target, labels, current_user, method)
recipients = NotificationRecipientService.new(project).build_relabeled_recipients(target, current_user, labels: labels) recipients = labels.flat_map { |l| l.subscribers(target.project) }
recipients = NotificationRecipientService.notifiable_users(
recipients, :subscription,
target: target,
acting_user: current_user
)
label_names = labels.map(&:name) label_names = labels.map(&:name)
recipients.each do |recipient| recipients.each do |recipient|
...@@ -404,8 +405,8 @@ class NotificationService ...@@ -404,8 +405,8 @@ class NotificationService
end end
end end
def reopen_resource_email(target, project, current_user, method, status) def reopen_resource_email(target, current_user, method, status)
recipients = NotificationRecipientService.new(project).build_recipients(target, current_user, action: "reopen") recipients = NotificationRecipientService.build_recipients(target, current_user, action: "reopen")
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id, status, current_user.id).deliver_later mailer.send(method, recipient.id, target.id, status, current_user.id).deliver_later
......
...@@ -132,6 +132,8 @@ module Banzai ...@@ -132,6 +132,8 @@ module Banzai
end end
def self.cacheless_render(text, context = {}) def self.cacheless_render(text, context = {})
return text.to_s unless text.present?
Gitlab::Metrics.measure(:banzai_cacheless_render) do Gitlab::Metrics.measure(:banzai_cacheless_render) do
result = render_result(text, context) result = render_result(text, context)
......
...@@ -28,7 +28,13 @@ module DeclarativePolicy ...@@ -28,7 +28,13 @@ module DeclarativePolicy
subject = find_delegate(subject) subject = find_delegate(subject)
class_for_class(subject.class) policy_class = class_for_class(subject.class)
raise "no policy for #{subject.class.name}" if policy_class.nil?
policy_class
end
def has_policy?(subject)
!class_for_class(subject.class).nil?
end end
private private
...@@ -51,9 +57,7 @@ module DeclarativePolicy ...@@ -51,9 +57,7 @@ module DeclarativePolicy
end end
end end
policy_class = subject_class.instance_variable_get(CLASS_CACHE_IVAR) subject_class.instance_variable_get(CLASS_CACHE_IVAR)
raise "no policy for #{subject.class.name}" if policy_class.nil?
policy_class
end end
def compute_class_for_class(subject_class) def compute_class_for_class(subject_class)
...@@ -71,6 +75,8 @@ module DeclarativePolicy ...@@ -71,6 +75,8 @@ module DeclarativePolicy
nil nil
end end
end end
nil
end end
def find_delegate(subject) def find_delegate(subject)
......
...@@ -6,10 +6,10 @@ import '~/abuse_reports'; ...@@ -6,10 +6,10 @@ import '~/abuse_reports';
const FIXTURE = 'abuse_reports/abuse_reports_list.html.raw'; const FIXTURE = 'abuse_reports/abuse_reports_list.html.raw';
const MAX_MESSAGE_LENGTH = 500; const MAX_MESSAGE_LENGTH = 500;
let messages; let $messages;
const assertMaxLength = $message => expect($message.text().length).toEqual(MAX_MESSAGE_LENGTH); const assertMaxLength = $message => expect($message.text().length).toEqual(MAX_MESSAGE_LENGTH);
const findMessage = searchText => messages.filter( const findMessage = searchText => $messages.filter(
(index, element) => element.innerText.indexOf(searchText) > -1, (index, element) => element.innerText.indexOf(searchText) > -1,
).first(); ).first();
...@@ -18,7 +18,7 @@ import '~/abuse_reports'; ...@@ -18,7 +18,7 @@ import '~/abuse_reports';
beforeEach(function () { beforeEach(function () {
loadFixtures(FIXTURE); loadFixtures(FIXTURE);
this.abuseReports = new global.AbuseReports(); this.abuseReports = new global.AbuseReports();
messages = $('.abuse-reports .message'); $messages = $('.abuse-reports .message');
}); });
it('should truncate long messages', () => { it('should truncate long messages', () => {
......
import '~/extensions/array';
import 'jquery'; import 'jquery';
import 'jquery-ujs'; import 'jquery-ujs';
import '~/ajax_loading_spinner'; import '~/ajax_loading_spinner';
......
/* eslint-disable space-before-function-paren, no-var */
import '~/extensions/array';
(function() {
describe('Array extensions', function() {
describe('first', function() {
return it('returns the first item', function() {
var arr;
arr = [0, 1, 2, 3, 4, 5];
return expect(arr.first()).toBe(0);
});
});
describe('last', function() {
return it('returns the last item', function() {
var arr;
arr = [0, 1, 2, 3, 4, 5];
return expect(arr.last()).toBe(5);
});
});
});
}).call(window);
import '~/extensions/array';
import '~/filtered_search/dropdown_utils'; import '~/filtered_search/dropdown_utils';
import '~/filtered_search/filtered_search_tokenizer'; import '~/filtered_search/filtered_search_tokenizer';
import '~/filtered_search/filtered_search_dropdown_manager'; import '~/filtered_search/filtered_search_dropdown_manager';
......
import '~/extensions/array';
import '~/filtered_search/filtered_search_visual_tokens'; import '~/filtered_search/filtered_search_visual_tokens';
import '~/filtered_search/filtered_search_tokenizer'; import '~/filtered_search/filtered_search_tokenizer';
import '~/filtered_search/filtered_search_dropdown_manager'; import '~/filtered_search/filtered_search_dropdown_manager';
......
import '~/extensions/array';
import '~/filtered_search/filtered_search_token_keys'; import '~/filtered_search/filtered_search_token_keys';
describe('Filtered Search Token Keys', () => { describe('Filtered Search Token Keys', () => {
......
import '~/extensions/array';
import '~/filtered_search/filtered_search_token_keys'; import '~/filtered_search/filtered_search_token_keys';
import '~/filtered_search/filtered_search_tokenizer'; import '~/filtered_search/filtered_search_tokenizer';
......
...@@ -153,6 +153,15 @@ describe JiraService do ...@@ -153,6 +153,15 @@ describe JiraService do
expect(WebMock).not_to have_requested(:post, @remote_link_url) expect(WebMock).not_to have_requested(:post, @remote_link_url)
end end
it "does not send comment or remote links to issues with unknown resolution" do
allow_any_instance_of(JIRA::Resource::Issue).to receive(:respond_to?).with(:resolution).and_return(false)
@jira_service.close_issue(merge_request, ExternalIssue.new("JIRA-123", project))
expect(WebMock).not_to have_requested(:post, @comment_url)
expect(WebMock).not_to have_requested(:post, @remote_link_url)
end
it "references the GitLab commit/merge request" do it "references the GitLab commit/merge request" do
stub_config_setting(base_url: custom_base_url) stub_config_setting(base_url: custom_base_url)
......
require 'spec_helper'
describe NotificationRecipientService do
set(:user) { create(:user) }
set(:project) { create(:project, :public) }
set(:issue) { create(:issue, project: project) }
set(:watcher) do
watcher = create(:user)
setting = watcher.notification_settings_for(project)
setting.level = :watch
setting.save
watcher
end
subject { described_class.new(project) }
describe '#build_recipients' do
it 'does not modify the participants of the target' do
expect { subject.build_recipients(issue, user, action: :new_issue) }
.not_to change { issue.participants(user) }
end
end
describe '#build_new_note_recipients' do
set(:note) { create(:note_on_issue, noteable: issue, project: project) }
it 'does not modify the participants of the target' do
expect { subject.build_new_note_recipients(note) }
.not_to change { note.noteable.participants(note.author) }
end
end
end
...@@ -306,6 +306,11 @@ describe NotificationService, :mailer do ...@@ -306,6 +306,11 @@ describe NotificationService, :mailer do
before do before do
build_team(note.project) build_team(note.project)
# make sure these users can read the project snippet!
project.add_guest(@u_guest_watcher)
project.add_guest(@u_guest_custom)
note.project.add_master(note.author) note.project.add_master(note.author)
reset_delivered_emails! reset_delivered_emails!
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment