debian-mirror-gitlab/app/graphql/mutations/user_preferences/update.rb

46 lines
1.2 KiB
Ruby
Raw Normal View History

2022-04-04 11:22:00 +05:30
# frozen_string_literal: true
module Mutations
module UserPreferences
class Update < BaseMutation
graphql_name 'UserPreferencesUpdate'
argument :issues_sort, Types::IssueSortEnum,
required: false,
description: 'Sort order for issue lists.'
field :user_preferences,
Types::UserPreferencesType,
null: true,
description: 'User preferences after mutation.'
2022-06-21 17:19:12 +05:30
def ready?(**args)
if disabled_sort_value?(args)
raise Gitlab::Graphql::Errors::ArgumentError,
'Feature flag `incident_escalations` must be enabled to use this sort order.'
end
super
end
2022-04-04 11:22:00 +05:30
def resolve(**attributes)
user_preferences = current_user.user_preference
user_preferences.update(attributes)
{
user_preferences: user_preferences.valid? ? user_preferences : nil,
errors: errors_on_object(user_preferences)
}
end
2022-06-21 17:19:12 +05:30
private
def disabled_sort_value?(args)
return false unless [:escalation_status_asc, :escalation_status_desc].include?(args[:issues_sort])
Feature.disabled?(:incident_escalations, default_enabled: :yaml)
end
2022-04-04 11:22:00 +05:30
end
end
end