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

destroy_service.rb « achievements « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3204adb8e891596c052a9a7b7f10d9080378925b (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
30
31
32
33
# frozen_string_literal: true

module Achievements
  class DestroyService
    attr_reader :current_user, :achievement

    def initialize(current_user, achievement)
      @current_user = current_user
      @achievement = achievement
    end

    def execute
      return error_no_permissions unless allowed?

      achievement.delete
      ServiceResponse.success(payload: achievement)
    end

    private

    def allowed?
      current_user&.can?(:admin_achievement, achievement)
    end

    def error_no_permissions
      error('You have insufficient permissions to delete this achievement')
    end

    def error(message)
      ServiceResponse.error(message: Array(message))
    end
  end
end