blob: 7e585a3d62020c83c5e47d52c890d365ea09f1fe (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# frozen_string_literal: true
class CustomEmojiPolicy < ApplicationPolicy
def index?
user_signed_in?
end
def create?
user_signed_in?
end
def update?
user_signed_in? && owned?
end
def copy?
staff? || (user_signed_in? && new_or_owned?)
end
def enable?
user_signed_in? && owned?
end
def disable?
user_signed_in? && owned?
end
def destroy?
user_signed_in? && owned?
end
def claim?
staff? || claimable?
end
def unclaim?
user_signed_in? && owned?
end
private
def owned?
staff? || (current_account.present? && record.account_id == current_account.id)
end
def new_or_owned?
!CustomEmoji.where(domain: nil, shortcode: record.shortcode).where('account_id IS NULL OR account_id != ?', current_account.id).exists?
end
def claimable?
record.local? ? record.account_id.blank? || record.account_id == current_account.id : new_or_owned?
end
end
|