diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 514f68d49..23fe19333 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -600,7 +600,7 @@ private def has_login unless @attachment && @attachment.container_type == "PhoneAppVersion" - render_403 if !User.current.logged? && @attachment.container_type != 'OrgSubfield' && @attachment.container_type != 'OrgDocumentComment' + render_403 if !User.current.logged? && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download) end end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index c8dcf0b8e..5966b310f 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -25,7 +25,9 @@ class CommentsController < ApplicationController def create raise Unauthorized unless @news.commentable? - + if !@news.org_subfield_id.nil? + @org_subfield = OrgSubfield.find(@news.org_subfield_id) + end @comment = Comment.new #@project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment] if params[:user_activity_id] diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index d3ac71b99..0962deb10 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -46,15 +46,16 @@ class NewsController < ApplicationController @course = Course.find(params[:course_id]) end if @project + @page = params[:page] ? params[:page].to_i + 1 : 0 scope = @project ? @project.news.visible : News.visible @news_count = scope.count - @news_pages = Paginator.new @news_count, @limit, params['page'] - @offset ||= @news_pages.offset + #@news_pages = Paginator.new @news_count, @limit, params['page'] + #@offset ||= @news_pages.offset @newss = scope.all(:include => [:author, :project], :order => "#{News.table_name}.created_on DESC", - :offset => @offset, - :limit => @limit) + :offset => @page * 10, + :limit => 10) respond_to do |format| format.html { @@ -63,6 +64,7 @@ class NewsController < ApplicationController render :layout => false if request.xhr? } + format.js format.api format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") } end @@ -144,6 +146,10 @@ class NewsController < ApplicationController if @course render :layout => 'base_courses' end + elsif @news.org_subfield_id + @org_subfield = OrgSubfield.find(@news.org_subfield_id) + @organization = @org_subfield.organization + render :layout => 'base_org' end end @@ -151,6 +157,21 @@ class NewsController < ApplicationController #modify by nwb if @project @news = News.new(:project => @project, :author => User.current) + @news.safe_attributes = params[:news] + @news.save_attachments(params[:attachments]) + if @news.save + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS + end + render_attachment_warning_if_needed(@news) + #flash[:notice] = l(:notice_successful_create) + redirect_to project_news_index_url(@project) + else + redirect_to project_news_index_url(@project) + #layout_file = 'base_courses' + #render :action => 'new', :layout => layout_file + end elsif @course @news = News.new(:course => @course, :author => User.current) #render :layout => 'base_courses' @@ -221,8 +242,14 @@ class NewsController < ApplicationController end def edit + if @news.org_subfield_id + @org_subfield = OrgSubfield.find(@news.org_subfield_id) + @organization = @org_subfield.organization + end if @course render :layout => "base_courses" + elsif @org_subfield + render :layout => 'base_org' end end @@ -240,12 +267,17 @@ class NewsController < ApplicationController end def destroy + if @news.org_subfield_id + @org_subfield = OrgSubfield.find(@news.org_subfield_id) + end @news.destroy # modify by nwb if @project redirect_to project_news_index_url(@project) elsif @course redirect_to course_news_index_url(@course) + elsif @org_subfield + redirect_to organization_path(@org_subfield.organization, :org_subfield_id => @org_subfield.id) end end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 39ece6fbe..361303833 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -116,6 +116,7 @@ class OrganizationsController < ApplicationController @organization.description = params[:organization][:description] # @organization.domain = params[:organization][:domain] @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0 + @organization.allow_guest_download = params[:organization][:allow_guest_download] == 'on' ? 1 : 0 #@organization.name = params[:organization][:name] @organization.save respond_to do |format| @@ -300,7 +301,11 @@ class OrganizationsController < ApplicationController def org_resources_subfield @org = Organization.find(params[:id]) - @subfield = @org.org_subfields.where('field_type = "Resource" ') + if params[:send_type].present? and params[:send_type] == 'news' + @subfield = @org.org_subfields.where("field_type = 'Post'") + else + @subfield = @org.org_subfields.where('field_type = "Resource" ') + end respond_to do | format| format.js end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b7e507b28..b1c384ae4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1773,6 +1773,48 @@ class UsersController < ApplicationController end end + def share_news_to_course + news = News.find(params[:send_id]) + course_ids = params[:course_ids] + course_ids.each do |course_id| + if Course.find(course_id).news.map(&:id).exclude?(news.id) + course_news = News.create(:course_id => course_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1) + news.attachments.each do |attach| + course_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) + end + end + end + end + + def share_news_to_project + news = News.find(params[:send_id]) + project_ids = params[:project_ids] + project_ids.each do |project_id| + if Project.find(project_id).news.map(&:id).exclude?(news.id) + project_news = News.create(:project_id => project_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now) + news.attachments.each do |attach| + project_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) + end + end + end + end + + def share_news_to_org + news = News.find(params[:send_id]) + field_id = params[:subfield] + org_news = News.create(:org_subfield_id => field_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1) + news.attachments.each do |attach| + org_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) + end + OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'News', :org_act_id => org_news.id, :user_id => User.current.id) + end + def change_org_subfield end @@ -2122,9 +2164,17 @@ class UsersController < ApplicationController @user = User.current if !params[:search].nil? #发送到有栏目类型为资源的组织中 search = "%#{params[:search].to_s.strip.downcase}%" - @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + if params[:send_type].present? and params[:send_type] == 'news' + @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0} + else + @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + end else - @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + if params[:send_type].present? and params[:send_type] == 'news' + @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0} + else + @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + end end @search = params[:search] #这里仅仅是传递需要发送的资源id diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 318de2942..e7a17d4d1 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -379,6 +379,16 @@ class Mailer < ActionMailer::Base end + # issue截止时间提醒 + def issue_due_date(issue, recipients) + @author = issue.author.login + @issue_name = issue.subject + @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id) + @subject = "#{l(:mail_issue)}#{issue.subject} #{l(:mail_issue_due_date)} " + mail :to => recipients, + :subject => @subject + end + # Builds a Mail::Message object used to email recipients of the added issue. # # Example: diff --git a/app/models/news.rb b/app/models/news.rb index 7c44f7e8a..fee5d2801 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -22,6 +22,7 @@ class News < ActiveRecord::Base has_many_kindeditor_assets :assets, :dependent => :destroy #added by nwb belongs_to :course,:touch => true + belongs_to :org_subfield, :touch => true belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :comments, :as => :commented, :dependent => :destroy, :order => "created_on" # fq @@ -57,7 +58,7 @@ class News < ActiveRecord::Base after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count after_update :update_activity - after_destroy :delete_kindeditor_assets, :decrease_news_count + after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities scope :visible, lambda {|*args| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) @@ -187,4 +188,8 @@ class News < ActiveRecord::Base Mailer.run.news_added(self) if Setting.notified_events.include?('news_added') end + def delete_org_activities + OrgActivity.where("container_type='OrgSubfield' and org_act_type='News' and org_act_id=?", self.id).destroy_all + end + end \ No newline at end of file diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index b109ba042..c62cbf4f8 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -6,6 +6,7 @@ class OrgSubfield < ActiveRecord::Base has_many :org_subfield_messages, :dependent => :destroy has_many :messages, :through => :org_subfield_messages has_many :boards, :dependent => :destroy + has_many :news, :dependent => :destroy acts_as_attachable after_create :create_board_sync # 创建资源栏目讨论区 diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index 8f0c5f38d..f94eda065 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -1,6 +1,8 @@ <% if @course %> -$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); +<% elsif @project %> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'projects/project_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); <% else %> -$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'projects/project_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'organizations/org_subfield_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); <% end %> init_activity_KindEditor_data('<%= @user_activity_id%>',"","87%", "UserActivity"); diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index f1d96d22c..47c08d2fb 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -43,7 +43,7 @@ <% if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" %>