Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/users')
-rw-r--r--app/services/users/allow_possible_spam_service.rb18
-rw-r--r--app/services/users/auto_ban_service.rb33
-rw-r--r--app/services/users/in_product_marketing_email_records.rb3
-rw-r--r--app/services/users/set_namespace_commit_email_service.rb2
-rw-r--r--app/services/users/signup_service.rb34
-rw-r--r--app/services/users/trust_service.rb (renamed from app/services/users/disallow_possible_spam_service.rb)5
-rw-r--r--app/services/users/untrust_service.rb14
7 files changed, 52 insertions, 57 deletions
diff --git a/app/services/users/allow_possible_spam_service.rb b/app/services/users/allow_possible_spam_service.rb
deleted file mode 100644
index d9273fe0fc1..00000000000
--- a/app/services/users/allow_possible_spam_service.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-module Users
- class AllowPossibleSpamService < BaseService
- def initialize(current_user)
- @current_user = current_user
- end
-
- def execute(user)
- custom_attribute = {
- user_id: user.id,
- key: UserCustomAttribute::ALLOW_POSSIBLE_SPAM,
- value: "#{current_user.username}/#{current_user.id}+#{Time.current}"
- }
- UserCustomAttribute.upsert_custom_attributes([custom_attribute])
- end
- end
-end
diff --git a/app/services/users/auto_ban_service.rb b/app/services/users/auto_ban_service.rb
new file mode 100644
index 00000000000..fa3b738b4cd
--- /dev/null
+++ b/app/services/users/auto_ban_service.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Users
+ class AutoBanService < BaseService
+ def initialize(user:, reason:)
+ @user = user
+ @reason = reason
+ end
+
+ def execute
+ if user.ban
+ record_custom_attribute
+ success
+ else
+ messages = user.errors.full_messages
+ error(messages.uniq.join('. '))
+ end
+ end
+
+ private
+
+ attr_reader :user, :reason
+
+ def record_custom_attribute
+ custom_attribute = {
+ user_id: user.id,
+ key: UserCustomAttribute::AUTO_BANNED_BY,
+ value: reason
+ }
+ UserCustomAttribute.upsert_custom_attributes([custom_attribute])
+ end
+ end
+end
diff --git a/app/services/users/in_product_marketing_email_records.rb b/app/services/users/in_product_marketing_email_records.rb
index 94dbd809496..fcb252536b3 100644
--- a/app/services/users/in_product_marketing_email_records.rb
+++ b/app/services/users/in_product_marketing_email_records.rb
@@ -13,10 +13,9 @@ module Users
@records = []
end
- def add(user, campaign: nil, track: nil, series: nil)
+ def add(user, track: nil, series: nil)
@records << Users::InProductMarketingEmail.new(
user: user,
- campaign: campaign,
track: track,
series: series,
created_at: Time.zone.now,
diff --git a/app/services/users/set_namespace_commit_email_service.rb b/app/services/users/set_namespace_commit_email_service.rb
index 30ee597120d..775db364625 100644
--- a/app/services/users/set_namespace_commit_email_service.rb
+++ b/app/services/users/set_namespace_commit_email_service.rb
@@ -20,7 +20,7 @@ module Users
return error(_("User doesn't exist or you don't have permission to change namespace commit emails."))
end
- unless can?(target_user, :read_namespace, namespace)
+ unless can?(target_user, :read_namespace_via_membership, namespace)
return error(_("Namespace doesn't exist or you don't have permission."))
end
diff --git a/app/services/users/signup_service.rb b/app/services/users/signup_service.rb
deleted file mode 100644
index 9eb1e75988c..00000000000
--- a/app/services/users/signup_service.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-module Users
- class SignupService < BaseService
- def initialize(current_user, params = {})
- @user = current_user
- @params = params.dup
- end
-
- def execute
- assign_attributes
- inject_validators
-
- if @user.save
- ServiceResponse.success
- else
- ServiceResponse.error(message: @user.errors.full_messages.join('. '))
- end
- end
-
- private
-
- def assign_attributes
- @user.assign_attributes(params) unless params.empty?
- end
-
- def inject_validators
- class << @user
- validates :role, presence: true
- validates :setup_for_company, inclusion: { in: [true, false], message: :blank } if Gitlab.com?
- end
- end
- end
-end
diff --git a/app/services/users/disallow_possible_spam_service.rb b/app/services/users/trust_service.rb
index e31ba7ddff0..faf0b9c40ea 100644
--- a/app/services/users/disallow_possible_spam_service.rb
+++ b/app/services/users/trust_service.rb
@@ -1,13 +1,14 @@
# frozen_string_literal: true
module Users
- class DisallowPossibleSpamService < BaseService
+ class TrustService < BaseService
def initialize(current_user)
@current_user = current_user
end
def execute(user)
- user.custom_attributes.by_key(UserCustomAttribute::ALLOW_POSSIBLE_SPAM).delete_all
+ UserCustomAttribute.set_trusted_by(user: user, trusted_by: @current_user)
+ success
end
end
end
diff --git a/app/services/users/untrust_service.rb b/app/services/users/untrust_service.rb
new file mode 100644
index 00000000000..aa5de71b97f
--- /dev/null
+++ b/app/services/users/untrust_service.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module Users
+ class UntrustService < BaseService
+ def initialize(current_user)
+ @current_user = current_user
+ end
+
+ def execute(user)
+ user.trusted_with_spam_attribute.delete
+ success
+ end
+ end
+end