Class: WorkDecorator
- Inherits:
-
Object
- Object
- WorkDecorator
- Defined in:
- app/decorators/work_decorator.rb
Instance Attribute Summary collapse
-
#can_curate ⇒ Object
readonly
Returns the value of attribute can_curate.
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#work ⇒ Object
readonly
Returns the value of attribute work.
Instance Method Summary collapse
- #current_user_is_admin? ⇒ Boolean
- #download_path ⇒ Object
- #edit_path ⇒ Object
- #file_list_path ⇒ Object
-
#initialize(work, current_user) ⇒ WorkDecorator
constructor
A new instance of WorkDecorator.
- #show_approve_button? ⇒ Boolean
- #show_complete_button? ⇒ Boolean
- #show_migrate_button? ⇒ Boolean
- #show_revert_button? ⇒ Boolean
Constructor Details
#initialize(work, current_user) ⇒ WorkDecorator
Returns a new instance of WorkDecorator.
10 11 12 13 14 15 16 |
# File 'app/decorators/work_decorator.rb', line 10 def initialize(work, current_user) @work = work @current_user = current_user @changes = WorkActivity.changes_for_work(work.id).order(created_at: :asc) @messages = WorkActivity.(work.id).order(created_at: :desc) @can_curate = current_user&.can_admin?(group) end |
Instance Attribute Details
#can_curate ⇒ Object (readonly)
Returns the value of attribute can_curate.
5 6 7 |
# File 'app/decorators/work_decorator.rb', line 5 def can_curate @can_curate end |
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
5 6 7 |
# File 'app/decorators/work_decorator.rb', line 5 def changes @changes end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
5 6 7 |
# File 'app/decorators/work_decorator.rb', line 5 def current_user @current_user end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
5 6 7 |
# File 'app/decorators/work_decorator.rb', line 5 def @messages end |
#work ⇒ Object (readonly)
Returns the value of attribute work.
5 6 7 |
# File 'app/decorators/work_decorator.rb', line 5 def work @work end |
Instance Method Details
#current_user_is_admin? ⇒ Boolean
18 19 20 |
# File 'app/decorators/work_decorator.rb', line 18 def current_user_is_admin? current_user.has_role?(:group_admin, group) end |
#download_path ⇒ Object
[View source]
52 53 54 55 56 |
# File 'app/decorators/work_decorator.rb', line 52 def download_path return if @work.nil? || !@work.persisted? work_download_path(@work.id) end |
#edit_path ⇒ Object
[View source]
38 39 40 41 42 43 44 |
# File 'app/decorators/work_decorator.rb', line 38 def edit_path if draft? && !migrated # wizard mode edit_work_wizard_path(work) else edit_work_path(work) end end |
#file_list_path ⇒ Object
[View source]
46 47 48 49 50 |
# File 'app/decorators/work_decorator.rb', line 46 def file_list_path return work_file_list_path("NONE") if @work.nil? || !@work.persisted? work_file_list_path(@work.id) end |
#show_approve_button? ⇒ Boolean
22 23 24 |
# File 'app/decorators/work_decorator.rb', line 22 def work.awaiting_approval? && current_user_is_admin? end |
#show_complete_button? ⇒ Boolean
30 31 32 |
# File 'app/decorators/work_decorator.rb', line 30 def draft? && (work.created_by_user_id == current_user.id || current_user_is_admin?) end |
#show_migrate_button? ⇒ Boolean
34 35 36 |
# File 'app/decorators/work_decorator.rb', line 34 def draft? && migrated && current_user_is_admin? end |
#show_revert_button? ⇒ Boolean
26 27 28 |
# File 'app/decorators/work_decorator.rb', line 26 def work.awaiting_approval? && (work.created_by_user_id == current_user.id || current_user_is_admin?) end |