Class: OrganizationAccessMode::ReadOnly

Inherits:
Base
  • Object
show all
Defined in:
app/models/organization_access_mode/read_only.rb

Instance Attribute Summary

Attributes inherited from Base

#organization, #user

Instance Method Summary collapse

Methods inherited from Base

#resolve_discussions_here?, #show_content_element?, #show_discussion_element?, #submit_solutions_here?, #validate_active!, #validate_content_here!

Constructor Details

#initialize(user, organization, *global_scopes, **specific_scopes) ⇒ ReadOnly

Returns a new instance of ReadOnly.



2
3
4
5
# File 'app/models/organization_access_mode/read_only.rb', line 2

def initialize(user, organization, *global_scopes, **specific_scopes)
  super user, organization
  @scopes = global_scopes.map { |scope| [scope, :all] }.to_h.merge specific_scopes
end

Instance Method Details

#discuss_here?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/models/organization_access_mode/read_only.rb', line 15

def discuss_here?
  has_scope(:discussions) && super
end

#faqs_here?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/models/organization_access_mode/read_only.rb', line 7

def faqs_here?
  has_scope(:faqs) && super
end

#profile_here?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/models/organization_access_mode/read_only.rb', line 11

def profile_here?
  has_scope(:profile)
end

#read_only?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/organization_access_mode/read_only.rb', line 32

def read_only?
  true
end

#restore_indicators?(book) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/organization_access_mode/read_only.rb', line 28

def restore_indicators?(book)
  !book.has_progress_for?(user, organization) && user.has_assignments_in_organization?(organization)
end

#show_content?(content) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'app/models/organization_access_mode/read_only.rb', line 23

def show_content?(content)
  has_scope(:exercises) ||
    (has_scope(:exercises, :submitted) && content.has_progress_for?(user, organization))
end

#validate_discuss_here!(discussion) ⇒ Object



19
20
21
# File 'app/models/organization_access_mode/read_only.rb', line 19

def validate_discuss_here!(discussion)
  super(discussion) unless discuss_here? && discussion&.initiator == user
end