Class: Biovision::Components::PostsComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- Biovision::Components::PostsComponent
- 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
- #allow_post_type?(type) ⇒ Boolean
- #edit_path(entity) ⇒ Object
- #editable?(entity) ⇒ Boolean
- #group?(name) ⇒ Boolean
- #show_dashboard? ⇒ Boolean
- #use_parameters? ⇒ Boolean
Class Method Details
.privilege_names ⇒ Object
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
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
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
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
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
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
13 14 15 |
# File 'app/services/biovision/components/posts_component.rb', line 13 def use_parameters? false end |