Compare commits
63 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa4fb5f4ca | ||
|
|
6872c5e0b9 | ||
|
|
e27460a0a7 | ||
|
|
3f6656a495 | ||
|
|
a3f69e248a | ||
|
|
3022d067ba | ||
|
|
e06987ab52 | ||
|
|
ace65df230 | ||
|
|
c5dadfd322 | ||
|
|
7a59f2df12 | ||
|
|
7b699af837 | ||
|
|
babbe88a86 | ||
|
|
51a9f6a6eb | ||
|
|
16810acf01 | ||
|
|
e28b5e1f08 | ||
|
|
aa38f755c6 | ||
|
|
2679cc2045 | ||
|
|
b6600d5fe9 | ||
|
|
37da5ba187 | ||
|
|
20bdba13cf | ||
|
|
46c0d72782 | ||
|
|
36b5d4f6af | ||
|
|
b366375e7e | ||
|
|
629c106a46 | ||
|
|
f19ae06a72 | ||
|
|
69b99aa518 | ||
|
|
cb5d0c469d | ||
|
|
57d10ed893 | ||
|
|
28e4ff8957 | ||
|
|
3d1bd79ffb | ||
|
|
7f957653ad | ||
|
|
9a9141041e | ||
|
|
bc4249e3d3 | ||
|
|
fae04f3ae1 | ||
|
|
b13ef64794 | ||
|
|
683e1c5d73 | ||
|
|
1c1755d278 | ||
|
|
5e6ff86f47 | ||
|
|
764393aa6a | ||
|
|
3155b8ccad | ||
|
|
567c8ed9b0 | ||
|
|
49b6f9e4dd | ||
|
|
c9d4d3a2be | ||
|
|
31178553f3 | ||
|
|
dea10c54f9 | ||
|
|
6abd32be9e | ||
|
|
56318aab53 | ||
|
|
babb14dd94 | ||
|
|
3b90141543 | ||
|
|
bce764d9bc | ||
|
|
b65d546245 | ||
|
|
9f12151ac0 | ||
|
|
78cac6f02b | ||
|
|
16b85bda32 | ||
|
|
733987fbb6 | ||
|
|
7389b4bed0 | ||
|
|
4570fcb7a2 | ||
|
|
0a709660d2 | ||
|
|
633e026e44 | ||
|
|
618ab6004e | ||
|
|
644f03b834 | ||
|
|
1154141ee7 | ||
|
|
bf42d9b706 |
25
.gitignore
vendored
25
.gitignore
vendored
@@ -1,25 +0,0 @@
|
||||
/.project
|
||||
/.loadpath
|
||||
/config/additional_environment.rb
|
||||
/config/configuration.yml
|
||||
/config/database.yml
|
||||
/config/email.yml
|
||||
/config/initializers/session_store.rb
|
||||
/coverage
|
||||
/db/*.db
|
||||
/db/*.sqlite3
|
||||
/db/schema.rb
|
||||
/files/*
|
||||
/lib/redmine/scm/adapters/mercurial/redminehelper.pyc
|
||||
/lib/redmine/scm/adapters/mercurial/redminehelper.pyo
|
||||
/log/*.log*
|
||||
/log/mongrel_debug
|
||||
/public/dispatch.*
|
||||
/public/plugin_assets
|
||||
/tmp/*
|
||||
/tmp/cache/*
|
||||
/tmp/sessions/*
|
||||
/tmp/sockets/*
|
||||
/tmp/test/*
|
||||
/vendor/rails
|
||||
*.rbc
|
||||
29
.hgignore
29
.hgignore
@@ -1,29 +0,0 @@
|
||||
syntax: glob
|
||||
|
||||
.project
|
||||
.loadpath
|
||||
config/additional_environment.rb
|
||||
config/configuration.yml
|
||||
config/database.yml
|
||||
config/email.yml
|
||||
config/initializers/session_store.rb
|
||||
coverage
|
||||
db/*.db
|
||||
db/*.sqlite3
|
||||
db/schema.rb
|
||||
files/*
|
||||
lib/redmine/scm/adapters/mercurial/redminehelper.pyc
|
||||
lib/redmine/scm/adapters/mercurial/redminehelper.pyo
|
||||
log/*.log*
|
||||
log/mongrel_debug
|
||||
public/dispatch.*
|
||||
public/plugin_assets
|
||||
tmp/*
|
||||
tmp/cache/*
|
||||
tmp/sessions/*
|
||||
tmp/sockets/*
|
||||
tmp/test/*
|
||||
vendor/rails
|
||||
*.rbc
|
||||
.svn/
|
||||
.git/
|
||||
@@ -1,5 +0,0 @@
|
||||
= Redmine
|
||||
|
||||
Redmine is a flexible project management web application written using Ruby on Rails framework.
|
||||
|
||||
More details can be found at in the doc directory or on the official website http://www.redmine.org
|
||||
@@ -15,8 +15,19 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class IssueObserver < ActiveRecord::Observer
|
||||
def after_create(issue)
|
||||
Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added')
|
||||
end
|
||||
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,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||
# 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
|
||||
@@ -20,20 +20,60 @@ class AccountController < ApplicationController
|
||||
include CustomFieldsHelper
|
||||
|
||||
# prevents login action to be filtered by check_if_login_required application scope filter
|
||||
skip_before_filter :check_if_login_required
|
||||
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
|
||||
# Logout user
|
||||
self.logged_user = nil
|
||||
else
|
||||
authenticate_user
|
||||
# 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
|
||||
logout_user
|
||||
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
|
||||
|
||||
@@ -59,9 +99,9 @@ class AccountController < ApplicationController
|
||||
if request.post?
|
||||
user = User.find_by_mail(params[:mail])
|
||||
# user not found in db
|
||||
(flash.now[:error] = l(:notice_account_unknown_email); return) unless user
|
||||
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); return) if user.auth_source_id
|
||||
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
|
||||
@@ -83,9 +123,9 @@ class AccountController < ApplicationController
|
||||
else
|
||||
@user = User.new(params[:user])
|
||||
@user.admin = false
|
||||
@user.register
|
||||
@user.status = User::STATUS_REGISTERED
|
||||
if session[:auth_source_registration]
|
||||
@user.activate
|
||||
@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
|
||||
@@ -97,14 +137,31 @@ class AccountController < ApplicationController
|
||||
else
|
||||
@user.login = params[:user][:login]
|
||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
|
||||
|
||||
case Setting.self_registration
|
||||
when '1'
|
||||
register_by_email_activation(@user)
|
||||
# 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'
|
||||
register_automatically(@user)
|
||||
# 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
|
||||
register_manually_by_administrator(@user)
|
||||
# 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
|
||||
@@ -116,8 +173,8 @@ class AccountController < ApplicationController
|
||||
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.registered?
|
||||
user.activate
|
||||
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)
|
||||
@@ -125,160 +182,14 @@ class AccountController < ApplicationController
|
||||
redirect_to :action => 'login'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def logout_user
|
||||
if User.current.logged?
|
||||
cookies.delete :autologin
|
||||
Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin'])
|
||||
self.logged_user = nil
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate_user
|
||||
if Setting.openid? && using_open_id?
|
||||
open_id_authenticate(params[:openid_url])
|
||||
private
|
||||
def logged_user=(user)
|
||||
if user && user.is_a?(User)
|
||||
User.current = user
|
||||
session[:user_id] = user.id
|
||||
else
|
||||
password_authentication
|
||||
User.current = User.anonymous
|
||||
session[:user_id] = nil
|
||||
end
|
||||
end
|
||||
|
||||
def password_authentication
|
||||
user = User.try_to_login(params[:username], params[:password])
|
||||
|
||||
if user.nil?
|
||||
invalid_credentials
|
||||
elsif user.new_record?
|
||||
onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id })
|
||||
else
|
||||
# Valid user
|
||||
successful_authentication(user)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def open_id_authenticate(openid_url)
|
||||
authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration|
|
||||
if result.successful?
|
||||
user = User.find_or_initialize_by_identity_url(identity_url)
|
||||
if user.new_record?
|
||||
# Self-registration off
|
||||
redirect_to(home_url) && return unless Setting.self_registration?
|
||||
|
||||
# Create on the fly
|
||||
user.login = registration['nickname'] unless registration['nickname'].nil?
|
||||
user.mail = registration['email'] unless registration['email'].nil?
|
||||
user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
|
||||
user.random_password
|
||||
user.register
|
||||
|
||||
case Setting.self_registration
|
||||
when '1'
|
||||
register_by_email_activation(user) do
|
||||
onthefly_creation_failed(user)
|
||||
end
|
||||
when '3'
|
||||
register_automatically(user) do
|
||||
onthefly_creation_failed(user)
|
||||
end
|
||||
else
|
||||
register_manually_by_administrator(user) do
|
||||
onthefly_creation_failed(user)
|
||||
end
|
||||
end
|
||||
else
|
||||
# Existing record
|
||||
if user.active?
|
||||
successful_authentication(user)
|
||||
else
|
||||
account_pending
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def successful_authentication(user)
|
||||
# Valid user
|
||||
self.logged_user = user
|
||||
# generate a key and set cookie if autologin
|
||||
if params[:autologin] && Setting.autologin?
|
||||
set_autologin_cookie(user)
|
||||
end
|
||||
call_hook(:controller_account_success_authentication_after, {:user => user })
|
||||
redirect_back_or_default :controller => 'my', :action => 'page'
|
||||
end
|
||||
|
||||
def set_autologin_cookie(user)
|
||||
token = Token.create(:user => user, :action => 'autologin')
|
||||
cookie_name = Redmine::Configuration['autologin_cookie_name'] || 'autologin'
|
||||
cookie_options = {
|
||||
:value => token.value,
|
||||
:expires => 1.year.from_now,
|
||||
:path => (Redmine::Configuration['autologin_cookie_path'] || '/'),
|
||||
:secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false),
|
||||
:httponly => true
|
||||
}
|
||||
cookies[cookie_name] = cookie_options
|
||||
end
|
||||
|
||||
# Onthefly creation failed, display the registration form to fill/fix attributes
|
||||
def onthefly_creation_failed(user, auth_source_options = { })
|
||||
@user = user
|
||||
session[:auth_source_registration] = auth_source_options unless auth_source_options.empty?
|
||||
render :action => 'register'
|
||||
end
|
||||
|
||||
def invalid_credentials
|
||||
logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
|
||||
flash.now[:error] = l(:notice_account_invalid_creditentials)
|
||||
end
|
||||
|
||||
# Register a user for email activation.
|
||||
#
|
||||
# Pass a block for behavior when a user fails to save
|
||||
def register_by_email_activation(user, &block)
|
||||
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'
|
||||
else
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
# Automatically register a user
|
||||
#
|
||||
# Pass a block for behavior when a user fails to save
|
||||
def register_automatically(user, &block)
|
||||
# Automatic activation
|
||||
user.activate
|
||||
user.last_login_on = Time.now
|
||||
if user.save
|
||||
self.logged_user = user
|
||||
flash[:notice] = l(:notice_account_activated)
|
||||
redirect_to :controller => 'my', :action => 'account'
|
||||
else
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
# Manual activation by the administrator
|
||||
#
|
||||
# Pass a block for behavior when a user fails to save
|
||||
def register_manually_by_administrator(user, &block)
|
||||
if user.save
|
||||
# Sends an email to the administrators
|
||||
Mailer.deliver_account_activation_request(user)
|
||||
account_pending
|
||||
else
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
def account_pending
|
||||
flash[:notice] = l(:notice_account_pending)
|
||||
redirect_to :action => 'login'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 ActivitiesController < ApplicationController
|
||||
menu_item :activity
|
||||
before_filter :find_optional_project
|
||||
accept_rss_auth :index
|
||||
|
||||
def index
|
||||
@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)
|
||||
|
||||
if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, events.first, User.current, current_language])
|
||||
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
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# TODO: refactor, duplicated in projects_controller
|
||||
def find_optional_project
|
||||
return true unless params[:id]
|
||||
@project = Project.find(params[:id])
|
||||
authorize
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -16,8 +16,8 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AdminController < ApplicationController
|
||||
layout 'admin'
|
||||
before_filter :require_admin
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
@@ -26,22 +26,33 @@ class AdminController < ApplicationController
|
||||
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
|
||||
@projects = Project.find :all, :order => 'lft',
|
||||
:conditions => c.conditions
|
||||
|
||||
@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
|
||||
@@ -55,7 +66,7 @@ class AdminController < ApplicationController
|
||||
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
|
||||
@@ -69,16 +80,14 @@ class AdminController < ApplicationController
|
||||
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
|
||||
@checklist = [
|
||||
[:text_default_administrator_account_changed,
|
||||
User.find(:first,
|
||||
:conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?],
|
||||
[:text_file_repository_writable, File.writable?(Attachment.storage_path)],
|
||||
[:text_plugin_assets_writable, File.writable?(Engines.public_directory)],
|
||||
[:text_rmagick_available, Object.const_defined?(:Magick)]
|
||||
]
|
||||
end
|
||||
@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
|
||||
|
||||
234
app/controllers/application.rb
Normal file
234
app/controllers/application.rb
Normal file
@@ -0,0 +1,234 @@
|
||||
# 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,517 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 Unauthorized < Exception; end
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
include Redmine::I18n
|
||||
|
||||
layout 'base'
|
||||
exempt_from_layout 'builder', 'rsb'
|
||||
|
||||
# Remove broken cookie after upgrade from 0.8.x (#4292)
|
||||
# See https://rails.lighthouseapp.com/projects/8994/tickets/3360
|
||||
# TODO: remove it when Rails is fixed
|
||||
before_filter :delete_broken_cookies
|
||||
def delete_broken_cookies
|
||||
if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/
|
||||
cookies.delete '_redmine_session'
|
||||
redirect_to home_path
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
before_filter :user_setup, :check_if_login_required, :set_localization
|
||||
filter_parameter_logging :password
|
||||
protect_from_forgery
|
||||
|
||||
rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
|
||||
rescue_from ::Unauthorized, :with => :deny_access
|
||||
|
||||
include Redmine::Search::Controller
|
||||
include Redmine::MenuManager::MenuController
|
||||
helper Redmine::MenuManager::MenuHelper
|
||||
|
||||
Redmine::Scm::Base.all.each do |scm|
|
||||
require_dependency "repository/#{scm.underscore}"
|
||||
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
|
||||
# and starts a session if needed
|
||||
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 starts a new session
|
||||
user = User.try_to_autologin(cookies[:autologin])
|
||||
session[:user_id] = user.id if user
|
||||
user
|
||||
elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
|
||||
# RSS key authentication does not start a session
|
||||
User.find_by_rss_key(params[:key])
|
||||
elsif Setting.rest_api_enabled? && accept_api_auth?
|
||||
if (key = api_key_from_request)
|
||||
# Use API key
|
||||
User.find_by_api_key(key)
|
||||
else
|
||||
# HTTP Basic, either username/password or API key/random
|
||||
authenticate_with_http_basic do |username, password|
|
||||
User.try_to_login(username, password) || User.find_by_api_key(username)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Sets the logged in user
|
||||
def logged_user=(user)
|
||||
reset_session
|
||||
if user && user.is_a?(User)
|
||||
User.current = user
|
||||
session[:user_id] = user.id
|
||||
else
|
||||
User.current = User.anonymous
|
||||
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
|
||||
lang = nil
|
||||
if User.current.logged?
|
||||
lang = find_language(User.current.language)
|
||||
end
|
||||
if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
|
||||
accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
|
||||
if !accept_lang.blank?
|
||||
accept_lang = accept_lang.downcase
|
||||
lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
|
||||
end
|
||||
end
|
||||
lang ||= Setting.default_language
|
||||
set_language_if_valid(lang)
|
||||
end
|
||||
|
||||
def require_login
|
||||
if !User.current.logged?
|
||||
# Extract only the basic url parameters on non-GET requests
|
||||
if request.get?
|
||||
url = url_for(params)
|
||||
else
|
||||
url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
|
||||
format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
|
||||
format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
|
||||
format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
|
||||
format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
|
||||
end
|
||||
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], global = false)
|
||||
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
|
||||
if allowed
|
||||
true
|
||||
else
|
||||
if @project && @project.archived?
|
||||
render_403 :message => :notice_not_authorized_archived_project
|
||||
else
|
||||
deny_access
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Authorize the user for the requested action outside a project
|
||||
def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
|
||||
authorize(ctrl, action, global)
|
||||
end
|
||||
|
||||
# Find project of id params[:id]
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Find project of id params[:project_id]
|
||||
def find_project_by_project_id
|
||||
@project = Project.find(params[:project_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Find a project based on params[:project_id]
|
||||
# TODO: some subclasses override this, see about merging their logic
|
||||
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
|
||||
|
||||
# Finds and sets @project based on @object.project
|
||||
def find_project_from_association
|
||||
render_404 unless @object.present?
|
||||
|
||||
@project = @object.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_model_object
|
||||
model = self.class.read_inheritable_attribute('model_object')
|
||||
if model
|
||||
@object = model.find(params[:id])
|
||||
self.instance_variable_set('@' + controller_name.singularize, @object) if @object
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def self.model_object(model)
|
||||
write_inheritable_attribute('model_object', model)
|
||||
end
|
||||
|
||||
# Filter for bulk issue operations
|
||||
def find_issues
|
||||
@issues = Issue.find_all_by_id(params[:id] || params[:ids])
|
||||
raise ActiveRecord::RecordNotFound if @issues.empty?
|
||||
if @issues.detect {|issue| !issue.visible?}
|
||||
deny_access
|
||||
return
|
||||
end
|
||||
@projects = @issues.collect(&:project).compact.uniq
|
||||
@project = @projects.first if @projects.size == 1
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Check if project is unique before bulk operations
|
||||
def check_project_uniqueness
|
||||
unless @project
|
||||
# TODO: let users bulk edit/move/destroy issues from different projects
|
||||
render_error 'Can not bulk edit/move/destroy issues from different projects'
|
||||
return false
|
||||
end
|
||||
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 back_url
|
||||
params[:back_url] || request.env['HTTP_REFERER']
|
||||
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)
|
||||
return
|
||||
end
|
||||
rescue URI::InvalidURIError
|
||||
# redirect to default
|
||||
end
|
||||
end
|
||||
redirect_to default
|
||||
false
|
||||
end
|
||||
|
||||
def render_403(options={})
|
||||
@project = nil
|
||||
render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
|
||||
return false
|
||||
end
|
||||
|
||||
def render_404(options={})
|
||||
render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
|
||||
return false
|
||||
end
|
||||
|
||||
# Renders an error response
|
||||
def render_error(arg)
|
||||
arg = {:message => arg} unless arg.is_a?(Hash)
|
||||
|
||||
@message = arg[:message]
|
||||
@message = l(@message) if @message.is_a?(Symbol)
|
||||
@status = arg[:status] || 500
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :template => 'common/error', :layout => use_layout, :status => @status
|
||||
}
|
||||
format.atom { head @status }
|
||||
format.xml { head @status }
|
||||
format.js { head @status }
|
||||
format.json { head @status }
|
||||
end
|
||||
end
|
||||
|
||||
# Picks which layout to use based on the request
|
||||
#
|
||||
# @return [boolean, string] name of the layout to use or false for no layout
|
||||
def use_layout
|
||||
request.xhr? ? false : 'base'
|
||||
end
|
||||
|
||||
def invalid_authenticity_token
|
||||
if api_request?
|
||||
logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
|
||||
end
|
||||
render_error "Invalid form authenticity token."
|
||||
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
|
||||
|
||||
# TODO: remove in Redmine 1.4
|
||||
def self.accept_key_auth(*actions)
|
||||
ActiveSupport::Deprecation.warn "ApplicationController.accept_key_auth is deprecated and will be removed in Redmine 1.4. Use accept_rss_auth (or accept_api_auth) instead."
|
||||
accept_rss_auth(*actions)
|
||||
end
|
||||
|
||||
# TODO: remove in Redmine 1.4
|
||||
def accept_key_auth_actions
|
||||
ActiveSupport::Deprecation.warn "ApplicationController.accept_key_auth_actions is deprecated and will be removed in Redmine 1.4. Use accept_rss_auth (or accept_api_auth) instead."
|
||||
self.class.accept_rss_auth
|
||||
end
|
||||
|
||||
def self.accept_rss_auth(*actions)
|
||||
if actions.any?
|
||||
write_inheritable_attribute('accept_rss_auth_actions', actions)
|
||||
else
|
||||
read_inheritable_attribute('accept_rss_auth_actions') || []
|
||||
end
|
||||
end
|
||||
|
||||
def accept_rss_auth?(action=action_name)
|
||||
self.class.accept_rss_auth.include?(action.to_sym)
|
||||
end
|
||||
|
||||
def self.accept_api_auth(*actions)
|
||||
if actions.any?
|
||||
write_inheritable_attribute('accept_api_auth_actions', actions)
|
||||
else
|
||||
read_inheritable_attribute('accept_api_auth_actions') || []
|
||||
end
|
||||
end
|
||||
|
||||
def accept_api_auth?(action=action_name)
|
||||
self.class.accept_api_auth.include?(action.to_sym)
|
||||
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
|
||||
|
||||
# Returns offset and limit used to retrieve objects
|
||||
# for an API response based on offset, limit and page parameters
|
||||
def api_offset_and_limit(options=params)
|
||||
if options[:offset].present?
|
||||
offset = options[:offset].to_i
|
||||
if offset < 0
|
||||
offset = 0
|
||||
end
|
||||
end
|
||||
limit = options[:limit].to_i
|
||||
if limit < 1
|
||||
limit = 25
|
||||
elsif limit > 100
|
||||
limit = 100
|
||||
end
|
||||
if offset.nil? && options[:page].present?
|
||||
offset = (options[:page].to_i - 1) * limit
|
||||
offset = 0 if offset < 0
|
||||
end
|
||||
offset ||= 0
|
||||
|
||||
[offset, limit]
|
||||
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
|
||||
rescue
|
||||
nil
|
||||
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
|
||||
|
||||
def api_request?
|
||||
%w(xml json).include? params[:format]
|
||||
end
|
||||
|
||||
# Returns the API key present in the request
|
||||
def api_key_from_request
|
||||
if params[:key].present?
|
||||
params[:key]
|
||||
elsif request.headers["X-Redmine-API-Key"].present?
|
||||
request.headers["X-Redmine-API-Key"]
|
||||
end
|
||||
end
|
||||
|
||||
# Renders a warning flash if obj has unsaved attachments
|
||||
def render_attachment_warning_if_needed(obj)
|
||||
flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
|
||||
end
|
||||
|
||||
# Sets the `flash` notice or error based the number of issues that did not save
|
||||
#
|
||||
# @param [Array, Issue] issues all of the saved and unsaved Issues
|
||||
# @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
|
||||
def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
|
||||
if unsaved_issue_ids.empty?
|
||||
flash[:notice] = l(:notice_successful_update) unless issues.empty?
|
||||
else
|
||||
flash[:error] = l(:notice_failed_to_save_issues,
|
||||
:count => unsaved_issue_ids.size,
|
||||
:total => issues.size,
|
||||
:ids => '#' + unsaved_issue_ids.join(', #'))
|
||||
end
|
||||
end
|
||||
|
||||
# Rescues an invalid query statement. Just in case...
|
||||
def query_statement_invalid(exception)
|
||||
logger.error "Query::StatementInvalid: #{exception.message}" if logger
|
||||
session.delete(:query)
|
||||
sort_clear if respond_to?(:sort_clear)
|
||||
render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
|
||||
end
|
||||
|
||||
# Converts the errors on an ActiveRecord object into a common JSON format
|
||||
def object_errors_to_json(object)
|
||||
object.errors.collect do |attribute, error|
|
||||
{ attribute => error }
|
||||
end.to_json
|
||||
end
|
||||
|
||||
# Renders API response on validation failure
|
||||
def render_validation_errors(object)
|
||||
options = { :status => :unprocessable_entity, :layout => false }
|
||||
options.merge!(case params[:format]
|
||||
when 'xml'; { :xml => object.errors }
|
||||
when 'json'; { :json => {'errors' => object.errors} } # ActiveResource client compliance
|
||||
else
|
||||
raise "Unknown format #{params[:format]} in #render_validation_errors"
|
||||
end
|
||||
)
|
||||
render options
|
||||
end
|
||||
|
||||
# Overrides #default_template so that the api template
|
||||
# is used automatically if it exists
|
||||
def default_template(action_name = self.action_name)
|
||||
if api_request?
|
||||
begin
|
||||
return self.view_paths.find_template(default_template_name(action_name), 'api')
|
||||
rescue ::ActionView::MissingTemplate
|
||||
# the api template was not found
|
||||
# fallback to the default behaviour
|
||||
end
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
# Overrides #pick_layout so that #render with no arguments
|
||||
# doesn't use the layout for api requests
|
||||
def pick_layout(*args)
|
||||
api_request? ? nil : super
|
||||
end
|
||||
end
|
||||
@@ -1,51 +1,51 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# 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 :file_readable, :read_authorize, :except => :destroy
|
||||
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? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
|
||||
elsif @attachment.is_text?
|
||||
@content = File.new(@attachment.diskfile, "rb").read
|
||||
render :action => 'file'
|
||||
else
|
||||
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 => detect_content_type(@attachment),
|
||||
:type => @attachment.content_type,
|
||||
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
# Make sure association callbacks are called
|
||||
@attachment.container.attachments.delete(@attachment)
|
||||
@@ -53,7 +53,7 @@ class AttachmentsController < ApplicationController
|
||||
rescue ::ActionController::RedirectBackError
|
||||
redirect_to :controller => 'projects', :action => 'show', :id => @project
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def find_project
|
||||
@attachment = Attachment.find(params[:id])
|
||||
@@ -63,25 +63,12 @@ private
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Checks that the file exists and is readable
|
||||
def file_readable
|
||||
@attachment.readable? ? true : render_404
|
||||
end
|
||||
|
||||
|
||||
def read_authorize
|
||||
@attachment.visible? ? true : deny_access
|
||||
end
|
||||
|
||||
|
||||
def delete_authorize
|
||||
@attachment.deletable? ? true : deny_access
|
||||
end
|
||||
|
||||
def detect_content_type(attachment)
|
||||
content_type = attachment.content_type
|
||||
if content_type.blank?
|
||||
content_type = Redmine::MimeType.of(attachment.filename)
|
||||
end
|
||||
content_type.to_s
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,46 +16,47 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AuthSourcesController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
list
|
||||
render :action => 'list' unless request.xhr?
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :template => :index }
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def index
|
||||
@auth_source_pages, @auth_sources = paginate auth_source_class.name.tableize, :per_page => 10
|
||||
render "auth_sources/index"
|
||||
def list
|
||||
@auth_source_pages, @auth_sources = paginate :auth_sources, :per_page => 10
|
||||
render :action => "list", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def new
|
||||
@auth_source = auth_source_class.new
|
||||
render 'auth_sources/new'
|
||||
@auth_source = AuthSourceLdap.new
|
||||
end
|
||||
|
||||
def create
|
||||
@auth_source = auth_source_class.new(params[:auth_source])
|
||||
@auth_source = AuthSourceLdap.new(params[:auth_source])
|
||||
if @auth_source.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'index'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render 'auth_sources/new'
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@auth_source = AuthSource.find(params[:id])
|
||||
render 'auth_sources/edit'
|
||||
end
|
||||
|
||||
def update
|
||||
@auth_source = AuthSource.find(params[:id])
|
||||
if @auth_source.update_attributes(params[:auth_source])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'index'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render 'auth_sources/edit'
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,9 +66,9 @@ class AuthSourcesController < ApplicationController
|
||||
@auth_method.test_connection
|
||||
flash[:notice] = l(:notice_successful_connection)
|
||||
rescue => text
|
||||
flash[:error] = l(:error_unable_to_connect, text.message)
|
||||
flash[:error] = "Unable to connect (#{text})"
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -76,12 +77,6 @@ class AuthSourcesController < ApplicationController
|
||||
@auth_source.destroy
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def auth_source_class
|
||||
AuthSource
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
class AutoCompletesController < ApplicationController
|
||||
before_filter :find_project
|
||||
|
||||
def issues
|
||||
@issues = []
|
||||
q = params[:q].to_s
|
||||
query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues
|
||||
if q.match(/^\d+$/)
|
||||
@issues << query.visible.find_by_id(q.to_i)
|
||||
end
|
||||
unless q.blank?
|
||||
@issues += query.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
|
||||
end
|
||||
@issues.compact!
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
|
||||
@project = Project.find(project_id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,9 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class BoardsController < ApplicationController
|
||||
default_search_scope :messages
|
||||
before_filter :find_project, :find_board_if_available, :authorize
|
||||
accept_rss_auth :index, :show
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
helper :messages
|
||||
include MessagesHelper
|
||||
@@ -37,29 +35,18 @@ class BoardsController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
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
|
||||
@message = Message.new
|
||||
render :action => 'show', :layout => !request.xhr?
|
||||
}
|
||||
format.atom {
|
||||
@messages = @board.messages.find :all, :order => 'created_on DESC',
|
||||
:include => [:author, :board],
|
||||
:limit => Setting.feeds_limit.to_i
|
||||
render_feed(@messages, :title => "#{@project}: #{@board}")
|
||||
}
|
||||
end
|
||||
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 }
|
||||
@@ -69,33 +56,30 @@ class BoardsController < ApplicationController
|
||||
@board.project = @project
|
||||
if request.post? && @board.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to_settings_in_projects
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
if request.post? && @board.update_attributes(params[:board])
|
||||
redirect_to_settings_in_projects
|
||||
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_settings_in_projects
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
||||
end
|
||||
|
||||
private
|
||||
def redirect_to_settings_in_projects
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
|
||||
end
|
||||
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_board_if_available
|
||||
@board = @project.boards.find(params[:id]) if params[:id]
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 CalendarsController < ApplicationController
|
||||
menu_item :calendar
|
||||
before_filter :find_optional_project
|
||||
|
||||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||
|
||||
helper :issues
|
||||
helper :projects
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
def show
|
||||
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
|
||||
@query.group_by = nil
|
||||
if @query.valid?
|
||||
events = []
|
||||
events += @query.issues(:include => [:tracker, :assigned_to, :priority],
|
||||
:conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
|
||||
)
|
||||
events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
|
||||
|
||||
@calendar.events = events
|
||||
end
|
||||
|
||||
render :action => 'show', :layout => false if request.xhr?
|
||||
end
|
||||
end
|
||||
@@ -1,36 +0,0 @@
|
||||
class CommentsController < ApplicationController
|
||||
default_search_scope :news
|
||||
model_object News
|
||||
before_filter :find_model_object
|
||||
before_filter :find_project_from_association
|
||||
before_filter :authorize
|
||||
|
||||
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def create
|
||||
@comment = Comment.new(params[:comment])
|
||||
@comment.author = User.current
|
||||
if @news.comments << @comment
|
||||
flash[:notice] = l(:label_comment_added)
|
||||
end
|
||||
|
||||
redirect_to :controller => 'news', :action => 'show', :id => @news
|
||||
end
|
||||
|
||||
verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def destroy
|
||||
@news.comments.find(params[:comment_id]).destroy
|
||||
redirect_to :controller => 'news', :action => 'show', :id => @news
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# ApplicationController's find_model_object sets it based on the controller
|
||||
# name so it needs to be overriden and set to @news instead
|
||||
def find_model_object
|
||||
super
|
||||
@news = @object
|
||||
@comment = nil
|
||||
@news
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,57 +0,0 @@
|
||||
class ContextMenusController < ApplicationController
|
||||
helper :watchers
|
||||
helper :issues
|
||||
|
||||
def issues
|
||||
@issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
|
||||
|
||||
if (@issues.size == 1)
|
||||
@issue = @issues.first
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
else
|
||||
@allowed_statuses = @issues.map do |i|
|
||||
i.new_statuses_allowed_to(User.current)
|
||||
end.inject do |memo,s|
|
||||
memo & s
|
||||
end
|
||||
end
|
||||
@projects = @issues.collect(&:project).compact.uniq
|
||||
@project = @projects.first if @projects.size == 1
|
||||
|
||||
@can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
|
||||
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
|
||||
:update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
|
||||
:move => (@project && User.current.allowed_to?(:move_issues, @project)),
|
||||
:copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
|
||||
:delete => User.current.allowed_to?(:delete_issues, @projects)
|
||||
}
|
||||
if @project
|
||||
@assignables = @project.assignable_users
|
||||
@assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
|
||||
@trackers = @project.trackers
|
||||
else
|
||||
#when multiple projects, we only keep the intersection of each set
|
||||
@assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
|
||||
@trackers = @projects.map(&:trackers).inject{|memo,t| memo & t}
|
||||
end
|
||||
|
||||
@priorities = IssuePriority.all.reverse
|
||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||
@back = back_url
|
||||
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def time_entries
|
||||
@time_entries = TimeEntry.all(
|
||||
:conditions => {:id => params[:ids]}, :include => :project)
|
||||
@projects = @time_entries.collect(&:project).compact.uniq
|
||||
@project = @projects.first if @projects.size == 1
|
||||
@activities = TimeEntryActivity.shared.active
|
||||
@can = {:edit => User.current.allowed_to?(:edit_time_entries, @projects),
|
||||
:delete => User.current.allowed_to?(:edit_time_entries, @projects)
|
||||
}
|
||||
@back = back_url
|
||||
render :layout => false
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,49 +16,75 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class CustomFieldsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
list
|
||||
render :action => 'list' unless request.xhr?
|
||||
end
|
||||
|
||||
def list
|
||||
@custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
|
||||
@tab = params[:tab] || 'IssueCustomField'
|
||||
render :action => "list", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def new
|
||||
@custom_field = begin
|
||||
if params[:type].to_s.match(/.+CustomField$/)
|
||||
params[:type].to_s.constantize.new(params[:custom_field])
|
||||
end
|
||||
rescue
|
||||
end
|
||||
(redirect_to(:action => 'index'); return) unless @custom_field.is_a?(CustomField)
|
||||
|
||||
case params[:type]
|
||||
when "IssueCustomField"
|
||||
@custom_field = IssueCustomField.new(params[:custom_field])
|
||||
@custom_field.trackers = Tracker.find(params[:tracker_ids]) if params[:tracker_ids]
|
||||
when "UserCustomField"
|
||||
@custom_field = UserCustomField.new(params[:custom_field])
|
||||
when "ProjectCustomField"
|
||||
@custom_field = ProjectCustomField.new(params[:custom_field])
|
||||
when "TimeEntryCustomField"
|
||||
@custom_field = TimeEntryCustomField.new(params[:custom_field])
|
||||
else
|
||||
redirect_to :action => 'list'
|
||||
return
|
||||
end
|
||||
if request.post? and @custom_field.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
|
||||
redirect_to :action => 'index', :tab => @custom_field.class.name
|
||||
else
|
||||
@trackers = Tracker.find(:all, :order => 'position')
|
||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||
end
|
||||
@trackers = Tracker.find(:all, :order => 'position')
|
||||
end
|
||||
|
||||
def edit
|
||||
@custom_field = CustomField.find(params[:id])
|
||||
if request.post? and @custom_field.update_attributes(params[:custom_field])
|
||||
if @custom_field.is_a? IssueCustomField
|
||||
@custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
|
||||
redirect_to :action => 'index', :tab => @custom_field.class.name
|
||||
else
|
||||
@trackers = Tracker.find(:all, :order => 'position')
|
||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||
end
|
||||
@trackers = Tracker.find(:all, :order => 'position')
|
||||
end
|
||||
|
||||
def move
|
||||
@custom_field = CustomField.find(params[:id])
|
||||
case params[:position]
|
||||
when 'highest'
|
||||
@custom_field.move_to_top
|
||||
when 'higher'
|
||||
@custom_field.move_higher
|
||||
when 'lower'
|
||||
@custom_field.move_lower
|
||||
when 'lowest'
|
||||
@custom_field.move_to_bottom
|
||||
end if params[:position]
|
||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||
end
|
||||
|
||||
def destroy
|
||||
@custom_field = CustomField.find(params[:id]).destroy
|
||||
redirect_to :action => 'index', :tab => @custom_field.class.name
|
||||
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||
rescue
|
||||
flash[:error] = l(:error_can_not_delete_custom_field)
|
||||
redirect_to :action => 'index'
|
||||
flash[:error] = "Unable to delete custom field"
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class DocumentsController < ApplicationController
|
||||
default_search_scope :documents
|
||||
model_object Document
|
||||
before_filter :find_project, :only => [:index, :new]
|
||||
before_filter :find_model_object, :except => [:index, :new]
|
||||
before_filter :find_project_from_association, :except => [:index, :new]
|
||||
before_filter :find_document, :except => [:index, :new]
|
||||
before_filter :authorize
|
||||
|
||||
helper :attachments
|
||||
@@ -30,7 +27,7 @@ class DocumentsController < ApplicationController
|
||||
documents = @project.documents.find :all, :include => [:attachments, :category]
|
||||
case @sort_by
|
||||
when 'date'
|
||||
@grouped = documents.group_by {|d| d.updated_on.to_date }
|
||||
@grouped = documents.group_by {|d| d.created_on.to_date }
|
||||
when 'title'
|
||||
@grouped = documents.group_by {|d| d.title.first.upcase}
|
||||
when 'author'
|
||||
@@ -49,15 +46,15 @@ class DocumentsController < ApplicationController
|
||||
def new
|
||||
@document = @project.documents.build(params[:document])
|
||||
if request.post? and @document.save
|
||||
attachments = Attachment.attach_files(@document, params[:attachments])
|
||||
render_attachment_warning_if_needed(@document)
|
||||
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 = DocumentCategory.all
|
||||
@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
|
||||
@@ -70,10 +67,8 @@ class DocumentsController < ApplicationController
|
||||
end
|
||||
|
||||
def add_attachment
|
||||
attachments = Attachment.attach_files(@document, params[:attachments])
|
||||
render_attachment_warning_if_needed(@document)
|
||||
|
||||
Mailer.deliver_attachments_added(attachments[:files]) if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
|
||||
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
|
||||
|
||||
@@ -83,4 +78,11 @@ private
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_document
|
||||
@document = Document.find(params[:id])
|
||||
@project = @document.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,12 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class EnumerationsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
def index
|
||||
list
|
||||
@@ -36,19 +31,14 @@ class EnumerationsController < ApplicationController
|
||||
end
|
||||
|
||||
def new
|
||||
begin
|
||||
@enumeration = params[:type].constantize.new
|
||||
rescue NameError
|
||||
@enumeration = Enumeration.new
|
||||
end
|
||||
@enumeration = Enumeration.new(:opt => params[:opt])
|
||||
end
|
||||
|
||||
def create
|
||||
@enumeration = Enumeration.new(params[:enumeration])
|
||||
@enumeration.type = params[:enumeration][:type]
|
||||
if @enumeration.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'list', :type => @enumeration.type
|
||||
redirect_to :action => 'list', :opt => @enumeration.opt
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
@@ -60,14 +50,28 @@ class EnumerationsController < ApplicationController
|
||||
|
||||
def update
|
||||
@enumeration = Enumeration.find(params[:id])
|
||||
@enumeration.type = params[:enumeration][:type] if params[:enumeration][:type]
|
||||
if @enumeration.update_attributes(params[:enumeration])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'list', :type => @enumeration.type
|
||||
redirect_to :action => 'list', :opt => @enumeration.opt
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def move
|
||||
@enumeration = Enumeration.find(params[:id])
|
||||
case params[:position]
|
||||
when 'highest'
|
||||
@enumeration.move_to_top
|
||||
when 'higher'
|
||||
@enumeration.move_higher
|
||||
when 'lower'
|
||||
@enumeration.move_lower
|
||||
when 'lowest'
|
||||
@enumeration.move_to_bottom
|
||||
end if params[:position]
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def destroy
|
||||
@enumeration = Enumeration.find(params[:id])
|
||||
@@ -75,15 +79,13 @@ class EnumerationsController < ApplicationController
|
||||
# No associated objects
|
||||
@enumeration.destroy
|
||||
redirect_to :action => 'index'
|
||||
return
|
||||
elsif params[:reassign_to_id]
|
||||
if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id])
|
||||
if reassign_to = Enumeration.find_by_opt_and_id(@enumeration.opt, params[:reassign_to_id])
|
||||
@enumeration.destroy(reassign_to)
|
||||
redirect_to :action => 'index'
|
||||
return
|
||||
end
|
||||
end
|
||||
@enumerations = @enumeration.class.find(:all) - [@enumeration]
|
||||
@enumerations = Enumeration.get_values(@enumeration.opt) - [@enumeration]
|
||||
#rescue
|
||||
# flash[:error] = 'Unable to delete enumeration'
|
||||
# redirect_to :action => 'index'
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
class FilesController < ApplicationController
|
||||
menu_item :files
|
||||
|
||||
before_filter :find_project_by_project_id
|
||||
before_filter :authorize
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
def index
|
||||
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
|
||||
|
||||
def new
|
||||
@versions = @project.versions.sort
|
||||
end
|
||||
|
||||
def create
|
||||
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
||||
attachments = Attachment.attach_files(container, params[:attachments])
|
||||
render_attachment_warning_if_needed(container)
|
||||
|
||||
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
||||
Mailer.deliver_attachments_added(attachments[:files])
|
||||
end
|
||||
redirect_to project_files_path(@project)
|
||||
end
|
||||
end
|
||||
@@ -1,48 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 GanttsController < ApplicationController
|
||||
menu_item :gantt
|
||||
before_filter :find_optional_project
|
||||
|
||||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||
|
||||
helper :gantt
|
||||
helper :issues
|
||||
helper :projects
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :sort
|
||||
include SortHelper
|
||||
include Redmine::Export::PDF
|
||||
|
||||
def show
|
||||
@gantt = Redmine::Helpers::Gantt.new(params)
|
||||
@gantt.project = @project
|
||||
retrieve_query
|
||||
@query.group_by = nil
|
||||
@gantt.query = @query if @query.valid?
|
||||
|
||||
basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :action => "show", :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, :type => 'application/pdf', :filename => "#{basename}.pdf") }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,170 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 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 GroupsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
helper :custom_fields
|
||||
|
||||
# GET /groups
|
||||
# GET /groups.xml
|
||||
def index
|
||||
@groups = Group.find(:all, :order => 'lastname')
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @groups }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /groups/1
|
||||
# GET /groups/1.xml
|
||||
def show
|
||||
@group = Group.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.xml { render :xml => @group }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /groups/new
|
||||
# GET /groups/new.xml
|
||||
def new
|
||||
@group = Group.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @group }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /groups/1/edit
|
||||
def edit
|
||||
@group = Group.find(params[:id], :include => :projects)
|
||||
end
|
||||
|
||||
# POST /groups
|
||||
# POST /groups.xml
|
||||
def create
|
||||
@group = Group.new(params[:group])
|
||||
|
||||
respond_to do |format|
|
||||
if @group.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
format.html { redirect_to(groups_path) }
|
||||
format.xml { render :xml => @group, :status => :created, :location => @group }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /groups/1
|
||||
# PUT /groups/1.xml
|
||||
def update
|
||||
@group = Group.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @group.update_attributes(params[:group])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
format.html { redirect_to(groups_path) }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /groups/1
|
||||
# DELETE /groups/1.xml
|
||||
def destroy
|
||||
@group = Group.find(params[:id])
|
||||
@group.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(groups_url) }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
|
||||
def add_users
|
||||
@group = Group.find(params[:id])
|
||||
users = User.find_all_by_id(params[:user_ids])
|
||||
@group.users << users if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
|
||||
format.js {
|
||||
render(:update) {|page|
|
||||
page.replace_html "tab-content-users", :partial => 'groups/users'
|
||||
users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def remove_user
|
||||
@group = Group.find(params[:id])
|
||||
@group.users.delete(User.find(params[:user_id])) if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
|
||||
format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
|
||||
end
|
||||
end
|
||||
|
||||
def autocomplete_for_user
|
||||
@group = Group.find(params[:id])
|
||||
@users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def edit_membership
|
||||
@group = Group.find(params[:id])
|
||||
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
|
||||
@membership.save if request.post?
|
||||
respond_to do |format|
|
||||
if @membership.valid?
|
||||
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
||||
format.js {
|
||||
render(:update) {|page|
|
||||
page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
|
||||
page.visual_effect(:highlight, "member-#{@membership.id}")
|
||||
}
|
||||
}
|
||||
else
|
||||
format.js {
|
||||
render(:update) {|page|
|
||||
page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_membership
|
||||
@group = Group.find(params[:id])
|
||||
Member.find(params[:membership_id]).destroy if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
||||
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -17,41 +17,10 @@
|
||||
|
||||
class IssueCategoriesController < ApplicationController
|
||||
menu_item :settings
|
||||
model_object IssueCategory
|
||||
before_filter :find_model_object, :except => :new
|
||||
before_filter :find_project_from_association, :except => :new
|
||||
before_filter :find_project, :only => :new
|
||||
before_filter :authorize
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
verify :method => :post, :only => :destroy
|
||||
|
||||
def new
|
||||
@category = @project.issue_categories.build(params[:category])
|
||||
if request.post?
|
||||
if @category.save
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :controller => 'projects', :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
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js do
|
||||
render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
if request.post? and @category.update_attributes(params[:category])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
@@ -65,27 +34,19 @@ class IssueCategoriesController < ApplicationController
|
||||
# No issue assigned to this category
|
||||
@category.destroy
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
|
||||
return
|
||||
elsif params[:todo]
|
||||
reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign'
|
||||
@category.destroy(reassign_to)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
|
||||
return
|
||||
end
|
||||
@categories = @project.issue_categories - [@category]
|
||||
end
|
||||
|
||||
private
|
||||
# Wrap ApplicationController's find_model_object method to set
|
||||
# @category instead of just @issue_category
|
||||
def find_model_object
|
||||
super
|
||||
@category = @object
|
||||
end
|
||||
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id])
|
||||
@category = IssueCategory.find(params[:id])
|
||||
@project = @category.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
class IssueMovesController < ApplicationController
|
||||
default_search_scope :issues
|
||||
before_filter :find_issues, :check_project_uniqueness
|
||||
before_filter :authorize
|
||||
|
||||
def new
|
||||
prepare_for_issue_move
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def create
|
||||
prepare_for_issue_move
|
||||
|
||||
if request.post?
|
||||
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
|
||||
unsaved_issue_ids = []
|
||||
moved_issues = []
|
||||
@issues.each do |issue|
|
||||
issue.reload
|
||||
issue.init_journal(User.current)
|
||||
issue.current_journal.notes = @notes if @notes.present?
|
||||
call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
|
||||
if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
|
||||
moved_issues << r
|
||||
else
|
||||
unsaved_issue_ids << issue.id
|
||||
end
|
||||
end
|
||||
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
|
||||
|
||||
if params[:follow]
|
||||
if @issues.size == 1 && moved_issues.size == 1
|
||||
redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
|
||||
else
|
||||
redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
|
||||
end
|
||||
else
|
||||
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prepare_for_issue_move
|
||||
@issues.sort!
|
||||
@copy = params[:copy_options] && params[:copy_options][:copy]
|
||||
@allowed_projects = Issue.allowed_target_projects_on_move
|
||||
@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
|
||||
@available_statuses = Workflow.available_statuses(@project)
|
||||
@notes = params[:notes]
|
||||
@notes ||= ''
|
||||
end
|
||||
|
||||
def extract_changed_attributes_for_move(params)
|
||||
changed_attributes = {}
|
||||
[:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
|
||||
unless params[valid_attribute].blank?
|
||||
changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
|
||||
end
|
||||
end
|
||||
changed_attributes
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
# Redmine - project management software
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
@@ -16,19 +16,15 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class IssueRelationsController < ApplicationController
|
||||
before_filter :find_issue, :find_project_from_association, :authorize
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
def new
|
||||
@relation = IssueRelation.new(params[:relation])
|
||||
@relation.issue_from = @issue
|
||||
if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/)
|
||||
@relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
|
||||
end
|
||||
@relation.save if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
||||
format.js do
|
||||
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
||||
render :update do |page|
|
||||
page.replace_html "relations", :partial => 'issues/relations'
|
||||
if @relation.errors.empty?
|
||||
@@ -48,16 +44,14 @@ class IssueRelationsController < ApplicationController
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
||||
format.js {
|
||||
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
||||
render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'}
|
||||
}
|
||||
format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_issue
|
||||
@issue = @object = Issue.find(params[:issue_id])
|
||||
def find_project
|
||||
@issue = Issue.find(params[:issue_id])
|
||||
@project = @issue.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
@@ -16,16 +16,19 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class IssueStatusesController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
verify :method => :post, :only => [ :destroy, :create, :update, :move, :update_issue_done_ratio ],
|
||||
:redirect_to => { :action => :index }
|
||||
verify :method => :post, :only => [ :destroy, :create, :update, :move ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def index
|
||||
list
|
||||
render :action => 'list' unless request.xhr?
|
||||
end
|
||||
|
||||
def list
|
||||
@issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
|
||||
render :action => "index", :layout => false if request.xhr?
|
||||
render :action => "list", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -36,7 +39,7 @@ class IssueStatusesController < ApplicationController
|
||||
@issue_status = IssueStatus.new(params[:issue_status])
|
||||
if @issue_status.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'index'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
@@ -50,26 +53,32 @@ class IssueStatusesController < ApplicationController
|
||||
@issue_status = IssueStatus.find(params[:id])
|
||||
if @issue_status.update_attributes(params[:issue_status])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'index'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def move
|
||||
@issue_status = IssueStatus.find(params[:id])
|
||||
case params[:position]
|
||||
when 'highest'
|
||||
@issue_status.move_to_top
|
||||
when 'higher'
|
||||
@issue_status.move_higher
|
||||
when 'lower'
|
||||
@issue_status.move_lower
|
||||
when 'lowest'
|
||||
@issue_status.move_to_bottom
|
||||
end if params[:position]
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def destroy
|
||||
IssueStatus.find(params[:id]).destroy
|
||||
redirect_to :action => 'index'
|
||||
redirect_to :action => 'list'
|
||||
rescue
|
||||
flash[:error] = l(:error_unable_delete_issue_status)
|
||||
redirect_to :action => 'index'
|
||||
flash[:error] = "Unable to delete issue status"
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def update_issue_done_ratio
|
||||
if IssueStatus.update_issue_done_ratios
|
||||
flash[:notice] = l(:notice_issue_done_ratios_updated)
|
||||
else
|
||||
flash[:error] = l(:error_issue_done_ratios_not_updated)
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,40 +1,33 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# 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, :create]
|
||||
default_search_scope :issues
|
||||
|
||||
before_filter :find_issue, :only => [:show, :edit, :update]
|
||||
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy]
|
||||
before_filter :check_project_uniqueness, :only => [:move, :perform_move]
|
||||
before_filter :find_project, :only => [:new, :create]
|
||||
before_filter :authorize, :except => [:index]
|
||||
before_filter :find_optional_project, :only => [:index]
|
||||
before_filter :check_for_default_issue_status, :only => [:new, :create]
|
||||
before_filter :build_new_issue_from_params, :only => [:new, :create]
|
||||
accept_rss_auth :index, :show
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
||||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||
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
|
||||
include ProjectsHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
helper :issue_relations
|
||||
@@ -44,56 +37,37 @@ class IssuesController < ApplicationController
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :repositories
|
||||
include RepositoriesHelper
|
||||
helper :sort
|
||||
include SortHelper
|
||||
include IssuesHelper
|
||||
helper :timelog
|
||||
helper :gantt
|
||||
include Redmine::Export::PDF
|
||||
|
||||
verify :method => [:post, :delete],
|
||||
:only => :destroy,
|
||||
:render => { :nothing => true, :status => :method_not_allowed }
|
||||
|
||||
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
|
||||
def index
|
||||
retrieve_query
|
||||
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
|
||||
sort_update(@query.sortable_columns)
|
||||
|
||||
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?
|
||||
case params[:format]
|
||||
when 'csv', 'pdf'
|
||||
@limit = Setting.issues_export_limit.to_i
|
||||
when 'atom'
|
||||
@limit = Setting.feeds_limit.to_i
|
||||
when 'xml', 'json'
|
||||
@offset, @limit = api_offset_and_limit
|
||||
else
|
||||
@limit = per_page_option
|
||||
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 = @query.issue_count
|
||||
@issue_pages = Paginator.new self, @issue_count, @limit, params['page']
|
||||
@offset ||= @issue_pages.current.offset
|
||||
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
||||
:order => sort_clause,
|
||||
:offset => @offset,
|
||||
:limit => @limit)
|
||||
@issue_count_by_group = @query.issue_count_by_group
|
||||
|
||||
@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.api
|
||||
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
||||
format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
|
||||
format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
|
||||
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
|
||||
@@ -102,26 +76,35 @@ class IssuesController < ApplicationController
|
||||
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?
|
||||
|
||||
if User.current.allowed_to?(:view_changesets, @project)
|
||||
@changesets = @issue.changesets.visible.all
|
||||
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
end
|
||||
|
||||
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||
@priorities = IssuePriority.all
|
||||
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
|
||||
@priorities = Enumeration::get_values('IPRI')
|
||||
@time_entry = TimeEntry.new
|
||||
respond_to do |format|
|
||||
format.html { render :template => 'issues/show.rhtml' }
|
||||
format.api
|
||||
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
|
||||
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
|
||||
@@ -129,97 +112,188 @@ class IssuesController < ApplicationController
|
||||
# Add a new issue
|
||||
# The new issue will be created from an existing one if copy_from parameter is given
|
||||
def new
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new', :layout => !request.xhr? }
|
||||
format.js { render :partial => 'attributes' }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
|
||||
if @issue.save
|
||||
attachments = Attachment.attach_files(@issue, params[:attachments])
|
||||
render_attachment_warning_if_needed(@issue)
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
redirect_to(params[:continue] ? { :action => 'new', :project_id => @project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
|
||||
{ :action => 'show', :id => @issue })
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
|
||||
end
|
||||
@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
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new' }
|
||||
format.api { render_validation_errors(@issue) }
|
||||
end
|
||||
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
|
||||
update_issue_from_params
|
||||
|
||||
@journal = @issue.current_journal
|
||||
|
||||
respond_to do |format|
|
||||
format.html { }
|
||||
format.xml { }
|
||||
@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 update
|
||||
update_issue_from_params
|
||||
|
||||
if @issue.save_issue_with_child_records(params, @time_entry)
|
||||
render_attachment_warning_if_needed(@issue)
|
||||
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
|
||||
format.api { head :ok }
|
||||
end
|
||||
def reply
|
||||
journal = Journal.find(params[:journal_id]) if params[:journal_id]
|
||||
if journal
|
||||
user = journal.user
|
||||
text = journal.notes
|
||||
else
|
||||
render_attachment_warning_if_needed(@issue)
|
||||
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
|
||||
@journal = @issue.current_journal
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@issue) }
|
||||
end
|
||||
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
|
||||
@issues.sort!
|
||||
@available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
|
||||
@custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
|
||||
@assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
|
||||
@trackers = @projects.map(&:trackers).inject{|memo,t| memo & t}
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
@issues.sort!
|
||||
attributes = parse_params_for_bulk_issue_attributes(params)
|
||||
|
||||
unsaved_issue_ids = []
|
||||
@issues.each do |issue|
|
||||
issue.reload
|
||||
journal = issue.init_journal(User.current, params[:notes])
|
||||
issue.safe_attributes = attributes
|
||||
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
|
||||
unless issue.save
|
||||
# Keep unsaved issue ids to display them in flash error
|
||||
unsaved_issue_ids << issue.id
|
||||
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
|
||||
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
|
||||
redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
|
||||
# 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
|
||||
@@ -237,100 +311,179 @@ class IssuesController < ApplicationController
|
||||
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
|
||||
end
|
||||
else
|
||||
# display the destroy form if it's a user request
|
||||
return unless api_request?
|
||||
# display the destroy form
|
||||
return
|
||||
end
|
||||
end
|
||||
@issues.each do |issue|
|
||||
begin
|
||||
issue.reload.destroy
|
||||
rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
|
||||
# nothing to do, issue was already deleted (eg. by a parent)
|
||||
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 { redirect_back_or_default(:action => 'index', :project_id => @project) }
|
||||
format.api { head :ok }
|
||||
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.visible.find(...) can not be used to redirect user to the login form
|
||||
# if the issue actually exists but requires authentication
|
||||
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
|
||||
unless @issue.visible?
|
||||
deny_access
|
||||
return
|
||||
end
|
||||
@project = @issue.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_project
|
||||
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
|
||||
@project = Project.find(project_id)
|
||||
|
||||
# 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
|
||||
|
||||
# Used by #edit and #update to set some common instance variables
|
||||
# from the params
|
||||
# TODO: Refactor, not everything in here is needed by #edit
|
||||
def update_issue_from_params
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
@priorities = IssuePriority.all
|
||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
|
||||
@notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
|
||||
@issue.init_journal(User.current, @notes)
|
||||
@issue.safe_attributes = params[:issue]
|
||||
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# TODO: Refactor, lots of extra code in here
|
||||
# TODO: Changing tracker on an existing issue should not trigger this
|
||||
def build_new_issue_from_params
|
||||
if params[:id].blank?
|
||||
@issue = Issue.new
|
||||
@issue.copy_from(params[:copy_from]) if params[:copy_from]
|
||||
@issue.project = @project
|
||||
|
||||
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
|
||||
@issue = @project.issues.visible.find(params[:id])
|
||||
end
|
||||
|
||||
@issue.project = @project
|
||||
@issue.author = User.current
|
||||
# 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?
|
||||
render_error l(:error_no_tracker_in_project)
|
||||
return false
|
||||
end
|
||||
@issue.start_date ||= Date.today
|
||||
if params[:issue].is_a?(Hash)
|
||||
@issue.safe_attributes = params[:issue]
|
||||
if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record?
|
||||
@issue.watcher_user_ids = params[:issue]['watcher_user_ids']
|
||||
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
|
||||
@priorities = IssuePriority.all
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
|
||||
end
|
||||
|
||||
def check_for_default_issue_status
|
||||
if IssueStatus.default.nil?
|
||||
render_error l(:error_no_default_issue_status)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def parse_params_for_bulk_issue_attributes(params)
|
||||
attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
|
||||
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
|
||||
attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
|
||||
attributes
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# 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
|
||||
@@ -16,71 +16,9 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class JournalsController < ApplicationController
|
||||
before_filter :find_journal, :only => [:edit, :diff]
|
||||
before_filter :find_issue, :only => [:new]
|
||||
before_filter :find_optional_project, :only => [:index]
|
||||
before_filter :authorize, :only => [:new, :edit, :diff]
|
||||
accept_rss_auth :index
|
||||
menu_item :issues
|
||||
|
||||
helper :issues
|
||||
helper :custom_fields
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
def index
|
||||
retrieve_query
|
||||
sort_init 'id', 'desc'
|
||||
sort_update(@query.sortable_columns)
|
||||
|
||||
if @query.valid?
|
||||
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
|
||||
:limit => 25)
|
||||
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 diff
|
||||
@issue = @journal.issue
|
||||
if params[:detail_id].present?
|
||||
@detail = @journal.details.find_by_id(params[:detail_id])
|
||||
else
|
||||
@detail = @journal.details.detect {|d| d.prop_key == 'description'}
|
||||
end
|
||||
(render_404; return false) unless @issue && @detail
|
||||
@diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
|
||||
end
|
||||
|
||||
def new
|
||||
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
|
||||
# Replaces pre blocks with [...]
|
||||
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
||||
content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
||||
content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||||
|
||||
render(:update) { |page|
|
||||
page.<< "$('notes').value = \"#{escape_javascript content}\";"
|
||||
page.show 'update'
|
||||
page << "Form.Element.focus('notes');"
|
||||
page << "Element.scrollTo('update');"
|
||||
page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
|
||||
}
|
||||
end
|
||||
before_filter :find_journal
|
||||
|
||||
def edit
|
||||
(render_403; return false) unless @journal.editable_by?(User.current)
|
||||
if request.post?
|
||||
@journal.update_attributes(:notes => params[:notes]) if params[:notes]
|
||||
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
|
||||
@@ -89,31 +27,15 @@ class JournalsController < ApplicationController
|
||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
|
||||
format.js { render :action => 'update' }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# TODO: implement non-JS journal update
|
||||
render :nothing => true
|
||||
}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
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
|
||||
|
||||
# TODO: duplicated in IssuesController
|
||||
def find_issue
|
||||
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
|
||||
@project = @issue.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,25 +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 LdapAuthSourcesController < AuthSourcesController
|
||||
|
||||
protected
|
||||
|
||||
def auth_source_class
|
||||
AuthSourceLdap
|
||||
end
|
||||
end
|
||||
@@ -1,27 +1,27 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# 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
|
||||
@@ -32,13 +32,13 @@ class MailHandlerController < ActionController::Base
|
||||
render :nothing => true, :status => :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def check_credential
|
||||
User.current = nil
|
||||
unless Setting.mail_handler_api_enabled? && params[:key].to_s == Setting.mail_handler_api_key
|
||||
render :text => 'Access denied. Incoming emails WS is disabled or key is invalid.', :status => 403
|
||||
unless Setting.mail_handler_api_enabled? && params[:key] == Setting.mail_handler_api_key
|
||||
render :nothing => true, :status => 403
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,50 +16,15 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MembersController < ApplicationController
|
||||
model_object Member
|
||||
before_filter :find_model_object, :except => [:new, :autocomplete_for_member]
|
||||
before_filter :find_project_from_association, :except => [:new, :autocomplete_for_member]
|
||||
before_filter :find_project, :only => [:new, :autocomplete_for_member]
|
||||
before_filter :find_member, :except => :new
|
||||
before_filter :find_project, :only => :new
|
||||
before_filter :authorize
|
||||
|
||||
def new
|
||||
members = []
|
||||
if params[:member] && request.post?
|
||||
attrs = params[:member].dup
|
||||
if (user_ids = attrs.delete(:user_ids))
|
||||
user_ids.each do |user_id|
|
||||
members << Member.new(attrs.merge(:user_id => user_id))
|
||||
end
|
||||
else
|
||||
members << Member.new(attrs)
|
||||
end
|
||||
@project.members << members
|
||||
end
|
||||
@project.members << Member.new(params[:member]) if request.post?
|
||||
respond_to do |format|
|
||||
if members.present? && members.all? {|m| m.valid? }
|
||||
|
||||
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'
|
||||
page << 'hideOnLoad()'
|
||||
members.each {|member| page.visual_effect(:highlight, "member-#{member.id}") }
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
format.js {
|
||||
render(:update) {|page|
|
||||
errors = members.collect {|m|
|
||||
m.errors.full_messages
|
||||
}.flatten.uniq
|
||||
|
||||
page.alert(l(:notice_failed_to_save_members, :errors => errors.join(', ')))
|
||||
}
|
||||
}
|
||||
|
||||
end
|
||||
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
|
||||
|
||||
@@ -67,34 +32,30 @@ class MembersController < ApplicationController
|
||||
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'
|
||||
page << 'hideOnLoad()'
|
||||
page.visual_effect(:highlight, "member-#{@member.id}")
|
||||
}
|
||||
}
|
||||
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if request.post? && @member.deletable?
|
||||
@member.destroy
|
||||
end
|
||||
respond_to do |format|
|
||||
@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'
|
||||
page << 'hideOnLoad()'
|
||||
}
|
||||
}
|
||||
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
|
||||
end
|
||||
end
|
||||
|
||||
def autocomplete_for_member
|
||||
@principals = Principal.active.like(params[:q]).find(:all, :limit => 100) - @project.principals
|
||||
render :layout => false
|
||||
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
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
class MessagesController < ApplicationController
|
||||
menu_item :boards
|
||||
default_search_scope :messages
|
||||
before_filter :find_board, :only => [:new, :preview]
|
||||
before_filter :find_message, :except => [:new, :preview]
|
||||
before_filter :authorize, :except => [:preview, :edit, :destroy]
|
||||
@@ -29,24 +28,10 @@ class MessagesController < ApplicationController
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
|
||||
REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
|
||||
|
||||
# Show a topic and its replies
|
||||
def show
|
||||
page = params[:page]
|
||||
# Find the page of the requested reply
|
||||
if params[:r] && page.nil?
|
||||
offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
|
||||
page = 1 + offset / REPLIES_PER_PAGE
|
||||
end
|
||||
|
||||
@reply_count = @topic.children.count
|
||||
@reply_pages = Paginator.new self, @reply_count, REPLIES_PER_PAGE, page
|
||||
@replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}],
|
||||
:order => "#{Message.table_name}.created_on ASC",
|
||||
:limit => @reply_pages.items_per_page,
|
||||
:offset => @reply_pages.current.offset)
|
||||
|
||||
@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
|
||||
@@ -61,9 +46,7 @@ class MessagesController < ApplicationController
|
||||
@message.sticky = params[:message]['sticky']
|
||||
end
|
||||
if request.post? && @message.save
|
||||
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
|
||||
attachments = Attachment.attach_files(@message, params[:attachments])
|
||||
render_attachment_warning_if_needed(@message)
|
||||
attach_files(@message, params[:attachments])
|
||||
redirect_to :action => 'show', :id => @message
|
||||
end
|
||||
end
|
||||
@@ -75,47 +58,40 @@ class MessagesController < ApplicationController
|
||||
@reply.board = @board
|
||||
@topic.children << @reply
|
||||
if !@reply.new_record?
|
||||
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
|
||||
attachments = Attachment.attach_files(@reply, params[:attachments])
|
||||
render_attachment_warning_if_needed(@reply)
|
||||
attach_files(@reply, params[:attachments])
|
||||
end
|
||||
redirect_to :action => 'show', :id => @topic, :r => @reply
|
||||
redirect_to :action => 'show', :id => @topic
|
||||
end
|
||||
|
||||
# Edit a message
|
||||
def edit
|
||||
(render_403; return false) unless @message.editable_by?(User.current)
|
||||
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])
|
||||
attachments = Attachment.attach_files(@message, params[:attachments])
|
||||
render_attachment_warning_if_needed(@message)
|
||||
attach_files(@message, params[:attachments])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
@message.reload
|
||||
redirect_to :action => 'show', :board_id => @message.board, :id => @message.root, :r => (@message.parent_id && @message.id)
|
||||
redirect_to :action => 'show', :id => @topic
|
||||
end
|
||||
end
|
||||
|
||||
# Delete a messages
|
||||
def destroy
|
||||
(render_403; return false) unless @message.destroyable_by?(User.current)
|
||||
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, :r => @message }
|
||||
{ :action => 'show', :id => @message.parent }
|
||||
end
|
||||
|
||||
def quote
|
||||
user = @message.author
|
||||
text = @message.content
|
||||
subject = @message.subject.gsub('"', '\"')
|
||||
subject = "RE: #{subject}" unless subject.starts_with?('RE:')
|
||||
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 << "$('reply_subject').value = \"#{subject}\";"
|
||||
page.<< "$('message_content').value = \"#{content}\";"
|
||||
page.show 'reply'
|
||||
page << "Form.Element.focus('message_content');"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -19,8 +19,6 @@ class MyController < ApplicationController
|
||||
before_filter :require_login
|
||||
|
||||
helper :issues
|
||||
helper :users
|
||||
helper :custom_fields
|
||||
|
||||
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
||||
'issuesreportedbyme' => :label_reported_issues,
|
||||
@@ -29,13 +27,14 @@ class MyController < ApplicationController
|
||||
'calendar' => :label_calendar,
|
||||
'documents' => :label_document_plural,
|
||||
'timelog' => :label_spent_time
|
||||
}.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
|
||||
}.freeze
|
||||
|
||||
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
|
||||
'right' => ['issuesreportedbyme']
|
||||
}.freeze
|
||||
|
||||
verify :xhr => true,
|
||||
:session => :page_layout,
|
||||
:only => [:add_block, :remove_block, :order_blocks]
|
||||
|
||||
def index
|
||||
@@ -54,28 +53,31 @@ class MyController < ApplicationController
|
||||
@user = User.current
|
||||
@pref = @user.pref
|
||||
if request.post?
|
||||
@user.safe_attributes = params[:user]
|
||||
@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 = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
||||
@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
|
||||
unless @user.change_password_allowed?
|
||||
flash[:error] = l(:notice_can_t_change_password)
|
||||
redirect_to :action => 'account'
|
||||
return
|
||||
end
|
||||
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]
|
||||
@@ -91,65 +93,43 @@ class MyController < ApplicationController
|
||||
|
||||
# Create a new feeds key
|
||||
def reset_rss_key
|
||||
if request.post?
|
||||
if User.current.rss_token
|
||||
User.current.rss_token.destroy
|
||||
User.current.reload
|
||||
end
|
||||
User.current.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
|
||||
|
||||
# Create a new API key
|
||||
def reset_api_key
|
||||
if request.post?
|
||||
if User.current.api_token
|
||||
User.current.api_token.destroy
|
||||
User.current.reload
|
||||
end
|
||||
User.current.api_key
|
||||
flash[:notice] = l(:notice_api_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("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
|
||||
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].to_s.underscore
|
||||
(render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
|
||||
block = params[:block]
|
||||
render(:nothing => true) and return unless block && (BLOCKS.keys.include? block)
|
||||
@user = User.current
|
||||
layout = @user.pref[:my_page_layout] || {}
|
||||
# remove if already present in a group
|
||||
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
||||
# add it on top
|
||||
layout['top'].unshift block
|
||||
@user.pref[:my_page_layout] = layout
|
||||
@user.pref.save
|
||||
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].to_s.underscore
|
||||
@user = User.current
|
||||
block = params[:block]
|
||||
# remove block in all groups
|
||||
layout = @user.pref[:my_page_layout] || {}
|
||||
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||
@user.pref[:my_page_layout] = layout
|
||||
@user.pref.save
|
||||
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
@@ -158,20 +138,23 @@ class MyController < ApplicationController
|
||||
# params[:list-(top|left|right)] : array of block ids of the group
|
||||
def order_blocks
|
||||
group = params[:group]
|
||||
@user = User.current
|
||||
if group.is_a?(String)
|
||||
group_items = (params["list-#{group}"] || []).collect(&:underscore)
|
||||
if group_items and group_items.is_a? Array
|
||||
layout = @user.pref[:my_page_layout] || {}
|
||||
# remove group blocks if they are presents in other groups
|
||||
%w(top left right).each {|f|
|
||||
layout[f] = (layout[f] || []) - group_items
|
||||
}
|
||||
layout[group] = group_items
|
||||
@user.pref[:my_page_layout] = layout
|
||||
@user.pref.save
|
||||
end
|
||||
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,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,39 +16,20 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class NewsController < ApplicationController
|
||||
default_search_scope :news
|
||||
model_object News
|
||||
before_filter :find_model_object, :except => [:new, :create, :index]
|
||||
before_filter :find_project_from_association, :except => [:new, :create, :index]
|
||||
before_filter :find_project, :only => [:new, :create]
|
||||
before_filter :authorize, :except => [:index]
|
||||
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_rss_auth :index
|
||||
accept_api_auth :index
|
||||
|
||||
helper :watchers
|
||||
accept_key_auth :index
|
||||
|
||||
def index
|
||||
case params[:format]
|
||||
when 'xml', 'json'
|
||||
@offset, @limit = api_offset_and_limit
|
||||
else
|
||||
@limit = 10
|
||||
end
|
||||
|
||||
scope = @project ? @project.news.visible : News.visible
|
||||
|
||||
@news_count = scope.count
|
||||
@news_pages = Paginator.new self, @news_count, @limit, params['page']
|
||||
@offset ||= @news_pages.current.offset
|
||||
@newss = scope.all(:include => [:author, :project],
|
||||
:order => "#{News.table_name}.created_on DESC",
|
||||
:offset => @offset,
|
||||
:limit => @limit)
|
||||
|
||||
@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.api
|
||||
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
||||
end
|
||||
end
|
||||
@@ -60,39 +41,57 @@ class NewsController < ApplicationController
|
||||
|
||||
def new
|
||||
@news = News.new(:project => @project, :author => User.current)
|
||||
end
|
||||
|
||||
def create
|
||||
@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
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if request.put? and @news.update_attributes(params[:news])
|
||||
def edit
|
||||
if request.post? and @news.update_attributes(params[:news])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'show', :id => @news
|
||||
else
|
||||
render :action => 'edit'
|
||||
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
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 PreviewsController < ApplicationController
|
||||
before_filter :find_project
|
||||
|
||||
def issue
|
||||
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
||||
if @issue
|
||||
@attachements = @issue.attachments
|
||||
@description = params[:issue] && params[:issue][:description]
|
||||
if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
|
||||
@description = nil
|
||||
end
|
||||
@notes = params[:notes]
|
||||
else
|
||||
@description = (params[:issue] ? params[:issue][:description] : nil)
|
||||
end
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def news
|
||||
@text = (params[:news] ? params[:news][:description] : nil)
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
|
||||
@project = Project.find(project_id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
class ProjectEnumerationsController < ApplicationController
|
||||
before_filter :find_project_by_project_id
|
||||
before_filter :authorize
|
||||
|
||||
def update
|
||||
if request.put? && params[:enumerations]
|
||||
Project.transaction do
|
||||
params[:enumerations].each do |id, activity|
|
||||
@project.update_or_create_time_entry_activity(id, activity)
|
||||
end
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
end
|
||||
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
|
||||
end
|
||||
|
||||
def destroy
|
||||
@project.time_entry_activities.each do |time_entry_activity|
|
||||
time_entry_activity.destroy(time_entry_activity.parent)
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -17,27 +17,24 @@
|
||||
|
||||
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
|
||||
|
||||
before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ]
|
||||
before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
|
||||
before_filter :authorize_global, :only => [:new, :create]
|
||||
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
|
||||
accept_rss_auth :index
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
||||
after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
|
||||
if controller.request.post?
|
||||
controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt'
|
||||
end
|
||||
end
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
helper :issues
|
||||
helper IssuesHelper
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :repositories
|
||||
@@ -46,93 +43,41 @@ class ProjectsController < ApplicationController
|
||||
|
||||
# Lists visible projects
|
||||
def index
|
||||
projects = Project.find :all,
|
||||
:conditions => Project.visible_by(User.current),
|
||||
:include => :parent
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@projects = Project.visible.find(:all, :order => 'lft')
|
||||
}
|
||||
format.api {
|
||||
@offset, @limit = api_offset_and_limit
|
||||
@project_count = Project.visible.count
|
||||
@projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft')
|
||||
@project_tree = projects.group_by {|p| p.parent || p}
|
||||
@project_tree.keys.each {|p| @project_tree[p] -= [p]}
|
||||
}
|
||||
format.atom {
|
||||
projects = Project.visible.find(:all, :order => 'created_on DESC',
|
||||
:limit => Setting.feeds_limit.to_i)
|
||||
render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
|
||||
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
|
||||
|
||||
def new
|
||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||
@trackers = Tracker.all
|
||||
@project = Project.new(params[:project])
|
||||
end
|
||||
|
||||
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def create
|
||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||
@trackers = Tracker.all
|
||||
@project = Project.new
|
||||
@project.safe_attributes = params[:project]
|
||||
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
# Add current user as a project member if he is not admin
|
||||
unless User.current.admin?
|
||||
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||
m = Member.new(:user => User.current, :roles => [r])
|
||||
@project.members << m
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new' }
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def copy
|
||||
# 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')
|
||||
@source_project = Project.find(params[:id])
|
||||
@project = Project.new(params[:project])
|
||||
if request.get?
|
||||
@project = Project.copy_from(@source_project)
|
||||
if @project
|
||||
@project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
|
||||
else
|
||||
redirect_to :controller => 'admin', :action => 'projects'
|
||||
end
|
||||
@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
|
||||
Mailer.with_deliveries(params[:notifications] == '1') do
|
||||
@project = Project.new
|
||||
@project.safe_attributes = params[:project]
|
||||
if validate_parent_id && @project.copy(@source_project, :only => params[:only])
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project
|
||||
elsif !@project.new_record?
|
||||
# Project was created
|
||||
# But some objects were not copied due to validation failures
|
||||
# (eg. issues from disabled trackers)
|
||||
# TODO: inform about that
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_to :controller => 'admin', :action => 'projects'
|
||||
@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
|
||||
@@ -142,33 +87,32 @@ class ProjectsController < ApplicationController
|
||||
redirect_to_project_menu_item(@project, params[:jump]) && return
|
||||
end
|
||||
|
||||
@users_by_role = @project.users_by_role
|
||||
@subprojects = @project.children.visible.all
|
||||
@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?)
|
||||
|
||||
@open_issues_by_tracker = Issue.visible.count(:group => :tracker,
|
||||
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.visible.count(:group => :tracker,
|
||||
@total_issues_by_tracker = Issue.count(:group => :tracker,
|
||||
:include => [:project, :status, :tracker],
|
||||
:conditions => cond)
|
||||
|
||||
if User.current.allowed_to?(:view_time_entries, @project)
|
||||
@total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
|
||||
end
|
||||
|
||||
TimeEntry.visible_by(User.current) do
|
||||
@total_hours = TimeEntry.sum(:hours,
|
||||
:include => :project,
|
||||
:conditions => cond).to_f
|
||||
end
|
||||
@key = User.current.rss_key
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.api
|
||||
end
|
||||
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
|
||||
@@ -177,73 +121,163 @@ class ProjectsController < ApplicationController
|
||||
@wiki ||= @project.wiki
|
||||
end
|
||||
|
||||
# Edit @project
|
||||
def edit
|
||||
end
|
||||
|
||||
# TODO: convert to PUT only
|
||||
verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def update
|
||||
@project.safe_attributes = params[:project]
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'settings', :id => @project
|
||||
}
|
||||
format.api { head :ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
settings
|
||||
render :action => 'settings'
|
||||
}
|
||||
format.api { render_validation_errors(@project) }
|
||||
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
|
||||
|
||||
verify :method => :post, :only => :modules, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
|
||||
def modules
|
||||
@project.enabled_module_names = params[:enabled_module_names]
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
@project.enabled_module_names = params[:enabled_modules]
|
||||
redirect_to :action => 'settings', :id => @project, :tab => 'modules'
|
||||
end
|
||||
|
||||
def archive
|
||||
if request.post?
|
||||
unless @project.archive
|
||||
flash[:error] = l(:error_can_not_archive_project)
|
||||
end
|
||||
end
|
||||
redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
|
||||
@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(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
|
||||
redirect_to :controller => 'admin', :action => 'projects'
|
||||
end
|
||||
|
||||
# Delete @project
|
||||
def destroy
|
||||
@project_to_destroy = @project
|
||||
if request.get?
|
||||
# display confirmation view
|
||||
else
|
||||
if api_request? || params[:confirm]
|
||||
@project_to_destroy.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'admin', :action => 'projects' }
|
||||
format.api { head :ok }
|
||||
end
|
||||
end
|
||||
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])
|
||||
@@ -252,18 +286,11 @@ private
|
||||
render_404
|
||||
end
|
||||
|
||||
# Validates parent_id param according to user's permissions
|
||||
# TODO: move it to Project model in a validation that depends on User.current
|
||||
def validate_parent_id
|
||||
return true if User.current.admin?
|
||||
parent_id = params[:project] && params[:project][:parent_id]
|
||||
if parent_id || @project.new_record?
|
||||
parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
|
||||
unless @project.allowed_parents.include?(parent)
|
||||
@project.errors.add :parent_id, :invalid
|
||||
return false
|
||||
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
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,13 +24,13 @@ class QueriesController < ApplicationController
|
||||
@query = Query.new(params[:query])
|
||||
@query.project = params[:query_is_for_all] ? nil : @project
|
||||
@query.user = User.current
|
||||
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
||||
|
||||
@query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f]
|
||||
@query.group_by ||= params[:group_by]
|
||||
@query.column_names = params[:c] if params[:c]
|
||||
@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
|
||||
@@ -42,12 +42,12 @@ class QueriesController < ApplicationController
|
||||
def edit
|
||||
if request.post?
|
||||
@query.filters = {}
|
||||
@query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f]
|
||||
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 User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
||||
@query.group_by ||= params[:group_by]
|
||||
@query.column_names = params[:c] if params[:c]
|
||||
@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
|
||||
@@ -73,7 +73,7 @@ private
|
||||
|
||||
def find_optional_project
|
||||
@project = Project.find(params[:project_id]) if params[:project_id]
|
||||
render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
|
||||
User.current.allowed_to?(:save_queries, @project, :global => true)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
@@ -17,79 +17,220 @@
|
||||
|
||||
class ReportsController < ApplicationController
|
||||
menu_item :issues
|
||||
before_filter :find_project, :authorize, :find_issue_statuses
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
def issue_report
|
||||
@trackers = @project.trackers
|
||||
@versions = @project.shared_versions.sort
|
||||
@priorities = IssuePriority.all
|
||||
@categories = @project.issue_categories
|
||||
@assignees = @project.members.collect { |m| m.user }.sort
|
||||
@authors = @project.members.collect { |m| m.user }.sort
|
||||
@subprojects = @project.descendants.visible
|
||||
|
||||
@issues_by_tracker = Issue.by_tracker(@project)
|
||||
@issues_by_version = Issue.by_version(@project)
|
||||
@issues_by_priority = Issue.by_priority(@project)
|
||||
@issues_by_category = Issue.by_category(@project)
|
||||
@issues_by_assigned_to = Issue.by_assigned_to(@project)
|
||||
@issues_by_author = Issue.by_author(@project)
|
||||
@issues_by_subproject = Issue.by_subproject(@project) || []
|
||||
|
||||
render :template => "reports/issue_report"
|
||||
end
|
||||
|
||||
def issue_report_details
|
||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||
|
||||
case params[:detail]
|
||||
when "tracker"
|
||||
@field = "tracker_id"
|
||||
@rows = @project.trackers
|
||||
@data = Issue.by_tracker(@project)
|
||||
@data = issues_by_tracker
|
||||
@report_title = l(:field_tracker)
|
||||
render :template => "reports/issue_report_details"
|
||||
when "version"
|
||||
@field = "fixed_version_id"
|
||||
@rows = @project.shared_versions.sort
|
||||
@data = Issue.by_version(@project)
|
||||
@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 = IssuePriority.all
|
||||
@data = Issue.by_priority(@project)
|
||||
@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 = Issue.by_category(@project)
|
||||
@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 }.sort
|
||||
@data = Issue.by_assigned_to(@project)
|
||||
@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 }.sort
|
||||
@data = Issue.by_author(@project)
|
||||
@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.descendants.visible
|
||||
@data = Issue.by_subproject(@project) || []
|
||||
@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
|
||||
|
||||
respond_to do |format|
|
||||
if @field
|
||||
format.html {}
|
||||
else
|
||||
format.html { redirect_to :action => 'issue_report', :id => @project }
|
||||
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
|
||||
|
||||
private
|
||||
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 find_issue_statuses
|
||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||
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,16 +1,16 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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.
|
||||
@@ -24,47 +24,26 @@ class InvalidRevisionParam < Exception; end
|
||||
|
||||
class RepositoriesController < ApplicationController
|
||||
menu_item :repository
|
||||
menu_item :settings, :only => :edit
|
||||
default_search_scope :changesets
|
||||
|
||||
before_filter :find_repository, :except => :edit
|
||||
before_filter :find_project, :only => :edit
|
||||
before_filter :authorize
|
||||
accept_rss_auth :revisions
|
||||
|
||||
accept_key_auth :revisions
|
||||
|
||||
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
|
||||
|
||||
|
||||
def edit
|
||||
@repository = @project.repository
|
||||
if !@repository && !params[:repository_scm].blank?
|
||||
if !@repository
|
||||
@repository = Repository.factory(params[:repository_scm])
|
||||
@repository.project = @project if @repository
|
||||
end
|
||||
if request.post? && @repository
|
||||
p1 = params[:repository]
|
||||
p = {}
|
||||
p_extra = {}
|
||||
p1.each do |k, v|
|
||||
if k =~ /^extra_/
|
||||
p_extra[k] = v
|
||||
else
|
||||
p[k] = v
|
||||
end
|
||||
end
|
||||
@repository.attributes = p
|
||||
@repository.merge_extra_info(p_extra)
|
||||
@repository.attributes = params[:repository]
|
||||
@repository.save
|
||||
end
|
||||
render(:update) do |page|
|
||||
page.replace_html "tab-content-repository",
|
||||
:partial => 'projects/settings/repository'
|
||||
if @repository && !@project.repository
|
||||
@project.reload # needed to reload association
|
||||
page.replace_html "main-menu", render_main_menu(@project)
|
||||
end
|
||||
end
|
||||
render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'}
|
||||
end
|
||||
|
||||
|
||||
def committers
|
||||
@committers = @repository.committers
|
||||
@users = @project.users
|
||||
@@ -79,106 +58,84 @@ class RepositoriesController < ApplicationController
|
||||
redirect_to :action => 'committers', :id => @project
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@repository.destroy
|
||||
redirect_to :controller => 'projects',
|
||||
:action => 'settings',
|
||||
:id => @project,
|
||||
:tab => 'repository'
|
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
||||
|
||||
# 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)
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
if request.xhr?
|
||||
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
||||
else
|
||||
(show_error_not_found; return) unless @entries
|
||||
@changesets = @repository.latest_changesets(@path, @rev)
|
||||
show_error_not_found and return unless @entries
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
render :action => 'show'
|
||||
render :action => 'browse'
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :browse, :show
|
||||
|
||||
|
||||
def changes
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
(show_error_not_found; return) unless @entry
|
||||
@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
|
||||
show_error_not_found and return unless @entry
|
||||
@changesets = @repository.changesets_for_path(@path)
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
end
|
||||
|
||||
|
||||
def revisions
|
||||
@changeset_count = @repository.changesets.count
|
||||
@changeset_pages = Paginator.new self, @changeset_count,
|
||||
per_page_option,
|
||||
params['page']
|
||||
per_page_option,
|
||||
params['page']
|
||||
@changesets = @repository.changesets.find(:all,
|
||||
:limit => @changeset_pages.items_per_page,
|
||||
:offset => @changeset_pages.current.offset,
|
||||
:include => [:user, :repository])
|
||||
: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; return) unless @entry
|
||||
|
||||
show_error_not_found and return unless @entry
|
||||
|
||||
# If the entry is a dir, show the browser
|
||||
(show; return) if @entry.is_dir?
|
||||
|
||||
browse and return if @entry.is_dir?
|
||||
|
||||
@content = @repository.cat(@path, @rev)
|
||||
(show_error_not_found; return) unless @content
|
||||
if 'raw' == params[:format] ||
|
||||
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
|
||||
! is_entry_text_data?(@content, @path)
|
||||
# Force the download
|
||||
send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
|
||||
send_type = Redmine::MimeType.of(@path)
|
||||
send_opt[:type] = send_type.to_s if send_type
|
||||
send_data @content, send_opt
|
||||
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
|
||||
# TODO: UTF-16
|
||||
# Is this needs? AttachmentsController reads file simply.
|
||||
@content.gsub!("\r\n", "\n")
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def is_entry_text_data?(ent, path)
|
||||
# UTF-16 contains "\x00".
|
||||
# It is very strict that file contains less than 30% of ascii symbols
|
||||
# in non Western Europe.
|
||||
return true if Redmine::MimeType.is_type?('text', path)
|
||||
# Ruby 1.8.6 has a bug of integer divisions.
|
||||
# http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
|
||||
return false if ent.is_binary_data?
|
||||
true
|
||||
end
|
||||
private :is_entry_text_data?
|
||||
|
||||
|
||||
def annotate
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
(show_error_not_found; return) unless @entry
|
||||
|
||||
show_error_not_found and return unless @entry
|
||||
|
||||
@annotate = @repository.scm.annotate(@path, @rev)
|
||||
(render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
render_error l(:error_scm_annotate) and return if @annotate.nil? || @annotate.empty?
|
||||
end
|
||||
|
||||
|
||||
def revision
|
||||
raise ChangesetNotFound if @rev.blank?
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
@changeset = @repository.changesets.find_by_revision(@rev)
|
||||
raise ChangesetNotFound unless @changeset
|
||||
|
||||
respond_to do |format|
|
||||
@@ -188,11 +145,11 @@ class RepositoriesController < ApplicationController
|
||||
rescue ChangesetNotFound
|
||||
show_error_not_found
|
||||
end
|
||||
|
||||
|
||||
def diff
|
||||
if params[:format] == 'diff'
|
||||
@diff = @repository.diff(@path, @rev, @rev_to)
|
||||
(show_error_not_found; return) unless @diff
|
||||
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",
|
||||
@@ -201,30 +158,26 @@ class RepositoriesController < ApplicationController
|
||||
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}-#{current_language}")
|
||||
|
||||
@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
|
||||
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
@changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
|
||||
@diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
|
||||
end
|
||||
end
|
||||
|
||||
def stats
|
||||
|
||||
def stats
|
||||
end
|
||||
|
||||
|
||||
def graph
|
||||
data = nil
|
||||
data = nil
|
||||
case params[:graph]
|
||||
when "commits_per_month"
|
||||
data = graph_commits_per_month(@repository)
|
||||
@@ -238,25 +191,25 @@ class RepositoriesController < ApplicationController
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
|
||||
|
||||
|
||||
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; return false) unless @repository
|
||||
render_404 and return false unless @repository
|
||||
@path = params[:path].join('/') unless params[:path].nil?
|
||||
@path ||= ''
|
||||
@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip
|
||||
@rev = params[:rev]
|
||||
@rev_to = params[:rev_to]
|
||||
|
||||
unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
|
||||
if @repository.branches.blank?
|
||||
raise InvalidRevisionParam
|
||||
end
|
||||
end
|
||||
raise InvalidRevisionParam unless @rev.to_s.match(REV_PARAM_RE) && @rev.to_s.match(REV_PARAM_RE)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
rescue InvalidRevisionParam
|
||||
@@ -264,33 +217,30 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def show_error_not_found
|
||||
render_error :message => l(:error_scm_not_found), :status => 404
|
||||
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_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_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 = []
|
||||
12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
|
||||
|
||||
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,
|
||||
@@ -302,7 +252,7 @@ class RepositoriesController < ApplicationController
|
||||
: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)
|
||||
@@ -312,28 +262,28 @@ class RepositoriesController < ApplicationController
|
||||
: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.to_a.sort! {|x, y| x.last <=> y.last}
|
||||
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,
|
||||
@@ -345,18 +295,22 @@ class RepositoriesController < ApplicationController
|
||||
: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
|
||||
|
||||
end
|
||||
|
||||
class Date
|
||||
def months_ago(date = Date.today)
|
||||
(date.year - self.year)*12 + (date.month - self.month)
|
||||
|
||||
@@ -16,16 +16,19 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class RolesController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
verify :method => :post, :only => [ :destroy, :move ],
|
||||
:redirect_to => { :action => :index }
|
||||
: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 => "index", :layout => false if request.xhr?
|
||||
render :action => "list", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -37,32 +40,45 @@ class RolesController < ApplicationController
|
||||
@role.workflows.copy(copy_from)
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'index'
|
||||
else
|
||||
@permissions = @role.setable_permissions
|
||||
@roles = Role.find :all, :order => 'builtin, position'
|
||||
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 => 'index'
|
||||
else
|
||||
@permissions = @role.setable_permissions
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
@permissions = @role.setable_permissions
|
||||
end
|
||||
|
||||
def destroy
|
||||
@role = Role.find(params[:id])
|
||||
@role.destroy
|
||||
redirect_to :action => 'index'
|
||||
redirect_to :action => 'list'
|
||||
rescue
|
||||
flash[:error] = l(:error_can_not_remove_role)
|
||||
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? }
|
||||
@@ -72,7 +88,7 @@ class RolesController < ApplicationController
|
||||
role.save
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'index'
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -24,8 +24,8 @@ class SearchController < ApplicationController
|
||||
def index
|
||||
@question = params[:q] || ""
|
||||
@question.strip!
|
||||
@all_words = params[:all_words] ? params[:all_words].present? : true
|
||||
@titles_only = params[:titles_only] ? params[:titles_only].present? : false
|
||||
@all_words = params[:all_words] || (params[:submit] ? false : true)
|
||||
@titles_only = !params[:titles_only].nil?
|
||||
|
||||
projects_to_search =
|
||||
case params[:scope]
|
||||
@@ -34,7 +34,7 @@ class SearchController < ApplicationController
|
||||
when 'my_projects'
|
||||
User.current.memberships.collect(&:project)
|
||||
when 'subprojects'
|
||||
@project ? (@project.self_and_descendants.active) : nil
|
||||
@project ? ([ @project ] + @project.active_children) : nil
|
||||
else
|
||||
@project
|
||||
end
|
||||
@@ -43,12 +43,12 @@ class SearchController < ApplicationController
|
||||
begin; offset = params[:offset].to_time if params[:offset]; rescue; end
|
||||
|
||||
# quick jump to an issue
|
||||
if @question.match(/^#?(\d+)$/) && Issue.visible.find_by_id($1.to_i)
|
||||
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 = Redmine::Search.available_search_types.dup
|
||||
@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')
|
||||
@@ -62,19 +62,21 @@ class SearchController < ApplicationController
|
||||
# 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 2 characters long
|
||||
@tokens = @tokens.uniq.select {|w| w.length > 1 }
|
||||
# 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
|
||||
@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(@tokens, projects_to_search,
|
||||
r, c = s.singularize.camelcase.constantize.search(like_tokens, projects_to_search,
|
||||
:all_words => @all_words,
|
||||
:titles_only => @titles_only,
|
||||
:limit => (limit+1),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,8 +16,6 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class SettingsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
@@ -26,7 +24,7 @@ class SettingsController < ApplicationController
|
||||
end
|
||||
|
||||
def edit
|
||||
@notifiables = Redmine::Notifiable.all
|
||||
@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|
|
||||
@@ -36,16 +34,14 @@ class SettingsController < ApplicationController
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'edit', :tab => params[:tab]
|
||||
else
|
||||
@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 << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
|
||||
|
||||
Redmine::Themes.rescan
|
||||
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
|
||||
@@ -54,10 +50,9 @@ class SettingsController < ApplicationController
|
||||
Setting["plugin_#{@plugin.id}"] = params[:settings]
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'plugin', :id => @plugin.id
|
||||
else
|
||||
@partial = @plugin.settings[:partial]
|
||||
@settings = Setting["plugin_#{@plugin.id}"]
|
||||
end
|
||||
@partial = @plugin.settings[:partial]
|
||||
@settings = Setting["plugin_#{@plugin.id}"]
|
||||
rescue Redmine::PluginNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,53 +16,31 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class SysController < ActionController::Base
|
||||
before_filter :check_enabled
|
||||
wsdl_service_name 'Sys'
|
||||
web_service_api SysApi
|
||||
web_service_scaffold :invoke
|
||||
|
||||
def projects
|
||||
p = Project.active.has_module(:repository).find(:all, :include => :repository, :order => 'identifier')
|
||||
# extra_info attribute from repository breaks activeresource client
|
||||
render :xml => p.to_xml(:only => [:id, :identifier, :name, :is_public, :status], :include => {:repository => {:only => [:id, :url]}})
|
||||
end
|
||||
before_invocation :check_enabled
|
||||
|
||||
def create_project_repository
|
||||
project = Project.find(params[:id])
|
||||
if project.repository
|
||||
render :nothing => true, :status => 409
|
||||
else
|
||||
logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
|
||||
project.repository = Repository.factory(params[:vendor], params[:repository])
|
||||
if project.repository && project.repository.save
|
||||
render :xml => project.repository.to_xml(:only => [:id, :url]), :status => 201
|
||||
else
|
||||
render :nothing => true, :status => 422
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
projects = []
|
||||
if params[:id]
|
||||
projects << Project.active.has_module(:repository).find(params[:id])
|
||||
else
|
||||
projects = Project.active.has_module(:repository).find(:all, :include => :repository)
|
||||
end
|
||||
projects.each do |project|
|
||||
if project.repository
|
||||
project.repository.fetch_changesets
|
||||
end
|
||||
end
|
||||
render :nothing => true, :status => 200
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render :nothing => true, :status => 404
|
||||
# Returns the projects list, with their repositories
|
||||
def projects_with_repository_enabled
|
||||
Project.has_module(:repository).find(:all, :include => :repository, :order => 'identifier')
|
||||
end
|
||||
|
||||
protected
|
||||
# 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
|
||||
|
||||
def check_enabled
|
||||
User.current = nil
|
||||
unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
|
||||
render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
|
||||
return false
|
||||
end
|
||||
protected
|
||||
|
||||
def check_enabled(name, args)
|
||||
Setting.sys_api_enabled?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,209 +0,0 @@
|
||||
class TimeEntryReportsController < ApplicationController
|
||||
menu_item :issues
|
||||
before_filter :find_optional_project
|
||||
before_filter :load_available_criterias
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :issues
|
||||
helper :timelog
|
||||
include TimelogHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
def report
|
||||
@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_condition = ''
|
||||
|
||||
if @project.nil?
|
||||
sql_condition = Project.allowed_to_condition(User.current, :view_time_entries)
|
||||
elsif @issue.nil?
|
||||
sql_condition = @project.project_condition(Setting.display_subprojects_issues?)
|
||||
else
|
||||
sql_condition = "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
|
||||
end
|
||||
|
||||
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
|
||||
sql << " FROM #{TimeEntry.table_name}"
|
||||
sql << time_report_joins
|
||||
sql << " WHERE"
|
||||
sql << " (%s) AND" % sql_condition
|
||||
sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from), ActiveRecord::Base.connection.quoted_date(@to)]
|
||||
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
|
||||
|
||||
@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), :type => 'text/csv; header=present', :filename => 'timelog.csv') }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# TODO: duplicated in TimelogController
|
||||
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
|
||||
# TODO: duplicated in TimelogController
|
||||
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.earilest_date_for_project(@project) || Date.today)
|
||||
@to ||= (TimeEntry.latest_date_for_project(@project) || Date.today)
|
||||
end
|
||||
|
||||
def load_available_criterias
|
||||
@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 => TimeEntryActivity,
|
||||
: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
|
||||
|
||||
# Add list and boolean time entry activity custom fields
|
||||
TimeEntryActivityCustomField.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 = 'Enumeration' AND c.customized_id = #{TimeEntry.table_name}.activity_id)",
|
||||
:format => cf.field_format,
|
||||
:label => cf.name}
|
||||
end
|
||||
|
||||
call_hook(:controller_timelog_available_criterias, { :available_criterias => @available_criterias, :project => @project })
|
||||
@available_criterias
|
||||
end
|
||||
|
||||
def time_report_joins
|
||||
sql = ''
|
||||
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"
|
||||
# TODO: rename hook
|
||||
call_hook(:controller_timelog_time_report_joins, {:sql => sql} )
|
||||
sql
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -17,13 +17,10 @@
|
||||
|
||||
class TimelogController < ApplicationController
|
||||
menu_item :issues
|
||||
before_filter :find_project, :only => [:new, :create]
|
||||
before_filter :find_time_entry, :only => [:show, :edit, :update]
|
||||
before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
|
||||
before_filter :authorize, :except => [:index]
|
||||
before_filter :find_optional_project, :only => [:index]
|
||||
accept_rss_auth :index
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
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
|
||||
@@ -32,7 +29,114 @@ class TimelogController < ApplicationController
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
def index
|
||||
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',
|
||||
@@ -42,215 +146,84 @@ class TimelogController < ApplicationController
|
||||
'hours' => 'hours'
|
||||
|
||||
cond = ARCondition.new
|
||||
if @issue
|
||||
cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
|
||||
elsif @project
|
||||
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]
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# Paginate results
|
||||
@entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
|
||||
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
|
||||
@entries = TimeEntry.visible.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.visible.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f
|
||||
|
||||
render :layout => !request.xhr?
|
||||
}
|
||||
format.api {
|
||||
@entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
|
||||
@offset, @limit = api_offset_and_limit
|
||||
@entries = TimeEntry.visible.find(:all,
|
||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||
:conditions => cond.conditions,
|
||||
:order => sort_clause,
|
||||
:limit => @limit,
|
||||
:offset => @offset)
|
||||
}
|
||||
format.atom {
|
||||
entries = TimeEntry.visible.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.visible.find(:all,
|
||||
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
||||
:conditions => cond.conditions,
|
||||
:order => sort_clause)
|
||||
send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
# TODO: Implement html response
|
||||
format.html { render :nothing => true, :status => 406 }
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
|
||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
||||
render :action => 'edit'
|
||||
end
|
||||
|
||||
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def create
|
||||
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
|
||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
||||
|
||||
if @time_entry.save
|
||||
TimeEntry.visible_by(User.current) do
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_back_or_default :action => 'index', :project_id => @time_entry.project
|
||||
# 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')
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@time_entry) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
render_403 and return if @time_entry && !@time_entry.editable_by?(User.current)
|
||||
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
|
||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
||||
end
|
||||
|
||||
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def update
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
|
||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
||||
|
||||
if @time_entry.save
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_back_or_default :action => 'index', :project_id => @time_entry.project
|
||||
}
|
||||
format.api { head :ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@time_entry) }
|
||||
end
|
||||
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 bulk_edit
|
||||
@available_activities = TimeEntryActivity.shared.active
|
||||
@custom_fields = TimeEntry.first.available_custom_fields
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
attributes = parse_params_for_bulk_time_entry_attributes(params)
|
||||
|
||||
unsaved_time_entry_ids = []
|
||||
@time_entries.each do |time_entry|
|
||||
time_entry.reload
|
||||
time_entry.attributes = attributes
|
||||
call_hook(:controller_time_entries_bulk_edit_before_save, { :params => params, :time_entry => time_entry })
|
||||
unless time_entry.save
|
||||
# Keep unsaved time_entry ids to display them in flash error
|
||||
unsaved_time_entry_ids << time_entry.id
|
||||
end
|
||||
end
|
||||
set_flash_from_bulk_time_entry_save(@time_entries, unsaved_time_entry_ids)
|
||||
redirect_back_or_default({:controller => 'timelog', :action => 'index', :project_id => @projects.first})
|
||||
end
|
||||
|
||||
verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
|
||||
def destroy
|
||||
@time_entries.each do |t|
|
||||
begin
|
||||
unless t.destroy && t.destroyed?
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:error] = l(:notice_unable_delete_time_entry)
|
||||
redirect_to :back
|
||||
}
|
||||
format.api { render_validation_errors(t) }
|
||||
end
|
||||
return
|
||||
end
|
||||
rescue ::ActionController::RedirectBackError
|
||||
redirect_to :action => 'index', :project_id => @projects.first
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
redirect_back_or_default(:action => 'index', :project_id => @projects.first)
|
||||
}
|
||||
format.api { head :ok }
|
||||
end
|
||||
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_time_entry
|
||||
@time_entry = TimeEntry.find(params[:id])
|
||||
unless @time_entry.editable_by?(User.current)
|
||||
render_403
|
||||
return false
|
||||
end
|
||||
@project = @time_entry.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_time_entries
|
||||
@time_entries = TimeEntry.find_all_by_id(params[:id] || params[:ids])
|
||||
raise ActiveRecord::RecordNotFound if @time_entries.empty?
|
||||
@projects = @time_entries.collect(&:project).compact.uniq
|
||||
@project = @projects.first if @projects.size == 1
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def set_flash_from_bulk_time_entry_save(time_entries, unsaved_time_entry_ids)
|
||||
if unsaved_time_entry_ids.empty?
|
||||
flash[:notice] = l(:notice_successful_update) unless time_entries.empty?
|
||||
else
|
||||
flash[:error] = l(:notice_failed_to_save_time_entries,
|
||||
:count => unsaved_time_entry_ids.size,
|
||||
:total => time_entries.size,
|
||||
:ids => '#' + unsaved_time_entry_ids.join(', #'))
|
||||
end
|
||||
end
|
||||
|
||||
def find_project
|
||||
if (issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id])).present?
|
||||
@issue = Issue.find(issue_id)
|
||||
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 (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
|
||||
@project = Project.find(project_id)
|
||||
elsif params[:project_id]
|
||||
@project = Project.find(params[:project_id])
|
||||
else
|
||||
render_404
|
||||
return false
|
||||
@@ -311,14 +284,7 @@ private
|
||||
end
|
||||
|
||||
@from, @to = @to, @from if @from && @to && @from > @to
|
||||
@from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today)
|
||||
@to ||= (TimeEntry.latest_date_for_project(@project) || Date.today)
|
||||
end
|
||||
|
||||
def parse_params_for_bulk_time_entry_attributes(params)
|
||||
attributes = (params[:time_entry] || {}).reject {|k,v| v.blank?}
|
||||
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
|
||||
attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
|
||||
attributes
|
||||
@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,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,15 +16,19 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class TrackersController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
|
||||
|
||||
def index
|
||||
list
|
||||
render :action => 'list' unless request.xhr?
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :move ], :redirect_to => { :action => :list }
|
||||
|
||||
def list
|
||||
@tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
|
||||
render :action => "index", :layout => false if request.xhr?
|
||||
render :action => "list", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -35,30 +39,41 @@ class TrackersController < ApplicationController
|
||||
@tracker.workflows.copy(copy_from)
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'index'
|
||||
return
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
@trackers = Tracker.find :all, :order => 'position'
|
||||
@projects = Project.find(:all)
|
||||
end
|
||||
|
||||
def edit
|
||||
@tracker = Tracker.find(params[:id])
|
||||
if request.post? and @tracker.update_attributes(params[:tracker])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'index'
|
||||
return
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
@projects = Project.find(:all)
|
||||
end
|
||||
|
||||
def move
|
||||
@tracker = Tracker.find(params[:id])
|
||||
case params[:position]
|
||||
when 'highest'
|
||||
@tracker.move_to_top
|
||||
when 'higher'
|
||||
@tracker.move_higher
|
||||
when 'lower'
|
||||
@tracker.move_lower
|
||||
when 'lowest'
|
||||
@tracker.move_to_bottom
|
||||
end if params[:position]
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def destroy
|
||||
@tracker = Tracker.find(params[:id])
|
||||
unless @tracker.issues.empty?
|
||||
flash[:error] = l(:error_can_not_delete_tracker)
|
||||
flash[:error] = "This tracker contains issues and can\'t be deleted."
|
||||
else
|
||||
@tracker.destroy
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,11 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class UsersController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin, :except => :show
|
||||
before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership]
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
before_filter :require_admin
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
@@ -28,213 +24,85 @@ class UsersController < ApplicationController
|
||||
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)
|
||||
|
||||
case params[:format]
|
||||
when 'xml', 'json'
|
||||
@offset, @limit = api_offset_and_limit
|
||||
else
|
||||
@limit = per_page_option
|
||||
end
|
||||
|
||||
scope = User
|
||||
scope = scope.in_group(params[:group_id].to_i) if params[:group_id].present?
|
||||
|
||||
@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 ? OR LOWER(mail) LIKE ?", name, name, name, name]
|
||||
c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ?", name, name, name]
|
||||
end
|
||||
|
||||
@user_count = scope.count(:conditions => c.conditions)
|
||||
@user_pages = Paginator.new self, @user_count, @limit, params['page']
|
||||
@offset ||= @user_pages.current.offset
|
||||
@users = scope.find :all,
|
||||
:order => sort_clause,
|
||||
@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 => @limit,
|
||||
:offset => @offset
|
||||
:limit => @user_pages.items_per_page,
|
||||
:offset => @user_pages.current.offset
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@groups = Group.all.sort
|
||||
render :layout => !request.xhr?
|
||||
}
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
# show projects based on current user visibility
|
||||
@memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
||||
|
||||
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
|
||||
@events_by_day = events.group_by(&:event_date)
|
||||
|
||||
unless User.current.admin?
|
||||
if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
|
||||
render_404
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :layout => 'base' }
|
||||
format.api
|
||||
end
|
||||
render :action => "list", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
|
||||
@auth_sources = AuthSource.find(:all)
|
||||
end
|
||||
|
||||
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def create
|
||||
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
|
||||
@user.safe_attributes = params[:user]
|
||||
@user.admin = params[:user][:admin] || false
|
||||
@user.login = params[:user][:login]
|
||||
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
|
||||
|
||||
# TODO: Similar to My#account
|
||||
@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 = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
||||
|
||||
Mailer.deliver_account_information(@user, params[:user][:password]) if params[:send_information]
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to(params[:continue] ?
|
||||
{:controller => 'users', :action => 'new'} :
|
||||
{:controller => 'users', :action => 'edit', :id => @user}
|
||||
)
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
|
||||
end
|
||||
def add
|
||||
if request.get?
|
||||
@user = User.new(:language => Setting.default_language)
|
||||
else
|
||||
@auth_sources = AuthSource.find(:all)
|
||||
# Clear password input
|
||||
@user.password = @user.password_confirmation = nil
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new' }
|
||||
format.api { render_validation_errors(@user) }
|
||||
@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
|
||||
|
||||
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def update
|
||||
@user.admin = params[:user][:admin] if params[:user][:admin]
|
||||
@user.login = params[:user][:login] if params[:user][:login]
|
||||
if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
|
||||
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
|
||||
end
|
||||
@user.safe_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])
|
||||
# TODO: Similar to My#account
|
||||
@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 = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
||||
|
||||
if was_activated
|
||||
Mailer.deliver_account_activated(@user)
|
||||
elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil?
|
||||
Mailer.deliver_account_information(@user, params[:user][:password])
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :back
|
||||
}
|
||||
format.api { head :ok }
|
||||
end
|
||||
else
|
||||
@auth_sources = AuthSource.find(:all)
|
||||
@membership ||= Member.new
|
||||
# Clear password input
|
||||
@user.password = @user.password_confirmation = nil
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :action => :edit }
|
||||
format.api { render_validation_errors(@user) }
|
||||
end
|
||||
end
|
||||
rescue ::ActionController::RedirectBackError
|
||||
redirect_to :controller => 'users', :action => 'edit', :id => @user
|
||||
end
|
||||
|
||||
verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def destroy
|
||||
@user.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(users_url) }
|
||||
format.api { head :ok }
|
||||
end
|
||||
end
|
||||
|
||||
def edit_membership
|
||||
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
|
||||
@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?
|
||||
respond_to do |format|
|
||||
if @membership.valid?
|
||||
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
||||
format.js {
|
||||
render(:update) {|page|
|
||||
page.replace_html "tab-content-memberships", :partial => 'users/memberships'
|
||||
page.visual_effect(:highlight, "member-#{@membership.id}")
|
||||
}
|
||||
}
|
||||
else
|
||||
format.js {
|
||||
render(:update) {|page|
|
||||
page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
|
||||
end
|
||||
|
||||
def destroy_membership
|
||||
@membership = Member.find(params[:membership_id])
|
||||
if request.post? && @membership.deletable?
|
||||
@membership.destroy
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
||||
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_user
|
||||
if params[:id] == 'current'
|
||||
require_login || return
|
||||
@user = User.current
|
||||
else
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
@user = User.find(params[:id])
|
||||
Member.find(params[:membership_id]).destroy if request.post?
|
||||
redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,121 +17,24 @@
|
||||
|
||||
class VersionsController < ApplicationController
|
||||
menu_item :roadmap
|
||||
model_object Version
|
||||
before_filter :find_model_object, :except => [:index, :new, :create, :close_completed]
|
||||
before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed]
|
||||
before_filter :find_project, :only => [:index, :new, :create, :close_completed]
|
||||
before_filter :authorize
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
helper :custom_fields
|
||||
helper :projects
|
||||
|
||||
def index
|
||||
@trackers = @project.trackers.find(:all, :order => 'position')
|
||||
retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
|
||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||
project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
|
||||
|
||||
@versions = @project.shared_versions || []
|
||||
@versions += @project.rolled_up_versions.visible if @with_subprojects
|
||||
@versions = @versions.uniq.sort
|
||||
@versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
|
||||
|
||||
@issues_by_version = {}
|
||||
unless @selected_tracker_ids.empty?
|
||||
@versions.each do |version|
|
||||
issues = version.fixed_issues.visible.find(:all,
|
||||
:include => [:project, :status, :tracker, :priority],
|
||||
:conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids},
|
||||
:order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
|
||||
@issues_by_version[version] = issues
|
||||
end
|
||||
end
|
||||
@versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
|
||||
end
|
||||
|
||||
def show
|
||||
@issues = @version.fixed_issues.visible.find(:all,
|
||||
:include => [:status, :tracker, :priority],
|
||||
:order => "#{Tracker.table_name}.position, #{Issue.table_name}.id")
|
||||
end
|
||||
|
||||
def new
|
||||
@version = @project.versions.build
|
||||
if params[:version]
|
||||
attributes = params[:version].dup
|
||||
attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
|
||||
@version.attributes = attributes
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
# TODO: refactor with code above in #new
|
||||
@version = @project.versions.build
|
||||
if params[:version]
|
||||
attributes = params[:version].dup
|
||||
attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
|
||||
@version.attributes = attributes
|
||||
end
|
||||
|
||||
if request.post?
|
||||
if @version.save
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :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_fixed_version_id",
|
||||
content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
|
||||
}
|
||||
end
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new' }
|
||||
format.js do
|
||||
render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if request.put? && params[:version]
|
||||
attributes = params[:version].dup
|
||||
attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
|
||||
if @version.update_attributes(attributes)
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
end
|
||||
end
|
||||
if request.post? and @version.update_attributes(params[:version])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||
end
|
||||
end
|
||||
|
||||
def close_completed
|
||||
if request.put?
|
||||
@project.close_completed_versions
|
||||
end
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @version.fixed_issues.empty?
|
||||
@version.destroy
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||
else
|
||||
flash[:error] = l(:notice_unable_delete_version)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||
end
|
||||
@version.destroy
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||
rescue
|
||||
flash[:error] = l(:notice_unable_delete_version)
|
||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||
end
|
||||
|
||||
def status_by
|
||||
@@ -143,17 +46,9 @@ class VersionsController < ApplicationController
|
||||
|
||||
private
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id])
|
||||
@version = Version.find(params[:id])
|
||||
@project = @version.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
|
||||
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 = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -18,18 +18,14 @@
|
||||
class WatchersController < ApplicationController
|
||||
before_filter :find_project
|
||||
before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
|
||||
before_filter :authorize, :only => [:new, :destroy]
|
||||
before_filter :authorize, :only => :new
|
||||
|
||||
verify :method => :post,
|
||||
:only => [ :watch, :unwatch ],
|
||||
:render => { :nothing => true, :status => :method_not_allowed }
|
||||
|
||||
def watch
|
||||
if @watched.respond_to?(:visible?) && !@watched.visible?(User.current)
|
||||
render_403
|
||||
else
|
||||
set_watcher(User.current, true)
|
||||
end
|
||||
set_watcher(User.current, true)
|
||||
end
|
||||
|
||||
def unwatch
|
||||
@@ -52,18 +48,6 @@ class WatchersController < ApplicationController
|
||||
render :text => 'Watcher added.', :layout => true
|
||||
end
|
||||
|
||||
def destroy
|
||||
@watched.set_watcher(User.find(params[:user_id]), false) 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
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
klass = Object.const_get(params[:object_type].camelcase)
|
||||
@@ -78,14 +62,7 @@ private
|
||||
@watched.set_watcher(user, watching)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js do
|
||||
render(:update) do |page|
|
||||
c = watcher_css(@watched)
|
||||
page.select(".#{c}").each do |item|
|
||||
page.replace_html item, watcher_link(@watched, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
@@ -16,15 +16,9 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WelcomeController < ApplicationController
|
||||
caches_action :robots
|
||||
|
||||
def index
|
||||
@news = News.latest User.current
|
||||
@projects = Project.latest User.current
|
||||
end
|
||||
|
||||
def robots
|
||||
@projects = Project.all_public.active
|
||||
render :layout => false, :content_type => 'text/plain'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,62 +1,37 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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'
|
||||
|
||||
# The WikiController follows the Rails REST controller pattern but with
|
||||
# a few differences
|
||||
#
|
||||
# * index - shows a list of WikiPages grouped by page or date
|
||||
# * new - not used
|
||||
# * create - not used
|
||||
# * show - will also show the form for creating a new wiki page
|
||||
# * edit - used to edit an existing or new page
|
||||
# * update - used to save a wiki page update to the database, including new pages
|
||||
# * destroy - normal
|
||||
#
|
||||
# Other member and collection methods are also used
|
||||
#
|
||||
# TODO: still being worked on
|
||||
class WikiController < ApplicationController
|
||||
default_search_scope :wiki_pages
|
||||
before_filter :find_wiki, :authorize
|
||||
before_filter :find_existing_or_new_page, :only => [:show, :edit, :update]
|
||||
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
|
||||
helper :watchers
|
||||
|
||||
# List of pages, sorted alphabetically and by parent (hierarchy)
|
||||
def index
|
||||
load_pages_for_index
|
||||
@pages_by_parent_id = @pages.group_by(&:parent_id)
|
||||
end
|
||||
|
||||
# List of page, by last update
|
||||
def date_index
|
||||
load_pages_for_index
|
||||
@pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
|
||||
end
|
||||
|
||||
include AttachmentsHelper
|
||||
|
||||
# display a page (in editing mode if it doesn't exist)
|
||||
def show
|
||||
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) && editable?
|
||||
if User.current.allowed_to?(:edit_wiki_pages, @project)
|
||||
edit
|
||||
render :action => 'edit'
|
||||
else
|
||||
@@ -70,70 +45,51 @@ class WikiController < ApplicationController
|
||||
return
|
||||
end
|
||||
@content = @page.content_for_version(params[:version])
|
||||
if User.current.allowed_to?(:export_wiki_pages, @project)
|
||||
if params[:format] == 'html'
|
||||
export = render_to_string :action => 'export', :layout => false
|
||||
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
|
||||
return
|
||||
elsif params[:format] == 'txt'
|
||||
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
|
||||
return
|
||||
end
|
||||
end
|
||||
@editable = editable?
|
||||
render :action => 'show'
|
||||
end
|
||||
|
||||
# edit an existing page or a new one
|
||||
def edit
|
||||
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
|
||||
|
||||
# To prevent StaleObjectError exception when reverting to a previous version
|
||||
@content.version = @page.content.version
|
||||
end
|
||||
|
||||
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
# Creates a new page or updates an existing one
|
||||
def update
|
||||
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 !@page.new_record? && params[:content].present? && @content.text == params[:content][:text]
|
||||
attachments = Attachment.attach_files(@page, params[:attachments])
|
||||
render_attachment_warning_if_needed(@page)
|
||||
# don't save if text wasn't changed
|
||||
redirect_to :action => 'show', :project_id => @project, :id => @page.title
|
||||
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
|
||||
@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)
|
||||
attachments = Attachment.attach_files(@page, params[:attachments])
|
||||
render_attachment_warning_if_needed(@page)
|
||||
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
|
||||
redirect_to :action => 'show', :project_id => @project, :id => @page.title
|
||||
@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
|
||||
render :action => 'edit'
|
||||
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.now[:error] = l(:notice_locking_conflict)
|
||||
render :action => 'edit'
|
||||
flash[:error] = l(:notice_locking_conflict)
|
||||
end
|
||||
|
||||
|
||||
# rename a page
|
||||
def rename
|
||||
return render_403 unless editable?
|
||||
@@ -142,22 +98,21 @@ class WikiController < ApplicationController
|
||||
@original_title = @page.pretty_title
|
||||
if request.post? && @page.update_attributes(params[:wiki_page])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'show', :project_id => @project, :id => @page.title
|
||||
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||||
end
|
||||
end
|
||||
|
||||
verify :method => :post, :only => :protect, :redirect_to => { :action => :show }
|
||||
|
||||
def protect
|
||||
@page.update_attribute :protected, params[:protected]
|
||||
redirect_to :action => 'show', :project_id => @project, :id => @page.title
|
||||
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,
|
||||
# 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,
|
||||
@@ -165,60 +120,51 @@ class WikiController < ApplicationController
|
||||
|
||||
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
|
||||
|
||||
verify :method => :delete, :only => [:destroy], :redirect_to => { :action => :show }
|
||||
# Removes a wiki page and its history
|
||||
# Children can be either set as root pages, removed or reassigned to another parent page
|
||||
|
||||
# remove a wiki page and its history
|
||||
def destroy
|
||||
return render_403 unless editable?
|
||||
|
||||
@descendants_count = @page.descendants.size
|
||||
if @descendants_count > 0
|
||||
case params[:todo]
|
||||
when 'nullify'
|
||||
# Nothing to do
|
||||
when 'destroy'
|
||||
# Removes all its descendants
|
||||
@page.descendants.each(&:destroy)
|
||||
when 'reassign'
|
||||
# Reassign children to another parent page
|
||||
reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
|
||||
return unless reassign_to
|
||||
@page.children.each do |child|
|
||||
child.update_attribute(:parent, reassign_to)
|
||||
end
|
||||
else
|
||||
@reassignable_to = @wiki.pages - @page.self_and_descendants
|
||||
return
|
||||
end
|
||||
end
|
||||
@page.destroy
|
||||
redirect_to :action => 'index', :project_id => @project
|
||||
redirect_to :action => 'special', :id => @project, :page => 'Page_index'
|
||||
end
|
||||
|
||||
# Export wiki to a single html file
|
||||
def export
|
||||
if User.current.allowed_to?(:export_wiki_pages, @project)
|
||||
# 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
|
||||
redirect_to :action => 'show', :project_id => @project, :id => nil
|
||||
# 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[:id])
|
||||
page = @wiki.find_page(params[:page])
|
||||
# page is nil when previewing a new page
|
||||
return render_403 unless page.nil? || editable?(page)
|
||||
if page
|
||||
@@ -231,41 +177,26 @@ class WikiController < ApplicationController
|
||||
|
||||
def add_attachment
|
||||
return render_403 unless editable?
|
||||
attachments = Attachment.attach_files(@page, params[:attachments])
|
||||
render_attachment_warning_if_needed(@page)
|
||||
redirect_to :action => 'show', :id => @page.title, :project_id => @project
|
||||
attach_files(@page, params[:attachments])
|
||||
redirect_to :action => 'index', :page => @page.title
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def find_wiki
|
||||
@project = Project.find(params[:project_id])
|
||||
@project = Project.find(params[:id])
|
||||
@wiki = @project.wiki
|
||||
render_404 unless @wiki
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Finds the requested page or a new page if it doesn't exist
|
||||
def find_existing_or_new_page
|
||||
@page = @wiki.find_or_new_page(params[:id])
|
||||
if @wiki.page_found_with_redirect?
|
||||
redirect_to params.update(:id => @page.title)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Finds the requested page and returns a 404 error if it doesn't exist
|
||||
def find_existing_page
|
||||
@page = @wiki.find_page(params[:id])
|
||||
if @page.nil?
|
||||
render_404
|
||||
return
|
||||
end
|
||||
if @wiki.page_found_with_redirect?
|
||||
redirect_to params.update(:id => @page.title)
|
||||
end
|
||||
@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)
|
||||
@@ -277,8 +208,4 @@ private
|
||||
extend helper unless self.instance_of?(helper)
|
||||
helper.instance_method(:initial_page_content).bind(self).call(page)
|
||||
end
|
||||
|
||||
def load_pages_for_index
|
||||
@pages = @wiki.pages.with_updated_on.all(:order => 'title', :include => {:wiki => :project})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,4 +34,11 @@ class WikisController < ApplicationController
|
||||
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
|
||||
|
||||
@@ -16,12 +16,8 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WorkflowsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
before_filter :find_roles
|
||||
before_filter :find_trackers
|
||||
|
||||
|
||||
def index
|
||||
@workflow_counts = Workflow.count_by_tracker_and_role
|
||||
end
|
||||
@@ -32,71 +28,18 @@ class WorkflowsController < ApplicationController
|
||||
|
||||
if request.post?
|
||||
Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
|
||||
(params[:issue_status] || []).each { |status_id, transitions|
|
||||
transitions.each { |new_status_id, options|
|
||||
author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
|
||||
assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
|
||||
@role.workflows.build(:tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee)
|
||||
(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
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
|
||||
if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
|
||||
@statuses = @tracker.issue_statuses
|
||||
end
|
||||
@statuses ||= IssueStatus.find(:all, :order => 'position')
|
||||
|
||||
if @tracker && @role && @statuses.any?
|
||||
workflows = Workflow.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id})
|
||||
@workflows = {}
|
||||
@workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
|
||||
@workflows['author'] = workflows.select {|w| w.author}
|
||||
@workflows['assignee'] = workflows.select {|w| w.assignee}
|
||||
end
|
||||
end
|
||||
|
||||
def copy
|
||||
|
||||
if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
|
||||
@source_tracker = nil
|
||||
else
|
||||
@source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
|
||||
end
|
||||
if params[:source_role_id].blank? || params[:source_role_id] == 'any'
|
||||
@source_role = nil
|
||||
else
|
||||
@source_role = Role.find_by_id(params[:source_role_id].to_i)
|
||||
end
|
||||
|
||||
@target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
|
||||
@target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
|
||||
|
||||
if request.post?
|
||||
if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
|
||||
flash.now[:error] = l(:error_workflow_copy_source)
|
||||
elsif @target_trackers.nil? || @target_roles.nil?
|
||||
flash.now[:error] = l(:error_workflow_copy_target)
|
||||
else
|
||||
Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_roles
|
||||
@roles = Role.find(:all, :order => 'builtin, position')
|
||||
end
|
||||
|
||||
def find_trackers
|
||||
@trackers = Tracker.find(:all, :order => 'position')
|
||||
@statuses = IssueStatus.find(:all, :order => 'position')
|
||||
end
|
||||
end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,16 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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.
|
||||
@@ -21,26 +21,14 @@ module AttachmentsHelper
|
||||
# :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)
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
return str if str.valid_encoding?
|
||||
else
|
||||
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||
end
|
||||
|
||||
begin
|
||||
Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
|
||||
rescue Iconv::InvalidEncoding
|
||||
# "UTF-8//IGNORE" is not supported on some OS
|
||||
str
|
||||
end
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
module CalendarsHelper
|
||||
def link_to_previous_month(year, month, options={})
|
||||
target_year, target_month = if month == 1
|
||||
[year - 1, 12]
|
||||
else
|
||||
[year, month - 1]
|
||||
end
|
||||
|
||||
name = if target_month == 12
|
||||
"#{month_name(target_month)} #{target_year}"
|
||||
else
|
||||
"#{month_name(target_month)}"
|
||||
end
|
||||
|
||||
link_to_month(('« ' + name), target_year, target_month, options)
|
||||
end
|
||||
|
||||
def link_to_next_month(year, month, options={})
|
||||
target_year, target_month = if month == 12
|
||||
[year + 1, 1]
|
||||
else
|
||||
[year, month + 1]
|
||||
end
|
||||
|
||||
name = if target_month == 1
|
||||
"#{month_name(target_month)} #{target_year}"
|
||||
else
|
||||
"#{month_name(target_month)}"
|
||||
end
|
||||
|
||||
link_to_month((name + ' »'), target_year, target_month, options)
|
||||
end
|
||||
|
||||
def link_to_month(link_name, year, month, options={})
|
||||
link_to_content_update(link_name, params.merge(:year => year, :month => month))
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -18,15 +18,10 @@
|
||||
module CustomFieldsHelper
|
||||
|
||||
def custom_fields_tabs
|
||||
tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural},
|
||||
{:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
|
||||
{:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
|
||||
{:name => 'VersionCustomField', :partial => 'custom_fields/index', :label => :label_version_plural},
|
||||
{:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
|
||||
{:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural},
|
||||
{:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index', :label => TimeEntryActivity::OptionName},
|
||||
{:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index', :label => IssuePriority::OptionName},
|
||||
{:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index', :label => DocumentCategory::OptionName}
|
||||
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
|
||||
|
||||
@@ -35,21 +30,20 @@ module CustomFieldsHelper
|
||||
custom_field = custom_value.custom_field
|
||||
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||||
field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||||
|
||||
field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
|
||||
case field_format.try(:edit_as)
|
||||
|
||||
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"
|
||||
hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, :id => field_id)
|
||||
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_options(custom_value.customized), custom_value.value), :id => field_id)
|
||||
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
|
||||
@@ -67,27 +61,6 @@ module CustomFieldsHelper
|
||||
def custom_field_tag_with_label(name, custom_value)
|
||||
custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
|
||||
end
|
||||
|
||||
def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil)
|
||||
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||||
field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||||
field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
|
||||
case field_format.try(:edit_as)
|
||||
when "date"
|
||||
text_field_tag(field_name, '', :id => field_id, :size => 10) +
|
||||
calendar_for(field_id)
|
||||
when "text"
|
||||
text_area_tag(field_name, '', :id => field_id, :rows => 3, :style => 'width:90%')
|
||||
when "bool"
|
||||
select_tag(field_name, options_for_select([[l(:label_no_change_option), ''],
|
||||
[l(:general_text_yes), '1'],
|
||||
[l(:general_text_no), '0']]), :id => field_id)
|
||||
when "list"
|
||||
select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values_options(projects)), :id => field_id)
|
||||
else
|
||||
text_field_tag(field_name, '', :id => field_id)
|
||||
end
|
||||
end
|
||||
|
||||
# Return a string used to display a custom value
|
||||
def show_value(custom_value)
|
||||
@@ -97,22 +70,19 @@ module CustomFieldsHelper
|
||||
|
||||
# Return a string used to display a custom value
|
||||
def format_value(value, field_format)
|
||||
Redmine::CustomFieldFormat.format_value(value, field_format) # Proxy
|
||||
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(custom_field)
|
||||
Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name)
|
||||
end
|
||||
|
||||
# Renders the custom_values in api views
|
||||
def render_api_custom_values(custom_values, api)
|
||||
api.array :custom_fields do
|
||||
custom_values.each do |custom_value|
|
||||
api.custom_field :id => custom_value.custom_field_id, :name => custom_value.custom_field.name do
|
||||
api.value custom_value.value
|
||||
end
|
||||
end
|
||||
end unless custom_values.empty?
|
||||
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,41 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 GanttHelper
|
||||
|
||||
def gantt_zoom_link(gantt, in_or_out)
|
||||
case in_or_out
|
||||
when :in
|
||||
if gantt.zoom < 4
|
||||
link_to_content_update l(:text_zoom_in),
|
||||
params.merge(gantt.params.merge(:zoom => (gantt.zoom+1))),
|
||||
:class => 'icon icon-zoom-in'
|
||||
else
|
||||
content_tag('span', l(:text_zoom_in), :class => 'icon icon-zoom-in')
|
||||
end
|
||||
|
||||
when :out
|
||||
if gantt.zoom > 1
|
||||
link_to_content_update l(:text_zoom_out),
|
||||
params.merge(gantt.params.merge(:zoom => (gantt.zoom-1))),
|
||||
:class => 'icon icon-zoom-out'
|
||||
else
|
||||
content_tag('span', l(:text_zoom_out), :class => 'icon icon-zoom-out')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,34 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 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 GroupsHelper
|
||||
# Options for the new membership projects combo-box
|
||||
def options_for_membership_project_select(user, projects)
|
||||
options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
|
||||
options << project_tree_options_for_select(projects) do |p|
|
||||
{:disabled => (user.projects.include?(p))}
|
||||
end
|
||||
options
|
||||
end
|
||||
|
||||
def group_settings_tabs
|
||||
tabs = [{:name => 'general', :partial => 'groups/general', :label => :label_general},
|
||||
{:name => 'users', :partial => 'groups/users', :label => :label_user_plural},
|
||||
{:name => 'memberships', :partial => 'groups/memberships', :label => :label_project_plural}
|
||||
]
|
||||
end
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
module IssueMovesHelper
|
||||
end
|
||||
@@ -1,191 +1,93 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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 issue_list(issues, &block)
|
||||
ancestors = []
|
||||
issues.each do |issue|
|
||||
while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
|
||||
ancestors.pop
|
||||
end
|
||||
yield issue, ancestors.size
|
||||
ancestors << issue unless issue.leaf?
|
||||
end
|
||||
end
|
||||
|
||||
# Renders a HTML/CSS tooltip
|
||||
#
|
||||
# To use, a trigger div is needed. This is a div with the class of "tooltip"
|
||||
# that contains this method wrapped in a span with the class of "tip"
|
||||
#
|
||||
# <div class="tooltip"><%= link_to_issue(issue) %>
|
||||
# <span class="tip"><%= render_issue_tooltip(issue) %></span>
|
||||
# </div>
|
||||
#
|
||||
def render_issue_tooltip(issue)
|
||||
@cached_label_status ||= l(:field_status)
|
||||
@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)
|
||||
@cached_label_project ||= l(:field_project)
|
||||
|
||||
link_to_issue(issue) + "<br /><br />" +
|
||||
"<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />" +
|
||||
"<strong>#{@cached_label_status}</strong>: #{issue.status.name}<br />" +
|
||||
|
||||
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
|
||||
|
||||
def issue_heading(issue)
|
||||
h("#{issue.tracker} ##{issue.id}")
|
||||
end
|
||||
|
||||
def render_issue_subject_with_tree(issue)
|
||||
s = ''
|
||||
ancestors = issue.root? ? [] : issue.ancestors.visible.all
|
||||
ancestors.each do |ancestor|
|
||||
s << '<div>' + content_tag('p', link_to_issue(ancestor))
|
||||
end
|
||||
s << '<div>'
|
||||
subject = h(issue.subject)
|
||||
if issue.is_private?
|
||||
subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
|
||||
end
|
||||
s << content_tag('h3', subject)
|
||||
s << '</div>' * (ancestors.size + 1)
|
||||
|
||||
# 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 render_descendants_tree(issue)
|
||||
s = '<form><table class="list issues">'
|
||||
issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
|
||||
s << content_tag('tr',
|
||||
content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
|
||||
content_tag('td', link_to_issue(child, :truncate => 60), :class => 'subject') +
|
||||
content_tag('td', h(child.status)) +
|
||||
content_tag('td', link_to_user(child.assigned_to)) +
|
||||
content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
|
||||
:class => "issue issue-#{child.id} hascontextmenu #{level > 0 ? "idnt idnt-#{level}" : nil}")
|
||||
end
|
||||
s << '</form></table>'
|
||||
s
|
||||
end
|
||||
|
||||
def render_custom_fields_rows(issue)
|
||||
return if issue.custom_field_values.empty?
|
||||
ordered_values = []
|
||||
half = (issue.custom_field_values.size / 2.0).ceil
|
||||
half.times do |i|
|
||||
ordered_values << issue.custom_field_values[i]
|
||||
ordered_values << issue.custom_field_values[i + half]
|
||||
end
|
||||
s = "<tr>\n"
|
||||
n = 0
|
||||
ordered_values.compact.each do |value|
|
||||
s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
|
||||
s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
|
||||
n += 1
|
||||
end
|
||||
s << "</tr>\n"
|
||||
s
|
||||
end
|
||||
|
||||
def issues_destroy_confirmation_message(issues)
|
||||
issues = [issues] unless issues.is_a?(Array)
|
||||
message = l(:text_issues_destroy_confirmation)
|
||||
descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
|
||||
if descendant_count > 0
|
||||
issues.each do |issue|
|
||||
next if issue.root?
|
||||
issues.each do |other_issue|
|
||||
descendant_count -= 1 if issue.is_descendant_of?(other_issue)
|
||||
end
|
||||
end
|
||||
if descendant_count > 0
|
||||
message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
|
||||
end
|
||||
end
|
||||
message
|
||||
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,
|
||||
:select => 'id, name, is_public',
|
||||
@sidebar_queries = Query.find(:all,
|
||||
:order => "name ASC",
|
||||
:conditions => visible.conditions)
|
||||
end
|
||||
@sidebar_queries
|
||||
end
|
||||
|
||||
def query_links(title, queries)
|
||||
# links to #index on issues/show
|
||||
url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
|
||||
|
||||
content_tag('h3', title) +
|
||||
queries.collect {|query|
|
||||
link_to(h(query.name), url_params.merge(:query_id => query))
|
||||
}.join('<br />')
|
||||
end
|
||||
|
||||
def render_sidebar_queries
|
||||
out = ''
|
||||
queries = sidebar_queries.select {|q| !q.is_public?}
|
||||
out << query_links(l(:label_my_queries), queries) if queries.any?
|
||||
queries = sidebar_queries.select {|q| q.is_public?}
|
||||
out << query_links(l(:label_query_plural), queries) if queries.any?
|
||||
out
|
||||
end
|
||||
|
||||
def show_detail(detail, no_html=false)
|
||||
case detail.property
|
||||
when 'attr'
|
||||
field = detail.prop_key.to_s.gsub(/\_id$/, "")
|
||||
label = l(("field_" + field).to_sym)
|
||||
case
|
||||
when ['due_date', 'start_date'].include?(detail.prop_key)
|
||||
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', 'status_id', 'tracker_id', 'assigned_to_id', 'priority_id', 'category_id', 'fixed_version_id'].include?(detail.prop_key)
|
||||
value = find_name_by_reflection(field, detail.value)
|
||||
old_value = find_name_by_reflection(field, detail.old_value)
|
||||
|
||||
when detail.prop_key == 'estimated_hours'
|
||||
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?
|
||||
|
||||
when detail.prop_key == 'parent_id'
|
||||
label = l(:field_parent_issue)
|
||||
value = "##{detail.value}" unless detail.value.blank?
|
||||
old_value = "##{detail.old_value}" unless detail.old_value.blank?
|
||||
|
||||
when detail.prop_key == 'is_private'
|
||||
value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
|
||||
old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
|
||||
end
|
||||
when 'cf'
|
||||
custom_field = CustomField.find_by_id(detail.prop_key)
|
||||
@@ -202,7 +104,7 @@ module IssuesHelper
|
||||
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
|
||||
@@ -214,62 +116,36 @@ module IssuesHelper
|
||||
value = content_tag("i", h(value)) if value
|
||||
end
|
||||
end
|
||||
|
||||
if detail.property == 'attr' && detail.prop_key == 'description'
|
||||
s = l(:text_journal_changed_no_detail, :label => label)
|
||||
unless no_html
|
||||
diff_link = link_to 'diff',
|
||||
{:controller => 'journals', :action => 'diff', :id => detail.journal_id, :detail_id => detail.id},
|
||||
:title => l(:label_view_diff)
|
||||
s << " (#{ diff_link })"
|
||||
end
|
||||
s
|
||||
elsif !detail.value.blank?
|
||||
|
||||
if !detail.value.blank?
|
||||
case detail.property
|
||||
when 'attr', 'cf'
|
||||
if !detail.old_value.blank?
|
||||
l(:text_journal_changed, :label => label, :old => old_value, :new => value)
|
||||
label + " " + l(:text_journal_changed, old_value, value)
|
||||
else
|
||||
l(:text_journal_set_to, :label => label, :value => value)
|
||||
label + " " + l(:text_journal_set_to, value)
|
||||
end
|
||||
when 'attachment'
|
||||
l(:text_journal_added, :label => label, :value => value)
|
||||
"#{label} #{value} #{l(:label_added)}"
|
||||
end
|
||||
else
|
||||
l(:text_journal_deleted, :label => label, :old => old_value)
|
||||
end
|
||||
end
|
||||
|
||||
# Find the name of an associated record stored in the field attribute
|
||||
def find_name_by_reflection(field, id)
|
||||
association = Issue.reflect_on_association(field.to_sym)
|
||||
if association
|
||||
record = association.class_name.constantize.find_by_id(id)
|
||||
return record.name if record
|
||||
end
|
||||
end
|
||||
|
||||
# Renders issue children recursively
|
||||
def render_api_issue_children(issue, api)
|
||||
return if issue.leaf?
|
||||
api.array :children do
|
||||
issue.children.each do |child|
|
||||
api.issue(:id => child.id) do
|
||||
api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
|
||||
api.subject child.subject
|
||||
render_api_issue_children(child, api)
|
||||
end
|
||||
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')
|
||||
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||
decimal_separator = l(:general_csv_decimal_separator)
|
||||
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||
export = StringIO.new
|
||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
||||
# csv header fields
|
||||
headers = [ "#",
|
||||
l(:field_status),
|
||||
l(:field_status),
|
||||
l(:field_project),
|
||||
l(:field_tracker),
|
||||
l(:field_priority),
|
||||
@@ -282,7 +158,6 @@ module IssuesHelper
|
||||
l(:field_due_date),
|
||||
l(:field_done_ratio),
|
||||
l(:field_estimated_hours),
|
||||
l(:field_parent_issue),
|
||||
l(:field_created_on),
|
||||
l(:field_updated_on)
|
||||
]
|
||||
@@ -296,9 +171,9 @@ module IssuesHelper
|
||||
# csv lines
|
||||
issues.each do |issue|
|
||||
fields = [issue.id,
|
||||
issue.status.name,
|
||||
issue.status.name,
|
||||
issue.project.name,
|
||||
issue.tracker.name,
|
||||
issue.tracker.name,
|
||||
issue.priority.name,
|
||||
issue.subject,
|
||||
issue.assigned_to,
|
||||
@@ -309,8 +184,7 @@ module IssuesHelper
|
||||
format_date(issue.due_date),
|
||||
issue.done_ratio,
|
||||
issue.estimated_hours.to_s.gsub('.', decimal_separator),
|
||||
issue.parent_id,
|
||||
format_time(issue.created_on),
|
||||
format_time(issue.created_on),
|
||||
format_time(issue.updated_on)
|
||||
]
|
||||
custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
|
||||
@@ -318,6 +192,7 @@ module IssuesHelper
|
||||
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||
end
|
||||
end
|
||||
export.rewind
|
||||
export
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module JournalsHelper
|
||||
def render_notes(issue, journal, options={})
|
||||
def render_notes(journal, options={})
|
||||
content = ''
|
||||
editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project)))
|
||||
editable = journal.editable_by?(User.current)
|
||||
links = []
|
||||
if !journal.notes.blank?
|
||||
links << link_to_remote(image_tag('comment.png'),
|
||||
{ :url => {:controller => 'journals', :action => 'new', :id => issue, :journal_id => journal} },
|
||||
{ :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 },
|
||||
@@ -30,9 +30,7 @@ module JournalsHelper
|
||||
end
|
||||
content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty?
|
||||
content << textilizable(journal, :notes)
|
||||
css_classes = "wiki"
|
||||
css_classes << " editable" if editable
|
||||
content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => css_classes)
|
||||
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={})
|
||||
|
||||
@@ -16,4 +16,13 @@
|
||||
# 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,16 +1,16 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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.
|
||||
@@ -18,9 +18,9 @@
|
||||
module ProjectsHelper
|
||||
def link_to_version(version, options = {})
|
||||
return '' unless version && version.is_a?(Version)
|
||||
link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
|
||||
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},
|
||||
@@ -29,80 +29,8 @@ module ProjectsHelper
|
||||
{: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},
|
||||
{:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
|
||||
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}
|
||||
]
|
||||
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
||||
end
|
||||
|
||||
def parent_project_select_tag(project)
|
||||
selected = project.parent
|
||||
# retrieve the requested parent project
|
||||
parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
|
||||
if parent_id
|
||||
selected = (parent_id.blank? ? nil : Project.find(parent_id))
|
||||
end
|
||||
|
||||
options = ''
|
||||
options << "<option value=''></option>" if project.allowed_parents.include?(nil)
|
||||
options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
|
||||
content_tag('select', options, :name => 'project[parent_id]', :id => 'project_parent_id')
|
||||
end
|
||||
|
||||
# Renders a tree of projects as a nested set of unordered lists
|
||||
# The given collection may be a subset of the whole project tree
|
||||
# (eg. some intermediate nodes are private and can not be seen)
|
||||
def render_project_hierarchy(projects)
|
||||
s = ''
|
||||
if projects.any?
|
||||
ancestors = []
|
||||
original_project = @project
|
||||
projects.each do |project|
|
||||
# set the project environment to please macros.
|
||||
@project = project
|
||||
if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
|
||||
s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
|
||||
else
|
||||
ancestors.pop
|
||||
s << "</li>"
|
||||
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
||||
ancestors.pop
|
||||
s << "</ul></li>\n"
|
||||
end
|
||||
end
|
||||
classes = (ancestors.empty? ? 'root' : 'child')
|
||||
s << "<li class='#{classes}'><div class='#{classes}'>" +
|
||||
link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
|
||||
s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank?
|
||||
s << "</div>\n"
|
||||
ancestors << project
|
||||
end
|
||||
s << ("</li></ul>\n" * ancestors.size)
|
||||
@project = original_project
|
||||
end
|
||||
s
|
||||
end
|
||||
|
||||
# Returns a set of options for a select field, grouped by project.
|
||||
def version_options_for_select(versions, selected=nil)
|
||||
grouped = Hash.new {|h,k| h[k] = []}
|
||||
versions.each do |version|
|
||||
grouped[version.project.name] << [version.name, version.id]
|
||||
end
|
||||
# Add in the selected
|
||||
if selected && !versions.include?(selected)
|
||||
grouped[selected.project.name] << [selected.name, selected.id]
|
||||
end
|
||||
|
||||
if grouped.keys.size > 1
|
||||
grouped_options_for_select(grouped, selected && selected.id)
|
||||
else
|
||||
options_for_select((grouped.values.first || []), selected && selected.id)
|
||||
end
|
||||
end
|
||||
|
||||
def format_version_sharing(sharing)
|
||||
sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
|
||||
l("label_version_sharing_#{sharing}")
|
||||
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -28,72 +28,33 @@ module QueriesHelper
|
||||
end
|
||||
|
||||
def column_content(column, issue)
|
||||
value = column.value(issue)
|
||||
|
||||
case value.class.name
|
||||
when 'String'
|
||||
if column.name == :subject
|
||||
link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
|
||||
else
|
||||
h(value)
|
||||
end
|
||||
when 'Time'
|
||||
format_time(value)
|
||||
when 'Date'
|
||||
format_date(value)
|
||||
when 'Fixnum', 'Float'
|
||||
if column.name == :done_ratio
|
||||
progress_bar(value, :width => '80px')
|
||||
else
|
||||
value.to_s
|
||||
end
|
||||
when 'User'
|
||||
link_to_user value
|
||||
when 'Project'
|
||||
link_to_project value
|
||||
when 'Version'
|
||||
link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
|
||||
when 'TrueClass'
|
||||
l(:general_text_Yes)
|
||||
when 'FalseClass'
|
||||
l(:general_text_No)
|
||||
when 'Issue'
|
||||
link_to_issue(value, :subject => false)
|
||||
if column.is_a?(QueryCustomFieldColumn)
|
||||
cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
|
||||
show_value(cv)
|
||||
else
|
||||
h(value)
|
||||
end
|
||||
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)
|
||||
raise ::Unauthorized unless @query.visible?
|
||||
@query.project = @project
|
||||
session[:query] = {:id => @query.id, :project_id => @query.project_id}
|
||||
sort_clear
|
||||
else
|
||||
if api_request? || 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] || params[:f]
|
||||
@query.filters = {}
|
||||
@query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
|
||||
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
|
||||
@query.available_filters.keys.each do |field|
|
||||
@query.add_short_filter(field, params[field]) if params[field]
|
||||
end
|
||||
h(value)
|
||||
end
|
||||
@query.group_by = params[:group_by]
|
||||
@query.column_names = params[:c] || (params[:query] && params[:query][:column_names])
|
||||
session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
|
||||
else
|
||||
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
|
||||
@query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
|
||||
@query.project = @project
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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 ReportsHelper
|
||||
|
||||
|
||||
def aggregate(data, criteria)
|
||||
a = 0
|
||||
data.each { |row|
|
||||
@@ -28,9 +28,9 @@ module ReportsHelper
|
||||
} unless data.nil?
|
||||
a
|
||||
end
|
||||
|
||||
|
||||
def aggregate_link(data, criteria, *args)
|
||||
a = aggregate data, criteria
|
||||
a > 0 ? link_to(a, *args) : '-'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,38 +1,33 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'iconv'
|
||||
require 'redmine/codeset_util'
|
||||
|
||||
module RepositoriesHelper
|
||||
def format_revision(revision)
|
||||
if revision.respond_to? :format_identifier
|
||||
revision.format_identifier
|
||||
else
|
||||
revision.to_s
|
||||
end
|
||||
def format_revision(txt)
|
||||
txt.to_s[0,8]
|
||||
end
|
||||
|
||||
|
||||
def truncate_at_line_break(text, length = 255)
|
||||
if text
|
||||
text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def render_properties(properties)
|
||||
unless properties.nil? || properties.empty?
|
||||
content = ''
|
||||
@@ -42,15 +37,14 @@ module RepositoriesHelper
|
||||
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'
|
||||
change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
|
||||
end
|
||||
change
|
||||
when 'D'
|
||||
@@ -59,82 +53,61 @@ module RepositoriesHelper
|
||||
change
|
||||
end
|
||||
end.compact
|
||||
|
||||
|
||||
tree = { }
|
||||
changes.each do |change|
|
||||
p = tree
|
||||
dirs = change.path.to_s.split('/').select {|d| !d.blank?}
|
||||
path = ''
|
||||
dirs.each do |dir|
|
||||
path += '/' + dir
|
||||
p[:s] ||= {}
|
||||
p = p[:s]
|
||||
p[path] ||= {}
|
||||
p = p[path]
|
||||
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'
|
||||
text = File.basename(h(file))
|
||||
if s = tree[file][:s]
|
||||
style << ' folder'
|
||||
path_param = to_path_param(@repository.relative_path(file))
|
||||
text = link_to(text, :controller => 'repositories',
|
||||
:action => 'show',
|
||||
:id => @project,
|
||||
:path => path_param,
|
||||
:rev => @changeset.identifier)
|
||||
output << "<li class='#{style}'>#{text}</li>"
|
||||
output << render_changes_tree(s)
|
||||
elsif c = tree[file][:c]
|
||||
style << " change-#{c.action}"
|
||||
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.identifier) unless c.action == 'D'
|
||||
: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.identifier) + ') ' if c.action == 'M'
|
||||
:rev => @changeset.revision) + ') ' if c.action == 'M'
|
||||
text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank?
|
||||
output << "<li class='#{style}'>#{text}</li>"
|
||||
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 str.nil?
|
||||
str = to_utf8_internal(str)
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def to_utf8_internal(str)
|
||||
return str if str.nil?
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('ASCII-8BIT')
|
||||
end
|
||||
return str if str.empty?
|
||||
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
end
|
||||
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
|
||||
@encodings.each do |encoding|
|
||||
begin
|
||||
@@ -143,142 +116,67 @@ module RepositoriesHelper
|
||||
# do nothing here and try the next encoding
|
||||
end
|
||||
end
|
||||
str = Redmine::CodesetUtil.replace_invalid_utf8(str)
|
||||
str
|
||||
end
|
||||
private :to_utf8_internal
|
||||
|
||||
def repository_field_tags(form, repository)
|
||||
|
||||
def repository_field_tags(form, repository)
|
||||
method = repository.class.name.demodulize.underscore + "_field_tags"
|
||||
if repository.is_a?(Repository) &&
|
||||
respond_to?(method) && method != 'repository_field_tags'
|
||||
send(method, form, repository)
|
||||
end
|
||||
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::Scm::Base.all.each do |scm|
|
||||
if Setting.enabled_scm.include?(scm) ||
|
||||
(repository && repository.class.name.demodulize == scm)
|
||||
scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
|
||||
end
|
||||
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',
|
||||
|
||||
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)")
|
||||
)
|
||||
: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?)) +
|
||||
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]';"))
|
||||
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 => l(:field_path_to_repository),
|
||||
:size => 60, :required => true,
|
||||
:disabled => (repository && !repository.new_record?))) +
|
||||
content_tag('p', form.select(
|
||||
:log_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_commit_logs_encoding), :required => true))
|
||||
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 => l(:field_path_to_repository),
|
||||
:size => 60, :required => true,
|
||||
:disabled => (repository && !repository.root_url.blank?)
|
||||
) +
|
||||
'<br />' + l(:text_mercurial_repository_note)) +
|
||||
content_tag('p', form.select(
|
||||
:path_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_scm_path_encoding)
|
||||
) +
|
||||
'<br />' + l(:text_scm_path_encoding_note))
|
||||
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 => l(:field_path_to_repository),
|
||||
:size => 60, :required => true,
|
||||
:disabled => (repository && !repository.root_url.blank?)
|
||||
) +
|
||||
'<br />' + l(:text_git_repository_note)) +
|
||||
content_tag('p', form.select(
|
||||
:path_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_scm_path_encoding)
|
||||
) +
|
||||
'<br />' + l(:text_scm_path_encoding_note)) +
|
||||
content_tag('p', form.check_box(
|
||||
:extra_report_last_commit,
|
||||
:label => l(:label_git_report_last_commit)
|
||||
))
|
||||
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 => l(:field_cvsroot),
|
||||
:size => 60, :required => true,
|
||||
:disabled => !repository.new_record?)) +
|
||||
content_tag('p', form.text_field(
|
||||
:url,
|
||||
:label => l(:field_cvs_module),
|
||||
:size => 30, :required => true,
|
||||
:disabled => !repository.new_record?)) +
|
||||
content_tag('p', form.select(
|
||||
:log_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_commit_logs_encoding), :required => true)) +
|
||||
content_tag('p', form.select(
|
||||
:path_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_scm_path_encoding)
|
||||
) +
|
||||
'<br />' + l(:text_scm_path_encoding_note))
|
||||
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 => l(:field_path_to_repository),
|
||||
:size => 60, :required => true,
|
||||
:disabled => (repository && !repository.new_record?))) +
|
||||
content_tag('p', form.select(
|
||||
:log_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_commit_logs_encoding), :required => true))
|
||||
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 => l(:field_root_directory),
|
||||
:size => 60, :required => true,
|
||||
:disabled => (repository && !repository.root_url.blank?))) +
|
||||
content_tag('p', form.select(
|
||||
:path_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_scm_path_encoding)
|
||||
) +
|
||||
'<br />' + l(:text_scm_path_encoding_note))
|
||||
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -27,9 +27,8 @@ module SearchHelper
|
||||
result << '...'
|
||||
break
|
||||
end
|
||||
words = words.mb_chars
|
||||
if i.even?
|
||||
result << h(words.length > 100 ? "#{words.slice(0..44)} ... #{words.slice(-45..-1)}" : words)
|
||||
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}")
|
||||
@@ -39,13 +38,13 @@ module SearchHelper
|
||||
end
|
||||
|
||||
def type_label(t)
|
||||
l("label_#{t.singularize}_plural", :default => t.to_s.humanize)
|
||||
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.descendants.active.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
|
||||
@@ -57,7 +56,7 @@ module SearchHelper
|
||||
c = results_by_type[t]
|
||||
next if c == 0
|
||||
text = "#{type_label(t)} (#{c})"
|
||||
links << link_to(text, :q => params[:q], :titles_only => params[:titles_only], :all_words => params[:all_words], :scope => params[:scope], t => 1)
|
||||
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
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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.
|
||||
@@ -18,74 +18,12 @@
|
||||
module SettingsHelper
|
||||
def administration_settings_tabs
|
||||
tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
|
||||
{:name => 'display', :partial => 'settings/display', :label => :label_display},
|
||||
{: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 => :field_mail_notification},
|
||||
{:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
|
||||
{: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
|
||||
|
||||
def setting_select(setting, choices, options={})
|
||||
if blank_text = options.delete(:blank)
|
||||
choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
|
||||
end
|
||||
setting_label(setting, options) +
|
||||
select_tag("settings[#{setting}]",
|
||||
options_for_select(choices, Setting.send(setting).to_s),
|
||||
options)
|
||||
end
|
||||
|
||||
def setting_multiselect(setting, choices, options={})
|
||||
setting_values = Setting.send(setting)
|
||||
setting_values = [] unless setting_values.is_a?(Array)
|
||||
|
||||
setting_label(setting, options) +
|
||||
hidden_field_tag("settings[#{setting}][]", '') +
|
||||
choices.collect do |choice|
|
||||
text, value = (choice.is_a?(Array) ? choice : [choice, choice])
|
||||
content_tag(
|
||||
'label',
|
||||
check_box_tag(
|
||||
"settings[#{setting}][]",
|
||||
value,
|
||||
Setting.send(setting).include?(value)
|
||||
) + text.to_s,
|
||||
:class => 'block'
|
||||
)
|
||||
end.join
|
||||
end
|
||||
|
||||
def setting_text_field(setting, options={})
|
||||
setting_label(setting, options) +
|
||||
text_field_tag("settings[#{setting}]", Setting.send(setting), options)
|
||||
end
|
||||
|
||||
def setting_text_area(setting, options={})
|
||||
setting_label(setting, options) +
|
||||
text_area_tag("settings[#{setting}]", Setting.send(setting), options)
|
||||
end
|
||||
|
||||
def setting_check_box(setting, options={})
|
||||
setting_label(setting, options) +
|
||||
hidden_field_tag("settings[#{setting}]", 0) +
|
||||
check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options)
|
||||
end
|
||||
|
||||
def setting_label(setting, options={})
|
||||
label = options.delete(:label)
|
||||
label != false ? content_tag("label", l(label || "setting_#{setting}")) : ''
|
||||
end
|
||||
|
||||
# Renders a notification field for a Redmine::Notifiable option
|
||||
def notification_field(notifiable)
|
||||
return content_tag(:label,
|
||||
check_box_tag('settings[notified_events][]',
|
||||
notifiable.name,
|
||||
Setting.notified_events.include?(notifiable.name)) +
|
||||
l_or_humanize(notifiable.name, :prefix => 'label_'),
|
||||
:class => notifiable.parent.present? ? "parent" : '')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
# Helpers to sort tables using clickable column headers.
|
||||
#
|
||||
# Author: Stuart Rackham <srackham@methods.co.nz>, March 2005.
|
||||
# Jean-Philippe Lang, 2009
|
||||
# License: This source code is released under the MIT license.
|
||||
#
|
||||
# - Consecutive clicks toggle the column's sort order.
|
||||
# - Sort state is maintained by a session hash entry.
|
||||
# - CSS classes identify sort column and state.
|
||||
# - Icon image identifies sort column and state.
|
||||
# - Typically used in conjunction with the Pagination module.
|
||||
#
|
||||
# Example code snippets:
|
||||
@@ -18,7 +17,7 @@
|
||||
#
|
||||
# def list
|
||||
# sort_init 'last_name'
|
||||
# sort_update %w(first_name last_name)
|
||||
# sort_update
|
||||
# @items = Contact.find_all nil, sort_clause
|
||||
# end
|
||||
#
|
||||
@@ -29,7 +28,7 @@
|
||||
#
|
||||
# def list
|
||||
# sort_init 'last_name'
|
||||
# sort_update %w(first_name last_name)
|
||||
# sort_update
|
||||
# @contact_pages, @items = paginate :contacts,
|
||||
# :order_by => sort_clause,
|
||||
# :per_page => 10
|
||||
@@ -46,166 +45,85 @@
|
||||
# </tr>
|
||||
# </thead>
|
||||
#
|
||||
# - Introduces instance variables: @sort_default, @sort_criteria
|
||||
# - Introduces param :sort
|
||||
# - The ascending and descending sort icon images are sort_asc.png and
|
||||
# sort_desc.png and reside in the application's images directory.
|
||||
# - Introduces instance variables: @sort_name, @sort_default.
|
||||
# - Introduces params :sort_key and :sort_order.
|
||||
#
|
||||
|
||||
module SortHelper
|
||||
class SortCriteria
|
||||
|
||||
def initialize
|
||||
@criteria = []
|
||||
end
|
||||
|
||||
def available_criteria=(criteria)
|
||||
unless criteria.is_a?(Hash)
|
||||
criteria = criteria.inject({}) {|h,k| h[k] = k; h}
|
||||
end
|
||||
@available_criteria = criteria
|
||||
end
|
||||
|
||||
def from_param(param)
|
||||
@criteria = param.to_s.split(',').collect {|s| s.split(':')[0..1]}
|
||||
normalize!
|
||||
end
|
||||
|
||||
def criteria=(arg)
|
||||
@criteria = arg
|
||||
normalize!
|
||||
end
|
||||
|
||||
def to_param
|
||||
@criteria.collect {|k,o| k + (o ? '' : ':desc')}.join(',')
|
||||
end
|
||||
|
||||
def to_sql
|
||||
sql = @criteria.collect do |k,o|
|
||||
if s = @available_criteria[k]
|
||||
(o ? s.to_a : s.to_a.collect {|c| append_desc(c)}).join(', ')
|
||||
end
|
||||
end.compact.join(', ')
|
||||
sql.blank? ? nil : sql
|
||||
end
|
||||
|
||||
def add!(key, asc)
|
||||
@criteria.delete_if {|k,o| k == key}
|
||||
@criteria = [[key, asc]] + @criteria
|
||||
normalize!
|
||||
end
|
||||
|
||||
def add(*args)
|
||||
r = self.class.new.from_param(to_param)
|
||||
r.add!(*args)
|
||||
r
|
||||
end
|
||||
|
||||
def first_key
|
||||
@criteria.first && @criteria.first.first
|
||||
end
|
||||
|
||||
def first_asc?
|
||||
@criteria.first && @criteria.first.last
|
||||
end
|
||||
|
||||
def empty?
|
||||
@criteria.empty?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def normalize!
|
||||
@criteria ||= []
|
||||
@criteria = @criteria.collect {|s| s = s.to_a; [s.first, (s.last == false || s.last == 'desc') ? false : true]}
|
||||
@criteria = @criteria.select {|k,o| @available_criteria.has_key?(k)} if @available_criteria
|
||||
@criteria.slice!(3)
|
||||
self
|
||||
end
|
||||
|
||||
# Appends DESC to the sort criterion unless it has a fixed order
|
||||
def append_desc(criterion)
|
||||
if criterion =~ / (asc|desc)$/i
|
||||
criterion
|
||||
else
|
||||
"#{criterion} DESC"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def sort_name
|
||||
controller_name + '_' + action_name + '_sort'
|
||||
end
|
||||
|
||||
# Initializes the default sort.
|
||||
# Examples:
|
||||
#
|
||||
# sort_init 'name'
|
||||
# sort_init 'id', 'desc'
|
||||
# sort_init ['name', ['id', 'desc']]
|
||||
# sort_init [['name', 'desc'], ['id', 'desc']]
|
||||
# Initializes the default sort column (default_key) and sort order
|
||||
# (default_order).
|
||||
#
|
||||
def sort_init(*args)
|
||||
case args.size
|
||||
when 1
|
||||
@sort_default = args.first.is_a?(Array) ? args.first : [[args.first]]
|
||||
when 2
|
||||
@sort_default = [[args.first, args.last]]
|
||||
else
|
||||
raise ArgumentError
|
||||
end
|
||||
# - default_key is a column attribute name.
|
||||
# - default_order is 'asc' or 'desc'.
|
||||
# - name is the name of the session hash entry that stores the sort state,
|
||||
# defaults to '<controller_name>_sort'.
|
||||
#
|
||||
def sort_init(default_key, default_order='asc', name=nil)
|
||||
@sort_name = name || params[:controller] + params[:action] + '_sort'
|
||||
@sort_default = {:key => default_key, :order => default_order}
|
||||
end
|
||||
|
||||
# Updates the sort state. Call this in the controller prior to calling
|
||||
# sort_clause.
|
||||
# - criteria can be either an array or a hash of allowed keys
|
||||
#
|
||||
def sort_update(criteria)
|
||||
@sort_criteria = SortCriteria.new
|
||||
@sort_criteria.available_criteria = criteria
|
||||
@sort_criteria.from_param(params[:sort] || session[sort_name])
|
||||
@sort_criteria.criteria = @sort_default if @sort_criteria.empty?
|
||||
session[sort_name] = @sort_criteria.to_param
|
||||
end
|
||||
|
||||
# Clears the sort criteria session data
|
||||
#
|
||||
def sort_clear
|
||||
session[sort_name] = nil
|
||||
# sort_keys can be either an array or a hash of allowed keys
|
||||
def sort_update(sort_keys)
|
||||
sort_key = params[:sort_key]
|
||||
sort_key = nil unless (sort_keys.is_a?(Array) ? sort_keys.include?(sort_key) : sort_keys[sort_key])
|
||||
|
||||
sort_order = (params[:sort_order] == 'desc' ? 'DESC' : 'ASC')
|
||||
|
||||
if sort_key
|
||||
sort = {:key => sort_key, :order => sort_order}
|
||||
elsif session[@sort_name]
|
||||
sort = session[@sort_name] # Previous sort.
|
||||
else
|
||||
sort = @sort_default
|
||||
end
|
||||
session[@sort_name] = sort
|
||||
|
||||
sort_column = (sort_keys.is_a?(Hash) ? sort_keys[sort[:key]] : sort[:key])
|
||||
@sort_clause = (sort_column.blank? ? nil : "#{sort_column} #{sort[:order]}")
|
||||
end
|
||||
|
||||
# Returns an SQL sort clause corresponding to the current sort state.
|
||||
# Use this to sort the controller's table items collection.
|
||||
#
|
||||
def sort_clause()
|
||||
@sort_criteria.to_sql
|
||||
@sort_clause
|
||||
end
|
||||
|
||||
# Returns a link which sorts by the named column.
|
||||
#
|
||||
# - column is the name of an attribute in the sorted record collection.
|
||||
# - the optional caption explicitly specifies the displayed link text.
|
||||
# - 2 CSS classes reflect the state of the link: sort and asc or desc
|
||||
# - The optional caption explicitly specifies the displayed link text.
|
||||
# - A sort icon image is positioned to the right of the sort link.
|
||||
#
|
||||
def sort_link(column, caption, default_order)
|
||||
css, order = nil, default_order
|
||||
|
||||
if column.to_s == @sort_criteria.first_key
|
||||
if @sort_criteria.first_asc?
|
||||
css = 'sort asc'
|
||||
key, order = session[@sort_name][:key], session[@sort_name][:order]
|
||||
if key == column
|
||||
if order.downcase == 'asc'
|
||||
icon = 'sort_asc.png'
|
||||
order = 'desc'
|
||||
else
|
||||
css = 'sort desc'
|
||||
icon = 'sort_desc.png'
|
||||
order = 'asc'
|
||||
end
|
||||
else
|
||||
icon = nil
|
||||
order = default_order
|
||||
end
|
||||
caption = column.to_s.humanize unless caption
|
||||
caption = titleize(Inflector::humanize(column)) unless caption
|
||||
|
||||
sort_options = { :sort => @sort_criteria.add(column.to_s, order).to_param }
|
||||
url_options = params.merge(sort_options)
|
||||
sort_options = { :sort_key => column, :sort_order => order }
|
||||
# don't reuse params if filters are present
|
||||
url_options = params.has_key?(:set_filter) ? sort_options : params.merge(sort_options)
|
||||
|
||||
# Add project_id to url_options
|
||||
url_options = url_options.merge(:project_id => params[:project_id]) if params.has_key?(:project_id)
|
||||
|
||||
link_to_content_update(caption, url_options, :class => css)
|
||||
link_to_remote(caption,
|
||||
{:update => "content", :url => url_options},
|
||||
{:href => url_for(url_options)}) +
|
||||
(icon ? nbsp(2) + image_tag(icon) : '')
|
||||
end
|
||||
|
||||
# Returns a table header <th> tag with a sort link for the named column
|
||||
@@ -221,11 +139,30 @@ module SortHelper
|
||||
#
|
||||
# <%= sort_header_tag('id', :title => 'Sort by contact ID', :width => 40) %>
|
||||
#
|
||||
# Renders:
|
||||
#
|
||||
# <th title="Sort by contact ID" width="40">
|
||||
# <a href="/contact/list?sort_order=desc&sort_key=id">Id</a>
|
||||
# <img alt="Sort_asc" src="/images/sort_asc.png" />
|
||||
# </th>
|
||||
#
|
||||
def sort_header_tag(column, options = {})
|
||||
caption = options.delete(:caption) || column.to_s.humanize
|
||||
caption = options.delete(:caption) || titleize(Inflector::humanize(column))
|
||||
default_order = options.delete(:default_order) || 'asc'
|
||||
options[:title] = l(:label_sort_by, "\"#{caption}\"") unless options[:title]
|
||||
options[:title]= l(:label_sort_by, "\"#{caption}\"") unless options[:title]
|
||||
content_tag('th', sort_link(column, caption, default_order), options)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Return n non-breaking spaces.
|
||||
def nbsp(n)
|
||||
' ' * n
|
||||
end
|
||||
|
||||
# Return capitalized title.
|
||||
def titleize(title)
|
||||
title.split.map {|w| w.capitalize }.join(' ')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -22,33 +22,14 @@ module TimelogHelper
|
||||
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
|
||||
if @issue
|
||||
if @issue.visible?
|
||||
links << link_to_issue(@issue, :subject => false)
|
||||
else
|
||||
links << "##{@issue.id}"
|
||||
end
|
||||
end
|
||||
links << link_to_issue(@issue) if @issue
|
||||
breadcrumb links
|
||||
end
|
||||
|
||||
# Returns a collection of activities for a select field. time_entry
|
||||
# is optional and will be used to check if the selected TimeEntryActivity
|
||||
# is active.
|
||||
def activity_collection_for_select_options(time_entry=nil, project=nil)
|
||||
project ||= @project
|
||||
if project.nil?
|
||||
activities = TimeEntryActivity.shared.active
|
||||
else
|
||||
activities = project.activities
|
||||
end
|
||||
|
||||
|
||||
def activity_collection_for_select_options
|
||||
activities = Enumeration::get_values('ACTI')
|
||||
collection = []
|
||||
if time_entry && time_entry.activity && !time_entry.activity.active?
|
||||
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ]
|
||||
else
|
||||
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default)
|
||||
end
|
||||
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default)
|
||||
activities.each { |a| collection << [a.name, a.id] }
|
||||
collection
|
||||
end
|
||||
@@ -57,7 +38,7 @@ module TimelogHelper
|
||||
if value.to_s.empty?
|
||||
data.select {|row| row[criteria].blank? }
|
||||
else
|
||||
data.select {|row| row[criteria].to_s == value.to_s}
|
||||
data.select {|row| row[criteria] == value}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -87,7 +68,8 @@ module TimelogHelper
|
||||
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||
decimal_separator = l(:general_csv_decimal_separator)
|
||||
custom_fields = TimeEntryCustomField.find(:all)
|
||||
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||
export = StringIO.new
|
||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
||||
# csv header fields
|
||||
headers = [l(:field_spent_on),
|
||||
l(:field_user),
|
||||
@@ -120,26 +102,17 @@ module TimelogHelper
|
||||
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)
|
||||
if value.blank?
|
||||
l(:label_none)
|
||||
elsif k = @available_criterias[criteria][:klass]
|
||||
obj = k.find_by_id(value.to_i)
|
||||
if obj.is_a?(Issue)
|
||||
obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}"
|
||||
else
|
||||
obj
|
||||
end
|
||||
else
|
||||
format_value(value, @available_criterias[criteria][:format])
|
||||
end
|
||||
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 = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||
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
|
||||
@@ -158,6 +131,7 @@ module TimelogHelper
|
||||
row << "%.2f" %total
|
||||
csv << row
|
||||
end
|
||||
export.rewind
|
||||
export
|
||||
end
|
||||
|
||||
|
||||
@@ -25,27 +25,28 @@ module UsersHelper
|
||||
end
|
||||
|
||||
# Options for the new membership projects combo-box
|
||||
def options_for_membership_project_select(user, projects)
|
||||
def projects_options_for_select(projects)
|
||||
options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
|
||||
options << project_tree_options_for_select(projects) do |p|
|
||||
{:disabled => (user.projects.include?(p))}
|
||||
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 user_mail_notification_options(user)
|
||||
user.valid_notification_options.collect {|o| [l(o.last), o.first]}
|
||||
end
|
||||
|
||||
def change_status_link(user)
|
||||
url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
|
||||
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 => :put, :class => 'icon icon-unlock'
|
||||
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 => :put, :class => 'icon icon-unlock'
|
||||
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 => :put, :class => 'icon icon-lock'
|
||||
link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,9 +54,5 @@ module UsersHelper
|
||||
tabs = [{:name => 'general', :partial => 'users/general', :label => :label_general},
|
||||
{:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural}
|
||||
]
|
||||
if Group.all.any?
|
||||
tabs.insert 1, {:name => 'groups', :partial => 'users/groups', :label => :label_group_plural}
|
||||
end
|
||||
tabs
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -17,10 +17,11 @@
|
||||
|
||||
module VersionsHelper
|
||||
|
||||
STATUS_BY_CRITERIAS = %w(category tracker status priority author assigned_to)
|
||||
STATUS_BY_CRITERIAS = %w(category tracker priority author assigned_to)
|
||||
|
||||
def render_issue_status_by(version, criteria)
|
||||
criteria = 'category' unless STATUS_BY_CRITERIAS.include?(criteria)
|
||||
criteria ||= 'category'
|
||||
raise 'Unknown criteria' unless STATUS_BY_CRITERIAS.include?(criteria)
|
||||
|
||||
h = Hash.new {|k,v| k[v] = [0, 0]}
|
||||
begin
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -16,9 +16,8 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module WatchersHelper
|
||||
|
||||
def watcher_tag(object, user, options={})
|
||||
content_tag("span", watcher_link(object, user), :class => watcher_css(object))
|
||||
def watcher_tag(object, user)
|
||||
content_tag("span", watcher_link(object, user), :id => 'watcher')
|
||||
end
|
||||
|
||||
def watcher_link(object, user)
|
||||
@@ -27,7 +26,7 @@ module WatchersHelper
|
||||
url = {:controller => 'watchers',
|
||||
:action => (watched ? 'unwatch' : 'watch'),
|
||||
:object_type => object.class.to_s.underscore,
|
||||
:object_id => object.id}
|
||||
:object_id => object.id}
|
||||
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
|
||||
{:url => url},
|
||||
:href => url_for(url),
|
||||
@@ -35,30 +34,8 @@ module WatchersHelper
|
||||
|
||||
end
|
||||
|
||||
# Returns the css class used to identify watch links for a given +object+
|
||||
def watcher_css(object)
|
||||
"#{object.class.to_s.underscore}-#{object.id}-watcher"
|
||||
end
|
||||
|
||||
# Returns a comma separated list of users watching the given object
|
||||
def watchers_list(object)
|
||||
remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
|
||||
lis = object.watcher_users.collect do |user|
|
||||
s = avatar(user, :size => "16").to_s + link_to_user(user, :class => 'user').to_s
|
||||
if remove_allowed
|
||||
url = {:controller => 'watchers',
|
||||
:action => 'destroy',
|
||||
:object_type => object.class.to_s.underscore,
|
||||
:object_id => object.id,
|
||||
:user_id => user}
|
||||
s += ' ' + link_to_remote(image_tag('delete.png'),
|
||||
{:url => url},
|
||||
:href => url_for(url),
|
||||
:style => "vertical-align: middle",
|
||||
:class => "delete")
|
||||
end
|
||||
"<li>#{ s }</li>"
|
||||
end
|
||||
lis.empty? ? "" : "<ul>#{ lis.join("\n") }</ul>"
|
||||
object.watcher_users.collect {|u| content_tag('span', link_to_user(u), :class => 'user') }.join(",\n")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -17,19 +17,40 @@
|
||||
|
||||
module WikiHelper
|
||||
|
||||
def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
|
||||
pages = pages.group_by(&:parent) unless pages.is_a?(Hash)
|
||||
s = ''
|
||||
if pages.has_key?(parent)
|
||||
pages[parent].each do |page|
|
||||
attrs = "value='#{page.id}'"
|
||||
attrs << " selected='selected'" if selected == page
|
||||
indent = (level > 0) ? (' ' * level * 2 + '» ') : nil
|
||||
|
||||
s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" +
|
||||
wiki_page_options_for_select(pages, selected, page, level + 1)
|
||||
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
|
||||
s
|
||||
simple_format_without_paragraph(words.join(' '))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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.
|
||||
@@ -20,7 +20,7 @@ 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
|
||||
@@ -31,24 +31,22 @@ class Attachment < ActiveRecord::Base
|
||||
acts_as_activity_provider :type => 'files',
|
||||
:permission => :view_files,
|
||||
:author_key => :author_id,
|
||||
:find_options => {:select => "#{Attachment.table_name}.*",
|
||||
: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}.*",
|
||||
: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 = Redmine::Configuration['attachments_storage_path'] || "#{RAILS_ROOT}/files"
|
||||
|
||||
@@storage_path = "#{RAILS_ROOT}/files"
|
||||
|
||||
def validate
|
||||
if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
||||
errors.add(:base, :too_long, :count => Setting.attachment_max_size.to_i.kilobytes)
|
||||
end
|
||||
errors.add_to_base :too_long if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
||||
end
|
||||
|
||||
def file=(incoming_file)
|
||||
@@ -58,9 +56,6 @@ class Attachment < ActiveRecord::Base
|
||||
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
|
||||
if content_type.blank?
|
||||
self.content_type = Redmine::MimeType.of(filename)
|
||||
end
|
||||
self.filesize = @temp_file.size
|
||||
end
|
||||
end
|
||||
@@ -76,7 +71,7 @@ class Attachment < ActiveRecord::Base
|
||||
if @temp_file && (@temp_file.size > 0)
|
||||
logger.debug("saving '#{self.diskfile}'")
|
||||
md5 = Digest::MD5.new
|
||||
File.open(diskfile, "wb") do |f|
|
||||
File.open(diskfile, "wb") do |f|
|
||||
buffer = ""
|
||||
while (buffer = @temp_file.read(8192))
|
||||
f.write(buffer)
|
||||
@@ -100,7 +95,7 @@ class Attachment < ActiveRecord::Base
|
||||
def diskfile
|
||||
"#{@@storage_path}/#{self.disk_filename}"
|
||||
end
|
||||
|
||||
|
||||
def increment_download
|
||||
increment!(:downloads)
|
||||
end
|
||||
@@ -108,84 +103,48 @@ class Attachment < ActiveRecord::Base
|
||||
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
|
||||
|
||||
# Returns true if the file is readable
|
||||
def readable?
|
||||
File.readable?(diskfile)
|
||||
end
|
||||
|
||||
# Bulk attaches a set of files to an object
|
||||
#
|
||||
# Returns a Hash of the results:
|
||||
# :files => array of the attached files
|
||||
# :unsaved => array of the files that could not be attached
|
||||
def self.attach_files(obj, attachments)
|
||||
attached = []
|
||||
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)
|
||||
|
||||
if a.new_record?
|
||||
obj.unsaved_attachments ||= []
|
||||
obj.unsaved_attachments << a
|
||||
else
|
||||
attached << a
|
||||
end
|
||||
end
|
||||
end
|
||||
{:files => attached, :unsaved => obj.unsaved_attachments}
|
||||
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('\\\\', '/'))
|
||||
# INCORRECT: just_filename = File.basename(value.gsub('\\\\', '/'))
|
||||
|
||||
# Finally, replace all non alphanumeric, hyphens or periods with underscore
|
||||
@filename = just_filename.gsub(/[^\w\.\-]/,'_')
|
||||
@filename = just_filename.gsub(/[^\w\.\-]/,'_')
|
||||
end
|
||||
|
||||
|
||||
# Returns an ASCII or hashed filename
|
||||
def self.disk_filename(filename)
|
||||
timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
|
||||
ascii = ''
|
||||
df = DateTime.now.strftime("%y%m%d%H%M%S") + "_"
|
||||
if filename =~ %r{^[a-zA-Z0-9_\.\-]*$}
|
||||
ascii = filename
|
||||
df << filename
|
||||
else
|
||||
ascii = Digest::MD5.hexdigest(filename)
|
||||
df << Digest::MD5.hexdigest(filename)
|
||||
# keep the extension if any
|
||||
ascii << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
|
||||
df << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
|
||||
end
|
||||
while File.exist?(File.join(@@storage_path, "#{timestamp}_#{ascii}"))
|
||||
timestamp.succ!
|
||||
end
|
||||
"#{timestamp}_#{ascii}"
|
||||
df
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AuthSource < ActiveRecord::Base
|
||||
include Redmine::Ciphering
|
||||
|
||||
has_many :users
|
||||
|
||||
validates_presence_of :name
|
||||
@@ -33,23 +31,6 @@ class AuthSource < ActiveRecord::Base
|
||||
def auth_method_name
|
||||
"Abstract"
|
||||
end
|
||||
|
||||
def account_password
|
||||
read_ciphered_attribute(:account_password)
|
||||
end
|
||||
|
||||
def account_password=(arg)
|
||||
write_ciphered_attribute(:account_password, arg)
|
||||
end
|
||||
|
||||
def allow_password_changes?
|
||||
self.class.allow_password_changes?
|
||||
end
|
||||
|
||||
# Does this auth source backend allow password changes?
|
||||
def self.allow_password_changes?
|
||||
false
|
||||
end
|
||||
|
||||
# Try to authenticate a user not yet registered against available sources
|
||||
def self.authenticate(login, password)
|
||||
|
||||
@@ -20,8 +20,8 @@ require 'iconv'
|
||||
|
||||
class AuthSourceLdap < AuthSource
|
||||
validates_presence_of :host, :port, :attr_login
|
||||
validates_length_of :name, :host, :maximum => 60, :allow_nil => true
|
||||
validates_length_of :account, :account_password, :base_dn, :maximum => 255, :allow_nil => true
|
||||
validates_length_of :name, :host, :account_password, :maximum => 60, :allow_nil => true
|
||||
validates_length_of :account, :base_dn, :maximum => 255, :allow_nil => true
|
||||
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
|
||||
validates_numericality_of :port, :only_integer => true
|
||||
|
||||
@@ -33,12 +33,30 @@ class AuthSourceLdap < AuthSource
|
||||
|
||||
def authenticate(login, password)
|
||||
return nil if login.blank? || password.blank?
|
||||
attrs = get_user_dn(login)
|
||||
|
||||
if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password)
|
||||
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
|
||||
return attrs.except(:dn)
|
||||
attrs = []
|
||||
# get user's DN
|
||||
ldap_con = initialize_ldap_con(self.account, self.account_password)
|
||||
login_filter = Net::LDAP::Filter.eq( self.attr_login, login )
|
||||
object_filter = Net::LDAP::Filter.eq( "objectClass", "*" )
|
||||
dn = String.new
|
||||
ldap_con.search( :base => self.base_dn,
|
||||
:filter => object_filter & login_filter,
|
||||
# only ask for the DN if on-the-fly registration is disabled
|
||||
:attributes=> (onthefly_register? ? ['dn', self.attr_firstname, self.attr_lastname, self.attr_mail] : ['dn'])) do |entry|
|
||||
dn = entry.dn
|
||||
attrs = [:firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
|
||||
:lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
|
||||
:mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
|
||||
:auth_source_id => self.id ] if onthefly_register?
|
||||
end
|
||||
return nil if dn.empty?
|
||||
logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug?
|
||||
# authenticate user
|
||||
ldap_con = initialize_ldap_con(dn, password)
|
||||
return nil unless ldap_con.bind
|
||||
# return user's attributes
|
||||
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
|
||||
attrs
|
||||
rescue Net::LDAP::LdapError => text
|
||||
raise "LdapError: " + text
|
||||
end
|
||||
@@ -71,56 +89,6 @@ class AuthSourceLdap < AuthSource
|
||||
options.merge!(:auth => { :method => :simple, :username => ldap_user, :password => ldap_password }) unless ldap_user.blank? && ldap_password.blank?
|
||||
Net::LDAP.new options
|
||||
end
|
||||
|
||||
def get_user_attributes_from_ldap_entry(entry)
|
||||
{
|
||||
:dn => entry.dn,
|
||||
:firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
|
||||
:lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
|
||||
:mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
|
||||
:auth_source_id => self.id
|
||||
}
|
||||
end
|
||||
|
||||
# Return the attributes needed for the LDAP search. It will only
|
||||
# include the user attributes if on-the-fly registration is enabled
|
||||
def search_attributes
|
||||
if onthefly_register?
|
||||
['dn', self.attr_firstname, self.attr_lastname, self.attr_mail]
|
||||
else
|
||||
['dn']
|
||||
end
|
||||
end
|
||||
|
||||
# Check if a DN (user record) authenticates with the password
|
||||
def authenticate_dn(dn, password)
|
||||
if dn.present? && password.present?
|
||||
initialize_ldap_con(dn, password).bind
|
||||
end
|
||||
end
|
||||
|
||||
# Get the user's dn and any attributes for them, given their login
|
||||
def get_user_dn(login)
|
||||
ldap_con = initialize_ldap_con(self.account, self.account_password)
|
||||
login_filter = Net::LDAP::Filter.eq( self.attr_login, login )
|
||||
object_filter = Net::LDAP::Filter.eq( "objectClass", "*" )
|
||||
attrs = {}
|
||||
|
||||
ldap_con.search( :base => self.base_dn,
|
||||
:filter => object_filter & login_filter,
|
||||
:attributes=> search_attributes) do |entry|
|
||||
|
||||
if onthefly_register?
|
||||
attrs = get_user_attributes_from_ldap_entry(entry)
|
||||
else
|
||||
attrs = {:dn => entry.dn}
|
||||
end
|
||||
|
||||
logger.debug "DN found for #{login}: #{attrs[:dn]}" if logger && logger.debug?
|
||||
end
|
||||
|
||||
attrs
|
||||
end
|
||||
|
||||
def self.get_attr(entry, attr_name)
|
||||
if !attr_name.blank?
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
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 => :destroy, :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
|
||||
@@ -26,25 +26,4 @@ class Board < ActiveRecord::Base
|
||||
validates_presence_of :name, :description
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_length_of :description, :maximum => 255
|
||||
|
||||
def visible?(user=User.current)
|
||||
!user.nil? && user.allowed_to?(:view_messages, project)
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
def reset_counters!
|
||||
self.class.reset_counters!(id)
|
||||
end
|
||||
|
||||
# Updates topics_count, messages_count and last_message_id attributes for +board_id+
|
||||
def self.reset_counters!(board_id)
|
||||
board_id = board_id.to_i
|
||||
update_all("topics_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id} AND parent_id IS NULL)," +
|
||||
" messages_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id})," +
|
||||
" last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=#{board_id})",
|
||||
["id = ?", board_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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
|
||||
before_save :init_path
|
||||
|
||||
|
||||
def relative_path
|
||||
changeset.repository.relative_path(path)
|
||||
end
|
||||
|
||||
def before_validation
|
||||
self.path = Redmine::CodesetUtil.replace_invalid_utf8(self.path)
|
||||
self.from_path = Redmine::CodesetUtil.replace_invalid_utf8(self.from_path)
|
||||
end
|
||||
|
||||
def init_path
|
||||
self.path ||= ""
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# 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.
|
||||
@@ -23,268 +23,132 @@ class Changeset < ActiveRecord::Base
|
||||
has_many :changes, :dependent => :delete_all
|
||||
has_and_belongs_to_many :issues
|
||||
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.format_identifier}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments))},
|
||||
:description => :long_comments,
|
||||
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, :rev => o.identifier}}
|
||||
|
||||
: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 => [:user, {:repository => :project}]}
|
||||
|
||||
: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
|
||||
|
||||
named_scope :visible, lambda {|*args| { :include => {:repository => :project},
|
||||
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args) } }
|
||||
|
||||
|
||||
def revision=(r)
|
||||
write_attribute :revision, (r.nil? ? nil : r.to_s)
|
||||
end
|
||||
|
||||
# Returns the identifier of this changeset; depending on repository backends
|
||||
def identifier
|
||||
if repository.class.respond_to? :changeset_identifier
|
||||
repository.class.changeset_identifier self
|
||||
else
|
||||
revision.to_s
|
||||
end
|
||||
|
||||
def comments=(comment)
|
||||
write_attribute(:comments, Changeset.normalize_comments(comment))
|
||||
end
|
||||
|
||||
def committed_on=(date)
|
||||
self.commit_date = date
|
||||
super
|
||||
end
|
||||
|
||||
# Returns the readable identifier
|
||||
def format_identifier
|
||||
if repository.class.respond_to? :format_changeset_identifier
|
||||
repository.class.format_changeset_identifier self
|
||||
else
|
||||
identifier
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def project
|
||||
repository.project
|
||||
end
|
||||
|
||||
|
||||
def author
|
||||
user || committer.to_s.split('<').first
|
||||
end
|
||||
|
||||
|
||||
def before_create
|
||||
self.committer = self.class.to_utf8(self.committer, repository.repo_log_encoding)
|
||||
self.comments = self.class.normalize_comments(
|
||||
self.comments, repository.repo_log_encoding)
|
||||
self.user = repository.find_committer_user(self.committer)
|
||||
self.user = repository.find_committer_user(committer)
|
||||
end
|
||||
|
||||
|
||||
def after_create
|
||||
scan_comment_for_issue_ids
|
||||
end
|
||||
|
||||
TIMELOG_RE = /
|
||||
(
|
||||
((\d+)(h|hours?))((\d+)(m|min)?)?
|
||||
|
|
||||
((\d+)(h|hours?|m|min))
|
||||
|
|
||||
(\d+):(\d+)
|
||||
|
|
||||
(\d+([\.,]\d+)?)h?
|
||||
)
|
||||
/x
|
||||
|
||||
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)
|
||||
ref_keywords_any = ref_keywords.delete('*')
|
||||
# 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 = []
|
||||
|
||||
comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
|
||||
action, refs = match[2], match[3]
|
||||
next unless action.present? || ref_keywords_any
|
||||
|
||||
refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
|
||||
issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
|
||||
if issue
|
||||
referenced_issues << issue
|
||||
fix_issue(issue) if fix_keywords.include?(action.to_s.downcase)
|
||||
log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
|
||||
|
||||
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
|
||||
|
||||
referenced_issues.uniq!
|
||||
self.issues = referenced_issues unless referenced_issues.empty?
|
||||
|
||||
self.issues = referenced_issues.uniq
|
||||
end
|
||||
|
||||
def short_comments
|
||||
@short_comments || split_comments.first
|
||||
end
|
||||
|
||||
def long_comments
|
||||
@long_comments || split_comments.last
|
||||
end
|
||||
|
||||
def text_tag
|
||||
if scmid?
|
||||
"commit:#{scmid}"
|
||||
else
|
||||
"r#{revision}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Returns the previous changeset
|
||||
def previous
|
||||
@previous ||= Changeset.find(:first,
|
||||
:conditions => ['id < ? AND repository_id = ?',
|
||||
self.id, self.repository_id],
|
||||
:order => 'id DESC')
|
||||
@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')
|
||||
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
|
||||
end
|
||||
|
||||
# Creates a new Change from it's common parameters
|
||||
def create_change(change)
|
||||
Change.create(:changeset => self,
|
||||
:action => change[:action],
|
||||
:path => change[:path],
|
||||
:from_path => change[:from_path],
|
||||
:from_revision => change[:from_revision])
|
||||
|
||||
# Strips and reencodes a commit log before insertion into the database
|
||||
def self.normalize_comments(str)
|
||||
to_utf8(str.to_s.strip)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
# Finds an issue that can be referenced by the commit message
|
||||
# i.e. an issue that belong to the repository project, a subproject or a parent project
|
||||
def find_referenced_issue_by_id(id)
|
||||
return nil if id.blank?
|
||||
issue = Issue.find_by_id(id.to_i, :include => :project)
|
||||
if issue
|
||||
unless issue.project &&
|
||||
(project == issue.project || project.is_ancestor_of?(issue.project) ||
|
||||
project.is_descendant_of?(issue.project))
|
||||
issue = nil
|
||||
end
|
||||
end
|
||||
issue
|
||||
end
|
||||
|
||||
def fix_issue(issue)
|
||||
status = IssueStatus.find_by_id(Setting.commit_fix_status_id.to_i)
|
||||
if status.nil?
|
||||
logger.warn("No status matches commit_fix_status_id setting (#{Setting.commit_fix_status_id})") if logger
|
||||
return issue
|
||||
end
|
||||
|
||||
# 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
|
||||
return if issue.status && issue.status.is_closed?
|
||||
|
||||
journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, text_tag))
|
||||
issue.status = status
|
||||
unless Setting.commit_fix_done_ratio.blank?
|
||||
issue.done_ratio = Setting.commit_fix_done_ratio.to_i
|
||||
end
|
||||
Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,
|
||||
{ :changeset => self, :issue => issue })
|
||||
unless issue.save
|
||||
logger.warn("Issue ##{issue.id} could not be saved by changeset #{id}: #{issue.errors.full_messages}") if logger
|
||||
end
|
||||
issue
|
||||
end
|
||||
|
||||
def log_time(issue, hours)
|
||||
time_entry = TimeEntry.new(
|
||||
:user => user,
|
||||
:hours => hours,
|
||||
:issue => issue,
|
||||
:spent_on => commit_date,
|
||||
:comments => l(:text_time_logged_by_changeset, :value => text_tag,
|
||||
:locale => Setting.default_language)
|
||||
)
|
||||
time_entry.activity = log_time_activity unless log_time_activity.nil?
|
||||
|
||||
unless time_entry.save
|
||||
logger.warn("TimeEntry could not be created by changeset #{id}: #{time_entry.errors.full_messages}") if logger
|
||||
end
|
||||
time_entry
|
||||
end
|
||||
|
||||
def log_time_activity
|
||||
if Setting.commit_logtime_activity_id.to_i > 0
|
||||
TimeEntryActivity.find_by_id(Setting.commit_logtime_activity_id.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
def split_comments
|
||||
comments =~ /\A(.+?)\r?\n(.*)$/m
|
||||
@short_comments = $1 || comments
|
||||
@long_comments = $2.to_s.strip
|
||||
return @short_comments, @long_comments
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
# Strips and reencodes a commit log before insertion into the database
|
||||
def self.normalize_comments(str, encoding)
|
||||
Changeset.to_utf8(str.to_s.strip, encoding)
|
||||
end
|
||||
|
||||
def self.to_utf8(str, encoding)
|
||||
return str if str.nil?
|
||||
str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
|
||||
if str.empty?
|
||||
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
|
||||
return str
|
||||
end
|
||||
enc = encoding.blank? ? "UTF-8" : encoding
|
||||
if str.respond_to?(:force_encoding)
|
||||
if enc.upcase != "UTF-8"
|
||||
str.force_encoding(enc)
|
||||
str = str.encode("UTF-8", :invalid => :replace,
|
||||
:undef => :replace, :replace => '?')
|
||||
else
|
||||
str.force_encoding("UTF-8")
|
||||
if ! str.valid_encoding?
|
||||
str = str.encode("US-ASCII", :invalid => :replace,
|
||||
:undef => :replace, :replace => '?').encode("UTF-8")
|
||||
end
|
||||
end
|
||||
else
|
||||
ic = Iconv.new('UTF-8', enc)
|
||||
txtar = ""
|
||||
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
|
||||
txtar += ic.iconv(str)
|
||||
rescue Iconv::IllegalSequence
|
||||
txtar += $!.success
|
||||
str = '?' + $!.failed[1,$!.failed.length]
|
||||
retry
|
||||
rescue
|
||||
txtar += $!.success
|
||||
return Iconv.conv('UTF-8', encoding, str)
|
||||
rescue Iconv::Failure
|
||||
# do nothing here
|
||||
end
|
||||
str = txtar
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 CommentObserver < ActiveRecord::Observer
|
||||
def after_create(comment)
|
||||
if comment.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added')
|
||||
Mailer.deliver_news_comment_added(comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -20,10 +20,20 @@ class CustomField < ActiveRecord::Base
|
||||
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_inclusion_of :field_format, :in => Redmine::CustomFieldFormat.available_formats
|
||||
validates_format_of :name, :with => /^[\w\s\.\'\-]*$/i
|
||||
validates_inclusion_of :field_format, :in => FIELD_FORMATS.keys
|
||||
|
||||
def initialize(attributes = nil)
|
||||
super
|
||||
@@ -31,6 +41,8 @@ class CustomField < ActiveRecord::Base
|
||||
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
|
||||
@@ -38,116 +50,20 @@ class CustomField < ActiveRecord::Base
|
||||
|
||||
def validate
|
||||
if self.field_format == "list"
|
||||
errors.add(:possible_values, :blank) if self.possible_values.nil? || self.possible_values.empty?
|
||||
errors.add(:possible_values, :invalid) unless self.possible_values.is_a? Array
|
||||
end
|
||||
|
||||
if regexp.present?
|
||||
begin
|
||||
Regexp.new(regexp)
|
||||
rescue
|
||||
errors.add(:regexp, :invalid)
|
||||
end
|
||||
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, :invalid) unless v.valid?
|
||||
end
|
||||
|
||||
def possible_values_options(obj=nil)
|
||||
case field_format
|
||||
when 'user', 'version'
|
||||
if obj.respond_to?(:project) && obj.project
|
||||
case field_format
|
||||
when 'user'
|
||||
obj.project.users.sort.collect {|u| [u.to_s, u.id.to_s]}
|
||||
when 'version'
|
||||
obj.project.shared_versions.sort.collect {|u| [u.to_s, u.id.to_s]}
|
||||
end
|
||||
elsif obj.is_a?(Array)
|
||||
obj.collect {|o| possible_values_options(o)}.inject {|memo, v| memo & v}
|
||||
else
|
||||
[]
|
||||
end
|
||||
else
|
||||
read_attribute :possible_values
|
||||
end
|
||||
end
|
||||
|
||||
def possible_values(obj=nil)
|
||||
case field_format
|
||||
when 'user', 'version'
|
||||
possible_values_options(obj).collect(&:last)
|
||||
else
|
||||
read_attribute :possible_values
|
||||
end
|
||||
end
|
||||
|
||||
# Makes possible_values accept a multiline string
|
||||
def possible_values=(arg)
|
||||
if arg.is_a?(Array)
|
||||
write_attribute(:possible_values, arg.compact.collect(&:strip).select {|v| !v.blank?})
|
||||
else
|
||||
self.possible_values = arg.to_s.split(/[\n\r]+/)
|
||||
end
|
||||
end
|
||||
|
||||
def cast_value(value)
|
||||
casted = nil
|
||||
unless value.blank?
|
||||
case field_format
|
||||
when 'string', 'text', 'list'
|
||||
casted = value
|
||||
when 'date'
|
||||
casted = begin; value.to_date; rescue; nil end
|
||||
when 'bool'
|
||||
casted = (value == '1' ? true : false)
|
||||
when 'int'
|
||||
casted = value.to_i
|
||||
when 'float'
|
||||
casted = value.to_f
|
||||
when 'user', 'version'
|
||||
casted = (value.blank? ? nil : field_format.classify.constantize.find_by_id(value.to_i))
|
||||
end
|
||||
end
|
||||
casted
|
||||
end
|
||||
|
||||
# Returns a ORDER BY clause that can used to sort customized
|
||||
# objects by their value of the custom field.
|
||||
# Returns false, if the custom field can not be used for sorting.
|
||||
def order_statement
|
||||
case field_format
|
||||
when 'string', 'text', 'list', 'date', 'bool'
|
||||
# COALESCE is here to make sure that blank and NULL values are sorted equally
|
||||
"COALESCE((SELECT cv_sort.value FROM #{CustomValue.table_name} cv_sort" +
|
||||
" WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" +
|
||||
" AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" +
|
||||
" AND cv_sort.custom_field_id=#{id} LIMIT 1), '')"
|
||||
when 'int', 'float'
|
||||
# Make the database cast values into numeric
|
||||
# Postgresql will raise an error if a value can not be casted!
|
||||
# CustomValue validations should ensure that it doesn't occur
|
||||
"(SELECT CAST(cv_sort.value AS decimal(60,3)) FROM #{CustomValue.table_name} cv_sort" +
|
||||
" WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" +
|
||||
" AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" +
|
||||
" AND cv_sort.custom_field_id=#{id} AND cv_sort.value <> '' AND cv_sort.value IS NOT NULL LIMIT 1)"
|
||||
else
|
||||
nil
|
||||
end
|
||||
errors.add(:default_value, :activerecord_error_invalid) unless v.valid?
|
||||
end
|
||||
|
||||
def <=>(field)
|
||||
position <=> field.position
|
||||
end
|
||||
|
||||
def self.customized_class
|
||||
self.name =~ /^(.+)CustomField$/
|
||||
begin; $1.constantize; rescue nil; end
|
||||
end
|
||||
|
||||
# to move in project_custom_field
|
||||
def self.for_all
|
||||
find(:all, :conditions => ["is_for_all=?", true], :order => 'position')
|
||||
|
||||
@@ -20,7 +20,7 @@ class CustomValue < ActiveRecord::Base
|
||||
belongs_to :customized, :polymorphic => true
|
||||
|
||||
def after_initialize
|
||||
if new_record? && custom_field && (customized_type.blank? || (customized && customized.new_record?))
|
||||
if custom_field && new_record? && (customized_type.blank? || (customized && customized.new_record?))
|
||||
self.value ||= custom_field.default_value
|
||||
end
|
||||
end
|
||||
@@ -30,41 +30,25 @@ class CustomValue < ActiveRecord::Base
|
||||
self.value == '1'
|
||||
end
|
||||
|
||||
def editable?
|
||||
custom_field.editable?
|
||||
end
|
||||
|
||||
def visible?
|
||||
custom_field.visible?
|
||||
end
|
||||
|
||||
def required?
|
||||
custom_field.is_required?
|
||||
end
|
||||
|
||||
def to_s
|
||||
value.to_s
|
||||
end
|
||||
|
||||
protected
|
||||
def validate
|
||||
if value.blank?
|
||||
errors.add(:value, :blank) if custom_field.is_required? and value.blank?
|
||||
errors.add(:value, :activerecord_error_blank) if custom_field.is_required? and value.blank?
|
||||
else
|
||||
errors.add(:value, :invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
|
||||
errors.add(:value, :too_short, :count => custom_field.min_length) if custom_field.min_length > 0 and value.length < custom_field.min_length
|
||||
errors.add(:value, :too_long, :count => custom_field.max_length) if custom_field.max_length > 0 and value.length > custom_field.max_length
|
||||
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, :not_a_number) unless value =~ /^[+-]?\d+$/
|
||||
errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[+-]?\d+$/
|
||||
when 'float'
|
||||
begin; Kernel.Float(value); rescue; errors.add(:value, :invalid) end
|
||||
begin; Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end
|
||||
when 'date'
|
||||
errors.add(:value, :not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ && begin; value.to_date; rescue; false end
|
||||
errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/
|
||||
when 'list'
|
||||
errors.add(:value, :inclusion) unless custom_field.possible_values.include?(value)
|
||||
errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include?(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
# RedMine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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 => "DocumentCategory", :foreign_key => "category_id"
|
||||
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
|
||||
@@ -25,28 +25,13 @@ class Document < ActiveRecord::Base
|
||||
: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
|
||||
|
||||
named_scope :visible, lambda {|*args| { :include => :project,
|
||||
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_documents, *args) } }
|
||||
|
||||
def visible?(user=User.current)
|
||||
!user.nil? && user.allowed_to?(:view_documents, project)
|
||||
end
|
||||
|
||||
|
||||
def after_initialize
|
||||
if new_record?
|
||||
self.category ||= DocumentCategory.default
|
||||
self.category ||= Enumeration.default('DCAT')
|
||||
end
|
||||
end
|
||||
|
||||
def updated_on
|
||||
unless @updated_on
|
||||
a = attachments.find(:first, :order => 'created_on DESC')
|
||||
@updated_on = (a && a.created_on) || created_on
|
||||
end
|
||||
@updated_on
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 DocumentCategory < Enumeration
|
||||
has_many :documents, :foreign_key => 'category_id'
|
||||
|
||||
OptionName = :enumeration_doc_categories
|
||||
|
||||
def option_name
|
||||
OptionName
|
||||
end
|
||||
|
||||
def objects_count
|
||||
documents.count
|
||||
end
|
||||
|
||||
def transfer_relations(to)
|
||||
documents.update_all("category_id = #{to.id}")
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 DocumentCategoryCustomField < CustomField
|
||||
def type_name
|
||||
:enumeration_doc_categories
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 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 DocumentObserver < ActiveRecord::Observer
|
||||
def after_create(document)
|
||||
Mailer.deliver_document_added(document) if Setting.notified_events.include?('document_added')
|
||||
end
|
||||
end
|
||||
@@ -1,38 +1,23 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# 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 EnabledModule < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name, :scope => :project_id
|
||||
|
||||
after_create :module_enabled
|
||||
|
||||
private
|
||||
|
||||
# after_create callback used to do things when a module is enabled
|
||||
def module_enabled
|
||||
case name
|
||||
when 'wiki'
|
||||
# Create a wiki with a default start page
|
||||
if project && project.wiki.nil?
|
||||
Wiki.create(:project => project, :start_page => 'Wiki')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,60 +16,46 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class Enumeration < ActiveRecord::Base
|
||||
default_scope :order => "#{Enumeration.table_name}.position ASC"
|
||||
|
||||
belongs_to :project
|
||||
|
||||
acts_as_list :scope => 'type = \'#{type}\''
|
||||
acts_as_customizable
|
||||
acts_as_tree :order => 'position ASC'
|
||||
acts_as_list :scope => 'opt = \'#{opt}\''
|
||||
|
||||
before_destroy :check_integrity
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name, :scope => [:type, :project_id]
|
||||
validates_presence_of :opt, :name
|
||||
validates_uniqueness_of :name, :scope => [:opt]
|
||||
validates_length_of :name, :maximum => 30
|
||||
|
||||
named_scope :shared, :conditions => { :project_id => nil }
|
||||
named_scope :active, :conditions => { :active => true }
|
||||
named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
|
||||
|
||||
def self.default
|
||||
# Creates a fake default scope so Enumeration.default will check
|
||||
# it's type. STI subclasses will automatically add their own
|
||||
# types to the finder.
|
||||
if self.descends_from_active_record?
|
||||
find(:first, :conditions => { :is_default => true, :type => 'Enumeration' })
|
||||
else
|
||||
# STI classes are
|
||||
find(:first, :conditions => { :is_default => true })
|
||||
end
|
||||
# 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
|
||||
|
||||
# Overloaded on concrete classes
|
||||
def self.default(option)
|
||||
find(:first, :conditions => {:opt => option, :is_default => true}, :order => 'position')
|
||||
end
|
||||
|
||||
def option_name
|
||||
nil
|
||||
OPTIONS[self.opt][:label]
|
||||
end
|
||||
|
||||
def before_save
|
||||
if is_default? && is_default_changed?
|
||||
Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type})
|
||||
Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt})
|
||||
end
|
||||
end
|
||||
|
||||
# Overloaded on concrete classes
|
||||
def objects_count
|
||||
0
|
||||
OPTIONS[self.opt][:model].count(:conditions => "#{OPTIONS[self.opt][:foreign_key]} = #{id}")
|
||||
end
|
||||
|
||||
def in_use?
|
||||
self.objects_count != 0
|
||||
end
|
||||
|
||||
# Is this enumeration overiding a system level enumeration?
|
||||
def is_override?
|
||||
!self.parent.nil?
|
||||
end
|
||||
|
||||
alias :destroy_without_reassign :destroy
|
||||
|
||||
@@ -77,7 +63,7 @@ class Enumeration < ActiveRecord::Base
|
||||
# If a enumeration is specified, objects are reassigned
|
||||
def destroy(reassign_to = nil)
|
||||
if reassign_to && reassign_to.is_a?(Enumeration)
|
||||
self.transfer_relations(reassign_to)
|
||||
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
|
||||
@@ -87,49 +73,9 @@ class Enumeration < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def to_s; name end
|
||||
|
||||
# Returns the Subclasses of Enumeration. Each Subclass needs to be
|
||||
# required in development mode.
|
||||
#
|
||||
# Note: subclasses is protected in ActiveRecord
|
||||
def self.get_subclasses
|
||||
@@subclasses[Enumeration]
|
||||
end
|
||||
|
||||
# Does the +new+ Hash override the previous Enumeration?
|
||||
def self.overridding_change?(new, previous)
|
||||
if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous)
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
# Does the +new+ Hash have the same custom values as the previous Enumeration?
|
||||
def self.same_custom_values?(new, previous)
|
||||
previous.custom_field_values.each do |custom_value|
|
||||
if custom_value.value != new["custom_field_values"][custom_value.custom_field_id.to_s]
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
# Are the new and previous fields equal?
|
||||
def self.same_active_state?(new, previous)
|
||||
new = (new == "1" ? true : false)
|
||||
return new == previous
|
||||
end
|
||||
|
||||
private
|
||||
def check_integrity
|
||||
raise "Can't delete enumeration" if self.in_use?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Force load the subclasses in development mode
|
||||
require_dependency 'time_entry_activity'
|
||||
require_dependency 'document_category'
|
||||
require_dependency 'issue_priority'
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 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 Group < Principal
|
||||
has_and_belongs_to_many :users, :after_add => :user_added,
|
||||
:after_remove => :user_removed
|
||||
|
||||
acts_as_customizable
|
||||
|
||||
validates_presence_of :lastname
|
||||
validates_uniqueness_of :lastname, :case_sensitive => false
|
||||
validates_length_of :lastname, :maximum => 30
|
||||
|
||||
def to_s
|
||||
lastname.to_s
|
||||
end
|
||||
|
||||
def user_added(user)
|
||||
members.each do |member|
|
||||
next if member.project.nil?
|
||||
user_member = Member.find_by_project_id_and_user_id(member.project_id, user.id) || Member.new(:project_id => member.project_id, :user_id => user.id)
|
||||
member.member_roles.each do |member_role|
|
||||
user_member.member_roles << MemberRole.new(:role => member_role.role, :inherited_from => member_role.id)
|
||||
end
|
||||
user_member.save!
|
||||
end
|
||||
end
|
||||
|
||||
def user_removed(user)
|
||||
members.each do |member|
|
||||
MemberRole.find(:all, :include => :member,
|
||||
:conditions => ["#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids]).each(&:destroy)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 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 GroupCustomField < CustomField
|
||||
def type_name
|
||||
:label_group_plural
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -24,8 +24,6 @@ class IssueCategory < ActiveRecord::Base
|
||||
validates_uniqueness_of :name, :scope => [:project_id]
|
||||
validates_length_of :name, :maximum => 30
|
||||
|
||||
named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
|
||||
|
||||
alias :destroy_without_reassign :destroy
|
||||
|
||||
# Destroy the category
|
||||
|
||||
@@ -1,34 +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 IssuePriority < Enumeration
|
||||
has_many :issues, :foreign_key => 'priority_id'
|
||||
|
||||
OptionName = :enumeration_issue_priorities
|
||||
|
||||
def option_name
|
||||
OptionName
|
||||
end
|
||||
|
||||
def objects_count
|
||||
issues.count
|
||||
end
|
||||
|
||||
def transfer_relations(to)
|
||||
issues.update_all("priority_id = #{to.id}")
|
||||
end
|
||||
end
|
||||
@@ -1,23 +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 IssuePriorityCustomField < CustomField
|
||||
def type_name
|
||||
:enumeration_issue_priorities
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,19 +21,13 @@ class IssueRelation < ActiveRecord::Base
|
||||
|
||||
TYPE_RELATES = "relates"
|
||||
TYPE_DUPLICATES = "duplicates"
|
||||
TYPE_DUPLICATED = "duplicated"
|
||||
TYPE_BLOCKS = "blocks"
|
||||
TYPE_BLOCKED = "blocked"
|
||||
TYPE_PRECEDES = "precedes"
|
||||
TYPE_FOLLOWS = "follows"
|
||||
|
||||
TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1, :sym => TYPE_RELATES },
|
||||
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2, :sym => TYPE_DUPLICATED },
|
||||
TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES },
|
||||
TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4, :sym => TYPE_BLOCKED },
|
||||
TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS },
|
||||
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6, :sym => TYPE_FOLLOWS },
|
||||
TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_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
|
||||
@@ -41,19 +35,11 @@ class IssueRelation < ActiveRecord::Base
|
||||
validates_numericality_of :delay, :allow_nil => true
|
||||
validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
|
||||
|
||||
attr_protected :issue_from_id, :issue_to_id
|
||||
|
||||
def validate
|
||||
if issue_from && issue_to
|
||||
errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
|
||||
errors.add :issue_to_id, :not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations?
|
||||
#detect circular dependencies depending wether the relation should be reversed
|
||||
if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse]
|
||||
errors.add_to_base :circular_dependency if issue_from.all_dependent_issues.include? issue_to
|
||||
else
|
||||
errors.add_to_base :circular_dependency if issue_to.all_dependent_issues.include? issue_from
|
||||
end
|
||||
errors.add_to_base :cant_link_an_issue_with_a_descendant if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(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
|
||||
|
||||
@@ -61,24 +47,11 @@ class IssueRelation < ActiveRecord::Base
|
||||
(self.issue_from_id == issue.id) ? issue_to : issue_from
|
||||
end
|
||||
|
||||
# Returns the relation type for +issue+
|
||||
def relation_type_for(issue)
|
||||
if TYPES[relation_type]
|
||||
if self.issue_from_id == issue.id
|
||||
relation_type
|
||||
else
|
||||
TYPES[relation_type][:sym]
|
||||
end
|
||||
end
|
||||
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
|
||||
reverse_if_needed
|
||||
|
||||
if TYPE_PRECEDES == relation_type
|
||||
self.delay ||= 0
|
||||
else
|
||||
@@ -89,30 +62,18 @@ class IssueRelation < ActiveRecord::Base
|
||||
|
||||
def set_issue_to_dates
|
||||
soonest_start = self.successor_soonest_start
|
||||
if soonest_start && issue_to
|
||||
issue_to.reschedule_after(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
|
||||
if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && (issue_from.start_date || issue_from.due_date)
|
||||
(issue_from.due_date || issue_from.start_date) + 1 + delay
|
||||
end
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
# Reverses the relation if needed so that it gets stored in the proper way
|
||||
def reverse_if_needed
|
||||
if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse]
|
||||
issue_tmp = issue_to
|
||||
self.issue_to = issue_from
|
||||
self.issue_from = issue_tmp
|
||||
self.relation_type = TYPES[relation_type][:reverse]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,17 +17,13 @@
|
||||
|
||||
class IssueStatus < ActiveRecord::Base
|
||||
before_destroy :check_integrity
|
||||
has_many :workflows, :foreign_key => "old_status_id"
|
||||
has_many :workflows, :foreign_key => "old_status_id", :dependent => :delete_all
|
||||
acts_as_list
|
||||
|
||||
before_destroy :delete_workflows
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name
|
||||
validates_length_of :name, :maximum => 30
|
||||
validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
|
||||
|
||||
named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
|
||||
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?
|
||||
@@ -37,52 +33,27 @@ class IssueStatus < ActiveRecord::Base
|
||||
def self.default
|
||||
find(:first, :conditions =>["is_default=?", true])
|
||||
end
|
||||
|
||||
# Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
|
||||
def self.update_issue_done_ratios
|
||||
if Issue.use_status_for_done_ratio?
|
||||
IssueStatus.find(:all, :conditions => ["default_done_ratio >= 0"]).each do |status|
|
||||
Issue.update_all(["done_ratio = ?", status.default_done_ratio],
|
||||
["status_id = ?", status.id])
|
||||
end
|
||||
end
|
||||
|
||||
return Issue.use_status_for_done_ratio?
|
||||
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(roles, tracker, author=false, assignee=false)
|
||||
if roles && tracker
|
||||
role_ids = roles.collect(&:id)
|
||||
transitions = workflows.select do |w|
|
||||
role_ids.include?(w.role_id) &&
|
||||
w.tracker_id == tracker.id &&
|
||||
((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee))
|
||||
end
|
||||
transitions.collect{|w| w.new_status}.compact.sort
|
||||
else
|
||||
[]
|
||||
end
|
||||
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(roles, tracker, author=false, assignee=false)
|
||||
if roles.present? && tracker
|
||||
conditions = "(author = :false AND assignee = :false)"
|
||||
conditions << " OR author = :true" if author
|
||||
conditions << " OR assignee = :true" if assignee
|
||||
|
||||
workflows.find(:all,
|
||||
:include => :new_status,
|
||||
:conditions => ["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})",
|
||||
{:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false}
|
||||
]
|
||||
).collect{|w| w.new_status}.compact.sort
|
||||
else
|
||||
[]
|
||||
end
|
||||
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)
|
||||
@@ -95,9 +66,4 @@ private
|
||||
def check_integrity
|
||||
raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
|
||||
end
|
||||
|
||||
# Deletes associated workflows
|
||||
def delete_workflows
|
||||
Workflow.delete_all(["old_status_id = :id OR new_status_id = :id", {:id => id}])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -32,16 +32,12 @@ class Journal < ActiveRecord::Base
|
||||
: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 <> '')"}
|
||||
|
||||
named_scope :visible, lambda {|*args| {
|
||||
:include => {:issue => :project},
|
||||
:conditions => Issue.visible_condition(args.shift || User.current, *args)
|
||||
}}
|
||||
|
||||
def save(*args)
|
||||
# Do not save an empty journal
|
||||
(details.empty? && notes.blank?) ? false : super
|
||||
@@ -69,20 +65,4 @@ class Journal < ActiveRecord::Base
|
||||
def attachments
|
||||
journalized.respond_to?(:attachments) ? journalized.attachments : nil
|
||||
end
|
||||
|
||||
# Returns a string of css classes
|
||||
def css_classes
|
||||
s = 'journal'
|
||||
s << ' has-notes' unless notes.blank?
|
||||
s << ' has-details' unless details.blank?
|
||||
s
|
||||
end
|
||||
|
||||
def notify?
|
||||
@notify != false
|
||||
end
|
||||
|
||||
def notify=(arg)
|
||||
@notify = arg
|
||||
end
|
||||
end
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user