Class: Decidim::Posts::PostHeaderCell

Inherits:
ViewModel
  • Object
show all
Includes:
Cell::ViewModel::Partial, EndorsableHelper
Defined in:
app/cells/decidim/posts/post_header_cell.rb

Instance Method Summary collapse

Instance Method Details

#delete_methodObject



34
35
36
37
38
39
40
# File 'app/cells/decidim/posts/post_header_cell.rb', line 34

def delete_method
  if post.component.manifest_name == "meetings"
    :put
  else
    :delete
  end
end

#delete_post_pathObject



25
26
27
28
29
30
31
32
# File 'app/cells/decidim/posts/post_header_cell.rb', line 25

def delete_post_path
  if post.component.manifest_name == "meetings"
    # use MeetingsController from posts module
    Decidim::EngineRouter.main_proxy(posts_component_for_meeting(post)).withdraw_meeting_path(assembly_slug: post.component.participatory_space.slug, component_id: 1, id: post)
  else
    Decidim::EngineRouter.main_proxy(post.component).post_path(post)
  end
end

#edit_post_pathObject



16
17
18
19
20
21
22
23
# File 'app/cells/decidim/posts/post_header_cell.rb', line 16

def edit_post_path
  if post.component.manifest_name == "meetings"
    # use MeetingsController from posts module
    Decidim::EngineRouter.main_proxy(posts_component_for_meeting(post)).edit_meeting_path(post)
  else
    Decidim::EngineRouter.main_proxy(post.component).edit_post_path(post)
  end
end

#postObject



12
13
14
# File 'app/cells/decidim/posts/post_header_cell.rb', line 12

def post
  model
end

#post_deleteable?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'app/cells/decidim/posts/post_header_cell.rb', line 52

def post_deleteable?
  if post.component.manifest_name == "meetings"
    post.withdrawable_by?(current_user)
  else
    post.deleteable_by?(current_user)
  end
end

#post_editable?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
# File 'app/cells/decidim/posts/post_header_cell.rb', line 42

def post_editable?
  if post.component.manifest_name == "meetings"
    post.authored_by?(current_user)
  else
    # Don't allow editing of survey posts
    return false if post.category == "survey"
    post.editable_by?(current_user)
  end
end

#showObject



8
9
10
# File 'app/cells/decidim/posts/post_header_cell.rb', line 8

def show
  render :show
end

#show_menu?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'app/cells/decidim/posts/post_header_cell.rb', line 68

def show_menu?
  show_report_button? || post_editable? || post_deleteable? || show_translate_button?
end

#show_report_button?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/cells/decidim/posts/post_header_cell.rb', line 60

def show_report_button?
  post.author != current_user && post.class == Decidim::Posts::Post
end

#show_translate_button?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/cells/decidim/posts/post_header_cell.rb', line 64

def show_translate_button?
  false # disbled for now
end