Class: Users::SetNamespaceCommitEmailService
- Inherits:
-
Object
- Object
- Users::SetNamespaceCommitEmailService
- Includes:
- Gitlab::Allowable
- Defined in:
- app/services/users/set_namespace_commit_email_service.rb
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#email_id ⇒ Object
readonly
Returns the value of attribute email_id.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#target_user ⇒ Object
readonly
Returns the value of attribute target_user.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(current_user, namespace, email_id, params) ⇒ SetNamespaceCommitEmailService
constructor
A new instance of SetNamespaceCommitEmailService.
Methods included from Gitlab::Allowable
Constructor Details
#initialize(current_user, namespace, email_id, params) ⇒ SetNamespaceCommitEmailService
Returns a new instance of SetNamespaceCommitEmailService.
9 10 11 12 13 14 |
# File 'app/services/users/set_namespace_commit_email_service.rb', line 9 def initialize(current_user, namespace, email_id, params) @current_user = current_user @target_user = params.delete(:user) || current_user @namespace = namespace @email_id = email_id end |
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
7 8 9 |
# File 'app/services/users/set_namespace_commit_email_service.rb', line 7 def current_user @current_user end |
#email_id ⇒ Object (readonly)
Returns the value of attribute email_id.
7 8 9 |
# File 'app/services/users/set_namespace_commit_email_service.rb', line 7 def email_id @email_id end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'app/services/users/set_namespace_commit_email_service.rb', line 7 def namespace @namespace end |
#target_user ⇒ Object (readonly)
Returns the value of attribute target_user.
7 8 9 |
# File 'app/services/users/set_namespace_commit_email_service.rb', line 7 def target_user @target_user end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/users/set_namespace_commit_email_service.rb', line 16 def execute return error(_('Namespace must be provided.')) if namespace.nil? unless can?(current_user, :admin_user_email_address, target_user) return error(_("User doesn't exist or you don't have permission to change namespace commit emails.")) end unless can?(target_user, :read_namespace_via_membership, namespace) return error(_("Namespace doesn't exist or you don't have permission.")) end email = target_user.emails.find_by(id: email_id) unless email_id.nil? # rubocop: disable CodeReuse/ActiveRecord existing_namespace_commit_email = target_user.namespace_commit_email_for_namespace(namespace) if existing_namespace_commit_email.nil? return error(_('Email must be provided.')) if email.nil? create_namespace_commit_email(email) elsif email_id.nil? remove_namespace_commit_email(existing_namespace_commit_email) else update_namespace_commit_email(existing_namespace_commit_email, email) end end |