Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
131b15fc7a | ||
|
|
f6b1583a1a | ||
|
|
5bea900443 | ||
|
|
81baddad00 | ||
|
|
f6b5632fec | ||
|
|
f7ede727fd | ||
|
|
b870417860 | ||
|
|
25a7838e0a | ||
|
|
7c3ddf2bc0 | ||
|
|
0f8df81b87 | ||
|
|
c5121d804d | ||
|
|
8bcbbebf65 | ||
|
|
2d2afab549 | ||
|
|
35f601e769 | ||
|
|
b84cffd62e | ||
|
|
2eba0b66d4 | ||
|
|
eb2d814344 | ||
|
|
d9385ce9a2 | ||
|
|
d3522c10e4 | ||
|
|
b9957264eb |
@@ -15,19 +15,11 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AWSProjectWithRepository < ActionWebService::Struct
|
||||
member :id, :int
|
||||
member :identifier, :string
|
||||
member :name, :string
|
||||
member :is_public, :bool
|
||||
member :repository, Repository
|
||||
end
|
||||
|
||||
class SysApi < ActionWebService::API::Base
|
||||
api_method :projects_with_repository_enabled,
|
||||
api_method :projects,
|
||||
:expects => [],
|
||||
:returns => [[AWSProjectWithRepository]]
|
||||
:returns => [[Project]]
|
||||
api_method :repository_created,
|
||||
:expects => [:string, :string, :string],
|
||||
:expects => [:string, :string],
|
||||
:returns => [:int]
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AccountController < ApplicationController
|
||||
layout 'base'
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
@@ -24,21 +25,13 @@ class AccountController < ApplicationController
|
||||
|
||||
# Show user's account
|
||||
def show
|
||||
@user = User.active.find(params[:id])
|
||||
@custom_values = @user.custom_values
|
||||
@user = User.find_active(params[:id])
|
||||
@custom_values = @user.custom_values.find(:all, :include => :custom_field)
|
||||
|
||||
# show only public projects and private projects that the logged in user is also a member of
|
||||
@memberships = @user.memberships.select do |membership|
|
||||
membership.project.is_public? || (User.current.member_of?(membership.project))
|
||||
end
|
||||
|
||||
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
|
||||
@events_by_day = events.group_by(&:event_date)
|
||||
|
||||
if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty?
|
||||
render_404 and return
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
@@ -51,24 +44,16 @@ class AccountController < ApplicationController
|
||||
else
|
||||
# Authenticate user
|
||||
user = User.try_to_login(params[:username], params[:password])
|
||||
if user.nil?
|
||||
# Invalid credentials
|
||||
flash.now[:error] = l(:notice_account_invalid_creditentials)
|
||||
elsif user.new_record?
|
||||
# Onthefly creation failed, display the registration form to fill/fix attributes
|
||||
@user = user
|
||||
session[:auth_source_registration] = {:login => user.login, :auth_source_id => user.auth_source_id }
|
||||
render :action => 'register'
|
||||
else
|
||||
# Valid user
|
||||
if user
|
||||
self.logged_user = user
|
||||
# generate a key and set cookie if autologin
|
||||
if params[:autologin] && Setting.autologin?
|
||||
token = Token.create(:user => user, :action => 'autologin')
|
||||
cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
|
||||
end
|
||||
call_hook(:controller_account_success_authentication_after, {:user => user })
|
||||
redirect_back_or_default :controller => 'my', :action => 'page'
|
||||
else
|
||||
flash.now[:error] = l(:notice_account_invalid_creditentials)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -120,52 +105,43 @@ class AccountController < ApplicationController
|
||||
|
||||
# User self-registration
|
||||
def register
|
||||
redirect_to(home_url) && return unless Setting.self_registration? || session[:auth_source_registration]
|
||||
redirect_to(home_url) && return unless Setting.self_registration?
|
||||
if request.get?
|
||||
session[:auth_source_registration] = nil
|
||||
@user = User.new(:language => Setting.default_language)
|
||||
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
|
||||
else
|
||||
@user = User.new(params[:user])
|
||||
@user.admin = false
|
||||
@user.login = params[:user][:login]
|
||||
@user.status = User::STATUS_REGISTERED
|
||||
if session[:auth_source_registration]
|
||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
|
||||
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x,
|
||||
:customized => @user,
|
||||
:value => (params["custom_fields"] ? params["custom_fields"][x.id.to_s] : nil)) }
|
||||
@user.custom_values = @custom_values
|
||||
case Setting.self_registration
|
||||
when '1'
|
||||
# Email activation
|
||||
token = Token.new(:user => @user, :action => "register")
|
||||
if @user.save and token.save
|
||||
Mailer.deliver_register(token)
|
||||
flash[:notice] = l(:notice_account_register_done)
|
||||
redirect_to :action => 'login'
|
||||
end
|
||||
when '3'
|
||||
# Automatic activation
|
||||
@user.status = User::STATUS_ACTIVE
|
||||
@user.login = session[:auth_source_registration][:login]
|
||||
@user.auth_source_id = session[:auth_source_registration][:auth_source_id]
|
||||
if @user.save
|
||||
session[:auth_source_registration] = nil
|
||||
self.logged_user = @user
|
||||
flash[:notice] = l(:notice_account_activated)
|
||||
redirect_to :controller => 'my', :action => 'account'
|
||||
redirect_to :action => 'login'
|
||||
end
|
||||
else
|
||||
@user.login = params[:user][:login]
|
||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
|
||||
case Setting.self_registration
|
||||
when '1'
|
||||
# Email activation
|
||||
token = Token.new(:user => @user, :action => "register")
|
||||
if @user.save and token.save
|
||||
Mailer.deliver_register(token)
|
||||
flash[:notice] = l(:notice_account_register_done)
|
||||
redirect_to :action => 'login'
|
||||
end
|
||||
when '3'
|
||||
# Automatic activation
|
||||
@user.status = User::STATUS_ACTIVE
|
||||
if @user.save
|
||||
self.logged_user = @user
|
||||
flash[:notice] = l(:notice_account_activated)
|
||||
redirect_to :controller => 'my', :action => 'account'
|
||||
end
|
||||
else
|
||||
# Manual activation by the administrator
|
||||
if @user.save
|
||||
# Sends an email to the administrators
|
||||
Mailer.deliver_account_activation_request(@user)
|
||||
flash[:notice] = l(:notice_account_pending)
|
||||
redirect_to :action => 'login'
|
||||
end
|
||||
# Manual activation by the administrator
|
||||
if @user.save
|
||||
# Sends an email to the administrators
|
||||
Mailer.deliver_account_activation_request(@user)
|
||||
flash[:notice] = l(:notice_account_pending)
|
||||
redirect_to :action => 'login'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AdminController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_admin
|
||||
|
||||
helper :sort
|
||||
@@ -27,32 +28,24 @@ class AdminController < ApplicationController
|
||||
|
||||
def projects
|
||||
sort_init 'name', 'asc'
|
||||
sort_update %w(name is_public created_on)
|
||||
sort_update
|
||||
|
||||
@status = params[:status] ? params[:status].to_i : 1
|
||||
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
||||
@status = params[:status] ? params[:status].to_i : 0
|
||||
conditions = nil
|
||||
conditions = ["status=?", @status] unless @status == 0
|
||||
|
||||
unless params[:name].blank?
|
||||
name = "%#{params[:name].strip.downcase}%"
|
||||
c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name]
|
||||
end
|
||||
|
||||
@project_count = Project.count(:conditions => c.conditions)
|
||||
@project_count = Project.count(:conditions => conditions)
|
||||
@project_pages = Paginator.new self, @project_count,
|
||||
per_page_option,
|
||||
params['page']
|
||||
@projects = Project.find :all, :order => sort_clause,
|
||||
:conditions => c.conditions,
|
||||
:conditions => conditions,
|
||||
:limit => @project_pages.items_per_page,
|
||||
:offset => @project_pages.current.offset
|
||||
|
||||
render :action => "projects", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def plugins
|
||||
@plugins = Redmine::Plugin.all
|
||||
end
|
||||
|
||||
# Loads the default configuration
|
||||
# (roles, trackers, statuses, workflow, enumerations)
|
||||
def default_configuration
|
||||
@@ -86,8 +79,8 @@ class AdminController < ApplicationController
|
||||
@flags = {
|
||||
:default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?,
|
||||
:file_repository_writable => File.writable?(Attachment.storage_path),
|
||||
:plugin_assets_writable => File.writable?(Engines.public_directory),
|
||||
:rmagick_available => Object.const_defined?(:Magick)
|
||||
}
|
||||
@plugins = Redmine::Plugin.registered_plugins
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,21 +15,9 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'uri'
|
||||
require 'cgi'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
class MissingSessionSecret < Exception ; end
|
||||
layout 'base'
|
||||
|
||||
before_filter :user_setup, :check_if_login_required, :set_localization
|
||||
filter_parameter_logging :password
|
||||
|
||||
if session.first[:secret].blank?
|
||||
raise MissingSessionSecret, "Missing session secret. Please run 'rake config/initializers/session_store.rb' to generate one"
|
||||
else
|
||||
protect_from_forgery :secret => session.first[:secret]
|
||||
end
|
||||
|
||||
include Redmine::MenuManager::MenuController
|
||||
helper Redmine::MenuManager::MenuHelper
|
||||
@@ -53,7 +41,7 @@ class ApplicationController < ActionController::Base
|
||||
def find_current_user
|
||||
if session[:user_id]
|
||||
# existing session
|
||||
(User.active.find(session[:user_id]) rescue nil)
|
||||
(User.find_active(session[:user_id]) rescue nil)
|
||||
elsif cookies[:autologin] && Setting.autologin?
|
||||
# auto-login feature
|
||||
User.find_by_autologin_key(cookies[:autologin])
|
||||
@@ -73,11 +61,11 @@ class ApplicationController < ActionController::Base
|
||||
def set_localization
|
||||
User.current.language = nil unless User.current.logged?
|
||||
lang = begin
|
||||
if !User.current.language.blank? && GLoc.valid_language?(User.current.language)
|
||||
if !User.current.language.blank? and GLoc.valid_languages.include? User.current.language.to_sym
|
||||
User.current.language
|
||||
elsif request.env['HTTP_ACCEPT_LANGUAGE']
|
||||
accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.downcase
|
||||
if !accept_lang.blank? && (GLoc.valid_language?(accept_lang) || GLoc.valid_language?(accept_lang = accept_lang.split('-').first))
|
||||
accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first
|
||||
if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym
|
||||
User.current.language = accept_lang
|
||||
end
|
||||
end
|
||||
@@ -89,13 +77,8 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
def require_login
|
||||
if !User.current.logged?
|
||||
# Extract only the basic url parameters on non-GET requests
|
||||
if request.get?
|
||||
url = url_for(params)
|
||||
else
|
||||
url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
|
||||
end
|
||||
redirect_to :controller => "account", :action => "login", :back_url => url
|
||||
store_location
|
||||
redirect_to :controller => "account", :action => "login"
|
||||
return false
|
||||
end
|
||||
true
|
||||
@@ -109,15 +92,11 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def deny_access
|
||||
User.current.logged? ? render_403 : require_login
|
||||
end
|
||||
|
||||
# Authorize the user for the requested action
|
||||
def authorize(ctrl = params[:controller], action = params[:action])
|
||||
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project)
|
||||
allowed ? true : deny_access
|
||||
allowed ? true : (User.current.logged? ? render_403 : require_login)
|
||||
end
|
||||
|
||||
# make sure that the user is a member of the project (or admin) if project is private
|
||||
@@ -136,20 +115,20 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
end
|
||||
|
||||
# store current uri in session.
|
||||
# return to this location by calling redirect_back_or_default
|
||||
def store_location
|
||||
session[:return_to_params] = params
|
||||
end
|
||||
|
||||
# move to the last store_location call or to the passed default one
|
||||
def redirect_back_or_default(default)
|
||||
back_url = CGI.unescape(params[:back_url].to_s)
|
||||
if !back_url.blank?
|
||||
begin
|
||||
uri = URI.parse(back_url)
|
||||
# do not redirect user to another host or to the login or register page
|
||||
if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
|
||||
redirect_to(back_url) and return
|
||||
end
|
||||
rescue URI::InvalidURIError
|
||||
# redirect to default
|
||||
end
|
||||
if session[:return_to_params].nil?
|
||||
redirect_to default
|
||||
else
|
||||
redirect_to session[:return_to_params]
|
||||
session[:return_to_params] = nil
|
||||
end
|
||||
redirect_to default
|
||||
end
|
||||
|
||||
def render_403
|
||||
@@ -188,7 +167,6 @@ class ApplicationController < ActionController::Base
|
||||
# TODO: move to model
|
||||
def attach_files(obj, attachments)
|
||||
attached = []
|
||||
unsaved = []
|
||||
if attachments && attachments.is_a?(Hash)
|
||||
attachments.each_value do |attachment|
|
||||
file = attachment['file']
|
||||
@@ -197,10 +175,7 @@ class ApplicationController < ActionController::Base
|
||||
:file => file,
|
||||
:description => attachment['description'].to_s.strip,
|
||||
:author => User.current)
|
||||
a.new_record? ? (unsaved << a) : (attached << a)
|
||||
end
|
||||
if unsaved.any?
|
||||
flash[:warning] = l(:warning_attachments_not_saved, unsaved.size)
|
||||
attached << a unless a.new_record?
|
||||
end
|
||||
end
|
||||
attached
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,59 +16,24 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AttachmentsController < ApplicationController
|
||||
before_filter :find_project
|
||||
before_filter :read_authorize, :except => :destroy
|
||||
before_filter :delete_authorize, :only => :destroy
|
||||
|
||||
verify :method => :post, :only => :destroy
|
||||
|
||||
def show
|
||||
if @attachment.is_diff?
|
||||
@diff = File.new(@attachment.diskfile, "rb").read
|
||||
render :action => 'diff'
|
||||
elsif @attachment.is_text?
|
||||
@content = File.new(@attachment.diskfile, "rb").read
|
||||
render :action => 'file'
|
||||
elsif
|
||||
download
|
||||
end
|
||||
end
|
||||
|
||||
layout 'base'
|
||||
before_filter :find_project, :check_project_privacy
|
||||
|
||||
def download
|
||||
if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project)
|
||||
@attachment.increment_download
|
||||
end
|
||||
|
||||
# images are sent inline
|
||||
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
||||
:type => @attachment.content_type,
|
||||
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
||||
|
||||
rescue
|
||||
# in case the disk file was deleted
|
||||
render_404
|
||||
end
|
||||
|
||||
def destroy
|
||||
# Make sure association callbacks are called
|
||||
@attachment.container.attachments.delete(@attachment)
|
||||
redirect_to :back
|
||||
rescue ::ActionController::RedirectBackError
|
||||
redirect_to :controller => 'projects', :action => 'show', :id => @project
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def find_project
|
||||
@attachment = Attachment.find(params[:id])
|
||||
# Show 404 if the filename in the url is wrong
|
||||
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
|
||||
@project = @attachment.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
|
||||
def read_authorize
|
||||
@attachment.visible? ? true : deny_access
|
||||
end
|
||||
|
||||
def delete_authorize
|
||||
@attachment.deletable? ? true : deny_access
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AuthSourcesController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class BoardsController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
helper :messages
|
||||
@@ -35,14 +36,12 @@ class BoardsController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
sort_init 'updated_on', 'desc'
|
||||
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
||||
'replies' => "#{Message.table_name}.replies_count",
|
||||
'updated_on' => "#{Message.table_name}.updated_on"
|
||||
sort_init "#{Message.table_name}.updated_on", "desc"
|
||||
sort_update
|
||||
|
||||
@topic_count = @board.topics.count
|
||||
@topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
|
||||
@topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '),
|
||||
@topics = @board.topics.find :all, :order => "#{Message.table_name}.sticky DESC, #{sort_clause}",
|
||||
:include => [:author, {:last_reply => :author}],
|
||||
:limit => @topic_pages.items_per_page,
|
||||
:offset => @topic_pages.current.offset
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class CustomFieldsController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
@@ -38,15 +39,12 @@ class CustomFieldsController < ApplicationController
|
||||
@custom_field = UserCustomField.new(params[:custom_field])
|
||||
when "ProjectCustomField"
|
||||
@custom_field = ProjectCustomField.new(params[:custom_field])
|
||||
when "TimeEntryCustomField"
|
||||
@custom_field = TimeEntryCustomField.new(params[:custom_field])
|
||||
else
|
||||
redirect_to :action => 'list'
|
||||
return
|
||||
end
|
||||
if request.post? and @custom_field.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
|
||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||
end
|
||||
@trackers = Tracker.find(:all, :order => 'position')
|
||||
@@ -59,7 +57,6 @@ class CustomFieldsController < ApplicationController
|
||||
@custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
|
||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||
end
|
||||
@trackers = Tracker.find(:all, :order => 'position')
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class DocumentsController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :find_project, :only => [:index, :new]
|
||||
before_filter :find_document, :except => [:index, :new]
|
||||
before_filter :authorize
|
||||
@@ -35,7 +36,6 @@ class DocumentsController < ApplicationController
|
||||
else
|
||||
@grouped = documents.group_by(&:category)
|
||||
end
|
||||
@document = @project.documents.build
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
@@ -65,12 +65,26 @@ class DocumentsController < ApplicationController
|
||||
@document.destroy
|
||||
redirect_to :controller => 'documents', :action => 'index', :project_id => @project
|
||||
end
|
||||
|
||||
def download
|
||||
@attachment = @document.attachments.find(params[:attachment_id])
|
||||
@attachment.increment_download
|
||||
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
||||
:type => @attachment.content_type
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
|
||||
def add_attachment
|
||||
attachments = attach_files(@document, params[:attachments])
|
||||
Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added')
|
||||
redirect_to :action => 'show', :id => @document
|
||||
end
|
||||
|
||||
def destroy_attachment
|
||||
@document.attachments.find(params[:attachment_id]).destroy
|
||||
redirect_to :action => 'show', :id => @document
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class EnumerationsController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
@@ -74,20 +75,11 @@ class EnumerationsController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
@enumeration = Enumeration.find(params[:id])
|
||||
if !@enumeration.in_use?
|
||||
# No associated objects
|
||||
@enumeration.destroy
|
||||
redirect_to :action => 'index'
|
||||
elsif params[:reassign_to_id]
|
||||
if reassign_to = Enumeration.find_by_opt_and_id(@enumeration.opt, params[:reassign_to_id])
|
||||
@enumeration.destroy(reassign_to)
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
end
|
||||
@enumerations = Enumeration.get_values(@enumeration.opt) - [@enumeration]
|
||||
#rescue
|
||||
# flash[:error] = 'Unable to delete enumeration'
|
||||
# redirect_to :action => 'index'
|
||||
Enumeration.find(params[:id]).destroy
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
redirect_to :action => 'list'
|
||||
rescue
|
||||
flash[:error] = "Unable to delete enumeration"
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class IssueCategoriesController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :settings
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class IssueRelationsController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
def new
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class IssueStatusesController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_admin
|
||||
|
||||
verify :method => :post, :only => [ :destroy, :create, :update, :move ],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,20 +16,23 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class IssuesController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :new_issue, :only => :new
|
||||
|
||||
before_filter :find_issue, :only => [:show, :edit, :reply]
|
||||
before_filter :find_issue, :only => [:show, :edit, :destroy_attachment]
|
||||
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
|
||||
before_filter :find_project, :only => [:new, :update_form, :preview]
|
||||
before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :context_menu]
|
||||
before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
|
||||
accept_key_auth :index, :show, :changes
|
||||
before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu]
|
||||
before_filter :find_optional_project, :only => [:index, :changes]
|
||||
accept_key_auth :index, :changes
|
||||
|
||||
helper :journals
|
||||
helper :projects
|
||||
include ProjectsHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
helper :ifpdf
|
||||
include IfpdfHelper
|
||||
helper :issue_relations
|
||||
include IssueRelationsHelper
|
||||
helper :watchers
|
||||
@@ -40,18 +43,11 @@ class IssuesController < ApplicationController
|
||||
helper :sort
|
||||
include SortHelper
|
||||
include IssuesHelper
|
||||
helper :timelog
|
||||
include Redmine::Export::PDF
|
||||
|
||||
verify :method => :post,
|
||||
:only => :destroy,
|
||||
:render => { :nothing => true, :status => :method_not_allowed }
|
||||
|
||||
def index
|
||||
sort_init "#{Issue.table_name}.id", "desc"
|
||||
sort_update
|
||||
retrieve_query
|
||||
sort_init 'id', 'desc'
|
||||
sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
|
||||
|
||||
if @query.valid?
|
||||
limit = per_page_option
|
||||
respond_to do |format|
|
||||
@@ -69,9 +65,9 @@ class IssuesController < ApplicationController
|
||||
:offset => @issue_pages.current.offset
|
||||
respond_to do |format|
|
||||
format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
|
||||
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
||||
format.atom { render_feed(@issues, :title => l(:label_issue_plural)) }
|
||||
format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
|
||||
format.pdf { send_data(issues_to_pdf(@issues, @project), :type => 'application/pdf', :filename => 'export.pdf') }
|
||||
format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') }
|
||||
end
|
||||
else
|
||||
# Send html if the query is not valid
|
||||
@@ -82,10 +78,9 @@ class IssuesController < ApplicationController
|
||||
end
|
||||
|
||||
def changes
|
||||
sort_init "#{Issue.table_name}.id", "desc"
|
||||
sort_update
|
||||
retrieve_query
|
||||
sort_init 'id', 'desc'
|
||||
sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
|
||||
|
||||
if @query.valid?
|
||||
@journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
|
||||
:conditions => @query.statement,
|
||||
@@ -99,38 +94,33 @@ class IssuesController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }
|
||||
@journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
|
||||
@journals.each_with_index {|j,i| j.indice = i+1}
|
||||
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||
@activities = Enumeration::get_values('ACTI')
|
||||
@priorities = Enumeration::get_values('IPRI')
|
||||
@time_entry = TimeEntry.new
|
||||
respond_to do |format|
|
||||
format.html { render :template => 'issues/show.rhtml' }
|
||||
format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
|
||||
format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
|
||||
format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
|
||||
end
|
||||
end
|
||||
|
||||
# Add a new issue
|
||||
# The new issue will be created from an existing one if copy_from parameter is given
|
||||
def new
|
||||
@issue = Issue.new
|
||||
@issue.copy_from(params[:copy_from]) if params[:copy_from]
|
||||
@issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
|
||||
@issue.project = @project
|
||||
# Tracker must be set before custom field values
|
||||
@issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
|
||||
@issue.author = User.current
|
||||
@issue.tracker ||= @project.trackers.find(params[:tracker_id] ? params[:tracker_id] : :first)
|
||||
if @issue.tracker.nil?
|
||||
flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
|
||||
render :nothing => true, :layout => true
|
||||
return
|
||||
end
|
||||
if params[:issue].is_a?(Hash)
|
||||
@issue.attributes = params[:issue]
|
||||
@issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
|
||||
end
|
||||
@issue.author = User.current
|
||||
|
||||
default_status = IssueStatus.default
|
||||
unless default_status
|
||||
@@ -143,17 +133,20 @@ class IssuesController < ApplicationController
|
||||
|
||||
if request.get? || request.xhr?
|
||||
@issue.start_date ||= Date.today
|
||||
@custom_values = @issue.custom_values.empty? ?
|
||||
@project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
|
||||
@issue.custom_values
|
||||
else
|
||||
requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
|
||||
# Check that the user is allowed to apply the requested status
|
||||
@issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
|
||||
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
|
||||
@issue.custom_values = @custom_values
|
||||
if @issue.save
|
||||
attach_files(@issue, params[:attachments])
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
|
||||
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
|
||||
redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
|
||||
{ :action => 'show', :id => @issue })
|
||||
redirect_to :controller => 'issues', :action => 'show', :id => @issue, :project_id => @project
|
||||
return
|
||||
end
|
||||
end
|
||||
@@ -167,9 +160,10 @@ class IssuesController < ApplicationController
|
||||
|
||||
def edit
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
@activities = Enumeration::get_values('ACTI')
|
||||
@priorities = Enumeration::get_values('IPRI')
|
||||
@custom_values = []
|
||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||
@time_entry = TimeEntry.new
|
||||
|
||||
@notes = params[:notes]
|
||||
journal = @issue.init_journal(User.current, @notes)
|
||||
@@ -181,17 +175,21 @@ class IssuesController < ApplicationController
|
||||
@issue.attributes = attrs
|
||||
end
|
||||
|
||||
if request.post?
|
||||
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
if request.get?
|
||||
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }
|
||||
else
|
||||
# Update custom fields if user has :edit permission
|
||||
if @edit_allowed && params[:custom_fields]
|
||||
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
|
||||
@issue.custom_values = @custom_values
|
||||
end
|
||||
attachments = attach_files(@issue, params[:attachments])
|
||||
attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
|
||||
|
||||
call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
|
||||
|
||||
if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save
|
||||
if @issue.save
|
||||
# Log spend time
|
||||
if User.current.allowed_to?(:log_time, @project)
|
||||
if current_role.allowed_to?(:log_time)
|
||||
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
@time_entry.save
|
||||
end
|
||||
if !journal.new_record?
|
||||
@@ -199,7 +197,6 @@ class IssuesController < ApplicationController
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
||||
end
|
||||
call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
|
||||
redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
|
||||
end
|
||||
end
|
||||
@@ -208,26 +205,6 @@ class IssuesController < ApplicationController
|
||||
flash.now[:error] = l(:notice_locking_conflict)
|
||||
end
|
||||
|
||||
def reply
|
||||
journal = Journal.find(params[:journal_id]) if params[:journal_id]
|
||||
if journal
|
||||
user = journal.user
|
||||
text = journal.notes
|
||||
else
|
||||
user = @issue.author
|
||||
text = @issue.description
|
||||
end
|
||||
content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
|
||||
content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
|
||||
render(:update) { |page|
|
||||
page.<< "$('notes').value = \"#{content}\";"
|
||||
page.show 'update'
|
||||
page << "Form.Element.focus('notes');"
|
||||
page << "Element.scrollTo('update');"
|
||||
page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
|
||||
}
|
||||
end
|
||||
|
||||
# Bulk edit a set of issues
|
||||
def bulk_edit
|
||||
if request.post?
|
||||
@@ -247,7 +224,6 @@ class IssuesController < ApplicationController
|
||||
issue.start_date = params[:start_date] unless params[:start_date].blank?
|
||||
issue.due_date = params[:due_date] unless params[:due_date].blank?
|
||||
issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
|
||||
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
|
||||
# Don't save any change to the issue if the user is not authorized to apply the requested status
|
||||
if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
|
||||
# Send notification for each issue (if changed)
|
||||
@@ -262,12 +238,12 @@ class IssuesController < ApplicationController
|
||||
else
|
||||
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
|
||||
end
|
||||
redirect_to(params[:back_to] || {:controller => 'issues', :action => 'index', :project_id => @project})
|
||||
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
|
||||
return
|
||||
end
|
||||
# Find potential statuses the user could be allowed to switch issues to
|
||||
@available_statuses = Workflow.find(:all, :include => :new_status,
|
||||
:conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq.sort
|
||||
:conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
|
||||
end
|
||||
|
||||
def move
|
||||
@@ -286,7 +262,6 @@ class IssuesController < ApplicationController
|
||||
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
|
||||
unsaved_issue_ids = []
|
||||
@issues.each do |issue|
|
||||
issue.init_journal(User.current)
|
||||
unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
|
||||
end
|
||||
if unsaved_issue_ids.empty?
|
||||
@@ -324,65 +299,16 @@ class IssuesController < ApplicationController
|
||||
@issues.each(&:destroy)
|
||||
redirect_to :action => 'index', :project_id => @project
|
||||
end
|
||||
|
||||
def gantt
|
||||
@gantt = Redmine::Helpers::Gantt.new(params)
|
||||
retrieve_query
|
||||
if @query.valid?
|
||||
events = []
|
||||
# Issues that have start and due dates
|
||||
events += Issue.find(:all,
|
||||
:order => "start_date, due_date",
|
||||
:include => [:tracker, :status, :assigned_to, :priority, :project],
|
||||
:conditions => ["(#{@query.statement}) AND (((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
|
||||
)
|
||||
# Issues that don't have a due date but that are assigned to a version with a date
|
||||
events += Issue.find(:all,
|
||||
:order => "start_date, effective_date",
|
||||
:include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
|
||||
:conditions => ["(#{@query.statement}) AND (((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
|
||||
)
|
||||
# Versions
|
||||
events += Version.find(:all, :include => :project,
|
||||
:conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
|
||||
|
||||
@gantt.events = events
|
||||
end
|
||||
|
||||
basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
|
||||
format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
|
||||
format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
|
||||
end
|
||||
end
|
||||
|
||||
def calendar
|
||||
if params[:year] and params[:year].to_i > 1900
|
||||
@year = params[:year].to_i
|
||||
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
||||
@month = params[:month].to_i
|
||||
end
|
||||
end
|
||||
@year ||= Date.today.year
|
||||
@month ||= Date.today.month
|
||||
|
||||
@calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
|
||||
retrieve_query
|
||||
if @query.valid?
|
||||
events = []
|
||||
events += Issue.find(:all,
|
||||
:include => [:tracker, :status, :assigned_to, :priority, :project],
|
||||
:conditions => ["(#{@query.statement}) AND ((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
|
||||
)
|
||||
events += Version.find(:all, :include => :project,
|
||||
:conditions => ["(#{@query.project_statement}) AND effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
|
||||
|
||||
@calendar.events = events
|
||||
end
|
||||
|
||||
render :layout => false if request.xhr?
|
||||
|
||||
def destroy_attachment
|
||||
a = @issue.attachments.find(params[:attachment_id])
|
||||
a.destroy
|
||||
journal = @issue.init_journal(User.current)
|
||||
journal.details << JournalDetail.new(:property => 'attachment',
|
||||
:prop_key => a.id,
|
||||
:old_value => a.filename)
|
||||
journal.save
|
||||
redirect_to :action => 'show', :id => @issue
|
||||
end
|
||||
|
||||
def context_menu
|
||||
@@ -390,22 +316,19 @@ class IssuesController < ApplicationController
|
||||
if (@issues.size == 1)
|
||||
@issue = @issues.first
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
@assignables = @issue.assignable_users
|
||||
@assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
|
||||
end
|
||||
projects = @issues.collect(&:project).compact.uniq
|
||||
@project = projects.first if projects.size == 1
|
||||
|
||||
@can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
|
||||
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
|
||||
:update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
|
||||
:update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))),
|
||||
:move => (@project && User.current.allowed_to?(:move_issues, @project)),
|
||||
:copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
|
||||
:delete => (@project && User.current.allowed_to?(:delete_issues, @project))
|
||||
}
|
||||
if @project
|
||||
@assignables = @project.assignable_users
|
||||
@assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
|
||||
end
|
||||
|
||||
|
||||
@priorities = Enumeration.get_values('IPRI').reverse
|
||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||
@back = request.env['HTTP_REFERER']
|
||||
@@ -419,8 +342,8 @@ class IssuesController < ApplicationController
|
||||
end
|
||||
|
||||
def preview
|
||||
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
||||
@attachements = @issue.attachments if @issue
|
||||
issue = @project.issues.find_by_id(params[:id])
|
||||
@attachements = issue.attachments if issue
|
||||
@text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
@@ -455,9 +378,9 @@ private
|
||||
end
|
||||
|
||||
def find_optional_project
|
||||
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
|
||||
allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
|
||||
allowed ? true : deny_access
|
||||
return true unless params[:project_id]
|
||||
@project = Project.find(params[:project_id])
|
||||
authorize
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
@@ -488,7 +411,6 @@ private
|
||||
else
|
||||
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
|
||||
@query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters])
|
||||
@query.project = @project
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class JournalsController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :find_journal
|
||||
|
||||
def edit
|
||||
if request.post?
|
||||
@journal.update_attributes(:notes => params[:notes]) if params[:notes]
|
||||
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
|
||||
call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
|
||||
format.js { render :action => 'update' }
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MailHandlerController < ActionController::Base
|
||||
before_filter :check_credential
|
||||
|
||||
verify :method => :post,
|
||||
:only => :index,
|
||||
:render => { :nothing => true, :status => 405 }
|
||||
|
||||
# Submits an incoming email to MailHandler
|
||||
def index
|
||||
options = params.dup
|
||||
email = options.delete(:email)
|
||||
if MailHandler.receive(email, options)
|
||||
render :nothing => true, :status => :created
|
||||
else
|
||||
render :nothing => true, :status => :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_credential
|
||||
User.current = nil
|
||||
unless Setting.mail_handler_api_enabled? && params[:key] == Setting.mail_handler_api_key
|
||||
render :nothing => true, :status => 403
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MembersController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :find_member, :except => :new
|
||||
before_filter :find_project, :only => :new
|
||||
before_filter :authorize
|
||||
|
||||
@@ -16,21 +16,20 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MessagesController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :boards
|
||||
before_filter :find_board, :only => [:new, :preview]
|
||||
before_filter :find_message, :except => [:new, :preview]
|
||||
before_filter :authorize, :except => [:preview, :edit, :destroy]
|
||||
before_filter :authorize, :except => :preview
|
||||
|
||||
verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
|
||||
verify :xhr => true, :only => :quote
|
||||
|
||||
helper :watchers
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
|
||||
# Show a topic and its replies
|
||||
def show
|
||||
@replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}])
|
||||
@replies = @topic.children
|
||||
@replies.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||
render :action => "show", :layout => false if request.xhr?
|
||||
@@ -46,7 +45,6 @@ class MessagesController < ApplicationController
|
||||
@message.sticky = params[:message]['sticky']
|
||||
end
|
||||
if request.post? && @message.save
|
||||
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
|
||||
attach_files(@message, params[:attachments])
|
||||
redirect_to :action => 'show', :id => @message
|
||||
end
|
||||
@@ -59,7 +57,6 @@ class MessagesController < ApplicationController
|
||||
@reply.board = @board
|
||||
@topic.children << @reply
|
||||
if !@reply.new_record?
|
||||
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
|
||||
attach_files(@reply, params[:attachments])
|
||||
end
|
||||
redirect_to :action => 'show', :id => @topic
|
||||
@@ -67,8 +64,7 @@ class MessagesController < ApplicationController
|
||||
|
||||
# Edit a message
|
||||
def edit
|
||||
render_403 and return false unless @message.editable_by?(User.current)
|
||||
if params[:message]
|
||||
if params[:message] && User.current.allowed_to?(:edit_messages, @project)
|
||||
@message.locked = params[:message]['locked']
|
||||
@message.sticky = params[:message]['sticky']
|
||||
end
|
||||
@@ -81,27 +77,12 @@ class MessagesController < ApplicationController
|
||||
|
||||
# Delete a messages
|
||||
def destroy
|
||||
render_403 and return false unless @message.destroyable_by?(User.current)
|
||||
@message.destroy
|
||||
redirect_to @message.parent.nil? ?
|
||||
{ :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
|
||||
{ :action => 'show', :id => @message.parent }
|
||||
end
|
||||
|
||||
def quote
|
||||
user = @message.author
|
||||
text = @message.content
|
||||
content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
|
||||
content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
|
||||
render(:update) { |page|
|
||||
page.<< "$('message_content').value = \"#{content}\";"
|
||||
page.show 'reply'
|
||||
page << "Form.Element.focus('message_content');"
|
||||
page << "Element.scrollTo('reply');"
|
||||
page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;"
|
||||
}
|
||||
end
|
||||
|
||||
def preview
|
||||
message = @board.messages.find_by_id(params[:id])
|
||||
@attachements = message.attachments if message
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MyController < ApplicationController
|
||||
before_filter :require_login
|
||||
|
||||
helper :issues
|
||||
|
||||
layout 'base'
|
||||
before_filter :require_login
|
||||
|
||||
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
||||
'issuesreportedbyme' => :label_reported_issues,
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class NewsController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :find_news, :except => [:new, :index, :preview]
|
||||
before_filter :find_project, :only => [:new, :preview]
|
||||
before_filter :find_project, :only => :new
|
||||
before_filter :authorize, :except => [:index, :preview]
|
||||
before_filter :find_optional_project, :only => :index
|
||||
accept_key_auth :index
|
||||
@@ -65,7 +66,6 @@ class NewsController < ApplicationController
|
||||
flash[:notice] = l(:label_comment_added)
|
||||
redirect_to :action => 'show', :id => @news
|
||||
else
|
||||
show
|
||||
render :action => 'show'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class ProjectsController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :overview
|
||||
menu_item :activity, :only => :activity
|
||||
menu_item :roadmap, :only => :roadmap
|
||||
@@ -27,12 +28,14 @@ class ProjectsController < ApplicationController
|
||||
before_filter :find_optional_project, :only => :activity
|
||||
before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
|
||||
before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
|
||||
accept_key_auth :activity
|
||||
accept_key_auth :activity, :calendar
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
helper :ifpdf
|
||||
include IfpdfHelper
|
||||
helper :issues
|
||||
helper IssuesHelper
|
||||
helper :queries
|
||||
@@ -41,54 +44,50 @@ class ProjectsController < ApplicationController
|
||||
include RepositoriesHelper
|
||||
include ProjectsHelper
|
||||
|
||||
# Lists visible projects
|
||||
def index
|
||||
list
|
||||
render :action => 'list' unless request.xhr?
|
||||
end
|
||||
|
||||
# Lists visible projects
|
||||
def list
|
||||
projects = Project.find :all,
|
||||
:conditions => Project.visible_by(User.current),
|
||||
:include => :parent
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@project_tree = projects.group_by {|p| p.parent || p}
|
||||
@project_tree.keys.each {|p| @project_tree[p] -= [p]}
|
||||
}
|
||||
format.atom {
|
||||
render_feed(projects.sort_by(&:created_on).reverse.slice(0, Setting.feeds_limit.to_i),
|
||||
:title => "#{Setting.app_title}: #{l(:label_project_latest)}")
|
||||
}
|
||||
end
|
||||
@project_tree = projects.group_by {|p| p.parent || p}
|
||||
@project_tree.each_key {|p| @project_tree[p] -= [p]}
|
||||
end
|
||||
|
||||
# Add a new project
|
||||
def add
|
||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||
@custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||
@trackers = Tracker.all
|
||||
@root_projects = Project.find(:all,
|
||||
:conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
|
||||
:order => 'name')
|
||||
@project = Project.new(params[:project])
|
||||
@project.enabled_module_names = Redmine::AccessControl.available_project_modules
|
||||
if request.get?
|
||||
@project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
|
||||
@custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
|
||||
@project.trackers = Tracker.all
|
||||
@project.is_public = Setting.default_projects_public?
|
||||
@project.enabled_module_names = Redmine::AccessControl.available_project_modules
|
||||
else
|
||||
@project.enabled_module_names = params[:enabled_modules]
|
||||
@project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
|
||||
@custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
||||
@project.custom_values = @custom_values
|
||||
if @project.save
|
||||
@project.enabled_module_names = params[:enabled_modules]
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :controller => 'admin', :action => 'projects'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Show @project
|
||||
def show
|
||||
if params[:jump]
|
||||
# try to redirect to the requested menu item
|
||||
redirect_to_project_menu_item(@project, params[:jump]) && return
|
||||
end
|
||||
|
||||
@custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
|
||||
@members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
|
||||
@subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
|
||||
@subprojects = @project.active_children
|
||||
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
||||
@trackers = @project.rolled_up_trackers
|
||||
|
||||
@@ -113,10 +112,11 @@ class ProjectsController < ApplicationController
|
||||
@root_projects = Project.find(:all,
|
||||
:conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
|
||||
:order => 'name')
|
||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||
@custom_fields = IssueCustomField.find(:all)
|
||||
@issue_category ||= IssueCategory.new
|
||||
@member ||= @project.members.new
|
||||
@trackers = Tracker.all
|
||||
@custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
||||
@repository ||= @project.repository
|
||||
@wiki ||= @project.wiki
|
||||
end
|
||||
@@ -124,6 +124,10 @@ class ProjectsController < ApplicationController
|
||||
# Edit @project
|
||||
def edit
|
||||
if request.post?
|
||||
if params[:custom_fields]
|
||||
@custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
|
||||
@project.custom_values = @custom_values
|
||||
end
|
||||
@project.attributes = params[:project]
|
||||
if @project.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
@@ -191,27 +195,16 @@ class ProjectsController < ApplicationController
|
||||
|
||||
def add_file
|
||||
if request.post?
|
||||
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
||||
attachments = attach_files(container, params[:attachments])
|
||||
if !attachments.empty? && Setting.notified_events.include?('file_added')
|
||||
Mailer.deliver_attachments_added(attachments)
|
||||
end
|
||||
@version = @project.versions.find_by_id(params[:version_id])
|
||||
attachments = attach_files(@version, params[:attachments])
|
||||
Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
|
||||
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
||||
return
|
||||
end
|
||||
@versions = @project.versions.sort
|
||||
end
|
||||
|
||||
def list_files
|
||||
sort_init 'filename', 'asc'
|
||||
sort_update 'filename' => "#{Attachment.table_name}.filename",
|
||||
'created_on' => "#{Attachment.table_name}.created_on",
|
||||
'size' => "#{Attachment.table_name}.filesize",
|
||||
'downloads' => "#{Attachment.table_name}.downloads"
|
||||
|
||||
@containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
|
||||
@containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
|
||||
render :layout => !request.xhr?
|
||||
@versions = @project.versions.sort.reverse
|
||||
end
|
||||
|
||||
# Show changelog for @project
|
||||
@@ -232,40 +225,179 @@ class ProjectsController < ApplicationController
|
||||
@days = Setting.activity_days_default.to_i
|
||||
|
||||
if params[:from]
|
||||
begin; @date_to = params[:from].to_date + 1; rescue; end
|
||||
begin; @date_to = params[:from].to_date; rescue; end
|
||||
end
|
||||
|
||||
@date_to ||= Date.today + 1
|
||||
@date_from = @date_to - @days
|
||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
|
||||
|
||||
@activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
|
||||
:with_subprojects => @with_subprojects,
|
||||
:author => @author)
|
||||
@activity.scope_select {|t| !params["show_#{t}"].nil?}
|
||||
@activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
|
||||
|
||||
events = @activity.events(@date_from, @date_to)
|
||||
@event_types = %w(issues news files documents changesets wiki_pages messages)
|
||||
if @project
|
||||
@event_types.delete('wiki_pages') unless @project.wiki
|
||||
@event_types.delete('changesets') unless @project.repository
|
||||
@event_types.delete('messages') unless @project.boards.any?
|
||||
# only show what the user is allowed to view
|
||||
@event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
|
||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||
end
|
||||
@scope = @event_types.select {|t| params["show_#{t}"]}
|
||||
# default events if none is specified in parameters
|
||||
@scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@events_by_day = events.group_by(&:event_date)
|
||||
render :layout => false if request.xhr?
|
||||
}
|
||||
format.atom {
|
||||
title = l(:label_activity)
|
||||
if @author
|
||||
title = @author.name
|
||||
elsif @activity.scope.size == 1
|
||||
title = l("label_#{@activity.scope.first.singularize}_plural")
|
||||
end
|
||||
render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
|
||||
}
|
||||
@events = []
|
||||
|
||||
if @scope.include?('issues')
|
||||
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
|
||||
cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
|
||||
|
||||
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
|
||||
cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
if @scope.include?('news')
|
||||
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects))
|
||||
cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
|
||||
end
|
||||
|
||||
if @scope.include?('files')
|
||||
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects))
|
||||
cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events += Attachment.find(:all, :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",
|
||||
:conditions => cond.conditions)
|
||||
end
|
||||
|
||||
if @scope.include?('documents')
|
||||
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
|
||||
cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events += Document.find(:all, :include => :project, :conditions => cond.conditions)
|
||||
|
||||
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
|
||||
cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
|
||||
:joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
|
||||
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
|
||||
:conditions => cond.conditions)
|
||||
end
|
||||
|
||||
if @scope.include?('wiki_pages')
|
||||
select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
|
||||
"#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
|
||||
"#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
|
||||
"#{WikiContent.versioned_table_name}.id"
|
||||
joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
|
||||
"LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
|
||||
"LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"
|
||||
|
||||
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects))
|
||||
cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
|
||||
end
|
||||
|
||||
if @scope.include?('changesets')
|
||||
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects))
|
||||
cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
|
||||
end
|
||||
|
||||
if @scope.include?('messages')
|
||||
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects))
|
||||
cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions)
|
||||
end
|
||||
|
||||
@events_by_day = @events.group_by(&:event_date)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :layout => false if request.xhr? }
|
||||
format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") }
|
||||
end
|
||||
end
|
||||
|
||||
def calendar
|
||||
@trackers = @project.rolled_up_trackers
|
||||
retrieve_selected_tracker_ids(@trackers)
|
||||
|
||||
if params[:year] and params[:year].to_i > 1900
|
||||
@year = params[:year].to_i
|
||||
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
||||
@month = params[:month].to_i
|
||||
end
|
||||
end
|
||||
@year ||= Date.today.year
|
||||
@month ||= Date.today.month
|
||||
@calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
|
||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||
events = []
|
||||
@project.issues_with_subprojects(@with_subprojects) do
|
||||
events += Issue.find(:all,
|
||||
:include => [:tracker, :status, :assigned_to, :priority, :project],
|
||||
:conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
|
||||
) unless @selected_tracker_ids.empty?
|
||||
end
|
||||
events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
|
||||
@calendar.events = events
|
||||
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def gantt
|
||||
@trackers = @project.rolled_up_trackers
|
||||
retrieve_selected_tracker_ids(@trackers)
|
||||
|
||||
if params[:year] and params[:year].to_i >0
|
||||
@year_from = params[:year].to_i
|
||||
if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
|
||||
@month_from = params[:month].to_i
|
||||
else
|
||||
@month_from = 1
|
||||
end
|
||||
else
|
||||
@month_from ||= Date.today.month
|
||||
@year_from ||= Date.today.year
|
||||
end
|
||||
|
||||
zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
|
||||
@zoom = (zoom > 0 && zoom < 5) ? zoom : 2
|
||||
months = (params[:months] || User.current.pref[:gantt_months]).to_i
|
||||
@months = (months > 0 && months < 25) ? months : 6
|
||||
|
||||
# Save gantt paramters as user preference (zoom and months count)
|
||||
if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
|
||||
User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
|
||||
User.current.preference.save
|
||||
end
|
||||
|
||||
@date_from = Date.civil(@year_from, @month_from, 1)
|
||||
@date_to = (@date_from >> @months) - 1
|
||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||
|
||||
@events = []
|
||||
@project.issues_with_subprojects(@with_subprojects) do
|
||||
@events += Issue.find(:all,
|
||||
:order => "start_date, due_date",
|
||||
:include => [:tracker, :status, :assigned_to, :priority, :project],
|
||||
:conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
|
||||
) unless @selected_tracker_ids.empty?
|
||||
end
|
||||
@events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
|
||||
@events.sort! {|x,y| x.start_date <=> y.start_date }
|
||||
|
||||
if params[:format]=='pdf'
|
||||
@options_for_rfpdf ||= {}
|
||||
@options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
|
||||
render :template => "projects/gantt.rfpdf", :layout => false
|
||||
elsif params[:format]=='png' && respond_to?('gantt_image')
|
||||
image = gantt_image(@events, @date_from, @months, @zoom)
|
||||
image.format = 'PNG'
|
||||
send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
|
||||
else
|
||||
render :template => "projects/gantt.rhtml"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class QueriesController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :issues
|
||||
before_filter :find_query, :except => :new
|
||||
before_filter :find_optional_project, :only => :new
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class ReportsController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :issues
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
|
||||
@@ -19,46 +19,30 @@ require 'SVG/Graph/Bar'
|
||||
require 'SVG/Graph/BarHorizontal'
|
||||
require 'digest/sha1'
|
||||
|
||||
class ChangesetNotFound < Exception; end
|
||||
class InvalidRevisionParam < Exception; end
|
||||
class ChangesetNotFound < Exception
|
||||
end
|
||||
|
||||
class RepositoriesController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :repository
|
||||
before_filter :find_repository, :except => :edit
|
||||
before_filter :find_project, :only => :edit
|
||||
before_filter :authorize
|
||||
accept_key_auth :revisions
|
||||
|
||||
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
|
||||
|
||||
def edit
|
||||
@repository = @project.repository
|
||||
if !@repository
|
||||
@repository = Repository.factory(params[:repository_scm])
|
||||
@repository.project = @project if @repository
|
||||
@repository.project = @project
|
||||
end
|
||||
if request.post? && @repository
|
||||
if request.post?
|
||||
@repository.attributes = params[:repository]
|
||||
@repository.save
|
||||
end
|
||||
render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'}
|
||||
end
|
||||
|
||||
def committers
|
||||
@committers = @repository.committers
|
||||
@users = @project.users
|
||||
additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
|
||||
@users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
|
||||
@users.compact!
|
||||
@users.sort!
|
||||
if request.post? && params[:committers].is_a?(Hash)
|
||||
# Build a hash with repository usernames as keys and corresponding user ids as values
|
||||
@repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'committers', :id => @project
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@repository.destroy
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
|
||||
@@ -67,11 +51,13 @@ class RepositoriesController < ApplicationController
|
||||
def show
|
||||
# check if new revisions have been committed in the repository
|
||||
@repository.fetch_changesets if Setting.autofetch_changesets?
|
||||
# root entries
|
||||
@entries = @repository.entries('', @rev)
|
||||
# get entries for the browse frame
|
||||
@entries = @repository.entries('')
|
||||
# latest changesets
|
||||
@changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC")
|
||||
show_error_not_found unless @entries || @changesets.any?
|
||||
rescue Redmine::Scm::Adapters::CommandFailed => e
|
||||
show_error_command_failed(e.message)
|
||||
end
|
||||
|
||||
def browse
|
||||
@@ -79,17 +65,18 @@ class RepositoriesController < ApplicationController
|
||||
if request.xhr?
|
||||
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
||||
else
|
||||
show_error_not_found and return unless @entries
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
render :action => 'browse'
|
||||
show_error_not_found unless @entries
|
||||
end
|
||||
rescue Redmine::Scm::Adapters::CommandFailed => e
|
||||
show_error_command_failed(e.message)
|
||||
end
|
||||
|
||||
def changes
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
@entry = @repository.scm.entry(@path, @rev)
|
||||
show_error_not_found and return unless @entry
|
||||
@changesets = @repository.changesets_for_path(@path)
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
rescue Redmine::Scm::Adapters::CommandFailed => e
|
||||
show_error_command_failed(e.message)
|
||||
end
|
||||
|
||||
def revisions
|
||||
@@ -99,8 +86,7 @@ class RepositoriesController < ApplicationController
|
||||
params['page']
|
||||
@changesets = @repository.changesets.find(:all,
|
||||
:limit => @changeset_pages.items_per_page,
|
||||
:offset => @changeset_pages.current.offset,
|
||||
:include => :user)
|
||||
:offset => @changeset_pages.current.offset)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :layout => false if request.xhr? }
|
||||
@@ -109,13 +95,7 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def entry
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
show_error_not_found and return unless @entry
|
||||
|
||||
# If the entry is a dir, show the browser
|
||||
browse and return if @entry.is_dir?
|
||||
|
||||
@content = @repository.cat(@path, @rev)
|
||||
@content = @repository.scm.cat(@path, @rev)
|
||||
show_error_not_found and return unless @content
|
||||
if 'raw' == params[:format] || @content.is_binary_data?
|
||||
# Force the download if it's a binary file
|
||||
@@ -123,20 +103,26 @@ class RepositoriesController < ApplicationController
|
||||
else
|
||||
# Prevent empty lines when displaying a file with Windows style eol
|
||||
@content.gsub!("\r\n", "\n")
|
||||
end
|
||||
end
|
||||
rescue Redmine::Scm::Adapters::CommandFailed => e
|
||||
show_error_command_failed(e.message)
|
||||
end
|
||||
|
||||
def annotate
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
show_error_not_found and return unless @entry
|
||||
|
||||
@annotate = @repository.scm.annotate(@path, @rev)
|
||||
render_error l(:error_scm_annotate) and return if @annotate.nil? || @annotate.empty?
|
||||
rescue Redmine::Scm::Adapters::CommandFailed => e
|
||||
show_error_command_failed(e.message)
|
||||
end
|
||||
|
||||
def revision
|
||||
@changeset = @repository.changesets.find_by_revision(@rev)
|
||||
raise ChangesetNotFound unless @changeset
|
||||
@changes_count = @changeset.changes.size
|
||||
@changes_pages = Paginator.new self, @changes_count, 150, params['page']
|
||||
@changes = @changeset.changes.find(:all,
|
||||
:limit => @changes_pages.items_per_page,
|
||||
:offset => @changes_pages.current.offset)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
@@ -144,33 +130,28 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
rescue ChangesetNotFound
|
||||
show_error_not_found
|
||||
rescue Redmine::Scm::Adapters::CommandFailed => e
|
||||
show_error_command_failed(e.message)
|
||||
end
|
||||
|
||||
def diff
|
||||
if params[:format] == 'diff'
|
||||
@diff = @repository.diff(@path, @rev, @rev_to)
|
||||
show_error_not_found and return unless @diff
|
||||
filename = "changeset_r#{@rev}"
|
||||
filename << "_r#{@rev_to}" if @rev_to
|
||||
send_data @diff.join, :filename => "#{filename}.diff",
|
||||
:type => 'text/x-patch',
|
||||
:disposition => 'attachment'
|
||||
else
|
||||
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
|
||||
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
|
||||
|
||||
# Save diff type as user preference
|
||||
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
|
||||
User.current.pref[:diff_type] = @diff_type
|
||||
User.current.preference.save
|
||||
end
|
||||
|
||||
@cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
|
||||
unless read_fragment(@cache_key)
|
||||
@diff = @repository.diff(@path, @rev, @rev_to)
|
||||
show_error_not_found unless @diff
|
||||
end
|
||||
@rev_to = params[:rev_to]
|
||||
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
|
||||
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
|
||||
|
||||
# Save diff type as user preference
|
||||
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
|
||||
User.current.pref[:diff_type] = @diff_type
|
||||
User.current.preference.save
|
||||
end
|
||||
|
||||
@cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
|
||||
unless read_fragment(@cache_key)
|
||||
@diff = @repository.diff(@path, @rev, @rev_to, @diff_type)
|
||||
show_error_not_found unless @diff
|
||||
end
|
||||
rescue Redmine::Scm::Adapters::CommandFailed => e
|
||||
show_error_command_failed(e.message)
|
||||
end
|
||||
|
||||
def stats
|
||||
@@ -199,8 +180,6 @@ private
|
||||
render_404
|
||||
end
|
||||
|
||||
REV_PARAM_RE = %r{^[a-f0-9]*$}
|
||||
|
||||
def find_repository
|
||||
@project = Project.find(params[:id])
|
||||
@repository = @project.repository
|
||||
@@ -208,21 +187,16 @@ private
|
||||
@path = params[:path].join('/') unless params[:path].nil?
|
||||
@path ||= ''
|
||||
@rev = params[:rev]
|
||||
@rev_to = params[:rev_to]
|
||||
raise InvalidRevisionParam unless @rev.to_s.match(REV_PARAM_RE) && @rev.to_s.match(REV_PARAM_RE)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
rescue InvalidRevisionParam
|
||||
show_error_not_found
|
||||
end
|
||||
|
||||
def show_error_not_found
|
||||
render_error l(:error_scm_not_found)
|
||||
end
|
||||
|
||||
# Handler for Redmine::Scm::Adapters::CommandFailed exception
|
||||
def show_error_command_failed(exception)
|
||||
render_error l(:error_scm_command_failed, exception.message)
|
||||
def show_error_command_failed(msg)
|
||||
render_error l(:error_scm_command_failed, msg)
|
||||
end
|
||||
|
||||
def graph_commits_per_month(repository)
|
||||
@@ -243,7 +217,7 @@ private
|
||||
|
||||
graph = SVG::Graph::Bar.new(
|
||||
:height => 300,
|
||||
:width => 800,
|
||||
:width => 500,
|
||||
:fields => fields.reverse,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
@@ -281,12 +255,9 @@ private
|
||||
commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
|
||||
changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
|
||||
|
||||
# Remove email adress in usernames
|
||||
fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
|
||||
|
||||
graph = SVG::Graph::BarHorizontal.new(
|
||||
:height => 400,
|
||||
:width => 800,
|
||||
:height => 300,
|
||||
:width => 500,
|
||||
:fields => fields,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class RolesController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_admin
|
||||
|
||||
verify :method => :post, :only => [ :destroy, :move ],
|
||||
@@ -79,6 +80,27 @@ class RolesController < ApplicationController
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def workflow
|
||||
@role = Role.find_by_id(params[:role_id])
|
||||
@tracker = Tracker.find_by_id(params[:tracker_id])
|
||||
|
||||
if request.post?
|
||||
Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
|
||||
(params[:issue_status] || []).each { |old, news|
|
||||
news.each { |new|
|
||||
@role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
|
||||
}
|
||||
}
|
||||
if @role.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker
|
||||
end
|
||||
end
|
||||
@roles = Role.find(:all, :order => 'builtin, position')
|
||||
@trackers = Tracker.find(:all, :order => 'position')
|
||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||
end
|
||||
|
||||
def report
|
||||
@roles = Role.find(:all, :order => 'builtin, position')
|
||||
@permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class SearchController < ApplicationController
|
||||
layout 'base'
|
||||
|
||||
before_filter :find_optional_project
|
||||
|
||||
helper :messages
|
||||
@@ -27,18 +29,6 @@ class SearchController < ApplicationController
|
||||
@all_words = params[:all_words] || (params[:submit] ? false : true)
|
||||
@titles_only = !params[:titles_only].nil?
|
||||
|
||||
projects_to_search =
|
||||
case params[:scope]
|
||||
when 'all'
|
||||
nil
|
||||
when 'my_projects'
|
||||
User.current.memberships.collect(&:project)
|
||||
when 'subprojects'
|
||||
@project ? ([ @project ] + @project.active_children) : nil
|
||||
else
|
||||
@project
|
||||
end
|
||||
|
||||
offset = nil
|
||||
begin; offset = params[:offset].to_time if params[:offset]; rescue; end
|
||||
|
||||
@@ -48,16 +38,16 @@ class SearchController < ApplicationController
|
||||
return
|
||||
end
|
||||
|
||||
@object_types = %w(issues news documents changesets wiki_pages messages projects)
|
||||
if projects_to_search.is_a? Project
|
||||
# don't search projects
|
||||
@object_types.delete('projects')
|
||||
if @project
|
||||
# only show what the user is allowed to view
|
||||
@object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, projects_to_search)}
|
||||
end
|
||||
@object_types = %w(issues news documents changesets wiki_pages messages)
|
||||
@object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
|
||||
|
||||
@scope = @object_types.select {|t| params[t]}
|
||||
@scope = @object_types if @scope.empty?
|
||||
@scope = @object_types.select {|t| params[t]}
|
||||
@scope = @object_types if @scope.empty?
|
||||
else
|
||||
@object_types = @scope = %w(projects)
|
||||
end
|
||||
|
||||
# extract tokens from the question
|
||||
# eg. hello "bye bye" => ["hello", "bye bye"]
|
||||
@@ -70,34 +60,39 @@ class SearchController < ApplicationController
|
||||
@tokens.slice! 5..-1 if @tokens.size > 5
|
||||
# strings used in sql like statement
|
||||
like_tokens = @tokens.collect {|w| "%#{w.downcase}%"}
|
||||
|
||||
@results = []
|
||||
@results_by_type = Hash.new {|h,k| h[k] = 0}
|
||||
|
||||
limit = 10
|
||||
@scope.each do |s|
|
||||
r, c = s.singularize.camelcase.constantize.search(like_tokens, projects_to_search,
|
||||
:all_words => @all_words,
|
||||
:titles_only => @titles_only,
|
||||
:limit => (limit+1),
|
||||
:offset => offset,
|
||||
:before => params[:previous].nil?)
|
||||
@results += r
|
||||
@results_by_type[s] += c
|
||||
end
|
||||
@results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime}
|
||||
if params[:previous].nil?
|
||||
@pagination_previous_date = @results[0].event_datetime if offset && @results[0]
|
||||
if @results.size > limit
|
||||
@pagination_next_date = @results[limit-1].event_datetime
|
||||
@results = @results[0, limit]
|
||||
if @project
|
||||
@scope.each do |s|
|
||||
@results += s.singularize.camelcase.constantize.search(like_tokens, @project,
|
||||
:all_words => @all_words,
|
||||
:titles_only => @titles_only,
|
||||
:limit => (limit+1),
|
||||
:offset => offset,
|
||||
:before => params[:previous].nil?)
|
||||
end
|
||||
@results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime}
|
||||
if params[:previous].nil?
|
||||
@pagination_previous_date = @results[0].event_datetime if offset && @results[0]
|
||||
if @results.size > limit
|
||||
@pagination_next_date = @results[limit-1].event_datetime
|
||||
@results = @results[0, limit]
|
||||
end
|
||||
else
|
||||
@pagination_next_date = @results[-1].event_datetime if offset && @results[-1]
|
||||
if @results.size > limit
|
||||
@pagination_previous_date = @results[-(limit)].event_datetime
|
||||
@results = @results[-(limit), limit]
|
||||
end
|
||||
end
|
||||
else
|
||||
@pagination_next_date = @results[-1].event_datetime if offset && @results[-1]
|
||||
if @results.size > limit
|
||||
@pagination_previous_date = @results[-(limit)].event_datetime
|
||||
@results = @results[-(limit), limit]
|
||||
end
|
||||
operator = @all_words ? ' AND ' : ' OR '
|
||||
@results += Project.find(:all,
|
||||
:limit => limit,
|
||||
:conditions => [ (["(#{Project.visible_by(User.current)}) AND (LOWER(name) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort]
|
||||
) if @scope.include? 'projects'
|
||||
# if only one project is found, user is redirected to its overview
|
||||
redirect_to :controller => 'projects', :action => 'show', :id => @results.first and return if @results.size == 1
|
||||
end
|
||||
else
|
||||
@question = ""
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class SettingsController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_admin
|
||||
|
||||
|
||||
def index
|
||||
edit
|
||||
render :action => 'edit'
|
||||
@@ -38,22 +39,17 @@ class SettingsController < ApplicationController
|
||||
end
|
||||
@options = {}
|
||||
@options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
|
||||
@deliveries = ActionMailer::Base.perform_deliveries
|
||||
|
||||
@guessed_host_and_path = request.host_with_port.dup
|
||||
@guessed_host_and_path << ('/'+ request.relative_url_root.gsub(%r{^\/}, '')) unless request.relative_url_root.blank?
|
||||
end
|
||||
|
||||
|
||||
def plugin
|
||||
@plugin = Redmine::Plugin.find(params[:id])
|
||||
plugin_id = params[:id].to_sym
|
||||
@plugin = Redmine::Plugin.registered_plugins[plugin_id]
|
||||
if request.post?
|
||||
Setting["plugin_#{@plugin.id}"] = params[:settings]
|
||||
Setting["plugin_#{plugin_id}"] = params[:settings]
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'plugin', :id => @plugin.id
|
||||
redirect_to :action => 'plugin', :id => params[:id]
|
||||
end
|
||||
@partial = @plugin.settings[:partial]
|
||||
@settings = Setting["plugin_#{@plugin.id}"]
|
||||
rescue Redmine::PluginNotFound
|
||||
render_404
|
||||
@partial = "../../vendor/plugins/#{plugin_id}/app/views/" + @plugin.settings[:partial]
|
||||
@settings = Setting["plugin_#{plugin_id}"]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,17 +23,18 @@ class SysController < ActionController::Base
|
||||
before_invocation :check_enabled
|
||||
|
||||
# Returns the projects list, with their repositories
|
||||
def projects_with_repository_enabled
|
||||
Project.has_module(:repository).find(:all, :include => :repository, :order => 'identifier')
|
||||
def projects
|
||||
Project.find(:all, :include => :repository)
|
||||
end
|
||||
|
||||
# Registers a repository for the given project identifier
|
||||
def repository_created(identifier, vendor, url)
|
||||
# (Subversion specific)
|
||||
def repository_created(identifier, url)
|
||||
project = Project.find_by_identifier(identifier)
|
||||
# Do not create the repository if the project has already one
|
||||
return 0 unless project && project.repository.nil?
|
||||
logger.debug "Repository for #{project.name} was created"
|
||||
repository = Repository.factory(vendor, :project => project, :url => url)
|
||||
repository = Repository.factory('Subversion', :project => project, :url => url)
|
||||
repository.save
|
||||
repository.id || 0
|
||||
end
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class TimelogController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :issues
|
||||
before_filter :find_project, :authorize, :only => [:edit, :destroy]
|
||||
before_filter :find_optional_project, :only => [:report, :details]
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
|
||||
|
||||
@@ -26,8 +26,6 @@ class TimelogController < ApplicationController
|
||||
include SortHelper
|
||||
helper :issues
|
||||
include TimelogHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
def report
|
||||
@available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
|
||||
@@ -47,49 +45,37 @@ class TimelogController < ApplicationController
|
||||
:label => :label_tracker},
|
||||
'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
|
||||
:klass => Enumeration,
|
||||
:label => :label_activity},
|
||||
'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
|
||||
:klass => Issue,
|
||||
:label => :label_issue}
|
||||
:label => :label_activity}
|
||||
}
|
||||
|
||||
# Add list and boolean custom fields as available criterias
|
||||
custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields)
|
||||
custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
|
||||
@available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = #{Issue.table_name}.id)",
|
||||
:format => cf.field_format,
|
||||
:label => cf.name}
|
||||
end if @project
|
||||
|
||||
# Add list and boolean time entry custom fields
|
||||
TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
|
||||
@available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id)",
|
||||
:format => cf.field_format,
|
||||
:label => cf.name}
|
||||
end
|
||||
|
||||
@criterias = params[:criterias] || []
|
||||
@criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
|
||||
@criterias.uniq!
|
||||
@criterias = @criterias[0,3]
|
||||
|
||||
@columns = (params[:columns] && %w(year month week day).include?(params[:columns])) ? params[:columns] : 'month'
|
||||
@columns = (params[:period] && %w(year month week).include?(params[:period])) ? params[:period] : 'month'
|
||||
|
||||
retrieve_date_range
|
||||
if params[:date_from]
|
||||
begin; @date_from = params[:date_from].to_date; rescue; end
|
||||
end
|
||||
if params[:date_to]
|
||||
begin; @date_to = params[:date_to].to_date; rescue; end
|
||||
end
|
||||
@date_from ||= Date.civil(Date.today.year, 1, 1)
|
||||
@date_to ||= (Date.civil(Date.today.year, Date.today.month, 1) >> 1) - 1
|
||||
|
||||
unless @criterias.empty?
|
||||
sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
|
||||
sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
|
||||
|
||||
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
|
||||
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, SUM(hours) AS hours"
|
||||
sql << " FROM #{TimeEntry.table_name}"
|
||||
sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
|
||||
sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
|
||||
sql << " WHERE"
|
||||
sql << " (%s) AND" % @project.project_condition(Setting.display_subprojects_issues?) if @project
|
||||
sql << " (%s) AND" % Project.allowed_to_condition(User.current, :view_time_entries)
|
||||
sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from), ActiveRecord::Base.connection.quoted_date(@to)]
|
||||
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
|
||||
sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?)
|
||||
sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries)
|
||||
sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@date_from.to_time), ActiveRecord::Base.connection.quoted_date(@date_to.to_time)]
|
||||
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek"
|
||||
|
||||
@hours = ActiveRecord::Base.connection.select_all(sql)
|
||||
|
||||
@@ -101,152 +87,36 @@ class TimelogController < ApplicationController
|
||||
row['month'] = "#{row['tyear']}-#{row['tmonth']}"
|
||||
when 'week'
|
||||
row['week'] = "#{row['tyear']}-#{row['tweek']}"
|
||||
when 'day'
|
||||
row['day'] = "#{row['spent_on']}"
|
||||
end
|
||||
end
|
||||
|
||||
@total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
|
||||
|
||||
@periods = []
|
||||
# Date#at_beginning_of_ not supported in Rails 1.2.x
|
||||
date_from = @from.to_time
|
||||
# 100 columns max
|
||||
while date_from <= @to.to_time && @periods.length < 100
|
||||
case @columns
|
||||
when 'year'
|
||||
@periods << "#{date_from.year}"
|
||||
date_from = (date_from + 1.year).at_beginning_of_year
|
||||
when 'month'
|
||||
@periods << "#{date_from.year}-#{date_from.month}"
|
||||
date_from = (date_from + 1.month).at_beginning_of_month
|
||||
when 'week'
|
||||
@periods << "#{date_from.year}-#{date_from.to_date.cweek}"
|
||||
date_from = (date_from + 7.day).at_beginning_of_week
|
||||
when 'day'
|
||||
@periods << "#{date_from.to_date}"
|
||||
date_from = date_from + 1.day
|
||||
end
|
||||
end
|
||||
|
||||
@periods = []
|
||||
date_from = @date_from
|
||||
# 100 columns max
|
||||
while date_from < @date_to && @periods.length < 100
|
||||
case @columns
|
||||
when 'year'
|
||||
@periods << "#{date_from.year}"
|
||||
date_from = date_from >> 12
|
||||
when 'month'
|
||||
@periods << "#{date_from.year}-#{date_from.month}"
|
||||
date_from = date_from >> 1
|
||||
when 'week'
|
||||
@periods << "#{date_from.year}-#{date_from.cweek}"
|
||||
date_from = date_from + 7
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :layout => !request.xhr? }
|
||||
format.csv { send_data(report_to_csv(@criterias, @periods, @hours).read, :type => 'text/csv; header=present', :filename => 'timelog.csv') }
|
||||
end
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def details
|
||||
sort_init 'spent_on', 'desc'
|
||||
sort_update 'spent_on' => 'spent_on',
|
||||
'user' => 'user_id',
|
||||
'activity' => 'activity_id',
|
||||
'project' => "#{Project.table_name}.name",
|
||||
'issue' => 'issue_id',
|
||||
'hours' => 'hours'
|
||||
|
||||
cond = ARCondition.new
|
||||
if @project.nil?
|
||||
cond << Project.allowed_to_condition(User.current, :view_time_entries)
|
||||
elsif @issue.nil?
|
||||
cond << @project.project_condition(Setting.display_subprojects_issues?)
|
||||
else
|
||||
cond << ["#{TimeEntry.table_name}.issue_id = ?", @issue.id]
|
||||
end
|
||||
|
||||
retrieve_date_range
|
||||
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
||||
sort_update
|
||||
|
||||
TimeEntry.visible_by(User.current) do
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# Paginate results
|
||||
@entry_count = TimeEntry.count(:include => :project, :conditions => cond.conditions)
|
||||
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
|
||||
@entries = TimeEntry.find(:all,
|
||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||
:conditions => cond.conditions,
|
||||
:order => sort_clause,
|
||||
:limit => @entry_pages.items_per_page,
|
||||
:offset => @entry_pages.current.offset)
|
||||
@total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
|
||||
|
||||
render :layout => !request.xhr?
|
||||
}
|
||||
format.atom {
|
||||
entries = TimeEntry.find(:all,
|
||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||
:conditions => cond.conditions,
|
||||
:order => "#{TimeEntry.table_name}.created_on DESC",
|
||||
:limit => Setting.feeds_limit.to_i)
|
||||
render_feed(entries, :title => l(:label_spent_time))
|
||||
}
|
||||
format.csv {
|
||||
# Export all entries
|
||||
@entries = TimeEntry.find(:all,
|
||||
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
||||
:conditions => cond.conditions,
|
||||
:order => sort_clause)
|
||||
send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
render_403 and return if @time_entry && !@time_entry.editable_by?(User.current)
|
||||
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
|
||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
||||
|
||||
if request.post? and @time_entry.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_back_or_default :action => 'details', :project_id => @time_entry.project
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
render_404 and return unless @time_entry
|
||||
render_403 and return unless @time_entry.editable_by?(User.current)
|
||||
@time_entry.destroy
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
redirect_to :back
|
||||
rescue ::ActionController::RedirectBackError
|
||||
redirect_to :action => 'details', :project_id => @time_entry.project
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
if params[:id]
|
||||
@time_entry = TimeEntry.find(params[:id])
|
||||
@project = @time_entry.project
|
||||
elsif params[:issue_id]
|
||||
@issue = Issue.find(params[:issue_id])
|
||||
@project = @issue.project
|
||||
elsif params[:project_id]
|
||||
@project = Project.find(params[:project_id])
|
||||
else
|
||||
render_404
|
||||
return false
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_optional_project
|
||||
if !params[:issue_id].blank?
|
||||
@issue = Issue.find(params[:issue_id])
|
||||
@project = @issue.project
|
||||
elsif !params[:project_id].blank?
|
||||
@project = Project.find(params[:project_id])
|
||||
end
|
||||
deny_access unless User.current.allowed_to?(:view_time_entries, @project, :global => true)
|
||||
end
|
||||
|
||||
# Retrieves the date range based on predefined ranges or specific from/to param dates
|
||||
def retrieve_date_range
|
||||
@free_period = false
|
||||
@from, @to = nil, nil
|
||||
|
||||
@@ -287,7 +157,85 @@ private
|
||||
end
|
||||
|
||||
@from, @to = @to, @from if @from && @to && @from > @to
|
||||
@from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) - 1
|
||||
@to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today)
|
||||
|
||||
cond = ARCondition.new
|
||||
cond << (@issue.nil? ? @project.project_condition(Setting.display_subprojects_issues?) :
|
||||
["#{TimeEntry.table_name}.issue_id = ?", @issue.id])
|
||||
|
||||
if @from
|
||||
if @to
|
||||
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
||||
else
|
||||
cond << ['spent_on >= ?', @from]
|
||||
end
|
||||
elsif @to
|
||||
cond << ['spent_on <= ?', @to]
|
||||
end
|
||||
|
||||
TimeEntry.visible_by(User.current) do
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# Paginate results
|
||||
@entry_count = TimeEntry.count(:include => :project, :conditions => cond.conditions)
|
||||
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
|
||||
@entries = TimeEntry.find(:all,
|
||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||
:conditions => cond.conditions,
|
||||
:order => sort_clause,
|
||||
:limit => @entry_pages.items_per_page,
|
||||
:offset => @entry_pages.current.offset)
|
||||
@total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
|
||||
render :layout => !request.xhr?
|
||||
}
|
||||
format.csv {
|
||||
# Export all entries
|
||||
@entries = TimeEntry.find(:all,
|
||||
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
||||
:conditions => cond.conditions,
|
||||
:order => sort_clause)
|
||||
send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
render_403 and return if @time_entry && !@time_entry.editable_by?(User.current)
|
||||
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
if request.post? and @time_entry.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'details', :project_id => @time_entry.project
|
||||
return
|
||||
end
|
||||
@activities = Enumeration::get_values('ACTI')
|
||||
end
|
||||
|
||||
def destroy
|
||||
render_404 and return unless @time_entry
|
||||
render_403 and return unless @time_entry.editable_by?(User.current)
|
||||
@time_entry.destroy
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
redirect_to :back
|
||||
rescue RedirectBackError
|
||||
redirect_to :action => 'details', :project_id => @time_entry.project
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
if params[:id]
|
||||
@time_entry = TimeEntry.find(params[:id])
|
||||
@project = @time_entry.project
|
||||
elsif params[:issue_id]
|
||||
@issue = Issue.find(params[:issue_id])
|
||||
@project = @issue.project
|
||||
elsif params[:project_id]
|
||||
@project = Project.find(params[:project_id])
|
||||
else
|
||||
render_404
|
||||
return false
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class TrackersController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class UsersController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_admin
|
||||
|
||||
helper :sort
|
||||
@@ -30,22 +31,18 @@ class UsersController < ApplicationController
|
||||
|
||||
def list
|
||||
sort_init 'login', 'asc'
|
||||
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
||||
sort_update
|
||||
|
||||
@status = params[:status] ? params[:status].to_i : 1
|
||||
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
||||
|
||||
unless params[:name].blank?
|
||||
name = "%#{params[:name].strip.downcase}%"
|
||||
c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ?", name, name, name]
|
||||
end
|
||||
conditions = "status <> 0"
|
||||
conditions = ["status=?", @status] unless @status == 0
|
||||
|
||||
@user_count = User.count(:conditions => c.conditions)
|
||||
@user_count = User.count(:conditions => conditions)
|
||||
@user_pages = Paginator.new self, @user_count,
|
||||
per_page_option,
|
||||
params['page']
|
||||
@users = User.find :all,:order => sort_clause,
|
||||
:conditions => c.conditions,
|
||||
:conditions => conditions,
|
||||
:limit => @user_pages.items_per_page,
|
||||
:offset => @user_pages.current.offset
|
||||
|
||||
@@ -55,11 +52,14 @@ class UsersController < ApplicationController
|
||||
def add
|
||||
if request.get?
|
||||
@user = User.new(:language => Setting.default_language)
|
||||
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
|
||||
else
|
||||
@user = User.new(params[:user])
|
||||
@user.admin = params[:user][:admin] || false
|
||||
@user.login = params[:user][:login]
|
||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
|
||||
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
||||
@user.custom_values = @custom_values
|
||||
if @user.save
|
||||
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
@@ -71,38 +71,42 @@ class UsersController < ApplicationController
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
if request.post?
|
||||
if request.get?
|
||||
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
||||
else
|
||||
@user.admin = params[:user][:admin] if params[:user][:admin]
|
||||
@user.login = params[:user][:login] if params[:user][:login]
|
||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
|
||||
@user.attributes = params[:user]
|
||||
# Was the account actived ? (do it before User#save clears the change)
|
||||
was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
|
||||
if @user.save
|
||||
Mailer.deliver_account_activated(@user) if was_activated
|
||||
if params[:custom_fields]
|
||||
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
||||
@user.custom_values = @custom_values
|
||||
end
|
||||
if @user.update_attributes(params[:user])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
# Give a string to redirect_to otherwise it would use status param as the response code
|
||||
redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
end
|
||||
@auth_sources = AuthSource.find(:all)
|
||||
@roles = Role.find_all_givable
|
||||
@projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
|
||||
@membership ||= Member.new
|
||||
@memberships = @user.memberships
|
||||
end
|
||||
|
||||
def edit_membership
|
||||
@user = User.find(params[:id])
|
||||
@membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
|
||||
@membership.attributes = params[:membership]
|
||||
@membership.save if request.post?
|
||||
redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
|
||||
if request.post? and @membership.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
end
|
||||
redirect_to :action => 'edit', :id => @user and return
|
||||
end
|
||||
|
||||
def destroy_membership
|
||||
@user = User.find(params[:id])
|
||||
Member.find(params[:membership_id]).destroy if request.post?
|
||||
redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
|
||||
if request.post? and Member.find(params[:membership_id]).destroy
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
end
|
||||
redirect_to :action => 'edit', :id => @user and return
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class VersionsController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :roadmap
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
@@ -33,9 +34,24 @@ class VersionsController < ApplicationController
|
||||
@version.destroy
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||
rescue
|
||||
flash[:error] = l(:notice_unable_delete_version)
|
||||
flash[:error] = "Unable to delete version"
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||
end
|
||||
|
||||
def download
|
||||
@attachment = @version.attachments.find(params[:attachment_id])
|
||||
@attachment.increment_download
|
||||
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
||||
:type => @attachment.content_type
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
|
||||
def destroy_file
|
||||
@version.attachments.find(params[:attachment_id]).destroy
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
||||
end
|
||||
|
||||
def status_by
|
||||
respond_to do |format|
|
||||
|
||||
@@ -16,38 +16,27 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WatchersController < ApplicationController
|
||||
before_filter :find_project
|
||||
before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
|
||||
before_filter :authorize, :only => :new
|
||||
layout 'base'
|
||||
before_filter :require_login, :find_project, :check_project_privacy
|
||||
|
||||
verify :method => :post,
|
||||
:only => [ :watch, :unwatch ],
|
||||
:render => { :nothing => true, :status => :method_not_allowed }
|
||||
|
||||
def watch
|
||||
set_watcher(User.current, true)
|
||||
end
|
||||
|
||||
def unwatch
|
||||
set_watcher(User.current, false)
|
||||
end
|
||||
|
||||
def new
|
||||
@watcher = Watcher.new(params[:watcher])
|
||||
@watcher.watchable = @watched
|
||||
@watcher.save if request.post?
|
||||
def add
|
||||
user = User.current
|
||||
@watched.add_watcher(user)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js do
|
||||
render :update do |page|
|
||||
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
|
||||
end
|
||||
end
|
||||
format.html { render :text => 'Watcher added.', :layout => true }
|
||||
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
||||
end
|
||||
rescue ::ActionController::RedirectBackError
|
||||
render :text => 'Watcher added.', :layout => true
|
||||
end
|
||||
|
||||
def remove
|
||||
user = User.current
|
||||
@watched.remove_watcher(user)
|
||||
respond_to do |format|
|
||||
format.html { render :text => 'Watcher removed.', :layout => true }
|
||||
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
klass = Object.const_get(params[:object_type].camelcase)
|
||||
@@ -57,14 +46,4 @@ private
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
|
||||
def set_watcher(user, watching)
|
||||
@watched.set_watcher(user, watching)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
||||
end
|
||||
rescue ::ActionController::RedirectBackError
|
||||
render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WelcomeController < ApplicationController
|
||||
layout 'base'
|
||||
|
||||
def index
|
||||
@news = News.latest User.current
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
require 'diff'
|
||||
|
||||
class WikiController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :find_wiki, :authorize
|
||||
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
|
||||
|
||||
verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
|
||||
verify :method => :post, :only => [:destroy, :destroy_attachment], :redirect_to => { :action => :index }
|
||||
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
@@ -39,11 +39,6 @@ class WikiController < ApplicationController
|
||||
end
|
||||
return
|
||||
end
|
||||
if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
|
||||
# Redirects user to the current version if he's not allowed to view previous versions
|
||||
redirect_to :version => nil
|
||||
return
|
||||
end
|
||||
@content = @page.content_for_version(params[:version])
|
||||
if params[:export] == 'html'
|
||||
export = render_to_string :action => 'export', :layout => false
|
||||
@@ -53,24 +48,19 @@ class WikiController < ApplicationController
|
||||
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
|
||||
return
|
||||
end
|
||||
@editable = editable?
|
||||
render :action => 'show'
|
||||
end
|
||||
|
||||
# edit an existing page or a new one
|
||||
def edit
|
||||
@page = @wiki.find_or_new_page(params[:page])
|
||||
return render_403 unless editable?
|
||||
@page.content = WikiContent.new(:page => @page) if @page.new_record?
|
||||
|
||||
@content = @page.content_for_version(params[:version])
|
||||
@content.text = initial_page_content(@page) if @content.text.blank?
|
||||
@content.text = "h1. #{@page.pretty_title}" if @content.text.blank?
|
||||
# don't keep previous comment
|
||||
@content.comments = nil
|
||||
if request.get?
|
||||
# To prevent StaleObjectError exception when reverting to a previous version
|
||||
@content.version = @page.content.version
|
||||
else
|
||||
if request.post?
|
||||
if !@page.new_record? && @content.text == params[:content][:text]
|
||||
# don't save if text wasn't changed
|
||||
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||
@@ -82,7 +72,6 @@ class WikiController < ApplicationController
|
||||
@content.author = User.current
|
||||
# if page is new @page.save will also save content, but not if page isn't a new record
|
||||
if (@page.new_record? ? @page.save : @content.save)
|
||||
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
|
||||
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||
end
|
||||
end
|
||||
@@ -93,7 +82,7 @@ class WikiController < ApplicationController
|
||||
|
||||
# rename a page
|
||||
def rename
|
||||
return render_403 unless editable?
|
||||
@page = @wiki.find_page(params[:page])
|
||||
@page.redirect_existing_links = true
|
||||
# used to display the *original* title if some AR validation errors occur
|
||||
@original_title = @page.pretty_title
|
||||
@@ -103,13 +92,10 @@ class WikiController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def protect
|
||||
@page.update_attribute :protected, params[:protected]
|
||||
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||
end
|
||||
|
||||
# show page history
|
||||
def history
|
||||
@page = @wiki.find_page(params[:page])
|
||||
|
||||
@version_count = @page.content.versions.count
|
||||
@version_pages = Paginator.new self, @version_count, per_page_option, params['p']
|
||||
# don't load text
|
||||
@@ -123,19 +109,20 @@ class WikiController < ApplicationController
|
||||
end
|
||||
|
||||
def diff
|
||||
@page = @wiki.find_page(params[:page])
|
||||
@diff = @page.diff(params[:version], params[:version_from])
|
||||
render_404 unless @diff
|
||||
end
|
||||
|
||||
def annotate
|
||||
@page = @wiki.find_page(params[:page])
|
||||
@annotate = @page.annotate(params[:version])
|
||||
render_404 unless @annotate
|
||||
end
|
||||
|
||||
# remove a wiki page and its history
|
||||
def destroy
|
||||
return render_403 unless editable?
|
||||
@page.destroy
|
||||
@page = @wiki.find_page(params[:page])
|
||||
@page.destroy if @page
|
||||
redirect_to :action => 'special', :id => @project, :page => 'Page_index'
|
||||
end
|
||||
|
||||
@@ -150,7 +137,6 @@ class WikiController < ApplicationController
|
||||
:joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id",
|
||||
:order => 'title'
|
||||
@pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
|
||||
@pages_by_parent_id = @pages.group_by(&:parent_id)
|
||||
# export wiki to a single html file
|
||||
when 'export'
|
||||
@pages = @wiki.pages.find :all, :order => 'title'
|
||||
@@ -166,22 +152,23 @@ class WikiController < ApplicationController
|
||||
|
||||
def preview
|
||||
page = @wiki.find_page(params[:page])
|
||||
# page is nil when previewing a new page
|
||||
return render_403 unless page.nil? || editable?(page)
|
||||
if page
|
||||
@attachements = page.attachments
|
||||
@previewed = page.content
|
||||
end
|
||||
@attachements = page.attachments if page
|
||||
@text = params[:content][:text]
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
def add_attachment
|
||||
return render_403 unless editable?
|
||||
@page = @wiki.find_page(params[:page])
|
||||
attach_files(@page, params[:attachments])
|
||||
redirect_to :action => 'index', :page => @page.title
|
||||
end
|
||||
|
||||
def destroy_attachment
|
||||
@page = @wiki.find_page(params[:page])
|
||||
@page.attachments.find(params[:attachment_id]).destroy
|
||||
redirect_to :action => 'index', :page => @page.title
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_wiki
|
||||
@@ -191,22 +178,4 @@ private
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Finds the requested page and returns a 404 error if it doesn't exist
|
||||
def find_existing_page
|
||||
@page = @wiki.find_page(params[:page])
|
||||
render_404 if @page.nil?
|
||||
end
|
||||
|
||||
# Returns true if the current user is allowed to edit the page, otherwise false
|
||||
def editable?(page = @page)
|
||||
page.editable_by?(User.current)
|
||||
end
|
||||
|
||||
# Returns the default content of a new wiki page
|
||||
def initial_page_content(page)
|
||||
helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
|
||||
extend helper unless self.instance_of?(helper)
|
||||
helper.instance_method(:initial_page_content).bind(self).call(page)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WikisController < ApplicationController
|
||||
layout 'base'
|
||||
menu_item :settings
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WorkflowsController < ApplicationController
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
@workflow_counts = Workflow.count_by_tracker_and_role
|
||||
end
|
||||
|
||||
def edit
|
||||
@role = Role.find_by_id(params[:role_id])
|
||||
@tracker = Tracker.find_by_id(params[:tracker_id])
|
||||
|
||||
if request.post?
|
||||
Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
|
||||
(params[:issue_status] || []).each { |old, news|
|
||||
news.each { |new|
|
||||
@role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
|
||||
}
|
||||
}
|
||||
if @role.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
|
||||
end
|
||||
end
|
||||
@roles = Role.find(:all, :order => 'builtin, position')
|
||||
@trackers = Tracker.find(:all, :order => 'position')
|
||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||
end
|
||||
end
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
module AdminHelper
|
||||
def project_status_options_for_select(selected)
|
||||
options_for_select([[l(:label_all), ''],
|
||||
options_for_select([[l(:label_all), "*"],
|
||||
[l(:status_active), 1]], selected)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,32 +5,23 @@
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'coderay'
|
||||
require 'coderay/helpers/file_type'
|
||||
require 'forwardable'
|
||||
require 'cgi'
|
||||
|
||||
module ApplicationHelper
|
||||
include Redmine::WikiFormatting::Macros::Definitions
|
||||
include GravatarHelper::PublicMethods
|
||||
|
||||
extend Forwardable
|
||||
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
||||
|
||||
def current_role
|
||||
@current_role ||= User.current.role_for_project(@project)
|
||||
end
|
||||
|
||||
|
||||
# Return true if user is authorized for controller/action, otherwise false
|
||||
def authorize_for(controller, action)
|
||||
User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
||||
@@ -41,212 +32,134 @@ module ApplicationHelper
|
||||
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
||||
end
|
||||
|
||||
# Display a link to remote if user is authorized
|
||||
def link_to_remote_if_authorized(name, options = {}, html_options = nil)
|
||||
url = options[:url] || {}
|
||||
link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action])
|
||||
end
|
||||
|
||||
# Display a link to user's account page
|
||||
def link_to_user(user, options={})
|
||||
(user && !user.anonymous?) ? link_to(user.name(options[:format]), :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
|
||||
def link_to_user(user)
|
||||
user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
|
||||
end
|
||||
|
||||
|
||||
def link_to_issue(issue, options={})
|
||||
options[:class] ||= ''
|
||||
options[:class] << ' issue'
|
||||
options[:class] << ' closed' if issue.closed?
|
||||
link_to "#{issue.tracker.name} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue}, options
|
||||
end
|
||||
|
||||
# Generates a link to an attachment.
|
||||
# Options:
|
||||
# * :text - Link text (default to attachment filename)
|
||||
# * :download - Force download (default: false)
|
||||
def link_to_attachment(attachment, options={})
|
||||
text = options.delete(:text) || attachment.filename
|
||||
action = options.delete(:download) ? 'download' : 'show'
|
||||
|
||||
link_to(h(text), {:controller => 'attachments', :action => action, :id => attachment, :filename => attachment.filename }, options)
|
||||
end
|
||||
|
||||
|
||||
def toggle_link(name, id, options={})
|
||||
onclick = "Element.toggle('#{id}'); "
|
||||
onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
|
||||
onclick << "return false;"
|
||||
link_to(name, "#", :onclick => onclick)
|
||||
end
|
||||
|
||||
|
||||
def show_and_goto_link(name, id, options={})
|
||||
onclick = "Element.show('#{id}'); "
|
||||
onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
|
||||
onclick << "Element.scrollTo('#{id}'); "
|
||||
onclick << "return false;"
|
||||
link_to(name, "#", options.merge(:onclick => onclick))
|
||||
end
|
||||
|
||||
def image_to_function(name, function, html_options = {})
|
||||
html_options.symbolize_keys!
|
||||
tag(:input, html_options.merge({
|
||||
:type => "image", :src => image_path(name),
|
||||
:onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
|
||||
tag(:input, html_options.merge({
|
||||
:type => "image", :src => image_path(name),
|
||||
:onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
|
||||
}))
|
||||
end
|
||||
|
||||
|
||||
def prompt_to_remote(name, text, param, url, html_options = {})
|
||||
html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
|
||||
link_to name, {}, html_options
|
||||
end
|
||||
|
||||
|
||||
def format_date(date)
|
||||
return nil unless date
|
||||
# "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
|
||||
@date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
|
||||
date.strftime(@date_format)
|
||||
end
|
||||
|
||||
|
||||
def format_time(time, include_date = true)
|
||||
return nil unless time
|
||||
time = time.to_time if time.is_a?(String)
|
||||
zone = User.current.time_zone
|
||||
local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
|
||||
if time.utc?
|
||||
local = zone ? zone.adjust(time) : time.getlocal
|
||||
else
|
||||
local = zone ? zone.adjust(time.getutc) : time
|
||||
end
|
||||
@date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
|
||||
@time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
|
||||
include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
|
||||
end
|
||||
|
||||
def format_activity_title(text)
|
||||
h(truncate_single_line(text, 100))
|
||||
end
|
||||
|
||||
def format_activity_day(date)
|
||||
date == Date.today ? l(:label_today).titleize : format_date(date)
|
||||
end
|
||||
|
||||
def format_activity_description(text)
|
||||
h(truncate(text.to_s, 250).gsub(%r{<(pre|code)>.*$}m, '...'))
|
||||
end
|
||||
|
||||
def distance_of_date_in_words(from_date, to_date = 0)
|
||||
from_date = from_date.to_date if from_date.respond_to?(:to_date)
|
||||
to_date = to_date.to_date if to_date.respond_to?(:to_date)
|
||||
distance_in_days = (to_date - from_date).abs
|
||||
lwr(:actionview_datehelper_time_in_words_day, distance_in_days)
|
||||
end
|
||||
|
||||
def due_date_distance_in_words(date)
|
||||
if date
|
||||
l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
|
||||
end
|
||||
end
|
||||
|
||||
def render_page_hierarchy(pages, node=nil)
|
||||
content = ''
|
||||
if pages[node]
|
||||
content << "<ul class=\"pages-hierarchy\">\n"
|
||||
pages[node].each do |page|
|
||||
content << "<li>"
|
||||
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :id => page.project, :page => page.title},
|
||||
:title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
|
||||
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
|
||||
content << "</li>\n"
|
||||
end
|
||||
content << "</ul>\n"
|
||||
end
|
||||
content
|
||||
end
|
||||
|
||||
# Renders flash messages
|
||||
def render_flash_messages
|
||||
s = ''
|
||||
flash.each do |k,v|
|
||||
s << content_tag('div', v, :class => "flash #{k}")
|
||||
end
|
||||
s
|
||||
end
|
||||
|
||||
# Truncates and returns the string as a single line
|
||||
def truncate_single_line(string, *args)
|
||||
truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
|
||||
end
|
||||
|
||||
def html_hours(text)
|
||||
text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
|
||||
end
|
||||
|
||||
def authoring(created, author, options={})
|
||||
time_tag = @project.nil? ? content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created)) :
|
||||
link_to(distance_of_time_in_words(Time.now, created),
|
||||
{:controller => 'projects', :action => 'activity', :id => @project, :from => created.to_date},
|
||||
:title => format_time(created))
|
||||
author_tag = (author.is_a?(User) && !author.anonymous?) ? link_to(h(author), :controller => 'account', :action => 'show', :id => author) : h(author || 'Anonymous')
|
||||
l(options[:label] || :label_added_time_by, author_tag, time_tag)
|
||||
|
||||
def authoring(created, author)
|
||||
time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
|
||||
l(:label_added_time_by, author || 'Anonymous', time_tag)
|
||||
end
|
||||
|
||||
def l_or_humanize(s, options={})
|
||||
k = "#{options[:prefix]}#{s}".to_sym
|
||||
l_has_string?(k) ? l(k) : s.to_s.humanize
|
||||
|
||||
def l_or_humanize(s)
|
||||
l_has_string?("label_#{s}".to_sym) ? l("label_#{s}".to_sym) : s.to_s.humanize
|
||||
end
|
||||
|
||||
|
||||
def day_name(day)
|
||||
l(:general_day_names).split(',')[day-1]
|
||||
end
|
||||
|
||||
|
||||
def month_name(month)
|
||||
l(:actionview_datehelper_select_month_names).split(',')[month-1]
|
||||
end
|
||||
|
||||
def syntax_highlight(name, content)
|
||||
type = CodeRay::FileType[name]
|
||||
type ? CodeRay.scan(content, type).html : h(content)
|
||||
end
|
||||
|
||||
def to_path_param(path)
|
||||
path.to_s.split(%r{[/\\]}).select {|p| !p.blank?}
|
||||
end
|
||||
|
||||
def pagination_links_full(paginator, count=nil, options={})
|
||||
page_param = options.delete(:page_param) || :page
|
||||
url_param = params.dup
|
||||
# don't reuse params if filters are present
|
||||
url_param.clear if url_param.has_key?(:set_filter)
|
||||
|
||||
html = ''
|
||||
html << link_to_remote(('« ' + l(:label_previous)),
|
||||
|
||||
html = ''
|
||||
html << link_to_remote(('« ' + l(:label_previous)),
|
||||
{:update => 'content',
|
||||
:url => url_param.merge(page_param => paginator.current.previous),
|
||||
:complete => 'window.scrollTo(0,0)'},
|
||||
{:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
|
||||
|
||||
|
||||
html << (pagination_links_each(paginator, options) do |n|
|
||||
link_to_remote(n.to_s,
|
||||
link_to_remote(n.to_s,
|
||||
{:url => {:params => url_param.merge(page_param => n)},
|
||||
:update => 'content',
|
||||
:complete => 'window.scrollTo(0,0)'},
|
||||
{:href => url_for(:params => url_param.merge(page_param => n))})
|
||||
end || '')
|
||||
|
||||
html << ' ' + link_to_remote((l(:label_next) + ' »'),
|
||||
|
||||
html << ' ' + link_to_remote((l(:label_next) + ' »'),
|
||||
{:update => 'content',
|
||||
:url => url_param.merge(page_param => paginator.current.next),
|
||||
:complete => 'window.scrollTo(0,0)'},
|
||||
{:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
|
||||
|
||||
|
||||
unless count.nil?
|
||||
html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
|
||||
end
|
||||
|
||||
html
|
||||
|
||||
html
|
||||
end
|
||||
|
||||
|
||||
def per_page_links(selected=nil)
|
||||
url_param = params.dup
|
||||
url_param.clear if url_param.has_key?(:set_filter)
|
||||
|
||||
|
||||
links = Setting.per_page_options_array.collect do |n|
|
||||
n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
|
||||
n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
|
||||
{:href => url_for(url_param.merge(:per_page => n))})
|
||||
end
|
||||
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
|
||||
end
|
||||
|
||||
|
||||
def breadcrumb(*args)
|
||||
elements = args.flatten
|
||||
elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil
|
||||
content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb')
|
||||
end
|
||||
|
||||
|
||||
def html_title(*args)
|
||||
if args.empty?
|
||||
title = []
|
||||
@@ -272,7 +185,7 @@ module ApplicationHelper
|
||||
options = args.last.is_a?(Hash) ? args.pop : {}
|
||||
case args.size
|
||||
when 1
|
||||
obj = options[:object]
|
||||
obj = nil
|
||||
text = args.shift
|
||||
when 2
|
||||
obj = args.shift
|
||||
@@ -281,47 +194,47 @@ module ApplicationHelper
|
||||
raise ArgumentError, 'invalid arguments to textilizable'
|
||||
end
|
||||
return '' if text.blank?
|
||||
|
||||
|
||||
only_path = options.delete(:only_path) == false ? false : true
|
||||
|
||||
# when using an image link, try to use an attachment, if possible
|
||||
attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
|
||||
|
||||
|
||||
if attachments
|
||||
attachments = attachments.sort_by(&:created_on).reverse
|
||||
text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(bmp|gif|jpg|jpeg|png))!/i) do |m|
|
||||
text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
|
||||
style = $1
|
||||
filename = $6.downcase
|
||||
filename = $6
|
||||
rf = Regexp.new(filename, Regexp::IGNORECASE)
|
||||
# search for the picture in attachments
|
||||
if found = attachments.detect { |att| att.filename.downcase == filename }
|
||||
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
|
||||
desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1")
|
||||
alt = desc.blank? ? nil : "(#{desc})"
|
||||
"!#{style}#{image_url}#{alt}!"
|
||||
if found = attachments.detect { |att| att.filename =~ rf }
|
||||
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found.id
|
||||
"!#{style}#{image_url}!"
|
||||
else
|
||||
m
|
||||
"!#{style}#{filename}!"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text) { |macro, args| exec_macro(macro, obj, args) }
|
||||
|
||||
text = (Setting.text_formatting == 'textile') ?
|
||||
Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
|
||||
simple_format(auto_link(h(text)))
|
||||
|
||||
# different methods for formatting wiki links
|
||||
case options[:wiki_links]
|
||||
when :local
|
||||
# used for local links to html files
|
||||
format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" }
|
||||
format_wiki_link = Proc.new {|project, title| "#{title}.html" }
|
||||
when :anchor
|
||||
# used for single-file wiki export
|
||||
format_wiki_link = Proc.new {|project, title, anchor| "##{title}" }
|
||||
format_wiki_link = Proc.new {|project, title| "##{title}" }
|
||||
else
|
||||
format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
|
||||
format_wiki_link = Proc.new {|project, title| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title) }
|
||||
end
|
||||
|
||||
|
||||
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
|
||||
|
||||
|
||||
# Wiki links
|
||||
#
|
||||
#
|
||||
# Examples:
|
||||
# [[mypage]]
|
||||
# [[mypage|mytext]]
|
||||
@@ -339,16 +252,11 @@ module ApplicationHelper
|
||||
page = $2
|
||||
title ||= $1 if page.blank?
|
||||
end
|
||||
|
||||
|
||||
if link_project && link_project.wiki
|
||||
# extract anchor
|
||||
anchor = nil
|
||||
if page =~ /^(.+?)\#(.+)$/
|
||||
page, anchor = $1, $2
|
||||
end
|
||||
# check if page exists
|
||||
wiki_page = link_project.wiki.find_page(page)
|
||||
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor),
|
||||
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
|
||||
:class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
||||
else
|
||||
# project or wiki doesn't exist
|
||||
@@ -360,7 +268,7 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
# Redmine links
|
||||
#
|
||||
#
|
||||
# Examples:
|
||||
# Issues:
|
||||
# #52 -> Link to issue #52
|
||||
@@ -383,9 +291,7 @@ module ApplicationHelper
|
||||
# source:some/file#L120 -> Link to line 120 of the file
|
||||
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
||||
# export:some/file -> Force the download of the file
|
||||
# Forum messages:
|
||||
# message#1218 -> Link to message with id 1218
|
||||
text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
|
||||
text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version|commit|source|export)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
|
||||
leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
|
||||
link = nil
|
||||
if esc.nil?
|
||||
@@ -393,13 +299,13 @@ module ApplicationHelper
|
||||
if project && (changeset = project.changesets.find_by_revision(oid))
|
||||
link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
|
||||
:class => 'changeset',
|
||||
:title => truncate_single_line(changeset.comments, 100))
|
||||
:title => truncate(changeset.comments, 100))
|
||||
end
|
||||
elsif sep == '#'
|
||||
oid = oid.to_i
|
||||
case prefix
|
||||
when nil
|
||||
if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
|
||||
if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
|
||||
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
|
||||
:class => (issue.closed? ? 'issue closed' : 'issue'),
|
||||
:title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
|
||||
@@ -415,16 +321,6 @@ module ApplicationHelper
|
||||
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
||||
:class => 'version'
|
||||
end
|
||||
when 'message'
|
||||
if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
|
||||
link = link_to h(truncate(message.subject, 60)), {:only_path => only_path,
|
||||
:controller => 'messages',
|
||||
:action => 'show',
|
||||
:board_id => message.board,
|
||||
:id => message.root,
|
||||
:anchor => (message.parent ? "message-#{message.id}" : nil)},
|
||||
:class => 'message'
|
||||
end
|
||||
end
|
||||
elsif sep == ':'
|
||||
# removes the double quotes if any
|
||||
@@ -442,16 +338,13 @@ module ApplicationHelper
|
||||
end
|
||||
when 'commit'
|
||||
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
||||
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
||||
:class => 'changeset',
|
||||
:title => truncate_single_line(changeset.comments, 100)
|
||||
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, :class => 'changeset', :title => truncate(changeset.comments, 100)
|
||||
end
|
||||
when 'source', 'export'
|
||||
if project && project.repository
|
||||
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
||||
path, rev, anchor = $1, $3, $5
|
||||
link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
||||
:path => to_path_param(path),
|
||||
link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, :path => path,
|
||||
:rev => rev,
|
||||
:anchor => anchor,
|
||||
:format => (prefix == 'export' ? 'raw' : nil)},
|
||||
@@ -467,10 +360,10 @@ module ApplicationHelper
|
||||
end
|
||||
leading + (link || "#{prefix}#{sep}#{oid}")
|
||||
end
|
||||
|
||||
|
||||
text
|
||||
end
|
||||
|
||||
|
||||
# Same as Rails' simple_format helper without using paragraphs
|
||||
def simple_format_without_paragraph(text)
|
||||
text.to_s.
|
||||
@@ -478,7 +371,7 @@ module ApplicationHelper
|
||||
gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
|
||||
gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
||||
end
|
||||
|
||||
|
||||
def error_messages_for(object_name, options = {})
|
||||
options = options.symbolize_keys
|
||||
object = instance_variable_get("@#{object_name}")
|
||||
@@ -487,23 +380,23 @@ module ApplicationHelper
|
||||
full_messages = []
|
||||
object.errors.each do |attr, msg|
|
||||
next if msg.nil?
|
||||
msg = [msg] unless msg.is_a?(Array)
|
||||
msg = msg.first if msg.is_a? Array
|
||||
if attr == "base"
|
||||
full_messages << l(*msg)
|
||||
full_messages << l(msg)
|
||||
else
|
||||
full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(*msg) unless attr == "custom_values"
|
||||
full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values"
|
||||
end
|
||||
end
|
||||
# retrieve custom values error messages
|
||||
if object.errors[:custom_values]
|
||||
object.custom_values.each do |v|
|
||||
object.custom_values.each do |v|
|
||||
v.errors.each do |attr, msg|
|
||||
next if msg.nil?
|
||||
msg = [msg] unless msg.is_a?(Array)
|
||||
full_messages << "« " + v.custom_field.name + " » " + l(*msg)
|
||||
msg = msg.first if msg.is_a? Array
|
||||
full_messages << "« " + v.custom_field.name + " » " + l(msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
content_tag("div",
|
||||
content_tag(
|
||||
options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
|
||||
@@ -515,35 +408,29 @@ module ApplicationHelper
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def lang_options_for_select(blank=true)
|
||||
(blank ? [["(auto)", ""]] : []) +
|
||||
(blank ? [["(auto)", ""]] : []) +
|
||||
GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
|
||||
end
|
||||
|
||||
|
||||
def label_tag_for(name, option_tags = nil, options = {})
|
||||
label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
|
||||
content_tag("label", label_text)
|
||||
end
|
||||
|
||||
|
||||
def labelled_tabular_form_for(name, object, options, &proc)
|
||||
options[:html] ||= {}
|
||||
options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
|
||||
form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
|
||||
end
|
||||
|
||||
def back_url_hidden_field_tag
|
||||
back_url = params[:back_url] || request.env['HTTP_REFERER']
|
||||
back_url = CGI.unescape(back_url.to_s)
|
||||
hidden_field_tag('back_url', CGI.escape(back_url)) unless back_url.blank?
|
||||
end
|
||||
|
||||
|
||||
def check_all_links(form_name)
|
||||
link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
|
||||
" | " +
|
||||
link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
|
||||
link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
|
||||
end
|
||||
|
||||
|
||||
def progress_bar(pcts, options={})
|
||||
pcts = [pcts, pcts] unless pcts.is_a?(Array)
|
||||
pcts[1] = pcts[1] - pcts[0]
|
||||
@@ -552,13 +439,13 @@ module ApplicationHelper
|
||||
legend = options[:legend] || ''
|
||||
content_tag('table',
|
||||
content_tag('tr',
|
||||
(pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0].floor}%;", :class => 'closed') : '') +
|
||||
(pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1].floor}%;", :class => 'done') : '') +
|
||||
(pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2].floor}%;", :class => 'todo') : '')
|
||||
(pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
|
||||
(pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
|
||||
(pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
|
||||
), :class => 'progress', :style => "width: #{width};") +
|
||||
content_tag('p', legend, :class => 'pourcent')
|
||||
end
|
||||
|
||||
|
||||
def context_menu_link(name, url, options={})
|
||||
options[:class] ||= ''
|
||||
if options.delete(:selected)
|
||||
@@ -574,54 +461,31 @@ module ApplicationHelper
|
||||
end
|
||||
link_to name, url, options
|
||||
end
|
||||
|
||||
|
||||
def calendar_for(field_id)
|
||||
include_calendar_headers_tags
|
||||
image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
|
||||
javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
|
||||
end
|
||||
|
||||
def wikitoolbar_for(field_id)
|
||||
return '' unless Setting.text_formatting == 'textile'
|
||||
|
||||
help_link = l(:setting_text_formatting) + ': ' +
|
||||
link_to(l(:label_help), compute_public_path('wiki_syntax', 'help', 'html'),
|
||||
:onclick => "window.open(\"#{ compute_public_path('wiki_syntax', 'help', 'html') }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")
|
||||
|
||||
def include_calendar_headers_tags
|
||||
unless @calendar_headers_tags_included
|
||||
@calendar_headers_tags_included = true
|
||||
content_for :header_tags do
|
||||
javascript_include_tag('calendar/calendar') +
|
||||
javascript_include_tag("calendar/lang/calendar-#{current_language}.js") +
|
||||
javascript_include_tag('calendar/calendar-setup') +
|
||||
stylesheet_link_tag('calendar')
|
||||
end
|
||||
end
|
||||
javascript_include_tag('jstoolbar/jstoolbar') +
|
||||
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") +
|
||||
javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.setHelpLink('#{help_link}'); toolbar.draw();")
|
||||
end
|
||||
|
||||
|
||||
def content_for(name, content = nil, &block)
|
||||
@has_content ||= {}
|
||||
@has_content[name] = true
|
||||
super(name, content, &block)
|
||||
end
|
||||
|
||||
|
||||
def has_content?(name)
|
||||
(@has_content && @has_content[name]) || false
|
||||
end
|
||||
|
||||
# Returns the avatar image tag for the given +user+ if avatars are enabled
|
||||
# +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
|
||||
def avatar(user, options = { })
|
||||
if Setting.gravatar_enabled?
|
||||
email = nil
|
||||
if user.respond_to?(:mail)
|
||||
email = user.mail
|
||||
elsif user.to_s =~ %r{<(.+?)>}
|
||||
email = $1
|
||||
end
|
||||
return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wiki_helper
|
||||
helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
|
||||
extend helper
|
||||
return self
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,19 +16,10 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module AttachmentsHelper
|
||||
# Displays view/delete links to the attachments of the given object
|
||||
# Options:
|
||||
# :author -- author names are not displayed if set to false
|
||||
def link_to_attachments(container, options = {})
|
||||
options.assert_valid_keys(:author)
|
||||
|
||||
if container.attachments.any?
|
||||
options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
|
||||
render :partial => 'attachments/links', :locals => {:attachments => container.attachments, :options => options}
|
||||
# displays the links to a collection of attachments
|
||||
def link_to_attachments(attachments, options = {})
|
||||
if attachments.any?
|
||||
render :partial => 'attachments/links', :locals => {:attachments => attachments, :options => options}
|
||||
end
|
||||
end
|
||||
|
||||
def to_utf8(str)
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,47 +19,43 @@ module CustomFieldsHelper
|
||||
|
||||
def custom_fields_tabs
|
||||
tabs = [{:name => 'IssueCustomField', :label => :label_issue_plural},
|
||||
{:name => 'TimeEntryCustomField', :label => :label_spent_time},
|
||||
{:name => 'ProjectCustomField', :label => :label_project_plural},
|
||||
{:name => 'UserCustomField', :label => :label_user_plural}
|
||||
]
|
||||
end
|
||||
|
||||
# Return custom field html tag corresponding to its format
|
||||
def custom_field_tag(name, custom_value)
|
||||
def custom_field_tag(custom_value)
|
||||
custom_field = custom_value.custom_field
|
||||
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||||
field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||||
field_name = "custom_fields[#{custom_field.id}]"
|
||||
field_id = "custom_fields_#{custom_field.id}"
|
||||
|
||||
case custom_field.field_format
|
||||
when "date"
|
||||
text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
|
||||
text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) +
|
||||
calendar_for(field_id)
|
||||
when "text"
|
||||
text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%')
|
||||
text_area 'custom_value', 'value', :name => field_name, :id => field_id, :rows => 3, :style => 'width:99%'
|
||||
when "bool"
|
||||
check_box_tag(field_name, '1', custom_value.true?, :id => field_id) + hidden_field_tag(field_name, '0')
|
||||
check_box 'custom_value', 'value', :name => field_name, :id => field_id
|
||||
when "list"
|
||||
blank_option = custom_field.is_required? ?
|
||||
(custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
|
||||
'<option></option>'
|
||||
select_tag(field_name, blank_option + options_for_select(custom_field.possible_values, custom_value.value), :id => field_id)
|
||||
select 'custom_value', 'value', custom_field.possible_values, { :include_blank => true }, :name => field_name, :id => field_id
|
||||
else
|
||||
text_field_tag(field_name, custom_value.value, :id => field_id)
|
||||
text_field 'custom_value', 'value', :name => field_name, :id => field_id
|
||||
end
|
||||
end
|
||||
|
||||
# Return custom field label tag
|
||||
def custom_field_label_tag(name, custom_value)
|
||||
def custom_field_label_tag(custom_value)
|
||||
content_tag "label", custom_value.custom_field.name +
|
||||
(custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
|
||||
:for => "#{name}_custom_field_values_#{custom_value.custom_field.id}",
|
||||
:for => "custom_fields_#{custom_value.custom_field.id}",
|
||||
:class => (custom_value.errors.empty? ? nil : "error" )
|
||||
end
|
||||
|
||||
# Return custom field tag with its label tag
|
||||
def custom_field_tag_with_label(name, custom_value)
|
||||
custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
|
||||
def custom_field_tag_with_label(custom_value)
|
||||
custom_field_label_tag(custom_value) + custom_field_tag(custom_value)
|
||||
end
|
||||
|
||||
# Return a string used to display a custom value
|
||||
|
||||
85
app/helpers/ifpdf_helper.rb
Normal file
85
app/helpers/ifpdf_helper.rb
Normal file
@@ -0,0 +1,85 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'iconv'
|
||||
require 'rfpdf/chinese'
|
||||
|
||||
module IfpdfHelper
|
||||
|
||||
class IFPDF < FPDF
|
||||
include GLoc
|
||||
attr_accessor :footer_date
|
||||
|
||||
def initialize(lang)
|
||||
super()
|
||||
set_language_if_valid lang
|
||||
case current_language.to_s
|
||||
when 'ja'
|
||||
extend(PDF_Japanese)
|
||||
AddSJISFont()
|
||||
@font_for_content = 'SJIS'
|
||||
@font_for_footer = 'SJIS'
|
||||
when 'zh'
|
||||
extend(PDF_Chinese)
|
||||
AddGBFont()
|
||||
@font_for_content = 'GB'
|
||||
@font_for_footer = 'GB'
|
||||
when 'zh-tw'
|
||||
extend(PDF_Chinese)
|
||||
AddBig5Font()
|
||||
@font_for_content = 'Big5'
|
||||
@font_for_footer = 'Big5'
|
||||
else
|
||||
@font_for_content = 'Arial'
|
||||
@font_for_footer = 'Helvetica'
|
||||
end
|
||||
SetCreator("redMine #{Redmine::VERSION}")
|
||||
SetFont(@font_for_content)
|
||||
end
|
||||
|
||||
def SetFontStyle(style, size)
|
||||
SetFont(@font_for_content, style, size)
|
||||
end
|
||||
|
||||
def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
|
||||
@ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
|
||||
# these quotation marks are not correctly rendered in the pdf
|
||||
txt = txt.gsub(/[“”]/, '"') if txt
|
||||
txt = begin
|
||||
# 0x5c char handling
|
||||
txtar = txt.split('\\')
|
||||
txtar << '' if txt[-1] == ?\\
|
||||
txtar.collect {|x| @ic.iconv(x)}.join('\\').gsub(/\\/, "\\\\\\\\")
|
||||
rescue
|
||||
txt
|
||||
end || ''
|
||||
super w,h,txt,border,ln,align,fill,link
|
||||
end
|
||||
|
||||
def Footer
|
||||
SetFont(@font_for_footer, 'I', 8)
|
||||
SetY(-15)
|
||||
SetX(15)
|
||||
Cell(0, 5, @footer_date, 0, 0, 'L')
|
||||
SetY(-15)
|
||||
SetX(-30)
|
||||
Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -33,16 +33,6 @@ module IssuesHelper
|
||||
"<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
|
||||
end
|
||||
|
||||
# Returns a string of css classes that apply to the given issue
|
||||
def css_issue_classes(issue)
|
||||
s = "issue status-#{issue.status.position} priority-#{issue.priority.position}"
|
||||
s << ' closed' if issue.closed?
|
||||
s << ' overdue' if issue.overdue?
|
||||
s << ' created-by-me' if User.current.logged? && issue.author_id == User.current.id
|
||||
s << ' assigned-to-me' if User.current.logged? && issue.assigned_to_id == User.current.id
|
||||
s
|
||||
end
|
||||
|
||||
def sidebar_queries
|
||||
unless @sidebar_queries
|
||||
# User can see public queries and his own queries
|
||||
@@ -64,15 +54,9 @@ module IssuesHelper
|
||||
when 'due_date', 'start_date'
|
||||
value = format_date(detail.value.to_date) if detail.value
|
||||
old_value = format_date(detail.old_value.to_date) if detail.old_value
|
||||
when 'project_id'
|
||||
p = Project.find_by_id(detail.value) and value = p.name if detail.value
|
||||
p = Project.find_by_id(detail.old_value) and old_value = p.name if detail.old_value
|
||||
when 'status_id'
|
||||
s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value
|
||||
s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value
|
||||
when 'tracker_id'
|
||||
t = Tracker.find_by_id(detail.value) and value = t.name if detail.value
|
||||
t = Tracker.find_by_id(detail.old_value) and old_value = t.name if detail.old_value
|
||||
when 'assigned_to_id'
|
||||
u = User.find_by_id(detail.value) and value = u.name if detail.value
|
||||
u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value
|
||||
@@ -85,9 +69,6 @@ module IssuesHelper
|
||||
when 'fixed_version_id'
|
||||
v = Version.find_by_id(detail.value) and value = v.name if detail.value
|
||||
v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value
|
||||
when 'estimated_hours'
|
||||
value = "%0.02f" % detail.value.to_f unless detail.value.blank?
|
||||
old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
|
||||
end
|
||||
when 'cf'
|
||||
custom_field = CustomField.find_by_id(detail.prop_key)
|
||||
@@ -99,8 +80,7 @@ module IssuesHelper
|
||||
when 'attachment'
|
||||
label = l(:label_attachment)
|
||||
end
|
||||
call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value })
|
||||
|
||||
|
||||
label ||= detail.prop_key
|
||||
value ||= detail.value
|
||||
old_value ||= detail.old_value
|
||||
@@ -109,9 +89,9 @@ module IssuesHelper
|
||||
label = content_tag('strong', label)
|
||||
old_value = content_tag("i", h(old_value)) if detail.old_value
|
||||
old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
|
||||
if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key)
|
||||
if detail.property == 'attachment' && !value.blank? && Attachment.find_by_id(detail.prop_key)
|
||||
# Link to the attachment if it has not been removed
|
||||
value = link_to_attachment(a)
|
||||
value = link_to(value, :controller => 'attachments', :action => 'download', :id => detail.prop_key)
|
||||
else
|
||||
value = content_tag("i", h(value)) if value
|
||||
end
|
||||
@@ -140,7 +120,6 @@ module IssuesHelper
|
||||
|
||||
def issues_to_csv(issues, project = nil)
|
||||
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||
decimal_separator = l(:general_csv_decimal_separator)
|
||||
export = StringIO.new
|
||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
||||
# csv header fields
|
||||
@@ -163,7 +142,7 @@ module IssuesHelper
|
||||
]
|
||||
# Export project custom fields if project is given
|
||||
# otherwise export custom fields marked as "For all projects"
|
||||
custom_fields = project.nil? ? IssueCustomField.for_all : project.all_issue_custom_fields
|
||||
custom_fields = project.nil? ? IssueCustomField.for_all : project.all_custom_fields
|
||||
custom_fields.each {|f| headers << f.name}
|
||||
# Description in the last column
|
||||
headers << l(:field_description)
|
||||
@@ -183,7 +162,7 @@ module IssuesHelper
|
||||
format_date(issue.start_date),
|
||||
format_date(issue.due_date),
|
||||
issue.done_ratio,
|
||||
issue.estimated_hours.to_s.gsub('.', decimal_separator),
|
||||
issue.estimated_hours,
|
||||
format_time(issue.created_on),
|
||||
format_time(issue.updated_on)
|
||||
]
|
||||
|
||||
@@ -19,16 +19,13 @@ module JournalsHelper
|
||||
def render_notes(journal, options={})
|
||||
content = ''
|
||||
editable = journal.editable_by?(User.current)
|
||||
links = []
|
||||
if !journal.notes.blank?
|
||||
links << link_to_remote(image_tag('comment.png'),
|
||||
{ :url => {:controller => 'issues', :action => 'reply', :id => journal.journalized, :journal_id => journal} },
|
||||
:title => l(:button_quote)) if options[:reply_links]
|
||||
if editable && !journal.notes.blank?
|
||||
links = []
|
||||
links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
|
||||
{ :controller => 'journals', :action => 'edit', :id => journal },
|
||||
:title => l(:button_edit)) if editable
|
||||
:title => l(:button_edit))
|
||||
content << content_tag('div', links.join(' '), :class => 'contextual')
|
||||
end
|
||||
content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty?
|
||||
content << textilizable(journal, :notes)
|
||||
content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => (editable ? 'wiki editable' : 'wiki'))
|
||||
end
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module MailHandlerHelper
|
||||
end
|
||||
@@ -21,6 +21,14 @@ module ProjectsHelper
|
||||
link_to h(version.name), { :controller => 'versions', :action => 'show', :id => version }, options
|
||||
end
|
||||
|
||||
def format_activity_day(date)
|
||||
date == Date.today ? l(:label_today).titleize : format_date(date)
|
||||
end
|
||||
|
||||
def format_activity_description(text)
|
||||
h(truncate(text, 250))
|
||||
end
|
||||
|
||||
def project_settings_tabs
|
||||
tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
|
||||
{:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
|
||||
@@ -33,4 +41,154 @@ module ProjectsHelper
|
||||
]
|
||||
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
||||
end
|
||||
|
||||
# Generates a gantt image
|
||||
# Only defined if RMagick is avalaible
|
||||
def gantt_image(events, date_from, months, zoom)
|
||||
date_to = (date_from >> months)-1
|
||||
show_weeks = zoom > 1
|
||||
show_days = zoom > 2
|
||||
|
||||
subject_width = 320
|
||||
header_heigth = 18
|
||||
# width of one day in pixels
|
||||
zoom = zoom*2
|
||||
g_width = (date_to - date_from + 1)*zoom
|
||||
g_height = 20 * events.length + 20
|
||||
headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
|
||||
height = g_height + headers_heigth
|
||||
|
||||
imgl = Magick::ImageList.new
|
||||
imgl.new_image(subject_width+g_width+1, height)
|
||||
gc = Magick::Draw.new
|
||||
|
||||
# Subjects
|
||||
top = headers_heigth + 20
|
||||
gc.fill('black')
|
||||
gc.stroke('transparent')
|
||||
gc.stroke_width(1)
|
||||
events.each do |i|
|
||||
gc.text(4, top + 2, (i.is_a?(Issue) ? i.subject : i.name))
|
||||
top = top + 20
|
||||
end
|
||||
|
||||
# Months headers
|
||||
month_f = date_from
|
||||
left = subject_width
|
||||
months.times do
|
||||
width = ((month_f >> 1) - month_f) * zoom
|
||||
gc.fill('white')
|
||||
gc.stroke('grey')
|
||||
gc.stroke_width(1)
|
||||
gc.rectangle(left, 0, left + width, height)
|
||||
gc.fill('black')
|
||||
gc.stroke('transparent')
|
||||
gc.stroke_width(1)
|
||||
gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
|
||||
left = left + width
|
||||
month_f = month_f >> 1
|
||||
end
|
||||
|
||||
# Weeks headers
|
||||
if show_weeks
|
||||
left = subject_width
|
||||
height = header_heigth
|
||||
if date_from.cwday == 1
|
||||
# date_from is monday
|
||||
week_f = date_from
|
||||
else
|
||||
# find next monday after date_from
|
||||
week_f = date_from + (7 - date_from.cwday + 1)
|
||||
width = (7 - date_from.cwday + 1) * zoom
|
||||
gc.fill('white')
|
||||
gc.stroke('grey')
|
||||
gc.stroke_width(1)
|
||||
gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1)
|
||||
left = left + width
|
||||
end
|
||||
while week_f <= date_to
|
||||
width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
|
||||
gc.fill('white')
|
||||
gc.stroke('grey')
|
||||
gc.stroke_width(1)
|
||||
gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1)
|
||||
gc.fill('black')
|
||||
gc.stroke('transparent')
|
||||
gc.stroke_width(1)
|
||||
gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s)
|
||||
left = left + width
|
||||
week_f = week_f+7
|
||||
end
|
||||
end
|
||||
|
||||
# Days details (week-end in grey)
|
||||
if show_days
|
||||
left = subject_width
|
||||
height = g_height + header_heigth - 1
|
||||
wday = date_from.cwday
|
||||
(date_to - date_from + 1).to_i.times do
|
||||
width = zoom
|
||||
gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
|
||||
gc.stroke('grey')
|
||||
gc.stroke_width(1)
|
||||
gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1)
|
||||
left = left + width
|
||||
wday = wday + 1
|
||||
wday = 1 if wday > 7
|
||||
end
|
||||
end
|
||||
|
||||
# border
|
||||
gc.fill('transparent')
|
||||
gc.stroke('grey')
|
||||
gc.stroke_width(1)
|
||||
gc.rectangle(0, 0, subject_width+g_width, headers_heigth)
|
||||
gc.stroke('black')
|
||||
gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
|
||||
|
||||
# content
|
||||
top = headers_heigth + 20
|
||||
gc.stroke('transparent')
|
||||
events.each do |i|
|
||||
if i.is_a?(Issue)
|
||||
i_start_date = (i.start_date >= date_from ? i.start_date : date_from )
|
||||
i_end_date = (i.due_date <= date_to ? i.due_date : date_to )
|
||||
i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor
|
||||
i_done_date = (i_done_date <= date_from ? date_from : i_done_date )
|
||||
i_done_date = (i_done_date >= date_to ? date_to : i_done_date )
|
||||
i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
|
||||
|
||||
i_left = subject_width + ((i_start_date - date_from)*zoom).floor
|
||||
i_width = ((i_end_date - i_start_date + 1)*zoom).floor # total width of the issue
|
||||
d_width = ((i_done_date - i_start_date)*zoom).floor # done width
|
||||
l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor : 0 # delay width
|
||||
|
||||
gc.fill('grey')
|
||||
gc.rectangle(i_left, top, i_left + i_width, top - 6)
|
||||
gc.fill('red')
|
||||
gc.rectangle(i_left, top, i_left + l_width, top - 6) if l_width > 0
|
||||
gc.fill('blue')
|
||||
gc.rectangle(i_left, top, i_left + d_width, top - 6) if d_width > 0
|
||||
gc.fill('black')
|
||||
gc.text(i_left + i_width + 5,top + 1, "#{i.status.name} #{i.done_ratio}%")
|
||||
else
|
||||
i_left = subject_width + ((i.start_date - date_from)*zoom).floor
|
||||
gc.fill('green')
|
||||
gc.rectangle(i_left, top, i_left + 6, top - 6)
|
||||
gc.fill('black')
|
||||
gc.text(i_left + 11, top + 1, i.name)
|
||||
end
|
||||
top = top + 20
|
||||
end
|
||||
|
||||
# today red line
|
||||
if Date.today >= date_from and Date.today <= date_to
|
||||
gc.stroke('red')
|
||||
x = (Date.today-date_from+1)*zoom + subject_width
|
||||
gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
|
||||
end
|
||||
|
||||
gc.draw(imgl)
|
||||
imgl
|
||||
end if Object.const_defined?(:Magick)
|
||||
end
|
||||
|
||||
@@ -22,8 +22,8 @@ module QueriesHelper
|
||||
end
|
||||
|
||||
def column_header(column)
|
||||
column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
|
||||
:default_order => column.default_order) :
|
||||
column.sortable ? sort_header_tag(column.sortable, :caption => column.caption,
|
||||
:default_order => column.default_order) :
|
||||
content_tag('th', column.caption)
|
||||
end
|
||||
|
||||
@@ -40,18 +40,10 @@ module QueriesHelper
|
||||
else
|
||||
case column.name
|
||||
when :subject
|
||||
h((!@project.nil? && @project != issue.project) ? "#{issue.project.name} - " : '') +
|
||||
h((@project.nil? || @project != issue.project) ? "#{issue.project.name} - " : '') +
|
||||
link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
|
||||
when :project
|
||||
link_to(h(value), :controller => 'projects', :action => 'show', :id => value)
|
||||
when :assigned_to
|
||||
link_to(h(value), :controller => 'account', :action => 'show', :id => value)
|
||||
when :author
|
||||
link_to(h(value), :controller => 'account', :action => 'show', :id => value)
|
||||
when :done_ratio
|
||||
progress_bar(value, :width => '80px')
|
||||
when :fixed_version
|
||||
link_to(h(value), { :controller => 'versions', :action => 'show', :id => issue.fixed_version_id })
|
||||
else
|
||||
h(value)
|
||||
end
|
||||
|
||||
@@ -15,97 +15,20 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'coderay'
|
||||
require 'coderay/helpers/file_type'
|
||||
require 'iconv'
|
||||
|
||||
module RepositoriesHelper
|
||||
def syntax_highlight(name, content)
|
||||
type = CodeRay::FileType[name]
|
||||
type ? CodeRay.scan(content, type).html : h(content)
|
||||
end
|
||||
|
||||
def format_revision(txt)
|
||||
txt.to_s[0,8]
|
||||
end
|
||||
|
||||
def truncate_at_line_break(text, length = 255)
|
||||
if text
|
||||
text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
|
||||
end
|
||||
end
|
||||
|
||||
def render_properties(properties)
|
||||
unless properties.nil? || properties.empty?
|
||||
content = ''
|
||||
properties.keys.sort.each do |property|
|
||||
content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>")
|
||||
end
|
||||
content_tag('ul', content, :class => 'properties')
|
||||
end
|
||||
end
|
||||
|
||||
def render_changeset_changes
|
||||
changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
|
||||
case change.action
|
||||
when 'A'
|
||||
# Detects moved/copied files
|
||||
if !change.from_path.blank?
|
||||
change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
|
||||
end
|
||||
change
|
||||
when 'D'
|
||||
@changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
|
||||
else
|
||||
change
|
||||
end
|
||||
end.compact
|
||||
|
||||
tree = { }
|
||||
changes.each do |change|
|
||||
p = tree
|
||||
dirs = change.path.to_s.split('/').select {|d| !d.blank?}
|
||||
dirs.each do |dir|
|
||||
p[:s] ||= {}
|
||||
p = p[:s]
|
||||
p[dir] ||= {}
|
||||
p = p[dir]
|
||||
end
|
||||
p[:c] = change
|
||||
end
|
||||
|
||||
render_changes_tree(tree[:s])
|
||||
end
|
||||
|
||||
def render_changes_tree(tree)
|
||||
return '' if tree.nil?
|
||||
|
||||
output = ''
|
||||
output << '<ul>'
|
||||
tree.keys.sort.each do |file|
|
||||
s = !tree[file][:s].nil?
|
||||
c = tree[file][:c]
|
||||
|
||||
style = 'change'
|
||||
style << ' folder' if s
|
||||
style << " change-#{c.action}" if c
|
||||
|
||||
text = h(file)
|
||||
unless c.nil?
|
||||
path_param = to_path_param(@repository.relative_path(c.path))
|
||||
text = link_to(text, :controller => 'repositories',
|
||||
:action => 'entry',
|
||||
:id => @project,
|
||||
:path => path_param,
|
||||
:rev => @changeset.revision) unless s || c.action == 'D'
|
||||
text << " - #{c.revision}" unless c.revision.blank?
|
||||
text << ' (' + link_to('diff', :controller => 'repositories',
|
||||
:action => 'diff',
|
||||
:id => @project,
|
||||
:path => path_param,
|
||||
:rev => @changeset.revision) + ') ' if c.action == 'M'
|
||||
text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank?
|
||||
end
|
||||
output << "<li class='#{style}'>#{text}</li>"
|
||||
output << render_changes_tree(tree[file][:s]) if s
|
||||
end
|
||||
output << '</ul>'
|
||||
output
|
||||
end
|
||||
|
||||
def to_utf8(str)
|
||||
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
|
||||
@@ -125,29 +48,23 @@ module RepositoriesHelper
|
||||
end
|
||||
|
||||
def scm_select_tag(repository)
|
||||
scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
|
||||
REDMINE_SUPPORTED_SCM.each do |scm|
|
||||
scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm)
|
||||
end
|
||||
|
||||
container = [[]]
|
||||
REDMINE_SUPPORTED_SCM.each {|scm| container << ["Repository::#{scm}".constantize.scm_name, scm]}
|
||||
select_tag('repository_scm',
|
||||
options_for_select(scm_options, repository.class.name.demodulize),
|
||||
options_for_select(container, repository.class.name.demodulize),
|
||||
:disabled => (repository && !repository.new_record?),
|
||||
:onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
|
||||
)
|
||||
end
|
||||
|
||||
def with_leading_slash(path)
|
||||
path.to_s.starts_with?('/') ? path : "/#{path}"
|
||||
end
|
||||
|
||||
def without_leading_slash(path)
|
||||
path.gsub(%r{^/+}, '')
|
||||
path ||= ''
|
||||
path.starts_with?('/') ? path : "/#{path}"
|
||||
end
|
||||
|
||||
def subversion_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
|
||||
'<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
|
||||
'<br />(http://, https://, svn://, file:///)') +
|
||||
content_tag('p', form.text_field(:login, :size => 30)) +
|
||||
content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
|
||||
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
|
||||
@@ -175,8 +92,4 @@ module RepositoriesHelper
|
||||
def bazaar_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
|
||||
end
|
||||
|
||||
def filesystem_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
module SearchHelper
|
||||
def highlight_tokens(text, tokens)
|
||||
return text unless text && tokens && !tokens.empty?
|
||||
re_tokens = tokens.collect {|t| Regexp.escape(t)}
|
||||
regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE
|
||||
regexp = Regexp.new "(#{tokens.join('|')})", Regexp::IGNORECASE
|
||||
result = ''
|
||||
text.split(regexp).each_with_index do |words, i|
|
||||
if result.length > 1200
|
||||
@@ -36,28 +35,4 @@ module SearchHelper
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def type_label(t)
|
||||
l("label_#{t.singularize}_plural")
|
||||
end
|
||||
|
||||
def project_select_tag
|
||||
options = [[l(:label_project_all), 'all']]
|
||||
options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty?
|
||||
options << [l(:label_and_its_subprojects, @project.name), 'subprojects'] unless @project.nil? || @project.active_children.empty?
|
||||
options << [@project.name, ''] unless @project.nil?
|
||||
select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1
|
||||
end
|
||||
|
||||
def render_results_by_type(results_by_type)
|
||||
links = []
|
||||
# Sorts types by results count
|
||||
results_by_type.keys.sort {|a, b| results_by_type[b] <=> results_by_type[a]}.each do |t|
|
||||
c = results_by_type[t]
|
||||
next if c == 0
|
||||
text = "#{type_label(t)} (#{c})"
|
||||
links << link_to(text, :q => params[:q], :titles_only => params[:title_only], :all_words => params[:all_words], :scope => params[:scope], t => 1)
|
||||
end
|
||||
('<ul>' + links.map {|link| content_tag('li', link)}.join(' ') + '</ul>') unless links.empty?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,10 +19,8 @@ module SettingsHelper
|
||||
def administration_settings_tabs
|
||||
tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
|
||||
{:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
|
||||
{:name => 'projects', :partial => 'settings/projects', :label => :label_project_plural},
|
||||
{:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
|
||||
{:name => 'notifications', :partial => 'settings/notifications', :label => l(:field_mail_notification)},
|
||||
{:name => 'mail_handler', :partial => 'settings/mail_handler', :label => l(:label_incoming_emails)},
|
||||
{:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
|
||||
]
|
||||
end
|
||||
|
||||
@@ -67,31 +67,23 @@ module SortHelper
|
||||
|
||||
# Updates the sort state. Call this in the controller prior to calling
|
||||
# sort_clause.
|
||||
# sort_keys can be either an array or a hash of allowed keys
|
||||
def sort_update(sort_keys)
|
||||
sort_key = params[:sort_key]
|
||||
sort_key = nil unless (sort_keys.is_a?(Array) ? sort_keys.include?(sort_key) : sort_keys[sort_key])
|
||||
|
||||
sort_order = (params[:sort_order] == 'desc' ? 'DESC' : 'ASC')
|
||||
|
||||
if sort_key
|
||||
sort = {:key => sort_key, :order => sort_order}
|
||||
#
|
||||
def sort_update()
|
||||
if params[:sort_key]
|
||||
sort = {:key => params[:sort_key], :order => params[:sort_order]}
|
||||
elsif session[@sort_name]
|
||||
sort = session[@sort_name] # Previous sort.
|
||||
else
|
||||
sort = @sort_default
|
||||
end
|
||||
session[@sort_name] = sort
|
||||
|
||||
sort_column = (sort_keys.is_a?(Hash) ? sort_keys[sort[:key]] : sort[:key])
|
||||
@sort_clause = (sort_column.blank? ? nil : "#{sort_column} #{sort[:order]}")
|
||||
end
|
||||
|
||||
# Returns an SQL sort clause corresponding to the current sort state.
|
||||
# Use this to sort the controller's table items collection.
|
||||
#
|
||||
def sort_clause()
|
||||
@sort_clause
|
||||
session[@sort_name][:key] + ' ' + session[@sort_name][:order]
|
||||
end
|
||||
|
||||
# Returns a link which sorts by the named column.
|
||||
|
||||
@@ -16,30 +16,8 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module TimelogHelper
|
||||
include ApplicationHelper
|
||||
|
||||
def render_timelog_breadcrumb
|
||||
links = []
|
||||
links << link_to(l(:label_project_all), {:project_id => nil, :issue_id => nil})
|
||||
links << link_to(h(@project), {:project_id => @project, :issue_id => nil}) if @project
|
||||
links << link_to_issue(@issue) if @issue
|
||||
breadcrumb links
|
||||
end
|
||||
|
||||
def activity_collection_for_select_options
|
||||
activities = Enumeration::get_values('ACTI')
|
||||
collection = []
|
||||
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default)
|
||||
activities.each { |a| collection << [a.name, a.id] }
|
||||
collection
|
||||
end
|
||||
|
||||
def select_hours(data, criteria, value)
|
||||
if value.to_s.empty?
|
||||
data.select {|row| row[criteria].blank? }
|
||||
else
|
||||
data.select {|row| row[criteria] == value}
|
||||
end
|
||||
data.select {|row| row[criteria] == value}
|
||||
end
|
||||
|
||||
def sum_hours(data)
|
||||
@@ -66,8 +44,6 @@ module TimelogHelper
|
||||
|
||||
def entries_to_csv(entries)
|
||||
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||
decimal_separator = l(:general_csv_decimal_separator)
|
||||
custom_fields = TimeEntryCustomField.find(:all)
|
||||
export = StringIO.new
|
||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
||||
# csv header fields
|
||||
@@ -81,84 +57,23 @@ module TimelogHelper
|
||||
l(:field_hours),
|
||||
l(:field_comments)
|
||||
]
|
||||
# Export custom fields
|
||||
headers += custom_fields.collect(&:name)
|
||||
|
||||
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||
# csv lines
|
||||
entries.each do |entry|
|
||||
fields = [format_date(entry.spent_on),
|
||||
fields = [l_date(entry.spent_on),
|
||||
entry.user,
|
||||
entry.activity,
|
||||
entry.project,
|
||||
(entry.issue ? entry.issue.id : nil),
|
||||
(entry.issue ? entry.issue.tracker : nil),
|
||||
(entry.issue ? entry.issue.subject : nil),
|
||||
entry.hours.to_s.gsub('.', decimal_separator),
|
||||
entry.hours,
|
||||
entry.comments
|
||||
]
|
||||
fields += custom_fields.collect {|f| show_value(entry.custom_value_for(f)) }
|
||||
|
||||
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||
end
|
||||
end
|
||||
export.rewind
|
||||
export
|
||||
end
|
||||
|
||||
def format_criteria_value(criteria, value)
|
||||
value.blank? ? l(:label_none) : ((k = @available_criterias[criteria][:klass]) ? k.find_by_id(value.to_i) : format_value(value, @available_criterias[criteria][:format]))
|
||||
end
|
||||
|
||||
def report_to_csv(criterias, periods, hours)
|
||||
export = StringIO.new
|
||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
||||
# Column headers
|
||||
headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
|
||||
headers += periods
|
||||
headers << l(:label_total)
|
||||
csv << headers.collect {|c| to_utf8(c) }
|
||||
# Content
|
||||
report_criteria_to_csv(csv, criterias, periods, hours)
|
||||
# Total row
|
||||
row = [ l(:label_total) ] + [''] * (criterias.size - 1)
|
||||
total = 0
|
||||
periods.each do |period|
|
||||
sum = sum_hours(select_hours(hours, @columns, period.to_s))
|
||||
total += sum
|
||||
row << (sum > 0 ? "%.2f" % sum : '')
|
||||
end
|
||||
row << "%.2f" %total
|
||||
csv << row
|
||||
end
|
||||
export.rewind
|
||||
export
|
||||
end
|
||||
|
||||
def report_criteria_to_csv(csv, criterias, periods, hours, level=0)
|
||||
hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value|
|
||||
hours_for_value = select_hours(hours, criterias[level], value)
|
||||
next if hours_for_value.empty?
|
||||
row = [''] * level
|
||||
row << to_utf8(format_criteria_value(criterias[level], value))
|
||||
row += [''] * (criterias.length - level - 1)
|
||||
total = 0
|
||||
periods.each do |period|
|
||||
sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s))
|
||||
total += sum
|
||||
row << (sum > 0 ? "%.2f" % sum : '')
|
||||
end
|
||||
row << "%.2f" %total
|
||||
csv << row
|
||||
|
||||
if criterias.length > level + 1
|
||||
report_criteria_to_csv(csv, criterias, periods, hours_for_value, level + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_utf8(s)
|
||||
@ic ||= Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||
begin; @ic.iconv(s.to_s); rescue; s.to_s; end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,43 +16,10 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module UsersHelper
|
||||
def users_status_options_for_select(selected)
|
||||
user_count_by_status = User.count(:group => 'status').to_hash
|
||||
def status_options_for_select(selected)
|
||||
options_for_select([[l(:label_all), ''],
|
||||
["#{l(:status_active)} (#{user_count_by_status[1].to_i})", 1],
|
||||
["#{l(:status_registered)} (#{user_count_by_status[2].to_i})", 2],
|
||||
["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", 3]], selected)
|
||||
end
|
||||
|
||||
# Options for the new membership projects combo-box
|
||||
def projects_options_for_select(projects)
|
||||
options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
|
||||
projects_by_root = projects.group_by(&:root)
|
||||
projects_by_root.keys.sort.each do |root|
|
||||
options << content_tag('option', h(root.name), :value => root.id, :disabled => (!projects.include?(root)))
|
||||
projects_by_root[root].sort.each do |project|
|
||||
next if project == root
|
||||
options << content_tag('option', '» ' + h(project.name), :value => project.id)
|
||||
end
|
||||
end
|
||||
options
|
||||
end
|
||||
|
||||
def change_status_link(user)
|
||||
url = {:action => 'edit', :id => user, :page => params[:page], :status => params[:status]}
|
||||
|
||||
if user.locked?
|
||||
link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
|
||||
elsif user.registered?
|
||||
link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
|
||||
elsif user != User.current
|
||||
link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock'
|
||||
end
|
||||
end
|
||||
|
||||
def user_settings_tabs
|
||||
tabs = [{:name => 'general', :partial => 'users/general', :label => :label_general},
|
||||
{:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural}
|
||||
]
|
||||
[l(:status_active), 1],
|
||||
[l(:status_registered), 2],
|
||||
[l(:status_locked), 3]], selected)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ module WatchersHelper
|
||||
return '' unless user && user.logged? && object.respond_to?('watched_by?')
|
||||
watched = object.watched_by?(user)
|
||||
url = {:controller => 'watchers',
|
||||
:action => (watched ? 'unwatch' : 'watch'),
|
||||
:action => (watched ? 'remove' : 'add'),
|
||||
:object_type => object.class.to_s.underscore,
|
||||
:object_id => object.id}
|
||||
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
|
||||
@@ -33,9 +33,4 @@ module WatchersHelper
|
||||
:class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
|
||||
|
||||
end
|
||||
|
||||
# Returns a comma separated list of users watching the given object
|
||||
def watchers_list(object)
|
||||
object.watcher_users.collect {|u| content_tag('span', link_to_user(u), :class => 'user') }.join(",\n")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module WikiHelper
|
||||
|
||||
|
||||
def html_diff(wdiff)
|
||||
words = wdiff.words.collect{|word| h(word)}
|
||||
words_add = 0
|
||||
@@ -36,7 +36,7 @@ module WikiHelper
|
||||
words_add += 1
|
||||
else
|
||||
del_at = pos unless del_at
|
||||
deleted << ' ' + h(change[2])
|
||||
deleted << ' ' + change[2]
|
||||
words_del += 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module WorkflowsHelper
|
||||
end
|
||||
@@ -26,21 +26,7 @@ class Attachment < ActiveRecord::Base
|
||||
validates_length_of :disk_filename, :maximum => 255
|
||||
|
||||
acts_as_event :title => :filename,
|
||||
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}
|
||||
|
||||
acts_as_activity_provider :type => 'files',
|
||||
:permission => :view_files,
|
||||
:author_key => :author_id,
|
||||
: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',
|
||||
:permission => :view_documents,
|
||||
:author_key => :author_id,
|
||||
:find_options => {:select => "#{Attachment.table_name}.*",
|
||||
:joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
|
||||
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}
|
||||
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id}}
|
||||
|
||||
cattr_accessor :storage_path
|
||||
@@storage_path = "#{RAILS_ROOT}/files"
|
||||
@@ -49,52 +35,48 @@ class Attachment < ActiveRecord::Base
|
||||
errors.add_to_base :too_long if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
||||
end
|
||||
|
||||
def file=(incoming_file)
|
||||
unless incoming_file.nil?
|
||||
@temp_file = incoming_file
|
||||
if @temp_file.size > 0
|
||||
self.filename = sanitize_filename(@temp_file.original_filename)
|
||||
self.disk_filename = Attachment.disk_filename(filename)
|
||||
self.content_type = @temp_file.content_type.to_s.chomp
|
||||
self.filesize = @temp_file.size
|
||||
end
|
||||
end
|
||||
end
|
||||
def file=(incomming_file)
|
||||
unless incomming_file.nil?
|
||||
@temp_file = incomming_file
|
||||
if @temp_file.size > 0
|
||||
self.filename = sanitize_filename(@temp_file.original_filename)
|
||||
self.disk_filename = DateTime.now.strftime("%y%m%d%H%M%S") + "_" + self.filename
|
||||
self.content_type = @temp_file.content_type.to_s.chomp
|
||||
self.filesize = @temp_file.size
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def file
|
||||
nil
|
||||
end
|
||||
|
||||
# Copies the temporary file to its final location
|
||||
# and computes its MD5 hash
|
||||
def before_save
|
||||
if @temp_file && (@temp_file.size > 0)
|
||||
logger.debug("saving '#{self.diskfile}'")
|
||||
md5 = Digest::MD5.new
|
||||
File.open(diskfile, "wb") do |f|
|
||||
buffer = ""
|
||||
while (buffer = @temp_file.read(8192))
|
||||
f.write(buffer)
|
||||
md5.update(buffer)
|
||||
end
|
||||
end
|
||||
self.digest = md5.hexdigest
|
||||
end
|
||||
# Don't save the content type if it's longer than the authorized length
|
||||
if self.content_type && self.content_type.length > 255
|
||||
self.content_type = nil
|
||||
end
|
||||
end
|
||||
|
||||
# Deletes file on the disk
|
||||
def after_destroy
|
||||
File.delete(diskfile) if !filename.blank? && File.exist?(diskfile)
|
||||
end
|
||||
|
||||
# Returns file's location on disk
|
||||
def diskfile
|
||||
"#{@@storage_path}/#{self.disk_filename}"
|
||||
end
|
||||
def file
|
||||
nil
|
||||
end
|
||||
|
||||
# Copy temp file to its final location
|
||||
def before_save
|
||||
if @temp_file && (@temp_file.size > 0)
|
||||
logger.debug("saving '#{self.diskfile}'")
|
||||
File.open(diskfile, "wb") do |f|
|
||||
f.write(@temp_file.read)
|
||||
end
|
||||
self.digest = Digest::MD5.hexdigest(File.read(diskfile))
|
||||
end
|
||||
# Don't save the content type if it's longer than the authorized length
|
||||
if self.content_type && self.content_type.length > 255
|
||||
self.content_type = nil
|
||||
end
|
||||
end
|
||||
|
||||
# Deletes file on the disk
|
||||
def after_destroy
|
||||
if self.filename?
|
||||
File.delete(diskfile) if File.exist?(diskfile)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns file's location on disk
|
||||
def diskfile
|
||||
"#{@@storage_path}/#{self.disk_filename}"
|
||||
end
|
||||
|
||||
def increment_download
|
||||
increment!(:downloads)
|
||||
@@ -104,47 +86,19 @@ class Attachment < ActiveRecord::Base
|
||||
container.project
|
||||
end
|
||||
|
||||
def visible?(user=User.current)
|
||||
container.attachments_visible?(user)
|
||||
end
|
||||
|
||||
def deletable?(user=User.current)
|
||||
container.attachments_deletable?(user)
|
||||
end
|
||||
|
||||
def image?
|
||||
self.filename =~ /\.(jpe?g|gif|png)$/i
|
||||
end
|
||||
|
||||
def is_text?
|
||||
Redmine::MimeType.is_type?('text', filename)
|
||||
end
|
||||
|
||||
def is_diff?
|
||||
self.filename =~ /\.(patch|diff)$/i
|
||||
self.filename =~ /\.(jpeg|jpg|gif|png)$/i
|
||||
end
|
||||
|
||||
private
|
||||
def sanitize_filename(value)
|
||||
# get only the filename, not the whole path
|
||||
just_filename = value.gsub(/^.*(\\|\/)/, '')
|
||||
# NOTE: File.basename doesn't work right with Windows paths on Unix
|
||||
# INCORRECT: just_filename = File.basename(value.gsub('\\\\', '/'))
|
||||
# get only the filename, not the whole path
|
||||
just_filename = value.gsub(/^.*(\\|\/)/, '')
|
||||
# NOTE: File.basename doesn't work right with Windows paths on Unix
|
||||
# INCORRECT: just_filename = File.basename(value.gsub('\\\\', '/'))
|
||||
|
||||
# Finally, replace all non alphanumeric, hyphens or periods with underscore
|
||||
@filename = just_filename.gsub(/[^\w\.\-]/,'_')
|
||||
end
|
||||
|
||||
# Returns an ASCII or hashed filename
|
||||
def self.disk_filename(filename)
|
||||
df = DateTime.now.strftime("%y%m%d%H%M%S") + "_"
|
||||
if filename =~ %r{^[a-zA-Z0-9_\.\-]*$}
|
||||
df << filename
|
||||
else
|
||||
df << Digest::MD5.hexdigest(filename)
|
||||
# keep the extension if any
|
||||
df << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
|
||||
end
|
||||
df
|
||||
# Finally, replace all non alphanumeric, underscore or periods with underscore
|
||||
@filename = just_filename.gsub(/[^\w\.\-]/,'_')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -20,7 +20,10 @@ class AuthSource < ActiveRecord::Base
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name
|
||||
validates_length_of :name, :maximum => 60
|
||||
validates_length_of :name, :host, :maximum => 60
|
||||
validates_length_of :account_password, :maximum => 60, :allow_nil => true
|
||||
validates_length_of :account, :base_dn, :maximum => 255
|
||||
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30
|
||||
|
||||
def authenticate(login, password)
|
||||
end
|
||||
@@ -38,8 +41,7 @@ class AuthSource < ActiveRecord::Base
|
||||
begin
|
||||
logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug?
|
||||
attrs = source.authenticate(login, password)
|
||||
rescue => e
|
||||
logger.error "Error during authentication: #{e.message}"
|
||||
rescue
|
||||
attrs = nil
|
||||
end
|
||||
return attrs if attrs
|
||||
|
||||
@@ -20,12 +20,7 @@ require 'iconv'
|
||||
|
||||
class AuthSourceLdap < AuthSource
|
||||
validates_presence_of :host, :port, :attr_login
|
||||
validates_length_of :name, :host, :account_password, :maximum => 60, :allow_nil => true
|
||||
validates_length_of :account, :base_dn, :maximum => 255, :allow_nil => true
|
||||
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
|
||||
validates_numericality_of :port, :only_integer => true
|
||||
|
||||
before_validation :strip_ldap_attributes
|
||||
validates_presence_of :attr_firstname, :attr_lastname, :attr_mail, :if => Proc.new { |a| a.onthefly_register? }
|
||||
|
||||
def after_initialize
|
||||
self.port = 389 if self.port == 0
|
||||
@@ -73,14 +68,7 @@ class AuthSourceLdap < AuthSource
|
||||
"LDAP"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def strip_ldap_attributes
|
||||
[:attr_login, :attr_firstname, :attr_lastname, :attr_mail].each do |attr|
|
||||
write_attribute(attr, read_attribute(attr).strip) unless read_attribute(attr).nil?
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def initialize_ldap_con(ldap_user, ldap_password)
|
||||
options = { :host => self.host,
|
||||
:port => self.port,
|
||||
@@ -91,8 +79,6 @@ class AuthSourceLdap < AuthSource
|
||||
end
|
||||
|
||||
def self.get_attr(entry, attr_name)
|
||||
if !attr_name.blank?
|
||||
entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name]
|
||||
end
|
||||
entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,8 +19,4 @@ class Change < ActiveRecord::Base
|
||||
belongs_to :changeset
|
||||
|
||||
validates_presence_of :changeset_id, :action, :path
|
||||
|
||||
def relative_path
|
||||
changeset.repository.relative_path(path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -15,38 +15,28 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'iconv'
|
||||
|
||||
class Changeset < ActiveRecord::Base
|
||||
belongs_to :repository
|
||||
belongs_to :user
|
||||
has_many :changes, :dependent => :delete_all
|
||||
has_and_belongs_to_many :issues
|
||||
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.comments.blank? ? '' : (': ' + o.comments))},
|
||||
:description => :comments,
|
||||
:datetime => :committed_on,
|
||||
:author => :committer,
|
||||
:url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project_id, :rev => o.revision}}
|
||||
|
||||
acts_as_searchable :columns => 'comments',
|
||||
:include => {:repository => :project},
|
||||
:include => :repository,
|
||||
:project_key => "#{Repository.table_name}.project_id",
|
||||
:date_column => 'committed_on'
|
||||
|
||||
acts_as_activity_provider :timestamp => "#{table_name}.committed_on",
|
||||
:author_key => :user_id,
|
||||
:find_options => {:include => {:repository => :project}}
|
||||
|
||||
validates_presence_of :repository_id, :revision, :committed_on, :commit_date
|
||||
validates_uniqueness_of :revision, :scope => :repository_id
|
||||
validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
|
||||
|
||||
def revision=(r)
|
||||
write_attribute :revision, (r.nil? ? nil : r.to_s)
|
||||
end
|
||||
|
||||
def comments=(comment)
|
||||
write_attribute(:comments, Changeset.normalize_comments(comment))
|
||||
write_attribute(:comments, comment.strip)
|
||||
end
|
||||
|
||||
def committed_on=(date)
|
||||
@@ -58,14 +48,6 @@ class Changeset < ActiveRecord::Base
|
||||
repository.project
|
||||
end
|
||||
|
||||
def author
|
||||
user || committer.to_s.split('<').first
|
||||
end
|
||||
|
||||
def before_create
|
||||
self.user = repository.find_committer_user(committer)
|
||||
end
|
||||
|
||||
def after_create
|
||||
scan_comment_for_issue_ids
|
||||
end
|
||||
@@ -89,7 +71,7 @@ class Changeset < ActiveRecord::Base
|
||||
if ref_keywords.delete('*')
|
||||
# find any issue ID in the comments
|
||||
target_issue_ids = []
|
||||
comments.scan(%r{([\s\(,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] }
|
||||
comments.scan(%r{([\s\(,-^])#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] }
|
||||
referenced_issues += repository.project.issues.find_all_by_id(target_issue_ids)
|
||||
end
|
||||
|
||||
@@ -105,15 +87,14 @@ class Changeset < ActiveRecord::Base
|
||||
issue.reload
|
||||
# don't change the status is the issue is closed
|
||||
next if issue.status.is_closed?
|
||||
user = committer_user || User.anonymous
|
||||
csettext = "r#{self.revision}"
|
||||
if self.scmid && (! (csettext =~ /^r[0-9]+$/))
|
||||
csettext = "commit:\"#{self.scmid}\""
|
||||
end
|
||||
journal = issue.init_journal(user || User.anonymous, l(:text_status_changed_by_changeset, csettext))
|
||||
journal = issue.init_journal(user, l(:text_status_changed_by_changeset, csettext))
|
||||
issue.status = fix_status
|
||||
issue.done_ratio = done_ratio if done_ratio
|
||||
Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,
|
||||
{ :changeset => self, :issue => issue })
|
||||
issue.save
|
||||
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
||||
end
|
||||
@@ -123,6 +104,16 @@ class Changeset < ActiveRecord::Base
|
||||
|
||||
self.issues = referenced_issues.uniq
|
||||
end
|
||||
|
||||
# Returns the Redmine User corresponding to the committer
|
||||
def committer_user
|
||||
if committer && committer.strip =~ /^([^<]+)(<(.*)>)?$/
|
||||
username, email = $1.strip, $3
|
||||
u = User.find_by_login(username)
|
||||
u ||= User.find_by_mail(email) unless email.blank?
|
||||
u
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the previous changeset
|
||||
def previous
|
||||
@@ -133,25 +124,4 @@ class Changeset < ActiveRecord::Base
|
||||
def next
|
||||
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
|
||||
end
|
||||
|
||||
# Strips and reencodes a commit log before insertion into the database
|
||||
def self.normalize_comments(str)
|
||||
to_utf8(str.to_s.strip)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def self.to_utf8(str)
|
||||
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||
encoding = Setting.commit_logs_encoding.to_s.strip
|
||||
unless encoding.blank? || encoding == 'UTF-8'
|
||||
begin
|
||||
return Iconv.conv('UTF-8', encoding, str)
|
||||
rescue Iconv::Failure
|
||||
# do nothing here
|
||||
end
|
||||
end
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,9 +30,9 @@ class CustomField < ActiveRecord::Base
|
||||
}.freeze
|
||||
|
||||
validates_presence_of :name, :field_format
|
||||
validates_uniqueness_of :name, :scope => :type
|
||||
validates_uniqueness_of :name
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_format_of :name, :with => /^[\w\s\.\'\-]*$/i
|
||||
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
||||
validates_inclusion_of :field_format, :in => FIELD_FORMATS.keys
|
||||
|
||||
def initialize(attributes = nil)
|
||||
@@ -66,7 +66,7 @@ class CustomField < ActiveRecord::Base
|
||||
|
||||
# to move in project_custom_field
|
||||
def self.for_all
|
||||
find(:all, :conditions => ["is_for_all=?", true], :order => 'position')
|
||||
find(:all, :conditions => ["is_for_all=?", true])
|
||||
end
|
||||
|
||||
def type_name
|
||||
|
||||
@@ -25,11 +25,6 @@ class CustomValue < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
# Returns true if the boolean custom value is true
|
||||
def true?
|
||||
self.value == '1'
|
||||
end
|
||||
|
||||
protected
|
||||
def validate
|
||||
if value.blank?
|
||||
|
||||
@@ -18,20 +18,13 @@
|
||||
class Document < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
belongs_to :category, :class_name => "Enumeration", :foreign_key => "category_id"
|
||||
acts_as_attachable :delete_permission => :manage_documents
|
||||
has_many :attachments, :as => :container, :dependent => :destroy
|
||||
|
||||
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
||||
acts_as_searchable :columns => ['title', 'description']
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
|
||||
:author => Proc.new {|o| (a = o.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC")) ? a.author : nil },
|
||||
:url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
|
||||
acts_as_activity_provider :find_options => {:include => :project}
|
||||
|
||||
|
||||
validates_presence_of :project, :title, :category
|
||||
validates_length_of :title, :maximum => 60
|
||||
|
||||
def after_initialize
|
||||
if new_record?
|
||||
self.category ||= Enumeration.default('DCAT')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,12 +23,12 @@ class Enumeration < ActiveRecord::Base
|
||||
validates_presence_of :opt, :name
|
||||
validates_uniqueness_of :name, :scope => [:opt]
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
||||
|
||||
# Single table inheritance would be an option
|
||||
OPTIONS = {
|
||||
"IPRI" => {:label => :enumeration_issue_priorities, :model => Issue, :foreign_key => :priority_id},
|
||||
"DCAT" => {:label => :enumeration_doc_categories, :model => Document, :foreign_key => :category_id},
|
||||
"ACTI" => {:label => :enumeration_activities, :model => TimeEntry, :foreign_key => :activity_id}
|
||||
"IPRI" => :enumeration_issue_priorities,
|
||||
"DCAT" => :enumeration_doc_categories,
|
||||
"ACTI" => :enumeration_activities
|
||||
}.freeze
|
||||
|
||||
def self.get_values(option)
|
||||
@@ -40,32 +40,11 @@ class Enumeration < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def option_name
|
||||
OPTIONS[self.opt][:label]
|
||||
OPTIONS[self.opt]
|
||||
end
|
||||
|
||||
def before_save
|
||||
if is_default? && is_default_changed?
|
||||
Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt})
|
||||
end
|
||||
end
|
||||
|
||||
def objects_count
|
||||
OPTIONS[self.opt][:model].count(:conditions => "#{OPTIONS[self.opt][:foreign_key]} = #{id}")
|
||||
end
|
||||
|
||||
def in_use?
|
||||
self.objects_count != 0
|
||||
end
|
||||
|
||||
alias :destroy_without_reassign :destroy
|
||||
|
||||
# Destroy the enumeration
|
||||
# If a enumeration is specified, objects are reassigned
|
||||
def destroy(reassign_to = nil)
|
||||
if reassign_to && reassign_to.is_a?(Enumeration)
|
||||
OPTIONS[self.opt][:model].update_all("#{OPTIONS[self.opt][:foreign_key]} = #{reassign_to.id}", "#{OPTIONS[self.opt][:foreign_key]} = #{id}")
|
||||
end
|
||||
destroy_without_reassign
|
||||
Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) if is_default?
|
||||
end
|
||||
|
||||
def <=>(enumeration)
|
||||
@@ -76,6 +55,13 @@ class Enumeration < ActiveRecord::Base
|
||||
|
||||
private
|
||||
def check_integrity
|
||||
raise "Can't delete enumeration" if self.in_use?
|
||||
case self.opt
|
||||
when "IPRI"
|
||||
raise "Can't delete enumeration" if Issue.find(:first, :conditions => ["priority_id=?", self.id])
|
||||
when "DCAT"
|
||||
raise "Can't delete enumeration" if Document.find(:first, :conditions => ["category_id=?", self.id])
|
||||
when "ACTI"
|
||||
raise "Can't delete enumeration" if TimeEntry.find(:first, :conditions => ["activity_id=?", self.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,29 +26,25 @@ class Issue < ActiveRecord::Base
|
||||
belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
|
||||
|
||||
has_many :journals, :as => :journalized, :dependent => :destroy
|
||||
has_many :attachments, :as => :container, :dependent => :destroy
|
||||
has_many :time_entries, :dependent => :delete_all
|
||||
has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC"
|
||||
has_many :custom_values, :dependent => :delete_all, :as => :customized
|
||||
has_many :custom_fields, :through => :custom_values
|
||||
has_and_belongs_to_many :changesets, :order => "revision ASC"
|
||||
|
||||
has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
|
||||
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
|
||||
|
||||
acts_as_attachable :after_remove => :attachment_removed
|
||||
acts_as_customizable
|
||||
acts_as_watchable
|
||||
acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
|
||||
:include => [:project, :journals],
|
||||
# sort by id so that limited eager loading doesn't break with postgresql
|
||||
:order_column => "#{table_name}.id"
|
||||
acts_as_searchable :columns => ['subject', 'description'], :with => {:journal => :issue}
|
||||
acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"},
|
||||
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}
|
||||
|
||||
acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
|
||||
:author_key => :author_id
|
||||
|
||||
validates_presence_of :subject, :priority, :project, :tracker, :author, :status
|
||||
validates_presence_of :subject, :description, :priority, :project, :tracker, :author, :status
|
||||
validates_length_of :subject, :maximum => 255
|
||||
validates_inclusion_of :done_ratio, :in => 0..100
|
||||
validates_numericality_of :estimated_hours, :allow_nil => true
|
||||
validates_associated :custom_values, :on => :update
|
||||
|
||||
def after_initialize
|
||||
if new_record?
|
||||
@@ -58,11 +54,6 @@ class Issue < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
|
||||
def available_custom_fields
|
||||
(project && tracker) ? project.all_issue_custom_fields.select {|c| tracker.custom_fields.include? c } : []
|
||||
end
|
||||
|
||||
def copy_from(arg)
|
||||
issue = arg.is_a?(Issue) ? arg : Issue.find(arg)
|
||||
self.attributes = issue.attributes.dup
|
||||
@@ -80,9 +71,7 @@ class Issue < ActiveRecord::Base
|
||||
self.relations_to.clear
|
||||
end
|
||||
# issue is moved to another project
|
||||
# reassign to the category with same name if any
|
||||
new_category = category.nil? ? nil : new_project.issue_categories.find_by_name(category.name)
|
||||
self.category = new_category
|
||||
self.category = nil
|
||||
self.fixed_version = nil
|
||||
self.project = new_project
|
||||
end
|
||||
@@ -104,11 +93,7 @@ class Issue < ActiveRecord::Base
|
||||
self.priority = nil
|
||||
write_attribute(:priority_id, pid)
|
||||
end
|
||||
|
||||
def estimated_hours=(h)
|
||||
write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
|
||||
end
|
||||
|
||||
|
||||
def validate
|
||||
if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
|
||||
errors.add :due_date, :activerecord_error_not_a_date
|
||||
@@ -168,8 +153,6 @@ class Issue < ActiveRecord::Base
|
||||
# Close duplicates if the issue was closed
|
||||
if @issue_before_change && !@issue_before_change.closed? && self.closed?
|
||||
duplicates.each do |duplicate|
|
||||
# Reload is need in case the duplicate was updated by a previous duplicate
|
||||
duplicate.reload
|
||||
# Don't re-close it if it's already closed
|
||||
next if duplicate.closed?
|
||||
# Same user and notes
|
||||
@@ -179,14 +162,17 @@ class Issue < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def custom_value_for(custom_field)
|
||||
self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id }
|
||||
return nil
|
||||
end
|
||||
|
||||
def init_journal(user, notes = "")
|
||||
@current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
|
||||
@issue_before_change = self.clone
|
||||
@issue_before_change.status = self.status
|
||||
@custom_values_before_change = {}
|
||||
self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
|
||||
# Make sure updated_on is updated when adding a note.
|
||||
updated_on_will_change!
|
||||
@current_journal
|
||||
end
|
||||
|
||||
@@ -195,11 +181,6 @@ class Issue < ActiveRecord::Base
|
||||
self.status.is_closed?
|
||||
end
|
||||
|
||||
# Returns true if the issue is overdue
|
||||
def overdue?
|
||||
!due_date.nil? && (due_date < Date.today)
|
||||
end
|
||||
|
||||
# Users the issue can be assigned to
|
||||
def assignable_users
|
||||
project.assignable_users
|
||||
@@ -238,15 +219,9 @@ class Issue < ActiveRecord::Base
|
||||
dependencies
|
||||
end
|
||||
|
||||
# Returns an array of issues that duplicate this one
|
||||
# Returns an array of the duplicate issues
|
||||
def duplicates
|
||||
relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from}
|
||||
end
|
||||
|
||||
# Returns the due date or the target due date if any
|
||||
# Used on gantt chart
|
||||
def due_before
|
||||
due_date || (fixed_version ? fixed_version.effective_date : nil)
|
||||
relations.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.other_issue(self)}
|
||||
end
|
||||
|
||||
def duration
|
||||
@@ -262,19 +237,4 @@ class Issue < ActiveRecord::Base
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{tracker} ##{id}: #{subject}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Callback on attachment deletion
|
||||
def attachment_removed(obj)
|
||||
journal = init_journal(User.current)
|
||||
journal.details << JournalDetail.new(:property => 'attachment',
|
||||
:prop_key => obj.id,
|
||||
:old_value => obj.filename)
|
||||
journal.save
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ class IssueRelation < ActiveRecord::Base
|
||||
TYPE_PRECEDES = "precedes"
|
||||
|
||||
TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 },
|
||||
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 },
|
||||
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicates, :order => 2 },
|
||||
TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 },
|
||||
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 },
|
||||
}.freeze
|
||||
|
||||
@@ -25,8 +25,8 @@ class IssueStatus < ActiveRecord::Base
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
||||
|
||||
def after_save
|
||||
IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
|
||||
def before_save
|
||||
IssueStatus.update_all "is_default=#{connection.quoted_false}" if self.is_default?
|
||||
end
|
||||
|
||||
# Returns the default status for new issues
|
||||
|
||||
@@ -25,20 +25,17 @@ class Journal < ActiveRecord::Base
|
||||
has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
|
||||
attr_accessor :indice
|
||||
|
||||
acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
|
||||
acts_as_searchable :columns => 'notes',
|
||||
:include => :issue,
|
||||
:project_key => "#{Issue.table_name}.project_id",
|
||||
:date_column => "#{Issue.table_name}.created_on"
|
||||
|
||||
acts_as_event :title => Proc.new {|o| "#{o.issue.tracker.name} ##{o.issue.id}: #{o.issue.subject}" + ((s = o.new_status) ? " (#{s})" : '') },
|
||||
:description => :notes,
|
||||
:author => :user,
|
||||
:type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
|
||||
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
|
||||
|
||||
acts_as_activity_provider :type => 'issues',
|
||||
:permission => :view_issues,
|
||||
:author_key => :user_id,
|
||||
:find_options => {:include => [{:issue => :project}, :details, :user],
|
||||
:conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
||||
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
|
||||
|
||||
def save(*args)
|
||||
def save
|
||||
# Do not save an empty journal
|
||||
(details.empty? && notes.blank?) ? false : super
|
||||
end
|
||||
|
||||
@@ -16,185 +16,25 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MailHandler < ActionMailer::Base
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
|
||||
class UnauthorizedAction < StandardError; end
|
||||
class MissingInformation < StandardError; end
|
||||
|
||||
attr_reader :email, :user
|
||||
|
||||
def self.receive(email, options={})
|
||||
@@handler_options = options.dup
|
||||
|
||||
@@handler_options[:issue] ||= {}
|
||||
|
||||
@@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip) if @@handler_options[:allow_override].is_a?(String)
|
||||
@@handler_options[:allow_override] ||= []
|
||||
# Project needs to be overridable if not specified
|
||||
@@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project)
|
||||
# Status overridable by default
|
||||
@@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status)
|
||||
super email
|
||||
end
|
||||
|
||||
# Processes incoming emails
|
||||
# Currently, it only supports adding a note to an existing issue
|
||||
# by replying to the initial notification message
|
||||
def receive(email)
|
||||
@email = email
|
||||
@user = User.active.find(:first, :conditions => ["LOWER(mail) = ?", email.from.to_a.first.to_s.strip.downcase])
|
||||
unless @user
|
||||
# Unknown user => the email is ignored
|
||||
# TODO: ability to create the user's account
|
||||
logger.info "MailHandler: email submitted by unknown user [#{email.from.first}]" if logger && logger.info
|
||||
return false
|
||||
end
|
||||
User.current = @user
|
||||
dispatch
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]}
|
||||
|
||||
def dispatch
|
||||
if m = email.subject.match(ISSUE_REPLY_SUBJECT_RE)
|
||||
receive_issue_update(m[1].to_i)
|
||||
else
|
||||
receive_issue
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
# TODO: send a email to the user
|
||||
logger.error e.message if logger
|
||||
false
|
||||
rescue MissingInformation => e
|
||||
logger.error "MailHandler: missing information from #{user}: #{e.message}" if logger
|
||||
false
|
||||
rescue UnauthorizedAction => e
|
||||
logger.error "MailHandler: unauthorized attempt from #{user}" if logger
|
||||
false
|
||||
end
|
||||
|
||||
# Creates a new issue
|
||||
def receive_issue
|
||||
project = target_project
|
||||
tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker))) || project.trackers.find(:first)
|
||||
category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
|
||||
priority = (get_keyword(:priority) && Enumeration.find_by_opt_and_name('IPRI', get_keyword(:priority)))
|
||||
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
|
||||
|
||||
# check permission
|
||||
raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
|
||||
issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority)
|
||||
# check workflow
|
||||
if status && issue.new_statuses_allowed_to(user).include?(status)
|
||||
issue.status = status
|
||||
end
|
||||
issue.subject = email.subject.chomp.toutf8
|
||||
issue.description = plain_text_body
|
||||
# custom fields
|
||||
issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c|
|
||||
if value = get_keyword(c.name, :override => true)
|
||||
h[c.id] = value
|
||||
end
|
||||
h
|
||||
end
|
||||
issue.save!
|
||||
add_attachments(issue)
|
||||
logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
|
||||
# add To and Cc as watchers
|
||||
add_watchers(issue)
|
||||
# send notification after adding watchers so that they can reply to Redmine
|
||||
Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added')
|
||||
issue
|
||||
end
|
||||
|
||||
def target_project
|
||||
# TODO: other ways to specify project:
|
||||
# * parse the email To field
|
||||
# * specific project (eg. Setting.mail_handler_target_project)
|
||||
target = Project.find_by_identifier(get_keyword(:project))
|
||||
raise MissingInformation.new('Unable to determine target project') if target.nil?
|
||||
target
|
||||
end
|
||||
|
||||
# Adds a note to an existing issue
|
||||
def receive_issue_update(issue_id)
|
||||
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
|
||||
|
||||
issue = Issue.find_by_id(issue_id)
|
||||
# find related issue by parsing the subject
|
||||
m = email.subject.match %r{\[.*#(\d+)\]}
|
||||
return unless m
|
||||
issue = Issue.find_by_id(m[1])
|
||||
return unless issue
|
||||
|
||||
# find user
|
||||
user = User.find_active(:first, :conditions => {:mail => email.from.first})
|
||||
return unless user
|
||||
# check permission
|
||||
raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project)
|
||||
raise UnauthorizedAction unless status.nil? || user.allowed_to?(:edit_issues, issue.project)
|
||||
|
||||
return unless user.allowed_to?(:add_issue_notes, issue.project)
|
||||
|
||||
# add the note
|
||||
journal = issue.init_journal(user, plain_text_body)
|
||||
add_attachments(issue)
|
||||
# check workflow
|
||||
if status && issue.new_statuses_allowed_to(user).include?(status)
|
||||
issue.status = status
|
||||
end
|
||||
issue.save!
|
||||
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
|
||||
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
||||
journal
|
||||
end
|
||||
|
||||
def add_attachments(obj)
|
||||
if email.has_attachments?
|
||||
email.attachments.each do |attachment|
|
||||
Attachment.create(:container => obj,
|
||||
:file => attachment,
|
||||
:author => user,
|
||||
:content_type => attachment.content_type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Adds To and Cc as watchers of the given object if the sender has the
|
||||
# appropriate permission
|
||||
def add_watchers(obj)
|
||||
if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
|
||||
addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
|
||||
unless addresses.empty?
|
||||
watchers = User.active.find(:all, :conditions => ['LOWER(mail) IN (?)', addresses])
|
||||
watchers.each {|w| obj.add_watcher(w)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_keyword(attr, options={})
|
||||
@keywords ||= {}
|
||||
if @keywords.has_key?(attr)
|
||||
@keywords[attr]
|
||||
else
|
||||
@keywords[attr] = begin
|
||||
if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body.gsub!(/^#{attr}[ \t]*:[ \t]*(.+)\s*$/i, '')
|
||||
$1.strip
|
||||
elsif !@@handler_options[:issue][attr].blank?
|
||||
@@handler_options[:issue][attr]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the text/plain part of the email
|
||||
# If not found (eg. HTML-only email), returns the body with tags removed
|
||||
def plain_text_body
|
||||
return @plain_text_body unless @plain_text_body.nil?
|
||||
parts = @email.parts.collect {|c| (c.respond_to?(:parts) && !c.parts.empty?) ? c.parts : c}.flatten
|
||||
if parts.empty?
|
||||
parts << @email
|
||||
end
|
||||
plain_text_part = parts.detect {|p| p.content_type == 'text/plain'}
|
||||
if plain_text_part.nil?
|
||||
# no text/plain part found, assuming html-only email
|
||||
# strip html tags and remove doctype directive
|
||||
@plain_text_body = strip_tags(@email.body.to_s)
|
||||
@plain_text_body.gsub! %r{^<!DOCTYPE .*$}, ''
|
||||
else
|
||||
@plain_text_body = plain_text_part.body.to_s
|
||||
end
|
||||
@plain_text_body.strip!
|
||||
@plain_text_body
|
||||
issue.init_journal(user, email.body.chomp)
|
||||
issue.save
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
@@ -19,22 +19,15 @@ class Mailer < ActionMailer::Base
|
||||
helper :application
|
||||
helper :issues
|
||||
helper :custom_fields
|
||||
|
||||
include ActionController::UrlWriter
|
||||
|
||||
def self.default_url_options
|
||||
h = Setting.host_name
|
||||
h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
|
||||
{ :host => h, :protocol => Setting.protocol }
|
||||
end
|
||||
|
||||
def issue_add(issue)
|
||||
include ActionController::UrlWriter
|
||||
|
||||
def issue_add(issue)
|
||||
redmine_headers 'Project' => issue.project.identifier,
|
||||
'Issue-Id' => issue.id,
|
||||
'Issue-Author' => issue.author.login
|
||||
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
||||
recipients issue.recipients
|
||||
cc(issue.watcher_recipients - @recipients)
|
||||
recipients issue.recipients
|
||||
subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
|
||||
body :issue => issue,
|
||||
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
|
||||
@@ -46,7 +39,6 @@ class Mailer < ActionMailer::Base
|
||||
'Issue-Id' => issue.id,
|
||||
'Issue-Author' => issue.author.login
|
||||
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
||||
@author = journal.user
|
||||
recipients issue.recipients
|
||||
# Watchers in cc
|
||||
cc(issue.watcher_recipients - @recipients)
|
||||
@@ -58,16 +50,7 @@ class Mailer < ActionMailer::Base
|
||||
:journal => journal,
|
||||
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
|
||||
end
|
||||
|
||||
def reminder(user, issues, days)
|
||||
set_language_if_valid user.language
|
||||
recipients user.mail
|
||||
subject l(:mail_subject_reminder, issues.size)
|
||||
body :issues => issues,
|
||||
:days => days,
|
||||
:issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc')
|
||||
end
|
||||
|
||||
|
||||
def document_added(document)
|
||||
redmine_headers 'Project' => document.project.identifier
|
||||
recipients document.project.recipients
|
||||
@@ -75,15 +58,12 @@ class Mailer < ActionMailer::Base
|
||||
body :document => document,
|
||||
:document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
|
||||
end
|
||||
|
||||
|
||||
def attachments_added(attachments)
|
||||
container = attachments.first.container
|
||||
added_to = ''
|
||||
added_to_url = ''
|
||||
case container.class.name
|
||||
when 'Project'
|
||||
added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container)
|
||||
added_to = "#{l(:label_project)}: #{container}"
|
||||
when 'Version'
|
||||
added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
|
||||
added_to = "#{l(:label_version)}: #{container.name}"
|
||||
@@ -115,7 +95,7 @@ class Mailer < ActionMailer::Base
|
||||
body :message => message,
|
||||
:message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
|
||||
end
|
||||
|
||||
|
||||
def account_information(user, password)
|
||||
set_language_if_valid user.language
|
||||
recipients user.mail
|
||||
@@ -124,31 +104,22 @@ class Mailer < ActionMailer::Base
|
||||
:password => password,
|
||||
:login_url => url_for(:controller => 'account', :action => 'login')
|
||||
end
|
||||
|
||||
|
||||
def account_activation_request(user)
|
||||
# Send the email to all active administrators
|
||||
recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
|
||||
recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
|
||||
subject l(:mail_subject_account_activation_request, Setting.app_title)
|
||||
body :user => user,
|
||||
:url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
|
||||
end
|
||||
|
||||
# A registered user's account was activated by an administrator
|
||||
def account_activated(user)
|
||||
set_language_if_valid user.language
|
||||
recipients user.mail
|
||||
subject l(:mail_subject_register, Setting.app_title)
|
||||
body :user => user,
|
||||
:login_url => url_for(:controller => 'account', :action => 'login')
|
||||
end
|
||||
|
||||
def lost_password(token)
|
||||
set_language_if_valid(token.user.language)
|
||||
recipients token.user.mail
|
||||
subject l(:mail_subject_lost_password, Setting.app_title)
|
||||
body :token => token,
|
||||
:url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
|
||||
end
|
||||
end
|
||||
|
||||
def register(token)
|
||||
set_language_if_valid(token.user.language)
|
||||
@@ -157,7 +128,7 @@ class Mailer < ActionMailer::Base
|
||||
body :token => token,
|
||||
:url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
|
||||
end
|
||||
|
||||
|
||||
def test(user)
|
||||
set_language_if_valid(user.language)
|
||||
recipients user.mail
|
||||
@@ -168,95 +139,54 @@ class Mailer < ActionMailer::Base
|
||||
# Overrides default deliver! method to prevent from sending an email
|
||||
# with no recipient, cc or bcc
|
||||
def deliver!(mail = @mail)
|
||||
return false if (recipients.nil? || recipients.empty?) &&
|
||||
return false if (recipients.nil? || recipients.empty?) &&
|
||||
(cc.nil? || cc.empty?) &&
|
||||
(bcc.nil? || bcc.empty?)
|
||||
super
|
||||
end
|
||||
|
||||
# Sends reminders to issue assignees
|
||||
# Available options:
|
||||
# * :days => how many days in the future to remind about (defaults to 7)
|
||||
# * :tracker => id of tracker for filtering issues (defaults to all trackers)
|
||||
# * :project => id or identifier of project to process (defaults to all projects)
|
||||
def self.reminders(options={})
|
||||
days = options[:days] || 7
|
||||
project = options[:project] ? Project.find(options[:project]) : nil
|
||||
tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
|
||||
|
||||
s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date]
|
||||
s << "#{Issue.table_name}.assigned_to_id IS NOT NULL"
|
||||
s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
|
||||
s << "#{Issue.table_name}.project_id = #{project.id}" if project
|
||||
s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
|
||||
|
||||
issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker],
|
||||
:conditions => s.conditions
|
||||
).group_by(&:assigned_to)
|
||||
issues_by_assignee.each do |assignee, issues|
|
||||
deliver_reminder(assignee, issues, days) unless assignee.nil?
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def initialize_defaults(method_name)
|
||||
super
|
||||
set_language_if_valid Setting.default_language
|
||||
from Setting.mail_from
|
||||
|
||||
default_url_options[:host] = Setting.host_name
|
||||
default_url_options[:protocol] = Setting.protocol
|
||||
# Common headers
|
||||
headers 'X-Mailer' => 'Redmine',
|
||||
'X-Redmine-Host' => Setting.host_name,
|
||||
'X-Redmine-Site' => Setting.app_title,
|
||||
'Precedence' => 'bulk',
|
||||
'Auto-Submitted' => 'auto-generated'
|
||||
'X-Redmine-Site' => Setting.app_title
|
||||
end
|
||||
|
||||
|
||||
# Appends a Redmine header field (name is prepended with 'X-Redmine-')
|
||||
def redmine_headers(h)
|
||||
h.each { |k,v| headers["X-Redmine-#{k}"] = v }
|
||||
end
|
||||
|
||||
|
||||
# Overrides the create_mail method
|
||||
def create_mail
|
||||
# Removes the current user from the recipients and cc
|
||||
# if he doesn't want to receive notifications about what he does
|
||||
@author ||= User.current
|
||||
if @author.pref[:no_self_notified]
|
||||
recipients.delete(@author.mail) if recipients
|
||||
cc.delete(@author.mail) if cc
|
||||
if User.current.pref[:no_self_notified]
|
||||
recipients.delete(User.current.mail) if recipients
|
||||
cc.delete(User.current.mail) if cc
|
||||
end
|
||||
# Blind carbon copy recipients
|
||||
if Setting.bcc_recipients?
|
||||
bcc([recipients, cc].flatten.compact.uniq)
|
||||
recipients []
|
||||
cc []
|
||||
end
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
|
||||
# Renders a message with the corresponding layout
|
||||
def render_message(method_name, body)
|
||||
layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
|
||||
body[:content_for_layout] = render(:file => method_name, :body => body)
|
||||
ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true)
|
||||
ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}")
|
||||
end
|
||||
|
||||
# for the case of plain text only
|
||||
def body(*params)
|
||||
value = super(*params)
|
||||
if Setting.plain_text_mail?
|
||||
templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}")
|
||||
unless String === @body or templates.empty?
|
||||
template = File.basename(templates.first)
|
||||
@body[:content_for_layout] = render(:file => template, :body => @body)
|
||||
@body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true)
|
||||
return @body
|
||||
end
|
||||
end
|
||||
return value
|
||||
end
|
||||
|
||||
|
||||
# Makes partial rendering work with Rails 1.2 (retro-compatibility)
|
||||
def self.controller_path
|
||||
''
|
||||
|
||||
@@ -19,29 +19,21 @@ class Message < ActiveRecord::Base
|
||||
belongs_to :board
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
|
||||
acts_as_attachable
|
||||
has_many :attachments, :as => :container, :dependent => :destroy
|
||||
belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
|
||||
|
||||
acts_as_searchable :columns => ['subject', 'content'],
|
||||
:include => {:board => :project},
|
||||
:include => :board,
|
||||
:project_key => 'project_id',
|
||||
:date_column => "#{table_name}.created_on"
|
||||
:date_column => 'created_on'
|
||||
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
||||
:description => :content,
|
||||
:type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
|
||||
:url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
|
||||
{:id => o.parent_id, :anchor => "message-#{o.id}"})}
|
||||
|
||||
acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
|
||||
:author_key => :author_id
|
||||
acts_as_watchable
|
||||
|
||||
:url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id, :id => o.id}}
|
||||
|
||||
attr_protected :locked, :sticky
|
||||
validates_presence_of :subject, :content
|
||||
validates_length_of :subject, :maximum => 255
|
||||
|
||||
after_create :add_author_as_watcher
|
||||
|
||||
def validate_on_create
|
||||
# Can not reply to a locked topic
|
||||
errors.add_to_base 'Topic is locked' if root.locked? && self != root
|
||||
@@ -72,18 +64,4 @@ class Message < ActiveRecord::Base
|
||||
def project
|
||||
board.project
|
||||
end
|
||||
|
||||
def editable_by?(usr)
|
||||
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
|
||||
end
|
||||
|
||||
def destroyable_by?(usr)
|
||||
usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project)))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_author_as_watcher
|
||||
Watcher.create(:watchable => self.root, :user => author)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,13 +17,10 @@
|
||||
|
||||
class MessageObserver < ActiveRecord::Observer
|
||||
def after_create(message)
|
||||
recipients = []
|
||||
# send notification to the topic watchers
|
||||
recipients += message.root.watcher_recipients
|
||||
# send notification to the authors of the thread
|
||||
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author && m.author.active?}
|
||||
# send notification to the board watchers
|
||||
recipients += message.board.watcher_recipients
|
||||
# send notification to project members who want to be notified
|
||||
recipients += message.board.project.recipients
|
||||
recipients = recipients.compact.uniq
|
||||
Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?('message_posted')
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -24,13 +24,11 @@ class News < ActiveRecord::Base
|
||||
validates_length_of :title, :maximum => 60
|
||||
validates_length_of :summary, :maximum => 255
|
||||
|
||||
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :project
|
||||
acts_as_searchable :columns => ['title', 'description']
|
||||
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
||||
acts_as_activity_provider :find_options => {:include => [:project, :author]},
|
||||
:author_key => :author_id
|
||||
|
||||
|
||||
# returns latest news for projects visible by user
|
||||
def self.latest(user = User.current, count = 5)
|
||||
find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
||||
def self.latest(user=nil, count=5)
|
||||
find(:all, :limit => count, :conditions => Project.visible_by(user), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,6 +22,7 @@ class Project < ActiveRecord::Base
|
||||
|
||||
has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
|
||||
has_many :users, :through => :members
|
||||
has_many :custom_values, :dependent => :delete_all, :as => :customized
|
||||
has_many :enabled_modules, :dependent => :delete_all
|
||||
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
||||
has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
|
||||
@@ -32,40 +33,35 @@ class Project < ActiveRecord::Base
|
||||
has_many :documents, :dependent => :destroy
|
||||
has_many :news, :dependent => :delete_all, :include => :author
|
||||
has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
|
||||
has_many :boards, :dependent => :destroy, :order => "position ASC"
|
||||
has_many :boards, :order => "position ASC"
|
||||
has_one :repository, :dependent => :destroy
|
||||
has_many :changesets, :through => :repository
|
||||
has_one :wiki, :dependent => :destroy
|
||||
# Custom field for the project issues
|
||||
has_and_belongs_to_many :issue_custom_fields,
|
||||
has_and_belongs_to_many :custom_fields,
|
||||
:class_name => 'IssueCustomField',
|
||||
:order => "#{CustomField.table_name}.position",
|
||||
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
||||
:association_foreign_key => 'custom_field_id'
|
||||
|
||||
acts_as_tree :order => "name", :counter_cache => true
|
||||
acts_as_attachable :view_permission => :view_files,
|
||||
:delete_permission => :manage_files
|
||||
|
||||
acts_as_customizable
|
||||
acts_as_searchable :columns => ['name', 'description'], :project_key => 'id', :permission => nil
|
||||
acts_as_searchable :columns => ['name', 'description'], :project_key => 'id'
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
|
||||
:url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}},
|
||||
:author => nil
|
||||
:url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}}
|
||||
|
||||
attr_protected :status, :enabled_module_names
|
||||
|
||||
validates_presence_of :name, :identifier
|
||||
validates_uniqueness_of :name, :identifier
|
||||
validates_associated :custom_values, :on => :update
|
||||
validates_associated :repository, :wiki
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_length_of :homepage, :maximum => 255
|
||||
validates_length_of :identifier, :in => 1..20
|
||||
validates_length_of :homepage, :maximum => 60
|
||||
validates_length_of :identifier, :in => 3..20
|
||||
validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
|
||||
|
||||
before_destroy :delete_all_members
|
||||
|
||||
named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
|
||||
|
||||
def identifier=(identifier)
|
||||
super unless identifier_frozen?
|
||||
@@ -77,16 +73,14 @@ class Project < ActiveRecord::Base
|
||||
|
||||
def issues_with_subprojects(include_subprojects=false)
|
||||
conditions = nil
|
||||
if include_subprojects
|
||||
ids = [id] + child_ids
|
||||
conditions = ["#{Project.table_name}.id IN (#{ids.join(',')}) AND #{Project.visible_by}"]
|
||||
if include_subprojects && !active_children.empty?
|
||||
ids = [id] + active_children.collect {|c| c.id}
|
||||
conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"]
|
||||
end
|
||||
conditions ||= ["#{Project.table_name}.id = ?", id]
|
||||
conditions ||= ["#{Issue.table_name}.project_id = ?", id]
|
||||
# Quick and dirty fix for Rails 2 compatibility
|
||||
Issue.send(:with_scope, :find => { :conditions => conditions }) do
|
||||
Version.send(:with_scope, :find => { :conditions => conditions }) do
|
||||
yield
|
||||
end
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
@@ -97,7 +91,6 @@ class Project < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.visible_by(user=nil)
|
||||
user ||= User.current
|
||||
if user && user.admin?
|
||||
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
||||
elsif user && user.memberships.any?
|
||||
@@ -110,12 +103,6 @@ class Project < ActiveRecord::Base
|
||||
def self.allowed_to_condition(user, permission, options={})
|
||||
statements = []
|
||||
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
||||
if perm = Redmine::AccessControl.permission(permission)
|
||||
unless perm.project_module.nil?
|
||||
# If the permission belongs to a project module, make sure the module is enabled
|
||||
base_statement << " AND EXISTS (SELECT em.id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}' AND em.project_id=#{Project.table_name}.id)"
|
||||
end
|
||||
end
|
||||
if options[:project]
|
||||
project_statement = "#{Project.table_name}.id = #{options[:project].id}"
|
||||
project_statement << " OR #{Project.table_name}.parent_id = #{options[:project].id}" if options[:with_subprojects]
|
||||
@@ -123,18 +110,16 @@ class Project < ActiveRecord::Base
|
||||
end
|
||||
if user.admin?
|
||||
# no restriction
|
||||
elsif user.logged?
|
||||
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission)
|
||||
allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id}
|
||||
statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
|
||||
elsif Role.anonymous.allowed_to?(permission)
|
||||
# anonymous user allowed on public project
|
||||
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
||||
else
|
||||
# anonymous user is not authorized
|
||||
statements << "1=0"
|
||||
if user.logged?
|
||||
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission)
|
||||
allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id}
|
||||
statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
|
||||
elsif Role.anonymous.allowed_to?(permission)
|
||||
# anonymous user allowed on public project
|
||||
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
||||
else
|
||||
# anonymous user is not authorized
|
||||
end
|
||||
end
|
||||
statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))"
|
||||
end
|
||||
@@ -156,8 +141,7 @@ class Project < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def to_param
|
||||
# id is used for projects with a numeric identifier (compatibility)
|
||||
@to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier)
|
||||
identifier
|
||||
end
|
||||
|
||||
def active?
|
||||
@@ -207,12 +191,12 @@ class Project < ActiveRecord::Base
|
||||
|
||||
# Returns an array of all custom fields enabled for project issues
|
||||
# (explictly associated custom fields and custom fields enabled for all projects)
|
||||
def all_issue_custom_fields
|
||||
@all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort
|
||||
def custom_fields_for_issues(tracker)
|
||||
all_custom_fields.select {|c| tracker.custom_fields.include? c }
|
||||
end
|
||||
|
||||
def project
|
||||
self
|
||||
def all_custom_fields
|
||||
@all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq
|
||||
end
|
||||
|
||||
def <=>(project)
|
||||
@@ -248,12 +232,6 @@ class Project < ActiveRecord::Base
|
||||
enabled_modules << EnabledModule.new(:name => name.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns an auto-generated project identifier based on the last identifier used
|
||||
def self.next_identifier
|
||||
p = Project.find(:first, :order => 'created_on DESC')
|
||||
p.nil? ? nil : p.identifier.to_s.succ
|
||||
end
|
||||
|
||||
protected
|
||||
def validate
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -88,12 +88,11 @@ class Query < ActiveRecord::Base
|
||||
:date_past => [ ">t-", "<t-", "t-", "t", "w" ],
|
||||
:string => [ "=", "~", "!", "!~" ],
|
||||
:text => [ "~", "!~" ],
|
||||
:integer => [ "=", ">=", "<=", "!*", "*" ] }
|
||||
:integer => [ "=", ">=", "<=" ] }
|
||||
|
||||
cattr_reader :operators_by_filter_type
|
||||
|
||||
@@available_columns = [
|
||||
QueryColumn.new(:project, :sortable => "#{Project.table_name}.name"),
|
||||
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position"),
|
||||
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position"),
|
||||
QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position", :default_order => 'desc'),
|
||||
@@ -126,7 +125,7 @@ class Query < ActiveRecord::Base
|
||||
filters.each_key do |field|
|
||||
errors.add label_for(field), :activerecord_error_blank unless
|
||||
# filter requires one or more values
|
||||
(values_for(field) and !values_for(field).first.blank?) or
|
||||
(values_for(field) and !values_for(field).first.empty?) or
|
||||
# filter doesn't require any value
|
||||
["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
|
||||
end if filters
|
||||
@@ -153,8 +152,7 @@ class Query < ActiveRecord::Base
|
||||
"updated_on" => { :type => :date_past, :order => 10 },
|
||||
"start_date" => { :type => :date, :order => 11 },
|
||||
"due_date" => { :type => :date, :order => 12 },
|
||||
"estimated_hours" => { :type => :integer, :order => 13 },
|
||||
"done_ratio" => { :type => :integer, :order => 14 }}
|
||||
"done_ratio" => { :type => :integer, :order => 13 }}
|
||||
|
||||
user_values = []
|
||||
user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
|
||||
@@ -168,20 +166,29 @@ class Query < ActiveRecord::Base
|
||||
@available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
|
||||
|
||||
if project
|
||||
# project specific filters
|
||||
unless @project.issue_categories.empty?
|
||||
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
|
||||
end
|
||||
unless @project.versions.empty?
|
||||
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
|
||||
end
|
||||
# project specific filters
|
||||
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
|
||||
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
|
||||
unless @project.active_children.empty?
|
||||
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
|
||||
end
|
||||
add_custom_fields_filters(@project.all_issue_custom_fields)
|
||||
else
|
||||
# global filters for cross project issue list
|
||||
add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
|
||||
@project.all_custom_fields.select(&:is_filter?).each do |field|
|
||||
case field.field_format
|
||||
when "text"
|
||||
options = { :type => :text, :order => 20 }
|
||||
when "list"
|
||||
options = { :type => :list_optional, :values => field.possible_values, :order => 20}
|
||||
when "date"
|
||||
options = { :type => :date, :order => 20 }
|
||||
when "bool"
|
||||
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
|
||||
else
|
||||
options = { :type => :string, :order => 20 }
|
||||
end
|
||||
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
|
||||
end
|
||||
# remove category filter if no category defined
|
||||
@available_filters.delete "category_id" if @available_filters["category_id"][:values].empty?
|
||||
end
|
||||
@available_filters
|
||||
end
|
||||
@@ -220,7 +227,7 @@ class Query < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def label_for(field)
|
||||
label = available_filters[field][:name] if available_filters.has_key?(field)
|
||||
label = @available_filters[field][:name] if @available_filters.has_key?(field)
|
||||
label ||= field.gsub(/\_id$/, "")
|
||||
end
|
||||
|
||||
@@ -228,17 +235,14 @@ class Query < ActiveRecord::Base
|
||||
return @available_columns if @available_columns
|
||||
@available_columns = Query.available_columns
|
||||
@available_columns += (project ?
|
||||
project.all_issue_custom_fields :
|
||||
project.all_custom_fields :
|
||||
IssueCustomField.find(:all, :conditions => {:is_for_all => true})
|
||||
).collect {|cf| QueryCustomFieldColumn.new(cf) }
|
||||
end
|
||||
|
||||
def columns
|
||||
if has_default_columns?
|
||||
available_columns.select do |c|
|
||||
# Adds the project column by default for cross-project lists
|
||||
Setting.issue_list_default_columns.include?(c.name.to_s) || (c.name == :project && project.nil?)
|
||||
end
|
||||
available_columns.select {|c| Setting.issue_list_default_columns.include?(c.name.to_s) }
|
||||
else
|
||||
# preserve the column_names order
|
||||
column_names.collect {|name| available_columns.find {|col| col.name == name}}.compact
|
||||
@@ -258,9 +262,10 @@ class Query < ActiveRecord::Base
|
||||
def has_default_columns?
|
||||
column_names.nil? || column_names.empty?
|
||||
end
|
||||
|
||||
def project_statement
|
||||
project_clauses = []
|
||||
|
||||
def statement
|
||||
# project/subprojects clause
|
||||
clause = ''
|
||||
if project && !@project.active_children.empty?
|
||||
ids = [project.id]
|
||||
if has_filter?("subproject_id")
|
||||
@@ -272,20 +277,18 @@ class Query < ActiveRecord::Base
|
||||
# main project only
|
||||
else
|
||||
# all subprojects
|
||||
ids += project.child_ids
|
||||
ids += project.active_children.collect{|p| p.id}
|
||||
end
|
||||
elsif Setting.display_subprojects_issues?
|
||||
ids += project.child_ids
|
||||
ids += project.active_children.collect{|p| p.id}
|
||||
end
|
||||
project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
|
||||
clause << "#{Issue.table_name}.project_id IN (%s)" % ids.join(',')
|
||||
elsif project
|
||||
project_clauses << "#{Project.table_name}.id = %d" % project.id
|
||||
clause << "#{Issue.table_name}.project_id = %d" % project.id
|
||||
else
|
||||
clause << Project.visible_by(User.current)
|
||||
end
|
||||
project_clauses << Project.allowed_to_condition(User.current, :view_issues)
|
||||
project_clauses.join(' AND ')
|
||||
end
|
||||
|
||||
def statement
|
||||
|
||||
# filters clauses
|
||||
filters_clauses = []
|
||||
filters.each_key do |field|
|
||||
@@ -293,14 +296,12 @@ class Query < ActiveRecord::Base
|
||||
v = values_for(field).clone
|
||||
next unless v and !v.empty?
|
||||
|
||||
sql = ''
|
||||
is_custom_filter = false
|
||||
sql = ''
|
||||
if field =~ /^cf_(\d+)$/
|
||||
# custom field
|
||||
db_table = CustomValue.table_name
|
||||
db_field = 'value'
|
||||
is_custom_filter = true
|
||||
sql << "#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} WHERE "
|
||||
sql << "#{Issue.table_name}.id IN (SELECT #{db_table}.customized_id FROM #{db_table} where #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} AND "
|
||||
else
|
||||
# regular field
|
||||
db_table = Issue.table_name
|
||||
@@ -313,98 +314,55 @@ class Query < ActiveRecord::Base
|
||||
v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me")
|
||||
end
|
||||
|
||||
sql = sql + sql_for_field(field, v, db_table, db_field, is_custom_filter)
|
||||
|
||||
case operator_for field
|
||||
when "="
|
||||
sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
|
||||
when "!"
|
||||
sql = sql + "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
|
||||
when "!*"
|
||||
sql = sql + "#{db_table}.#{db_field} IS NULL"
|
||||
when "*"
|
||||
sql = sql + "#{db_table}.#{db_field} IS NOT NULL"
|
||||
when ">="
|
||||
sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}"
|
||||
when "<="
|
||||
sql = sql + "#{db_table}.#{db_field} <= #{v.first.to_i}"
|
||||
when "o"
|
||||
sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
|
||||
when "c"
|
||||
sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
|
||||
when ">t-"
|
||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today + 1).to_time)]
|
||||
when "<t-"
|
||||
sql = sql + "#{db_table}.#{db_field} <= '%s'" % connection.quoted_date((Date.today - v.first.to_i).to_time)
|
||||
when "t-"
|
||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today - v.first.to_i + 1).to_time)]
|
||||
when ">t+"
|
||||
sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date((Date.today + v.first.to_i).to_time)
|
||||
when "<t+"
|
||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)]
|
||||
when "t+"
|
||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today + v.first.to_i).to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)]
|
||||
when "t"
|
||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today+1).to_time)]
|
||||
when "w"
|
||||
from = l(:general_first_day_of_week) == '7' ?
|
||||
# week starts on sunday
|
||||
((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) :
|
||||
# week starts on monday (Rails default)
|
||||
Time.now.at_beginning_of_week
|
||||
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
|
||||
when "~"
|
||||
sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'"
|
||||
when "!~"
|
||||
sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
|
||||
end
|
||||
sql << ')'
|
||||
filters_clauses << sql
|
||||
end if filters and valid?
|
||||
|
||||
(filters_clauses << project_statement).join(' AND ')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Helper method to generate the WHERE sql for a +field+ with a +value+
|
||||
def sql_for_field(field, value, db_table, db_field, is_custom_filter)
|
||||
sql = ''
|
||||
case operator_for field
|
||||
when "="
|
||||
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
|
||||
when "!"
|
||||
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
|
||||
when "!*"
|
||||
sql = "#{db_table}.#{db_field} IS NULL"
|
||||
sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter
|
||||
when "*"
|
||||
sql = "#{db_table}.#{db_field} IS NOT NULL"
|
||||
sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter
|
||||
when ">="
|
||||
sql = "#{db_table}.#{db_field} >= #{value.first.to_i}"
|
||||
when "<="
|
||||
sql = "#{db_table}.#{db_field} <= #{value.first.to_i}"
|
||||
when "o"
|
||||
sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
|
||||
when "c"
|
||||
sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
|
||||
when ">t-"
|
||||
sql = date_range_clause(db_table, db_field, - value.first.to_i, 0)
|
||||
when "<t-"
|
||||
sql = date_range_clause(db_table, db_field, nil, - value.first.to_i)
|
||||
when "t-"
|
||||
sql = date_range_clause(db_table, db_field, - value.first.to_i, - value.first.to_i)
|
||||
when ">t+"
|
||||
sql = date_range_clause(db_table, db_field, value.first.to_i, nil)
|
||||
when "<t+"
|
||||
sql = date_range_clause(db_table, db_field, 0, value.first.to_i)
|
||||
when "t+"
|
||||
sql = date_range_clause(db_table, db_field, value.first.to_i, value.first.to_i)
|
||||
when "t"
|
||||
sql = date_range_clause(db_table, db_field, 0, 0)
|
||||
when "w"
|
||||
from = l(:general_first_day_of_week) == '7' ?
|
||||
# week starts on sunday
|
||||
((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) :
|
||||
# week starts on monday (Rails default)
|
||||
Time.now.at_beginning_of_week
|
||||
sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
|
||||
when "~"
|
||||
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
||||
when "!~"
|
||||
sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
||||
end
|
||||
|
||||
return sql
|
||||
end
|
||||
|
||||
def add_custom_fields_filters(custom_fields)
|
||||
@available_filters ||= {}
|
||||
|
||||
custom_fields.select(&:is_filter?).each do |field|
|
||||
case field.field_format
|
||||
when "text"
|
||||
options = { :type => :text, :order => 20 }
|
||||
when "list"
|
||||
options = { :type => :list_optional, :values => field.possible_values, :order => 20}
|
||||
when "date"
|
||||
options = { :type => :date, :order => 20 }
|
||||
when "bool"
|
||||
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
|
||||
else
|
||||
options = { :type => :string, :order => 20 }
|
||||
end
|
||||
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a SQL clause for a date or datetime field.
|
||||
def date_range_clause(table, field, from, to)
|
||||
s = []
|
||||
if from
|
||||
s << ("#{table}.#{field} > '%s'" % [connection.quoted_date((Date.yesterday + from).to_time.end_of_day)])
|
||||
end
|
||||
if to
|
||||
s << ("#{table}.#{field} <= '%s'" % [connection.quoted_date((Date.today + to).to_time.end_of_day)])
|
||||
end
|
||||
s.join(' AND ')
|
||||
clause << ' AND ' unless clause.empty?
|
||||
clause << filters_clauses.join(' AND ') unless filters_clauses.empty?
|
||||
clause
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,16 +17,9 @@
|
||||
|
||||
class Repository < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
|
||||
has_many :changesets, :dependent => :destroy, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
|
||||
has_many :changes, :through => :changesets
|
||||
|
||||
# Raw SQL to delete changesets and changes in the database
|
||||
# has_many :changesets, :dependent => :destroy is too slow for big repositories
|
||||
before_destroy :clear_changesets
|
||||
|
||||
# Checks if the SCM is enabled when creating a repository
|
||||
validate_on_create { |r| r.errors.add(:type, :activerecord_error_invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
|
||||
|
||||
|
||||
# Removes leading and trailing whitespace
|
||||
def url=(arg)
|
||||
write_attribute(:url, arg ? arg.to_s.strip : nil)
|
||||
@@ -55,39 +48,22 @@ class Repository < ActiveRecord::Base
|
||||
scm.supports_annotate?
|
||||
end
|
||||
|
||||
def entry(path=nil, identifier=nil)
|
||||
scm.entry(path, identifier)
|
||||
end
|
||||
|
||||
def entries(path=nil, identifier=nil)
|
||||
scm.entries(path, identifier)
|
||||
end
|
||||
|
||||
def properties(path, identifier=nil)
|
||||
scm.properties(path, identifier)
|
||||
end
|
||||
|
||||
def cat(path, identifier=nil)
|
||||
scm.cat(path, identifier)
|
||||
end
|
||||
|
||||
def diff(path, rev, rev_to)
|
||||
scm.diff(path, rev, rev_to)
|
||||
def diff(path, rev, rev_to, type)
|
||||
scm.diff(path, rev, rev_to, type)
|
||||
end
|
||||
|
||||
# Default behaviour: we search in cached changesets
|
||||
def changesets_for_path(path)
|
||||
path = "/#{path}" unless path.starts_with?('/')
|
||||
Change.find(:all, :include => {:changeset => :user},
|
||||
Change.find(:all, :include => :changeset,
|
||||
:conditions => ["repository_id = ? AND path = ?", id, path],
|
||||
:order => "committed_on DESC, #{Changeset.table_name}.id DESC").collect(&:changeset)
|
||||
end
|
||||
|
||||
# Returns a path relative to the url of the repository
|
||||
def relative_path(path)
|
||||
path
|
||||
end
|
||||
|
||||
def latest_changeset
|
||||
@latest_changeset ||= changesets.find(:first)
|
||||
end
|
||||
@@ -96,45 +72,6 @@ class Repository < ActiveRecord::Base
|
||||
self.changesets.each(&:scan_comment_for_issue_ids)
|
||||
end
|
||||
|
||||
# Returns an array of committers usernames and associated user_id
|
||||
def committers
|
||||
@committers ||= Changeset.connection.select_rows("SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}")
|
||||
end
|
||||
|
||||
# Maps committers username to a user ids
|
||||
def committer_ids=(h)
|
||||
if h.is_a?(Hash)
|
||||
committers.each do |committer, user_id|
|
||||
new_user_id = h[committer]
|
||||
if new_user_id && (new_user_id.to_i != user_id.to_i)
|
||||
new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil)
|
||||
Changeset.update_all("user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }", ["repository_id = ? AND committer = ?", id, committer])
|
||||
end
|
||||
end
|
||||
@committers = nil
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the Redmine User corresponding to the given +committer+
|
||||
# It will return nil if the committer is not yet mapped and if no User
|
||||
# with the same username or email was found
|
||||
def find_committer_user(committer)
|
||||
if committer
|
||||
c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
|
||||
if c && c.user
|
||||
c.user
|
||||
elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/
|
||||
username, email = $1.strip, $3
|
||||
u = User.find_by_login(username)
|
||||
u ||= User.find_by_mail(email) unless email.blank?
|
||||
u
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# fetch new changesets for all repositories
|
||||
# can be called periodically by an external script
|
||||
# eg. ruby script/runner "Repository.fetch_changesets"
|
||||
@@ -170,10 +107,4 @@ class Repository < ActiveRecord::Base
|
||||
root_url.strip!
|
||||
true
|
||||
end
|
||||
|
||||
def clear_changesets
|
||||
connection.delete("DELETE FROM changes WHERE changes.changeset_id IN (SELECT changesets.id FROM changesets WHERE changesets.repository_id = #{id})")
|
||||
connection.delete("DELETE FROM changesets_issues WHERE changesets_issues.changeset_id IN (SELECT changesets.id FROM changesets WHERE changesets.repository_id = #{id})")
|
||||
connection.delete("DELETE FROM changesets WHERE changesets.repository_id = #{id}")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,11 +34,6 @@ class Repository::Bazaar < Repository
|
||||
if entries
|
||||
entries.each do |e|
|
||||
next if e.lastrev.revision.blank?
|
||||
# Set the filesize unless browsing a specific revision
|
||||
if identifier.nil? && e.is_file?
|
||||
full_path = File.join(root_url, e.path)
|
||||
e.size = File.stat(full_path).size if File.file?(full_path)
|
||||
end
|
||||
c = Change.find(:first,
|
||||
:include => :changeset,
|
||||
:conditions => ["#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?", e.lastrev.revision, id],
|
||||
|
||||
@@ -29,14 +29,13 @@ class Repository::Cvs < Repository
|
||||
'CVS'
|
||||
end
|
||||
|
||||
def entry(path=nil, identifier=nil)
|
||||
rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||
scm.entry(path, rev.nil? ? nil : rev.committed_on)
|
||||
def entry(path, identifier)
|
||||
e = entries(path, identifier)
|
||||
e ? e.first : nil
|
||||
end
|
||||
|
||||
def entries(path=nil, identifier=nil)
|
||||
rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||
entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
|
||||
entries=scm.entries(path, identifier)
|
||||
if entries
|
||||
entries.each() do |entry|
|
||||
unless entry.lastrev.nil? || entry.lastrev.identifier
|
||||
@@ -53,12 +52,7 @@ class Repository::Cvs < Repository
|
||||
entries
|
||||
end
|
||||
|
||||
def cat(path, identifier=nil)
|
||||
rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||
scm.cat(path, rev.nil? ? nil : rev.committed_on)
|
||||
end
|
||||
|
||||
def diff(path, rev, rev_to)
|
||||
def diff(path, rev, rev_to, type)
|
||||
#convert rev to revision. CVS can't handle changesets here
|
||||
diff=[]
|
||||
changeset_from=changesets.find_by_revision(rev)
|
||||
@@ -81,8 +75,7 @@ class Repository::Cvs < Repository
|
||||
unless revision_to
|
||||
revision_to=scm.get_previous_revision(revision_from)
|
||||
end
|
||||
file_diff = scm.diff(change_from.path, revision_from, revision_to)
|
||||
diff = diff + file_diff unless file_diff.nil?
|
||||
diff=diff+scm.diff(change_from.path, revision_from, revision_to, type)
|
||||
end
|
||||
end
|
||||
return diff
|
||||
@@ -109,7 +102,7 @@ class Repository::Cvs < Repository
|
||||
cs = changesets.find(:first, :conditions=>{
|
||||
:committed_on=>revision.time-time_delta..revision.time+time_delta,
|
||||
:committer=>revision.author,
|
||||
:comments=>Changeset.normalize_comments(revision.message)
|
||||
:comments=>revision.message
|
||||
})
|
||||
|
||||
# create a new changeset....
|
||||
@@ -144,18 +137,12 @@ class Repository::Cvs < Repository
|
||||
end
|
||||
|
||||
# Renumber new changesets in chronological order
|
||||
c = changesets.find(:first, :order => 'committed_on DESC, id DESC', :conditions => "revision NOT LIKE '_%'")
|
||||
next_rev = c.nil? ? 1 : (c.revision.to_i + 1)
|
||||
changesets.find(:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE '_%'").each do |changeset|
|
||||
changeset.update_attribute :revision, next_revision_number
|
||||
changeset.update_attribute :revision, next_rev
|
||||
next_rev += 1
|
||||
end
|
||||
end # transaction
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns the next revision number to assign to a CVS changeset
|
||||
def next_revision_number
|
||||
# Need to retrieve existing revision numbers to sort them as integers
|
||||
@current_revision_number ||= (connection.select_values("SELECT revision FROM #{Changeset.table_name} WHERE repository_id = #{id} AND revision NOT LIKE '_%'").collect(&:to_i).max || 0)
|
||||
@current_revision_number += 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,14 +28,8 @@ class Repository::Darcs < Repository
|
||||
'Darcs'
|
||||
end
|
||||
|
||||
def entry(path=nil, identifier=nil)
|
||||
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||
scm.entry(path, patch.nil? ? nil : patch.scmid)
|
||||
end
|
||||
|
||||
def entries(path=nil, identifier=nil)
|
||||
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||
entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
|
||||
entries=scm.entries(path, identifier)
|
||||
if entries
|
||||
entries.each do |entry|
|
||||
# Search the DB for the entry's last change
|
||||
@@ -51,19 +45,14 @@ class Repository::Darcs < Repository
|
||||
entries
|
||||
end
|
||||
|
||||
def cat(path, identifier=nil)
|
||||
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s)
|
||||
scm.cat(path, patch.nil? ? nil : patch.scmid)
|
||||
end
|
||||
|
||||
def diff(path, rev, rev_to)
|
||||
def diff(path, rev, rev_to, type)
|
||||
patch_from = changesets.find_by_revision(rev)
|
||||
return nil if patch_from.nil?
|
||||
patch_to = changesets.find_by_revision(rev_to) if rev_to
|
||||
if path.blank?
|
||||
path = patch_from.changes.collect{|change| change.path}.join(' ')
|
||||
end
|
||||
patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil
|
||||
patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil, type) : nil
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
|
||||
@@ -30,7 +30,7 @@ class Repository::Git < Repository
|
||||
end
|
||||
|
||||
def changesets_for_path(path)
|
||||
Change.find(:all, :include => {:changeset => :user},
|
||||
Change.find(:all, :include => :changeset,
|
||||
:conditions => ["repository_id = ? AND path = ?", id, path],
|
||||
:order => "committed_on DESC, #{Changeset.table_name}.revision DESC").collect(&:changeset)
|
||||
end
|
||||
@@ -44,23 +44,23 @@ class Repository::Git < Repository
|
||||
scm_revision = scm_info.lastrev.scmid
|
||||
|
||||
unless changesets.find_by_scmid(scm_revision)
|
||||
scm.revisions('', db_revision, nil, :reverse => true) do |revision|
|
||||
if changesets.find_by_scmid(revision.scmid.to_s).nil?
|
||||
transaction do
|
||||
changeset = Changeset.create!(:repository => self,
|
||||
:revision => revision.identifier,
|
||||
:scmid => revision.scmid,
|
||||
:committer => revision.author,
|
||||
:committed_on => revision.time,
|
||||
:comments => revision.message)
|
||||
|
||||
revision.paths.each do |change|
|
||||
Change.create!(:changeset => changeset,
|
||||
:action => change[:action],
|
||||
:path => change[:path],
|
||||
:from_path => change[:from_path],
|
||||
:from_revision => change[:from_revision])
|
||||
end
|
||||
|
||||
revisions = scm.revisions('', db_revision, nil)
|
||||
transaction do
|
||||
revisions.reverse_each do |revision|
|
||||
changeset = Changeset.create(:repository => self,
|
||||
:revision => revision.identifier,
|
||||
:scmid => revision.scmid,
|
||||
:committer => revision.author,
|
||||
:committed_on => revision.time,
|
||||
:comments => revision.message)
|
||||
|
||||
revision.paths.each do |change|
|
||||
Change.create(:changeset => changeset,
|
||||
:action => change[:action],
|
||||
:path => change[:path],
|
||||
:from_path => change[:from_path],
|
||||
:from_revision => change[:from_revision])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,11 +34,6 @@ class Repository::Mercurial < Repository
|
||||
if entries
|
||||
entries.each do |entry|
|
||||
next unless entry.is_file?
|
||||
# Set the filesize unless browsing a specific revision
|
||||
if identifier.nil?
|
||||
full_path = File.join(root_url, entry.path)
|
||||
entry.size = File.stat(full_path).size if File.file?(full_path)
|
||||
end
|
||||
# Search the DB for the entry's last change
|
||||
change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
|
||||
if change
|
||||
@@ -58,9 +53,7 @@ class Repository::Mercurial < Repository
|
||||
# latest revision found in database
|
||||
db_revision = latest_changeset ? latest_changeset.revision.to_i : -1
|
||||
# latest revision in the repository
|
||||
latest_revision = scm_info.lastrev
|
||||
return if latest_revision.nil?
|
||||
scm_revision = latest_revision.identifier.to_i
|
||||
scm_revision = scm_info.lastrev.identifier.to_i
|
||||
if db_revision < scm_revision
|
||||
logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
|
||||
identifier_from = db_revision + 1
|
||||
|
||||
@@ -20,7 +20,7 @@ require 'redmine/scm/adapters/subversion_adapter'
|
||||
class Repository::Subversion < Repository
|
||||
attr_protected :root_url
|
||||
validates_presence_of :url
|
||||
validates_format_of :url, :with => /^(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+/i
|
||||
validates_format_of :url, :with => /^(http|https|svn|svn\+ssh|file):\/\/.+/i
|
||||
|
||||
def scm_adapter
|
||||
Redmine::Scm::Adapters::SubversionAdapter
|
||||
@@ -32,12 +32,7 @@ class Repository::Subversion < Repository
|
||||
|
||||
def changesets_for_path(path)
|
||||
revisions = scm.revisions(path)
|
||||
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
|
||||
end
|
||||
|
||||
# Returns a path relative to the url of the repository
|
||||
def relative_path(path)
|
||||
path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
|
||||
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC") : []
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
@@ -54,8 +49,8 @@ class Repository::Subversion < Repository
|
||||
# loads changesets by batches of 200
|
||||
identifier_to = [identifier_from + 199, scm_revision].min
|
||||
revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
|
||||
revisions.reverse_each do |revision|
|
||||
transaction do
|
||||
transaction do
|
||||
revisions.reverse_each do |revision|
|
||||
changeset = Changeset.create(:repository => self,
|
||||
:revision => revision.identifier,
|
||||
:committer => revision.author,
|
||||
@@ -68,7 +63,7 @@ class Repository::Subversion < Repository
|
||||
:path => change[:path],
|
||||
:from_path => change[:from_path],
|
||||
:from_revision => change[:from_revision])
|
||||
end unless changeset.new_record?
|
||||
end
|
||||
end
|
||||
end unless revisions.nil?
|
||||
identifier_from = identifier_to + 1
|
||||
@@ -76,14 +71,4 @@ class Repository::Subversion < Repository
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns the relative url of the repository
|
||||
# Eg: root_url = file:///var/svn/foo
|
||||
# url = file:///var/svn/foo/bar
|
||||
# => returns /bar
|
||||
def relative_url
|
||||
@relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url)}"), '')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,11 +19,6 @@ class Role < ActiveRecord::Base
|
||||
# Built-in roles
|
||||
BUILTIN_NON_MEMBER = 1
|
||||
BUILTIN_ANONYMOUS = 2
|
||||
|
||||
named_scope :builtin, lambda { |*args|
|
||||
compare = 'not' if args.first == true
|
||||
{ :conditions => "#{compare} builtin = 0" }
|
||||
}
|
||||
|
||||
before_destroy :check_deletable
|
||||
has_many :workflows, :dependent => :delete_all do
|
||||
@@ -31,9 +26,9 @@ class Role < ActiveRecord::Base
|
||||
raise "Can not copy workflow from a #{role.class}" unless role.is_a?(Role)
|
||||
raise "Can not copy workflow from/to an unsaved role" if proxy_owner.new_record? || role.new_record?
|
||||
clear
|
||||
connection.insert "INSERT INTO #{Workflow.table_name} (tracker_id, old_status_id, new_status_id, role_id)" +
|
||||
connection.insert "INSERT INTO workflows (tracker_id, old_status_id, new_status_id, role_id)" +
|
||||
" SELECT tracker_id, old_status_id, new_status_id, #{proxy_owner.id}" +
|
||||
" FROM #{Workflow.table_name}" +
|
||||
" FROM workflows" +
|
||||
" WHERE role_id = #{role.id}"
|
||||
end
|
||||
end
|
||||
@@ -41,7 +36,7 @@ class Role < ActiveRecord::Base
|
||||
has_many :members
|
||||
acts_as_list
|
||||
|
||||
serialize :permissions, Array
|
||||
serialize :permissions
|
||||
attr_protected :builtin
|
||||
|
||||
validates_presence_of :name
|
||||
@@ -54,32 +49,9 @@ class Role < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def permissions=(perms)
|
||||
perms = perms.collect {|p| p.to_sym unless p.blank? }.compact.uniq if perms
|
||||
perms = perms.collect {|p| p.to_sym unless p.blank? }.compact if perms
|
||||
write_attribute(:permissions, perms)
|
||||
end
|
||||
|
||||
def add_permission!(*perms)
|
||||
self.permissions = [] unless permissions.is_a?(Array)
|
||||
|
||||
permissions_will_change!
|
||||
perms.each do |p|
|
||||
p = p.to_sym
|
||||
permissions << p unless permissions.include?(p)
|
||||
end
|
||||
save!
|
||||
end
|
||||
|
||||
def remove_permission!(*perms)
|
||||
return unless permissions.is_a?(Array)
|
||||
permissions_will_change!
|
||||
perms.each { |p| permissions.delete(p.to_sym) }
|
||||
save!
|
||||
end
|
||||
|
||||
# Returns true if the role has the given permission
|
||||
def has_permission?(perm)
|
||||
!permissions.nil? && permissions.include?(perm.to_sym)
|
||||
end
|
||||
|
||||
def <=>(role)
|
||||
position <=> role.position
|
||||
|
||||
@@ -33,51 +33,12 @@ class Setting < ActiveRecord::Base
|
||||
'%H:%M',
|
||||
'%I:%M %p'
|
||||
]
|
||||
|
||||
ENCODINGS = %w(US-ASCII
|
||||
windows-1250
|
||||
windows-1251
|
||||
windows-1252
|
||||
windows-1253
|
||||
windows-1254
|
||||
windows-1255
|
||||
windows-1256
|
||||
windows-1257
|
||||
windows-1258
|
||||
windows-31j
|
||||
ISO-2022-JP
|
||||
ISO-2022-KR
|
||||
ISO-8859-1
|
||||
ISO-8859-2
|
||||
ISO-8859-3
|
||||
ISO-8859-4
|
||||
ISO-8859-5
|
||||
ISO-8859-6
|
||||
ISO-8859-7
|
||||
ISO-8859-8
|
||||
ISO-8859-9
|
||||
ISO-8859-13
|
||||
ISO-8859-15
|
||||
KOI8-R
|
||||
UTF-8
|
||||
UTF-16
|
||||
UTF-16BE
|
||||
UTF-16LE
|
||||
EUC-JP
|
||||
Shift_JIS
|
||||
GB18030
|
||||
GBK
|
||||
ISCII91
|
||||
EUC-KR
|
||||
Big5
|
||||
Big5-HKSCS
|
||||
TIS-620)
|
||||
|
||||
cattr_accessor :available_settings
|
||||
@@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
|
||||
Redmine::Plugin.all.each do |plugin|
|
||||
Redmine::Plugin.registered_plugins.each do |id, plugin|
|
||||
next unless plugin.settings
|
||||
@@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
|
||||
@@available_settings["plugin_#{id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
|
||||
end
|
||||
|
||||
validates_uniqueness_of :name
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -24,25 +24,11 @@ class TimeEntry < ActiveRecord::Base
|
||||
belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id
|
||||
|
||||
attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek
|
||||
|
||||
acts_as_customizable
|
||||
acts_as_event :title => Proc.new {|o| "#{o.user}: #{lwr(:label_f_hour, o.hours)} (#{(o.issue || o.project).event_title})"},
|
||||
:url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project}},
|
||||
:author => :user,
|
||||
:description => :comments
|
||||
|
||||
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
|
||||
validates_numericality_of :hours, :allow_nil => true, :message => :activerecord_error_invalid
|
||||
validates_length_of :comments, :maximum => 255, :allow_nil => true
|
||||
validates_numericality_of :hours, :allow_nil => true
|
||||
validates_length_of :comments, :maximum => 255
|
||||
|
||||
def after_initialize
|
||||
if new_record? && self.activity.nil?
|
||||
if default_activity = Enumeration.default('ACTI')
|
||||
self.activity_id = default_activity.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def before_validation
|
||||
self.project = issue.project if issue && project.nil?
|
||||
end
|
||||
@@ -53,10 +39,6 @@ class TimeEntry < ActiveRecord::Base
|
||||
errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project)
|
||||
end
|
||||
|
||||
def hours=(h)
|
||||
write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h)
|
||||
end
|
||||
|
||||
# tyear, tmonth, tweek assigned where setting spent_on attributes
|
||||
# these attributes make time aggregations easier
|
||||
def spent_on=(date)
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class TimeEntryCustomField < CustomField
|
||||
def type_name
|
||||
:label_spent_time
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,11 +15,8 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'rails_generator/secret_key_generator'
|
||||
|
||||
class Token < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
validates_uniqueness_of :value
|
||||
|
||||
@@validity_time = 1.day
|
||||
|
||||
@@ -39,7 +36,9 @@ class Token < ActiveRecord::Base
|
||||
|
||||
private
|
||||
def self.generate_token_value
|
||||
s = Rails::SecretKeyGenerator.new(object_id).generate_secret
|
||||
s[0, 40]
|
||||
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
||||
token_value = ''
|
||||
40.times { |i| token_value << chars[rand(chars.size-1)] }
|
||||
token_value
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,9 +23,9 @@ class Tracker < ActiveRecord::Base
|
||||
raise "Can not copy workflow from a #{tracker.class}" unless tracker.is_a?(Tracker)
|
||||
raise "Can not copy workflow from/to an unsaved tracker" if proxy_owner.new_record? || tracker.new_record?
|
||||
clear
|
||||
connection.insert "INSERT INTO #{Workflow.table_name} (tracker_id, old_status_id, new_status_id, role_id)" +
|
||||
connection.insert "INSERT INTO workflows (tracker_id, old_status_id, new_status_id, role_id)" +
|
||||
" SELECT #{proxy_owner.id}, old_status_id, new_status_id, role_id" +
|
||||
" FROM #{Workflow.table_name}" +
|
||||
" FROM workflows" +
|
||||
" WHERE tracker_id = #{tracker.id}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
require "digest/sha1"
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
|
||||
# Account statuses
|
||||
STATUS_ANONYMOUS = 0
|
||||
STATUS_ACTIVE = 1
|
||||
@@ -33,20 +32,14 @@ class User < ActiveRecord::Base
|
||||
:username => '#{login}'
|
||||
}
|
||||
|
||||
has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name"
|
||||
has_many :members, :dependent => :delete_all
|
||||
has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all
|
||||
has_many :projects, :through => :memberships
|
||||
has_many :custom_values, :dependent => :delete_all, :as => :customized
|
||||
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
|
||||
has_many :changesets, :dependent => :nullify
|
||||
has_one :preference, :dependent => :destroy, :class_name => 'UserPreference'
|
||||
has_one :rss_token, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'"
|
||||
belongs_to :auth_source
|
||||
|
||||
# Active non-anonymous users scope
|
||||
named_scope :active, :conditions => "#{User.table_name}.status = #{STATUS_ACTIVE}"
|
||||
|
||||
acts_as_customizable
|
||||
|
||||
attr_accessor :password, :password_confirmation
|
||||
attr_accessor :last_before_login_on
|
||||
# Prevents unauthorized assignments
|
||||
@@ -58,12 +51,13 @@ class User < ActiveRecord::Base
|
||||
# Login must contain lettres, numbers, underscores only
|
||||
validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i
|
||||
validates_length_of :login, :maximum => 30
|
||||
validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-\.]*$/i
|
||||
validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i
|
||||
validates_length_of :firstname, :lastname, :maximum => 30
|
||||
validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true
|
||||
validates_length_of :mail, :maximum => 60, :allow_nil => true
|
||||
validates_length_of :password, :minimum => 4, :allow_nil => true
|
||||
validates_confirmation_of :password, :allow_nil => true
|
||||
validates_associated :custom_values, :on => :update
|
||||
|
||||
def before_create
|
||||
self.mail_notification = false
|
||||
@@ -74,10 +68,17 @@ class User < ActiveRecord::Base
|
||||
# update hashed_password if password was set
|
||||
self.hashed_password = User.hash_password(self.password) if self.password
|
||||
end
|
||||
|
||||
def self.active
|
||||
with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def reload(*args)
|
||||
@name = nil
|
||||
super
|
||||
def self.find_active(*args)
|
||||
active do
|
||||
find(*args)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the user that matches provided login and password, or nil
|
||||
@@ -99,28 +100,26 @@ class User < ActiveRecord::Base
|
||||
# user is not yet registered, try to authenticate with available sources
|
||||
attrs = AuthSource.authenticate(login, password)
|
||||
if attrs
|
||||
user = new(*attrs)
|
||||
user.login = login
|
||||
user.language = Setting.default_language
|
||||
if user.save
|
||||
user.reload
|
||||
logger.info("User '#{user.login}' created from the LDAP") if logger
|
||||
onthefly = new(*attrs)
|
||||
onthefly.login = login
|
||||
onthefly.language = Setting.default_language
|
||||
if onthefly.save
|
||||
user = find(:first, :conditions => ["login=?", login])
|
||||
logger.info("User '#{user.login}' created on the fly.") if logger
|
||||
end
|
||||
end
|
||||
end
|
||||
user.update_attribute(:last_login_on, Time.now) if user && !user.new_record?
|
||||
user.update_attribute(:last_login_on, Time.now) if user
|
||||
user
|
||||
rescue => text
|
||||
raise text
|
||||
|
||||
rescue => text
|
||||
raise text
|
||||
end
|
||||
|
||||
# Return user's full name for display
|
||||
def name(formatter = nil)
|
||||
if formatter
|
||||
eval('"' + (USER_FORMATS[formatter] || USER_FORMATS[:firstname_lastname]) + '"')
|
||||
else
|
||||
@name ||= eval('"' + (USER_FORMATS[Setting.user_format] || USER_FORMATS[:firstname_lastname]) + '"')
|
||||
end
|
||||
f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname]
|
||||
eval '"' + f + '"'
|
||||
end
|
||||
|
||||
def active?
|
||||
@@ -144,7 +143,7 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def time_zone
|
||||
@time_zone ||= (self.pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[self.pref.time_zone])
|
||||
self.pref.time_zone.nil? ? nil : TimeZone[self.pref.time_zone]
|
||||
end
|
||||
|
||||
def wants_comments_in_reverse_order?
|
||||
@@ -175,24 +174,18 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.find_by_autologin_key(key)
|
||||
tokens = Token.find_all_by_action_and_value('autologin', key)
|
||||
# Make sure there's only 1 token that matches the key
|
||||
if tokens.size == 1
|
||||
token = tokens.first
|
||||
if (token.created_on > Setting.autologin.to_i.day.ago) && token.user && token.user.active?
|
||||
token.user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Makes find_by_mail case-insensitive
|
||||
def self.find_by_mail(mail)
|
||||
find(:first, :conditions => ["LOWER(mail) = ?", mail.to_s.downcase])
|
||||
token = Token.find_by_action_and_value('autologin', key)
|
||||
token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil
|
||||
end
|
||||
|
||||
# Sort users by their display names
|
||||
def <=>(user)
|
||||
self.to_s.downcase <=> user.to_s.downcase
|
||||
if user.nil?
|
||||
-1
|
||||
elsif lastname.to_s.downcase == user.lastname.to_s.downcase
|
||||
firstname.to_s.downcase <=> user.firstname.to_s.downcase
|
||||
else
|
||||
lastname.to_s.downcase <=> user.lastname.to_s.downcase
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
@@ -203,10 +196,6 @@ class User < ActiveRecord::Base
|
||||
true
|
||||
end
|
||||
|
||||
def anonymous?
|
||||
!logged?
|
||||
end
|
||||
|
||||
# Return user's role for project
|
||||
def role_for_project(project)
|
||||
# No role on archived projects
|
||||
@@ -249,7 +238,7 @@ class User < ActiveRecord::Base
|
||||
elsif options[:global]
|
||||
# authorize if user has at least one role that has this permission
|
||||
roles = memberships.collect {|m| m.role}.uniq
|
||||
roles.detect {|r| r.allowed_to?(action)} || (self.logged? ? Role.non_member.allowed_to?(action) : Role.anonymous.allowed_to?(action))
|
||||
roles.detect {|r| r.allowed_to?(action)}
|
||||
else
|
||||
false
|
||||
end
|
||||
@@ -264,12 +253,13 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.anonymous
|
||||
return @anonymous_user if @anonymous_user
|
||||
anonymous_user = AnonymousUser.find(:first)
|
||||
if anonymous_user.nil?
|
||||
anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :mail => '', :login => '', :status => 0)
|
||||
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
|
||||
end
|
||||
anonymous_user
|
||||
@anonymous_user = anonymous_user
|
||||
end
|
||||
|
||||
private
|
||||
@@ -286,10 +276,6 @@ class AnonymousUser < User
|
||||
errors.add_to_base 'An anonymous user already exists.' if AnonymousUser.find(:first)
|
||||
end
|
||||
|
||||
def available_custom_fields
|
||||
[]
|
||||
end
|
||||
|
||||
# Overrides a few properties
|
||||
def logged?; false end
|
||||
def admin; false end
|
||||
|
||||
@@ -42,10 +42,8 @@ class UserPreference < ActiveRecord::Base
|
||||
if attribute_present? attr_name
|
||||
super
|
||||
else
|
||||
h = read_attribute(:others).dup || {}
|
||||
h.update(attr_name => value)
|
||||
write_attribute(:others, h)
|
||||
value
|
||||
self.others ||= {}
|
||||
self.others.store attr_name, value
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -19,13 +19,12 @@ class Version < ActiveRecord::Base
|
||||
before_destroy :check_integrity
|
||||
belongs_to :project
|
||||
has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id'
|
||||
acts_as_attachable :view_permission => :view_files,
|
||||
:delete_permission => :manage_files
|
||||
has_many :attachments, :as => :container, :dependent => :destroy
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name, :scope => [:project_id]
|
||||
validates_length_of :name, :maximum => 60
|
||||
validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => 'activerecord_error_not_a_date', :allow_nil => true
|
||||
validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date, :allow_nil => true
|
||||
|
||||
def start_date
|
||||
effective_date
|
||||
|
||||
@@ -19,12 +19,5 @@ class Watcher < ActiveRecord::Base
|
||||
belongs_to :watchable, :polymorphic => true
|
||||
belongs_to :user
|
||||
|
||||
validates_presence_of :user
|
||||
validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id]
|
||||
|
||||
protected
|
||||
|
||||
def validate
|
||||
errors.add :user_id, :activerecord_error_invalid unless user.nil? || user.active?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
class Wiki < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
has_many :pages, :class_name => 'WikiPage', :dependent => :destroy, :order => 'title'
|
||||
has_many :pages, :class_name => 'WikiPage', :dependent => :destroy
|
||||
has_many :redirects, :class_name => 'WikiRedirect', :dependent => :delete_all
|
||||
|
||||
validates_presence_of :start_page
|
||||
@@ -43,25 +43,6 @@ class Wiki < ActiveRecord::Base
|
||||
page
|
||||
end
|
||||
|
||||
# Finds a page by title
|
||||
# The given string can be of one of the forms: "title" or "project:title"
|
||||
# Examples:
|
||||
# Wiki.find_page("bar", project => foo)
|
||||
# Wiki.find_page("foo:bar")
|
||||
def self.find_page(title, options = {})
|
||||
project = options[:project]
|
||||
if title.to_s =~ %r{^([^\:]+)\:(.*)$}
|
||||
project_identifier, title = $1, $2
|
||||
project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
|
||||
end
|
||||
if project && project.wiki
|
||||
page = project.wiki.find_page(title)
|
||||
if page && page.content
|
||||
page
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# turn a string into a valid page title
|
||||
def self.titleize(title)
|
||||
# replace spaces with _ and remove unwanted caracters
|
||||
|
||||
@@ -22,7 +22,6 @@ class WikiContent < ActiveRecord::Base
|
||||
belongs_to :page, :class_name => 'WikiPage', :foreign_key => 'page_id'
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||
validates_presence_of :text
|
||||
validates_length_of :comments, :maximum => 255, :allow_nil => true
|
||||
|
||||
acts_as_versioned
|
||||
class Version
|
||||
@@ -33,21 +32,8 @@ class WikiContent < ActiveRecord::Base
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"},
|
||||
:description => :comments,
|
||||
:datetime => :updated_on,
|
||||
:type => 'wiki-page',
|
||||
:url => Proc.new {|o| {:controller => 'wiki', :id => o.page.wiki.project_id, :page => o.page.title, :version => o.version}}
|
||||
|
||||
acts_as_activity_provider :type => 'wiki_edits',
|
||||
:timestamp => "#{WikiContent.versioned_table_name}.updated_on",
|
||||
:author_key => "#{WikiContent.versioned_table_name}.author_id",
|
||||
:permission => :view_wiki_edits,
|
||||
:find_options => {:select => "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
|
||||
"#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
|
||||
"#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
|
||||
"#{WikiContent.versioned_table_name}.id",
|
||||
:joins => "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
|
||||
"LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
|
||||
"LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"}
|
||||
|
||||
def text=(plain)
|
||||
case Setting.wiki_compression
|
||||
when 'gzip'
|
||||
|
||||
@@ -21,16 +21,15 @@ require 'enumerator'
|
||||
class WikiPage < ActiveRecord::Base
|
||||
belongs_to :wiki
|
||||
has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy
|
||||
acts_as_attachable :delete_permission => :delete_wiki_pages_attachments
|
||||
acts_as_tree :order => 'title'
|
||||
|
||||
has_many :attachments, :as => :container, :dependent => :destroy
|
||||
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"},
|
||||
:description => :text,
|
||||
:datetime => :created_on,
|
||||
:url => Proc.new {|o| {:controller => 'wiki', :id => o.wiki.project_id, :page => o.title}}
|
||||
|
||||
acts_as_searchable :columns => ['title', 'text'],
|
||||
:include => [{:wiki => :project}, :content],
|
||||
:include => [:wiki, :content],
|
||||
:project_key => "#{Wiki.table_name}.project_id"
|
||||
|
||||
attr_accessor :redirect_existing_links
|
||||
@@ -106,33 +105,6 @@ class WikiPage < ActiveRecord::Base
|
||||
def text
|
||||
content.text if content
|
||||
end
|
||||
|
||||
# Returns true if usr is allowed to edit the page, otherwise false
|
||||
def editable_by?(usr)
|
||||
!protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project)
|
||||
end
|
||||
|
||||
def attachments_deletable?(usr=User.current)
|
||||
editable_by?(usr) && super(usr)
|
||||
end
|
||||
|
||||
def parent_title
|
||||
@parent_title || (self.parent && self.parent.pretty_title)
|
||||
end
|
||||
|
||||
def parent_title=(t)
|
||||
@parent_title = t
|
||||
parent_page = t.blank? ? nil : self.wiki.find_page(t)
|
||||
self.parent = parent_page
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def validate
|
||||
errors.add(:parent_title, :activerecord_error_invalid) if !@parent_title.blank? && parent.nil?
|
||||
errors.add(:parent_title, :activerecord_error_circular_dependency) if parent && (parent == self || parent.ancestors.include?(self))
|
||||
errors.add(:parent_title, :activerecord_error_not_same_project) if parent && (parent.wiki_id != wiki_id)
|
||||
end
|
||||
end
|
||||
|
||||
class WikiDiff
|
||||
|
||||
@@ -21,23 +21,4 @@ class Workflow < ActiveRecord::Base
|
||||
belongs_to :new_status, :class_name => 'IssueStatus', :foreign_key => 'new_status_id'
|
||||
|
||||
validates_presence_of :role, :old_status, :new_status
|
||||
|
||||
# Returns workflow transitions count by tracker and role
|
||||
def self.count_by_tracker_and_role
|
||||
counts = connection.select_all("SELECT role_id, tracker_id, count(id) AS c FROM #{Workflow.table_name} GROUP BY role_id, tracker_id")
|
||||
roles = Role.find(:all, :order => 'builtin, position')
|
||||
trackers = Tracker.find(:all, :order => 'position')
|
||||
|
||||
result = []
|
||||
trackers.each do |tracker|
|
||||
t = []
|
||||
roles.each do |role|
|
||||
row = counts.detect {|c| c['role_id'] == role.id.to_s && c['tracker_id'] == tracker.id.to_s}
|
||||
t << [role, (row.nil? ? 0 : row['c'].to_i)]
|
||||
end
|
||||
result << [tracker, t]
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<div id="login-form">
|
||||
<% form_tag({:action=> "login"}) do %>
|
||||
<%= back_url_hidden_field_tag %>
|
||||
<table>
|
||||
<tr>
|
||||
<td align="right"><label for="username"><%=l(:field_login)%>:</label></td>
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
|
||||
<div class="box">
|
||||
<!--[form:user]-->
|
||||
<% if @user.auth_source_id.nil? %>
|
||||
<p><label for="user_login"><%=l(:field_login)%> <span class="required">*</span></label>
|
||||
<%= text_field 'user', 'login', :size => 25 %></p>
|
||||
<%= text_field 'user', 'login', :size => 25 %></p>
|
||||
|
||||
<p><label for="password"><%=l(:field_password)%> <span class="required">*</span></label>
|
||||
<%= password_field_tag 'password', nil, :size => 25 %><br />
|
||||
@@ -15,7 +14,6 @@
|
||||
|
||||
<p><label for="password_confirmation"><%=l(:field_password_confirmation)%> <span class="required">*</span></label>
|
||||
<%= password_field_tag 'password_confirmation', nil, :size => 25 %></p>
|
||||
<% end %>
|
||||
|
||||
<p><label for="user_firstname"><%=l(:field_firstname)%> <span class="required">*</span></label>
|
||||
<%= text_field 'user', 'firstname' %></p>
|
||||
@@ -29,11 +27,18 @@
|
||||
<p><label for="user_language"><%=l(:field_language)%></label>
|
||||
<%= select("user", "language", lang_options_for_select) %></p>
|
||||
|
||||
<% @user.custom_field_values.each do |value| %>
|
||||
<p><%= custom_field_tag_with_label :user, value %></p>
|
||||
<% for @custom_value in @custom_values %>
|
||||
<p><%= custom_field_tag_with_label @custom_value %></p>
|
||||
<% end %>
|
||||
<!--[eoform:user]-->
|
||||
</div>
|
||||
|
||||
<%= submit_tag l(:button_submit) %>
|
||||
<% end %>
|
||||
|
||||
<% content_for :header_tags do %>
|
||||
<%= javascript_include_tag 'calendar/calendar' %>
|
||||
<%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
|
||||
<%= javascript_include_tag 'calendar/calendar-setup' %>
|
||||
<%= stylesheet_link_tag 'calendar' %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,71 +1,28 @@
|
||||
<div class="contextual">
|
||||
<%= link_to(l(:button_edit), {:controller => 'users', :action => 'edit', :id => @user}, :class => 'icon icon-edit') if User.current.admin? %>
|
||||
</div>
|
||||
<h2><%=h @user.name %></h2>
|
||||
|
||||
<h2><%= avatar @user %> <%=h @user.name %></h2>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<p>
|
||||
<%= mail_to @user.mail unless @user.pref.hide_mail %>
|
||||
<ul>
|
||||
<% unless @user.pref.hide_mail %>
|
||||
<li><%=l(:field_mail)%>: <%= mail_to(h(@user.mail), nil, :encode => 'javascript') %></li>
|
||||
<% end %>
|
||||
<% for custom_value in @custom_values %>
|
||||
<% if !custom_value.value.blank? %>
|
||||
<li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<li><%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %></li>
|
||||
<% unless @user.last_login_on.nil? %>
|
||||
<li><%=l(:field_last_login_on)%>: <%= format_date(@user.last_login_on) %></li>
|
||||
<% end %>
|
||||
<% for custom_value in @custom_values %>
|
||||
<% if !custom_value.value.empty? %>
|
||||
<li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<% unless @memberships.empty? %>
|
||||
<h3><%=l(:label_project_plural)%></h3>
|
||||
<ul>
|
||||
<% for membership in @memberships %>
|
||||
<li><%= link_to(h(membership.project.name), :controller => 'projects', :action => 'show', :id => membership.project) %>
|
||||
(<%=h membership.role.name %>, <%= format_date(membership.created_on) %>)</li>
|
||||
<li><%= link_to membership.project.name, :controller => 'projects', :action => 'show', :id => membership.project %>
|
||||
(<%= membership.role.name %>, <%= format_date(membership.created_on) %>)</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
<%= call_hook :view_account_left_bottom, :user => @user %>
|
||||
</div>
|
||||
|
||||
<div class="splitcontentright">
|
||||
|
||||
<% unless @events_by_day.empty? %>
|
||||
<h3><%= link_to l(:label_activity), :controller => 'projects', :action => 'activity', :user_id => @user, :from => @events_by_day.keys.first %></h3>
|
||||
|
||||
<h3><%=l(:label_activity)%></h3>
|
||||
<p>
|
||||
<%=l(:label_reported_issues)%>: <%= Issue.count(:conditions => ["author_id=?", @user.id]) %>
|
||||
</p>
|
||||
|
||||
<div id="activity">
|
||||
<% @events_by_day.keys.sort.reverse.each do |day| %>
|
||||
<h4><%= format_activity_day(day) %></h4>
|
||||
<dl>
|
||||
<% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| -%>
|
||||
<dt class="<%= e.event_type %>">
|
||||
<span class="time"><%= format_time(e.event_datetime, false) %></span>
|
||||
<%= content_tag('span', h(e.project), :class => 'project') %>
|
||||
<%= link_to format_activity_title(e.event_title), e.event_url %></dt>
|
||||
<dd><span class="description"><%= format_activity_description(e.event_description) %></span></dd>
|
||||
<% end -%>
|
||||
</dl>
|
||||
<% end -%>
|
||||
</div>
|
||||
|
||||
<p class="other-formats">
|
||||
<%= l(:label_export_to) %>
|
||||
<%= link_to 'Atom', {:controller => 'projects', :action => 'activity', :user_id => @user, :format => :atom, :key => User.current.rss_key}, :class => 'feed' %>
|
||||
</p>
|
||||
|
||||
<% content_for :header_tags do %>
|
||||
<%= auto_discovery_link_tag(:atom, :controller => 'projects', :action => 'activity', :user_id => @user, :format => :atom, :key => User.current.rss_key) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= call_hook :view_account_right_bottom, :user => @user %>
|
||||
</div>
|
||||
|
||||
<% html_title @user.name %>
|
||||
</p>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user