From 2bba0ddd704485a7577db823157774c5284fbf28 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Wed, 14 Jan 2015 16:08:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E3=80=8A=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E9=99=84=E4=BB=B6=E4=B8=8B=E8=BD=BD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=8F=8A=E7=A7=81=E6=9C=89=E9=A1=B9=E7=9B=AE=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=99=BB=E5=BD=95=E3=80=8B=20Signed-off-by:=20alan=20?= =?UTF-8?q?<547533434@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 36 +++++++++++++++++++++-- app/controllers/attachments_controller.rb | 3 +- app/controllers/issues_controller.rb | 3 +- app/models/mailer.rb | 25 ++++++++++++++-- app/views/mailer/issue_add.html.erb | 11 +++++++ app/views/mailer/issue_add.text.erb | 4 +++ 6 files changed, 76 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1e7ccb952..a017753f6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -248,8 +248,8 @@ class ApplicationController < ActionController::Base end end end - def authorize1(ctrl = params[:controller], action = params[:action],login = params[:user_name],pwd = params[:password], global = false) - #modify by NWB + def authorize1(ctrl = params[:controller], action = params[:action],login = params[:user_name],password = params[:password], global = false) + if(!User.current.logged? && !login.nil?) password_authentication end @@ -278,6 +278,7 @@ class ApplicationController < ActionController::Base allowed end def authorize_attachment_download(ctrl = params[:controller], action = params[:action], global = false) + case @attachment.container_type when "Memo" allowed = User.current.allowed_to?(:memos_attachments_download,nil,:global => true) @@ -306,6 +307,37 @@ class ApplicationController < ActionController::Base end end + def authorize_attachment_download1(ctrl = params[:controller], action = params[:action],login = params[:user_name],password = params[:password], global = false) + if(!User.current.logged? && !login.nil?) + password_authentication + end + case @attachment.container_type + when "Memo" + allowed = User.current.allowed_to?(:memos_attachments_download,nil,:global => true) + when "Message" + if @project + allowed = User.current.allowed_to?(:projects_attachments_download,@project,:global => false) + elsif @course + allowed = User.current.allowed_to?(:course_attachments_download, @course, :global => false) + end + when "contest" + return true + when "Course" + allowed = User.current.allowed_to?(:course_attachments_download, @course, :global => false) + else + return true + end + + if allowed + true + else + if @project && @project.archived? + render_403 :message => :notice_not_authorized_archived_project + else + deny_access + end + end + end def authorize_course(ctrl = params[:controller], action = params[:action], global = false) allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @course, :global => global) if allowed diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 952dcdf44..2c6a002b4 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -17,11 +17,12 @@ class AttachmentsController < ApplicationController layout "users_base" + before_filter :find_project, :only => [:show, :download, :thumbnail, :destroy, :delete_homework]#, :except => [:upload, :autocomplete] before_filter :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young before_filter :delete_authorize, :only => :destroy before_filter :authorize_global, :only => :upload - before_filter :authorize_attachment_download, :only => :download + before_filter :authorize_attachment_download1, :only => :download #before_filter :login_without_softapplication, only: [:download] accept_api_auth :show, :download, :upload require 'iconv' diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 3d270da05..c0d83fdcd 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -19,11 +19,12 @@ class IssuesController < ApplicationController layout 'base_projects'#Added by young default_search_scope :issues + before_filter :authorize1, :only => [:show] before_filter :find_issue, :only => [:show, :edit, :update] before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] before_filter :find_project, :only => [:new, :create, :update_form] #before_filter :authorize, :except => [:index, :show] - before_filter :authorize1, :except => [:index] + before_filter :authorize, :except => [:index] before_filter :find_optional_project, :only => [:index] before_filter :check_for_default_issue_status, :only => [:new, :create] diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 9f599916f..327dd6b4a 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -110,7 +110,12 @@ class Mailer < ActionMailer::Base else @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id) end + + # issue.attachments.each do |attach| + # attachments["#{attach.filename}"] = File.read("#{attach.disk_filename}") + # end cc = issue.watcher_recipients - recipients + #mail.attachments['test'] = File.read("#{RAILS.root}/files/2015/01/150114094010_libegl.dll") mail :to => recipients, :cc => cc, :subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}" @@ -132,6 +137,12 @@ class Mailer < ActionMailer::Base references issue @author = journal.user recipients = journal.recipients + if recipients.include? "547533434@qq.com" + @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :anchor => "change-#{journal.id}", :user_name => 'alan', :password => 'alanlong') + else + @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :anchor => "change-#{journal.id}") + end + # Watchers in cc cc = journal.watcher_recipients - recipients s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] " @@ -139,7 +150,7 @@ class Mailer < ActionMailer::Base s << issue.subject @issue = issue @journal = journal - @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") + # @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") mail :to => recipients, :cc => cc, :subject => s @@ -619,5 +630,15 @@ class Mailer < ActionMailer::Base Rails.logger end - + def add_attachments(obj) + if email.attachments && email.attachments.any? + email.attachments.each do |attachment| + obj.attachments << Attachment.create(:container => obj, + :file => attachment.decoded, + :filename => attachment.filename, + :author => user, + :content_type => attachment.mime_type) + end + end + end end diff --git a/app/views/mailer/issue_add.html.erb b/app/views/mailer/issue_add.html.erb index 8c9da02da..da7f8ac65 100644 --- a/app/views/mailer/issue_add.html.erb +++ b/app/views/mailer/issue_add.html.erb @@ -1,3 +1,14 @@ + + <%= l(:text_issue_added, :id => "##{@issue.project_index}", :author => h(@issue.author)) %> +