添加《邮件加入附件下载功能及私有项目自动登录》

Signed-off-by: alan <547533434@qq.com>
enterprise
alan 11 years ago
parent cd504f8978
commit 2bba0ddd70

@ -248,8 +248,8 @@ class ApplicationController < ActionController::Base
end end
end end
end end
def authorize1(ctrl = params[:controller], action = params[:action],login = params[:user_name],pwd = params[:password], global = false) def authorize1(ctrl = params[:controller], action = params[:action],login = params[:user_name],password = params[:password], global = false)
#modify by NWB
if(!User.current.logged? && !login.nil?) if(!User.current.logged? && !login.nil?)
password_authentication password_authentication
end end
@ -278,6 +278,7 @@ class ApplicationController < ActionController::Base
allowed allowed
end end
def authorize_attachment_download(ctrl = params[:controller], action = params[:action], global = false) def authorize_attachment_download(ctrl = params[:controller], action = params[:action], global = false)
case @attachment.container_type case @attachment.container_type
when "Memo" when "Memo"
allowed = User.current.allowed_to?(:memos_attachments_download,nil,:global => true) allowed = User.current.allowed_to?(:memos_attachments_download,nil,:global => true)
@ -306,6 +307,37 @@ class ApplicationController < ActionController::Base
end end
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) def authorize_course(ctrl = params[:controller], action = params[:action], global = false)
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @course, :global => global) allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @course, :global => global)
if allowed if allowed

@ -17,11 +17,12 @@
class AttachmentsController < ApplicationController class AttachmentsController < ApplicationController
layout "users_base" layout "users_base"
before_filter :find_project, :only => [:show, :download, :thumbnail, :destroy, :delete_homework]#, :except => [:upload, :autocomplete] 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 :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young
before_filter :delete_authorize, :only => :destroy before_filter :delete_authorize, :only => :destroy
before_filter :authorize_global, :only => :upload 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] #before_filter :login_without_softapplication, only: [:download]
accept_api_auth :show, :download, :upload accept_api_auth :show, :download, :upload
require 'iconv' require 'iconv'

@ -19,11 +19,12 @@ class IssuesController < ApplicationController
layout 'base_projects'#Added by young layout 'base_projects'#Added by young
default_search_scope :issues default_search_scope :issues
before_filter :authorize1, :only => [:show]
before_filter :find_issue, :only => [:show, :edit, :update] before_filter :find_issue, :only => [:show, :edit, :update]
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
before_filter :find_project, :only => [:new, :create, :update_form] before_filter :find_project, :only => [:new, :create, :update_form]
#before_filter :authorize, :except => [:index, :show] #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 :find_optional_project, :only => [:index]
before_filter :check_for_default_issue_status, :only => [:new, :create] before_filter :check_for_default_issue_status, :only => [:new, :create]

@ -110,7 +110,12 @@ class Mailer < ActionMailer::Base
else else
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id) @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
end end
# issue.attachments.each do |attach|
# attachments["#{attach.filename}"] = File.read("#{attach.disk_filename}")
# end
cc = issue.watcher_recipients - recipients cc = issue.watcher_recipients - recipients
#mail.attachments['test'] = File.read("#{RAILS.root}/files/2015/01/150114094010_libegl.dll")
mail :to => recipients, mail :to => recipients,
:cc => cc, :cc => cc,
:subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}" :subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}"
@ -132,6 +137,12 @@ class Mailer < ActionMailer::Base
references issue references issue
@author = journal.user @author = journal.user
recipients = journal.recipients 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 # Watchers in cc
cc = journal.watcher_recipients - recipients cc = journal.watcher_recipients - recipients
s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] " s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] "
@ -139,7 +150,7 @@ class Mailer < ActionMailer::Base
s << issue.subject s << issue.subject
@issue = issue @issue = issue
@journal = journal @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, mail :to => recipients,
:cc => cc, :cc => cc,
:subject => s :subject => s
@ -619,5 +630,15 @@ class Mailer < ActionMailer::Base
Rails.logger Rails.logger
end 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 end

@ -1,3 +1,14 @@
<%= l(:text_issue_added, :id => "##{@issue.project_index}", :author => h(@issue.author)) %> <%= l(:text_issue_added, :id => "##{@issue.project_index}", :author => h(@issue.author)) %>
<ul>
<% unless @issue.attachments.nil? %>
<% @issue.attachments.each do |attach| %>
<li> <%= link_to_attachment(attach, :download => true, :only_path => false) %></li>
<% end %>
<% end %>
</ul>
<hr /> <hr />
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :issue_url => @issue_url } %> <%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :issue_url => @issue_url } %>

@ -1,4 +1,8 @@
<%= l(:text_issue_added, :id => "##{@issue.project_index}", :author => @issue.author) %> <%= l(:text_issue_added, :id => "##{@issue.project_index}", :author => @issue.author) %>
<% @issue.attachments.each do |attach| %>
<%= link_to_attachment(attach, :download => true, :only_path => false) %>
<% end %>
---------------------------------------- ----------------------------------------
<%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :issue_url => @issue_url } %> <%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :issue_url => @issue_url } %>

Loading…
Cancel
Save