Class: Biovision::Components::PostsComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/services/biovision/components/posts_component.rb

Overview

Component for posts

Constant Summary collapse

SLUG =
'posts'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.privilege_namesObject



9
10
11
# File 'app/services/biovision/components/posts_component.rb', line 9

def self.privilege_names
  %w[chief_editor deputy_chief_editor editor]
end

Instance Method Details

#allow_post_type?(type) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
# File 'app/services/biovision/components/posts_component.rb', line 37

def allow_post_type?(type)
  return false if user.nil?
  return true if user.super_user?
  return true if group?(:chief)

  criteria = {
    editorial_member: EditorialMember[user],
    post_type: type.is_a?(PostType) ? type : PostType[type]
  }
  EditorialMemberPostType.where(criteria).exists?
end

#edit_path(entity) ⇒ Object

Parameters:



56
57
58
59
60
61
62
# File 'app/services/biovision/components/posts_component.rb', line 56

def edit_path(entity)
  if group?(:chief)
    "/posts/#{entity.id}/edit"
  else
    "/my/posts/#{entity.id}/edit"
  end
end

#editable?(entity) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'app/services/biovision/components/posts_component.rb', line 49

def editable?(entity)
  return true if group?(:chief)

  entity.owned_by?(user)
end

#group?(name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'app/services/biovision/components/posts_component.rb', line 18

def group?(name)
  case name
  when :chief
    allow? 'chief_editor', 'deputy_chief_editor'
  else
    allow? 'chief_editor', 'deputy_chief_editor', 'editor'
  end
end

#show_dashboard?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# File 'app/services/biovision/components/posts_component.rb', line 27

def show_dashboard?
  return true if user.super_user?
  return true if group?(:chief)

  criterion = { editorial_member: EditorialMember[user] }
  editor = EditorialMemberPostType.where(criterion).exists?
  editor || Post.owned_by(user).exists?
end

#use_parameters?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/services/biovision/components/posts_component.rb', line 13

def use_parameters?
  false
end