Class: Organization
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Syncable
#platform_class_name, #sync_key
aggregate_of, all_except, defaults, numbered, #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
84
85
86
|
# File 'app/models/organization.rb', line 84
def self.accessible_as(user, role)
all.select { |it| it.public? || user.has_permission?(role, it.slug) }
end
|
.base ⇒ Object
121
122
123
|
# File 'app/models/organization.rb', line 121
def base
find_by name: 'base'
end
|
.central ⇒ Object
117
118
119
|
# File 'app/models/organization.rb', line 117
def central
find_by name: 'central'
end
|
.silenced? ⇒ Boolean
125
126
127
|
# File 'app/models/organization.rb', line 125
def silenced?
!Mumukit::Platform::Organization.current? || current.silent?
end
|
.sync_key_id_field ⇒ Object
129
130
131
|
# File 'app/models/organization.rb', line 129
def sync_key_id_field
:name
end
|
Instance Method Details
#accessible_exams_for(user) ⇒ Object
72
73
74
|
# File 'app/models/organization.rb', line 72
def accessible_exams_for(user)
exams.select { |exam| exam.accessible_for?(user) }
end
|
#ask_for_help_enabled? ⇒ Boolean
96
97
98
|
# File 'app/models/organization.rb', line 96
def ask_for_help_enabled?
report_issue_enabled? || .present? || forum_enabled?
end
|
#drop_usage_indices! ⇒ Object
64
65
66
|
# File 'app/models/organization.rb', line 64
def drop_usage_indices!
usages.destroy_all
end
|
#explain_error(code, advice) ⇒ Object
80
81
82
|
# File 'app/models/organization.rb', line 80
def explain_error(code, advice)
errors_explanations.try { |it| it[code.to_s] } || I18n.t(advice)
end
|
#has_login_method?(login_method) ⇒ Boolean
76
77
78
|
# File 'app/models/organization.rb', line 76
def has_login_method?(login_method)
self.login_methods.include? login_method.to_s
end
|
#import_from_resource_h!(resource_h) ⇒ Object
100
101
102
103
104
|
# File 'app/models/organization.rb', line 100
def import_from_resource_h!(resource_h)
attrs = Mumukit::Platform::Organization::Helpers.slice_platform_json resource_h
attrs[:book] = Book.locate! attrs[:book]
update! attrs
end
|
#in_path?(item) ⇒ Boolean
39
40
41
|
# File 'app/models/organization.rb', line 39
def in_path?(item)
usages.exists?(item: item) || usages.exists?(parent_item: item)
end
|
#index_usage_of!(item, parent) ⇒ Object
68
69
70
|
# File 'app/models/organization.rb', line 68
def index_usage_of!(item, parent)
Usage.create! organization: self, item: item, parent_item: parent
end
|
#notify_assignments_by!(submitter) ⇒ Object
47
48
49
|
# File 'app/models/organization.rb', line 47
def notify_assignments_by!(submitter)
notify_assignments! assignments.where(submitter_id: submitter.id)
end
|
#notify_recent_assignments!(date) ⇒ Object
43
44
45
|
# File 'app/models/organization.rb', line 43
def notify_recent_assignments!(date)
notify_assignments! assignments.where('assignments.updated_at > ?', date)
end
|
#reindex_usages! ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'app/models/organization.rb', line 55
def reindex_usages!
transaction do
drop_usage_indices!
book.index_usage! self
exams.each { |exam| exam.index_usage! self }
end
reload
end
|
#silent? ⇒ Boolean
51
52
53
|
# File 'app/models/organization.rb', line 51
def silent?
test?
end
|
#site_name ⇒ Object
92
93
94
|
# File 'app/models/organization.rb', line 92
def site_name
central? ? 'mumuki' : name
end
|
#title_suffix ⇒ Object
88
89
90
|
# File 'app/models/organization.rb', line 88
def title_suffix
central? ? '' : " - #{book.name}"
end
|