work_assignment_plugin.rb
1.53 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
require_dependency 'ext/uploaded_file'
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
work_assignment.publish_submissions || (user && (submission.author == user || user.has_permission?('view_private_content', work_assignment.profile)))
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.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 = lambda do
path = params[:page].join('/')
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
end