mirror of
https://github.com/discourse/discourse.git
synced 2024-12-13 04:33:42 +08:00
b806dce13d
- fetch models inside services - validate `user_id` in contracts - use policy objects - extract more logic to actions - write specs for services and action
24 lines
516 B
Ruby
24 lines
516 B
Ruby
# frozen_string_literal: true
|
|
|
|
class User::NotAlreadySilencedPolicy < PolicyBase
|
|
delegate :user, to: :context, private: true
|
|
delegate :silenced_record, to: :user, private: true
|
|
|
|
def call
|
|
!user.silenced?
|
|
end
|
|
|
|
def reason
|
|
I18n.t(
|
|
"user.already_silenced",
|
|
staff: silenced_record.acting_user.username,
|
|
time_ago:
|
|
AgeWords.time_ago_in_words(
|
|
silenced_record.created_at,
|
|
true,
|
|
scope: :"datetime.distance_in_words_verbose",
|
|
),
|
|
)
|
|
end
|
|
end
|