Class: Organization

Inherits:
ApplicationRecord show all
Includes:
Mumukit::Platform::Organization::Helpers, Syncable
Defined in:
app/models/organization.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Syncable

#platform_class_name, #sync_key

Methods inherited from ApplicationRecord

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

.baseObject



121
122
123
# File 'app/models/organization.rb', line 121

def base
  find_by name: 'base'
end

.centralObject



117
118
119
# File 'app/models/organization.rb', line 117

def central
  find_by name: 'central'
end

.silenced?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'app/models/organization.rb', line 125

def silenced?
  !Mumukit::Platform::Organization.current? || current.silent?
end

.sync_key_id_fieldObject



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

Returns:

  • (Boolean)


96
97
98
# File 'app/models/organization.rb', line 96

def ask_for_help_enabled?
  report_issue_enabled? || community_link.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

Returns:

  • (Boolean)


76
77
78
# File 'app/models/organization.rb', line 76

def ()
  self..include? .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

Returns:

  • (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

Returns:

  • (Boolean)


51
52
53
# File 'app/models/organization.rb', line 51

def silent?
  test?
end

#site_nameObject



92
93
94
# File 'app/models/organization.rb', line 92

def site_name
  central? ? 'mumuki' : name
end

#title_suffixObject



88
89
90
# File 'app/models/organization.rb', line 88

def title_suffix
  central? ? '' : " - #{book.name}"
end