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

Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
alan 2015-01-14 16:08:56 +08:00
parent cd504f8978
commit 2bba0ddd70
6 changed files with 76 additions and 6 deletions

View File

@ -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

View File

@ -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'

View File

@ -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]

View File

@ -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

View File

@ -1,3 +1,14 @@
<%= 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 />
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :issue_url => @issue_url } %>

View File

@ -1,4 +1,8 @@
<%= 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 } %>