Merge remote-tracking branch 'origin/szzh' into szzh

This commit is contained in:
sw 2014-07-14 13:54:14 +08:00
commit b704a44dfb
14 changed files with 66 additions and 12 deletions

View File

@ -630,7 +630,13 @@ class CoursesController < ApplicationController
:with_subprojects => false,
:author => @author)
@activity.scope_select {|t| has["show_#{t}"]}
events = @activity.events(@date_from, @date_to)
# modify by nwb
# 添加私密性判断
if User.current.member_of_course?(@course)|| User.current.admin?
events = @activity.events(@date_from, @date_to)
else
events = @activity.events(@date_from, @date_to, :is_public => 1)
end
@offset, @limit = api_offset_and_limit({:limit => 10})
@events_count = events.count

View File

@ -23,6 +23,7 @@ class DocumentsController < ApplicationController
before_filter :find_model_object, :except => [:index, :new, :create]
before_filter :find_project_from_association, :except => [:index, :new, :create]
before_filter :authorize , :except => [:index]#Added by young
before_filter :authorize_document
helper :attachments
@ -100,4 +101,12 @@ class DocumentsController < ApplicationController
end
redirect_to document_path(@document)
end
# 权限判断
# add by nwb
def authorize_document
if !(User.current.admin? || User.current.member_of?(@project) || @document.is_public==1)
render_403 :message => :notice_not_authorized
end
end
end

View File

@ -697,8 +697,14 @@ class ProjectsController < ApplicationController
@activity.scope_select {|t| !has["show_#{t}"].nil?}
# logger.debug "=========================================#{@activity.scope}"
# @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
#Added by young
events = @activity.events(@date_from, @date_to)
# modify by nwb
# 添加私密性判断
if User.current.member_of?(@project)|| User.current.admin?
events = @activity.events(@date_from, @date_to)
else
events = @activity.events(@date_from, @date_to, :is_public => 1)
end
@offset, @limit = api_offset_and_limit({:limit => 10})
@events_count = events.count

View File

@ -39,19 +39,22 @@ class Attachment < ActiveRecord::Base
#课程资源文件
acts_as_activity_provider :type => 'course_files',
:is_public => 'attachments.is_public',
:permission => :view_files,
:author_key => :author_id,
:find_options => {:select => "#{Attachment.table_name}.*",
:joins => "LEFT JOIN #{Course.table_name} ON ( #{Attachment.table_name}.container_type='Course' AND #{Attachment.table_name}.container_id = #{Course.table_name}.id )"}
acts_as_activity_provider :type => 'files',
:is_public => 'attachments.is_public',
:permission => :view_files,
:author_key => :author_id,
:find_options => {:select => "#{Attachment.table_name}.*",
:find_options => { :select => "#{Attachment.table_name}.*",
:joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
"LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id OR ( #{Attachment.table_name}.container_type='Project' AND #{Attachment.table_name}.container_id = #{Project.table_name}.id )"}
acts_as_activity_provider :type => 'documents',
:is_public => 'documents.is_public',
:permission => :view_documents,
:author_key => :author_id,
:find_options => {:select => "#{Attachment.table_name}.*",

View File

@ -30,7 +30,8 @@ class Document < ActiveRecord::Base
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
:author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) },
:url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
acts_as_activity_provider :find_options => {:include => :project}
acts_as_activity_provider :find_options => {:include => :project},
:is_public => 'documents.is_public'
validates_presence_of :project, :title, :category
validates_length_of :title, :maximum => 60
@ -39,7 +40,7 @@ class Document < ActiveRecord::Base
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
}
safe_attributes 'category_id', 'title', 'description'
safe_attributes 'category_id', 'title', 'description','is_public'
def visible?(user=User.current)
!user.nil? && user.allowed_to?(:view_documents, project)

View File

@ -1,3 +1,3 @@
class FirstPage < ActiveRecord::Base
attr_accessible :description, :title, :web_title
attr_accessible :description, :title, :web_title,:page_type
end

View File

@ -2,11 +2,19 @@
<% contests.each do |contest|%>
<table width="95%" border="0" style="padding-left: 10px; padding-top: 10px;">
<tr>
<td colspan="2" valign="top" width="50" ><%= link_to(image_tag(url_to_avatar(contest.author), :class => 'avatar'), user_path(contest.author), :class => "avatar") %></td>
<td colspan="2" valign="top" width="50" >
<% unless contest.author.nil? %>
<%= link_to(image_tag(url_to_avatar(contest.author), :class => 'avatar'), user_path(contest.author), :class => "avatar") %>
<% end %>
</td>
<td>
<table width="100%" border="0">
<tr>
<td colspan="2" valign="top"><strong><%= link_to(contest.author, user_path(contest.author), :class => 'bid_user') %>: &nbsp;<%= link_to(contest.name, show_contest_contest_path(contest), :class => 'bid_path', :target => "_blank") %></strong></td>
<td colspan="2" valign="top"><strong>
<% unless contest.author.nil? %>
<%= link_to(contest.author, user_path(contest.author), :class => 'bid_user') %>:
<% end %>
&nbsp;<%= link_to(contest.name, show_contest_contest_path(contest), :class => 'bid_path', :target => "_blank") %></strong></td>
</tr>
<tr>
<td width="500">

View File

@ -1,7 +1,10 @@
<%= error_messages_for @document %>
<div class="box tabular">
<p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
<p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %> </p>
<p> <em style ="display: block;font-size: 90%;font-style: normal;"><%= f.check_box :is_public, :style => "margin-left:10px;" %>
<%= l(:label_document_public_info) %></em>
</p>
<p><%= f.text_field :title, :required => true, :size => 60 %></p>
<p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
</div>

View File

@ -3,7 +3,11 @@
<% if forums.any? %>
<% forums.each do |forum| %>
<div class="forums-index">
<div class="forums-inex-avatar"><%= link_to image_tag(url_to_avatar(forum.creator), :class => "avatar"), user_path(forum.creator) %></div>
<div class="forums-inex-avatar">
<% unless forum.creator.nil? %>
<%= link_to image_tag(url_to_avatar(forum.creator), :class => "avatar"), user_path(forum.creator) %>
<% end %>
</div>
<div class="forums-index-content">
<p ><%= link_to h(forum.name), forum_path(forum) %></p>
<p ><%= forum.description%></p>

View File

@ -537,6 +537,7 @@ en:
label_document_new: New document
label_document_plural: Documents
label_document_added: Document added
label_document_public_info: "If you don't choose public, only the project's members can see the document."
label_role: Role
label_role_plural: Roles
label_role_new: New role

View File

@ -537,6 +537,7 @@ zh:
label_document_new: 新建文档
label_document_plural: 文档
label_document_added: 文档已添加
label_document_public_info: (打钩为公开,不打钩则不公开,若不公开,仅项目成员可见该文档。)
label_role: 角色
label_role_plural: 角色
label_role_new: 新建角色

View File

@ -0,0 +1,5 @@
class AddIsPublicToDocuments < ActiveRecord::Migration
def change
add_column :documents, :is_public, :integer,:default => 1
end
end

View File

@ -29,7 +29,7 @@ module Redmine
send :include, Redmine::Acts::ActivityProvider::InstanceMethods
end
options.assert_valid_keys(:type, :permission, :timestamp, :author_key, :find_options, :func)
options.assert_valid_keys(:type, :permission, :timestamp, :author_key, :find_options, :func,:is_public)
self.activity_provider_options ||= {}
# One model can provide different event types
@ -65,6 +65,11 @@ module Redmine
scope = scope.scoped(:conditions => ["#{provider_options[:author_key]} = ?", options[:author].id])
end
# add by nwb
if options[:is_public] && !provider_options[:is_public].nil?
scope = scope.scoped(:conditions => ["#{provider_options[:is_public]} = ?", options[:is_public]])
end
if options[:limit]
# id and creation time should be in same order in most cases
scope = scope.scoped(:order => "#{table_name}.id DESC", :limit => options[:limit])

View File

@ -82,6 +82,8 @@ module Redmine
def events(from = nil, to = nil, options={})
e = []
@options[:limit] = options[:limit]
# modify by nwb
@options[:is_public] = options[:is_public]
@scope.each do |event_type|
constantized_providers(event_type).each do |provider|