Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f01d4ae46 |
@@ -1,33 +0,0 @@
|
||||
# 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
|
||||
# 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 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,
|
||||
:expects => [],
|
||||
:returns => [[AWSProjectWithRepository]]
|
||||
api_method :repository_created,
|
||||
:expects => [:string, :string, :string],
|
||||
:returns => [:int]
|
||||
end
|
||||
@@ -1,195 +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 AccountController < ApplicationController
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
# prevents login action to be filtered by check_if_login_required application scope filter
|
||||
skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register, :activate]
|
||||
|
||||
# Show user's account
|
||||
def show
|
||||
@user = User.active.find(params[:id])
|
||||
@custom_values = @user.custom_values
|
||||
|
||||
# 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)
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Login request and validation
|
||||
def login
|
||||
if request.get?
|
||||
# Logout user
|
||||
self.logged_user = nil
|
||||
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
|
||||
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'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Log out current user and redirect to welcome page
|
||||
def logout
|
||||
cookies.delete :autologin
|
||||
Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) if User.current.logged?
|
||||
self.logged_user = nil
|
||||
redirect_to home_url
|
||||
end
|
||||
|
||||
# Enable user to choose a new password
|
||||
def lost_password
|
||||
redirect_to(home_url) && return unless Setting.lost_password?
|
||||
if params[:token]
|
||||
@token = Token.find_by_action_and_value("recovery", params[:token])
|
||||
redirect_to(home_url) && return unless @token and !@token.expired?
|
||||
@user = @token.user
|
||||
if request.post?
|
||||
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||
if @user.save
|
||||
@token.destroy
|
||||
flash[:notice] = l(:notice_account_password_updated)
|
||||
redirect_to :action => 'login'
|
||||
return
|
||||
end
|
||||
end
|
||||
render :template => "account/password_recovery"
|
||||
return
|
||||
else
|
||||
if request.post?
|
||||
user = User.find_by_mail(params[:mail])
|
||||
# user not found in db
|
||||
flash.now[:error] = l(:notice_account_unknown_email) and return unless user
|
||||
# user uses an external authentification
|
||||
flash.now[:error] = l(:notice_can_t_change_password) and return if user.auth_source_id
|
||||
# create a new token for password recovery
|
||||
token = Token.new(:user => user, :action => "recovery")
|
||||
if token.save
|
||||
Mailer.deliver_lost_password(token)
|
||||
flash[:notice] = l(:notice_account_lost_email_sent)
|
||||
redirect_to :action => 'login'
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# User self-registration
|
||||
def register
|
||||
redirect_to(home_url) && return unless Setting.self_registration? || session[:auth_source_registration]
|
||||
if request.get?
|
||||
session[:auth_source_registration] = nil
|
||||
@user = User.new(:language => Setting.default_language)
|
||||
else
|
||||
@user = User.new(params[:user])
|
||||
@user.admin = false
|
||||
@user.status = User::STATUS_REGISTERED
|
||||
if session[:auth_source_registration]
|
||||
@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'
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Token based account activation
|
||||
def activate
|
||||
redirect_to(home_url) && return unless Setting.self_registration? && params[:token]
|
||||
token = Token.find_by_action_and_value('register', params[:token])
|
||||
redirect_to(home_url) && return unless token and !token.expired?
|
||||
user = token.user
|
||||
redirect_to(home_url) && return unless user.status == User::STATUS_REGISTERED
|
||||
user.status = User::STATUS_ACTIVE
|
||||
if user.save
|
||||
token.destroy
|
||||
flash[:notice] = l(:notice_account_activated)
|
||||
end
|
||||
redirect_to :action => 'login'
|
||||
end
|
||||
|
||||
private
|
||||
def logged_user=(user)
|
||||
if user && user.is_a?(User)
|
||||
User.current = user
|
||||
session[:user_id] = user.id
|
||||
else
|
||||
User.current = User.anonymous
|
||||
session[:user_id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,93 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class AdminController < ApplicationController
|
||||
before_filter :require_admin
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
def index
|
||||
@no_configuration_data = Redmine::DefaultData::Loader::no_data?
|
||||
end
|
||||
|
||||
def projects
|
||||
sort_init 'name', 'asc'
|
||||
sort_update %w(name is_public created_on)
|
||||
|
||||
@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(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name]
|
||||
end
|
||||
|
||||
@project_count = Project.count(:conditions => c.conditions)
|
||||
@project_pages = Paginator.new self, @project_count,
|
||||
per_page_option,
|
||||
params['page']
|
||||
@projects = Project.find :all, :order => sort_clause,
|
||||
:conditions => c.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
|
||||
if request.post?
|
||||
begin
|
||||
Redmine::DefaultData::Loader::load(params[:lang])
|
||||
flash[:notice] = l(:notice_default_data_loaded)
|
||||
rescue Exception => e
|
||||
flash[:error] = l(:error_can_t_load_default_data, e.message)
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def test_email
|
||||
raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
|
||||
# Force ActionMailer to raise delivery errors so we can catch it
|
||||
ActionMailer::Base.raise_delivery_errors = true
|
||||
begin
|
||||
@test = Mailer.deliver_test(User.current)
|
||||
flash[:notice] = l(:notice_email_sent, User.current.mail)
|
||||
rescue Exception => e
|
||||
flash[:error] = l(:notice_email_error, e.message)
|
||||
end
|
||||
ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
|
||||
redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications'
|
||||
end
|
||||
|
||||
def info
|
||||
@db_adapter_name = ActiveRecord::Base.connection.adapter_name
|
||||
@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)
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -1,234 +0,0 @@
|
||||
# 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
|
||||
# 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 'uri'
|
||||
require 'cgi'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
layout 'base'
|
||||
|
||||
before_filter :user_setup, :check_if_login_required, :set_localization
|
||||
filter_parameter_logging :password
|
||||
|
||||
include Redmine::MenuManager::MenuController
|
||||
helper Redmine::MenuManager::MenuHelper
|
||||
|
||||
REDMINE_SUPPORTED_SCM.each do |scm|
|
||||
require_dependency "repository/#{scm.underscore}"
|
||||
end
|
||||
|
||||
def current_role
|
||||
@current_role ||= User.current.role_for_project(@project)
|
||||
end
|
||||
|
||||
def user_setup
|
||||
# Check the settings cache for each request
|
||||
Setting.check_cache
|
||||
# Find the current user
|
||||
User.current = find_current_user
|
||||
end
|
||||
|
||||
# Returns the current user or nil if no user is logged in
|
||||
def find_current_user
|
||||
if session[:user_id]
|
||||
# existing session
|
||||
(User.active.find(session[:user_id]) rescue nil)
|
||||
elsif cookies[:autologin] && Setting.autologin?
|
||||
# auto-login feature
|
||||
User.find_by_autologin_key(cookies[:autologin])
|
||||
elsif params[:key] && accept_key_auth_actions.include?(params[:action])
|
||||
# RSS key authentication
|
||||
User.find_by_rss_key(params[:key])
|
||||
end
|
||||
end
|
||||
|
||||
# check if login is globally required to access the application
|
||||
def check_if_login_required
|
||||
# no check needed if user is already logged in
|
||||
return true if User.current.logged?
|
||||
require_login if Setting.login_required?
|
||||
end
|
||||
|
||||
def set_localization
|
||||
User.current.language = nil unless User.current.logged?
|
||||
lang = begin
|
||||
if !User.current.language.blank? && GLoc.valid_language?(User.current.language)
|
||||
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))
|
||||
User.current.language = accept_lang
|
||||
end
|
||||
end
|
||||
rescue
|
||||
nil
|
||||
end || Setting.default_language
|
||||
set_language_if_valid(lang)
|
||||
end
|
||||
|
||||
def require_login
|
||||
if !User.current.logged?
|
||||
redirect_to :controller => "account", :action => "login", :back_url => url_for(params)
|
||||
return false
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def require_admin
|
||||
return unless require_login
|
||||
if !User.current.admin?
|
||||
render_403
|
||||
return false
|
||||
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
|
||||
end
|
||||
|
||||
# make sure that the user is a member of the project (or admin) if project is private
|
||||
# used as a before_filter for actions that do not require any particular permission on the project
|
||||
def check_project_privacy
|
||||
if @project && @project.active?
|
||||
if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
|
||||
true
|
||||
else
|
||||
User.current.logged? ? render_403 : require_login
|
||||
end
|
||||
else
|
||||
@project = nil
|
||||
render_404
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
redirect_to default
|
||||
end
|
||||
|
||||
def render_403
|
||||
@project = nil
|
||||
render :template => "common/403", :layout => !request.xhr?, :status => 403
|
||||
return false
|
||||
end
|
||||
|
||||
def render_404
|
||||
render :template => "common/404", :layout => !request.xhr?, :status => 404
|
||||
return false
|
||||
end
|
||||
|
||||
def render_error(msg)
|
||||
flash.now[:error] = msg
|
||||
render :nothing => true, :layout => !request.xhr?, :status => 500
|
||||
end
|
||||
|
||||
def render_feed(items, options={})
|
||||
@items = items || []
|
||||
@items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
|
||||
@items = @items.slice(0, Setting.feeds_limit.to_i)
|
||||
@title = options[:title] || Setting.app_title
|
||||
render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
|
||||
end
|
||||
|
||||
def self.accept_key_auth(*actions)
|
||||
actions = actions.flatten.map(&:to_s)
|
||||
write_inheritable_attribute('accept_key_auth_actions', actions)
|
||||
end
|
||||
|
||||
def accept_key_auth_actions
|
||||
self.class.read_inheritable_attribute('accept_key_auth_actions') || []
|
||||
end
|
||||
|
||||
# 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']
|
||||
next unless file && file.size > 0
|
||||
a = Attachment.create(:container => obj,
|
||||
: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)
|
||||
end
|
||||
end
|
||||
attached
|
||||
end
|
||||
|
||||
# Returns the number of objects that should be displayed
|
||||
# on the paginated list
|
||||
def per_page_option
|
||||
per_page = nil
|
||||
if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
|
||||
per_page = params[:per_page].to_s.to_i
|
||||
session[:per_page] = per_page
|
||||
elsif session[:per_page]
|
||||
per_page = session[:per_page]
|
||||
else
|
||||
per_page = Setting.per_page_options_array.first || 25
|
||||
end
|
||||
per_page
|
||||
end
|
||||
|
||||
# qvalues http header parser
|
||||
# code taken from webrick
|
||||
def parse_qvalues(value)
|
||||
tmp = []
|
||||
if value
|
||||
parts = value.split(/,\s*/)
|
||||
parts.each {|part|
|
||||
if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
|
||||
val = m[1]
|
||||
q = (m[2] or 1).to_f
|
||||
tmp.push([val, q])
|
||||
end
|
||||
}
|
||||
tmp = tmp.sort_by{|val, q| -q}
|
||||
tmp.collect!{|val, q| val}
|
||||
end
|
||||
return tmp
|
||||
end
|
||||
|
||||
# Returns a string that can be used as filename value in Content-Disposition header
|
||||
def filename_for_content_disposition(name)
|
||||
request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
|
||||
end
|
||||
end
|
||||
@@ -1,74 +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 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
|
||||
|
||||
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')
|
||||
|
||||
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
|
||||
render_404
|
||||
end
|
||||
|
||||
def read_authorize
|
||||
@attachment.visible? ? true : deny_access
|
||||
end
|
||||
|
||||
def delete_authorize
|
||||
@attachment.deletable? ? true : deny_access
|
||||
end
|
||||
end
|
||||
@@ -1,87 +0,0 @@
|
||||
# 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
|
||||
# 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 BoardsController < ApplicationController
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
helper :messages
|
||||
include MessagesHelper
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :watchers
|
||||
include WatchersHelper
|
||||
|
||||
def index
|
||||
@boards = @project.boards
|
||||
# show the board if there is only one
|
||||
if @boards.size == 1
|
||||
@board = @boards.first
|
||||
show
|
||||
end
|
||||
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"
|
||||
|
||||
@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(', '),
|
||||
:include => [:author, {:last_reply => :author}],
|
||||
:limit => @topic_pages.items_per_page,
|
||||
:offset => @topic_pages.current.offset
|
||||
render :action => 'show', :layout => !request.xhr?
|
||||
end
|
||||
|
||||
verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
|
||||
|
||||
def new
|
||||
@board = Board.new(params[:board])
|
||||
@board.project = @project
|
||||
if request.post? && @board.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
if request.post? && @board.update_attributes(params[:board])
|
||||
case params[:position]
|
||||
when 'highest'; @board.move_to_top
|
||||
when 'higher'; @board.move_higher
|
||||
when 'lower'; @board.move_lower
|
||||
when 'lowest'; @board.move_to_bottom
|
||||
end if params[:position]
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@board.destroy
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id])
|
||||
@board = @project.boards.find(params[:id]) if params[:id]
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -1,88 +0,0 @@
|
||||
# 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
|
||||
# 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 DocumentsController < ApplicationController
|
||||
before_filter :find_project, :only => [:index, :new]
|
||||
before_filter :find_document, :except => [:index, :new]
|
||||
before_filter :authorize
|
||||
|
||||
helper :attachments
|
||||
|
||||
def index
|
||||
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
|
||||
documents = @project.documents.find :all, :include => [:attachments, :category]
|
||||
case @sort_by
|
||||
when 'date'
|
||||
@grouped = documents.group_by {|d| d.created_on.to_date }
|
||||
when 'title'
|
||||
@grouped = documents.group_by {|d| d.title.first.upcase}
|
||||
when 'author'
|
||||
@grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
|
||||
else
|
||||
@grouped = documents.group_by(&:category)
|
||||
end
|
||||
@document = @project.documents.build
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def show
|
||||
@attachments = @document.attachments.find(:all, :order => "created_on DESC")
|
||||
end
|
||||
|
||||
def new
|
||||
@document = @project.documents.build(params[:document])
|
||||
if request.post? and @document.save
|
||||
attach_files(@document, params[:attachments])
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
|
||||
redirect_to :action => 'index', :project_id => @project
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@categories = Enumeration::get_values('DCAT')
|
||||
if request.post? and @document.update_attributes(params[:document])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'show', :id => @document
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@document.destroy
|
||||
redirect_to :controller => 'documents', :action => 'index', :project_id => @project
|
||||
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
|
||||
|
||||
private
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_document
|
||||
@document = Document.find(params[:id])
|
||||
@project = @document.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -1,58 +0,0 @@
|
||||
# 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
|
||||
# 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 IssueRelationsController < ApplicationController
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
def new
|
||||
@relation = IssueRelation.new(params[:relation])
|
||||
@relation.issue_from = @issue
|
||||
@relation.save if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
||||
format.js do
|
||||
render :update do |page|
|
||||
page.replace_html "relations", :partial => 'issues/relations'
|
||||
if @relation.errors.empty?
|
||||
page << "$('relation_delay').value = ''"
|
||||
page << "$('relation_issue_to_id').value = ''"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
relation = IssueRelation.find(params[:id])
|
||||
if request.post? && @issue.relations.include?(relation)
|
||||
relation.destroy
|
||||
@issue.reload
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
||||
format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@issue = Issue.find(params[:issue_id])
|
||||
@project = @issue.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -1,489 +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 IssuesController < ApplicationController
|
||||
menu_item :new_issue, :only => :new
|
||||
|
||||
before_filter :find_issue, :only => [:show, :edit, :reply]
|
||||
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
|
||||
|
||||
helper :journals
|
||||
helper :projects
|
||||
include ProjectsHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
helper :issue_relations
|
||||
include IssueRelationsHelper
|
||||
helper :watchers
|
||||
include WatchersHelper
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
helper :queries
|
||||
helper :sort
|
||||
include SortHelper
|
||||
include IssuesHelper
|
||||
helper :timelog
|
||||
include Redmine::Export::PDF
|
||||
|
||||
def index
|
||||
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|
|
||||
format.html { }
|
||||
format.atom { }
|
||||
format.csv { limit = Setting.issues_export_limit.to_i }
|
||||
format.pdf { limit = Setting.issues_export_limit.to_i }
|
||||
end
|
||||
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
|
||||
@issue_pages = Paginator.new self, @issue_count, limit, params['page']
|
||||
@issues = Issue.find :all, :order => sort_clause,
|
||||
:include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
|
||||
:conditions => @query.statement,
|
||||
:limit => limit,
|
||||
: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.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') }
|
||||
end
|
||||
else
|
||||
# Send html if the query is not valid
|
||||
render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def changes
|
||||
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,
|
||||
:limit => 25,
|
||||
:order => "#{Journal.table_name}.created_on DESC"
|
||||
end
|
||||
@title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
|
||||
render :layout => false, :content_type => 'application/atom+xml'
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def show
|
||||
@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)
|
||||
@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") }
|
||||
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.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)
|
||||
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
|
||||
flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
|
||||
render :nothing => true, :layout => true
|
||||
return
|
||||
end
|
||||
@issue.status = default_status
|
||||
@allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq
|
||||
|
||||
if request.get? || request.xhr?
|
||||
@issue.start_date ||= Date.today
|
||||
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
|
||||
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')
|
||||
redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
|
||||
{ :action => 'show', :id => @issue })
|
||||
return
|
||||
end
|
||||
end
|
||||
@priorities = Enumeration::get_values('IPRI')
|
||||
render :layout => !request.xhr?
|
||||
end
|
||||
|
||||
# Attributes that can be updated on workflow transition (without :edit permission)
|
||||
# TODO: make it configurable (at least per role)
|
||||
UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
|
||||
|
||||
def edit
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
@priorities = Enumeration::get_values('IPRI')
|
||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||
@time_entry = TimeEntry.new
|
||||
|
||||
@notes = params[:notes]
|
||||
journal = @issue.init_journal(User.current, @notes)
|
||||
# User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
|
||||
if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
|
||||
attrs = params[:issue].dup
|
||||
attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
|
||||
attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
|
||||
@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]
|
||||
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
|
||||
# Log spend time
|
||||
if User.current.allowed_to?(:log_time, @project)
|
||||
@time_entry.save
|
||||
end
|
||||
if !journal.new_record?
|
||||
# Only send notification if something was actually changed
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
||||
end
|
||||
redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
# Optimistic locking exception
|
||||
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?
|
||||
status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
|
||||
priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
|
||||
assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
|
||||
category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
|
||||
fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
|
||||
|
||||
unsaved_issue_ids = []
|
||||
@issues.each do |issue|
|
||||
journal = issue.init_journal(User.current, params[:notes])
|
||||
issue.priority = priority if priority
|
||||
issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
|
||||
issue.category = category if category || params[:category_id] == 'none'
|
||||
issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
|
||||
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)
|
||||
Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
|
||||
else
|
||||
# Keep unsaved issue ids to display them in flash error
|
||||
unsaved_issue_ids << issue.id
|
||||
end
|
||||
end
|
||||
if unsaved_issue_ids.empty?
|
||||
flash[:notice] = l(:notice_successful_update) unless @issues.empty?
|
||||
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})
|
||||
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
|
||||
end
|
||||
|
||||
def move
|
||||
@allowed_projects = []
|
||||
# find projects to which the user is allowed to move the issue
|
||||
if User.current.admin?
|
||||
# admin is allowed to move issues to any active (visible) project
|
||||
@allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
|
||||
else
|
||||
User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)}
|
||||
end
|
||||
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
|
||||
@target_project ||= @project
|
||||
@trackers = @target_project.trackers
|
||||
if request.post?
|
||||
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?
|
||||
flash[:notice] = l(:notice_successful_update) unless @issues.empty?
|
||||
else
|
||||
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
|
||||
end
|
||||
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
|
||||
return
|
||||
end
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def destroy
|
||||
@hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
|
||||
if @hours > 0
|
||||
case params[:todo]
|
||||
when 'destroy'
|
||||
# nothing to do
|
||||
when 'nullify'
|
||||
TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
|
||||
when 'reassign'
|
||||
reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
|
||||
if reassign_to.nil?
|
||||
flash.now[:error] = l(:error_issue_not_found_in_project)
|
||||
return
|
||||
else
|
||||
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
|
||||
end
|
||||
else
|
||||
# display the destroy form
|
||||
return
|
||||
end
|
||||
end
|
||||
@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?
|
||||
end
|
||||
|
||||
def context_menu
|
||||
@issues = Issue.find_all_by_id(params[:ids], :include => :project)
|
||||
if (@issues.size == 1)
|
||||
@issue = @issues.first
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
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?))),
|
||||
: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']
|
||||
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def update_form
|
||||
@issue = Issue.new(params[:issue])
|
||||
render :action => :new, :layout => false
|
||||
end
|
||||
|
||||
def preview
|
||||
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
||||
@attachements = @issue.attachments if @issue
|
||||
@text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
private
|
||||
def find_issue
|
||||
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
|
||||
@project = @issue.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Filter for bulk operations
|
||||
def find_issues
|
||||
@issues = Issue.find_all_by_id(params[:id] || params[:ids])
|
||||
raise ActiveRecord::RecordNotFound if @issues.empty?
|
||||
projects = @issues.collect(&:project).compact.uniq
|
||||
if projects.size == 1
|
||||
@project = projects.first
|
||||
else
|
||||
# TODO: let users bulk edit/move/destroy issues from different projects
|
||||
render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
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
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Retrieve query from session or build a new query
|
||||
def retrieve_query
|
||||
if !params[:query_id].blank?
|
||||
cond = "project_id IS NULL"
|
||||
cond << " OR project_id = #{@project.id}" if @project
|
||||
@query = Query.find(params[:query_id], :conditions => cond)
|
||||
@query.project = @project
|
||||
session[:query] = {:id => @query.id, :project_id => @query.project_id}
|
||||
else
|
||||
if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
|
||||
# Give it a name, required to be valid
|
||||
@query = Query.new(:name => "_")
|
||||
@query.project = @project
|
||||
if params[:fields] and params[:fields].is_a? Array
|
||||
params[:fields].each do |field|
|
||||
@query.add_filter(field, params[:operators][field], params[:values][field])
|
||||
end
|
||||
else
|
||||
@query.available_filters.keys.each do |field|
|
||||
@query.add_short_filter(field, params[field]) if params[field]
|
||||
end
|
||||
end
|
||||
session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
|
||||
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
|
||||
end
|
||||
@@ -1,41 +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 JournalsController < ApplicationController
|
||||
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' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_journal
|
||||
@journal = Journal.find(params[:id])
|
||||
render_403 and return false unless @journal.editable_by?(User.current)
|
||||
@project = @journal.journalized.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
@@ -1,61 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class MembersController < ApplicationController
|
||||
before_filter :find_member, :except => :new
|
||||
before_filter :find_project, :only => :new
|
||||
before_filter :authorize
|
||||
|
||||
def new
|
||||
@project.members << Member.new(params[:member]) if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project }
|
||||
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
if request.post? and @member.update_attributes(params[:member])
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
|
||||
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@member.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
|
||||
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_member
|
||||
@member = Member.find(params[:id])
|
||||
@project = @member.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -1,125 +0,0 @@
|
||||
# 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
|
||||
# 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 MessagesController < ApplicationController
|
||||
menu_item :boards
|
||||
before_filter :find_board, :only => [:new, :preview]
|
||||
before_filter :find_message, :except => [:new, :preview]
|
||||
before_filter :authorize, :except => [:preview, :edit, :destroy]
|
||||
|
||||
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.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||
render :action => "show", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
# Create a new topic
|
||||
def new
|
||||
@message = Message.new(params[:message])
|
||||
@message.author = User.current
|
||||
@message.board = @board
|
||||
if params[:message] && User.current.allowed_to?(:edit_messages, @project)
|
||||
@message.locked = params[:message]['locked']
|
||||
@message.sticky = params[:message]['sticky']
|
||||
end
|
||||
if request.post? && @message.save
|
||||
attach_files(@message, params[:attachments])
|
||||
redirect_to :action => 'show', :id => @message
|
||||
end
|
||||
end
|
||||
|
||||
# Reply to a topic
|
||||
def reply
|
||||
@reply = Message.new(params[:reply])
|
||||
@reply.author = User.current
|
||||
@reply.board = @board
|
||||
@topic.children << @reply
|
||||
if !@reply.new_record?
|
||||
attach_files(@reply, params[:attachments])
|
||||
end
|
||||
redirect_to :action => 'show', :id => @topic
|
||||
end
|
||||
|
||||
# Edit a message
|
||||
def edit
|
||||
render_403 and return false unless @message.editable_by?(User.current)
|
||||
if params[:message]
|
||||
@message.locked = params[:message]['locked']
|
||||
@message.sticky = params[:message]['sticky']
|
||||
end
|
||||
if request.post? && @message.update_attributes(params[:message])
|
||||
attach_files(@message, params[:attachments])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'show', :id => @topic
|
||||
end
|
||||
end
|
||||
|
||||
# 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
|
||||
@text = (params[:message] || params[:reply])[:content]
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
private
|
||||
def find_message
|
||||
find_board
|
||||
@message = @board.messages.find(params[:id], :include => :parent)
|
||||
@topic = @message.root
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_board
|
||||
@board = Board.find(params[:board_id], :include => :project)
|
||||
@project = @board.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -1,160 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class MyController < ApplicationController
|
||||
before_filter :require_login
|
||||
|
||||
helper :issues
|
||||
|
||||
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
||||
'issuesreportedbyme' => :label_reported_issues,
|
||||
'issueswatched' => :label_watched_issues,
|
||||
'news' => :label_news_latest,
|
||||
'calendar' => :label_calendar,
|
||||
'documents' => :label_document_plural,
|
||||
'timelog' => :label_spent_time
|
||||
}.freeze
|
||||
|
||||
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
|
||||
'right' => ['issuesreportedbyme']
|
||||
}.freeze
|
||||
|
||||
verify :xhr => true,
|
||||
:session => :page_layout,
|
||||
:only => [:add_block, :remove_block, :order_blocks]
|
||||
|
||||
def index
|
||||
page
|
||||
render :action => 'page'
|
||||
end
|
||||
|
||||
# Show user's page
|
||||
def page
|
||||
@user = User.current
|
||||
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
|
||||
end
|
||||
|
||||
# Edit user's account
|
||||
def account
|
||||
@user = User.current
|
||||
@pref = @user.pref
|
||||
if request.post?
|
||||
@user.attributes = params[:user]
|
||||
@user.mail_notification = (params[:notification_option] == 'all')
|
||||
@user.pref.attributes = params[:pref]
|
||||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
||||
if @user.save
|
||||
@user.pref.save
|
||||
@user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
|
||||
set_language_if_valid @user.language
|
||||
flash[:notice] = l(:notice_account_updated)
|
||||
redirect_to :action => 'account'
|
||||
return
|
||||
end
|
||||
end
|
||||
@notification_options = [[l(:label_user_mail_option_all), 'all'],
|
||||
[l(:label_user_mail_option_none), 'none']]
|
||||
# Only users that belong to more than 1 project can select projects for which they are notified
|
||||
# Note that @user.membership.size would fail since AR ignores :include association option when doing a count
|
||||
@notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
|
||||
@notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
|
||||
end
|
||||
|
||||
# Manage user's password
|
||||
def password
|
||||
@user = User.current
|
||||
flash[:error] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
|
||||
if request.post?
|
||||
if @user.check_password?(params[:password])
|
||||
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||
if @user.save
|
||||
flash[:notice] = l(:notice_account_password_updated)
|
||||
redirect_to :action => 'account'
|
||||
end
|
||||
else
|
||||
flash[:error] = l(:notice_account_wrong_password)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Create a new feeds key
|
||||
def reset_rss_key
|
||||
if request.post? && User.current.rss_token
|
||||
User.current.rss_token.destroy
|
||||
flash[:notice] = l(:notice_feeds_access_key_reseted)
|
||||
end
|
||||
redirect_to :action => 'account'
|
||||
end
|
||||
|
||||
# User's page layout configuration
|
||||
def page_layout
|
||||
@user = User.current
|
||||
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
||||
session[:page_layout] = @blocks
|
||||
%w(top left right).each {|f| session[:page_layout][f] ||= [] }
|
||||
@block_options = []
|
||||
BLOCKS.each {|k, v| @block_options << [l(v), k]}
|
||||
end
|
||||
|
||||
# Add a block to user's page
|
||||
# The block is added on top of the page
|
||||
# params[:block] : id of the block to add
|
||||
def add_block
|
||||
block = params[:block]
|
||||
render(:nothing => true) and return unless block && (BLOCKS.keys.include? block)
|
||||
@user = User.current
|
||||
# remove if already present in a group
|
||||
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
||||
# add it on top
|
||||
session[:page_layout]['top'].unshift block
|
||||
render :partial => "block", :locals => {:user => @user, :block_name => block}
|
||||
end
|
||||
|
||||
# Remove a block to user's page
|
||||
# params[:block] : id of the block to remove
|
||||
def remove_block
|
||||
block = params[:block]
|
||||
# remove block in all groups
|
||||
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
# Change blocks order on user's page
|
||||
# params[:group] : group to order (top, left or right)
|
||||
# params[:list-(top|left|right)] : array of block ids of the group
|
||||
def order_blocks
|
||||
group = params[:group]
|
||||
group_items = params["list-#{group}"]
|
||||
if group_items and group_items.is_a? Array
|
||||
# remove group blocks if they are presents in other groups
|
||||
%w(top left right).each {|f|
|
||||
session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
|
||||
}
|
||||
session[:page_layout][group] = group_items
|
||||
end
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
# Save user's page layout
|
||||
def page_layout_save
|
||||
@user = User.current
|
||||
@user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
|
||||
@user.pref.save
|
||||
session[:page_layout] = nil
|
||||
redirect_to :action => 'page'
|
||||
end
|
||||
end
|
||||
@@ -1,108 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class NewsController < ApplicationController
|
||||
before_filter :find_news, :except => [:new, :index, :preview]
|
||||
before_filter :find_project, :only => [:new, :preview]
|
||||
before_filter :authorize, :except => [:index, :preview]
|
||||
before_filter :find_optional_project, :only => :index
|
||||
accept_key_auth :index
|
||||
|
||||
def index
|
||||
@news_pages, @newss = paginate :news,
|
||||
:per_page => 10,
|
||||
:conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
|
||||
:include => [:author, :project],
|
||||
:order => "#{News.table_name}.created_on DESC"
|
||||
respond_to do |format|
|
||||
format.html { render :layout => false if request.xhr? }
|
||||
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@comments = @news.comments
|
||||
@comments.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
end
|
||||
|
||||
def new
|
||||
@news = News.new(:project => @project, :author => User.current)
|
||||
if request.post?
|
||||
@news.attributes = params[:news]
|
||||
if @news.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
|
||||
redirect_to :controller => 'news', :action => 'index', :project_id => @project
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
if request.post? and @news.update_attributes(params[:news])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'show', :id => @news
|
||||
end
|
||||
end
|
||||
|
||||
def add_comment
|
||||
@comment = Comment.new(params[:comment])
|
||||
@comment.author = User.current
|
||||
if @news.comments << @comment
|
||||
flash[:notice] = l(:label_comment_added)
|
||||
redirect_to :action => 'show', :id => @news
|
||||
else
|
||||
render :action => 'show'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_comment
|
||||
@news.comments.find(params[:comment_id]).destroy
|
||||
redirect_to :action => 'show', :id => @news
|
||||
end
|
||||
|
||||
def destroy
|
||||
@news.destroy
|
||||
redirect_to :action => 'index', :project_id => @project
|
||||
end
|
||||
|
||||
def preview
|
||||
@text = (params[:news] ? params[:news][:description] : nil)
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
private
|
||||
def find_news
|
||||
@news = News.find(params[:id])
|
||||
@project = @news.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_optional_project
|
||||
return true unless params[:project_id]
|
||||
@project = Project.find(params[:project_id])
|
||||
authorize
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -1,296 +0,0 @@
|
||||
# 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
|
||||
# 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 ProjectsController < ApplicationController
|
||||
menu_item :overview
|
||||
menu_item :activity, :only => :activity
|
||||
menu_item :roadmap, :only => :roadmap
|
||||
menu_item :files, :only => [:list_files, :add_file]
|
||||
menu_item :settings, :only => :settings
|
||||
menu_item :issues, :only => [:changelog]
|
||||
|
||||
before_filter :find_project, :except => [ :index, :list, :add, :activity ]
|
||||
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
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
helper :issues
|
||||
helper IssuesHelper
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :repositories
|
||||
include RepositoriesHelper
|
||||
include ProjectsHelper
|
||||
|
||||
# Lists visible projects
|
||||
def index
|
||||
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
|
||||
end
|
||||
|
||||
# Add a new project
|
||||
def add
|
||||
@issue_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])
|
||||
if request.get?
|
||||
@project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
|
||||
@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]
|
||||
if @project.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :controller => 'admin', :action => 'projects'
|
||||
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
|
||||
|
||||
@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))
|
||||
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
||||
@trackers = @project.rolled_up_trackers
|
||||
|
||||
cond = @project.project_condition(Setting.display_subprojects_issues?)
|
||||
Issue.visible_by(User.current) do
|
||||
@open_issues_by_tracker = Issue.count(:group => :tracker,
|
||||
:include => [:project, :status, :tracker],
|
||||
:conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
|
||||
@total_issues_by_tracker = Issue.count(:group => :tracker,
|
||||
:include => [:project, :status, :tracker],
|
||||
:conditions => cond)
|
||||
end
|
||||
TimeEntry.visible_by(User.current) do
|
||||
@total_hours = TimeEntry.sum(:hours,
|
||||
:include => :project,
|
||||
:conditions => cond).to_f
|
||||
end
|
||||
@key = User.current.rss_key
|
||||
end
|
||||
|
||||
def settings
|
||||
@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")
|
||||
@issue_category ||= IssueCategory.new
|
||||
@member ||= @project.members.new
|
||||
@trackers = Tracker.all
|
||||
@repository ||= @project.repository
|
||||
@wiki ||= @project.wiki
|
||||
end
|
||||
|
||||
# Edit @project
|
||||
def edit
|
||||
if request.post?
|
||||
@project.attributes = params[:project]
|
||||
if @project.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'settings', :id => @project
|
||||
else
|
||||
settings
|
||||
render :action => 'settings'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def modules
|
||||
@project.enabled_module_names = params[:enabled_modules]
|
||||
redirect_to :action => 'settings', :id => @project, :tab => 'modules'
|
||||
end
|
||||
|
||||
def archive
|
||||
@project.archive if request.post? && @project.active?
|
||||
redirect_to :controller => 'admin', :action => 'projects'
|
||||
end
|
||||
|
||||
def unarchive
|
||||
@project.unarchive if request.post? && !@project.active?
|
||||
redirect_to :controller => 'admin', :action => 'projects'
|
||||
end
|
||||
|
||||
# Delete @project
|
||||
def destroy
|
||||
@project_to_destroy = @project
|
||||
if request.post? and params[:confirm]
|
||||
@project_to_destroy.destroy
|
||||
redirect_to :controller => 'admin', :action => 'projects'
|
||||
end
|
||||
# hide project in layout
|
||||
@project = nil
|
||||
end
|
||||
|
||||
# Add a new issue category to @project
|
||||
def add_issue_category
|
||||
@category = @project.issue_categories.build(params[:category])
|
||||
if request.post? and @category.save
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'settings', :tab => 'categories', :id => @project
|
||||
end
|
||||
format.js do
|
||||
# IE doesn't support the replace_html rjs method for select box options
|
||||
render(:update) {|page| page.replace "issue_category_id",
|
||||
content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Add a new version to @project
|
||||
def add_version
|
||||
@version = @project.versions.build(params[:version])
|
||||
if request.post? and @version.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'settings', :tab => 'versions', :id => @project
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
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?
|
||||
end
|
||||
|
||||
# Show changelog for @project
|
||||
def changelog
|
||||
@trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
|
||||
retrieve_selected_tracker_ids(@trackers)
|
||||
@versions = @project.versions.sort
|
||||
end
|
||||
|
||||
def roadmap
|
||||
@trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
|
||||
retrieve_selected_tracker_ids(@trackers)
|
||||
@versions = @project.versions.sort
|
||||
@versions = @versions.select {|v| !v.completed? } unless params[:completed]
|
||||
end
|
||||
|
||||
def activity
|
||||
@days = Setting.activity_days_default.to_i
|
||||
|
||||
if params[:from]
|
||||
begin; @date_to = params[:from].to_date + 1; 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)
|
||||
|
||||
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}")
|
||||
}
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
private
|
||||
# Find project of id params[:id]
|
||||
# if not found, redirect to project list
|
||||
# Used as a before_filter
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_optional_project
|
||||
return true unless params[:id]
|
||||
@project = Project.find(params[:id])
|
||||
authorize
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def retrieve_selected_tracker_ids(selectable_trackers)
|
||||
if ids = params[:tracker_ids]
|
||||
@selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
|
||||
else
|
||||
@selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,80 +0,0 @@
|
||||
# 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
|
||||
# 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 QueriesController < ApplicationController
|
||||
menu_item :issues
|
||||
before_filter :find_query, :except => :new
|
||||
before_filter :find_optional_project, :only => :new
|
||||
|
||||
def new
|
||||
@query = Query.new(params[:query])
|
||||
@query.project = params[:query_is_for_all] ? nil : @project
|
||||
@query.user = User.current
|
||||
@query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
|
||||
@query.column_names = nil if params[:default_columns]
|
||||
|
||||
params[:fields].each do |field|
|
||||
@query.add_filter(field, params[:operators][field], params[:values][field])
|
||||
end if params[:fields]
|
||||
|
||||
if request.post? && params[:confirm] && @query.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
|
||||
return
|
||||
end
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def edit
|
||||
if request.post?
|
||||
@query.filters = {}
|
||||
params[:fields].each do |field|
|
||||
@query.add_filter(field, params[:operators][field], params[:values][field])
|
||||
end if params[:fields]
|
||||
@query.attributes = params[:query]
|
||||
@query.project = nil if params[:query_is_for_all]
|
||||
@query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
|
||||
@query.column_names = nil if params[:default_columns]
|
||||
|
||||
if @query.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@query.destroy if request.post?
|
||||
redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
|
||||
end
|
||||
|
||||
private
|
||||
def find_query
|
||||
@query = Query.find(params[:id])
|
||||
@project = @query.project
|
||||
render_403 unless @query.editable_by?(User.current)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_optional_project
|
||||
@project = Project.find(params[:project_id]) if params[:project_id]
|
||||
User.current.allowed_to?(:save_queries, @project, :global => true)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -1,236 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class ReportsController < ApplicationController
|
||||
menu_item :issues
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
def issue_report
|
||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||
|
||||
case params[:detail]
|
||||
when "tracker"
|
||||
@field = "tracker_id"
|
||||
@rows = @project.trackers
|
||||
@data = issues_by_tracker
|
||||
@report_title = l(:field_tracker)
|
||||
render :template => "reports/issue_report_details"
|
||||
when "version"
|
||||
@field = "fixed_version_id"
|
||||
@rows = @project.versions.sort
|
||||
@data = issues_by_version
|
||||
@report_title = l(:field_version)
|
||||
render :template => "reports/issue_report_details"
|
||||
when "priority"
|
||||
@field = "priority_id"
|
||||
@rows = Enumeration::get_values('IPRI')
|
||||
@data = issues_by_priority
|
||||
@report_title = l(:field_priority)
|
||||
render :template => "reports/issue_report_details"
|
||||
when "category"
|
||||
@field = "category_id"
|
||||
@rows = @project.issue_categories
|
||||
@data = issues_by_category
|
||||
@report_title = l(:field_category)
|
||||
render :template => "reports/issue_report_details"
|
||||
when "assigned_to"
|
||||
@field = "assigned_to_id"
|
||||
@rows = @project.members.collect { |m| m.user }
|
||||
@data = issues_by_assigned_to
|
||||
@report_title = l(:field_assigned_to)
|
||||
render :template => "reports/issue_report_details"
|
||||
when "author"
|
||||
@field = "author_id"
|
||||
@rows = @project.members.collect { |m| m.user }
|
||||
@data = issues_by_author
|
||||
@report_title = l(:field_author)
|
||||
render :template => "reports/issue_report_details"
|
||||
when "subproject"
|
||||
@field = "project_id"
|
||||
@rows = @project.active_children
|
||||
@data = issues_by_subproject
|
||||
@report_title = l(:field_subproject)
|
||||
render :template => "reports/issue_report_details"
|
||||
else
|
||||
@trackers = @project.trackers
|
||||
@versions = @project.versions.sort
|
||||
@priorities = Enumeration::get_values('IPRI')
|
||||
@categories = @project.issue_categories
|
||||
@assignees = @project.members.collect { |m| m.user }
|
||||
@authors = @project.members.collect { |m| m.user }
|
||||
@subprojects = @project.active_children
|
||||
issues_by_tracker
|
||||
issues_by_version
|
||||
issues_by_priority
|
||||
issues_by_category
|
||||
issues_by_assigned_to
|
||||
issues_by_author
|
||||
issues_by_subproject
|
||||
|
||||
render :template => "reports/issue_report"
|
||||
end
|
||||
end
|
||||
|
||||
def delays
|
||||
@trackers = Tracker.find(:all)
|
||||
if request.get?
|
||||
@selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
|
||||
else
|
||||
@selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
|
||||
end
|
||||
@selected_tracker_ids ||= []
|
||||
@raw =
|
||||
ActiveRecord::Base.connection.select_all("SELECT datediff( a.created_on, b.created_on ) as delay, count(a.id) as total
|
||||
FROM issue_histories a, issue_histories b, issues i
|
||||
WHERE a.status_id =5
|
||||
AND a.issue_id = b.issue_id
|
||||
AND a.issue_id = i.id
|
||||
AND i.tracker_id in (#{@selected_tracker_ids.join(',')})
|
||||
AND b.id = (
|
||||
SELECT min( c.id )
|
||||
FROM issue_histories c
|
||||
WHERE b.issue_id = c.issue_id )
|
||||
GROUP BY delay") unless @selected_tracker_ids.empty?
|
||||
@raw ||=[]
|
||||
|
||||
@x_from = 0
|
||||
@x_to = 0
|
||||
@y_from = 0
|
||||
@y_to = 0
|
||||
@sum_total = 0
|
||||
@sum_delay = 0
|
||||
@raw.each do |r|
|
||||
@x_to = [r['delay'].to_i, @x_to].max
|
||||
@y_to = [r['total'].to_i, @y_to].max
|
||||
@sum_total = @sum_total + r['total'].to_i
|
||||
@sum_delay = @sum_delay + r['total'].to_i * r['delay'].to_i
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Find project of id params[:id]
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def issues_by_tracker
|
||||
@issues_by_tracker ||=
|
||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||
s.is_closed as closed,
|
||||
t.id as tracker_id,
|
||||
count(i.id) as total
|
||||
from
|
||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Tracker.table_name} t
|
||||
where
|
||||
i.status_id=s.id
|
||||
and i.tracker_id=t.id
|
||||
and i.project_id=#{@project.id}
|
||||
group by s.id, s.is_closed, t.id")
|
||||
end
|
||||
|
||||
def issues_by_version
|
||||
@issues_by_version ||=
|
||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||
s.is_closed as closed,
|
||||
v.id as fixed_version_id,
|
||||
count(i.id) as total
|
||||
from
|
||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Version.table_name} v
|
||||
where
|
||||
i.status_id=s.id
|
||||
and i.fixed_version_id=v.id
|
||||
and i.project_id=#{@project.id}
|
||||
group by s.id, s.is_closed, v.id")
|
||||
end
|
||||
|
||||
def issues_by_priority
|
||||
@issues_by_priority ||=
|
||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||
s.is_closed as closed,
|
||||
p.id as priority_id,
|
||||
count(i.id) as total
|
||||
from
|
||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Enumeration.table_name} p
|
||||
where
|
||||
i.status_id=s.id
|
||||
and i.priority_id=p.id
|
||||
and i.project_id=#{@project.id}
|
||||
group by s.id, s.is_closed, p.id")
|
||||
end
|
||||
|
||||
def issues_by_category
|
||||
@issues_by_category ||=
|
||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||
s.is_closed as closed,
|
||||
c.id as category_id,
|
||||
count(i.id) as total
|
||||
from
|
||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{IssueCategory.table_name} c
|
||||
where
|
||||
i.status_id=s.id
|
||||
and i.category_id=c.id
|
||||
and i.project_id=#{@project.id}
|
||||
group by s.id, s.is_closed, c.id")
|
||||
end
|
||||
|
||||
def issues_by_assigned_to
|
||||
@issues_by_assigned_to ||=
|
||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||
s.is_closed as closed,
|
||||
a.id as assigned_to_id,
|
||||
count(i.id) as total
|
||||
from
|
||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
|
||||
where
|
||||
i.status_id=s.id
|
||||
and i.assigned_to_id=a.id
|
||||
and i.project_id=#{@project.id}
|
||||
group by s.id, s.is_closed, a.id")
|
||||
end
|
||||
|
||||
def issues_by_author
|
||||
@issues_by_author ||=
|
||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||
s.is_closed as closed,
|
||||
a.id as author_id,
|
||||
count(i.id) as total
|
||||
from
|
||||
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
|
||||
where
|
||||
i.status_id=s.id
|
||||
and i.author_id=a.id
|
||||
and i.project_id=#{@project.id}
|
||||
group by s.id, s.is_closed, a.id")
|
||||
end
|
||||
|
||||
def issues_by_subproject
|
||||
@issues_by_subproject ||=
|
||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||
s.is_closed as closed,
|
||||
i.project_id as project_id,
|
||||
count(i.id) as total
|
||||
from
|
||||
#{Issue.table_name} i, #{IssueStatus.table_name} s
|
||||
where
|
||||
i.status_id=s.id
|
||||
and i.project_id IN (#{@project.active_children.collect{|p| p.id}.join(',')})
|
||||
group by s.id, s.is_closed, i.project_id") if @project.active_children.any?
|
||||
@issues_by_subproject ||= []
|
||||
end
|
||||
end
|
||||
@@ -1,328 +0,0 @@
|
||||
# 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
|
||||
# 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 'SVG/Graph/Bar'
|
||||
require 'SVG/Graph/BarHorizontal'
|
||||
require 'digest/sha1'
|
||||
|
||||
class ChangesetNotFound < Exception; end
|
||||
class InvalidRevisionParam < Exception; end
|
||||
|
||||
class RepositoriesController < ApplicationController
|
||||
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
|
||||
end
|
||||
if request.post? && @repository
|
||||
@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'
|
||||
end
|
||||
|
||||
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)
|
||||
# latest changesets
|
||||
@changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC")
|
||||
show_error_not_found unless @entries || @changesets.any?
|
||||
end
|
||||
|
||||
def browse
|
||||
@entries = @repository.entries(@path, @rev)
|
||||
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'
|
||||
end
|
||||
end
|
||||
|
||||
def changes
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
show_error_not_found and return unless @entry
|
||||
@changesets = @repository.changesets_for_path(@path)
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
end
|
||||
|
||||
def revisions
|
||||
@changeset_count = @repository.changesets.count
|
||||
@changeset_pages = Paginator.new self, @changeset_count,
|
||||
per_page_option,
|
||||
params['page']
|
||||
@changesets = @repository.changesets.find(:all,
|
||||
:limit => @changeset_pages.items_per_page,
|
||||
:offset => @changeset_pages.current.offset,
|
||||
:include => :user)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :layout => false if request.xhr? }
|
||||
format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
|
||||
end
|
||||
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)
|
||||
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
|
||||
send_data @content, :filename => @path.split('/').last
|
||||
else
|
||||
# Prevent empty lines when displaying a file with Windows style eol
|
||||
@content.gsub!("\r\n", "\n")
|
||||
end
|
||||
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?
|
||||
end
|
||||
|
||||
def revision
|
||||
@changeset = @repository.changesets.find_by_revision(@rev)
|
||||
raise ChangesetNotFound unless @changeset
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js {render :layout => false}
|
||||
end
|
||||
rescue ChangesetNotFound
|
||||
show_error_not_found
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
def stats
|
||||
end
|
||||
|
||||
def graph
|
||||
data = nil
|
||||
case params[:graph]
|
||||
when "commits_per_month"
|
||||
data = graph_commits_per_month(@repository)
|
||||
when "commits_per_author"
|
||||
data = graph_commits_per_author(@repository)
|
||||
end
|
||||
if data
|
||||
headers["Content-Type"] = "image/svg+xml"
|
||||
send_data(data, :type => "image/svg+xml", :disposition => "inline")
|
||||
else
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
REV_PARAM_RE = %r{^[a-f0-9]*$}
|
||||
|
||||
def find_repository
|
||||
@project = Project.find(params[:id])
|
||||
@repository = @project.repository
|
||||
render_404 and return false unless @repository
|
||||
@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)
|
||||
end
|
||||
|
||||
def graph_commits_per_month(repository)
|
||||
@date_to = Date.today
|
||||
@date_from = @date_to << 11
|
||||
@date_from = Date.civil(@date_from.year, @date_from.month, 1)
|
||||
commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
|
||||
commits_by_month = [0] * 12
|
||||
commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
|
||||
|
||||
changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
|
||||
changes_by_month = [0] * 12
|
||||
changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
|
||||
|
||||
fields = []
|
||||
month_names = l(:actionview_datehelper_select_month_names_abbr).split(',')
|
||||
12.times {|m| fields << month_names[((Date.today.month - 1 - m) % 12)]}
|
||||
|
||||
graph = SVG::Graph::Bar.new(
|
||||
:height => 300,
|
||||
:width => 800,
|
||||
:fields => fields.reverse,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
:step_x_labels => 2,
|
||||
:show_data_values => false,
|
||||
:graph_title => l(:label_commits_per_month),
|
||||
:show_graph_title => true
|
||||
)
|
||||
|
||||
graph.add_data(
|
||||
:data => commits_by_month[0..11].reverse,
|
||||
:title => l(:label_revision_plural)
|
||||
)
|
||||
|
||||
graph.add_data(
|
||||
:data => changes_by_month[0..11].reverse,
|
||||
:title => l(:label_change_plural)
|
||||
)
|
||||
|
||||
graph.burn
|
||||
end
|
||||
|
||||
def graph_commits_per_author(repository)
|
||||
commits_by_author = repository.changesets.count(:all, :group => :committer)
|
||||
commits_by_author.sort! {|x, y| x.last <=> y.last}
|
||||
|
||||
changes_by_author = repository.changes.count(:all, :group => :committer)
|
||||
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
|
||||
|
||||
fields = commits_by_author.collect {|r| r.first}
|
||||
commits_data = commits_by_author.collect {|r| r.last}
|
||||
changes_data = commits_by_author.collect {|r| h[r.first] || 0}
|
||||
|
||||
fields = fields + [""]*(10 - fields.length) if fields.length<10
|
||||
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,
|
||||
:fields => fields,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
:show_data_values => false,
|
||||
:rotate_y_labels => false,
|
||||
:graph_title => l(:label_commits_per_author),
|
||||
:show_graph_title => true
|
||||
)
|
||||
|
||||
graph.add_data(
|
||||
:data => commits_data,
|
||||
:title => l(:label_revision_plural)
|
||||
)
|
||||
|
||||
graph.add_data(
|
||||
:data => changes_data,
|
||||
:title => l(:label_change_plural)
|
||||
)
|
||||
|
||||
graph.burn
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Date
|
||||
def months_ago(date = Date.today)
|
||||
(date.year - self.year)*12 + (date.month - self.month)
|
||||
end
|
||||
|
||||
def weeks_ago(date = Date.today)
|
||||
(date.year - self.year)*52 + (date.cweek - self.cweek)
|
||||
end
|
||||
end
|
||||
|
||||
class String
|
||||
def with_leading_slash
|
||||
starts_with?('/') ? self : "/#{self}"
|
||||
end
|
||||
end
|
||||
@@ -1,94 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class RolesController < ApplicationController
|
||||
before_filter :require_admin
|
||||
|
||||
verify :method => :post, :only => [ :destroy, :move ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def index
|
||||
list
|
||||
render :action => 'list' unless request.xhr?
|
||||
end
|
||||
|
||||
def list
|
||||
@role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
|
||||
render :action => "list", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def new
|
||||
# Prefills the form with 'Non member' role permissions
|
||||
@role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
|
||||
if request.post? && @role.save
|
||||
# workflow copy
|
||||
if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
|
||||
@role.workflows.copy(copy_from)
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
@permissions = @role.setable_permissions
|
||||
@roles = Role.find :all, :order => 'builtin, position'
|
||||
end
|
||||
|
||||
def edit
|
||||
@role = Role.find(params[:id])
|
||||
if request.post? and @role.update_attributes(params[:role])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
@permissions = @role.setable_permissions
|
||||
end
|
||||
|
||||
def destroy
|
||||
@role = Role.find(params[:id])
|
||||
@role.destroy
|
||||
redirect_to :action => 'list'
|
||||
rescue
|
||||
flash[:error] = 'This role is in use and can not be deleted.'
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def move
|
||||
@role = Role.find(params[:id])
|
||||
case params[:position]
|
||||
when 'highest'
|
||||
@role.move_to_top
|
||||
when 'higher'
|
||||
@role.move_higher
|
||||
when 'lower'
|
||||
@role.move_lower
|
||||
when 'lowest'
|
||||
@role.move_to_bottom
|
||||
end if params[:position]
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def report
|
||||
@roles = Role.find(:all, :order => 'builtin, position')
|
||||
@permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
|
||||
if request.post?
|
||||
@roles.each do |role|
|
||||
role.permissions = params[:permissions][role.id.to_s]
|
||||
role.save
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,116 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class SearchController < ApplicationController
|
||||
before_filter :find_optional_project
|
||||
|
||||
helper :messages
|
||||
include MessagesHelper
|
||||
|
||||
def index
|
||||
@question = params[:q] || ""
|
||||
@question.strip!
|
||||
@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
|
||||
|
||||
# quick jump to an issue
|
||||
if @question.match(/^#?(\d+)$/) && Issue.find_by_id($1, :include => :project, :conditions => Project.visible_by(User.current))
|
||||
redirect_to :controller => "issues", :action => "show", :id => $1
|
||||
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')
|
||||
# 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
|
||||
|
||||
@scope = @object_types.select {|t| params[t]}
|
||||
@scope = @object_types if @scope.empty?
|
||||
|
||||
# extract tokens from the question
|
||||
# eg. hello "bye bye" => ["hello", "bye bye"]
|
||||
@tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
|
||||
# tokens must be at least 3 character long
|
||||
@tokens = @tokens.uniq.select {|w| w.length > 2 }
|
||||
|
||||
if !@tokens.empty?
|
||||
# no more than 5 tokens to search for
|
||||
@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]
|
||||
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
|
||||
@question = ""
|
||||
end
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
private
|
||||
def find_optional_project
|
||||
return true unless params[:id]
|
||||
@project = Project.find(params[:id])
|
||||
check_project_privacy
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -1,59 +0,0 @@
|
||||
# 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
|
||||
# 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
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
edit
|
||||
render :action => 'edit'
|
||||
end
|
||||
|
||||
def edit
|
||||
@notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted)
|
||||
if request.post? && params[:settings] && params[:settings].is_a?(Hash)
|
||||
settings = (params[:settings] || {}).dup.symbolize_keys
|
||||
settings.each do |name, value|
|
||||
# remove blank values in array settings
|
||||
value.delete_if {|v| v.blank? } if value.is_a?(Array)
|
||||
Setting[name] = value
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'edit', :tab => params[:tab]
|
||||
return
|
||||
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])
|
||||
if request.post?
|
||||
Setting["plugin_#{@plugin.id}"] = params[:settings]
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'plugin', :id => @plugin.id
|
||||
end
|
||||
@partial = @plugin.settings[:partial]
|
||||
@settings = Setting["plugin_#{@plugin.id}"]
|
||||
rescue Redmine::PluginNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -1,46 +0,0 @@
|
||||
# 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
|
||||
# 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 SysController < ActionController::Base
|
||||
wsdl_service_name 'Sys'
|
||||
web_service_api SysApi
|
||||
web_service_scaffold :invoke
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
# Registers a repository for the given project identifier
|
||||
def repository_created(identifier, vendor, 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.save
|
||||
repository.id || 0
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def check_enabled(name, args)
|
||||
Setting.sys_api_enabled?
|
||||
end
|
||||
end
|
||||
@@ -1,290 +0,0 @@
|
||||
# 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
|
||||
# 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 TimelogController < ApplicationController
|
||||
menu_item :issues
|
||||
before_filter :find_project, :authorize, :only => [:edit, :destroy]
|
||||
before_filter :find_optional_project, :only => [:report, :details]
|
||||
|
||||
verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :issues
|
||||
include TimelogHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
def report
|
||||
@available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
|
||||
:klass => Project,
|
||||
:label => :label_project},
|
||||
'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
|
||||
:klass => Version,
|
||||
:label => :label_version},
|
||||
'category' => {:sql => "#{Issue.table_name}.category_id",
|
||||
:klass => IssueCategory,
|
||||
:label => :field_category},
|
||||
'member' => {:sql => "#{TimeEntry.table_name}.user_id",
|
||||
:klass => User,
|
||||
:label => :label_member},
|
||||
'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
|
||||
:klass => Tracker,
|
||||
: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}
|
||||
}
|
||||
|
||||
# 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'
|
||||
|
||||
retrieve_date_range
|
||||
|
||||
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 << " 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.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
|
||||
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
|
||||
|
||||
@hours = ActiveRecord::Base.connection.select_all(sql)
|
||||
|
||||
@hours.each do |row|
|
||||
case @columns
|
||||
when 'year'
|
||||
row['year'] = row['tyear']
|
||||
when 'month'
|
||||
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
|
||||
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
|
||||
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]
|
||||
|
||||
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]
|
||||
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
|
||||
|
||||
if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?)
|
||||
case params[:period].to_s
|
||||
when 'today'
|
||||
@from = @to = Date.today
|
||||
when 'yesterday'
|
||||
@from = @to = Date.today - 1
|
||||
when 'current_week'
|
||||
@from = Date.today - (Date.today.cwday - 1)%7
|
||||
@to = @from + 6
|
||||
when 'last_week'
|
||||
@from = Date.today - 7 - (Date.today.cwday - 1)%7
|
||||
@to = @from + 6
|
||||
when '7_days'
|
||||
@from = Date.today - 7
|
||||
@to = Date.today
|
||||
when 'current_month'
|
||||
@from = Date.civil(Date.today.year, Date.today.month, 1)
|
||||
@to = (@from >> 1) - 1
|
||||
when 'last_month'
|
||||
@from = Date.civil(Date.today.year, Date.today.month, 1) << 1
|
||||
@to = (@from >> 1) - 1
|
||||
when '30_days'
|
||||
@from = Date.today - 30
|
||||
@to = Date.today
|
||||
when 'current_year'
|
||||
@from = Date.civil(Date.today.year, 1, 1)
|
||||
@to = Date.civil(Date.today.year, 12, 31)
|
||||
end
|
||||
elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?))
|
||||
begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end
|
||||
begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end
|
||||
@free_period = true
|
||||
else
|
||||
# default
|
||||
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)
|
||||
end
|
||||
end
|
||||
@@ -1,108 +0,0 @@
|
||||
# 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
|
||||
# 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 UsersController < ApplicationController
|
||||
before_filter :require_admin
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
def index
|
||||
list
|
||||
render :action => 'list' unless request.xhr?
|
||||
end
|
||||
|
||||
def list
|
||||
sort_init 'login', 'asc'
|
||||
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
||||
|
||||
@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
|
||||
|
||||
@user_count = User.count(:conditions => c.conditions)
|
||||
@user_pages = Paginator.new self, @user_count,
|
||||
per_page_option,
|
||||
params['page']
|
||||
@users = User.find :all,:order => sort_clause,
|
||||
:conditions => c.conditions,
|
||||
:limit => @user_pages.items_per_page,
|
||||
:offset => @user_pages.current.offset
|
||||
|
||||
render :action => "list", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def add
|
||||
if request.get?
|
||||
@user = User.new(:language => Setting.default_language)
|
||||
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
|
||||
if @user.save
|
||||
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
end
|
||||
@auth_sources = AuthSource.find(:all)
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
if request.post?
|
||||
@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
|
||||
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]))
|
||||
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'
|
||||
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'
|
||||
end
|
||||
end
|
||||
@@ -1,70 +0,0 @@
|
||||
# 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
|
||||
# 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 WatchersController < ApplicationController
|
||||
before_filter :find_project
|
||||
before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
|
||||
before_filter :authorize, :only => :new
|
||||
|
||||
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?
|
||||
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
|
||||
end
|
||||
rescue ::ActionController::RedirectBackError
|
||||
render :text => 'Watcher added.', :layout => true
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
klass = Object.const_get(params[:object_type].camelcase)
|
||||
return false unless klass.respond_to?('watched_by')
|
||||
@watched = klass.find(params[:object_id])
|
||||
@project = @watched.project
|
||||
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
|
||||
@@ -1,211 +0,0 @@
|
||||
# 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
|
||||
# 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 'diff'
|
||||
|
||||
class WikiController < ApplicationController
|
||||
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 }
|
||||
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
|
||||
# display a page (in editing mode if it doesn't exist)
|
||||
def index
|
||||
page_title = params[:page]
|
||||
@page = @wiki.find_or_new_page(page_title)
|
||||
if @page.new_record?
|
||||
if User.current.allowed_to?(:edit_wiki_pages, @project)
|
||||
edit
|
||||
render :action => 'edit'
|
||||
else
|
||||
render_404
|
||||
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
|
||||
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
|
||||
return
|
||||
elsif params[:export] == 'txt'
|
||||
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?
|
||||
# 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 !@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
|
||||
return
|
||||
end
|
||||
#@content.text = params[:content][:text]
|
||||
#@content.comments = params[:content][:comments]
|
||||
@content.attributes = params[:content]
|
||||
@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)
|
||||
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
# Optimistic locking exception
|
||||
flash[:error] = l(:notice_locking_conflict)
|
||||
end
|
||||
|
||||
# rename a page
|
||||
def rename
|
||||
return render_403 unless editable?
|
||||
@page.redirect_existing_links = true
|
||||
# used to display the *original* title if some AR validation errors occur
|
||||
@original_title = @page.pretty_title
|
||||
if request.post? && @page.update_attributes(params[:wiki_page])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||
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
|
||||
@version_count = @page.content.versions.count
|
||||
@version_pages = Paginator.new self, @version_count, per_page_option, params['p']
|
||||
# don't load text
|
||||
@versions = @page.content.versions.find :all,
|
||||
:select => "id, author_id, comments, updated_on, version",
|
||||
:order => 'version DESC',
|
||||
:limit => @version_pages.items_per_page + 1,
|
||||
:offset => @version_pages.current.offset
|
||||
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def diff
|
||||
@diff = @page.diff(params[:version], params[:version_from])
|
||||
render_404 unless @diff
|
||||
end
|
||||
|
||||
def annotate
|
||||
@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
|
||||
redirect_to :action => 'special', :id => @project, :page => 'Page_index'
|
||||
end
|
||||
|
||||
# display special pages
|
||||
def special
|
||||
page_title = params[:page].downcase
|
||||
case page_title
|
||||
# show pages index, sorted by title
|
||||
when 'page_index', 'date_index'
|
||||
# eager load information about last updates, without loading text
|
||||
@pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
|
||||
: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'
|
||||
export = render_to_string :action => 'export_multiple', :layout => false
|
||||
send_data(export, :type => 'text/html', :filename => "wiki.html")
|
||||
return
|
||||
else
|
||||
# requested special page doesn't exist, redirect to default page
|
||||
redirect_to :action => 'index', :id => @project, :page => nil and return
|
||||
end
|
||||
render :action => "special_#{page_title}"
|
||||
end
|
||||
|
||||
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
|
||||
@text = params[:content][:text]
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
def add_attachment
|
||||
return render_403 unless editable?
|
||||
attach_files(@page, params[:attachments])
|
||||
redirect_to :action => 'index', :page => @page.title
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_wiki
|
||||
@project = Project.find(params[:id])
|
||||
@wiki = @project.wiki
|
||||
render_404 unless @wiki
|
||||
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
|
||||
@@ -1,44 +0,0 @@
|
||||
# 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
|
||||
# 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 WikisController < ApplicationController
|
||||
menu_item :settings
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
# Create or update a project's wiki
|
||||
def edit
|
||||
@wiki = @project.wiki || Wiki.new(:project => @project)
|
||||
@wiki.attributes = params[:wiki]
|
||||
@wiki.save if request.post?
|
||||
render(:update) {|page| page.replace_html "tab-content-wiki", :partial => 'projects/settings/wiki'}
|
||||
end
|
||||
|
||||
# Delete a project's wiki
|
||||
def destroy
|
||||
if request.post? && params[:confirm] && @project.wiki
|
||||
@project.wiki.destroy
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'wiki'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
@@ -1,627 +0,0 @@
|
||||
# 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
|
||||
# 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)
|
||||
end
|
||||
|
||||
# Display a link if user is authorized
|
||||
def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
||||
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'
|
||||
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 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};"
|
||||
}))
|
||||
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)
|
||||
@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, *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)
|
||||
end
|
||||
|
||||
def l_or_humanize(s, options={})
|
||||
k = "#{options[:prefix]}#{s}".to_sym
|
||||
l_has_string?(k) ? l(k) : 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)),
|
||||
{: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,
|
||||
{: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) + ' »'),
|
||||
{: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
|
||||
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)},
|
||||
{: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
|
||||
end
|
||||
|
||||
def html_title(*args)
|
||||
if args.empty?
|
||||
title = []
|
||||
title << @project.name if @project
|
||||
title += @html_title if @html_title
|
||||
title << Setting.app_title
|
||||
title.compact.join(' - ')
|
||||
else
|
||||
@html_title ||= []
|
||||
@html_title += args
|
||||
end
|
||||
end
|
||||
|
||||
def accesskey(s)
|
||||
Redmine::AccessKeys.key_for s
|
||||
end
|
||||
|
||||
# Formats text according to system settings.
|
||||
# 2 ways to call this method:
|
||||
# * with a String: textilizable(text, options)
|
||||
# * with an object and one of its attribute: textilizable(issue, :description, options)
|
||||
def textilizable(*args)
|
||||
options = args.last.is_a?(Hash) ? args.pop : {}
|
||||
case args.size
|
||||
when 1
|
||||
obj = options[:object]
|
||||
text = args.shift
|
||||
when 2
|
||||
obj = args.shift
|
||||
text = obj.send(args.shift).to_s
|
||||
else
|
||||
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|
|
||||
style = $1
|
||||
filename = $6.downcase
|
||||
# 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}!"
|
||||
else
|
||||
m
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text) { |macro, args| exec_macro(macro, obj, args) }
|
||||
|
||||
# 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" }
|
||||
when :anchor
|
||||
# used for single-file wiki export
|
||||
format_wiki_link = Proc.new {|project, title, anchor| "##{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) }
|
||||
end
|
||||
|
||||
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
|
||||
|
||||
# Wiki links
|
||||
#
|
||||
# Examples:
|
||||
# [[mypage]]
|
||||
# [[mypage|mytext]]
|
||||
# wiki links can refer other project wikis, using project name or identifier:
|
||||
# [[project:]] -> wiki starting page
|
||||
# [[project:|mytext]]
|
||||
# [[project:mypage]]
|
||||
# [[project:mypage|mytext]]
|
||||
text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
|
||||
link_project = project
|
||||
esc, all, page, title = $1, $2, $3, $5
|
||||
if esc.nil?
|
||||
if page =~ /^([^\:]+)\:(.*)$/
|
||||
link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
|
||||
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),
|
||||
:class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
||||
else
|
||||
# project or wiki doesn't exist
|
||||
title || page
|
||||
end
|
||||
else
|
||||
all
|
||||
end
|
||||
end
|
||||
|
||||
# Redmine links
|
||||
#
|
||||
# Examples:
|
||||
# Issues:
|
||||
# #52 -> Link to issue #52
|
||||
# Changesets:
|
||||
# r52 -> Link to revision 52
|
||||
# commit:a85130f -> Link to scmid starting with a85130f
|
||||
# Documents:
|
||||
# document#17 -> Link to document with id 17
|
||||
# document:Greetings -> Link to the document with title "Greetings"
|
||||
# document:"Some document" -> Link to the document with title "Some document"
|
||||
# Versions:
|
||||
# version#3 -> Link to version with id 3
|
||||
# version:1.0.0 -> Link to version named "1.0.0"
|
||||
# version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
|
||||
# Attachments:
|
||||
# attachment:file.zip -> Link to the attachment of the current object named file.zip
|
||||
# Source files:
|
||||
# source:some/file -> Link to the file located at /some/file in the project's repository
|
||||
# source:some/file@52 -> Link to the file's revision 52
|
||||
# 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|
|
||||
leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
|
||||
link = nil
|
||||
if esc.nil?
|
||||
if prefix.nil? && sep == 'r'
|
||||
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))
|
||||
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))
|
||||
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})")
|
||||
link = content_tag('del', link) if issue.closed?
|
||||
end
|
||||
when 'document'
|
||||
if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
||||
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
||||
:class => 'document'
|
||||
end
|
||||
when 'version'
|
||||
if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
||||
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
|
||||
name = oid.gsub(%r{^"(.*)"$}, "\\1")
|
||||
case prefix
|
||||
when 'document'
|
||||
if project && document = project.documents.find_by_title(name)
|
||||
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
||||
:class => 'document'
|
||||
end
|
||||
when 'version'
|
||||
if project && version = project.versions.find_by_name(name)
|
||||
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
||||
:class => 'version'
|
||||
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)
|
||||
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),
|
||||
:rev => rev,
|
||||
:anchor => anchor,
|
||||
:format => (prefix == 'export' ? 'raw' : nil)},
|
||||
:class => (prefix == 'export' ? 'source download' : 'source')
|
||||
end
|
||||
when 'attachment'
|
||||
if attachments && attachment = attachments.detect {|a| a.filename == name }
|
||||
link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
|
||||
:class => 'attachment'
|
||||
end
|
||||
end
|
||||
end
|
||||
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.
|
||||
gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
|
||||
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}")
|
||||
if object && !object.errors.empty?
|
||||
# build full_messages here with controller current language
|
||||
full_messages = []
|
||||
object.errors.each do |attr, msg|
|
||||
next if msg.nil?
|
||||
msg = [msg] unless msg.is_a?(Array)
|
||||
if attr == "base"
|
||||
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"
|
||||
end
|
||||
end
|
||||
# retrieve custom values error messages
|
||||
if object.errors[:custom_values]
|
||||
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)
|
||||
end
|
||||
end
|
||||
end
|
||||
content_tag("div",
|
||||
content_tag(
|
||||
options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
|
||||
) +
|
||||
content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
|
||||
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
||||
)
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def lang_options_for_select(blank=true)
|
||||
(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)")
|
||||
end
|
||||
|
||||
def progress_bar(pcts, options={})
|
||||
pcts = [pcts, pcts] unless pcts.is_a?(Array)
|
||||
pcts[1] = pcts[1] - pcts[0]
|
||||
pcts << (100 - pcts[1] - pcts[0])
|
||||
width = options[:width] || '100px;'
|
||||
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') : '')
|
||||
), :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)
|
||||
options[:class] << ' icon-checked disabled'
|
||||
options[:disabled] = true
|
||||
end
|
||||
if options.delete(:disabled)
|
||||
options.delete(:method)
|
||||
options.delete(:confirm)
|
||||
options.delete(:onclick)
|
||||
options[:class] << ' disabled'
|
||||
url = '#'
|
||||
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 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
|
||||
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
|
||||
@@ -1,34 +0,0 @@
|
||||
# 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
|
||||
# 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 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}
|
||||
end
|
||||
end
|
||||
|
||||
def to_utf8(str)
|
||||
str
|
||||
end
|
||||
end
|
||||
@@ -1,88 +0,0 @@
|
||||
# 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.
|
||||
|
||||
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)
|
||||
custom_field = custom_value.custom_field
|
||||
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||||
field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||||
|
||||
case custom_field.field_format
|
||||
when "date"
|
||||
text_field_tag(field_name, custom_value.value, :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%')
|
||||
when "bool"
|
||||
check_box_tag(field_name, '1', custom_value.true?, :id => field_id) + hidden_field_tag(field_name, '0')
|
||||
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)
|
||||
else
|
||||
text_field_tag(field_name, custom_value.value, :id => field_id)
|
||||
end
|
||||
end
|
||||
|
||||
# Return custom field label tag
|
||||
def custom_field_label_tag(name, 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}",
|
||||
: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)
|
||||
end
|
||||
|
||||
# Return a string used to display a custom value
|
||||
def show_value(custom_value)
|
||||
return "" unless custom_value
|
||||
format_value(custom_value.value, custom_value.custom_field.field_format)
|
||||
end
|
||||
|
||||
# Return a string used to display a custom value
|
||||
def format_value(value, field_format)
|
||||
return "" unless value && !value.empty?
|
||||
case field_format
|
||||
when "date"
|
||||
begin; format_date(value.to_date); rescue; value end
|
||||
when "bool"
|
||||
l_YesNo(value == "1")
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
# Return an array of custom field formats which can be used in select_tag
|
||||
def custom_field_formats_for_select
|
||||
CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] }
|
||||
end
|
||||
end
|
||||
@@ -1,23 +0,0 @@
|
||||
# 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
|
||||
# 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 IssueRelationsHelper
|
||||
def collection_for_relation_type_select
|
||||
values = IssueRelation::TYPES
|
||||
values.keys.sort{|x,y| values[x][:order] <=> values[y][:order]}.collect{|k| [l(values[k][:name]), k]}
|
||||
end
|
||||
end
|
||||
@@ -1,198 +0,0 @@
|
||||
# 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 'csv'
|
||||
|
||||
module IssuesHelper
|
||||
include ApplicationHelper
|
||||
|
||||
def render_issue_tooltip(issue)
|
||||
@cached_label_start_date ||= l(:field_start_date)
|
||||
@cached_label_due_date ||= l(:field_due_date)
|
||||
@cached_label_assigned_to ||= l(:field_assigned_to)
|
||||
@cached_label_priority ||= l(:field_priority)
|
||||
|
||||
link_to_issue(issue) + ": #{h(issue.subject)}<br /><br />" +
|
||||
"<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
|
||||
"<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
|
||||
"<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
|
||||
"<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
|
||||
visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)])
|
||||
# Project specific queries and global queries
|
||||
visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
|
||||
@sidebar_queries = Query.find(:all,
|
||||
:order => "name ASC",
|
||||
:conditions => visible.conditions)
|
||||
end
|
||||
@sidebar_queries
|
||||
end
|
||||
|
||||
def show_detail(detail, no_html=false)
|
||||
case detail.property
|
||||
when 'attr'
|
||||
label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym)
|
||||
case detail.prop_key
|
||||
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
|
||||
when 'priority_id'
|
||||
e = Enumeration.find_by_id(detail.value) and value = e.name if detail.value
|
||||
e = Enumeration.find_by_id(detail.old_value) and old_value = e.name if detail.old_value
|
||||
when 'category_id'
|
||||
c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value
|
||||
c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value
|
||||
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)
|
||||
if custom_field
|
||||
label = custom_field.name
|
||||
value = format_value(detail.value, custom_field.field_format) if detail.value
|
||||
old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
|
||||
end
|
||||
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
|
||||
|
||||
unless no_html
|
||||
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)
|
||||
# Link to the attachment if it has not been removed
|
||||
value = link_to_attachment(a)
|
||||
else
|
||||
value = content_tag("i", h(value)) if value
|
||||
end
|
||||
end
|
||||
|
||||
if !detail.value.blank?
|
||||
case detail.property
|
||||
when 'attr', 'cf'
|
||||
if !detail.old_value.blank?
|
||||
label + " " + l(:text_journal_changed, old_value, value)
|
||||
else
|
||||
label + " " + l(:text_journal_set_to, value)
|
||||
end
|
||||
when 'attachment'
|
||||
"#{label} #{value} #{l(:label_added)}"
|
||||
end
|
||||
else
|
||||
case detail.property
|
||||
when 'attr', 'cf'
|
||||
label + " " + l(:text_journal_deleted) + " (#{old_value})"
|
||||
when 'attachment'
|
||||
"#{label} #{old_value} #{l(:label_deleted)}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
headers = [ "#",
|
||||
l(:field_status),
|
||||
l(:field_project),
|
||||
l(:field_tracker),
|
||||
l(:field_priority),
|
||||
l(:field_subject),
|
||||
l(:field_assigned_to),
|
||||
l(:field_category),
|
||||
l(:field_fixed_version),
|
||||
l(:field_author),
|
||||
l(:field_start_date),
|
||||
l(:field_due_date),
|
||||
l(:field_done_ratio),
|
||||
l(:field_estimated_hours),
|
||||
l(:field_created_on),
|
||||
l(:field_updated_on)
|
||||
]
|
||||
# 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.each {|f| headers << f.name}
|
||||
# Description in the last column
|
||||
headers << l(:field_description)
|
||||
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||
# csv lines
|
||||
issues.each do |issue|
|
||||
fields = [issue.id,
|
||||
issue.status.name,
|
||||
issue.project.name,
|
||||
issue.tracker.name,
|
||||
issue.priority.name,
|
||||
issue.subject,
|
||||
issue.assigned_to,
|
||||
issue.category,
|
||||
issue.fixed_version,
|
||||
issue.author.name,
|
||||
format_date(issue.start_date),
|
||||
format_date(issue.due_date),
|
||||
issue.done_ratio,
|
||||
issue.estimated_hours.to_s.gsub('.', decimal_separator),
|
||||
format_time(issue.created_on),
|
||||
format_time(issue.updated_on)
|
||||
]
|
||||
custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
|
||||
fields << issue.description
|
||||
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||
end
|
||||
end
|
||||
export.rewind
|
||||
export
|
||||
end
|
||||
end
|
||||
@@ -1,40 +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 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]
|
||||
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
|
||||
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
|
||||
|
||||
def link_to_in_place_notes_editor(text, field_id, url, options={})
|
||||
onclick = "new Ajax.Request('#{url_for(url)}', {asynchronous:true, evalScripts:true, method:'get'}); return false;"
|
||||
link_to text, '#', options.merge(:onclick => onclick)
|
||||
end
|
||||
end
|
||||
@@ -1,28 +0,0 @@
|
||||
# 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
|
||||
# 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 MessagesHelper
|
||||
|
||||
def link_to_message(message)
|
||||
return '' unless message
|
||||
link_to h(truncate(message.subject, 60)), :controller => 'messages',
|
||||
:action => 'show',
|
||||
:board_id => message.board_id,
|
||||
:id => message.root,
|
||||
:anchor => (message.parent_id ? "message-#{message.id}" : nil)
|
||||
end
|
||||
end
|
||||
@@ -1,36 +0,0 @@
|
||||
# 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.
|
||||
|
||||
module ProjectsHelper
|
||||
def link_to_version(version, options = {})
|
||||
return '' unless version && version.is_a?(Version)
|
||||
link_to h(version.name), { :controller => 'versions', :action => 'show', :id => version }, options
|
||||
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},
|
||||
{:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
|
||||
{:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
|
||||
{:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
|
||||
{:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
|
||||
{:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
|
||||
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}
|
||||
]
|
||||
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
||||
end
|
||||
end
|
||||
@@ -1,61 +0,0 @@
|
||||
# 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
|
||||
# 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 QueriesHelper
|
||||
|
||||
def operators_for_select(filter_type)
|
||||
Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]}
|
||||
end
|
||||
|
||||
def column_header(column)
|
||||
column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
|
||||
:default_order => column.default_order) :
|
||||
content_tag('th', column.caption)
|
||||
end
|
||||
|
||||
def column_content(column, issue)
|
||||
if column.is_a?(QueryCustomFieldColumn)
|
||||
cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
|
||||
show_value(cv)
|
||||
else
|
||||
value = issue.send(column.name)
|
||||
if value.is_a?(Date)
|
||||
format_date(value)
|
||||
elsif value.is_a?(Time)
|
||||
format_time(value)
|
||||
else
|
||||
case column.name
|
||||
when :subject
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,182 +0,0 @@
|
||||
# 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'
|
||||
|
||||
module RepositoriesHelper
|
||||
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)
|
||||
@encodings.each do |encoding|
|
||||
begin
|
||||
return Iconv.conv('UTF-8', encoding, str)
|
||||
rescue Iconv::Failure
|
||||
# do nothing here and try the next encoding
|
||||
end
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def repository_field_tags(form, repository)
|
||||
method = repository.class.name.demodulize.underscore + "_field_tags"
|
||||
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
|
||||
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
|
||||
|
||||
select_tag('repository_scm',
|
||||
options_for_select(scm_options, 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{^/+}, '')
|
||||
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]://)') +
|
||||
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)),
|
||||
:onfocus => "this.value=''; this.name='repository[password]';",
|
||||
:onchange => "this.name='repository[password]';"))
|
||||
end
|
||||
|
||||
def darcs_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 mercurial_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
|
||||
|
||||
def git_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
||||
end
|
||||
|
||||
def cvs_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
|
||||
content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
|
||||
end
|
||||
|
||||
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
|
||||
@@ -1,63 +0,0 @@
|
||||
# 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
|
||||
# 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 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
|
||||
result = ''
|
||||
text.split(regexp).each_with_index do |words, i|
|
||||
if result.length > 1200
|
||||
# maximum length of the preview reached
|
||||
result << '...'
|
||||
break
|
||||
end
|
||||
if i.even?
|
||||
result << h(words.length > 100 ? "#{words[0..44]} ... #{words[-45..-1]}" : words)
|
||||
else
|
||||
t = (tokens.index(words.downcase) || 0) % 4
|
||||
result << content_tag('span', h(words), :class => "highlight token-#{t}")
|
||||
end
|
||||
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
|
||||
@@ -1,29 +0,0 @@
|
||||
# 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
|
||||
# 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 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
|
||||
end
|
||||
@@ -1,164 +0,0 @@
|
||||
# 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.
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def sum_hours(data)
|
||||
sum = 0
|
||||
data.each do |row|
|
||||
sum += row['hours'].to_f
|
||||
end
|
||||
sum
|
||||
end
|
||||
|
||||
def options_for_period_select(value)
|
||||
options_for_select([[l(:label_all_time), 'all'],
|
||||
[l(:label_today), 'today'],
|
||||
[l(:label_yesterday), 'yesterday'],
|
||||
[l(:label_this_week), 'current_week'],
|
||||
[l(:label_last_week), 'last_week'],
|
||||
[l(:label_last_n_days, 7), '7_days'],
|
||||
[l(:label_this_month), 'current_month'],
|
||||
[l(:label_last_month), 'last_month'],
|
||||
[l(:label_last_n_days, 30), '30_days'],
|
||||
[l(:label_this_year), 'current_year']],
|
||||
value)
|
||||
end
|
||||
|
||||
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
|
||||
headers = [l(:field_spent_on),
|
||||
l(:field_user),
|
||||
l(:field_activity),
|
||||
l(:field_project),
|
||||
l(:field_issue),
|
||||
l(:field_tracker),
|
||||
l(:field_subject),
|
||||
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),
|
||||
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.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
|
||||
@@ -1,58 +0,0 @@
|
||||
# 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.
|
||||
|
||||
module UsersHelper
|
||||
def users_status_options_for_select(selected)
|
||||
user_count_by_status = User.count(:group => 'status').to_hash
|
||||
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}
|
||||
]
|
||||
end
|
||||
end
|
||||
@@ -1,47 +0,0 @@
|
||||
# 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.
|
||||
|
||||
module VersionsHelper
|
||||
|
||||
STATUS_BY_CRITERIAS = %w(category tracker priority author assigned_to)
|
||||
|
||||
def render_issue_status_by(version, criteria)
|
||||
criteria ||= 'category'
|
||||
raise 'Unknown criteria' unless STATUS_BY_CRITERIAS.include?(criteria)
|
||||
|
||||
h = Hash.new {|k,v| k[v] = [0, 0]}
|
||||
begin
|
||||
# Total issue count
|
||||
Issue.count(:group => criteria,
|
||||
:conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s}
|
||||
# Open issues count
|
||||
Issue.count(:group => criteria,
|
||||
:include => :status,
|
||||
:conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s}
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# When grouping by an association, Rails throws this exception if there's no result (bug)
|
||||
end
|
||||
counts = h.keys.compact.sort.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}}
|
||||
max = counts.collect {|c| c[:total]}.max
|
||||
|
||||
render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
|
||||
end
|
||||
|
||||
def status_by_options_for_select(value)
|
||||
options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value)
|
||||
end
|
||||
end
|
||||
@@ -1,41 +0,0 @@
|
||||
# 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
|
||||
# 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 WatchersHelper
|
||||
def watcher_tag(object, user)
|
||||
content_tag("span", watcher_link(object, user), :id => 'watcher')
|
||||
end
|
||||
|
||||
def watcher_link(object, user)
|
||||
return '' unless user && user.logged? && object.respond_to?('watched_by?')
|
||||
watched = object.watched_by?(user)
|
||||
url = {:controller => 'watchers',
|
||||
:action => (watched ? 'unwatch' : 'watch'),
|
||||
:object_type => object.class.to_s.underscore,
|
||||
:object_id => object.id}
|
||||
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
|
||||
{:url => url},
|
||||
:href => url_for(url),
|
||||
: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
|
||||
@@ -1,56 +0,0 @@
|
||||
# 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
|
||||
# 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 WikiHelper
|
||||
|
||||
def html_diff(wdiff)
|
||||
words = wdiff.words.collect{|word| h(word)}
|
||||
words_add = 0
|
||||
words_del = 0
|
||||
dels = 0
|
||||
del_off = 0
|
||||
wdiff.diff.diffs.each do |diff|
|
||||
add_at = nil
|
||||
add_to = nil
|
||||
del_at = nil
|
||||
deleted = ""
|
||||
diff.each do |change|
|
||||
pos = change[1]
|
||||
if change[0] == "+"
|
||||
add_at = pos + dels unless add_at
|
||||
add_to = pos + dels
|
||||
words_add += 1
|
||||
else
|
||||
del_at = pos unless del_at
|
||||
deleted << ' ' + change[2]
|
||||
words_del += 1
|
||||
end
|
||||
end
|
||||
if add_at
|
||||
words[add_at] = '<span class="diff_in">' + words[add_at]
|
||||
words[add_to] = words[add_to] + '</span>'
|
||||
end
|
||||
if del_at
|
||||
words.insert del_at - del_off + dels + words_add, '<span class="diff_out">' + deleted + '</span>'
|
||||
dels += 1
|
||||
del_off += words_del
|
||||
words_del = 0
|
||||
end
|
||||
end
|
||||
simple_format_without_paragraph(words.join(' '))
|
||||
end
|
||||
end
|
||||
@@ -1,150 +0,0 @@
|
||||
# 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
|
||||
# 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 "digest/md5"
|
||||
|
||||
class Attachment < ActiveRecord::Base
|
||||
belongs_to :container, :polymorphic => true
|
||||
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
|
||||
|
||||
validates_presence_of :container, :filename, :author
|
||||
validates_length_of :filename, :maximum => 255
|
||||
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"}
|
||||
|
||||
cattr_accessor :storage_path
|
||||
@@storage_path = "#{RAILS_ROOT}/files"
|
||||
|
||||
def validate
|
||||
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
|
||||
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 increment_download
|
||||
increment!(:downloads)
|
||||
end
|
||||
|
||||
def project
|
||||
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
|
||||
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('\\\\', '/'))
|
||||
|
||||
# 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
|
||||
end
|
||||
end
|
||||
@@ -1,29 +0,0 @@
|
||||
# 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
|
||||
# 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 Board < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
|
||||
has_many :messages, :dependent => :delete_all, :order => "#{Message.table_name}.created_on DESC"
|
||||
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
|
||||
acts_as_list :scope => :project_id
|
||||
acts_as_watchable
|
||||
|
||||
validates_presence_of :name, :description
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_length_of :description, :maximum => 255
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
# 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
|
||||
# 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 Change < ActiveRecord::Base
|
||||
belongs_to :changeset
|
||||
|
||||
validates_presence_of :changeset_id, :action, :path
|
||||
|
||||
def relative_path
|
||||
changeset.repository.relative_path(path)
|
||||
end
|
||||
end
|
||||
@@ -1,155 +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.
|
||||
|
||||
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,
|
||||
:url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project_id, :rev => o.revision}}
|
||||
|
||||
acts_as_searchable :columns => 'comments',
|
||||
:include => {:repository => :project},
|
||||
: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))
|
||||
end
|
||||
|
||||
def committed_on=(date)
|
||||
self.commit_date = date
|
||||
super
|
||||
end
|
||||
|
||||
def project
|
||||
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
|
||||
require 'pp'
|
||||
|
||||
def scan_comment_for_issue_ids
|
||||
return if comments.blank?
|
||||
# keywords used to reference issues
|
||||
ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip)
|
||||
# keywords used to fix issues
|
||||
fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip)
|
||||
# status and optional done ratio applied
|
||||
fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id)
|
||||
done_ratio = Setting.commit_fix_done_ratio.blank? ? nil : Setting.commit_fix_done_ratio.to_i
|
||||
|
||||
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
|
||||
return if kw_regexp.blank?
|
||||
|
||||
referenced_issues = []
|
||||
|
||||
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] }
|
||||
referenced_issues += repository.project.issues.find_all_by_id(target_issue_ids)
|
||||
end
|
||||
|
||||
comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match|
|
||||
action = match[0]
|
||||
target_issue_ids = match[1].scan(/\d+/)
|
||||
target_issues = repository.project.issues.find_all_by_id(target_issue_ids)
|
||||
if fix_status && fix_keywords.include?(action.downcase)
|
||||
# update status of issues
|
||||
logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug?
|
||||
target_issues.each do |issue|
|
||||
# the issue may have been updated by the closure of another one (eg. duplicate)
|
||||
issue.reload
|
||||
# don't change the status is the issue is closed
|
||||
next if issue.status.is_closed?
|
||||
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))
|
||||
issue.status = fix_status
|
||||
issue.done_ratio = done_ratio if done_ratio
|
||||
issue.save
|
||||
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
||||
end
|
||||
end
|
||||
referenced_issues += target_issues
|
||||
end
|
||||
|
||||
self.issues = referenced_issues.uniq
|
||||
end
|
||||
|
||||
# Returns the previous changeset
|
||||
def previous
|
||||
@previous ||= Changeset.find(:first, :conditions => ['id < ? AND repository_id = ?', self.id, self.repository_id], :order => 'id DESC')
|
||||
end
|
||||
|
||||
# Returns the next changeset
|
||||
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
|
||||
@@ -1,75 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class CustomField < ActiveRecord::Base
|
||||
has_many :custom_values, :dependent => :delete_all
|
||||
acts_as_list :scope => 'type = \'#{self.class}\''
|
||||
serialize :possible_values
|
||||
|
||||
FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 },
|
||||
"text" => { :name => :label_text, :order => 2 },
|
||||
"int" => { :name => :label_integer, :order => 3 },
|
||||
"float" => { :name => :label_float, :order => 4 },
|
||||
"list" => { :name => :label_list, :order => 5 },
|
||||
"date" => { :name => :label_date, :order => 6 },
|
||||
"bool" => { :name => :label_boolean, :order => 7 }
|
||||
}.freeze
|
||||
|
||||
validates_presence_of :name, :field_format
|
||||
validates_uniqueness_of :name, :scope => :type
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_format_of :name, :with => /^[\w\s\.\'\-]*$/i
|
||||
validates_inclusion_of :field_format, :in => FIELD_FORMATS.keys
|
||||
|
||||
def initialize(attributes = nil)
|
||||
super
|
||||
self.possible_values ||= []
|
||||
end
|
||||
|
||||
def before_validation
|
||||
# remove empty values
|
||||
self.possible_values = self.possible_values.collect{|v| v unless v.empty?}.compact
|
||||
# make sure these fields are not searchable
|
||||
self.searchable = false if %w(int float date bool).include?(field_format)
|
||||
true
|
||||
end
|
||||
|
||||
def validate
|
||||
if self.field_format == "list"
|
||||
errors.add(:possible_values, :activerecord_error_blank) if self.possible_values.nil? || self.possible_values.empty?
|
||||
errors.add(:possible_values, :activerecord_error_invalid) unless self.possible_values.is_a? Array
|
||||
end
|
||||
|
||||
# validate default value
|
||||
v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil)
|
||||
v.custom_field.is_required = false
|
||||
errors.add(:default_value, :activerecord_error_invalid) unless v.valid?
|
||||
end
|
||||
|
||||
def <=>(field)
|
||||
position <=> field.position
|
||||
end
|
||||
|
||||
# to move in project_custom_field
|
||||
def self.for_all
|
||||
find(:all, :conditions => ["is_for_all=?", true], :order => 'position')
|
||||
end
|
||||
|
||||
def type_name
|
||||
nil
|
||||
end
|
||||
end
|
||||
@@ -1,55 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class CustomValue < ActiveRecord::Base
|
||||
belongs_to :custom_field
|
||||
belongs_to :customized, :polymorphic => true
|
||||
|
||||
def after_initialize
|
||||
if custom_field && new_record? && (customized_type.blank? || (customized && customized.new_record?))
|
||||
self.value ||= custom_field.default_value
|
||||
end
|
||||
end
|
||||
|
||||
# Returns true if the boolean custom value is true
|
||||
def true?
|
||||
self.value == '1'
|
||||
end
|
||||
|
||||
protected
|
||||
def validate
|
||||
if value.blank?
|
||||
errors.add(:value, :activerecord_error_blank) if custom_field.is_required? and value.blank?
|
||||
else
|
||||
errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
|
||||
errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length
|
||||
errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
|
||||
|
||||
# Format specific validations
|
||||
case custom_field.field_format
|
||||
when 'int'
|
||||
errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[+-]?\d+$/
|
||||
when 'float'
|
||||
begin; Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end
|
||||
when 'date'
|
||||
errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/
|
||||
when 'list'
|
||||
errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include?(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,37 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class Document < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
belongs_to :category, :class_name => "Enumeration", :foreign_key => "category_id"
|
||||
acts_as_attachable :delete_permission => :manage_documents
|
||||
|
||||
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
||||
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
|
||||
@@ -1,81 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class Enumeration < ActiveRecord::Base
|
||||
acts_as_list :scope => 'opt = \'#{opt}\''
|
||||
|
||||
before_destroy :check_integrity
|
||||
|
||||
validates_presence_of :opt, :name
|
||||
validates_uniqueness_of :name, :scope => [:opt]
|
||||
validates_length_of :name, :maximum => 30
|
||||
|
||||
# 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}
|
||||
}.freeze
|
||||
|
||||
def self.get_values(option)
|
||||
find(:all, :conditions => {:opt => option}, :order => 'position')
|
||||
end
|
||||
|
||||
def self.default(option)
|
||||
find(:first, :conditions => {:opt => option, :is_default => true}, :order => 'position')
|
||||
end
|
||||
|
||||
def option_name
|
||||
OPTIONS[self.opt][:label]
|
||||
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
|
||||
end
|
||||
|
||||
def <=>(enumeration)
|
||||
position <=> enumeration.position
|
||||
end
|
||||
|
||||
def to_s; name end
|
||||
|
||||
private
|
||||
def check_integrity
|
||||
raise "Can't delete enumeration" if self.in_use?
|
||||
end
|
||||
end
|
||||
@@ -1,280 +0,0 @@
|
||||
# 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
|
||||
# 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 Issue < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
belongs_to :tracker
|
||||
belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||
belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
|
||||
belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
|
||||
belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id'
|
||||
belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
|
||||
|
||||
has_many :journals, :as => :journalized, :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 :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_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_length_of :subject, :maximum => 255
|
||||
validates_inclusion_of :done_ratio, :in => 0..100
|
||||
validates_numericality_of :estimated_hours, :allow_nil => true
|
||||
|
||||
def after_initialize
|
||||
if new_record?
|
||||
# set default values for new records only
|
||||
self.status ||= IssueStatus.default
|
||||
self.priority ||= Enumeration.default('IPRI')
|
||||
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
|
||||
self.custom_values = issue.custom_values.collect {|v| v.clone}
|
||||
self
|
||||
end
|
||||
|
||||
# Move an issue to a new project and tracker
|
||||
def move_to(new_project, new_tracker = nil)
|
||||
transaction do
|
||||
if new_project && project_id != new_project.id
|
||||
# delete issue relations
|
||||
unless Setting.cross_project_issue_relations?
|
||||
self.relations_from.clear
|
||||
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.fixed_version = nil
|
||||
self.project = new_project
|
||||
end
|
||||
if new_tracker
|
||||
self.tracker = new_tracker
|
||||
end
|
||||
if save
|
||||
# Manually update project_id on related time entries
|
||||
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
|
||||
else
|
||||
rollback_db_transaction
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def priority_id=(pid)
|
||||
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
|
||||
end
|
||||
|
||||
if self.due_date and self.start_date and self.due_date < self.start_date
|
||||
errors.add :due_date, :activerecord_error_greater_than_start_date
|
||||
end
|
||||
|
||||
if start_date && soonest_start && start_date < soonest_start
|
||||
errors.add :start_date, :activerecord_error_invalid
|
||||
end
|
||||
end
|
||||
|
||||
def validate_on_create
|
||||
errors.add :tracker_id, :activerecord_error_invalid unless project.trackers.include?(tracker)
|
||||
end
|
||||
|
||||
def before_create
|
||||
# default assignment based on category
|
||||
if assigned_to.nil? && category && category.assigned_to
|
||||
self.assigned_to = category.assigned_to
|
||||
end
|
||||
end
|
||||
|
||||
def before_save
|
||||
if @current_journal
|
||||
# attributes changes
|
||||
(Issue.column_names - %w(id description)).each {|c|
|
||||
@current_journal.details << JournalDetail.new(:property => 'attr',
|
||||
:prop_key => c,
|
||||
:old_value => @issue_before_change.send(c),
|
||||
:value => send(c)) unless send(c)==@issue_before_change.send(c)
|
||||
}
|
||||
# custom fields changes
|
||||
custom_values.each {|c|
|
||||
next if (@custom_values_before_change[c.custom_field_id]==c.value ||
|
||||
(@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
|
||||
@current_journal.details << JournalDetail.new(:property => 'cf',
|
||||
:prop_key => c.custom_field_id,
|
||||
:old_value => @custom_values_before_change[c.custom_field_id],
|
||||
:value => c.value)
|
||||
}
|
||||
@current_journal.save
|
||||
end
|
||||
# Save the issue even if the journal is not saved (because empty)
|
||||
true
|
||||
end
|
||||
|
||||
def after_save
|
||||
# Reload is needed in order to get the right status
|
||||
reload
|
||||
|
||||
# Update start/due dates of following issues
|
||||
relations_from.each(&:set_issue_to_dates)
|
||||
|
||||
# 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
|
||||
duplicate.init_journal(@current_journal.user, @current_journal.notes)
|
||||
duplicate.update_attribute :status, self.status
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
# Return true if the issue is closed, otherwise false
|
||||
def closed?
|
||||
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
|
||||
end
|
||||
|
||||
# Returns an array of status that user is able to apply
|
||||
def new_statuses_allowed_to(user)
|
||||
statuses = status.find_new_statuses_allowed_to(user.role_for_project(project), tracker)
|
||||
statuses << status unless statuses.empty?
|
||||
statuses.uniq.sort
|
||||
end
|
||||
|
||||
# Returns the mail adresses of users that should be notified for the issue
|
||||
def recipients
|
||||
recipients = project.recipients
|
||||
# Author and assignee are always notified unless they have been locked
|
||||
recipients << author.mail if author && author.active?
|
||||
recipients << assigned_to.mail if assigned_to && assigned_to.active?
|
||||
recipients.compact.uniq
|
||||
end
|
||||
|
||||
def spent_hours
|
||||
@spent_hours ||= time_entries.sum(:hours) || 0
|
||||
end
|
||||
|
||||
def relations
|
||||
(relations_from + relations_to).sort
|
||||
end
|
||||
|
||||
def all_dependent_issues
|
||||
dependencies = []
|
||||
relations_from.each do |relation|
|
||||
dependencies << relation.issue_to
|
||||
dependencies += relation.issue_to.all_dependent_issues
|
||||
end
|
||||
dependencies
|
||||
end
|
||||
|
||||
# Returns an array of issues that duplicate this one
|
||||
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)
|
||||
end
|
||||
|
||||
def duration
|
||||
(start_date && due_date) ? due_date - start_date : 0
|
||||
end
|
||||
|
||||
def soonest_start
|
||||
@soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
|
||||
end
|
||||
|
||||
def self.visible_by(usr)
|
||||
with_scope(:find => { :conditions => Project.visible_by(usr) }) do
|
||||
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
|
||||
@@ -1,43 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class IssueCategory < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
|
||||
has_many :issues, :foreign_key => 'category_id', :dependent => :nullify
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name, :scope => [:project_id]
|
||||
validates_length_of :name, :maximum => 30
|
||||
|
||||
alias :destroy_without_reassign :destroy
|
||||
|
||||
# Destroy the category
|
||||
# If a category is specified, issues are reassigned to this category
|
||||
def destroy(reassign_to = nil)
|
||||
if reassign_to && reassign_to.is_a?(IssueCategory) && reassign_to.project == self.project
|
||||
Issue.update_all("category_id = #{reassign_to.id}", "category_id = #{id}")
|
||||
end
|
||||
destroy_without_reassign
|
||||
end
|
||||
|
||||
def <=>(category)
|
||||
name <=> category.name
|
||||
end
|
||||
|
||||
def to_s; name end
|
||||
end
|
||||
@@ -1,79 +0,0 @@
|
||||
# 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
|
||||
# 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 IssueRelation < ActiveRecord::Base
|
||||
belongs_to :issue_from, :class_name => 'Issue', :foreign_key => 'issue_from_id'
|
||||
belongs_to :issue_to, :class_name => 'Issue', :foreign_key => 'issue_to_id'
|
||||
|
||||
TYPE_RELATES = "relates"
|
||||
TYPE_DUPLICATES = "duplicates"
|
||||
TYPE_BLOCKS = "blocks"
|
||||
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_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 },
|
||||
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 },
|
||||
}.freeze
|
||||
|
||||
validates_presence_of :issue_from, :issue_to, :relation_type
|
||||
validates_inclusion_of :relation_type, :in => TYPES.keys
|
||||
validates_numericality_of :delay, :allow_nil => true
|
||||
validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
|
||||
|
||||
def validate
|
||||
if issue_from && issue_to
|
||||
errors.add :issue_to_id, :activerecord_error_invalid if issue_from_id == issue_to_id
|
||||
errors.add :issue_to_id, :activerecord_error_not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations?
|
||||
errors.add_to_base :activerecord_error_circular_dependency if issue_to.all_dependent_issues.include? issue_from
|
||||
end
|
||||
end
|
||||
|
||||
def other_issue(issue)
|
||||
(self.issue_from_id == issue.id) ? issue_to : issue_from
|
||||
end
|
||||
|
||||
def label_for(issue)
|
||||
TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow
|
||||
end
|
||||
|
||||
def before_save
|
||||
if TYPE_PRECEDES == relation_type
|
||||
self.delay ||= 0
|
||||
else
|
||||
self.delay = nil
|
||||
end
|
||||
set_issue_to_dates
|
||||
end
|
||||
|
||||
def set_issue_to_dates
|
||||
soonest_start = self.successor_soonest_start
|
||||
if soonest_start && (!issue_to.start_date || issue_to.start_date < soonest_start)
|
||||
issue_to.start_date, issue_to.due_date = successor_soonest_start, successor_soonest_start + issue_to.duration
|
||||
issue_to.save
|
||||
end
|
||||
end
|
||||
|
||||
def successor_soonest_start
|
||||
return nil unless (TYPE_PRECEDES == self.relation_type) && (issue_from.start_date || issue_from.due_date)
|
||||
(issue_from.due_date || issue_from.start_date) + 1 + delay
|
||||
end
|
||||
|
||||
def <=>(relation)
|
||||
TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order]
|
||||
end
|
||||
end
|
||||
@@ -1,69 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class IssueStatus < ActiveRecord::Base
|
||||
before_destroy :check_integrity
|
||||
has_many :workflows, :foreign_key => "old_status_id", :dependent => :delete_all
|
||||
acts_as_list
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name
|
||||
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?
|
||||
end
|
||||
|
||||
# Returns the default status for new issues
|
||||
def self.default
|
||||
find(:first, :conditions =>["is_default=?", true])
|
||||
end
|
||||
|
||||
# Returns an array of all statuses the given role can switch to
|
||||
# Uses association cache when called more than one time
|
||||
def new_statuses_allowed_to(role, tracker)
|
||||
new_statuses = workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} if role && tracker
|
||||
new_statuses ? new_statuses.compact.sort{|x, y| x.position <=> y.position } : []
|
||||
end
|
||||
|
||||
# Same thing as above but uses a database query
|
||||
# More efficient than the previous method if called just once
|
||||
def find_new_statuses_allowed_to(role, tracker)
|
||||
new_statuses = workflows.find(:all,
|
||||
:include => :new_status,
|
||||
:conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status }.compact if role && tracker
|
||||
new_statuses ? new_statuses.sort{|x, y| x.position <=> y.position } : []
|
||||
end
|
||||
|
||||
def new_status_allowed_to?(status, role, tracker)
|
||||
status && role && tracker ?
|
||||
!workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => role.id, :tracker_id => tracker.id}).nil? :
|
||||
false
|
||||
end
|
||||
|
||||
def <=>(status)
|
||||
position <=> status.position
|
||||
end
|
||||
|
||||
def to_s; name end
|
||||
|
||||
private
|
||||
def check_integrity
|
||||
raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
|
||||
end
|
||||
end
|
||||
@@ -1,68 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class Journal < ActiveRecord::Base
|
||||
belongs_to :journalized, :polymorphic => true
|
||||
# added as a quick fix to allow eager loading of the polymorphic association
|
||||
# since always associated to an issue, for now
|
||||
belongs_to :issue, :foreign_key => :journalized_id
|
||||
|
||||
belongs_to :user
|
||||
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}" },
|
||||
: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)
|
||||
# Do not save an empty journal
|
||||
(details.empty? && notes.blank?) ? false : super
|
||||
end
|
||||
|
||||
# Returns the new status if the journal contains a status change, otherwise nil
|
||||
def new_status
|
||||
c = details.detect {|detail| detail.prop_key == 'status_id'}
|
||||
(c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
|
||||
end
|
||||
|
||||
def new_value_for(prop)
|
||||
c = details.detect {|detail| detail.prop_key == prop}
|
||||
c ? c.value : nil
|
||||
end
|
||||
|
||||
def editable_by?(usr)
|
||||
usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
|
||||
end
|
||||
|
||||
def project
|
||||
journalized.respond_to?(:project) ? journalized.project : nil
|
||||
end
|
||||
|
||||
def attachments
|
||||
journalized.respond_to?(:attachments) ? journalized.attachments : nil
|
||||
end
|
||||
end
|
||||
@@ -1,200 +0,0 @@
|
||||
# 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
|
||||
# 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 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
|
||||
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)
|
||||
return unless issue
|
||||
# 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)
|
||||
|
||||
# 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]*(.+)\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
|
||||
end
|
||||
end
|
||||
@@ -1,264 +0,0 @@
|
||||
# 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
|
||||
# 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 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)
|
||||
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)
|
||||
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)
|
||||
end
|
||||
|
||||
def issue_edit(journal)
|
||||
issue = journal.journalized
|
||||
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
|
||||
@author = journal.user
|
||||
recipients issue.recipients
|
||||
# Watchers in cc
|
||||
cc(issue.watcher_recipients - @recipients)
|
||||
s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
|
||||
s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
|
||||
s << issue.subject
|
||||
subject s
|
||||
body :issue => issue,
|
||||
: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
|
||||
subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
|
||||
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}"
|
||||
when 'Document'
|
||||
added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
|
||||
added_to = "#{l(:label_document)}: #{container.title}"
|
||||
end
|
||||
redmine_headers 'Project' => container.project.identifier
|
||||
recipients container.project.recipients
|
||||
subject "[#{container.project.name}] #{l(:label_attachment_new)}"
|
||||
body :attachments => attachments,
|
||||
:added_to => added_to,
|
||||
:added_to_url => added_to_url
|
||||
end
|
||||
|
||||
def news_added(news)
|
||||
redmine_headers 'Project' => news.project.identifier
|
||||
recipients news.project.recipients
|
||||
subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
|
||||
body :news => news,
|
||||
:news_url => url_for(:controller => 'news', :action => 'show', :id => news)
|
||||
end
|
||||
|
||||
def message_posted(message, recipients)
|
||||
redmine_headers 'Project' => message.project.identifier,
|
||||
'Topic-Id' => (message.parent_id || message.id)
|
||||
recipients(recipients)
|
||||
subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
|
||||
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
|
||||
subject l(:mail_subject_register, Setting.app_title)
|
||||
body :user => user,
|
||||
: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
|
||||
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
|
||||
|
||||
def register(token)
|
||||
set_language_if_valid(token.user.language)
|
||||
recipients token.user.mail
|
||||
subject l(:mail_subject_register, Setting.app_title)
|
||||
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
|
||||
subject 'Redmine test'
|
||||
body :url => url_for(:controller => 'welcome')
|
||||
end
|
||||
|
||||
# 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?) &&
|
||||
(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
|
||||
|
||||
# Common headers
|
||||
headers 'X-Mailer' => 'Redmine',
|
||||
'X-Redmine-Host' => Setting.host_name,
|
||||
'X-Redmine-Site' => Setting.app_title,
|
||||
'Precedence' => 'bulk',
|
||||
'Auto-Submitted' => 'auto-generated'
|
||||
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
|
||||
end
|
||||
# Blind carbon copy recipients
|
||||
if Setting.bcc_recipients?
|
||||
bcc([recipients, cc].flatten.compact.uniq)
|
||||
recipients []
|
||||
cc []
|
||||
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)
|
||||
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
|
||||
''
|
||||
end unless respond_to?('controller_path')
|
||||
end
|
||||
@@ -1,89 +0,0 @@
|
||||
# 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
|
||||
# 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 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
|
||||
belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
|
||||
|
||||
acts_as_searchable :columns => ['subject', 'content'],
|
||||
:include => {:board => :project},
|
||||
:project_key => 'project_id',
|
||||
:date_column => "#{table_name}.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
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def after_create
|
||||
board.update_attribute(:last_message_id, self.id)
|
||||
board.increment! :messages_count
|
||||
if parent
|
||||
parent.reload.update_attribute(:last_reply_id, self.id)
|
||||
else
|
||||
board.increment! :topics_count
|
||||
end
|
||||
end
|
||||
|
||||
def after_destroy
|
||||
# The following line is required so that the previous counter
|
||||
# updates (due to children removal) are not overwritten
|
||||
board.reload
|
||||
board.decrement! :messages_count
|
||||
board.decrement! :topics_count unless parent
|
||||
end
|
||||
|
||||
def sticky?
|
||||
sticky == 1
|
||||
end
|
||||
|
||||
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
|
||||
@@ -1,30 +0,0 @@
|
||||
# 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
|
||||
# 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 MessageObserver < ActiveRecord::Observer
|
||||
def after_create(message)
|
||||
recipients = []
|
||||
# send notification to the topic watchers
|
||||
recipients += message.root.watcher_recipients
|
||||
# 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
|
||||
end
|
||||
@@ -1,36 +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 News < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||
has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on"
|
||||
|
||||
validates_presence_of :title, :description
|
||||
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_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")
|
||||
end
|
||||
end
|
||||
@@ -1,276 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class Project < ActiveRecord::Base
|
||||
# Project statuses
|
||||
STATUS_ACTIVE = 1
|
||||
STATUS_ARCHIVED = 9
|
||||
|
||||
has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
|
||||
has_many :users, :through => :members
|
||||
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]
|
||||
has_many :issue_changes, :through => :issues, :source => :journals
|
||||
has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
|
||||
has_many :time_entries, :dependent => :delete_all
|
||||
has_many :queries, :dependent => :delete_all
|
||||
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_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,
|
||||
: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_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
|
||||
:url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}},
|
||||
:author => nil
|
||||
|
||||
attr_protected :status, :enabled_module_names
|
||||
|
||||
validates_presence_of :name, :identifier
|
||||
validates_uniqueness_of :name, :identifier
|
||||
validates_associated :repository, :wiki
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_length_of :homepage, :maximum => 255
|
||||
validates_length_of :identifier, :in => 1..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?
|
||||
end
|
||||
|
||||
def identifier_frozen?
|
||||
errors[:identifier].nil? && !(new_record? || identifier.blank?)
|
||||
end
|
||||
|
||||
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}"]
|
||||
end
|
||||
conditions ||= ["#{Project.table_name}.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
|
||||
end
|
||||
end
|
||||
|
||||
# returns latest created projects
|
||||
# non public projects will be returned only if user is a member of those
|
||||
def self.latest(user=nil, count=5)
|
||||
find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
|
||||
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?
|
||||
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))"
|
||||
else
|
||||
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}"
|
||||
end
|
||||
end
|
||||
|
||||
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]
|
||||
base_statement = "(#{project_statement}) AND (#{base_statement})"
|
||||
end
|
||||
if user.admin?
|
||||
# no restriction
|
||||
else
|
||||
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
|
||||
|
||||
def project_condition(with_subprojects)
|
||||
cond = "#{Project.table_name}.id = #{id}"
|
||||
cond = "(#{cond} OR #{Project.table_name}.parent_id = #{id})" if with_subprojects
|
||||
cond
|
||||
end
|
||||
|
||||
def self.find(*args)
|
||||
if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
|
||||
project = find_by_identifier(*args)
|
||||
raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil?
|
||||
project
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def to_param
|
||||
# id is used for projects with a numeric identifier (compatibility)
|
||||
@to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier)
|
||||
end
|
||||
|
||||
def active?
|
||||
self.status == STATUS_ACTIVE
|
||||
end
|
||||
|
||||
def archive
|
||||
# Archive subprojects if any
|
||||
children.each do |subproject|
|
||||
subproject.archive
|
||||
end
|
||||
update_attribute :status, STATUS_ARCHIVED
|
||||
end
|
||||
|
||||
def unarchive
|
||||
return false if parent && !parent.active?
|
||||
update_attribute :status, STATUS_ACTIVE
|
||||
end
|
||||
|
||||
def active_children
|
||||
children.select {|child| child.active?}
|
||||
end
|
||||
|
||||
# Returns an array of the trackers used by the project and its sub projects
|
||||
def rolled_up_trackers
|
||||
@rolled_up_trackers ||=
|
||||
Tracker.find(:all, :include => :projects,
|
||||
:select => "DISTINCT #{Tracker.table_name}.*",
|
||||
:conditions => ["#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?", id, id],
|
||||
:order => "#{Tracker.table_name}.position")
|
||||
end
|
||||
|
||||
# Deletes all project's members
|
||||
def delete_all_members
|
||||
Member.delete_all(['project_id = ?', id])
|
||||
end
|
||||
|
||||
# Users issues can be assigned to
|
||||
def assignable_users
|
||||
members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort
|
||||
end
|
||||
|
||||
# Returns the mail adresses of users that should be always notified on project events
|
||||
def recipients
|
||||
members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
|
||||
end
|
||||
|
||||
# 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
|
||||
end
|
||||
|
||||
def project
|
||||
self
|
||||
end
|
||||
|
||||
def <=>(project)
|
||||
name.downcase <=> project.name.downcase
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
# Returns a short description of the projects (first lines)
|
||||
def short_description(length = 255)
|
||||
description.gsub(/^(.{#{length}}[^\n]*).*$/m, '\1').strip if description
|
||||
end
|
||||
|
||||
def allows_to?(action)
|
||||
if action.is_a? Hash
|
||||
allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
|
||||
else
|
||||
allowed_permissions.include? action
|
||||
end
|
||||
end
|
||||
|
||||
def module_enabled?(module_name)
|
||||
module_name = module_name.to_s
|
||||
enabled_modules.detect {|m| m.name == module_name}
|
||||
end
|
||||
|
||||
def enabled_module_names=(module_names)
|
||||
enabled_modules.clear
|
||||
module_names = [] unless module_names && module_names.is_a?(Array)
|
||||
module_names.each do |name|
|
||||
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
|
||||
errors.add(parent_id, " must be a root project") if parent and parent.parent
|
||||
errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0
|
||||
errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/)
|
||||
end
|
||||
|
||||
private
|
||||
def allowed_permissions
|
||||
@allowed_permissions ||= begin
|
||||
module_names = enabled_modules.collect {|m| m.name}
|
||||
Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
|
||||
end
|
||||
end
|
||||
|
||||
def allowed_actions
|
||||
@actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
|
||||
end
|
||||
end
|
||||
@@ -1,410 +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 QueryColumn
|
||||
attr_accessor :name, :sortable, :default_order
|
||||
include GLoc
|
||||
|
||||
def initialize(name, options={})
|
||||
self.name = name
|
||||
self.sortable = options[:sortable]
|
||||
self.default_order = options[:default_order]
|
||||
end
|
||||
|
||||
def caption
|
||||
set_language_if_valid(User.current.language)
|
||||
l("field_#{name}")
|
||||
end
|
||||
end
|
||||
|
||||
class QueryCustomFieldColumn < QueryColumn
|
||||
|
||||
def initialize(custom_field)
|
||||
self.name = "cf_#{custom_field.id}".to_sym
|
||||
self.sortable = false
|
||||
@cf = custom_field
|
||||
end
|
||||
|
||||
def caption
|
||||
@cf.name
|
||||
end
|
||||
|
||||
def custom_field
|
||||
@cf
|
||||
end
|
||||
end
|
||||
|
||||
class Query < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
serialize :filters
|
||||
serialize :column_names
|
||||
|
||||
attr_protected :project_id, :user_id
|
||||
|
||||
validates_presence_of :name, :on => :save
|
||||
validates_length_of :name, :maximum => 255
|
||||
|
||||
@@operators = { "=" => :label_equals,
|
||||
"!" => :label_not_equals,
|
||||
"o" => :label_open_issues,
|
||||
"c" => :label_closed_issues,
|
||||
"!*" => :label_none,
|
||||
"*" => :label_all,
|
||||
">=" => '>=',
|
||||
"<=" => '<=',
|
||||
"<t+" => :label_in_less_than,
|
||||
">t+" => :label_in_more_than,
|
||||
"t+" => :label_in,
|
||||
"t" => :label_today,
|
||||
"w" => :label_this_week,
|
||||
">t-" => :label_less_than_ago,
|
||||
"<t-" => :label_more_than_ago,
|
||||
"t-" => :label_ago,
|
||||
"~" => :label_contains,
|
||||
"!~" => :label_not_contains }
|
||||
|
||||
cattr_reader :operators
|
||||
|
||||
@@operators_by_filter_type = { :list => [ "=", "!" ],
|
||||
:list_status => [ "o", "=", "!", "c", "*" ],
|
||||
:list_optional => [ "=", "!", "!*", "*" ],
|
||||
:list_subprojects => [ "*", "!*", "=" ],
|
||||
:date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ],
|
||||
:date_past => [ ">t-", "<t-", "t-", "t", "w" ],
|
||||
:string => [ "=", "~", "!", "!~" ],
|
||||
:text => [ "~", "!~" ],
|
||||
: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'),
|
||||
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
|
||||
QueryColumn.new(:author),
|
||||
QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname"),
|
||||
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
|
||||
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"),
|
||||
QueryColumn.new(:fixed_version, :sortable => "#{Version.table_name}.effective_date", :default_order => 'desc'),
|
||||
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
|
||||
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
|
||||
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
|
||||
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"),
|
||||
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
|
||||
]
|
||||
cattr_reader :available_columns
|
||||
|
||||
def initialize(attributes = nil)
|
||||
super attributes
|
||||
self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
|
||||
set_language_if_valid(User.current.language)
|
||||
end
|
||||
|
||||
def after_initialize
|
||||
# Store the fact that project is nil (used in #editable_by?)
|
||||
@is_for_all = project.nil?
|
||||
end
|
||||
|
||||
def validate
|
||||
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
|
||||
# filter doesn't require any value
|
||||
["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
|
||||
end if filters
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
return false unless user
|
||||
# Admin can edit them all and regular users can edit their private queries
|
||||
return true if user.admin? || (!is_public && self.user_id == user.id)
|
||||
# Members can not edit public queries that are for all project (only admin is allowed to)
|
||||
is_public && !@is_for_all && user.allowed_to?(:manage_public_queries, project)
|
||||
end
|
||||
|
||||
def available_filters
|
||||
return @available_filters if @available_filters
|
||||
|
||||
trackers = project.nil? ? Tracker.find(:all, :order => 'position') : project.rolled_up_trackers
|
||||
|
||||
@available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
|
||||
"tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } },
|
||||
"priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI'], :order => 'position').collect{|s| [s.name, s.id.to_s] } },
|
||||
"subject" => { :type => :text, :order => 8 },
|
||||
"created_on" => { :type => :date_past, :order => 9 },
|
||||
"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 }}
|
||||
|
||||
user_values = []
|
||||
user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
|
||||
if project
|
||||
user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] }
|
||||
else
|
||||
# members of the user's projects
|
||||
user_values += User.current.projects.collect(&:users).flatten.uniq.sort.collect{|s| [s.name, s.id.to_s] }
|
||||
end
|
||||
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
|
||||
@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
|
||||
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}))
|
||||
end
|
||||
@available_filters
|
||||
end
|
||||
|
||||
def add_filter(field, operator, values)
|
||||
# values must be an array
|
||||
return unless values and values.is_a? Array # and !values.first.empty?
|
||||
# check if field is defined as an available filter
|
||||
if available_filters.has_key? field
|
||||
filter_options = available_filters[field]
|
||||
# check if operator is allowed for that filter
|
||||
#if @@operators_by_filter_type[filter_options[:type]].include? operator
|
||||
# allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]})
|
||||
# filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator
|
||||
#end
|
||||
filters[field] = {:operator => operator, :values => values }
|
||||
end
|
||||
end
|
||||
|
||||
def add_short_filter(field, expression)
|
||||
return unless expression
|
||||
parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first
|
||||
add_filter field, (parms[0] || "="), [parms[1] || ""]
|
||||
end
|
||||
|
||||
def has_filter?(field)
|
||||
filters and filters[field]
|
||||
end
|
||||
|
||||
def operator_for(field)
|
||||
has_filter?(field) ? filters[field][:operator] : nil
|
||||
end
|
||||
|
||||
def values_for(field)
|
||||
has_filter?(field) ? filters[field][:values] : nil
|
||||
end
|
||||
|
||||
def label_for(field)
|
||||
label = available_filters[field][:name] if available_filters.has_key?(field)
|
||||
label ||= field.gsub(/\_id$/, "")
|
||||
end
|
||||
|
||||
def available_columns
|
||||
return @available_columns if @available_columns
|
||||
@available_columns = Query.available_columns
|
||||
@available_columns += (project ?
|
||||
project.all_issue_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
|
||||
else
|
||||
# preserve the column_names order
|
||||
column_names.collect {|name| available_columns.find {|col| col.name == name}}.compact
|
||||
end
|
||||
end
|
||||
|
||||
def column_names=(names)
|
||||
names = names.select {|n| n.is_a?(Symbol) || !n.blank? } if names
|
||||
names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym } if names
|
||||
write_attribute(:column_names, names)
|
||||
end
|
||||
|
||||
def has_column?(column)
|
||||
column_names && column_names.include?(column.name)
|
||||
end
|
||||
|
||||
def has_default_columns?
|
||||
column_names.nil? || column_names.empty?
|
||||
end
|
||||
|
||||
def project_statement
|
||||
project_clauses = []
|
||||
if project && !@project.active_children.empty?
|
||||
ids = [project.id]
|
||||
if has_filter?("subproject_id")
|
||||
case operator_for("subproject_id")
|
||||
when '='
|
||||
# include the selected subprojects
|
||||
ids += values_for("subproject_id").each(&:to_i)
|
||||
when '!*'
|
||||
# main project only
|
||||
else
|
||||
# all subprojects
|
||||
ids += project.child_ids
|
||||
end
|
||||
elsif Setting.display_subprojects_issues?
|
||||
ids += project.child_ids
|
||||
end
|
||||
project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
|
||||
elsif project
|
||||
project_clauses << "#{Project.table_name}.id = %d" % project.id
|
||||
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|
|
||||
next if field == "subproject_id"
|
||||
v = values_for(field).clone
|
||||
next unless v and !v.empty?
|
||||
|
||||
sql = ''
|
||||
is_custom_filter = false
|
||||
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 "
|
||||
else
|
||||
# regular field
|
||||
db_table = Issue.table_name
|
||||
db_field = field
|
||||
sql << '('
|
||||
end
|
||||
|
||||
# "me" value subsitution
|
||||
if %w(assigned_to_id author_id).include?(field)
|
||||
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)
|
||||
|
||||
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 = "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(value.first)}%'"
|
||||
when "!~"
|
||||
sql = "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(value.first)}%'"
|
||||
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 ')
|
||||
end
|
||||
end
|
||||
@@ -1,179 +0,0 @@
|
||||
# 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
|
||||
# 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 Repository < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
has_many :changesets, :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)
|
||||
end
|
||||
|
||||
# Removes leading and trailing whitespace
|
||||
def root_url=(arg)
|
||||
write_attribute(:root_url, arg ? arg.to_s.strip : nil)
|
||||
end
|
||||
|
||||
def scm
|
||||
@scm ||= self.scm_adapter.new url, root_url, login, password
|
||||
update_attribute(:root_url, @scm.root_url) if root_url.blank?
|
||||
@scm
|
||||
end
|
||||
|
||||
def scm_name
|
||||
self.class.scm_name
|
||||
end
|
||||
|
||||
def supports_cat?
|
||||
scm.supports_cat?
|
||||
end
|
||||
|
||||
def supports_annotate?
|
||||
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)
|
||||
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},
|
||||
: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
|
||||
|
||||
def scan_changesets_for_issue_ids
|
||||
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"
|
||||
def self.fetch_changesets
|
||||
find(:all).each(&:fetch_changesets)
|
||||
end
|
||||
|
||||
# scan changeset comments to find related and fixed issues for all repositories
|
||||
def self.scan_changesets_for_issue_ids
|
||||
find(:all).each(&:scan_changesets_for_issue_ids)
|
||||
end
|
||||
|
||||
def self.scm_name
|
||||
'Abstract'
|
||||
end
|
||||
|
||||
def self.available_scm
|
||||
subclasses.collect {|klass| [klass.scm_name, klass.name]}
|
||||
end
|
||||
|
||||
def self.factory(klass_name, *args)
|
||||
klass = "Repository::#{klass_name}".constantize
|
||||
klass.new(*args)
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def before_save
|
||||
# Strips url and root_url
|
||||
url.strip!
|
||||
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
|
||||
@@ -1,91 +0,0 @@
|
||||
# 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
|
||||
# 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 'redmine/scm/adapters/bazaar_adapter'
|
||||
|
||||
class Repository::Bazaar < Repository
|
||||
attr_protected :root_url
|
||||
validates_presence_of :url
|
||||
|
||||
def scm_adapter
|
||||
Redmine::Scm::Adapters::BazaarAdapter
|
||||
end
|
||||
|
||||
def self.scm_name
|
||||
'Bazaar'
|
||||
end
|
||||
|
||||
def entries(path=nil, identifier=nil)
|
||||
entries = scm.entries(path, identifier)
|
||||
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],
|
||||
:order => "#{Changeset.table_name}.revision DESC")
|
||||
if c
|
||||
e.lastrev.identifier = c.changeset.revision
|
||||
e.lastrev.name = c.changeset.revision
|
||||
e.lastrev.author = c.changeset.committer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
scm_info = scm.info
|
||||
if scm_info
|
||||
# latest revision found in database
|
||||
db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
|
||||
# latest revision in the repository
|
||||
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
|
||||
while (identifier_from <= scm_revision)
|
||||
# loads changesets by batches of 200
|
||||
identifier_to = [identifier_from + 199, scm_revision].min
|
||||
revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
|
||||
transaction do
|
||||
revisions.reverse_each do |revision|
|
||||
changeset = Changeset.create(:repository => self,
|
||||
:revision => revision.identifier,
|
||||
:committer => revision.author,
|
||||
:committed_on => revision.time,
|
||||
:scmid => revision.scmid,
|
||||
:comments => revision.message)
|
||||
|
||||
revision.paths.each do |change|
|
||||
Change.create(:changeset => changeset,
|
||||
:action => change[:action],
|
||||
:path => change[:path],
|
||||
:revision => change[:revision])
|
||||
end
|
||||
end
|
||||
end unless revisions.nil?
|
||||
identifier_from = identifier_to + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,161 +0,0 @@
|
||||
# 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
|
||||
# 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 'redmine/scm/adapters/cvs_adapter'
|
||||
require 'digest/sha1'
|
||||
|
||||
class Repository::Cvs < Repository
|
||||
validates_presence_of :url, :root_url
|
||||
|
||||
def scm_adapter
|
||||
Redmine::Scm::Adapters::CvsAdapter
|
||||
end
|
||||
|
||||
def self.scm_name
|
||||
'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)
|
||||
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)
|
||||
if entries
|
||||
entries.each() do |entry|
|
||||
unless entry.lastrev.nil? || entry.lastrev.identifier
|
||||
change=changes.find_by_revision_and_path( entry.lastrev.revision, scm.with_leading_slash(entry.path) )
|
||||
if change
|
||||
entry.lastrev.identifier=change.changeset.revision
|
||||
entry.lastrev.author=change.changeset.committer
|
||||
entry.lastrev.revision=change.revision
|
||||
entry.lastrev.branch=change.branch
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
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)
|
||||
#convert rev to revision. CVS can't handle changesets here
|
||||
diff=[]
|
||||
changeset_from=changesets.find_by_revision(rev)
|
||||
if rev_to.to_i > 0
|
||||
changeset_to=changesets.find_by_revision(rev_to)
|
||||
end
|
||||
changeset_from.changes.each() do |change_from|
|
||||
|
||||
revision_from=nil
|
||||
revision_to=nil
|
||||
|
||||
revision_from=change_from.revision if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
|
||||
|
||||
if revision_from
|
||||
if changeset_to
|
||||
changeset_to.changes.each() do |change_to|
|
||||
revision_to=change_to.revision if change_to.path==change_from.path
|
||||
end
|
||||
end
|
||||
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?
|
||||
end
|
||||
end
|
||||
return diff
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
# some nifty bits to introduce a commit-id with cvs
|
||||
# natively cvs doesn't provide any kind of changesets, there is only a revision per file.
|
||||
# we now take a guess using the author, the commitlog and the commit-date.
|
||||
|
||||
# last one is the next step to take. the commit-date is not equal for all
|
||||
# commits in one changeset. cvs update the commit-date when the *,v file was touched. so
|
||||
# we use a small delta here, to merge all changes belonging to _one_ changeset
|
||||
time_delta=10.seconds
|
||||
|
||||
fetch_since = latest_changeset ? latest_changeset.committed_on : nil
|
||||
transaction do
|
||||
tmp_rev_num = 1
|
||||
scm.revisions('', fetch_since, nil, :with_paths => true) do |revision|
|
||||
# only add the change to the database, if it doen't exists. the cvs log
|
||||
# is not exclusive at all.
|
||||
unless changes.find_by_path_and_revision(scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
|
||||
revision
|
||||
cs = changesets.find(:first, :conditions=>{
|
||||
:committed_on=>revision.time-time_delta..revision.time+time_delta,
|
||||
:committer=>revision.author,
|
||||
:comments=>Changeset.normalize_comments(revision.message)
|
||||
})
|
||||
|
||||
# create a new changeset....
|
||||
unless cs
|
||||
# we use a temporaray revision number here (just for inserting)
|
||||
# later on, we calculate a continous positive number
|
||||
latest = changesets.find(:first, :order => 'id DESC')
|
||||
cs = Changeset.create(:repository => self,
|
||||
:revision => "_#{tmp_rev_num}",
|
||||
:committer => revision.author,
|
||||
:committed_on => revision.time,
|
||||
:comments => revision.message)
|
||||
tmp_rev_num += 1
|
||||
end
|
||||
|
||||
#convert CVS-File-States to internal Action-abbrevations
|
||||
#default action is (M)odified
|
||||
action="M"
|
||||
if revision.paths[0][:action]=="Exp" && revision.paths[0][:revision]=="1.1"
|
||||
action="A" #add-action always at first revision (= 1.1)
|
||||
elsif revision.paths[0][:action]=="dead"
|
||||
action="D" #dead-state is similar to Delete
|
||||
end
|
||||
|
||||
Change.create(:changeset => cs,
|
||||
:action => action,
|
||||
:path => scm.with_leading_slash(revision.paths[0][:path]),
|
||||
:revision => revision.paths[0][:revision],
|
||||
:branch => revision.paths[0][:branch]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# Renumber new changesets in chronological order
|
||||
changesets.find(:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE '_%'").each do |changeset|
|
||||
changeset.update_attribute :revision, next_revision_number
|
||||
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
|
||||
@@ -1,100 +0,0 @@
|
||||
# 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
|
||||
# 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 'redmine/scm/adapters/darcs_adapter'
|
||||
|
||||
class Repository::Darcs < Repository
|
||||
validates_presence_of :url
|
||||
|
||||
def scm_adapter
|
||||
Redmine::Scm::Adapters::DarcsAdapter
|
||||
end
|
||||
|
||||
def self.scm_name
|
||||
'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)
|
||||
if entries
|
||||
entries.each do |entry|
|
||||
# Search the DB for the entry's last change
|
||||
changeset = changesets.find_by_scmid(entry.lastrev.scmid) if entry.lastrev && !entry.lastrev.scmid.blank?
|
||||
if changeset
|
||||
entry.lastrev.identifier = changeset.revision
|
||||
entry.lastrev.name = changeset.revision
|
||||
entry.lastrev.time = changeset.committed_on
|
||||
entry.lastrev.author = changeset.committer
|
||||
end
|
||||
end
|
||||
end
|
||||
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)
|
||||
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
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
scm_info = scm.info
|
||||
if scm_info
|
||||
db_last_id = latest_changeset ? latest_changeset.scmid : nil
|
||||
next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
|
||||
# latest revision in the repository
|
||||
scm_revision = scm_info.lastrev.scmid
|
||||
unless changesets.find_by_scmid(scm_revision)
|
||||
revisions = scm.revisions('', db_last_id, nil, :with_path => true)
|
||||
transaction do
|
||||
revisions.reverse_each do |revision|
|
||||
changeset = Changeset.create(:repository => self,
|
||||
:revision => next_rev,
|
||||
: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
|
||||
next_rev += 1
|
||||
end if revisions
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,43 +0,0 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# FileSystem adapter
|
||||
# File written by Paul Rivier, at Demotera.
|
||||
#
|
||||
# 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 'redmine/scm/adapters/filesystem_adapter'
|
||||
|
||||
class Repository::Filesystem < Repository
|
||||
attr_protected :root_url
|
||||
validates_presence_of :url
|
||||
|
||||
def scm_adapter
|
||||
Redmine::Scm::Adapters::FilesystemAdapter
|
||||
end
|
||||
|
||||
def self.scm_name
|
||||
'Filesystem'
|
||||
end
|
||||
|
||||
def entries(path=nil, identifier=nil)
|
||||
scm.entries(path, identifier)
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,70 +0,0 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
# Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
|
||||
# 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 'redmine/scm/adapters/git_adapter'
|
||||
|
||||
class Repository::Git < Repository
|
||||
attr_protected :root_url
|
||||
validates_presence_of :url
|
||||
|
||||
def scm_adapter
|
||||
Redmine::Scm::Adapters::GitAdapter
|
||||
end
|
||||
|
||||
def self.scm_name
|
||||
'Git'
|
||||
end
|
||||
|
||||
def changesets_for_path(path)
|
||||
Change.find(:all, :include => {:changeset => :user},
|
||||
:conditions => ["repository_id = ? AND path = ?", id, path],
|
||||
:order => "committed_on DESC, #{Changeset.table_name}.revision DESC").collect(&:changeset)
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
scm_info = scm.info
|
||||
if scm_info
|
||||
# latest revision found in database
|
||||
db_revision = latest_changeset ? latest_changeset.revision : nil
|
||||
# latest revision in the 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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,94 +0,0 @@
|
||||
# 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
|
||||
# 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 'redmine/scm/adapters/mercurial_adapter'
|
||||
|
||||
class Repository::Mercurial < Repository
|
||||
attr_protected :root_url
|
||||
validates_presence_of :url
|
||||
|
||||
def scm_adapter
|
||||
Redmine::Scm::Adapters::MercurialAdapter
|
||||
end
|
||||
|
||||
def self.scm_name
|
||||
'Mercurial'
|
||||
end
|
||||
|
||||
def entries(path=nil, identifier=nil)
|
||||
entries=scm.entries(path, identifier)
|
||||
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
|
||||
entry.lastrev.identifier = change.changeset.revision
|
||||
entry.lastrev.name = change.changeset.revision
|
||||
entry.lastrev.author = change.changeset.committer
|
||||
entry.lastrev.revision = change.revision
|
||||
end
|
||||
end
|
||||
end
|
||||
entries
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
scm_info = scm.info
|
||||
if scm_info
|
||||
# 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
|
||||
if db_revision < scm_revision
|
||||
logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
|
||||
identifier_from = db_revision + 1
|
||||
while (identifier_from <= scm_revision)
|
||||
# loads changesets by batches of 100
|
||||
identifier_to = [identifier_from + 99, scm_revision].min
|
||||
revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
|
||||
transaction do
|
||||
revisions.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 unless revisions.nil?
|
||||
identifier_from = identifier_to + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,89 +0,0 @@
|
||||
# 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
|
||||
# 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 '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
|
||||
|
||||
def scm_adapter
|
||||
Redmine::Scm::Adapters::SubversionAdapter
|
||||
end
|
||||
|
||||
def self.scm_name
|
||||
'Subversion'
|
||||
end
|
||||
|
||||
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)}"), '')
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
scm_info = scm.info
|
||||
if scm_info
|
||||
# latest revision found in database
|
||||
db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
|
||||
# latest revision in the repository
|
||||
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
|
||||
while (identifier_from <= scm_revision)
|
||||
# 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
|
||||
changeset = Changeset.create(:repository => self,
|
||||
:revision => revision.identifier,
|
||||
: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 unless changeset.new_record?
|
||||
end
|
||||
end unless revisions.nil?
|
||||
identifier_from = identifier_to + 1
|
||||
end
|
||||
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
|
||||
@@ -1,147 +0,0 @@
|
||||
# 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.
|
||||
|
||||
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
|
||||
def copy(role)
|
||||
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)" +
|
||||
" SELECT tracker_id, old_status_id, new_status_id, #{proxy_owner.id}" +
|
||||
" FROM #{Workflow.table_name}" +
|
||||
" WHERE role_id = #{role.id}"
|
||||
end
|
||||
end
|
||||
|
||||
has_many :members
|
||||
acts_as_list
|
||||
|
||||
serialize :permissions, Array
|
||||
attr_protected :builtin
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
||||
|
||||
def permissions
|
||||
read_attribute(:permissions) || []
|
||||
end
|
||||
|
||||
def permissions=(perms)
|
||||
perms = perms.collect {|p| p.to_sym unless p.blank? }.compact.uniq 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
|
||||
end
|
||||
|
||||
# Return true if the role is a builtin role
|
||||
def builtin?
|
||||
self.builtin != 0
|
||||
end
|
||||
|
||||
# Return true if the role is a project member role
|
||||
def member?
|
||||
!self.builtin?
|
||||
end
|
||||
|
||||
# Return true if role is allowed to do the specified action
|
||||
# action can be:
|
||||
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
||||
# * a permission Symbol (eg. :edit_project)
|
||||
def allowed_to?(action)
|
||||
if action.is_a? Hash
|
||||
allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
|
||||
else
|
||||
allowed_permissions.include? action
|
||||
end
|
||||
end
|
||||
|
||||
# Return all the permissions that can be given to the role
|
||||
def setable_permissions
|
||||
setable_permissions = Redmine::AccessControl.permissions - Redmine::AccessControl.public_permissions
|
||||
setable_permissions -= Redmine::AccessControl.members_only_permissions if self.builtin == BUILTIN_NON_MEMBER
|
||||
setable_permissions -= Redmine::AccessControl.loggedin_only_permissions if self.builtin == BUILTIN_ANONYMOUS
|
||||
setable_permissions
|
||||
end
|
||||
|
||||
# Find all the roles that can be given to a project member
|
||||
def self.find_all_givable
|
||||
find(:all, :conditions => {:builtin => 0}, :order => 'position')
|
||||
end
|
||||
|
||||
# Return the builtin 'non member' role
|
||||
def self.non_member
|
||||
find(:first, :conditions => {:builtin => BUILTIN_NON_MEMBER}) || raise('Missing non-member builtin role.')
|
||||
end
|
||||
|
||||
# Return the builtin 'anonymous' role
|
||||
def self.anonymous
|
||||
find(:first, :conditions => {:builtin => BUILTIN_ANONYMOUS}) || raise('Missing anonymous builtin role.')
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def allowed_permissions
|
||||
@allowed_permissions ||= permissions + Redmine::AccessControl.public_permissions.collect {|p| p.name}
|
||||
end
|
||||
|
||||
def allowed_actions
|
||||
@actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
|
||||
end
|
||||
|
||||
def check_deletable
|
||||
raise "Can't delete role" if members.any?
|
||||
raise "Can't delete builtin role" if builtin?
|
||||
end
|
||||
end
|
||||
@@ -1,164 +0,0 @@
|
||||
# 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
|
||||
# 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 Setting < ActiveRecord::Base
|
||||
|
||||
DATE_FORMATS = [
|
||||
'%Y-%m-%d',
|
||||
'%d/%m/%Y',
|
||||
'%d.%m.%Y',
|
||||
'%d-%m-%Y',
|
||||
'%m/%d/%Y',
|
||||
'%d %b %Y',
|
||||
'%d %B %Y',
|
||||
'%b %d, %Y',
|
||||
'%B %d, %Y'
|
||||
]
|
||||
|
||||
TIME_FORMATS = [
|
||||
'%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|
|
||||
next unless plugin.settings
|
||||
@@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
|
||||
end
|
||||
|
||||
validates_uniqueness_of :name
|
||||
validates_inclusion_of :name, :in => @@available_settings.keys
|
||||
validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }
|
||||
|
||||
# Hash used to cache setting values
|
||||
@cached_settings = {}
|
||||
@cached_cleared_on = Time.now
|
||||
|
||||
def value
|
||||
v = read_attribute(:value)
|
||||
# Unserialize serialized settings
|
||||
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String)
|
||||
v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank?
|
||||
v
|
||||
end
|
||||
|
||||
def value=(v)
|
||||
v = v.to_yaml if v && @@available_settings[name]['serialized']
|
||||
write_attribute(:value, v.to_s)
|
||||
end
|
||||
|
||||
# Returns the value of the setting named name
|
||||
def self.[](name)
|
||||
v = @cached_settings[name]
|
||||
v ? v : (@cached_settings[name] = find_or_default(name).value)
|
||||
end
|
||||
|
||||
def self.[]=(name, v)
|
||||
setting = find_or_default(name)
|
||||
setting.value = (v ? v : "")
|
||||
@cached_settings[name] = nil
|
||||
setting.save
|
||||
setting.value
|
||||
end
|
||||
|
||||
# Defines getter and setter for each setting
|
||||
# Then setting values can be read using: Setting.some_setting_name
|
||||
# or set using Setting.some_setting_name = "some value"
|
||||
@@available_settings.each do |name, params|
|
||||
src = <<-END_SRC
|
||||
def self.#{name}
|
||||
self[:#{name}]
|
||||
end
|
||||
|
||||
def self.#{name}?
|
||||
self[:#{name}].to_i > 0
|
||||
end
|
||||
|
||||
def self.#{name}=(value)
|
||||
self[:#{name}] = value
|
||||
end
|
||||
END_SRC
|
||||
class_eval src, __FILE__, __LINE__
|
||||
end
|
||||
|
||||
# Helper that returns an array based on per_page_options setting
|
||||
def self.per_page_options_array
|
||||
per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
|
||||
end
|
||||
|
||||
# Checks if settings have changed since the values were read
|
||||
# and clears the cache hash if it's the case
|
||||
# Called once per request
|
||||
def self.check_cache
|
||||
settings_updated_on = Setting.maximum(:updated_on)
|
||||
if settings_updated_on && @cached_cleared_on <= settings_updated_on
|
||||
@cached_settings.clear
|
||||
@cached_cleared_on = Time.now
|
||||
logger.info "Settings cache cleared." if logger
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Returns the Setting instance for the setting named name
|
||||
# (record found in database or new record with default value)
|
||||
def self.find_or_default(name)
|
||||
name = name.to_s
|
||||
raise "There's no setting named #{name}" unless @@available_settings.has_key?(name)
|
||||
setting = find_by_name(name)
|
||||
setting ||= new(:name => name, :value => @@available_settings[name]['default']) if @@available_settings.has_key? name
|
||||
end
|
||||
end
|
||||
@@ -1,79 +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 TimeEntry < ActiveRecord::Base
|
||||
# could have used polymorphic association
|
||||
# project association here allows easy loading of time entries at project level with one database trip
|
||||
belongs_to :project
|
||||
belongs_to :issue
|
||||
belongs_to :user
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def validate
|
||||
errors.add :hours, :activerecord_error_invalid if hours && (hours < 0 || hours >= 1000)
|
||||
errors.add :project_id, :activerecord_error_invalid if project.nil?
|
||||
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)
|
||||
super
|
||||
self.tyear = spent_on ? spent_on.year : nil
|
||||
self.tmonth = spent_on ? spent_on.month : nil
|
||||
self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil
|
||||
end
|
||||
|
||||
# Returns true if the time entry can be edited by usr, otherwise false
|
||||
def editable_by?(usr)
|
||||
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
|
||||
end
|
||||
|
||||
def self.visible_by(usr)
|
||||
with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,56 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class Tracker < ActiveRecord::Base
|
||||
before_destroy :check_integrity
|
||||
has_many :issues
|
||||
has_many :workflows, :dependent => :delete_all do
|
||||
def copy(tracker)
|
||||
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)" +
|
||||
" SELECT #{proxy_owner.id}, old_status_id, new_status_id, role_id" +
|
||||
" FROM #{Workflow.table_name}" +
|
||||
" WHERE tracker_id = #{tracker.id}"
|
||||
end
|
||||
end
|
||||
|
||||
has_and_belongs_to_many :projects
|
||||
has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
|
||||
acts_as_list
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
||||
|
||||
def to_s; name end
|
||||
|
||||
def <=>(tracker)
|
||||
name <=> tracker.name
|
||||
end
|
||||
|
||||
def self.all
|
||||
find(:all, :order => 'position')
|
||||
end
|
||||
|
||||
private
|
||||
def check_integrity
|
||||
raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id])
|
||||
end
|
||||
end
|
||||
@@ -1,300 +0,0 @@
|
||||
# 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
|
||||
# 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 "digest/sha1"
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
|
||||
# Account statuses
|
||||
STATUS_ANONYMOUS = 0
|
||||
STATUS_ACTIVE = 1
|
||||
STATUS_REGISTERED = 2
|
||||
STATUS_LOCKED = 3
|
||||
|
||||
USER_FORMATS = {
|
||||
:firstname_lastname => '#{firstname} #{lastname}',
|
||||
:firstname => '#{firstname}',
|
||||
:lastname_firstname => '#{lastname} #{firstname}',
|
||||
:lastname_coma_firstname => '#{lastname}, #{firstname}',
|
||||
: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 :projects, :through => :memberships
|
||||
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
|
||||
attr_protected :login, :admin, :password, :password_confirmation, :hashed_password
|
||||
|
||||
validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
|
||||
validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? }
|
||||
validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? }
|
||||
# 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_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
|
||||
|
||||
def before_create
|
||||
self.mail_notification = false
|
||||
true
|
||||
end
|
||||
|
||||
def before_save
|
||||
# update hashed_password if password was set
|
||||
self.hashed_password = User.hash_password(self.password) if self.password
|
||||
end
|
||||
|
||||
def reload(*args)
|
||||
@name = nil
|
||||
super
|
||||
end
|
||||
|
||||
# Returns the user that matches provided login and password, or nil
|
||||
def self.try_to_login(login, password)
|
||||
# Make sure no one can sign in with an empty password
|
||||
return nil if password.to_s.empty?
|
||||
user = find(:first, :conditions => ["login=?", login])
|
||||
if user
|
||||
# user is already in local database
|
||||
return nil if !user.active?
|
||||
if user.auth_source
|
||||
# user has an external authentication method
|
||||
return nil unless user.auth_source.authenticate(login, password)
|
||||
else
|
||||
# authentication with local password
|
||||
return nil unless User.hash_password(password) == user.hashed_password
|
||||
end
|
||||
else
|
||||
# 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
|
||||
end
|
||||
end
|
||||
end
|
||||
user.update_attribute(:last_login_on, Time.now) if user && !user.new_record?
|
||||
user
|
||||
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
|
||||
end
|
||||
|
||||
def active?
|
||||
self.status == STATUS_ACTIVE
|
||||
end
|
||||
|
||||
def registered?
|
||||
self.status == STATUS_REGISTERED
|
||||
end
|
||||
|
||||
def locked?
|
||||
self.status == STATUS_LOCKED
|
||||
end
|
||||
|
||||
def check_password?(clear_password)
|
||||
User.hash_password(clear_password) == self.hashed_password
|
||||
end
|
||||
|
||||
def pref
|
||||
self.preference ||= UserPreference.new(:user => self)
|
||||
end
|
||||
|
||||
def time_zone
|
||||
@time_zone ||= (self.pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[self.pref.time_zone])
|
||||
end
|
||||
|
||||
def wants_comments_in_reverse_order?
|
||||
self.pref[:comments_sorting] == 'desc'
|
||||
end
|
||||
|
||||
# Return user's RSS key (a 40 chars long string), used to access feeds
|
||||
def rss_key
|
||||
token = self.rss_token || Token.create(:user => self, :action => 'feeds')
|
||||
token.value
|
||||
end
|
||||
|
||||
# Return an array of project ids for which the user has explicitly turned mail notifications on
|
||||
def notified_projects_ids
|
||||
@notified_projects_ids ||= memberships.select {|m| m.mail_notification?}.collect(&:project_id)
|
||||
end
|
||||
|
||||
def notified_project_ids=(ids)
|
||||
Member.update_all("mail_notification = #{connection.quoted_false}", ['user_id = ?', id])
|
||||
Member.update_all("mail_notification = #{connection.quoted_true}", ['user_id = ? AND project_id IN (?)', id, ids]) if ids && !ids.empty?
|
||||
@notified_projects_ids = nil
|
||||
notified_projects_ids
|
||||
end
|
||||
|
||||
def self.find_by_rss_key(key)
|
||||
token = Token.find_by_value(key)
|
||||
token && token.user.active? ? token.user : nil
|
||||
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])
|
||||
end
|
||||
|
||||
# Sort users by their display names
|
||||
def <=>(user)
|
||||
self.to_s.downcase <=> user.to_s.downcase
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
def logged?
|
||||
true
|
||||
end
|
||||
|
||||
def anonymous?
|
||||
!logged?
|
||||
end
|
||||
|
||||
# Return user's role for project
|
||||
def role_for_project(project)
|
||||
# No role on archived projects
|
||||
return nil unless project && project.active?
|
||||
if logged?
|
||||
# Find project membership
|
||||
membership = memberships.detect {|m| m.project_id == project.id}
|
||||
if membership
|
||||
membership.role
|
||||
else
|
||||
@role_non_member ||= Role.non_member
|
||||
end
|
||||
else
|
||||
@role_anonymous ||= Role.anonymous
|
||||
end
|
||||
end
|
||||
|
||||
# Return true if the user is a member of project
|
||||
def member_of?(project)
|
||||
role_for_project(project).member?
|
||||
end
|
||||
|
||||
# Return true if the user is allowed to do the specified action on project
|
||||
# action can be:
|
||||
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
||||
# * a permission Symbol (eg. :edit_project)
|
||||
def allowed_to?(action, project, options={})
|
||||
if project
|
||||
# No action allowed on archived projects
|
||||
return false unless project.active?
|
||||
# No action allowed on disabled modules
|
||||
return false unless project.allows_to?(action)
|
||||
# Admin users are authorized for anything else
|
||||
return true if admin?
|
||||
|
||||
role = role_for_project(project)
|
||||
return false unless role
|
||||
role.allowed_to?(action) && (project.is_public? || role.member?)
|
||||
|
||||
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))
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def self.current=(user)
|
||||
@current_user = user
|
||||
end
|
||||
|
||||
def self.current
|
||||
@current_user ||= User.anonymous
|
||||
end
|
||||
|
||||
def self.anonymous
|
||||
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
|
||||
end
|
||||
|
||||
private
|
||||
# Return password digest
|
||||
def self.hash_password(clear_password)
|
||||
Digest::SHA1.hexdigest(clear_password || "")
|
||||
end
|
||||
end
|
||||
|
||||
class AnonymousUser < User
|
||||
|
||||
def validate_on_create
|
||||
# There should be only one AnonymousUser in the database
|
||||
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
|
||||
def name; 'Anonymous' end
|
||||
def mail; nil end
|
||||
def time_zone; nil end
|
||||
def rss_key; nil end
|
||||
end
|
||||
@@ -1,107 +0,0 @@
|
||||
# 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.
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def start_date
|
||||
effective_date
|
||||
end
|
||||
|
||||
def due_date
|
||||
effective_date
|
||||
end
|
||||
|
||||
# Returns the total estimated time for this version
|
||||
def estimated_hours
|
||||
@estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f
|
||||
end
|
||||
|
||||
# Returns the total reported time for this version
|
||||
def spent_hours
|
||||
@spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f
|
||||
end
|
||||
|
||||
# Returns true if the version is completed: due date reached and no open issues
|
||||
def completed?
|
||||
effective_date && (effective_date <= Date.today) && (open_issues_count == 0)
|
||||
end
|
||||
|
||||
def completed_pourcent
|
||||
if fixed_issues.count == 0
|
||||
0
|
||||
elsif open_issues_count == 0
|
||||
100
|
||||
else
|
||||
(closed_issues_count * 100 + Issue.sum('done_ratio', :include => 'status', :conditions => ["fixed_version_id = ? AND is_closed = ?", id, false]).to_f) / fixed_issues.count
|
||||
end
|
||||
end
|
||||
|
||||
def closed_pourcent
|
||||
if fixed_issues.count == 0
|
||||
0
|
||||
else
|
||||
closed_issues_count * 100.0 / fixed_issues.count
|
||||
end
|
||||
end
|
||||
|
||||
# Returns true if the version is overdue: due date reached and some open issues
|
||||
def overdue?
|
||||
effective_date && (effective_date < Date.today) && (open_issues_count > 0)
|
||||
end
|
||||
|
||||
def open_issues_count
|
||||
@open_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, false], :include => :status)
|
||||
end
|
||||
|
||||
def closed_issues_count
|
||||
@closed_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, true], :include => :status)
|
||||
end
|
||||
|
||||
def wiki_page
|
||||
if project.wiki && !wiki_page_title.blank?
|
||||
@wiki_page ||= project.wiki.find_page(wiki_page_title)
|
||||
end
|
||||
@wiki_page
|
||||
end
|
||||
|
||||
def to_s; name end
|
||||
|
||||
# Versions are sorted by effective_date and name
|
||||
# Those with no effective_date are at the end, sorted by name
|
||||
def <=>(version)
|
||||
if self.effective_date
|
||||
version.effective_date ? (self.effective_date == version.effective_date ? self.name <=> version.name : self.effective_date <=> version.effective_date) : -1
|
||||
else
|
||||
version.effective_date ? 1 : (self.name <=> version.name)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def check_integrity
|
||||
raise "Can't delete version" if self.fixed_issues.find(:first)
|
||||
end
|
||||
end
|
||||
@@ -1,30 +0,0 @@
|
||||
# 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
|
||||
# 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 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
|
||||
@@ -1,73 +0,0 @@
|
||||
# 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
|
||||
# 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 Wiki < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
has_many :pages, :class_name => 'WikiPage', :dependent => :destroy, :order => 'title'
|
||||
has_many :redirects, :class_name => 'WikiRedirect', :dependent => :delete_all
|
||||
|
||||
validates_presence_of :start_page
|
||||
validates_format_of :start_page, :with => /^[^,\.\/\?\;\|\:]*$/
|
||||
|
||||
# find the page with the given title
|
||||
# if page doesn't exist, return a new page
|
||||
def find_or_new_page(title)
|
||||
title = start_page if title.blank?
|
||||
find_page(title) || WikiPage.new(:wiki => self, :title => Wiki.titleize(title))
|
||||
end
|
||||
|
||||
# find the page with the given title
|
||||
def find_page(title, options = {})
|
||||
title = start_page if title.blank?
|
||||
title = Wiki.titleize(title)
|
||||
page = pages.find_by_title(title)
|
||||
if !page && !(options[:with_redirect] == false)
|
||||
# search for a redirect
|
||||
redirect = redirects.find_by_title(title)
|
||||
page = find_page(redirect.redirects_to, :with_redirect => false) if redirect
|
||||
end
|
||||
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
|
||||
title = title.gsub(/\s+/, '_').delete(',./?;|:') if title
|
||||
# upcase the first letter
|
||||
title = (title.slice(0..0).upcase + (title.slice(1..-1) || '')) if title
|
||||
title
|
||||
end
|
||||
end
|
||||
@@ -1,91 +0,0 @@
|
||||
# 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
|
||||
# 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 'zlib'
|
||||
|
||||
class WikiContent < ActiveRecord::Base
|
||||
set_locking_column :version
|
||||
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
|
||||
belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id'
|
||||
belongs_to :author, :class_name => '::User', :foreign_key => 'author_id'
|
||||
attr_protected :data
|
||||
|
||||
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'
|
||||
begin
|
||||
self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION)
|
||||
self.compression = 'gzip'
|
||||
rescue
|
||||
self.data = plain
|
||||
self.compression = ''
|
||||
end
|
||||
else
|
||||
self.data = plain
|
||||
self.compression = ''
|
||||
end
|
||||
plain
|
||||
end
|
||||
|
||||
def text
|
||||
@text ||= case compression
|
||||
when 'gzip'
|
||||
Zlib::Inflate.inflate(data)
|
||||
else
|
||||
# uncompressed data
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
def project
|
||||
page.project
|
||||
end
|
||||
|
||||
# Returns the previous version or nil
|
||||
def previous
|
||||
@previous ||= WikiContent::Version.find(:first,
|
||||
:order => 'version DESC',
|
||||
:include => :author,
|
||||
:conditions => ["wiki_content_id = ? AND version < ?", wiki_content_id, version])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,188 +0,0 @@
|
||||
# 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
|
||||
# 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 'diff'
|
||||
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'
|
||||
|
||||
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],
|
||||
:project_key => "#{Wiki.table_name}.project_id"
|
||||
|
||||
attr_accessor :redirect_existing_links
|
||||
|
||||
validates_presence_of :title
|
||||
validates_format_of :title, :with => /^[^,\.\/\?\;\|\s]*$/
|
||||
validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
|
||||
validates_associated :content
|
||||
|
||||
def title=(value)
|
||||
value = Wiki.titleize(value)
|
||||
@previous_title = read_attribute(:title) if @previous_title.blank?
|
||||
write_attribute(:title, value)
|
||||
end
|
||||
|
||||
def before_save
|
||||
self.title = Wiki.titleize(title)
|
||||
# Manage redirects if the title has changed
|
||||
if !@previous_title.blank? && (@previous_title != title) && !new_record?
|
||||
# Update redirects that point to the old title
|
||||
wiki.redirects.find_all_by_redirects_to(@previous_title).each do |r|
|
||||
r.redirects_to = title
|
||||
r.title == r.redirects_to ? r.destroy : r.save
|
||||
end
|
||||
# Remove redirects for the new title
|
||||
wiki.redirects.find_all_by_title(title).each(&:destroy)
|
||||
# Create a redirect to the new title
|
||||
wiki.redirects << WikiRedirect.new(:title => @previous_title, :redirects_to => title) unless redirect_existing_links == "0"
|
||||
@previous_title = nil
|
||||
end
|
||||
end
|
||||
|
||||
def before_destroy
|
||||
# Remove redirects to this page
|
||||
wiki.redirects.find_all_by_redirects_to(title).each(&:destroy)
|
||||
end
|
||||
|
||||
def pretty_title
|
||||
WikiPage.pretty_title(title)
|
||||
end
|
||||
|
||||
def content_for_version(version=nil)
|
||||
result = content.versions.find_by_version(version.to_i) if version
|
||||
result ||= content
|
||||
result
|
||||
end
|
||||
|
||||
def diff(version_to=nil, version_from=nil)
|
||||
version_to = version_to ? version_to.to_i : self.content.version
|
||||
version_from = version_from ? version_from.to_i : version_to - 1
|
||||
version_to, version_from = version_from, version_to unless version_from < version_to
|
||||
|
||||
content_to = content.versions.find_by_version(version_to)
|
||||
content_from = content.versions.find_by_version(version_from)
|
||||
|
||||
(content_to && content_from) ? WikiDiff.new(content_to, content_from) : nil
|
||||
end
|
||||
|
||||
def annotate(version=nil)
|
||||
version = version ? version.to_i : self.content.version
|
||||
c = content.versions.find_by_version(version)
|
||||
c ? WikiAnnotate.new(c) : nil
|
||||
end
|
||||
|
||||
def self.pretty_title(str)
|
||||
(str && str.is_a?(String)) ? str.tr('_', ' ') : str
|
||||
end
|
||||
|
||||
def project
|
||||
wiki.project
|
||||
end
|
||||
|
||||
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
|
||||
attr_reader :diff, :words, :content_to, :content_from
|
||||
|
||||
def initialize(content_to, content_from)
|
||||
@content_to = content_to
|
||||
@content_from = content_from
|
||||
@words = content_to.text.split(/(\s+)/)
|
||||
@words = @words.select {|word| word != ' '}
|
||||
words_from = content_from.text.split(/(\s+)/)
|
||||
words_from = words_from.select {|word| word != ' '}
|
||||
@diff = words_from.diff @words
|
||||
end
|
||||
end
|
||||
|
||||
class WikiAnnotate
|
||||
attr_reader :lines, :content
|
||||
|
||||
def initialize(content)
|
||||
@content = content
|
||||
current = content
|
||||
current_lines = current.text.split(/\r?\n/)
|
||||
@lines = current_lines.collect {|t| [nil, nil, t]}
|
||||
positions = []
|
||||
current_lines.size.times {|i| positions << i}
|
||||
while (current.previous)
|
||||
d = current.previous.text.split(/\r?\n/).diff(current.text.split(/\r?\n/)).diffs.flatten
|
||||
d.each_slice(3) do |s|
|
||||
sign, line = s[0], s[1]
|
||||
if sign == '+' && positions[line] && positions[line] != -1
|
||||
if @lines[positions[line]][0].nil?
|
||||
@lines[positions[line]][0] = current.version
|
||||
@lines[positions[line]][1] = current.author
|
||||
end
|
||||
end
|
||||
end
|
||||
d.each_slice(3) do |s|
|
||||
sign, line = s[0], s[1]
|
||||
if sign == '-'
|
||||
positions.insert(line, -1)
|
||||
else
|
||||
positions[line] = nil
|
||||
end
|
||||
end
|
||||
positions.compact!
|
||||
# Stop if every line is annotated
|
||||
break unless @lines.detect { |line| line[0].nil? }
|
||||
current = current.previous
|
||||
end
|
||||
@lines.each { |line| line[0] ||= current.version }
|
||||
end
|
||||
end
|
||||
@@ -1,23 +0,0 @@
|
||||
# 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
|
||||
# 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 WikiRedirect < ActiveRecord::Base
|
||||
belongs_to :wiki
|
||||
|
||||
validates_presence_of :title, :redirects_to
|
||||
validates_length_of :title, :redirects_to, :maximum => 255
|
||||
end
|
||||
@@ -1,43 +0,0 @@
|
||||
# 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.
|
||||
|
||||
class Workflow < ActiveRecord::Base
|
||||
belongs_to :role
|
||||
belongs_to :old_status, :class_name => 'IssueStatus', :foreign_key => 'old_status_id'
|
||||
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,34 +0,0 @@
|
||||
<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>
|
||||
<td align="left"><p><%= text_field_tag 'username', nil, :size => 40 %></p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right"><label for="password"><%=l(:field_password)%>:</label></td>
|
||||
<td align="left"><%= password_field_tag 'password', nil, :size => 40 %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td align="left">
|
||||
<% if Setting.autologin? %>
|
||||
<label for="autologin"><%= check_box_tag 'autologin' %> <%= l(:label_stay_logged_in) %></label>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
<% if Setting.lost_password? %>
|
||||
<%= link_to l(:label_password_lost), :controller => 'account', :action => 'lost_password' %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td align="right">
|
||||
<input type="submit" name="login" value="<%=l(:button_login)%> »" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<%= javascript_tag "Form.Element.focus('username');" %>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,11 +0,0 @@
|
||||
<h2><%=l(:label_password_lost)%></h2>
|
||||
|
||||
<div class="box">
|
||||
<% form_tag({:action=> "lost_password"}, :class => "tabular") do %>
|
||||
|
||||
<p><label for="mail"><%=l(:field_mail)%> <span class="required">*</span></label>
|
||||
<%= text_field_tag 'mail', nil, :size => 40 %>
|
||||
<%= submit_tag l(:button_submit) %></p>
|
||||
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,15 +0,0 @@
|
||||
<h2><%=l(:label_password_lost)%></h2>
|
||||
|
||||
<%= error_messages_for 'user' %>
|
||||
|
||||
<% form_tag({:token => @token.value}) do %>
|
||||
<div class="box tabular">
|
||||
<p><label for="new_password"><%=l(:field_new_password)%> <span class="required">*</span></label>
|
||||
<%= password_field_tag 'new_password', nil, :size => 25 %><br />
|
||||
<em><%= l(:text_caracters_minimum, 4) %></em></p>
|
||||
|
||||
<p><label for="new_password_confirmation"><%=l(:field_password_confirmation)%> <span class="required">*</span></label>
|
||||
<%= password_field_tag 'new_password_confirmation', nil, :size => 25 %></p>
|
||||
</div>
|
||||
<p><%= submit_tag l(:button_save) %></p>
|
||||
<% end %>
|
||||
@@ -1,69 +0,0 @@
|
||||
<div class="contextual">
|
||||
<%= link_to(l(:button_edit), {:controller => 'users', :action => 'edit', :id => @user}, :class => 'icon icon-edit') if User.current.admin? %>
|
||||
</div>
|
||||
|
||||
<h2><%= avatar @user %> <%=h @user.name %></h2>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<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.empty? %>
|
||||
<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 %>
|
||||
</ul>
|
||||
|
||||
<% 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>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
</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>
|
||||
|
||||
<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 %>
|
||||
</div>
|
||||
|
||||
<% html_title @user.name %>
|
||||
@@ -1,25 +0,0 @@
|
||||
<div id="menuAdmin" class="menu" onmouseover="menuMouseover(event)">
|
||||
<a class="menuItem" href="#" onmouseover="menuItemMouseover(event,'menuProjects');" onclick="this.blur(); return false;"><span class="menuItemText"><%=l(:label_project_plural)%></span><span class="menuItemArrow">▶</span></a>
|
||||
<a class="menuItem" href="#" onmouseover="menuItemMouseover(event,'menuUsers');" onclick="this.blur(); return false;"><span class="menuItemText"><%=l(:label_user_plural)%></span><span class="menuItemArrow">▶</span></a>
|
||||
<%= link_to l(:label_role_and_permissions), {:controller => 'roles' }, :class => "menuItem" %>
|
||||
<a class="menuItem" href="#" onmouseover="menuItemMouseover(event,'menuTrackers');" onclick="this.blur(); return false;"><span class="menuItemText"><%=l(:label_issue_tracking)%></span><span class="menuItemArrow">▶</span></a>
|
||||
<%= link_to l(:label_custom_field_plural), {:controller => 'custom_fields' }, :class => "menuItem" %>
|
||||
<%= link_to l(:label_enumerations), {:controller => 'enumerations' }, :class => "menuItem" %>
|
||||
<%= link_to l(:field_mail_notification), {:controller => 'admin', :action => 'mail_options' }, :class => "menuItem" %>
|
||||
<%= link_to l(:label_authentication), {:controller => 'auth_sources' }, :class => "menuItem" %>
|
||||
<%= link_to l(:label_settings), {:controller => 'settings' }, :class => "menuItem" %>
|
||||
<%= link_to l(:label_information_plural), {:controller => 'admin', :action => 'info' }, :class => "menuItem" %>
|
||||
</div>
|
||||
<div id="menuTrackers" class="menu">
|
||||
<%= link_to l(:label_tracker_plural), {:controller => 'trackers' }, :class => "menuItem" %>
|
||||
<%= link_to l(:label_issue_status_plural), {:controller => 'issue_statuses' }, :class => "menuItem" %>
|
||||
<%= link_to l(:label_workflow), {:controller => 'roles', :action => 'workflow' }, :class => "menuItem" %>
|
||||
</div>
|
||||
<div id="menuProjects" class="menu">
|
||||
<%= link_to l(:button_list), {:controller => 'admin', :action => 'projects' }, :class => "menuItem" %>
|
||||
<%= link_to l(:label_new), {:controller => 'projects', :action => 'add' }, :class => "menuItem" %>
|
||||
</div>
|
||||
<div id="menuUsers" class="menu">
|
||||
<%= link_to l(:button_list), {:controller => 'users' }, :class => "menuItem" %>
|
||||
<%= link_to l(:label_new), {:controller => 'users', :action => 'add' }, :class => "menuItem" %>
|
||||
</div>
|
||||
@@ -1,8 +0,0 @@
|
||||
<div class="nodata">
|
||||
<% form_tag({:action => 'default_configuration'}) do %>
|
||||
<%= simple_format(l(:text_no_configuration_data)) %>
|
||||
<p><%= l(:field_language) %>:
|
||||
<%= select_tag 'lang', options_for_select(lang_options_for_select(false), current_language.to_s) %>
|
||||
<%= submit_tag l(:text_load_default_configuration) %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,51 +0,0 @@
|
||||
<h2><%=l(:label_administration)%></h2>
|
||||
|
||||
<%= render :partial => 'no_data' if @no_configuration_data %>
|
||||
|
||||
<p class="icon22 icon22-projects">
|
||||
<%= link_to l(:label_project_plural), :controller => 'admin', :action => 'projects' %> |
|
||||
<%= link_to l(:label_new), :controller => 'projects', :action => 'add' %>
|
||||
</p>
|
||||
|
||||
<p class="icon22 icon22-users">
|
||||
<%= link_to l(:label_user_plural), :controller => 'users' %> |
|
||||
<%= link_to l(:label_new), :controller => 'users', :action => 'add' %>
|
||||
</p>
|
||||
|
||||
<p class="icon22 icon22-role">
|
||||
<%= link_to l(:label_role_and_permissions), :controller => 'roles' %>
|
||||
</p>
|
||||
|
||||
<p class="icon22 icon22-tracker">
|
||||
<%= link_to l(:label_tracker_plural), :controller => 'trackers' %> |
|
||||
<%= link_to l(:label_issue_status_plural), :controller => 'issue_statuses' %> |
|
||||
<%= link_to l(:label_workflow), :controller => 'workflows', :action => 'edit' %>
|
||||
</p>
|
||||
|
||||
<p class="icon22 icon22-workflow">
|
||||
<%= link_to l(:label_custom_field_plural), :controller => 'custom_fields' %>
|
||||
</p>
|
||||
|
||||
<p class="icon22 icon22-options">
|
||||
<%= link_to l(:label_enumerations), :controller => 'enumerations' %>
|
||||
</p>
|
||||
|
||||
<p class="icon22 icon22-settings">
|
||||
<%= link_to l(:label_settings), :controller => 'settings' %>
|
||||
</p>
|
||||
|
||||
<% menu_items_for(:admin_menu) do |item, caption, url, selected| -%>
|
||||
<%= content_tag 'p',
|
||||
link_to(h(caption), item.url, item.html_options),
|
||||
:class => ["icon22", "icon22-#{item.name}"].join(' ') %>
|
||||
<% end -%>
|
||||
|
||||
<p class="icon22 icon22-plugin">
|
||||
<%= link_to l(:label_plugins), :controller => 'admin', :action => 'plugins' %>
|
||||
</p>
|
||||
|
||||
<p class="icon22 icon22-info">
|
||||
<%= link_to l(:label_information_plural), :controller => 'admin', :action => 'info' %>
|
||||
</p>
|
||||
|
||||
<% html_title(l(:label_administration)) -%>
|
||||
@@ -1,12 +0,0 @@
|
||||
<h2><%=l(:label_information_plural)%></h2>
|
||||
|
||||
<p><strong><%= Redmine::Info.versioned_name %></strong> (<%= @db_adapter_name %>)</p>
|
||||
|
||||
<table class="list">
|
||||
<tr class="odd"><td><%= l(:text_default_administrator_account_changed) %></td><td><%= image_tag (@flags[:default_admin_changed] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
|
||||
<tr class="even"><td><%= l(:text_file_repository_writable) %> (<%= Attachment.storage_path %>)</td><td><%= image_tag (@flags[:file_repository_writable] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
|
||||
<tr class="even"><td><%= l(:text_plugin_assets_writable) %> (<%= Engines.public_directory %>)</td><td><%= image_tag (@flags[:plugin_assets_writable] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
|
||||
<tr class="odd"><td><%= l(:text_rmagick_available) %></td><td><%= image_tag (@flags[:rmagick_available] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
|
||||
</table>
|
||||
|
||||
<% html_title(l(:label_information_plural)) -%>
|
||||
@@ -1,19 +0,0 @@
|
||||
<h2><%= l(:label_plugins) %></h2>
|
||||
|
||||
<% if @plugins.any? %>
|
||||
<table class="list plugins">
|
||||
<% @plugins.each do |plugin| %>
|
||||
<tr class="<%= cycle('odd', 'even') %>">
|
||||
<td><span class="name"><%=h plugin.name %></span>
|
||||
<%= content_tag('span', h(plugin.description), :class => 'description') unless plugin.description.blank? %>
|
||||
<%= content_tag('span', link_to(h(plugin.url), plugin.url), :class => 'url') unless plugin.url.blank? %>
|
||||
</td>
|
||||
<td class="author"><%= plugin.author_url.blank? ? h(plugin.author) : link_to(h(plugin.author), plugin.author_url) %></td>
|
||||
<td class="version"><%=h plugin.version %></td>
|
||||
<td class="configure"><%= link_to(l(:button_configure), :controller => 'settings', :action => 'plugin', :id => plugin.id) if plugin.configurable? %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
@@ -1,52 +0,0 @@
|
||||
<div class="contextual">
|
||||
<%= link_to l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add' %>
|
||||
</div>
|
||||
|
||||
<h2><%=l(:label_project_plural)%></h2>
|
||||
|
||||
<% form_tag({}, :method => :get) do %>
|
||||
<fieldset><legend><%= l(:label_filter_plural) %></legend>
|
||||
<label><%= l(:field_status) %> :</label>
|
||||
<%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
|
||||
<label><%= l(:label_project) %>:</label>
|
||||
<%= text_field_tag 'name', params[:name], :size => 30 %>
|
||||
<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
|
||||
<table class="list">
|
||||
<thead><tr>
|
||||
<%= sort_header_tag('name', :caption => l(:label_project)) %>
|
||||
<th><%=l(:field_description)%></th>
|
||||
<th><%=l(:label_subproject_plural)%></th>
|
||||
<%= sort_header_tag('is_public', :caption => l(:field_is_public), :default_order => 'desc') %>
|
||||
<%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<% for project in @projects %>
|
||||
<tr class="<%= cycle("odd", "even") %>">
|
||||
<td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %>
|
||||
<td><%= textilizable project.short_description, :project => project %>
|
||||
<td align="center"><%= project.children.size %>
|
||||
<td align="center"><%= image_tag 'true.png' if project.is_public? %>
|
||||
<td align="center"><%= format_date(project.created_on) %>
|
||||
<td align="center" style="width:10%">
|
||||
<small>
|
||||
<%= link_to(l(:button_archive), { :controller => 'projects', :action => 'archive', :id => project }, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-lock') if project.active? %>
|
||||
<%= link_to(l(:button_unarchive), { :controller => 'projects', :action => 'unarchive', :id => project }, :method => :post, :class => 'icon icon-unlock') if !project.active? && (project.parent.nil? || project.parent.active?) %>
|
||||
</small>
|
||||
</td>
|
||||
<td align="center" style="width:10%">
|
||||
<small><%= link_to(l(:button_delete), { :controller => 'projects', :action => 'destroy', :id => project }, :class => 'icon icon-del') %></small>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="pagination"><%= pagination_links_full @project_pages, @project_count %></p>
|
||||
|
||||
<% html_title(l(:label_project_plural)) -%>
|
||||
@@ -1,9 +0,0 @@
|
||||
<span id="attachments_fields">
|
||||
<%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil -%>
|
||||
<%= text_field_tag 'attachments[1][description]', '', :size => 60, :id => nil %>
|
||||
<em><%= l(:label_optional_description) %></em>
|
||||
</span>
|
||||
<br />
|
||||
<small><%= link_to l(:label_add_another_file), '#', :onclick => 'addFileField(); return false;' %>
|
||||
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
|
||||
</small>
|
||||
@@ -1,18 +0,0 @@
|
||||
<div class="attachments">
|
||||
<% for attachment in attachments %>
|
||||
<p><%= link_to_attachment attachment, :class => 'icon icon-attachment' -%>
|
||||
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
|
||||
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
||||
<% if options[:deletable] %>
|
||||
<%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => attachment},
|
||||
:confirm => l(:text_are_you_sure),
|
||||
:method => :post,
|
||||
:class => 'delete',
|
||||
:title => l(:button_delete) %>
|
||||
<% end %>
|
||||
<% if options[:author] %>
|
||||
<span class="author"><%= attachment.author %>, <%= format_time(attachment.created_on) %></span>
|
||||
<% end %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,15 +0,0 @@
|
||||
<h2><%=h @attachment.filename %></h2>
|
||||
|
||||
<div class="attachments">
|
||||
<p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %>
|
||||
<span class="author"><%= @attachment.author %>, <%= format_time(@attachment.created_on) %></span></p>
|
||||
<p><%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%>
|
||||
<span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p>
|
||||
|
||||
</div>
|
||||
|
||||
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %>
|
||||
|
||||
<% content_for :header_tags do -%>
|
||||
<%= stylesheet_link_tag "scm" -%>
|
||||
<% end -%>
|
||||
@@ -1,15 +0,0 @@
|
||||
<h2><%=h @attachment.filename %></h2>
|
||||
|
||||
<div class="attachments">
|
||||
<p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %>
|
||||
<span class="author"><%= @attachment.author %>, <%= format_time(@attachment.created_on) %></span></p>
|
||||
<p><%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%>
|
||||
<span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p>
|
||||
|
||||
</div>
|
||||
|
||||
<%= render :partial => 'common/file', :locals => {:content => @content, :filename => @attachment.filename} %>
|
||||
|
||||
<% content_for :header_tags do -%>
|
||||
<%= stylesheet_link_tag "scm" -%>
|
||||
<% end -%>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user