Class: WorkDecorator

Inherits:
Object
  • Object
show all
Defined in:
app/decorators/work_decorator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work, current_user) ⇒ WorkDecorator

Returns a new instance of WorkDecorator.

[View source]

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.messages_for_work(work.id).order(created_at: :desc)
  @can_curate = current_user&.can_admin?(group)
end

Instance Attribute Details

#can_curateObject (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

#changesObject (readonly)

Returns the value of attribute changes.


5
6
7
# File 'app/decorators/work_decorator.rb', line 5

def changes
  @changes
end

#current_userObject (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

#messagesObject (readonly)

Returns the value of attribute messages.


5
6
7
# File 'app/decorators/work_decorator.rb', line 5

def messages
  @messages
end

#workObject (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

Returns:

  • (Boolean)
[View source]

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_pathObject

[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_pathObject

[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_pathObject

[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

Returns:

  • (Boolean)
[View source]

22
23
24
# File 'app/decorators/work_decorator.rb', line 22

def show_approve_button?
  work.awaiting_approval? && current_user_is_admin?
end

#show_complete_button?Boolean

Returns:

  • (Boolean)
[View source]

30
31
32
# File 'app/decorators/work_decorator.rb', line 30

def show_complete_button?
  draft? && (work.created_by_user_id == current_user.id || current_user_is_admin?)
end

#show_migrate_button?Boolean

Returns:

  • (Boolean)
[View source]

34
35
36
# File 'app/decorators/work_decorator.rb', line 34

def show_migrate_button?
  draft? && migrated && current_user_is_admin?
end

#show_revert_button?Boolean

Returns:

  • (Boolean)
[View source]

26
27
28
# File 'app/decorators/work_decorator.rb', line 26

def show_revert_button?
  work.awaiting_approval? && (work.created_by_user_id == current_user.id || current_user_is_admin?)
end