trabajo-afectivo/app/models/mention/validation.rb
2022-01-01 14:38:12 +01:00

22 lines
491 B
Ruby

# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class Mention::Validation < ActiveModel::Validator
attr_reader :record
def validate(record)
@record = record
check_user_permission
end
private
def check_user_permission
return if MentionPolicy.new(record.user, record).create?
invalid_because(:user, 'has no ticket.agent permissions')
end
def invalid_because(attribute, message)
record.errors.add attribute, message
end
end