From 7aab108a3f977b17a595fb8eb91316a4efa353c6 Mon Sep 17 00:00:00 2001 From: Tallys Martins Date: Tue, 6 Jan 2015 17:13:16 +0000 Subject: [PATCH] Refactoring work assignment plugin --- app/controllers/my_profile/cms_controller.rb | 3 +-- plugins/work_assignment/lib/ext/cms_controller.rb | 24 +++++++++++++----------- plugins/work_assignment/lib/work_assignment_plugin/helper.rb | 14 ++++++++------ plugins/work_assignment/views/cms/edit_visibility.html.erb | 3 +-- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index c660c0a..3860d91 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -34,8 +34,7 @@ class CmsController < MyProfileController false end - action_list = [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files, :new] - protect_if :except => action_list do |c, user, profile| + protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files, :new] do |c, user, profile| add_as_exception?(c.action_name) || user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) end diff --git a/plugins/work_assignment/lib/ext/cms_controller.rb b/plugins/work_assignment/lib/ext/cms_controller.rb index b591bb2..e9cd474 100644 --- a/plugins/work_assignment/lib/ext/cms_controller.rb +++ b/plugins/work_assignment/lib/ext/cms_controller.rb @@ -8,19 +8,21 @@ protect_if :only => :edit_visibility do |c,user,profile| end def edit_visibility - @folder = profile.articles.find(params[:article_id]) - @back_to = url_for(@folder.parent.url) - if request.post? - @folder.published = params[:article][:published] - unless params[:q].nil? - @folder.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i} - @folder.children.each do |c| - c.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i} - c.save! + unless params[:article_id].blank? + @folder = profile.articles.find(params[:article_id]) + @back_to = url_for(@folder.parent.url) + unless params[:article].blank? + @folder.published = params[:article][:published] + unless params[:q].nil? + @folder.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i} + @folder.children.each do |c| + c.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i} + c.save! + end end + @folder.save! + redirect_to @back_to end - @folder.save! - redirect_to @back_to end end diff --git a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb index bd40de4..0b10796 100644 --- a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb +++ b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb @@ -68,7 +68,7 @@ module WorkAssignmentPlugin::Helper def display_delete_button(article) expirable_button article, :delete, _('Delete'), - {:controller =>'cms', :action => 'destroy', :id => article.id }, + {:controller =>'cms', :action => 'destroy', :id => article.id }, :method => :post, :confirm => delete_article_message(article) end @@ -76,15 +76,17 @@ module WorkAssignmentPlugin::Helper if author_folder @folder = environment.articles.find_by_id(author_folder.id) work_assignment = @folder.parent + @back_to = url_for(@folder.parent.url) + if(user && work_assignment.allow_privacy_edition && + (author_folder.author_id == user.id || user.has_permission?('view_private_content', work_assignment.profile))) - if(user && work_assignment.allow_privacy_edition && (author_folder.author_id == user.id || user.has_permission?('view_private_content', work_assignment.profile))) @tokenized_children = prepare_to_token_input( profile.members.includes(:articles_with_access).find_all{ |m| m.articles_with_access.include?(@folder) - } - ) - colorbox_button :edit, _('Edit'), { :controller => 'cms', - :action => 'edit_visibility', :article_id => @folder.id, :tokenized_children => @tokenized_children} + }) + button :edit, _('Edit'), { :controller => 'cms', + :action => 'edit_visibility', :article_id => @folder.id, + :tokenized_children => @tokenized_children, :back_to => @back_to}, :method => :post end end end diff --git a/plugins/work_assignment/views/cms/edit_visibility.html.erb b/plugins/work_assignment/views/cms/edit_visibility.html.erb index 9d907f4..ded8bb6 100644 --- a/plugins/work_assignment/views/cms/edit_visibility.html.erb +++ b/plugins/work_assignment/views/cms/edit_visibility.html.erb @@ -1,4 +1,3 @@ -
<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> @@ -14,7 +13,7 @@ <% button_bar do %> <%= submit_button :save, _('Save') %> - <%= colorbox_close_button(_('Cancel')) %> + <%= button :cancel, _('Cancel'), @back_to %> <% end %> <% end %>
-- libgit2 0.21.2