Class: Organization
Class Method Summary
collapse
Instance Method Summary
collapse
#to_mumukit_grant, #to_mumukit_slug
#base?, #central?, #domain, #platform_class_name, #slug, #switch!, #test?, #to_param, #to_s, #url, #url_for, #validate_active!
#platform_class_name, #sync_key
aggregate_of, all_except, defaults, #delete, #destroy!, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, #update_and_notify!, update_or_create!, whitelist_attributes
Class Method Details
.accessible_as(user, role) ⇒ Object
92
93
94
|
# File 'app/models/organization.rb', line 92
def self.accessible_as(user, role)
all.select { |it| it.public? || user.has_permission?(role, it.slug) }
end
|
.base ⇒ Object
160
161
162
|
# File 'app/models/organization.rb', line 160
def base
find_by name: 'base'
end
|
.central ⇒ Object
156
157
158
|
# File 'app/models/organization.rb', line 156
def central
find_by name: 'central'
end
|
.in_path(content) ⇒ Object
Answers organizations that have the given item in their paths.
Warning: unlike ‘in_path?`, this method does only work with content - child - items instead of both kind of items - content and content containers.
See ‘Organization#in_path?`
179
180
181
|
# File 'app/models/organization.rb', line 179
def in_path(content)
joins(:usages).where('usages.item': content).distinct
end
|
.silenced? ⇒ Boolean
164
165
166
|
# File 'app/models/organization.rb', line 164
def silenced?
!Mumukit::Platform::Organization.current? || current.silent?
end
|
.sync_key_id_field ⇒ Object
168
169
170
|
# File 'app/models/organization.rb', line 168
def sync_key_id_field
:name
end
|
Instance Method Details
#accessible_exams_for(user) ⇒ Object
80
81
82
|
# File 'app/models/organization.rb', line 80
def accessible_exams_for(user)
exams.select { |exam| exam.accessible_for?(user) }
end
|
#ask_for_help_enabled?(user = nil) ⇒ Boolean
Tells if the given user can ask for help in this organization
Warning: this method does not strictly check user’s permission
108
109
110
|
# File 'app/models/organization.rb', line 108
def ask_for_help_enabled?(user = nil)
report_issue_enabled? || .present? || can_create_discussions?(user)
end
|
#can_create_discussions?(user = nil) ⇒ Boolean
Tells if the given user can create discussion in this organization
This is true only when this organization has a forum and the user has the discusser pseudo-permission
117
118
119
|
# File 'app/models/organization.rb', line 117
def can_create_discussions?(user = nil)
forum_enabled? && (!user || user.discusser_of?(self))
end
|
#drop_usage_indices! ⇒ Object
72
73
74
|
# File 'app/models/organization.rb', line 72
def drop_usage_indices!
usages.destroy_all
end
|
#enable_progressive_display!(lookahead: 1) ⇒ Object
135
136
137
|
# File 'app/models/organization.rb', line 135
def enable_progressive_display!(lookahead: 1)
update! progressive_display_lookahead: lookahead
end
|
#explain_error(code, advice) ⇒ Object
88
89
90
|
# File 'app/models/organization.rb', line 88
def explain_error(code, advice)
errors_explanations.try { |it| it[code.to_s] } || I18n.t(advice)
end
|
#has_login_method?(login_method) ⇒ Boolean
84
85
86
|
# File 'app/models/organization.rb', line 84
def has_login_method?(login_method)
self.login_methods.include? login_method.to_s
end
|
#import_from_resource_h!(resource_h) ⇒ Object
121
122
123
124
125
|
# File 'app/models/organization.rb', line 121
def import_from_resource_h!(resource_h)
attrs = self.class.slice_resource_h resource_h
attrs[:book] = Book.locate! attrs[:book]
update! attrs
end
|
#in_path?(item) ⇒ Boolean
47
48
49
|
# File 'app/models/organization.rb', line 47
def in_path?(item)
usages.exists?(item: item) || usages.exists?(parent_item: item)
end
|
#index_usage_of!(item, parent) ⇒ Object
76
77
78
|
# File 'app/models/organization.rb', line 76
def index_usage_of!(item, parent)
Usage.create! organization: self, item: item, parent_item: parent
end
|
#notify_assignments_by!(submitter) ⇒ Object
55
56
57
|
# File 'app/models/organization.rb', line 55
def notify_assignments_by!(submitter)
notify_assignments! assignments.where(submitter_id: submitter.id)
end
|
#notify_recent_assignments!(date) ⇒ Object
51
52
53
|
# File 'app/models/organization.rb', line 51
def notify_recent_assignments!(date)
notify_assignments! assignments.where('assignments.updated_at > ?', date)
end
|
#reindex_usages! ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'app/models/organization.rb', line 63
def reindex_usages!
transaction do
drop_usage_indices!
book.index_usage! self
exams.each { |exam| exam.index_usage! self }
end
reload
end
|
#silent? ⇒ Boolean
59
60
61
|
# File 'app/models/organization.rb', line 59
def silent?
test?
end
|
#site_name ⇒ Object
100
101
102
|
# File 'app/models/organization.rb', line 100
def site_name
central? ? 'mumuki' : name
end
|
#title_suffix ⇒ Object
96
97
98
|
# File 'app/models/organization.rb', line 96
def title_suffix
central? ? '' : " - #{book.name}"
end
|
#to_organization ⇒ Object
131
132
133
|
# File 'app/models/organization.rb', line 131
def to_organization
self
end
|
#to_resource_h ⇒ Object
127
128
129
|
# File 'app/models/organization.rb', line 127
def to_resource_h
super.merge(book: book.slug)
end
|