Class: Mutations::Achievements::UpdateUserAchievementPriorities

Inherits:
BaseMutation
  • Object
show all
Defined in:
app/graphql/mutations/achievements/update_user_achievement_priorities.rb

Constant Summary

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, authorization, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #ready?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #raise_resource_not_available_error!

Instance Method Details

#find_object(id) ⇒ Object



32
33
34
# File 'app/graphql/mutations/achievements/update_user_achievement_priorities.rb', line 32

def find_object(id)
  ::Gitlab::Graphql::Lazy.force(GitlabSchema.object_from_id(id, expected_type: ::Achievements::UserAchievement))
end

#resolve(args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/graphql/mutations/achievements/update_user_achievement_priorities.rb', line 19

def resolve(args)
  user_achievements = args.delete(:user_achievement_ids).map { |id| find_object(id) }

  user_achievements.each do |user_achievement|
    unless Ability.allowed?(current_user, :update_owned_user_achievement, user_achievement)
      raise_resource_not_available_error!
    end
  end

  result = ::Achievements::UpdateUserAchievementPrioritiesService.new(current_user, user_achievements).execute
  { user_achievements: result.payload, errors: result.errors }
end