Class: Organization

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

aggregate_of, all_except, defaults, name_model_as, numbered, #save, #save_and_notify!, #save_and_notify_changes!, #update_and_notify!, update_or_create!

Class Method Details

.accessible_as(user, role) ⇒ Object



83
84
85
# File 'app/models/organization.rb', line 83

def self.accessible_as(user, role)
  all.select { |it| it.public? || user.has_permission?(role, it.slug) }
end

.baseObject



114
115
116
# File 'app/models/organization.rb', line 114

def base
  find_by name: 'base'
end

.centralObject



110
111
112
# File 'app/models/organization.rb', line 110

def central
  find_by name: 'central'
end

Instance Method Details

#accessible_exams_for(user) ⇒ Object



71
72
73
# File 'app/models/organization.rb', line 71

def accessible_exams_for(user)
  exams.select { |exam| exam.accessible_for?(user) }
end

#ask_for_help_enabled?Boolean

Returns:

  • (Boolean)


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

def ask_for_help_enabled?
  report_issue_enabled? || community_link.present? || forum_enabled?
end

#drop_usage_indices!Object



63
64
65
# File 'app/models/organization.rb', line 63

def drop_usage_indices!
  usages.destroy_all
end

#explain_error(code, advice) ⇒ Object



79
80
81
# File 'app/models/organization.rb', line 79

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)


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

def ()
  self..include? .to_s
end

#in_path?(item) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/organization.rb', line 38

def in_path?(item)
  usages.exists?(item: item) || usages.exists?(parent_item: item)
end

#index_usage_of!(item, parent) ⇒ Object



67
68
69
# File 'app/models/organization.rb', line 67

def index_usage_of!(item, parent)
  Usage.create! organization: self, item: item, parent_item: parent
end

#notify_assignments_by!(submitter) ⇒ Object



46
47
48
# File 'app/models/organization.rb', line 46

def notify_assignments_by!(submitter)
  notify_assignments! assignments.where(submitter_id: submitter.id)
end

#notify_recent_assignments!(date) ⇒ Object



42
43
44
# File 'app/models/organization.rb', line 42

def notify_recent_assignments!(date)
  notify_assignments! assignments.where('assignments.updated_at > ?', date)
end

#reindex_usages!Object



54
55
56
57
58
59
60
61
# File 'app/models/organization.rb', line 54

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)


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

def silent?
  test?
end

#site_nameObject



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

def site_name
  central? ? 'mumuki' : name
end

#title_suffixObject



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

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