Commit 03744acd4ab84d8e2779be43d056d3777e57cb4e

Authored by Tallys Martins
1 parent 4fe9e656

Work Assignment Privacy Options

- Added privacy button to work_Assignment uploaded files
- Added style for privacy options
- Applying privacy permitions on Uploaded Files

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>
plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +class WorkAssignmentPluginCmsController < CmsController
  2 +
  3 + def edits
  4 + @folder = profile.articles.find(params[:article_id])
  5 + @back_to = url_for(@folder.parent.url)
  6 + if request.post?
  7 + @folder.published = params[:article][:published]
  8 + unless params[:q].nil?
  9 + @folder.article_privacy_exceptions = params[:q].split(/,/).map{|n| environment.people.find n.to_i}
  10 + end
  11 + @folder.save!
  12 + redirect_to @back_to
  13 + x = Article.find_by_id(@folder.id)
  14 + puts "a"*55
  15 + puts "#{x.published?}"
  16 + end
  17 + end
  18 +end
0 19 \ No newline at end of file
... ...
plugins/work_assignment/controllers/public/work_assignment_plugin_content_viewer_controller.rb
... ... @@ -1,19 +0,0 @@
1   -class WorkAssignmentPluginContentViewerController < ContentViewerController
2   - def toggle_friends_permission
3   - folder = environment.articles.find_by_id(params[:folder_id])
4   - puts "#{params[:folder_id]}"
5   -
6   - if folder
7   - author = folder.author
8   - work_assignment = folder.parent
9   -
10   - if !work_assignment.only_friends.include?(author)
11   - work_assignment.only_friends << author
12   - else
13   - work_assignment.only_friends.delete(author)
14   - end
15   - end
16   - redirect_to :action => :index
17   - #render :action => 'view'
18   - end
19   -end
20 0 \ No newline at end of file
plugins/work_assignment/lib/work_assignment_plugin.rb
... ... @@ -9,20 +9,18 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
9 9 end
10 10  
11 11 def self.can_download_submission?(user, submission)
12   - work_assignment = submission.parent.parent
  12 + work_assignment = submission.parent.parent
  13 + submission_folder = submission.parent
13 14  
14   - if work_assignment.publish_submissions
15   - if work_assignment.only_friends.include?(submission.author)
16   - submission.author.friends.include?(user)
  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)))
17 18 else
18   - true
  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
19 23 end
20   - elsif (user && (submission.author == user || user.has_permission?('view_private_content', work_assignment.profile)))
21   - #work_assignment.publish_submissions || (user && (submission.author == user || user.has_permission?('view_private_content', work_assignment.profile)))
22   - true
23   - else
24   - false
25   - end
26 24 end
27 25  
28 26 def self.is_submission?(content)
... ...
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
... ... @@ -7,6 +7,7 @@ module WorkAssignmentPlugin::Helper
7 7 content_tag('th', c_('Author'), :style => 'width: 50%') +
8 8 content_tag('th', _('Submission date')) +
9 9 content_tag('th', _('Versions'), :style => 'text-align: center') +
  10 + content_tag('th', '') +
10 11 content_tag('th', '')
11 12 ).html_safe +
12 13 work_assignment.children.map {|author_folder| display_author_folder(author_folder, user)}.join("\n").html_safe
... ... @@ -15,14 +16,13 @@ module WorkAssignmentPlugin::Helper
15 16  
16 17 def display_author_folder(author_folder, user)
17 18 return if author_folder.children.empty?
18   - only_friends = author_folder.parent.only_friends
19 19 action = 'toggle_friends_permission'
20 20 content_tag('tr',
21 21 content_tag('td', link_to_last_submission(author_folder, user)) +
22 22 content_tag('td', time_format(author_folder.children.last.created_at)) +
23 23 content_tag('td', author_folder.children.count, :style => 'text-align: center') +
24 24 content_tag('td', content_tag('button', _('View all versions'), :class => 'view-author-versions', 'data-folder-id' => author_folder.id)) +
25   - content_tag('td', button('toggle_friends_permission', only_friends.include?(author_folder.author) ? _('All') : _('Only Friends'),:controller => 'work_assignment_plugin_content_viewer', :action => action, :folder_id => author_folder.id))
  25 + content_tag('td', display_privacy_button(author_folder, user))
26 26 ).html_safe +
27 27 author_folder.children.map {|submission| display_submission(submission, user)}.join("\n").html_safe
28 28 end
... ... @@ -69,4 +69,23 @@ module WorkAssignmentPlugin::Helper
69 69 def display_delete_button(article)
70 70 expirable_button article, :delete, _('Delete'), {:controller =>'cms', :action => 'destroy', :id => article.id }, :method => :post, :confirm => delete_article_message(article)
71 71 end
  72 +
  73 +
  74 + def display_privacy_button(author_folder, user)
  75 + if author_folder
  76 + @folder = environment.articles.find_by_id(author_folder.id)
  77 + work_assignment = @folder.parent
  78 +
  79 + if(user && (author_folder.author_id == user.id || user.has_permission?('view_private_content', work_assignment.profile)))
  80 + @tokenized_children = prepare_to_token_input(
  81 + profile.members.includes(:articles_with_access).find_all{ |m|
  82 + m.articles_with_access.include?(@folder)
  83 + }
  84 + )
  85 + colorbox_button('edit', _('Edit'), :controller => 'work_assignment_plugin_cms',
  86 + :action => 'edits', :layout => false, :article_id => @folder.id, :tokenized_children => @tokenized_children)
  87 + end
  88 + end
  89 + end
  90 +
72 91 end
... ...
plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
... ... @@ -2,12 +2,12 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder
2 2  
3 3 settings_items :publish_submissions, :type => :boolean, :default => false
4 4 settings_items :default_email, :type => :string, :default => ""
5   - settings_items :only_friends, :type => Array, :default => []
  5 + settings_items :allow_privacy_edition, :type => :boolean, :default => false
6 6  
7 7 attr_accessible :publish_submissions
8 8 attr_accessible :default_email
9   - attr_accessible :only_friends
10   -
  9 + attr_accessible :allow_privacy_edition
  10 +
11 11 def self.icon_name(article = nil)
12 12 'work-assignment'
13 13 end
... ... @@ -39,7 +39,15 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder
39 39 end
40 40  
41 41 def find_or_create_author_folder(author)
42   - children.find_by_slug(author.name.to_slug) || Folder.create!(:name => author.name, :parent => self, :profile => profile, :author => author)
  42 + children.find_by_slug(author.name.to_slug) || Folder.create!(
  43 + {
  44 + :name => author.name,
  45 + :parent => self,
  46 + :profile => profile,
  47 + :author => author,
  48 + },
  49 + :without_protection => true
  50 + )
43 51 end
44 52  
45 53 def submissions
... ...
plugins/work_assignment/public/style.css
1 1 .icon-newwork-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) }
2   -.icon-work-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) }
3 2 \ No newline at end of file
  3 +.icon-work-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) }
  4 +.select-privacy-options {
  5 + padding: 5px 20px;
  6 + width: 400px;
  7 + height: 300px;
  8 +}
4 9 \ No newline at end of file
... ...
plugins/work_assignment/views/cms/edits.html.erb 0 → 100644
... ... @@ -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 25 \ No newline at end of file
... ...
plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
... ... @@ -4,3 +4,5 @@
4 4  
5 5 <%=labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %>
6 6  
  7 +<%=labelled_check_box(_('Allow users set privacy?'), 'article[allow_privacy_edition]', true, @article.allow_privacy_edition) %>
  8 +
... ...