-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathuser.rb
128 lines (99 loc) · 3.04 KB
/
user.rb
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
class User < ApplicationRecord
include GDS::SSO::User
belongs_to :organisation, foreign_key: :organisation_slug, primary_key: :slug
has_many :user_world_locations
has_many :world_locations, through: :user_world_locations
has_many :statistics_announcements, foreign_key: :creator_id
has_many :republishing_events
serialize :permissions, coder: YAML, type: Array
validates :name, presence: true
scope :enabled, -> { where(disabled: false) }
module Permissions
SIGNIN = "signin".freeze
DEPARTMENTAL_EDITOR = "Editor".freeze
MANAGING_EDITOR = "Managing Editor".freeze
GDS_EDITOR = "GDS Editor".freeze
VIP_EDITOR = "VIP Editor".freeze
PUBLISH_SCHEDULED_EDITIONS = "Publish scheduled editions".freeze
WORLD_WRITER = "World Writer".freeze
WORLD_EDITOR = "World Editor".freeze
FORCE_PUBLISH_ANYTHING = "Force publish anything".freeze
GDS_ADMIN = "GDS Admin".freeze
PREVIEW_DESIGN_SYSTEM = "Preview design system".freeze
PREVIEW_NEXT_RELEASE = "Preview next release".freeze
SIDEKIQ_ADMIN = "Sidekiq Admin".freeze
VISUAL_EDITOR_PRIVATE_BETA = "Visual editor private beta".freeze
end
def role
if gds_editor? then "GDS Editor"
elsif departmental_editor? then "Departmental Editor"
elsif managing_editor? then "Managing Editor"
elsif world_editor? then "World Editor"
elsif world_writer? then "World Writer"
else
"Writer"
end
end
def departmental_editor?
has_permission?(Permissions::DEPARTMENTAL_EDITOR)
end
def managing_editor?
has_permission?(Permissions::MANAGING_EDITOR)
end
def gds_editor?
has_permission?(Permissions::GDS_EDITOR)
end
def vip_editor?
has_permission?(Permissions::VIP_EDITOR)
end
def world_editor?
has_permission?(Permissions::WORLD_EDITOR)
end
def world_writer?
has_permission?(Permissions::WORLD_WRITER)
end
def gds_admin?
has_permission?(Permissions::GDS_ADMIN)
end
def scheduled_publishing_robot?
can_publish_scheduled_editions?
end
def location_limited?
world_editor? || world_writer?
end
def can_publish_scheduled_editions?
has_permission?(Permissions::PUBLISH_SCHEDULED_EDITIONS)
end
def can_force_publish_anything?
has_permission?(Permissions::FORCE_PUBLISH_ANYTHING)
end
def can_preview_design_system?
has_permission?(Permissions::PREVIEW_DESIGN_SYSTEM)
end
def can_preview_next_release?
has_permission?(Permissions::PREVIEW_NEXT_RELEASE)
end
def can_see_visual_editor_private_beta?
has_permission?(Permissions::VISUAL_EDITOR_PRIVATE_BETA)
end
def organisation_name
organisation ? organisation.name : nil
end
def has_email?
email.present?
end
def editable_by?(user)
user.gds_editor?
end
def can_handle_fatalities?
gds_editor? || (organisation && organisation.handles_fatalities?)
end
def fuzzy_last_name
name.split(/ +/, 2).last
end
def organisation_content_id
return organisation.content_id if organisation
@organisation_content_id || ""
end
attr_writer :organisation_content_id
end