Commit 1db348b82e1aa60abc6679bb75225604e2e696c0

Authored by Marcos Pereira
Committed by Tallys Martins
1 parent 03744acd

WorkAssignment submissions visibility edition is now working for admins user

- Refactored the name of the action to edit_visibility
- Refactored edit_visibility behavior to apply privacy to also the Folder's children
- Fixed bug on plugin content_viewer filter not passing the right path of article

Signed-off-by: Andre Bernardes <andrebsguedes@gmail.com>
Signed-off-by: Filipe Ribeiro <firibeiro77@live.com>
Signed-off-by: Dylan Guedes <djmgguedes@gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
app/controllers/my_profile/cms_controller.rb
@@ -30,7 +30,8 @@ class CmsController &lt; MyProfileController @@ -30,7 +30,8 @@ class CmsController &lt; MyProfileController
30 (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) 30 (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)))
31 end 31 end
32 32
33 - protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files, :new] do |c, user, profile| 33 + action_list = [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files, :new]
  34 + protect_if :except => action_list do |c, user, profile|
34 user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) 35 user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))
35 end 36 end
36 37
@@ -48,6 +49,8 @@ class CmsController &lt; MyProfileController @@ -48,6 +49,8 @@ class CmsController &lt; MyProfileController
48 profile.articles.find(c.params[:id]).allow_edit?(user) 49 profile.articles.find(c.params[:id]).allow_edit?(user)
49 end 50 end
50 51
  52 +
  53 +
51 def boxes_holder 54 def boxes_holder
52 profile 55 profile
53 end 56 end
lib/noosfero/plugin.rb
@@ -224,6 +224,12 @@ class Noosfero::Plugin @@ -224,6 +224,12 @@ class Noosfero::Plugin
224 false 224 false
225 end 225 end
226 226
  227 + # -> Add action names to a list of filtered actions on cms controller
  228 + # returns = []
  229 + def add_action_to_list
  230 + []
  231 + end
  232 +
227 # -> Adds buttons to the control panel 233 # -> Adds buttons to the control panel
228 # returns = { :title => title, :icon => icon, :url => url } 234 # returns = { :title => title, :icon => icon, :url => url }
229 # title = name that will be displayed. 235 # title = name that will be displayed.
plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
1 class WorkAssignmentPluginCmsController < CmsController 1 class WorkAssignmentPluginCmsController < CmsController
2 2
3 - def edits 3 + def edit_visibility
4 @folder = profile.articles.find(params[:article_id]) 4 @folder = profile.articles.find(params[:article_id])
5 @back_to = url_for(@folder.parent.url) 5 @back_to = url_for(@folder.parent.url)
6 if request.post? 6 if request.post?
7 @folder.published = params[:article][:published] 7 @folder.published = params[:article][:published]
8 unless params[:q].nil? 8 unless params[:q].nil?
9 @folder.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i} 9 @folder.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i}
  10 + @folder.children.each do |c|
  11 + c.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i}
  12 + c.save!
  13 + end
10 end 14 end
11 @folder.save! 15 @folder.save!
12 redirect_to @back_to 16 redirect_to @back_to
13 - x = Article.find_by_id(@folder.id)  
14 - puts "a"*55  
15 - puts "#{x.published?}"  
16 end 17 end
17 end 18 end
18 end 19 end
19 \ No newline at end of file 20 \ No newline at end of file
plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -9,18 +9,8 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -9,18 +9,8 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
9 end 9 end
10 10
11 def self.can_download_submission?(user, submission) 11 def self.can_download_submission?(user, submission)
12 - work_assignment = submission.parent.parent  
13 - submission_folder = submission.parent  
14 -  
15 - if work_assignment.allow_privacy_edition  
16 - submission_folder.published? || (user && (submission.author == user ||  
17 - user.has_permission?('view_private_content', work_assignment.profile)))  
18 - else  
19 - # work_assignment.publish_submissions || (user && (submission.author == user ||  
20 - # user.has_permission?('view_private_content', work_assignment.profile) ||  
21 - # work_assignment.display_unpublished_article_to?(user)))  
22 - false  
23 - end 12 + submission.published? || (user && (submission.author == user || user.has_permission?('view_private_content', submission.profile) ||
  13 + submission.display_unpublished_article_to?(user)))
24 end 14 end
25 15
26 def self.is_submission?(content) 16 def self.is_submission?(content)
@@ -47,7 +37,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -47,7 +37,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
47 37
48 def content_viewer_controller_filters 38 def content_viewer_controller_filters
49 block = proc do 39 block = proc do
50 - path = params[:page] 40 + path = get_path(params[:page], params[:format])
51 content = profile.articles.find_by_path(path) 41 content = profile.articles.find_by_path(path)
52 42
53 if WorkAssignmentPlugin.is_submission?(content) && !WorkAssignmentPlugin.can_download_submission?(user, content) 43 if WorkAssignmentPlugin.is_submission?(content) && !WorkAssignmentPlugin.can_download_submission?(user, content)
@@ -92,4 +82,10 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -92,4 +82,10 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
92 end 82 end
93 end 83 end
94 84
  85 + def add_action_to_list
  86 + proc do
  87 + action_list.append(", edits, search_article_privacy_exceptions")
  88 + end
  89 + end
  90 +
95 end 91 end
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
@@ -50,7 +50,6 @@ module WorkAssignmentPlugin::Helper @@ -50,7 +50,6 @@ module WorkAssignmentPlugin::Helper
50 end 50 end
51 end 51 end
52 52
53 -  
54 def link_to_last_submission(author_folder, user) 53 def link_to_last_submission(author_folder, user)
55 if WorkAssignmentPlugin.can_download_submission?(user, author_folder.children.last) 54 if WorkAssignmentPlugin.can_download_submission?(user, author_folder.children.last)
56 link_to(author_folder.name, author_folder.children.last.url) 55 link_to(author_folder.name, author_folder.children.last.url)
@@ -58,6 +57,7 @@ module WorkAssignmentPlugin::Helper @@ -58,6 +57,7 @@ module WorkAssignmentPlugin::Helper
58 author_folder.name 57 author_folder.name
59 end 58 end
60 end 59 end
  60 +
61 # FIXME Copied from custom-froms. Consider passing it to core... 61 # FIXME Copied from custom-froms. Consider passing it to core...
62 def time_format(time) 62 def time_format(time)
63 minutes = (time.min == 0) ? '' : ':%M' 63 minutes = (time.min == 0) ? '' : ':%M'
@@ -67,23 +67,24 @@ module WorkAssignmentPlugin::Helper @@ -67,23 +67,24 @@ module WorkAssignmentPlugin::Helper
67 end 67 end
68 68
69 def display_delete_button(article) 69 def display_delete_button(article)
70 - expirable_button article, :delete, _('Delete'), {:controller =>'cms', :action => 'destroy', :id => article.id }, :method => :post, :confirm => delete_article_message(article) 70 + expirable_button article, :delete, _('Delete'),
  71 + {:controller =>'cms', :action => 'destroy', :id => article.id },
  72 + :method => :post, :confirm => delete_article_message(article)
71 end 73 end
72 74
73 -  
74 def display_privacy_button(author_folder, user) 75 def display_privacy_button(author_folder, user)
75 if author_folder 76 if author_folder
76 @folder = environment.articles.find_by_id(author_folder.id) 77 @folder = environment.articles.find_by_id(author_folder.id)
77 work_assignment = @folder.parent 78 work_assignment = @folder.parent
78 79
79 - if(user && (author_folder.author_id == user.id || user.has_permission?('view_private_content', work_assignment.profile))) 80 + if(user && work_assignment.allow_privacy_edition && (author_folder.author_id == user.id || user.has_permission?('view_private_content', work_assignment.profile)))
80 @tokenized_children = prepare_to_token_input( 81 @tokenized_children = prepare_to_token_input(
81 profile.members.includes(:articles_with_access).find_all{ |m| 82 profile.members.includes(:articles_with_access).find_all{ |m|
82 m.articles_with_access.include?(@folder) 83 m.articles_with_access.include?(@folder)
83 } 84 }
84 ) 85 )
85 - colorbox_button('edit', _('Edit'), :controller => 'work_assignment_plugin_cms',  
86 - :action => 'edits', :layout => false, :article_id => @folder.id, :tokenized_children => @tokenized_children) 86 + colorbox_button :edit, _('Edit'), { :controller => 'work_assignment_plugin_cms',
  87 + :action => 'edit_visibility', :article_id => @folder.id, :tokenized_children => @tokenized_children}
87 end 88 end
88 end 89 end
89 end 90 end
plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
@@ -45,6 +45,7 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder @@ -45,6 +45,7 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder
45 :parent => self, 45 :parent => self,
46 :profile => profile, 46 :profile => profile,
47 :author => author, 47 :author => author,
  48 + :published => publish_submissions,
48 }, 49 },
49 :without_protection => true 50 :without_protection => true
50 ) 51 )
plugins/work_assignment/public/content_resize.js 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +
  2 +
  3 + alert( 'oi');
plugins/work_assignment/views/cms/edit_visibility.html.erb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +<!-- <div class='<%= (environment.enabled?('media_panel') ? 'with_media_panel' : 'no_media_panel') %>'> -->
  2 +<div class="select-privacy-options">
  3 +<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %>
  4 +
  5 + <% @article = environment.articles.find_by_id((params[:article_id]))%>
  6 +
  7 + <% @tokenized_children = params[:tokenized_children]%>
  8 +
  9 + <%= hidden_field_tag('article_id', @article.id) %>
  10 +
  11 + <div id='edit-article-options'>
  12 + <%= options_for_article(@article, @tokenized_children) %>
  13 + </div>
  14 +
  15 + <% button_bar do %>
  16 + <%= submit_button :save, _('Save') %>
  17 + <%= colorbox_close_button(_('Cancel')) %>
  18 + <% end %>
  19 +<% end %>
  20 +</div>
  21 +
  22 +<br style='clear: both'/>
  23 +
  24 +<%= javascript_include_tag "article.js" %>
0 \ No newline at end of file 25 \ No newline at end of file
plugins/work_assignment/views/cms/edits.html.erb
@@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
1 -<!-- <div class='<%= (environment.enabled?('media_panel') ? 'with_media_panel' : 'no_media_panel') %>'> -->  
2 -<div class="select-privacy-options">  
3 -<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %>  
4 -  
5 - <% @article = environment.articles.find_by_id((params[:article_id]))%>  
6 -  
7 - <% @tokenized_children = params[:tokenized_children]%>  
8 -  
9 - <%= hidden_field_tag('article_id', @article.id) %>  
10 -  
11 - <div id='edit-article-options'>  
12 - <%= options_for_article(@article, @tokenized_children) %>  
13 - </div>  
14 -  
15 - <% button_bar do %>  
16 - <%= submit_button :save, _('Save') %>  
17 - <%= colorbox_close_button(_('Cancel')) %>  
18 - <% end %>  
19 -<% end %>  
20 -</div>  
21 -  
22 -<br style='clear: both'/>  
23 -  
24 -<%= javascript_include_tag "article.js" %>  
25 \ No newline at end of file 0 \ No newline at end of file