Commit bfb524805ffc503cb4b65c7ff4def80a57cec66c

Authored by Victor Costa
1 parent 5453c5a4

proposals_discussion: allow any users to create proposals

Also create a proposal private by default and allow the author to
publish.
controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb
1 1 class ProposalsDiscussionPluginMyprofileController < MyProfileController
2 2  
  3 + before_filter :check_edit_permission_to_proposal, :only => :publish_proposal
  4 +
3 5 def select_topic
4 6 @discussion = profile.articles.find(params[:parent_id])
5 7 render :file => 'select_topic'
... ... @@ -9,4 +11,20 @@ class ProposalsDiscussionPluginMyprofileController &lt; MyProfileController
9 11 redirect_to :controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => params[:discussion][:topic]
10 12 end
11 13  
  14 + def publish_proposal
  15 + if @proposal.update_attribute(:published, true)
  16 + session[:notice] = _('Proposal published!')
  17 + else
  18 + session[:notice] = _('Failed to publish your proposal.')
  19 + end
  20 + redirect_to @proposal.view_url
  21 + end
  22 +
  23 + protected
  24 +
  25 + def check_edit_permission_to_proposal
  26 + @proposal = profile.articles.find(params[:proposal_id])
  27 + render_access_denied unless @proposal.allow_edit?(user)
  28 + end
  29 +
12 30 end
... ...
controllers/public/proposals_discussion_plugin_public_controller.rb
... ... @@ -9,7 +9,7 @@ class ProposalsDiscussionPluginPublicController &lt; ApplicationController
9 9 page = (params[:page] || 1).to_i
10 10  
11 11 set_seed
12   - proposals = holder.proposals.includes(:parent, :profile).reorder('random()')
  12 + proposals = holder.proposals.public.reorder('random()')
13 13 proposals = proposals.page(page).per_page(5)
14 14  
15 15 unless proposals.empty?
... ...
lib/proposals_discussion_plugin/discussion.rb
1 1 class ProposalsDiscussionPlugin::Discussion < Folder
2 2  
3   - alias :topics :children
4   -
  3 + has_many :topics, :class_name => 'ProposalsDiscussionPlugin::Topic', :foreign_key => 'parent_id'
5 4 has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :through => :children, :source => :children
6 5  
7 6 def self.short_description
... ...
lib/proposals_discussion_plugin/proposal.rb
1 1 class ProposalsDiscussionPlugin::Proposal < TinyMceArticle
2 2  
  3 + scope :private, lambda {|user| {:conditions => {:last_changed_by_id => user.id, :published => false}}}
  4 +
3 5 alias :topic :parent
4 6  
5 7 def self.short_description
... ... @@ -19,4 +21,8 @@ class ProposalsDiscussionPlugin::Proposal &lt; TinyMceArticle
19 21 end
20 22 end
21 23  
  24 + def allow_edit?(user)
  25 + super || created_by == user
  26 + end
  27 +
22 28 end
... ...
lib/proposals_discussion_plugin/proposal_helper.rb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +module ProposalsDiscussionPlugin::ProposalHelper
  2 +
  3 + def visibility_options(article, tokenized_children)
  4 + article.published = false if article.new_record?
  5 + super
  6 + end
  7 +
  8 +end
... ...
lib/proposals_discussion_plugin/topic.rb
1 1 class ProposalsDiscussionPlugin::Topic < Folder
2 2  
3 3 alias :discussion :parent
4   - alias :proposals :children
5 4  
  5 + has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :foreign_key => 'parent_id'
6 6 has_many :proposals_comments, :class_name => 'Comment', :through => :children, :source => :comments
7 7 has_many :proposals_authors, :class_name => 'Person', :through => :children, :source => :created_by
8 8  
... ...
public/style.css
  1 +.private-proposals .proposal {
  2 + background: rgb(249, 252, 193);
  3 +}
  4 +
1 5 .proposal {
2 6 background: rgb(236, 236, 236);
3 7 width: 100%;
... ... @@ -30,7 +34,7 @@
30 34 }
31 35  
32 36 .proposal .content:hover, .proposal .topic:hover {
33   - background: rgb(223, 223, 223);
  37 + background: rgba(0, 0, 0, 0.1);
34 38 }
35 39  
36 40 .proposal .title {
... ...
views/content_viewer/_proposals_list.html.erb
... ... @@ -9,7 +9,16 @@
9 9 });
10 10 </script>
11 11  
  12 +<% private_proposals = @page.proposals.private(user)%>
  13 +<% unless private_proposals.empty? %>
  14 +<div class="private-proposals">
  15 + <h5><%= _('My private proposals') %></h5>
  16 + <%= render :partial => 'content_viewer/proposal_card', :collection => private_proposals %>
  17 +</div>
  18 +<% end %>
  19 +
12 20 <div class="proposals">
  21 + <h5><%= _('Proposals') %></h5>
13 22 <div class="more">
14 23 <img src="/images/loading.gif" alt="Loading" /><%= _("Loading...") %>
15 24 <%= link_to '', url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier }) %>
... ...
views/content_viewer/proposal.html.erb
... ... @@ -17,3 +17,11 @@
17 17 <h5><%= _('Body') %></h4>
18 18 <div class="content"><%= @page.body %></div>
19 19 </div>
  20 +
  21 +<% if @page.allow_edit?(user) && !@page.published %>
  22 +<div class="actions">
  23 + <%= link_to url_for({:controller => 'proposals_discussion_plugin_myprofile', :action => 'publish_proposal', :proposal_id => @page.id}), :class => 'button with-text icon-add' do %>
  24 + <strong><%= _("Publish") %></strong>
  25 + <% end %>
  26 +</div>
  27 +<% end %>
... ...