Commit 56eca94bb93d717f9e2c841ba33b85a0dabe5a5d
1 parent
f87e72da
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
proposals_discussion: allow any users to create proposals
Also create a proposal private by default and allow the author to publish.
Showing
9 changed files
with
57 additions
and
5 deletions
Show diff stats
plugins/proposals_discussion/controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb
| 1 | class ProposalsDiscussionPluginMyprofileController < MyProfileController | 1 | class ProposalsDiscussionPluginMyprofileController < MyProfileController |
| 2 | 2 | ||
| 3 | + before_filter :check_edit_permission_to_proposal, :only => :publish_proposal | ||
| 4 | + | ||
| 3 | def select_topic | 5 | def select_topic |
| 4 | @discussion = profile.articles.find(params[:parent_id]) | 6 | @discussion = profile.articles.find(params[:parent_id]) |
| 5 | render :file => 'select_topic' | 7 | render :file => 'select_topic' |
| @@ -9,4 +11,20 @@ class ProposalsDiscussionPluginMyprofileController < MyProfileController | @@ -9,4 +11,20 @@ class ProposalsDiscussionPluginMyprofileController < MyProfileController | ||
| 9 | redirect_to :controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => params[:discussion][:topic] | 11 | redirect_to :controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => params[:discussion][:topic] |
| 10 | end | 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 | end | 30 | end |
plugins/proposals_discussion/controllers/public/proposals_discussion_plugin_public_controller.rb
| @@ -9,7 +9,7 @@ class ProposalsDiscussionPluginPublicController < ApplicationController | @@ -9,7 +9,7 @@ class ProposalsDiscussionPluginPublicController < ApplicationController | ||
| 9 | page = (params[:page] || 1).to_i | 9 | page = (params[:page] || 1).to_i |
| 10 | 10 | ||
| 11 | set_seed | 11 | set_seed |
| 12 | - proposals = holder.proposals.includes(:parent, :profile).reorder('random()') | 12 | + proposals = holder.proposals.public.reorder('random()') |
| 13 | proposals = proposals.page(page).per_page(5) | 13 | proposals = proposals.page(page).per_page(5) |
| 14 | 14 | ||
| 15 | unless proposals.empty? | 15 | unless proposals.empty? |
plugins/proposals_discussion/lib/proposals_discussion_plugin/discussion.rb
| 1 | class ProposalsDiscussionPlugin::Discussion < Folder | 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 | has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :through => :children, :source => :children | 4 | has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :through => :children, :source => :children |
| 6 | 5 | ||
| 7 | def self.short_description | 6 | def self.short_description |
plugins/proposals_discussion/lib/proposals_discussion_plugin/proposal.rb
| 1 | class ProposalsDiscussionPlugin::Proposal < TinyMceArticle | 1 | class ProposalsDiscussionPlugin::Proposal < TinyMceArticle |
| 2 | 2 | ||
| 3 | + scope :private, lambda {|user| {:conditions => {:last_changed_by_id => user.id, :published => false}}} | ||
| 4 | + | ||
| 3 | alias :topic :parent | 5 | alias :topic :parent |
| 4 | 6 | ||
| 5 | def self.short_description | 7 | def self.short_description |
| @@ -19,4 +21,8 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle | @@ -19,4 +21,8 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle | ||
| 19 | end | 21 | end |
| 20 | end | 22 | end |
| 21 | 23 | ||
| 24 | + def allow_edit?(user) | ||
| 25 | + super || created_by == user | ||
| 26 | + end | ||
| 27 | + | ||
| 22 | end | 28 | end |
plugins/proposals_discussion/lib/proposals_discussion_plugin/proposal_helper.rb
0 → 100644
plugins/proposals_discussion/lib/proposals_discussion_plugin/topic.rb
| 1 | class ProposalsDiscussionPlugin::Topic < Folder | 1 | class ProposalsDiscussionPlugin::Topic < Folder |
| 2 | 2 | ||
| 3 | alias :discussion :parent | 3 | alias :discussion :parent |
| 4 | - alias :proposals :children | ||
| 5 | 4 | ||
| 5 | + has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :foreign_key => 'parent_id' | ||
| 6 | has_many :proposals_comments, :class_name => 'Comment', :through => :children, :source => :comments | 6 | has_many :proposals_comments, :class_name => 'Comment', :through => :children, :source => :comments |
| 7 | has_many :proposals_authors, :class_name => 'Person', :through => :children, :source => :created_by | 7 | has_many :proposals_authors, :class_name => 'Person', :through => :children, :source => :created_by |
| 8 | 8 |
plugins/proposals_discussion/public/style.css
| 1 | +.private-proposals .proposal { | ||
| 2 | + background: rgb(249, 252, 193); | ||
| 3 | +} | ||
| 4 | + | ||
| 1 | .proposal { | 5 | .proposal { |
| 2 | background: rgb(236, 236, 236); | 6 | background: rgb(236, 236, 236); |
| 3 | width: 100%; | 7 | width: 100%; |
| @@ -30,7 +34,7 @@ | @@ -30,7 +34,7 @@ | ||
| 30 | } | 34 | } |
| 31 | 35 | ||
| 32 | .proposal .content:hover, .proposal .topic:hover { | 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 | .proposal .title { | 40 | .proposal .title { |
plugins/proposals_discussion/views/content_viewer/_proposals_list.html.erb
| @@ -9,7 +9,16 @@ | @@ -9,7 +9,16 @@ | ||
| 9 | }); | 9 | }); |
| 10 | </script> | 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 | <div class="proposals"> | 20 | <div class="proposals"> |
| 21 | + <h5><%= _('Proposals') %></h5> | ||
| 13 | <div class="more"> | 22 | <div class="more"> |
| 14 | <img src="/images/loading.gif" alt="Loading" /><%= _("Loading...") %> | 23 | <img src="/images/loading.gif" alt="Loading" /><%= _("Loading...") %> |
| 15 | <%= link_to '', url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier }) %> | 24 | <%= link_to '', url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier }) %> |
plugins/proposals_discussion/views/content_viewer/proposal.html.erb
| @@ -17,3 +17,11 @@ | @@ -17,3 +17,11 @@ | ||
| 17 | <h5><%= _('Body') %></h4> | 17 | <h5><%= _('Body') %></h4> |
| 18 | <div class="content"><%= @page.body %></div> | 18 | <div class="content"><%= @page.body %></div> |
| 19 | </div> | 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 %> |