work_assignment_plugin.rb
2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class WorkAssignmentPlugin < Noosfero::Plugin
def self.plugin_name
"Work Assignment"
end
def self.plugin_description
_("New kind of content for organizations.")
end
def self.can_download_submission?(user, submission)
work_assignment = submission.parent.parent
if work_assignment.publish_submissions
if work_assignment.only_friends.include?(submission.author)
submission.author.friends.include?(user)
else
true
end
elsif (user && (submission.author == user || user.has_permission?('view_private_content', work_assignment.profile)))
#work_assignment.publish_submissions || (user && (submission.author == user || user.has_permission?('view_private_content', work_assignment.profile)))
true
else
false
end
end
def self.is_submission?(content)
content && content.parent && content.parent.parent && content.parent.parent.kind_of?(WorkAssignmentPlugin::WorkAssignment)
end
def content_types
[WorkAssignmentPlugin::WorkAssignment] if context.respond_to?(:profile) && context.profile.organization?
end
def stylesheet?
true
end
def content_remove_new(content)
content.kind_of?(WorkAssignmentPlugin::WorkAssignment)
end
def content_remove_upload(content)
if content.kind_of?(WorkAssignmentPlugin::WorkAssignment)
!content.profile.members.include?(context.send(:user))
end
end
def content_viewer_controller_filters
block = proc do
path = params[:page]
content = profile.articles.find_by_path(path)
if WorkAssignmentPlugin.is_submission?(content) && !WorkAssignmentPlugin.can_download_submission?(user, content)
render_access_denied
end
end
{ :type => 'before_filter',
:method_name => 'work_assingment_only_admin_or_owner_download',
:options => {:only => 'view_page'},
:block => block }
end
def cms_controller_filters
block = proc do
if request.post? && params[:uploaded_files]
@email_notification = params[:article_email_notification]
unless !@email_notification || @email_notification.empty?
@email_contact = EmailContact.new(:subject => @parent.name, :receiver => @email_notification, :sender => user)
@email_contact.build_mail_message!(environment, @uploaded_files, @parent.id)
if @email_contact.deliver
session[:notice] = _('Notification successfully sent')
else
session[:notice] = _('Notification not sent')
end
end
end
end
{ :type => 'after_filter',
:method_name => 'send_email_after_upload_file',
:options => {:only => 'upload_files'},
:block => block }
end
def article_extra_fields(article)
proc do
@article = Article.find_by_id(article)
if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment"
render :partial => 'notify_text_field', :locals => { :size => '45'}
end
end
end
end