Sha256: e1886df85d8624ce62a71d473a31096fba61e3518218dd13b6fcd839d369d811

Contents?: true

Size: 720 Bytes

Versions: 2

Compression:

Stored size: 720 Bytes

Contents

module Mutations
  module Managers::UserManager
    class RemoveUserRole < BaseMutation
      argument :target_user_id, String, required: true
      argument :user_roles, [String], required: true

      field :user, Types::UserType, null: true

      def resolve(**args)
        check_user_permissions(context[:user], context[:user], :update_user_role?)
        _, user_id = SoulsApiSchema.from_global_id(args[:target_user_id])
        target_user = ::User.find(user_id)
        args[:user_roles].each { |role| target_user.roles.delete(role) }
        return { user: target_user } if target_user.save

        raise
      rescue StandardError => e
        GraphQL::ExecutionError.new(e.to_s)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
souls-0.24.2 apps/api/app/graphql/mutations/managers/user_manager/remove_user_role.rb
souls-0.24.1 apps/api/app/graphql/mutations/managers/user_manager/remove_user_role.rb