trabajo-afectivo/app/models/mention/validation.rb

23 lines
491 B
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# 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