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
95
96
97
|
# File 'app/models/organization.rb', line 95
def self.accessible_as(user, role)
all.select { |it| it.public? || user.has_permission?(role, it.slug) }
end
|
.base ⇒ Object
158
159
160
|
# File 'app/models/organization.rb', line 158
def base
find_by name: 'base'
end
|
.central ⇒ Object
154
155
156
|
# File 'app/models/organization.rb', line 154
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?`
177
178
179
|
# File 'app/models/organization.rb', line 177
def in_path(content)
joins(:usages).where('usages.item': content).distinct
end
|
.silenced? ⇒ Boolean
162
163
164
|
# File 'app/models/organization.rb', line 162
def silenced?
!Mumukit::Platform::Organization.current? || current.silent?
end
|
.sync_key_id_field ⇒ Object
166
167
168
|
# File 'app/models/organization.rb', line 166
def sync_key_id_field
:name
end
|
Instance Method Details
#accessible_exams_for(user) ⇒ Object
83
84
85
|
# File 'app/models/organization.rb', line 83
def accessible_exams_for(user)
exams.select { |exam| exam.accessible_for?(user) }
end
|
#ask_for_help_enabled?(user) ⇒ Boolean
Tells if the given user can ask for help in this organization
Warning: this method does not strictly check user’s permission
111
112
113
|
# File 'app/models/organization.rb', line 111
def ask_for_help_enabled?(user)
report_issue_enabled? || .present? || user.can_discuss_in?(self)
end
|
#display_name ⇒ Object
133
134
135
|
# File 'app/models/organization.rb', line 133
def display_name
name.gsub(/\W/, ' ').titleize
end
|
#drop_usage_indices! ⇒ Object
75
76
77
|
# File 'app/models/organization.rb', line 75
def drop_usage_indices!
usages.destroy_all
end
|
#enable_progressive_display!(lookahead: 1) ⇒ Object
129
130
131
|
# File 'app/models/organization.rb', line 129
def enable_progressive_display!(lookahead: 1)
update! progressive_display_lookahead: lookahead
end
|
#explain_error(code, advice) ⇒ Object
91
92
93
|
# File 'app/models/organization.rb', line 91
def explain_error(code, advice)
errors_explanations.try { |it| it[code.to_s] } || I18n.t(advice)
end
|
#has_login_method?(login_method) ⇒ Boolean
87
88
89
|
# File 'app/models/organization.rb', line 87
def has_login_method?(login_method)
self.login_methods.include? login_method.to_s
end
|
#import_from_resource_h!(resource_h) ⇒ Object
115
116
117
118
119
|
# File 'app/models/organization.rb', line 115
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
50
51
52
|
# File 'app/models/organization.rb', line 50
def in_path?(item)
usages.exists?(item: item) || usages.exists?(parent_item: item)
end
|
#index_usage_of!(item, parent) ⇒ Object
79
80
81
|
# File 'app/models/organization.rb', line 79
def index_usage_of!(item, parent)
Usage.create! organization: self, item: item, parent_item: parent
end
|
#notify_assignments_by!(submitter) ⇒ Object
58
59
60
|
# File 'app/models/organization.rb', line 58
def notify_assignments_by!(submitter)
notify_assignments! assignments.where(submitter_id: submitter.id)
end
|
#notify_recent_assignments!(date) ⇒ Object
54
55
56
|
# File 'app/models/organization.rb', line 54
def notify_recent_assignments!(date)
notify_assignments! assignments.where('assignments.updated_at > ?', date)
end
|
#reindex_usages! ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'app/models/organization.rb', line 66
def reindex_usages!
transaction do
drop_usage_indices!
book.index_usage! self
exams.each { |exam| exam.index_usage! self }
end
reload
end
|
#silent? ⇒ Boolean
62
63
64
|
# File 'app/models/organization.rb', line 62
def silent?
test?
end
|
#site_name ⇒ Object
103
104
105
|
# File 'app/models/organization.rb', line 103
def site_name
central? ? 'mumuki' : name
end
|
#title_suffix ⇒ Object
99
100
101
|
# File 'app/models/organization.rb', line 99
def title_suffix
central? ? '' : " - #{book.name}"
end
|
#to_organization ⇒ Object
125
126
127
|
# File 'app/models/organization.rb', line 125
def to_organization
self
end
|
#to_resource_h ⇒ Object
121
122
123
|
# File 'app/models/organization.rb', line 121
def to_resource_h
super.merge(book: book.slug)
end
|