summaryrefslogtreecommitdiff
path: root/app/services/users/block_service.rb
blob: 8513664ee85f4c8d6fcdfa0a74b6de3e2fc9233f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module Users
  class BlockService < BaseService
    def initialize(current_user)
      @current_user = current_user
    end

    def execute(user)
      return error('An internal user cannot be blocked', 403) if user.internal?

      if user.block
        after_block_hook(user)
        success
      else
        messages = user.errors.full_messages
        error(messages.uniq.join('. '))
      end
    end

    private

    def after_block_hook(user)
      # overridden by EE module
    end
  end
end

Users::BlockService.prepend_if_ee('EE::Users::BlockService')