Module: ReadOnlyMixin
- Included in:
- ApplicationController, ForumsController
- Defined in:
- lib/read_only_mixin.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #add_readonly_header ⇒ Object
- #allowed_in_staff_writes_only_mode? ⇒ Boolean
- #block_if_readonly_mode ⇒ Object
- #check_readonly_mode ⇒ Object
- #get_or_check_readonly_mode ⇒ Object
- #get_or_check_staff_writes_only_mode ⇒ Object
- #staff_writes_only_mode? ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
65 66 67 |
# File 'lib/read_only_mixin.rb', line 65 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#add_readonly_header ⇒ Object
45 46 47 |
# File 'lib/read_only_mixin.rb', line 45 def add_readonly_header response.headers["Discourse-Readonly"] = "true" if @readonly_mode end |
#allowed_in_staff_writes_only_mode? ⇒ Boolean
49 50 51 |
# File 'lib/read_only_mixin.rb', line 49 def allowed_in_staff_writes_only_mode? self.class.allowed_in_staff_writes_only_mode?(action_name) end |
#block_if_readonly_mode ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/read_only_mixin.rb', line 53 def block_if_readonly_mode return if request.fullpath.start_with?(path "/admin/backups") return if request.fullpath.start_with?(path "/categories/search") return if request.get? || request.head? if @staff_writes_only_mode raise Discourse::ReadOnly.new if !current_user&.staff? && !allowed_in_staff_writes_only_mode? elsif @readonly_mode raise Discourse::ReadOnly.new end end |
#check_readonly_mode ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/read_only_mixin.rb', line 22 def check_readonly_mode if Discourse.readonly_mode? @readonly_mode = true @staff_writes_only_mode = false elsif Discourse.staff_writes_only_mode? @readonly_mode = true @staff_writes_only_mode = true else @readonly_mode = false @staff_writes_only_mode = false end end |
#get_or_check_readonly_mode ⇒ Object
35 36 37 38 |
# File 'lib/read_only_mixin.rb', line 35 def get_or_check_readonly_mode check_readonly_mode if @readonly_mode.nil? @readonly_mode end |
#get_or_check_staff_writes_only_mode ⇒ Object
40 41 42 43 |
# File 'lib/read_only_mixin.rb', line 40 def get_or_check_staff_writes_only_mode check_readonly_mode if @staff_writes_only_mode.nil? @staff_writes_only_mode end |
#staff_writes_only_mode? ⇒ Boolean
18 19 20 |
# File 'lib/read_only_mixin.rb', line 18 def staff_writes_only_mode? @staff_writes_only_mode end |