Compare commits
169
Commits
1.2-stable
..
1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5cfe79044 | ||
|
|
38a2beb2c0 | ||
|
|
77ba8bbfc0 | ||
|
|
7bbf4af0c1 | ||
|
|
babcd39918 | ||
|
|
924bb8da0b | ||
|
|
2c91d15c58 | ||
|
|
dd91dc4cb7 | ||
|
|
98eaff414f | ||
|
|
eb05880717 | ||
|
|
25b2ffb8fd | ||
|
|
c4e123b2f0 | ||
|
|
324baf60a6 | ||
|
|
22bcce63aa | ||
|
|
ef90132cf3 | ||
|
|
3909d2c8ba | ||
|
|
5e7e11440c | ||
|
|
7d55572bd1 | ||
|
|
945cd3933e | ||
|
|
47b969de00 | ||
|
|
c51f9b8907 | ||
|
|
65b6b7f5a9 | ||
|
|
d44a90045a | ||
|
|
1c63c443b6 | ||
|
|
b0b321bd11 | ||
|
|
8bd0ff03a0 | ||
|
|
7dbc8b4f97 | ||
|
|
019ea4adf3 | ||
|
|
0a62a9187c | ||
|
|
e450c124d9 | ||
|
|
e1a557fa58 | ||
|
|
b35bc6d93c | ||
|
|
4593d97472 | ||
|
|
d99d2efcca | ||
|
|
1c62645270 | ||
|
|
60caea006a | ||
|
|
5003152542 | ||
|
|
2149add25c | ||
|
|
b5bbc93325 | ||
|
|
7ad17f92b1 | ||
|
|
066f648949 | ||
|
|
46fc878396 | ||
|
|
d1952aefb8 | ||
|
|
4a5dce41e2 | ||
|
|
f74d9809fd | ||
|
|
f219a92c1f | ||
|
|
f8e46cfd30 | ||
|
|
9321ffde39 | ||
|
|
1e370f2c5a | ||
|
|
d2f9a726bb | ||
|
|
00423307ce | ||
|
|
5a639173de | ||
|
|
823fd16c3a | ||
|
|
e32fc44dc2 | ||
|
|
934221337d | ||
|
|
c48e40af31 | ||
|
|
47e12f12cc | ||
|
|
897258289a | ||
|
|
67867d99fe | ||
|
|
32b2e84477 | ||
|
|
1f278a0221 | ||
|
|
5e49df04d2 | ||
|
|
973c54d49b | ||
|
|
d2a4265f86 | ||
|
|
771723c595 | ||
|
|
8de76de8a1 | ||
|
|
f2711afe65 | ||
|
|
8fa5019e69 | ||
|
|
7b472a605d | ||
|
|
56fba472a7 | ||
|
|
af5d9ca907 | ||
|
|
8a42ca81a9 | ||
|
|
ada4c889be | ||
|
|
6fe600b163 | ||
|
|
b2e82fd5a0 | ||
|
|
cee0dce6b7 | ||
|
|
d090e539f6 | ||
|
|
29f9f3feff | ||
|
|
2bea4b30a5 | ||
|
|
00b53286fd | ||
|
|
c8c4fb130c | ||
|
|
0d7cead479 | ||
|
|
b5d64b9a2f | ||
|
|
519069b867 | ||
|
|
7443f2a310 | ||
|
|
b419deb907 | ||
|
|
b8d5a05b20 | ||
|
|
e29244652c | ||
|
|
27ef72c35e | ||
|
|
86e986f014 | ||
|
|
d60cc50d99 | ||
|
|
9e5d2100b6 | ||
|
|
ccbc9f8ff9 | ||
|
|
047bf692b3 | ||
|
|
3e692a908b | ||
|
|
d457f90fcd | ||
|
|
b9f23bedb7 | ||
|
|
d1a9f81fc6 | ||
|
|
80e833cd88 | ||
|
|
a12a073a6e | ||
|
|
bc57078b12 | ||
|
|
1c93f99a55 | ||
|
|
758feaccab | ||
|
|
2012c60bfd | ||
|
|
8ca6941a33 | ||
|
|
10a76f5e73 | ||
|
|
6e5f567346 | ||
|
|
7af610631f | ||
|
|
fab5064643 | ||
|
|
ab5ce45b43 | ||
|
|
5345a2dd89 | ||
|
|
7ca197b37f | ||
|
|
72ce3e18f8 | ||
|
|
358ee2ef2e | ||
|
|
b5b8d34d94 | ||
|
|
597266e5a2 | ||
|
|
36ad597b69 | ||
|
|
c67272599c | ||
|
|
b6bc3a3665 | ||
|
|
a96eb375ec | ||
|
|
c7e719fc4b | ||
|
|
18d841553e | ||
|
|
31d233e567 | ||
|
|
4ff6070126 | ||
|
|
dfe44017b6 | ||
|
|
7cae43314a | ||
|
|
2f529fd834 | ||
|
|
9892ede7b7 | ||
|
|
102e845391 | ||
|
|
7bdf0ab729 | ||
|
|
4426fd695e | ||
|
|
3f1c3fa020 | ||
|
|
19bbb6e2cb | ||
|
|
b02463184a | ||
|
|
a6408945e5 | ||
|
|
c20e85e4dd | ||
|
|
7a9fab7748 | ||
|
|
acaa223cf8 | ||
|
|
8dde6e019d | ||
|
|
ae3d542664 | ||
|
|
c731d11209 | ||
|
|
8458dc23d4 | ||
|
|
9af4cb5c38 | ||
|
|
df120e43cd | ||
|
|
59f98693ae | ||
|
|
677fee310a | ||
|
|
0843b188fb | ||
|
|
8f64938b9e | ||
|
|
29e7ae9698 | ||
|
|
f682be8468 | ||
|
|
e771fc03bd | ||
|
|
52a12aaca8 | ||
|
|
8146e096f4 | ||
|
|
41e38483a6 | ||
|
|
41c6d3cef6 | ||
|
|
ec526c1261 | ||
|
|
b4122707f6 | ||
|
|
f70a8cde88 | ||
|
|
69f34a595d | ||
|
|
be52ccf01f | ||
|
|
8a1d45ffd6 | ||
|
|
4b52b7a8df | ||
|
|
6ed2e003a1 | ||
|
|
1cc116fe5c | ||
|
|
619c148719 | ||
|
|
0ae9cc7d07 | ||
|
|
a2a3dae974 | ||
|
|
4f5dc94170 | ||
|
|
4775864d69 |
@@ -1,7 +1,4 @@
|
|||||||
/.project
|
|
||||||
/.loadpath
|
|
||||||
/config/additional_environment.rb
|
/config/additional_environment.rb
|
||||||
/config/configuration.yml
|
|
||||||
/config/database.yml
|
/config/database.yml
|
||||||
/config/email.yml
|
/config/email.yml
|
||||||
/config/initializers/session_store.rb
|
/config/initializers/session_store.rb
|
||||||
@@ -10,8 +7,6 @@
|
|||||||
/db/*.sqlite3
|
/db/*.sqlite3
|
||||||
/db/schema.rb
|
/db/schema.rb
|
||||||
/files/*
|
/files/*
|
||||||
/lib/redmine/scm/adapters/mercurial/redminehelper.pyc
|
|
||||||
/lib/redmine/scm/adapters/mercurial/redminehelper.pyo
|
|
||||||
/log/*.log*
|
/log/*.log*
|
||||||
/log/mongrel_debug
|
/log/mongrel_debug
|
||||||
/public/dispatch.*
|
/public/dispatch.*
|
||||||
|
|||||||
@@ -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/
|
|
||||||
@@ -203,25 +203,13 @@ class AccountController < ApplicationController
|
|||||||
self.logged_user = user
|
self.logged_user = user
|
||||||
# generate a key and set cookie if autologin
|
# generate a key and set cookie if autologin
|
||||||
if params[:autologin] && Setting.autologin?
|
if params[:autologin] && Setting.autologin?
|
||||||
set_autologin_cookie(user)
|
token = Token.create(:user => user, :action => 'autologin')
|
||||||
|
cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
|
||||||
end
|
end
|
||||||
call_hook(:controller_account_success_authentication_after, {:user => user })
|
call_hook(:controller_account_success_authentication_after, {:user => user })
|
||||||
redirect_back_or_default :controller => 'my', :action => 'page'
|
redirect_back_or_default :controller => 'my', :action => 'page'
|
||||||
end
|
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
|
# Onthefly creation failed, display the registration form to fill/fix attributes
|
||||||
def onthefly_creation_failed(user, auth_source_options = { })
|
def onthefly_creation_failed(user, auth_source_options = { })
|
||||||
@user = user
|
@user = user
|
||||||
|
|||||||
@@ -1,24 +1,7 @@
|
|||||||
# 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
|
class ActivitiesController < ApplicationController
|
||||||
menu_item :activity
|
menu_item :activity
|
||||||
before_filter :find_optional_project
|
before_filter :find_optional_project
|
||||||
accept_rss_auth :index
|
accept_key_auth :index
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@days = Setting.activity_days_default.to_i
|
@days = Setting.activity_days_default.to_i
|
||||||
@@ -40,7 +23,7 @@ class ActivitiesController < ApplicationController
|
|||||||
|
|
||||||
events = @activity.events(@date_from, @date_to)
|
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])
|
if events.empty? || stale?(:etag => [events.first, User.current])
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
@events_by_day = events.group_by(&:event_date)
|
@events_by_day = events.group_by(&:event_date)
|
||||||
@@ -72,4 +55,5 @@ class ActivitiesController < ApplicationController
|
|||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
class AdminController < ApplicationController
|
class AdminController < ApplicationController
|
||||||
layout 'admin'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
|
||||||
helper :sort
|
helper :sort
|
||||||
include SortHelper
|
include SortHelper
|
||||||
|
|
||||||
@@ -28,10 +30,12 @@ class AdminController < ApplicationController
|
|||||||
def projects
|
def projects
|
||||||
@status = params[:status] ? params[:status].to_i : 1
|
@status = params[:status] ? params[:status].to_i : 1
|
||||||
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
||||||
|
|
||||||
unless params[:name].blank?
|
unless params[:name].blank?
|
||||||
name = "%#{params[:name].strip.downcase}%"
|
name = "%#{params[:name].strip.downcase}%"
|
||||||
c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name]
|
c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name]
|
||||||
end
|
end
|
||||||
|
|
||||||
@projects = Project.find :all, :order => 'lft',
|
@projects = Project.find :all, :order => 'lft',
|
||||||
:conditions => c.conditions
|
:conditions => c.conditions
|
||||||
|
|
||||||
@@ -73,12 +77,10 @@ class AdminController < ApplicationController
|
|||||||
def info
|
def info
|
||||||
@db_adapter_name = ActiveRecord::Base.connection.adapter_name
|
@db_adapter_name = ActiveRecord::Base.connection.adapter_name
|
||||||
@checklist = [
|
@checklist = [
|
||||||
[:text_default_administrator_account_changed,
|
[:text_default_administrator_account_changed, User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?],
|
||||||
User.find(:first,
|
|
||||||
:conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?],
|
|
||||||
[:text_file_repository_writable, File.writable?(Attachment.storage_path)],
|
[:text_file_repository_writable, File.writable?(Attachment.storage_path)],
|
||||||
[:text_plugin_assets_writable, File.writable?(Engines.public_directory)],
|
[:text_plugin_assets_writable, File.writable?(Engines.public_directory)],
|
||||||
[:text_rmagick_available, Object.const_defined?(:Magick)]
|
[:text_rmagick_available, Object.const_defined?(:Magick)]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -18,13 +18,11 @@
|
|||||||
require 'uri'
|
require 'uri'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
|
|
||||||
class Unauthorized < Exception; end
|
|
||||||
|
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
|
|
||||||
layout 'base'
|
layout 'base'
|
||||||
exempt_from_layout 'builder', 'rsb'
|
exempt_from_layout 'builder'
|
||||||
|
|
||||||
# Remove broken cookie after upgrade from 0.8.x (#4292)
|
# Remove broken cookie after upgrade from 0.8.x (#4292)
|
||||||
# See https://rails.lighthouseapp.com/projects/8994/tickets/3360
|
# See https://rails.lighthouseapp.com/projects/8994/tickets/3360
|
||||||
@@ -43,7 +41,6 @@ class ApplicationController < ActionController::Base
|
|||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
|
|
||||||
rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
|
rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
|
||||||
rescue_from ::Unauthorized, :with => :deny_access
|
|
||||||
|
|
||||||
include Redmine::Search::Controller
|
include Redmine::Search::Controller
|
||||||
include Redmine::MenuManager::MenuController
|
include Redmine::MenuManager::MenuController
|
||||||
@@ -71,13 +68,13 @@ class ApplicationController < ActionController::Base
|
|||||||
user = User.try_to_autologin(cookies[:autologin])
|
user = User.try_to_autologin(cookies[:autologin])
|
||||||
session[:user_id] = user.id if user
|
session[:user_id] = user.id if user
|
||||||
user
|
user
|
||||||
elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
|
elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])
|
||||||
# RSS key authentication does not start a session
|
# RSS key authentication does not start a session
|
||||||
User.find_by_rss_key(params[:key])
|
User.find_by_rss_key(params[:key])
|
||||||
elsif Setting.rest_api_enabled? && accept_api_auth?
|
elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format])
|
||||||
if (key = api_key_from_request)
|
if params[:key].present? && accept_key_auth_actions.include?(params[:action])
|
||||||
# Use API key
|
# Use API key
|
||||||
User.find_by_api_key(key)
|
User.find_by_api_key(params[:key])
|
||||||
else
|
else
|
||||||
# HTTP Basic, either username/password or API key/random
|
# HTTP Basic, either username/password or API key/random
|
||||||
authenticate_with_http_basic do |username, password|
|
authenticate_with_http_basic do |username, password|
|
||||||
@@ -156,16 +153,8 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
# Authorize the user for the requested action
|
# Authorize the user for the requested action
|
||||||
def authorize(ctrl = params[:controller], action = params[:action], global = false)
|
def authorize(ctrl = params[:controller], action = params[:action], global = false)
|
||||||
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
|
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project, :global => global)
|
||||||
if allowed
|
allowed ? true : deny_access
|
||||||
true
|
|
||||||
else
|
|
||||||
if @project && @project.archived?
|
|
||||||
render_403 :message => :notice_not_authorized_archived_project
|
|
||||||
else
|
|
||||||
deny_access
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Authorize the user for the requested action outside a project
|
# Authorize the user for the requested action outside a project
|
||||||
@@ -180,13 +169,6 @@ class ApplicationController < ActionController::Base
|
|||||||
render_404
|
render_404
|
||||||
end
|
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]
|
# Find a project based on params[:project_id]
|
||||||
# TODO: some subclasses override this, see about merging their logic
|
# TODO: some subclasses override this, see about merging their logic
|
||||||
def find_optional_project
|
def find_optional_project
|
||||||
@@ -224,23 +206,16 @@ class ApplicationController < ActionController::Base
|
|||||||
def find_issues
|
def find_issues
|
||||||
@issues = Issue.find_all_by_id(params[:id] || params[:ids])
|
@issues = Issue.find_all_by_id(params[:id] || params[:ids])
|
||||||
raise ActiveRecord::RecordNotFound if @issues.empty?
|
raise ActiveRecord::RecordNotFound if @issues.empty?
|
||||||
if @issues.detect {|issue| !issue.visible?}
|
projects = @issues.collect(&:project).compact.uniq
|
||||||
deny_access
|
if projects.size == 1
|
||||||
return
|
@project = projects.first
|
||||||
end
|
else
|
||||||
@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
|
# TODO: let users bulk edit/move/destroy issues from different projects
|
||||||
render_error 'Can not bulk edit/move/destroy issues from different projects'
|
render_error 'Can not bulk edit/move/destroy issues from different projects'
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
# make sure that the user is a member of the project (or admin) if project is private
|
# make sure that the user is a member of the project (or admin) if project is private
|
||||||
@@ -278,36 +253,41 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
redirect_to default
|
redirect_to default
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_403(options={})
|
def render_403
|
||||||
@project = nil
|
@project = nil
|
||||||
render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
|
respond_to do |format|
|
||||||
|
format.html { render :template => "common/403", :layout => use_layout, :status => 403 }
|
||||||
|
format.atom { head 403 }
|
||||||
|
format.xml { head 403 }
|
||||||
|
format.js { head 403 }
|
||||||
|
format.json { head 403 }
|
||||||
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_404(options={})
|
def render_404
|
||||||
render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
|
respond_to do |format|
|
||||||
|
format.html { render :template => "common/404", :layout => use_layout, :status => 404 }
|
||||||
|
format.atom { head 404 }
|
||||||
|
format.xml { head 404 }
|
||||||
|
format.js { head 404 }
|
||||||
|
format.json { head 404 }
|
||||||
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Renders an error response
|
def render_error(msg)
|
||||||
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|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
render :template => 'common/error', :layout => use_layout, :status => @status
|
flash.now[:error] = msg
|
||||||
|
render :text => '', :layout => use_layout, :status => 500
|
||||||
}
|
}
|
||||||
format.atom { head @status }
|
format.atom { head 500 }
|
||||||
format.xml { head @status }
|
format.xml { head 500 }
|
||||||
format.js { head @status }
|
format.js { head 500 }
|
||||||
format.json { head @status }
|
format.json { head 500 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -333,40 +313,13 @@ class ApplicationController < ActionController::Base
|
|||||||
render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
|
render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: remove in Redmine 1.4
|
|
||||||
def self.accept_key_auth(*actions)
|
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."
|
actions = actions.flatten.map(&:to_s)
|
||||||
accept_rss_auth(*actions)
|
write_inheritable_attribute('accept_key_auth_actions', actions)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: remove in Redmine 1.4
|
|
||||||
def accept_key_auth_actions
|
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.read_inheritable_attribute('accept_key_auth_actions') || []
|
||||||
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
|
end
|
||||||
|
|
||||||
# Returns the number of objects that should be displayed
|
# Returns the number of objects that should be displayed
|
||||||
@@ -384,30 +337,6 @@ class ApplicationController < ActionController::Base
|
|||||||
per_page
|
per_page
|
||||||
end
|
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
|
# qvalues http header parser
|
||||||
# code taken from webrick
|
# code taken from webrick
|
||||||
def parse_qvalues(value)
|
def parse_qvalues(value)
|
||||||
@@ -438,15 +367,6 @@ class ApplicationController < ActionController::Base
|
|||||||
%w(xml json).include? params[:format]
|
%w(xml json).include? params[:format]
|
||||||
end
|
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
|
# Renders a warning flash if obj has unsaved attachments
|
||||||
def render_attachment_warning_if_needed(obj)
|
def render_attachment_warning_if_needed(obj)
|
||||||
flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
|
flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
|
||||||
@@ -482,36 +402,4 @@ class ApplicationController < ActionController::Base
|
|||||||
end.to_json
|
end.to_json
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# 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
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ class AutoCompletesController < ApplicationController
|
|||||||
def issues
|
def issues
|
||||||
@issues = []
|
@issues = []
|
||||||
q = params[:q].to_s
|
q = params[:q].to_s
|
||||||
query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues
|
|
||||||
if q.match(/^\d+$/)
|
if q.match(/^\d+$/)
|
||||||
@issues << query.visible.find_by_id(q.to_i)
|
@issues << @project.issues.visible.find_by_id(q.to_i)
|
||||||
end
|
end
|
||||||
unless q.blank?
|
unless q.blank?
|
||||||
@issues += query.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
|
@issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
|
||||||
end
|
end
|
||||||
@issues.compact!
|
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
class BoardsController < ApplicationController
|
class BoardsController < ApplicationController
|
||||||
default_search_scope :messages
|
default_search_scope :messages
|
||||||
before_filter :find_project, :find_board_if_available, :authorize
|
before_filter :find_project, :find_board_if_available, :authorize
|
||||||
accept_rss_auth :index, :show
|
accept_key_auth :index, :show
|
||||||
|
|
||||||
helper :messages
|
helper :messages
|
||||||
include MessagesHelper
|
include MessagesHelper
|
||||||
|
|||||||
@@ -1,20 +1,3 @@
|
|||||||
# 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
|
class CalendarsController < ApplicationController
|
||||||
menu_item :calendar
|
menu_item :calendar
|
||||||
before_filter :find_optional_project
|
before_filter :find_optional_project
|
||||||
@@ -25,8 +8,6 @@ class CalendarsController < ApplicationController
|
|||||||
helper :projects
|
helper :projects
|
||||||
helper :queries
|
helper :queries
|
||||||
include QueriesHelper
|
include QueriesHelper
|
||||||
helper :sort
|
|
||||||
include SortHelper
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
if params[:year] and params[:year].to_i > 1900
|
if params[:year] and params[:year].to_i > 1900
|
||||||
@@ -51,6 +32,8 @@ class CalendarsController < ApplicationController
|
|||||||
@calendar.events = events
|
@calendar.events = events
|
||||||
end
|
end
|
||||||
|
|
||||||
render :action => 'show', :layout => false if request.xhr?
|
render :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
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,10 +1,8 @@
|
|||||||
class ContextMenusController < ApplicationController
|
class ContextMenusController < ApplicationController
|
||||||
helper :watchers
|
helper :watchers
|
||||||
helper :issues
|
|
||||||
|
|
||||||
def issues
|
def issues
|
||||||
@issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
|
@issues = Issue.find_all_by_id(params[:ids], :include => :project)
|
||||||
|
|
||||||
if (@issues.size == 1)
|
if (@issues.size == 1)
|
||||||
@issue = @issues.first
|
@issue = @issues.first
|
||||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||||
@@ -18,21 +16,17 @@ class ContextMenusController < ApplicationController
|
|||||||
@projects = @issues.collect(&:project).compact.uniq
|
@projects = @issues.collect(&:project).compact.uniq
|
||||||
@project = @projects.first if @projects.size == 1
|
@project = @projects.first if @projects.size == 1
|
||||||
|
|
||||||
@can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
|
@can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
|
||||||
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
|
: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?)),
|
: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)),
|
:move => (@project && User.current.allowed_to?(:move_issues, @project)),
|
||||||
:copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
|
:copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
|
||||||
:delete => User.current.allowed_to?(:delete_issues, @projects)
|
:delete => (@project && User.current.allowed_to?(:delete_issues, @project))
|
||||||
}
|
}
|
||||||
if @project
|
if @project
|
||||||
@assignables = @project.assignable_users
|
@assignables = @project.assignable_users
|
||||||
@assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
|
@assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
|
||||||
@trackers = @project.trackers
|
@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
|
end
|
||||||
|
|
||||||
@priorities = IssuePriority.all.reverse
|
@priorities = IssuePriority.all.reverse
|
||||||
@@ -42,16 +36,4 @@ class ContextMenusController < ApplicationController
|
|||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -38,9 +38,8 @@ class CustomFieldsController < ApplicationController
|
|||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
|
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
|
||||||
redirect_to :action => 'index', :tab => @custom_field.class.name
|
redirect_to :action => 'index', :tab => @custom_field.class.name
|
||||||
else
|
|
||||||
@trackers = Tracker.find(:all, :order => 'position')
|
|
||||||
end
|
end
|
||||||
|
@trackers = Tracker.find(:all, :order => 'position')
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@@ -49,9 +48,8 @@ class CustomFieldsController < ApplicationController
|
|||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
|
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
|
||||||
redirect_to :action => 'index', :tab => @custom_field.class.name
|
redirect_to :action => 'index', :tab => @custom_field.class.name
|
||||||
else
|
|
||||||
@trackers = Tracker.find(:all, :order => 'position')
|
|
||||||
end
|
end
|
||||||
|
@trackers = Tracker.find(:all, :order => 'position')
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|||||||
@@ -75,12 +75,10 @@ class EnumerationsController < ApplicationController
|
|||||||
# No associated objects
|
# No associated objects
|
||||||
@enumeration.destroy
|
@enumeration.destroy
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
return
|
|
||||||
elsif params[:reassign_to_id]
|
elsif params[:reassign_to_id]
|
||||||
if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id])
|
if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id])
|
||||||
@enumeration.destroy(reassign_to)
|
@enumeration.destroy(reassign_to)
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@enumerations = @enumeration.class.find(:all) - [@enumeration]
|
@enumerations = @enumeration.class.find(:all) - [@enumeration]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class FilesController < ApplicationController
|
class FilesController < ApplicationController
|
||||||
menu_item :files
|
menu_item :files
|
||||||
|
|
||||||
before_filter :find_project_by_project_id
|
before_filter :find_project
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
||||||
helper :sort
|
helper :sort
|
||||||
@@ -19,18 +19,19 @@ class FilesController < ApplicationController
|
|||||||
render :layout => !request.xhr?
|
render :layout => !request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: split method into new (GET) and create (POST)
|
||||||
def new
|
def new
|
||||||
|
if request.post?
|
||||||
|
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 :controller => 'files', :action => 'index', :id => @project
|
||||||
|
return
|
||||||
|
end
|
||||||
@versions = @project.versions.sort
|
@versions = @project.versions.sort
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -1,27 +1,9 @@
|
|||||||
# 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
|
class GanttsController < ApplicationController
|
||||||
menu_item :gantt
|
menu_item :gantt
|
||||||
before_filter :find_optional_project
|
before_filter :find_optional_project
|
||||||
|
|
||||||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||||
|
|
||||||
helper :gantt
|
|
||||||
helper :issues
|
helper :issues
|
||||||
helper :projects
|
helper :projects
|
||||||
helper :queries
|
helper :queries
|
||||||
@@ -32,17 +14,33 @@ class GanttsController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
@gantt = Redmine::Helpers::Gantt.new(params)
|
@gantt = Redmine::Helpers::Gantt.new(params)
|
||||||
@gantt.project = @project
|
|
||||||
retrieve_query
|
retrieve_query
|
||||||
@query.group_by = nil
|
@query.group_by = nil
|
||||||
@gantt.query = @query if @query.valid?
|
if @query.valid?
|
||||||
|
events = []
|
||||||
|
# Issues that have start and due dates
|
||||||
|
events += @query.issues(:include => [:tracker, :assigned_to, :priority],
|
||||||
|
:order => "start_date, due_date",
|
||||||
|
:conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @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 += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version],
|
||||||
|
:order => "start_date, effective_date",
|
||||||
|
:conditions => ["(((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 += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
|
||||||
|
|
||||||
|
@gantt.events = events
|
||||||
|
end
|
||||||
|
|
||||||
basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
|
basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :action => "show", :layout => !request.xhr? }
|
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.png { send_data(@gantt.to_image(@project), :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") }
|
format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class GroupsController < ApplicationController
|
|||||||
|
|
||||||
def autocomplete_for_user
|
def autocomplete_for_user
|
||||||
@group = Group.find(params[:id])
|
@group = Group.find(params[:id])
|
||||||
@users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
|
@users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -65,12 +65,10 @@ class IssueCategoriesController < ApplicationController
|
|||||||
# No issue assigned to this category
|
# No issue assigned to this category
|
||||||
@category.destroy
|
@category.destroy
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
|
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
|
||||||
return
|
|
||||||
elsif params[:todo]
|
elsif params[:todo]
|
||||||
reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign'
|
reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign'
|
||||||
@category.destroy(reassign_to)
|
@category.destroy(reassign_to)
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
|
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
|
||||||
return
|
|
||||||
end
|
end
|
||||||
@categories = @project.issue_categories - [@category]
|
@categories = @project.issue_categories - [@category]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class IssueMovesController < ApplicationController
|
class IssueMovesController < ApplicationController
|
||||||
default_search_scope :issues
|
default_search_scope :issues
|
||||||
before_filter :find_issues, :check_project_uniqueness
|
before_filter :find_issues
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -18,7 +18,6 @@ class IssueMovesController < ApplicationController
|
|||||||
@issues.each do |issue|
|
@issues.each do |issue|
|
||||||
issue.reload
|
issue.reload
|
||||||
issue.init_journal(User.current)
|
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 })
|
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)})
|
if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
|
||||||
moved_issues << r
|
moved_issues << r
|
||||||
@@ -51,13 +50,11 @@ class IssueMovesController < ApplicationController
|
|||||||
@target_project ||= @project
|
@target_project ||= @project
|
||||||
@trackers = @target_project.trackers
|
@trackers = @target_project.trackers
|
||||||
@available_statuses = Workflow.available_statuses(@project)
|
@available_statuses = Workflow.available_statuses(@project)
|
||||||
@notes = params[:notes]
|
|
||||||
@notes ||= ''
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_changed_attributes_for_move(params)
|
def extract_changed_attributes_for_move(params)
|
||||||
changed_attributes = {}
|
changed_attributes = {}
|
||||||
[:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
|
[:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
|
||||||
unless params[valid_attribute].blank?
|
unless params[valid_attribute].blank?
|
||||||
changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
|
changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
@@ -28,7 +28,6 @@ class IssueRelationsController < ApplicationController
|
|||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
||||||
format.js do
|
format.js do
|
||||||
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
|
||||||
render :update do |page|
|
render :update do |page|
|
||||||
page.replace_html "relations", :partial => 'issues/relations'
|
page.replace_html "relations", :partial => 'issues/relations'
|
||||||
if @relation.errors.empty?
|
if @relation.errors.empty?
|
||||||
@@ -48,10 +47,7 @@ class IssueRelationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
||||||
format.js {
|
format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} }
|
||||||
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
|
||||||
render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# 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
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -21,14 +21,12 @@ class IssuesController < ApplicationController
|
|||||||
|
|
||||||
before_filter :find_issue, :only => [:show, :edit, :update]
|
before_filter :find_issue, :only => [:show, :edit, :update]
|
||||||
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy]
|
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 :find_project, :only => [:new, :create]
|
||||||
before_filter :authorize, :except => [:index]
|
before_filter :authorize, :except => [:index]
|
||||||
before_filter :find_optional_project, :only => [:index]
|
before_filter :find_optional_project, :only => [:index]
|
||||||
before_filter :check_for_default_issue_status, :only => [:new, :create]
|
before_filter :check_for_default_issue_status, :only => [:new, :create]
|
||||||
before_filter :build_new_issue_from_params, :only => [:new, :create]
|
before_filter :build_new_issue_from_params, :only => [:new, :create]
|
||||||
accept_rss_auth :index, :show
|
accept_key_auth :index, :show
|
||||||
accept_api_auth :index, :show, :create, :update, :destroy
|
|
||||||
|
|
||||||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||||
|
|
||||||
@@ -45,13 +43,10 @@ class IssuesController < ApplicationController
|
|||||||
include AttachmentsHelper
|
include AttachmentsHelper
|
||||||
helper :queries
|
helper :queries
|
||||||
include QueriesHelper
|
include QueriesHelper
|
||||||
helper :repositories
|
|
||||||
include RepositoriesHelper
|
|
||||||
helper :sort
|
helper :sort
|
||||||
include SortHelper
|
include SortHelper
|
||||||
include IssuesHelper
|
include IssuesHelper
|
||||||
helper :timelog
|
helper :timelog
|
||||||
helper :gantt
|
|
||||||
include Redmine::Export::PDF
|
include Redmine::Export::PDF
|
||||||
|
|
||||||
verify :method => [:post, :delete],
|
verify :method => [:post, :delete],
|
||||||
@@ -68,29 +63,27 @@ class IssuesController < ApplicationController
|
|||||||
sort_update(@query.sortable_columns)
|
sort_update(@query.sortable_columns)
|
||||||
|
|
||||||
if @query.valid?
|
if @query.valid?
|
||||||
case params[:format]
|
limit = case params[:format]
|
||||||
when 'csv', 'pdf'
|
when 'csv', 'pdf'
|
||||||
@limit = Setting.issues_export_limit.to_i
|
Setting.issues_export_limit.to_i
|
||||||
when 'atom'
|
when 'atom'
|
||||||
@limit = Setting.feeds_limit.to_i
|
Setting.feeds_limit.to_i
|
||||||
when 'xml', 'json'
|
|
||||||
@offset, @limit = api_offset_and_limit
|
|
||||||
else
|
else
|
||||||
@limit = per_page_option
|
per_page_option
|
||||||
end
|
end
|
||||||
|
|
||||||
@issue_count = @query.issue_count
|
@issue_count = @query.issue_count
|
||||||
@issue_pages = Paginator.new self, @issue_count, @limit, params['page']
|
@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],
|
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
||||||
:order => sort_clause,
|
:order => sort_clause,
|
||||||
:offset => @offset,
|
:offset => @issue_pages.current.offset,
|
||||||
:limit => @limit)
|
:limit => limit)
|
||||||
@issue_count_by_group = @query.issue_count_by_group
|
@issue_count_by_group = @query.issue_count_by_group
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
|
format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
|
||||||
format.api
|
format.xml { render :layout => false }
|
||||||
|
format.json { render :text => @issues.to_json, :layout => false }
|
||||||
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
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.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.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
|
||||||
@@ -107,20 +100,16 @@ class IssuesController < ApplicationController
|
|||||||
@journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
|
@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.each_with_index {|j,i| j.indice = i+1}
|
||||||
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
||||||
|
@changesets = @issue.changesets.visible.all
|
||||||
if User.current.allowed_to?(:view_changesets, @project)
|
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
|
||||||
@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)
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||||
@priorities = IssuePriority.all
|
@priorities = IssuePriority.all
|
||||||
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
|
@time_entry = TimeEntry.new
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :template => 'issues/show.rhtml' }
|
format.html { render :template => 'issues/show.rhtml' }
|
||||||
format.api
|
format.xml { render :layout => false }
|
||||||
|
format.json { render :text => @issue.to_json, :layout => false }
|
||||||
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
|
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
|
||||||
format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
|
format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
|
||||||
end
|
end
|
||||||
@@ -147,17 +136,23 @@ class IssuesController < ApplicationController
|
|||||||
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?} } :
|
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 })
|
{ :action => 'show', :id => @issue })
|
||||||
}
|
}
|
||||||
format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
|
format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) }
|
||||||
|
format.json { render :text => @issue.to_json, :status => :created, :location => url_for(:controller => 'issues', :action => 'show'), :layout => false }
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :action => 'new' }
|
format.html { render :action => 'new' }
|
||||||
format.api { render_validation_errors(@issue) }
|
format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return }
|
||||||
|
format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
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
|
def edit
|
||||||
update_issue_from_params
|
update_issue_from_params
|
||||||
|
|
||||||
@@ -178,7 +173,8 @@ class IssuesController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
|
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
|
||||||
format.api { head :ok }
|
format.xml { head :ok }
|
||||||
|
format.json { head :ok }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render_attachment_warning_if_needed(@issue)
|
render_attachment_warning_if_needed(@issue)
|
||||||
@@ -187,7 +183,8 @@ class IssuesController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :action => 'edit' }
|
format.html { render :action => 'edit' }
|
||||||
format.api { render_validation_errors(@issue) }
|
format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
|
||||||
|
format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -195,10 +192,8 @@ class IssuesController < ApplicationController
|
|||||||
# Bulk edit a set of issues
|
# Bulk edit a set of issues
|
||||||
def bulk_edit
|
def bulk_edit
|
||||||
@issues.sort!
|
@issues.sort!
|
||||||
@available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
|
@available_statuses = Workflow.available_statuses(@project)
|
||||||
@custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
|
@custom_fields = @project.all_issue_custom_fields
|
||||||
@assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
|
|
||||||
@trackers = @projects.map(&:trackers).inject{|memo,t| memo & t}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_update
|
def bulk_update
|
||||||
@@ -237,32 +232,23 @@ class IssuesController < ApplicationController
|
|||||||
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
|
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# display the destroy form if it's a user request
|
unless params[:format] == 'xml' || params[:format] == 'json'
|
||||||
return unless api_request?
|
# display the destroy form if it's a user request
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@issues.each(&:destroy)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
|
format.html { redirect_to :action => 'index', :project_id => @project }
|
||||||
format.api { head :ok }
|
format.xml { head :ok }
|
||||||
|
format.json { head :ok }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_issue
|
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])
|
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
|
||||||
unless @issue.visible?
|
|
||||||
deny_access
|
|
||||||
return
|
|
||||||
end
|
|
||||||
@project = @issue.project
|
@project = @issue.project
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
@@ -282,12 +268,18 @@ private
|
|||||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||||
@priorities = IssuePriority.all
|
@priorities = IssuePriority.all
|
||||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||||
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
|
@time_entry = TimeEntry.new
|
||||||
@time_entry.attributes = params[:time_entry]
|
|
||||||
|
|
||||||
@notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
|
@notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
|
||||||
@issue.init_journal(User.current, @notes)
|
@issue.init_journal(User.current, @notes)
|
||||||
@issue.safe_attributes = params[:issue]
|
# 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.safe_attributes = attrs
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Refactor, lots of extra code in here
|
# TODO: Refactor, lots of extra code in here
|
||||||
@@ -302,20 +294,20 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
@issue.project = @project
|
@issue.project = @project
|
||||||
@issue.author = User.current
|
|
||||||
# Tracker must be set before custom field values
|
# Tracker must be set before custom field values
|
||||||
@issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
|
@issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
|
||||||
if @issue.tracker.nil?
|
if @issue.tracker.nil?
|
||||||
render_error l(:error_no_tracker_in_project)
|
render_error l(:error_no_tracker_in_project)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@issue.start_date ||= Date.today
|
|
||||||
if params[:issue].is_a?(Hash)
|
if params[:issue].is_a?(Hash)
|
||||||
@issue.safe_attributes = params[:issue]
|
@issue.safe_attributes = params[:issue]
|
||||||
if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record?
|
if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record?
|
||||||
@issue.watcher_user_ids = params[:issue]['watcher_user_ids']
|
@issue.watcher_user_ids = params[:issue]['watcher_user_ids']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@issue.author = User.current
|
||||||
|
@issue.start_date ||= Date.today
|
||||||
@priorities = IssuePriority.all
|
@priorities = IssuePriority.all
|
||||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# 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
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,15 +16,12 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class JournalsController < ApplicationController
|
class JournalsController < ApplicationController
|
||||||
before_filter :find_journal, :only => [:edit, :diff]
|
before_filter :find_journal, :only => [:edit]
|
||||||
before_filter :find_issue, :only => [:new]
|
before_filter :find_issue, :only => [:new]
|
||||||
before_filter :find_optional_project, :only => [:index]
|
before_filter :find_optional_project, :only => [:index]
|
||||||
before_filter :authorize, :only => [:new, :edit, :diff]
|
accept_key_auth :index
|
||||||
accept_rss_auth :index
|
|
||||||
menu_item :issues
|
|
||||||
|
|
||||||
helper :issues
|
helper :issues
|
||||||
helper :custom_fields
|
|
||||||
helper :queries
|
helper :queries
|
||||||
include QueriesHelper
|
include QueriesHelper
|
||||||
helper :sort
|
helper :sort
|
||||||
@@ -45,17 +42,6 @@ class JournalsController < ApplicationController
|
|||||||
render_404
|
render_404
|
||||||
end
|
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
|
def new
|
||||||
journal = Journal.find(params[:journal_id]) if params[:journal_id]
|
journal = Journal.find(params[:journal_id]) if params[:journal_id]
|
||||||
if journal
|
if journal
|
||||||
@@ -80,7 +66,6 @@ class JournalsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
(render_403; return false) unless @journal.editable_by?(User.current)
|
|
||||||
if request.post?
|
if request.post?
|
||||||
@journal.update_attributes(:notes => params[:notes]) if params[:notes]
|
@journal.update_attributes(:notes => params[:notes]) if params[:notes]
|
||||||
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
|
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
|
||||||
@@ -89,21 +74,13 @@ class JournalsController < ApplicationController
|
|||||||
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
|
||||||
format.js { render :action => 'update' }
|
format.js { render :action => 'update' }
|
||||||
end
|
end
|
||||||
else
|
|
||||||
respond_to do |format|
|
|
||||||
format.html {
|
|
||||||
# TODO: implement non-JS journal update
|
|
||||||
render :nothing => true
|
|
||||||
}
|
|
||||||
format.js
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_journal
|
def find_journal
|
||||||
@journal = Journal.find(params[:id])
|
@journal = Journal.find(params[:id])
|
||||||
|
(render_403; return false) unless @journal.editable_by?(User.current)
|
||||||
@project = @journal.journalized.project
|
@project = @journal.journalized.project
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# 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
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ class MyController < ApplicationController
|
|||||||
before_filter :require_login
|
before_filter :require_login
|
||||||
|
|
||||||
helper :issues
|
helper :issues
|
||||||
helper :users
|
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
|
|
||||||
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
||||||
@@ -54,18 +53,25 @@ class MyController < ApplicationController
|
|||||||
@user = User.current
|
@user = User.current
|
||||||
@pref = @user.pref
|
@pref = @user.pref
|
||||||
if request.post?
|
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.attributes = params[:pref]
|
||||||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
||||||
if @user.save
|
if @user.save
|
||||||
@user.pref.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
|
set_language_if_valid @user.language
|
||||||
flash[:notice] = l(:notice_account_updated)
|
flash[:notice] = l(:notice_account_updated)
|
||||||
redirect_to :action => 'account'
|
redirect_to :action => 'account'
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
# Manage user's password
|
# Manage user's password
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -18,37 +18,23 @@
|
|||||||
class NewsController < ApplicationController
|
class NewsController < ApplicationController
|
||||||
default_search_scope :news
|
default_search_scope :news
|
||||||
model_object News
|
model_object News
|
||||||
before_filter :find_model_object, :except => [:new, :create, :index]
|
before_filter :find_model_object, :except => [:new, :index, :preview]
|
||||||
before_filter :find_project_from_association, :except => [:new, :create, :index]
|
before_filter :find_project_from_association, :except => [:new, :index, :preview]
|
||||||
before_filter :find_project, :only => [:new, :create]
|
before_filter :find_project, :only => [:new, :preview]
|
||||||
before_filter :authorize, :except => [:index]
|
before_filter :authorize, :except => [:index, :preview]
|
||||||
before_filter :find_optional_project, :only => :index
|
before_filter :find_optional_project, :only => :index
|
||||||
accept_rss_auth :index
|
accept_key_auth :index
|
||||||
accept_api_auth :index
|
|
||||||
|
|
||||||
helper :watchers
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
case params[:format]
|
@news_pages, @newss = paginate :news,
|
||||||
when 'xml', 'json'
|
:per_page => 10,
|
||||||
@offset, @limit = api_offset_and_limit
|
:conditions => Project.allowed_to_condition(User.current, :view_news, :project => @project),
|
||||||
else
|
:include => [:author, :project],
|
||||||
@limit = 10
|
:order => "#{News.table_name}.created_on DESC"
|
||||||
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)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => false if request.xhr? }
|
format.html { render :layout => false if request.xhr? }
|
||||||
format.api
|
format.xml { render :xml => @newss.to_xml }
|
||||||
|
format.json { render :json => @newss.to_json }
|
||||||
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -60,38 +46,49 @@ class NewsController < ApplicationController
|
|||||||
|
|
||||||
def new
|
def new
|
||||||
@news = News.new(:project => @project, :author => User.current)
|
@news = News.new(:project => @project, :author => User.current)
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@news = News.new(:project => @project, :author => User.current)
|
|
||||||
if request.post?
|
if request.post?
|
||||||
@news.attributes = params[:news]
|
@news.attributes = params[:news]
|
||||||
if @news.save
|
if @news.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :controller => 'news', :action => 'index', :project_id => @project
|
redirect_to :controller => 'news', :action => 'index', :project_id => @project
|
||||||
else
|
|
||||||
render :action => 'new'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
end
|
if request.post? and @news.update_attributes(params[:news])
|
||||||
|
|
||||||
def update
|
|
||||||
if request.put? and @news.update_attributes(params[:news])
|
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'show', :id => @news
|
redirect_to :action => 'show', :id => @news
|
||||||
else
|
|
||||||
render :action => 'edit'
|
|
||||||
end
|
end
|
||||||
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
|
||||||
|
show
|
||||||
|
render :action => 'show'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy_comment
|
||||||
|
@news.comments.find(params[:comment_id]).destroy
|
||||||
|
redirect_to :action => 'show', :id => @news
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@news.destroy
|
@news.destroy
|
||||||
redirect_to :action => 'index', :project_id => @project
|
redirect_to :action => 'index', :project_id => @project
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def preview
|
||||||
|
@text = (params[:news] ? params[:news][:description] : nil)
|
||||||
|
render :partial => 'common/preview'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@project = Project.find(params[:project_id])
|
@project = Project.find(params[:project_id])
|
||||||
|
|||||||
@@ -1,20 +1,3 @@
|
|||||||
# 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
|
class PreviewsController < ApplicationController
|
||||||
before_filter :find_project
|
before_filter :find_project
|
||||||
|
|
||||||
@@ -33,11 +16,6 @@ class PreviewsController < ApplicationController
|
|||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def news
|
|
||||||
@text = (params[:news] ? params[:news][:description] : nil)
|
|
||||||
render :partial => 'common/preview'
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
class ProjectEnumerationsController < ApplicationController
|
class ProjectEnumerationsController < ApplicationController
|
||||||
before_filter :find_project_by_project_id
|
before_filter :find_project
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
||||||
def update
|
def save
|
||||||
if request.put? && params[:enumerations]
|
if request.post? && params[:enumerations]
|
||||||
Project.transaction do
|
Project.transaction do
|
||||||
params[:enumerations].each do |id, activity|
|
params[:enumerations].each do |id, activity|
|
||||||
@project.update_or_create_time_entry_activity(id, activity)
|
@project.update_or_create_time_entry_activity(id, activity)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -24,8 +24,7 @@ class ProjectsController < ApplicationController
|
|||||||
before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
|
before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
|
||||||
before_filter :authorize_global, :only => [:new, :create]
|
before_filter :authorize_global, :only => [:new, :create]
|
||||||
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
|
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
|
||||||
accept_rss_auth :index
|
accept_key_auth :index
|
||||||
accept_api_auth :index, :show, :create, :update, :destroy
|
|
||||||
|
|
||||||
after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
|
after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
|
||||||
if controller.request.post?
|
if controller.request.post?
|
||||||
@@ -33,6 +32,9 @@ class ProjectsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: convert to PUT only
|
||||||
|
verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
||||||
|
|
||||||
helper :sort
|
helper :sort
|
||||||
include SortHelper
|
include SortHelper
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
@@ -50,10 +52,8 @@ class ProjectsController < ApplicationController
|
|||||||
format.html {
|
format.html {
|
||||||
@projects = Project.visible.find(:all, :order => 'lft')
|
@projects = Project.visible.find(:all, :order => 'lft')
|
||||||
}
|
}
|
||||||
format.api {
|
format.xml {
|
||||||
@offset, @limit = api_offset_and_limit
|
@projects = Project.visible.find(:all, :order => 'lft')
|
||||||
@project_count = Project.visible.count
|
|
||||||
@projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft')
|
|
||||||
}
|
}
|
||||||
format.atom {
|
format.atom {
|
||||||
projects = Project.visible.find(:all, :order => 'created_on DESC',
|
projects = Project.visible.find(:all, :order => 'created_on DESC',
|
||||||
@@ -67,15 +67,19 @@ class ProjectsController < ApplicationController
|
|||||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
@trackers = Tracker.all
|
@trackers = Tracker.all
|
||||||
@project = Project.new(params[:project])
|
@project = Project.new(params[:project])
|
||||||
|
|
||||||
|
@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 = Setting.default_projects_modules
|
||||||
end
|
end
|
||||||
|
|
||||||
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
|
||||||
def create
|
def create
|
||||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
@trackers = Tracker.all
|
@trackers = Tracker.all
|
||||||
@project = Project.new
|
@project = Project.new(params[:project])
|
||||||
@project.safe_attributes = params[:project]
|
|
||||||
|
|
||||||
|
@project.enabled_module_names = params[:enabled_modules]
|
||||||
if validate_parent_id && @project.save
|
if validate_parent_id && @project.save
|
||||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
@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
|
# Add current user as a project member if he is not admin
|
||||||
@@ -89,12 +93,12 @@ class ProjectsController < ApplicationController
|
|||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project
|
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) }
|
format.xml { head :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :action => 'new' }
|
format.html { render :action => 'new' }
|
||||||
format.api { render_validation_errors(@project) }
|
format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -116,18 +120,18 @@ class ProjectsController < ApplicationController
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
Mailer.with_deliveries(params[:notifications] == '1') do
|
Mailer.with_deliveries(params[:notifications] == '1') do
|
||||||
@project = Project.new
|
@project = Project.new(params[:project])
|
||||||
@project.safe_attributes = params[:project]
|
@project.enabled_module_names = params[:enabled_modules]
|
||||||
if validate_parent_id && @project.copy(@source_project, :only => params[:only])
|
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')
|
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project
|
redirect_to :controller => 'projects', :action => 'settings'
|
||||||
elsif !@project.new_record?
|
elsif !@project.new_record?
|
||||||
# Project was created
|
# Project was created
|
||||||
# But some objects were not copied due to validation failures
|
# But some objects were not copied due to validation failures
|
||||||
# (eg. issues from disabled trackers)
|
# (eg. issues from disabled trackers)
|
||||||
# TODO: inform about that
|
# TODO: inform about that
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project
|
redirect_to :controller => 'projects', :action => 'settings'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -143,7 +147,7 @@ class ProjectsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
@users_by_role = @project.users_by_role
|
@users_by_role = @project.users_by_role
|
||||||
@subprojects = @project.children.visible.all
|
@subprojects = @project.children.visible
|
||||||
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
||||||
@trackers = @project.rolled_up_trackers
|
@trackers = @project.rolled_up_trackers
|
||||||
|
|
||||||
@@ -156,15 +160,16 @@ class ProjectsController < ApplicationController
|
|||||||
:include => [:project, :status, :tracker],
|
:include => [:project, :status, :tracker],
|
||||||
:conditions => cond)
|
:conditions => cond)
|
||||||
|
|
||||||
if User.current.allowed_to?(:view_time_entries, @project)
|
TimeEntry.visible_by(User.current) do
|
||||||
@total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
|
@total_hours = TimeEntry.sum(:hours,
|
||||||
|
:include => :project,
|
||||||
|
:conditions => cond).to_f
|
||||||
end
|
end
|
||||||
|
|
||||||
@key = User.current.rss_key
|
@key = User.current.rss_key
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
format.api
|
format.xml
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -180,10 +185,8 @@ class ProjectsController < ApplicationController
|
|||||||
def edit
|
def edit
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: convert to PUT only
|
|
||||||
verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
|
||||||
def update
|
def update
|
||||||
@project.safe_attributes = params[:project]
|
@project.attributes = params[:project]
|
||||||
if validate_parent_id && @project.save
|
if validate_parent_id && @project.save
|
||||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
@@ -191,7 +194,7 @@ class ProjectsController < ApplicationController
|
|||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'settings', :id => @project
|
redirect_to :action => 'settings', :id => @project
|
||||||
}
|
}
|
||||||
format.api { head :ok }
|
format.xml { head :ok }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
@@ -199,14 +202,13 @@ class ProjectsController < ApplicationController
|
|||||||
settings
|
settings
|
||||||
render :action => 'settings'
|
render :action => 'settings'
|
||||||
}
|
}
|
||||||
format.api { render_validation_errors(@project) }
|
format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
verify :method => :post, :only => :modules, :render => {:nothing => true, :status => :method_not_allowed }
|
|
||||||
def modules
|
def modules
|
||||||
@project.enabled_module_names = params[:enabled_module_names]
|
@project.enabled_module_names = params[:enabled_modules]
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'settings', :id => @project, :tab => 'modules'
|
redirect_to :action => 'settings', :id => @project, :tab => 'modules'
|
||||||
end
|
end
|
||||||
@@ -231,11 +233,11 @@ class ProjectsController < ApplicationController
|
|||||||
if request.get?
|
if request.get?
|
||||||
# display confirmation view
|
# display confirmation view
|
||||||
else
|
else
|
||||||
if api_request? || params[:confirm]
|
if params[:format] == 'xml' || params[:confirm]
|
||||||
@project_to_destroy.destroy
|
@project_to_destroy.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :controller => 'admin', :action => 'projects' }
|
format.html { redirect_to :controller => 'admin', :action => 'projects' }
|
||||||
format.api { head :ok }
|
format.xml { head :ok }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,12 +25,11 @@ class QueriesController < ApplicationController
|
|||||||
@query.project = params[:query_is_for_all] ? nil : @project
|
@query.project = params[:query_is_for_all] ? nil : @project
|
||||||
@query.user = User.current
|
@query.user = User.current
|
||||||
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
@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.column_names = nil if params[:default_columns]
|
@query.column_names = nil if params[:default_columns]
|
||||||
|
|
||||||
|
@query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
|
||||||
|
@query.group_by ||= params[:group_by]
|
||||||
|
|
||||||
if request.post? && params[:confirm] && @query.save
|
if request.post? && params[:confirm] && @query.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
|
redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
|
||||||
@@ -42,12 +41,10 @@ class QueriesController < ApplicationController
|
|||||||
def edit
|
def edit
|
||||||
if request.post?
|
if request.post?
|
||||||
@query.filters = {}
|
@query.filters = {}
|
||||||
@query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f]
|
@query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
|
||||||
@query.attributes = params[:query]
|
@query.attributes = params[:query]
|
||||||
@query.project = nil if params[:query_is_for_all]
|
@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.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.column_names = nil if params[:default_columns]
|
@query.column_names = nil if params[:default_columns]
|
||||||
|
|
||||||
if @query.save
|
if @query.save
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -30,36 +30,24 @@ class RepositoriesController < ApplicationController
|
|||||||
before_filter :find_repository, :except => :edit
|
before_filter :find_repository, :except => :edit
|
||||||
before_filter :find_project, :only => :edit
|
before_filter :find_project, :only => :edit
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
accept_rss_auth :revisions
|
accept_key_auth :revisions
|
||||||
|
|
||||||
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
|
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@repository = @project.repository
|
@repository = @project.repository
|
||||||
if !@repository && !params[:repository_scm].blank?
|
if !@repository
|
||||||
@repository = Repository.factory(params[:repository_scm])
|
@repository = Repository.factory(params[:repository_scm])
|
||||||
@repository.project = @project if @repository
|
@repository.project = @project if @repository
|
||||||
end
|
end
|
||||||
if request.post? && @repository
|
if request.post? && @repository
|
||||||
p1 = params[:repository]
|
@repository.attributes = 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.save
|
@repository.save
|
||||||
end
|
end
|
||||||
render(:update) do |page|
|
render(:update) do |page|
|
||||||
page.replace_html "tab-content-repository",
|
page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'
|
||||||
:partial => 'projects/settings/repository'
|
|
||||||
if @repository && !@project.repository
|
if @repository && !@project.repository
|
||||||
@project.reload # needed to reload association
|
@project.reload #needed to reload association
|
||||||
page.replace_html "main-menu", render_main_menu(@project)
|
page.replace_html "main-menu", render_main_menu(@project)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -82,17 +70,13 @@ class RepositoriesController < ApplicationController
|
|||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@repository.destroy
|
@repository.destroy
|
||||||
redirect_to :controller => 'projects',
|
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
|
||||||
:action => 'settings',
|
|
||||||
:id => @project,
|
|
||||||
:tab => 'repository'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
||||||
|
|
||||||
@entries = @repository.entries(@path, @rev)
|
@entries = @repository.entries(@path, @rev)
|
||||||
@changeset = @repository.find_changeset_by_name(@rev)
|
|
||||||
if request.xhr?
|
if request.xhr?
|
||||||
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
||||||
else
|
else
|
||||||
@@ -110,18 +94,17 @@ class RepositoriesController < ApplicationController
|
|||||||
(show_error_not_found; return) unless @entry
|
(show_error_not_found; return) unless @entry
|
||||||
@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
|
@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
|
||||||
@properties = @repository.properties(@path, @rev)
|
@properties = @repository.properties(@path, @rev)
|
||||||
@changeset = @repository.find_changeset_by_name(@rev)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def revisions
|
def revisions
|
||||||
@changeset_count = @repository.changesets.count
|
@changeset_count = @repository.changesets.count
|
||||||
@changeset_pages = Paginator.new self, @changeset_count,
|
@changeset_pages = Paginator.new self, @changeset_count,
|
||||||
per_page_option,
|
per_page_option,
|
||||||
params['page']
|
params['page']
|
||||||
@changesets = @repository.changesets.find(:all,
|
@changesets = @repository.changesets.find(:all,
|
||||||
:limit => @changeset_pages.items_per_page,
|
:limit => @changeset_pages.items_per_page,
|
||||||
:offset => @changeset_pages.current.offset,
|
:offset => @changeset_pages.current.offset,
|
||||||
:include => [:user, :repository])
|
:include => [:user, :repository])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => false if request.xhr? }
|
format.html { render :layout => false if request.xhr? }
|
||||||
@@ -138,46 +121,24 @@ class RepositoriesController < ApplicationController
|
|||||||
|
|
||||||
@content = @repository.cat(@path, @rev)
|
@content = @repository.cat(@path, @rev)
|
||||||
(show_error_not_found; return) unless @content
|
(show_error_not_found; return) unless @content
|
||||||
if 'raw' == params[:format] ||
|
if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte)
|
||||||
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
|
|
||||||
! is_entry_text_data?(@content, @path)
|
|
||||||
# Force the download
|
# Force the download
|
||||||
send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
|
send_data @content, :filename => @path.split('/').last
|
||||||
send_type = Redmine::MimeType.of(@path)
|
|
||||||
send_opt[:type] = send_type.to_s if send_type
|
|
||||||
send_data @content, send_opt
|
|
||||||
else
|
else
|
||||||
# Prevent empty lines when displaying a file with Windows style eol
|
# 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")
|
@content.gsub!("\r\n", "\n")
|
||||||
@changeset = @repository.find_changeset_by_name(@rev)
|
end
|
||||||
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
|
def annotate
|
||||||
@entry = @repository.entry(@path, @rev)
|
@entry = @repository.entry(@path, @rev)
|
||||||
(show_error_not_found; return) unless @entry
|
(show_error_not_found; return) unless @entry
|
||||||
|
|
||||||
@annotate = @repository.scm.annotate(@path, @rev)
|
@annotate = @repository.scm.annotate(@path, @rev)
|
||||||
(render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
|
(render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
|
||||||
@changeset = @repository.find_changeset_by_name(@rev)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def revision
|
def revision
|
||||||
raise ChangesetNotFound if @rev.blank?
|
|
||||||
@changeset = @repository.find_changeset_by_name(@rev)
|
@changeset = @repository.find_changeset_by_name(@rev)
|
||||||
raise ChangesetNotFound unless @changeset
|
raise ChangesetNotFound unless @changeset
|
||||||
|
|
||||||
@@ -207,16 +168,12 @@ class RepositoriesController < ApplicationController
|
|||||||
User.current.pref[:diff_type] = @diff_type
|
User.current.pref[:diff_type] = @diff_type
|
||||||
User.current.preference.save
|
User.current.preference.save
|
||||||
end
|
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)
|
unless read_fragment(@cache_key)
|
||||||
@diff = @repository.diff(@path, @rev, @rev_to)
|
@diff = @repository.diff(@path, @rev, @rev_to)
|
||||||
show_error_not_found unless @diff
|
show_error_not_found unless @diff
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -239,10 +196,7 @@ class RepositoriesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
|
|
||||||
|
|
||||||
def find_repository
|
def find_repository
|
||||||
@project = Project.find(params[:id])
|
@project = Project.find(params[:id])
|
||||||
@repository = @project.repository
|
@repository = @project.repository
|
||||||
@@ -251,12 +205,6 @@ class RepositoriesController < ApplicationController
|
|||||||
@path ||= ''
|
@path ||= ''
|
||||||
@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip
|
@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip
|
||||||
@rev_to = params[:rev_to]
|
@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
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
rescue InvalidRevisionParam
|
rescue InvalidRevisionParam
|
||||||
@@ -264,7 +212,7 @@ class RepositoriesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show_error_not_found
|
def show_error_not_found
|
||||||
render_error :message => l(:error_scm_not_found), :status => 404
|
render_error l(:error_scm_not_found)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Handler for Redmine::Scm::Adapters::CommandFailed exception
|
# Handler for Redmine::Scm::Adapters::CommandFailed exception
|
||||||
@@ -276,15 +224,11 @@ class RepositoriesController < ApplicationController
|
|||||||
@date_to = Date.today
|
@date_to = Date.today
|
||||||
@date_from = @date_to << 11
|
@date_from = @date_to << 11
|
||||||
@date_from = Date.civil(@date_from.year, @date_from.month, 1)
|
@date_from = Date.civil(@date_from.year, @date_from.month, 1)
|
||||||
commits_by_day = repository.changesets.count(
|
commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
|
||||||
:all, :group => :commit_date,
|
|
||||||
:conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
|
|
||||||
commits_by_month = [0] * 12
|
commits_by_month = [0] * 12
|
||||||
commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
|
commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
|
||||||
|
|
||||||
changes_by_day = repository.changes.count(
|
changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
|
||||||
:all, :group => :commit_date,
|
|
||||||
:conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
|
|
||||||
changes_by_month = [0] * 12
|
changes_by_month = [0] * 12
|
||||||
changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
|
changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
|
||||||
|
|
||||||
@@ -345,16 +289,20 @@ class RepositoriesController < ApplicationController
|
|||||||
:graph_title => l(:label_commits_per_author),
|
:graph_title => l(:label_commits_per_author),
|
||||||
:show_graph_title => true
|
:show_graph_title => true
|
||||||
)
|
)
|
||||||
|
|
||||||
graph.add_data(
|
graph.add_data(
|
||||||
:data => commits_data,
|
:data => commits_data,
|
||||||
:title => l(:label_revision_plural)
|
:title => l(:label_revision_plural)
|
||||||
)
|
)
|
||||||
|
|
||||||
graph.add_data(
|
graph.add_data(
|
||||||
:data => changes_data,
|
:data => changes_data,
|
||||||
:title => l(:label_change_plural)
|
:title => l(:label_change_plural)
|
||||||
)
|
)
|
||||||
|
|
||||||
graph.burn
|
graph.burn
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Date
|
class Date
|
||||||
|
|||||||
@@ -38,10 +38,9 @@ class RolesController < ApplicationController
|
|||||||
end
|
end
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
else
|
|
||||||
@permissions = @role.setable_permissions
|
|
||||||
@roles = Role.find :all, :order => 'builtin, position'
|
|
||||||
end
|
end
|
||||||
|
@permissions = @role.setable_permissions
|
||||||
|
@roles = Role.find :all, :order => 'builtin, position'
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@@ -49,9 +48,8 @@ class RolesController < ApplicationController
|
|||||||
if request.post? and @role.update_attributes(params[:role])
|
if request.post? and @role.update_attributes(params[:role])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
else
|
|
||||||
@permissions = @role.setable_permissions
|
|
||||||
end
|
end
|
||||||
|
@permissions = @role.setable_permissions
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -24,8 +24,8 @@ class SearchController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
@question = params[:q] || ""
|
@question = params[:q] || ""
|
||||||
@question.strip!
|
@question.strip!
|
||||||
@all_words = params[:all_words] ? params[:all_words].present? : true
|
@all_words = params[:all_words] || (params[:submit] ? false : true)
|
||||||
@titles_only = params[:titles_only] ? params[:titles_only].present? : false
|
@titles_only = !params[:titles_only].nil?
|
||||||
|
|
||||||
projects_to_search =
|
projects_to_search =
|
||||||
case params[:scope]
|
case params[:scope]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -26,7 +26,7 @@ class SettingsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@notifiables = Redmine::Notifiable.all
|
@notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted wiki_content_added wiki_content_updated)
|
||||||
if request.post? && params[:settings] && params[:settings].is_a?(Hash)
|
if request.post? && params[:settings] && params[:settings].is_a?(Hash)
|
||||||
settings = (params[:settings] || {}).dup.symbolize_keys
|
settings = (params[:settings] || {}).dup.symbolize_keys
|
||||||
settings.each do |name, value|
|
settings.each do |name, value|
|
||||||
@@ -36,16 +36,14 @@ class SettingsController < ApplicationController
|
|||||||
end
|
end
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'edit', :tab => params[:tab]
|
redirect_to :action => 'edit', :tab => params[:tab]
|
||||||
else
|
return
|
||||||
@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
|
|
||||||
end
|
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 << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def plugin
|
def plugin
|
||||||
@@ -54,10 +52,9 @@ class SettingsController < ApplicationController
|
|||||||
Setting["plugin_#{@plugin.id}"] = params[:settings]
|
Setting["plugin_#{@plugin.id}"] = params[:settings]
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'plugin', :id => @plugin.id
|
redirect_to :action => 'plugin', :id => @plugin.id
|
||||||
else
|
|
||||||
@partial = @plugin.settings[:partial]
|
|
||||||
@settings = Setting["plugin_#{@plugin.id}"]
|
|
||||||
end
|
end
|
||||||
|
@partial = @plugin.settings[:partial]
|
||||||
|
@settings = Setting["plugin_#{@plugin.id}"]
|
||||||
rescue Redmine::PluginNotFound
|
rescue Redmine::PluginNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ class SysController < ActionController::Base
|
|||||||
|
|
||||||
def projects
|
def projects
|
||||||
p = Project.active.has_module(:repository).find(:all, :include => :repository, :order => 'identifier')
|
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(:include => :repository)
|
||||||
render :xml => p.to_xml(:only => [:id, :identifier, :name, :is_public, :status], :include => {:repository => {:only => [:id, :url]}})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_project_repository
|
def create_project_repository
|
||||||
@@ -32,7 +31,7 @@ class SysController < ActionController::Base
|
|||||||
logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
|
logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
|
||||||
project.repository = Repository.factory(params[:vendor], params[:repository])
|
project.repository = Repository.factory(params[:vendor], params[:repository])
|
||||||
if project.repository && project.repository.save
|
if project.repository && project.repository.save
|
||||||
render :xml => project.repository.to_xml(:only => [:id, :url]), :status => 201
|
render :xml => project.repository, :status => 201
|
||||||
else
|
else
|
||||||
render :nothing => true, :status => 422
|
render :nothing => true, :status => 422
|
||||||
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
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -17,13 +17,11 @@
|
|||||||
|
|
||||||
class TimelogController < ApplicationController
|
class TimelogController < ApplicationController
|
||||||
menu_item :issues
|
menu_item :issues
|
||||||
before_filter :find_project, :only => [:new, :create]
|
before_filter :find_project, :authorize, :only => [:edit, :destroy]
|
||||||
before_filter :find_time_entry, :only => [:show, :edit, :update]
|
before_filter :find_optional_project, :only => [:report, :details]
|
||||||
before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
|
before_filter :load_available_criterias, :only => [:report]
|
||||||
before_filter :authorize, :except => [:index]
|
|
||||||
before_filter :find_optional_project, :only => [:index]
|
verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
|
||||||
accept_rss_auth :index
|
|
||||||
accept_api_auth :index, :show, :create, :update, :destroy
|
|
||||||
|
|
||||||
helper :sort
|
helper :sort
|
||||||
include SortHelper
|
include SortHelper
|
||||||
@@ -32,7 +30,83 @@ class TimelogController < ApplicationController
|
|||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
include CustomFieldsHelper
|
include CustomFieldsHelper
|
||||||
|
|
||||||
def index
|
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
|
||||||
|
|
||||||
|
def details
|
||||||
sort_init 'spent_on', 'desc'
|
sort_init 'spent_on', 'desc'
|
||||||
sort_update 'spent_on' => 'spent_on',
|
sort_update 'spent_on' => 'spent_on',
|
||||||
'user' => 'user_id',
|
'user' => 'user_id',
|
||||||
@@ -42,215 +116,90 @@ class TimelogController < ApplicationController
|
|||||||
'hours' => 'hours'
|
'hours' => 'hours'
|
||||||
|
|
||||||
cond = ARCondition.new
|
cond = ARCondition.new
|
||||||
if @issue
|
if @project.nil?
|
||||||
cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
|
cond << Project.allowed_to_condition(User.current, :view_time_entries)
|
||||||
elsif @project
|
elsif @issue.nil?
|
||||||
cond << @project.project_condition(Setting.display_subprojects_issues?)
|
cond << @project.project_condition(Setting.display_subprojects_issues?)
|
||||||
|
else
|
||||||
|
cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
|
||||||
end
|
end
|
||||||
|
|
||||||
retrieve_date_range
|
retrieve_date_range
|
||||||
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
||||||
|
|
||||||
respond_to do |format|
|
TimeEntry.visible_by(User.current) do
|
||||||
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
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
flash[:notice] = l(:notice_successful_update)
|
# Paginate results
|
||||||
redirect_back_or_default :action => 'index', :project_id => @time_entry.project
|
@entry_count = TimeEntry.count(:include => [:project, :issue], :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, :issue], :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), :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
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@time_entry.attributes = params[:time_entry]
|
(render_403; return) if @time_entry && !@time_entry.editable_by?(User.current)
|
||||||
|
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
|
||||||
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]
|
@time_entry.attributes = params[:time_entry]
|
||||||
|
|
||||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
||||||
|
|
||||||
if @time_entry.save
|
if request.post? and @time_entry.save
|
||||||
respond_to do |format|
|
flash[:notice] = l(:notice_successful_update)
|
||||||
format.html {
|
redirect_back_or_default :action => 'details', :project_id => @time_entry.project
|
||||||
flash[:notice] = l(:notice_successful_update)
|
return
|
||||||
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
|
|
||||||
end
|
end
|
||||||
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
|
def destroy
|
||||||
@time_entries.each do |t|
|
(render_404; return) unless @time_entry
|
||||||
begin
|
(render_403; return) unless @time_entry.editable_by?(User.current)
|
||||||
unless t.destroy && t.destroyed?
|
if @time_entry.destroy && @time_entry.destroyed?
|
||||||
respond_to do |format|
|
flash[:notice] = l(:notice_successful_delete)
|
||||||
format.html {
|
else
|
||||||
flash[:error] = l(:notice_unable_delete_time_entry)
|
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
|
end
|
||||||
|
redirect_to :back
|
||||||
|
rescue ::ActionController::RedirectBackError
|
||||||
|
redirect_to :action => 'details', :project_id => @time_entry.project
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
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
|
def find_project
|
||||||
if (issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id])).present?
|
if params[:id]
|
||||||
@issue = Issue.find(issue_id)
|
@time_entry = TimeEntry.find(params[:id])
|
||||||
|
@project = @time_entry.project
|
||||||
|
elsif params[:issue_id]
|
||||||
|
@issue = Issue.find(params[:issue_id])
|
||||||
@project = @issue.project
|
@project = @issue.project
|
||||||
elsif (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
|
elsif params[:project_id]
|
||||||
@project = Project.find(project_id)
|
@project = Project.find(params[:project_id])
|
||||||
else
|
else
|
||||||
render_404
|
render_404
|
||||||
return false
|
return false
|
||||||
@@ -315,10 +264,61 @@ private
|
|||||||
@to ||= (TimeEntry.latest_date_for_project(@project) || Date.today)
|
@to ||= (TimeEntry.latest_date_for_project(@project) || Date.today)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_params_for_bulk_time_entry_attributes(params)
|
def load_available_criterias
|
||||||
attributes = (params[:time_entry] || {}).reject {|k,v| v.blank?}
|
@available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
|
||||||
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
|
:klass => Project,
|
||||||
attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
|
:label => :label_project},
|
||||||
attributes
|
'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"
|
||||||
|
call_hook(:controller_timelog_time_report_joins, {:sql => sql} )
|
||||||
|
sql
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -19,8 +19,6 @@ class UsersController < ApplicationController
|
|||||||
layout 'admin'
|
layout 'admin'
|
||||||
|
|
||||||
before_filter :require_admin, :except => :show
|
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
|
|
||||||
|
|
||||||
helper :sort
|
helper :sort
|
||||||
include SortHelper
|
include SortHelper
|
||||||
@@ -31,16 +29,6 @@ class UsersController < ApplicationController
|
|||||||
sort_init 'login', 'asc'
|
sort_init 'login', 'asc'
|
||||||
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
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
|
@status = params[:status] ? params[:status].to_i : 1
|
||||||
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
||||||
|
|
||||||
@@ -49,27 +37,24 @@ class UsersController < ApplicationController
|
|||||||
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 ? OR LOWER(mail) LIKE ?", name, name, name, name]
|
||||||
end
|
end
|
||||||
|
|
||||||
@user_count = scope.count(:conditions => c.conditions)
|
@user_count = User.count(:conditions => c.conditions)
|
||||||
@user_pages = Paginator.new self, @user_count, @limit, params['page']
|
@user_pages = Paginator.new self, @user_count,
|
||||||
@offset ||= @user_pages.current.offset
|
per_page_option,
|
||||||
@users = scope.find :all,
|
params['page']
|
||||||
:order => sort_clause,
|
@users = User.find :all,:order => sort_clause,
|
||||||
:conditions => c.conditions,
|
:conditions => c.conditions,
|
||||||
:limit => @limit,
|
:limit => @user_pages.items_per_page,
|
||||||
:offset => @offset
|
:offset => @user_pages.current.offset
|
||||||
|
|
||||||
respond_to do |format|
|
render :layout => !request.xhr?
|
||||||
format.html {
|
|
||||||
@groups = Group.all.sort
|
|
||||||
render :layout => !request.xhr?
|
|
||||||
}
|
|
||||||
format.api
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@user = User.find(params[:id])
|
||||||
|
@custom_values = @user.custom_values
|
||||||
|
|
||||||
# show projects based on current user visibility
|
# show projects based on current user visibility
|
||||||
@memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
@memberships = @user.memberships.all(:conditions => Project.visible_by(User.current))
|
||||||
|
|
||||||
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
|
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
|
||||||
@events_by_day = events.group_by(&:event_date)
|
@events_by_day = events.group_by(&:event_date)
|
||||||
@@ -80,119 +65,61 @@ class UsersController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
render :layout => 'base'
|
||||||
|
|
||||||
respond_to do |format|
|
rescue ActiveRecord::RecordNotFound
|
||||||
format.html { render :layout => 'base' }
|
render_404
|
||||||
format.api
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def add
|
||||||
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
|
if request.get?
|
||||||
@auth_sources = AuthSource.find(:all)
|
@user = User.new(:language => Setting.default_language)
|
||||||
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
|
|
||||||
else
|
else
|
||||||
@auth_sources = AuthSource.find(:all)
|
@user = User.new(params[:user])
|
||||||
# Clear password input
|
@user.admin = params[:user][:admin] || false
|
||||||
@user.password = @user.password_confirmation = nil
|
@user.login = params[:user][:login]
|
||||||
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
|
||||||
respond_to do |format|
|
if @user.save
|
||||||
format.html { render :action => 'new' }
|
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
|
||||||
format.api { render_validation_errors(@user) }
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} :
|
||||||
|
{:controller => 'users', :action => 'edit', :id => @user})
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@auth_sources = AuthSource.find(:all)
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
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]
|
||||||
|
if params[:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
|
||||||
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
|
||||||
|
end
|
||||||
|
@user.group_ids = params[:user][:group_ids] if params[:user][:group_ids]
|
||||||
|
@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
|
||||||
|
if was_activated
|
||||||
|
Mailer.deliver_account_activated(@user)
|
||||||
|
elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil?
|
||||||
|
Mailer.deliver_account_information(@user, params[:password])
|
||||||
|
end
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to :back
|
||||||
|
end
|
||||||
|
end
|
||||||
@auth_sources = AuthSource.find(:all)
|
@auth_sources = AuthSource.find(:all)
|
||||||
@membership ||= Member.new
|
@membership ||= Member.new
|
||||||
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
|
rescue ::ActionController::RedirectBackError
|
||||||
redirect_to :controller => 'users', :action => 'edit', :id => @user
|
redirect_to :controller => 'users', :action => 'edit', :id => @user
|
||||||
end
|
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
|
def edit_membership
|
||||||
|
@user = User.find(params[:id])
|
||||||
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
|
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
|
||||||
@membership.save if request.post?
|
@membership.save if request.post?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
@@ -215,6 +142,7 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy_membership
|
def destroy_membership
|
||||||
|
@user = User.find(params[:id])
|
||||||
@membership = Member.find(params[:membership_id])
|
@membership = Member.find(params[:membership_id])
|
||||||
if request.post? && @membership.deletable?
|
if request.post? && @membership.deletable?
|
||||||
@membership.destroy
|
@membership.destroy
|
||||||
@@ -224,17 +152,4 @@ class UsersController < ApplicationController
|
|||||||
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} }
|
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} }
|
||||||
end
|
end
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -103,22 +103,18 @@ class VersionsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if request.put? && params[:version]
|
if request.post? && params[:version]
|
||||||
attributes = params[:version].dup
|
attributes = params[:version].dup
|
||||||
attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
|
attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
|
||||||
if @version.update_attributes(attributes)
|
if @version.update_attributes(attributes)
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||||
else
|
|
||||||
respond_to do |format|
|
|
||||||
format.html { render :action => 'edit' }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def close_completed
|
def close_completed
|
||||||
if request.put?
|
if request.post?
|
||||||
@project.close_completed_versions
|
@project.close_completed_versions
|
||||||
end
|
end
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -76,13 +76,21 @@ private
|
|||||||
|
|
||||||
def set_watcher(user, watching)
|
def set_watcher(user, watching)
|
||||||
@watched.set_watcher(user, watching)
|
@watched.set_watcher(user, watching)
|
||||||
|
if params[:replace].present?
|
||||||
|
if params[:replace].is_a? Array
|
||||||
|
replace_ids = params[:replace]
|
||||||
|
else
|
||||||
|
replace_ids = [params[:replace]]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
replace_ids = ['watcher']
|
||||||
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :back }
|
format.html { redirect_to :back }
|
||||||
format.js do
|
format.js do
|
||||||
render(:update) do |page|
|
render(:update) do |page|
|
||||||
c = watcher_css(@watched)
|
replace_ids.each do |replace_id|
|
||||||
page.select(".#{c}").each do |item|
|
page.replace_html replace_id, watcher_link(@watched, user, :replace => replace_ids)
|
||||||
page.replace_html item, watcher_link(@watched, user)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -17,44 +17,21 @@
|
|||||||
|
|
||||||
require 'diff'
|
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
|
class WikiController < ApplicationController
|
||||||
default_search_scope :wiki_pages
|
default_search_scope :wiki_pages
|
||||||
before_filter :find_wiki, :authorize
|
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]
|
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
|
helper :attachments
|
||||||
include AttachmentsHelper
|
include AttachmentsHelper
|
||||||
helper :watchers
|
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
|
|
||||||
|
|
||||||
# display a page (in editing mode if it doesn't exist)
|
# 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 @page.new_record?
|
||||||
if User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
|
if User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
|
||||||
edit
|
edit
|
||||||
@@ -86,6 +63,7 @@ class WikiController < ApplicationController
|
|||||||
|
|
||||||
# edit an existing page or a new one
|
# edit an existing page or a new one
|
||||||
def edit
|
def edit
|
||||||
|
@page = @wiki.find_or_new_page(params[:page])
|
||||||
return render_403 unless editable?
|
return render_403 unless editable?
|
||||||
@page.content = WikiContent.new(:page => @page) if @page.new_record?
|
@page.content = WikiContent.new(:page => @page) if @page.new_record?
|
||||||
|
|
||||||
@@ -93,45 +71,32 @@ class WikiController < ApplicationController
|
|||||||
@content.text = initial_page_content(@page) if @content.text.blank?
|
@content.text = initial_page_content(@page) if @content.text.blank?
|
||||||
# don't keep previous comment
|
# don't keep previous comment
|
||||||
@content.comments = nil
|
@content.comments = nil
|
||||||
|
if request.get?
|
||||||
# To prevent StaleObjectError exception when reverting to a previous version
|
# To prevent StaleObjectError exception when reverting to a previous version
|
||||||
@content.version = @page.content.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
|
|
||||||
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
|
|
||||||
else
|
else
|
||||||
render :action => 'edit'
|
if !@page.new_record? && @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 => '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)
|
||||||
|
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 => 'index', :id => @project, :page => @page.title
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue ActiveRecord::StaleObjectError
|
rescue ActiveRecord::StaleObjectError
|
||||||
# Optimistic locking exception
|
# Optimistic locking exception
|
||||||
flash.now[:error] = l(:notice_locking_conflict)
|
flash[:error] = l(:notice_locking_conflict)
|
||||||
render :action => 'edit'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# rename a page
|
# rename a page
|
||||||
@@ -142,14 +107,13 @@ class WikiController < ApplicationController
|
|||||||
@original_title = @page.pretty_title
|
@original_title = @page.pretty_title
|
||||||
if request.post? && @page.update_attributes(params[:wiki_page])
|
if request.post? && @page.update_attributes(params[:wiki_page])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
verify :method => :post, :only => :protect, :redirect_to => { :action => :show }
|
|
||||||
def protect
|
def protect
|
||||||
@page.update_attribute :protected, params[:protected]
|
@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
|
end
|
||||||
|
|
||||||
# show page history
|
# show page history
|
||||||
@@ -176,7 +140,6 @@ class WikiController < ApplicationController
|
|||||||
render_404 unless @annotate
|
render_404 unless @annotate
|
||||||
end
|
end
|
||||||
|
|
||||||
verify :method => :delete, :only => [:destroy], :redirect_to => { :action => :show }
|
|
||||||
# Removes a wiki page and its history
|
# Removes a wiki page and its history
|
||||||
# Children can be either set as root pages, removed or reassigned to another parent page
|
# Children can be either set as root pages, removed or reassigned to another parent page
|
||||||
def destroy
|
def destroy
|
||||||
@@ -203,22 +166,41 @@ class WikiController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
@page.destroy
|
@page.destroy
|
||||||
redirect_to :action => 'index', :project_id => @project
|
redirect_to :action => 'special', :id => @project, :page => 'Page_index'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Export wiki to a single html file
|
# display special pages
|
||||||
def export
|
def special
|
||||||
if User.current.allowed_to?(:export_wiki_pages, @project)
|
page_title = params[:page].downcase
|
||||||
@pages = @wiki.pages.find :all, :order => 'title'
|
case page_title
|
||||||
export = render_to_string :action => 'export_multiple', :layout => false
|
# show pages index, sorted by title
|
||||||
send_data(export, :type => 'text/html', :filename => "wiki.html")
|
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'
|
||||||
|
if User.current.allowed_to?(:export_wiki_pages, @project)
|
||||||
|
@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")
|
||||||
|
else
|
||||||
|
redirect_to :action => 'index', :id => @project, :page => nil
|
||||||
|
end
|
||||||
|
return
|
||||||
else
|
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
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
render :action => "special_#{page_title}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview
|
def preview
|
||||||
page = @wiki.find_page(params[:id])
|
page = @wiki.find_page(params[:page])
|
||||||
# page is nil when previewing a new page
|
# page is nil when previewing a new page
|
||||||
return render_403 unless page.nil? || editable?(page)
|
return render_403 unless page.nil? || editable?(page)
|
||||||
if page
|
if page
|
||||||
@@ -233,37 +215,23 @@ class WikiController < ApplicationController
|
|||||||
return render_403 unless editable?
|
return render_403 unless editable?
|
||||||
attachments = Attachment.attach_files(@page, params[:attachments])
|
attachments = Attachment.attach_files(@page, params[:attachments])
|
||||||
render_attachment_warning_if_needed(@page)
|
render_attachment_warning_if_needed(@page)
|
||||||
redirect_to :action => 'show', :id => @page.title, :project_id => @project
|
redirect_to :action => 'index', :page => @page.title
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_wiki
|
def find_wiki
|
||||||
@project = Project.find(params[:project_id])
|
@project = Project.find(params[:id])
|
||||||
@wiki = @project.wiki
|
@wiki = @project.wiki
|
||||||
render_404 unless @wiki
|
render_404 unless @wiki
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
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
|
# Finds the requested page and returns a 404 error if it doesn't exist
|
||||||
def find_existing_page
|
def find_existing_page
|
||||||
@page = @wiki.find_page(params[:id])
|
@page = @wiki.find_page(params[:page])
|
||||||
if @page.nil?
|
render_404 if @page.nil?
|
||||||
render_404
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if @wiki.page_found_with_redirect?
|
|
||||||
redirect_to params.update(:id => @page.title)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if the current user is allowed to edit the page, otherwise false
|
# Returns true if the current user is allowed to edit the page, otherwise false
|
||||||
@@ -277,8 +245,4 @@ private
|
|||||||
extend helper unless self.instance_of?(helper)
|
extend helper unless self.instance_of?(helper)
|
||||||
helper.instance_method(:initial_page_content).bind(self).call(page)
|
helper.instance_method(:initial_page_content).bind(self).call(page)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_pages_for_index
|
|
||||||
@pages = @wiki.pages.with_updated_on.all(:order => 'title', :include => {:wiki => :project})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,17 +32,14 @@ class WorkflowsController < ApplicationController
|
|||||||
|
|
||||||
if request.post?
|
if request.post?
|
||||||
Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
|
Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
|
||||||
(params[:issue_status] || []).each { |status_id, transitions|
|
(params[:issue_status] || []).each { |old, news|
|
||||||
transitions.each { |new_status_id, options|
|
news.each { |new|
|
||||||
author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
|
@role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if @role.save
|
if @role.save
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
|
redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -51,14 +48,6 @@ class WorkflowsController < ApplicationController
|
|||||||
@statuses = @tracker.issue_statuses
|
@statuses = @tracker.issue_statuses
|
||||||
end
|
end
|
||||||
@statuses ||= IssueStatus.find(:all, :order => 'position')
|
@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
|
end
|
||||||
|
|
||||||
def copy
|
def copy
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -34,11 +34,25 @@ module ApplicationHelper
|
|||||||
# Display a link if user is authorized
|
# Display a link if user is authorized
|
||||||
#
|
#
|
||||||
# @param [String] name Anchor text (passed to link_to)
|
# @param [String] name Anchor text (passed to link_to)
|
||||||
# @param [Hash] options Hash params. This will checked by authorize_for to see if the user is authorized
|
# @param [Hash, String] options Hash params or url for the link target (passed to link_to).
|
||||||
|
# This will checked by authorize_for to see if the user is authorized
|
||||||
# @param [optional, Hash] html_options Options passed to link_to
|
# @param [optional, Hash] html_options Options passed to link_to
|
||||||
# @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
|
# @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
|
||||||
def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
||||||
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
if options.is_a?(String)
|
||||||
|
begin
|
||||||
|
route = ActionController::Routing::Routes.recognize_path(options.gsub(/\?.*/,''), :method => options[:method] || :get)
|
||||||
|
link_controller = route[:controller]
|
||||||
|
link_action = route[:action]
|
||||||
|
rescue ActionController::RoutingError # Parse failed, not a route
|
||||||
|
link_controller, link_action = nil, nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
link_controller = options[:controller] || params[:controller]
|
||||||
|
link_action = options[:action]
|
||||||
|
end
|
||||||
|
|
||||||
|
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(link_controller, link_action)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display a link to remote if user is authorized
|
# Display a link to remote if user is authorized
|
||||||
@@ -104,24 +118,8 @@ module ApplicationHelper
|
|||||||
# * :text - Link text (default to the formatted revision)
|
# * :text - Link text (default to the formatted revision)
|
||||||
def link_to_revision(revision, project, options={})
|
def link_to_revision(revision, project, options={})
|
||||||
text = options.delete(:text) || format_revision(revision)
|
text = options.delete(:text) || format_revision(revision)
|
||||||
rev = revision.respond_to?(:identifier) ? revision.identifier : revision
|
|
||||||
|
|
||||||
link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev},
|
link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision))
|
||||||
:title => l(:label_revision_id, format_revision(revision)))
|
|
||||||
end
|
|
||||||
|
|
||||||
# Generates a link to a message
|
|
||||||
def link_to_message(message, options={}, html_options = nil)
|
|
||||||
link_to(
|
|
||||||
h(truncate(message.subject, :length => 60)),
|
|
||||||
{ :controller => 'messages', :action => 'show',
|
|
||||||
:board_id => message.board_id,
|
|
||||||
:id => message.root,
|
|
||||||
:r => (message.parent_id && message.id),
|
|
||||||
:anchor => (message.parent_id ? "message-#{message.id}" : nil)
|
|
||||||
}.merge(options),
|
|
||||||
html_options
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generates a link to a project if active
|
# Generates a link to a project if active
|
||||||
@@ -187,15 +185,15 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_page_hierarchy(pages, node=nil, options={})
|
def render_page_hierarchy(pages, node=nil)
|
||||||
content = ''
|
content = ''
|
||||||
if pages[node]
|
if pages[node]
|
||||||
content << "<ul class=\"pages-hierarchy\">\n"
|
content << "<ul class=\"pages-hierarchy\">\n"
|
||||||
pages[node].each do |page|
|
pages[node].each do |page|
|
||||||
content << "<li>"
|
content << "<li>"
|
||||||
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title},
|
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :id => page.project, :page => page.title},
|
||||||
:title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
|
:title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
|
||||||
content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
|
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
|
||||||
content << "</li>\n"
|
content << "</li>\n"
|
||||||
end
|
end
|
||||||
content << "</ul>\n"
|
content << "</ul>\n"
|
||||||
@@ -223,8 +221,8 @@ module ApplicationHelper
|
|||||||
|
|
||||||
# Renders the project quick-jump box
|
# Renders the project quick-jump box
|
||||||
def render_project_jump_box
|
def render_project_jump_box
|
||||||
return unless User.current.logged?
|
# Retrieve them now to avoid a COUNT query
|
||||||
projects = User.current.memberships.collect(&:project).compact.uniq
|
projects = User.current.projects.all
|
||||||
if projects.any?
|
if projects.any?
|
||||||
s = '<select onchange="if (this.value != \'\') { window.location = this.value; }">' +
|
s = '<select onchange="if (this.value != \'\') { window.location = this.value; }">' +
|
||||||
"<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
|
"<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
|
||||||
@@ -254,10 +252,15 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Yields the given block for each project with its level in the tree
|
# Yields the given block for each project with its level in the tree
|
||||||
#
|
|
||||||
# Wrapper for Project#project_tree
|
|
||||||
def project_tree(projects, &block)
|
def project_tree(projects, &block)
|
||||||
Project.project_tree(projects, &block)
|
ancestors = []
|
||||||
|
projects.sort_by(&:lft).each do |project|
|
||||||
|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
||||||
|
ancestors.pop
|
||||||
|
end
|
||||||
|
yield project, ancestors.size
|
||||||
|
ancestors << project
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_nested_ul(projects, &block)
|
def project_nested_ul(projects, &block)
|
||||||
@@ -336,18 +339,20 @@ module ApplicationHelper
|
|||||||
page_param = options.delete(:page_param) || :page
|
page_param = options.delete(:page_param) || :page
|
||||||
per_page_links = options.delete(:per_page_links)
|
per_page_links = options.delete(:per_page_links)
|
||||||
url_param = params.dup
|
url_param = params.dup
|
||||||
|
# don't reuse query params if filters are present
|
||||||
|
url_param.merge!(:fields => nil, :values => nil, :operators => nil) if url_param.delete(:set_filter)
|
||||||
|
|
||||||
html = ''
|
html = ''
|
||||||
if paginator.current.previous
|
if paginator.current.previous
|
||||||
html << link_to_content_update('« ' + l(:label_previous), url_param.merge(page_param => paginator.current.previous)) + ' '
|
html << link_to_remote_content_update('« ' + l(:label_previous), url_param.merge(page_param => paginator.current.previous)) + ' '
|
||||||
end
|
end
|
||||||
|
|
||||||
html << (pagination_links_each(paginator, options) do |n|
|
html << (pagination_links_each(paginator, options) do |n|
|
||||||
link_to_content_update(n.to_s, url_param.merge(page_param => n))
|
link_to_remote_content_update(n.to_s, url_param.merge(page_param => n))
|
||||||
end || '')
|
end || '')
|
||||||
|
|
||||||
if paginator.current.next
|
if paginator.current.next
|
||||||
html << ' ' + link_to_content_update((l(:label_next) + ' »'), url_param.merge(page_param => paginator.current.next))
|
html << ' ' + link_to_remote_content_update((l(:label_next) + ' »'), url_param.merge(page_param => paginator.current.next))
|
||||||
end
|
end
|
||||||
|
|
||||||
unless count.nil?
|
unless count.nil?
|
||||||
@@ -361,8 +366,14 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def per_page_links(selected=nil)
|
def per_page_links(selected=nil)
|
||||||
|
url_param = params.dup
|
||||||
|
url_param.clear if url_param.has_key?(:set_filter)
|
||||||
|
|
||||||
links = Setting.per_page_options_array.collect do |n|
|
links = Setting.per_page_options_array.collect do |n|
|
||||||
n == selected ? n : link_to_content_update(n, params.merge(:per_page => n))
|
n == selected ? n : link_to_remote(n, {:update => "content",
|
||||||
|
:url => params.dup.merge(:per_page => n),
|
||||||
|
:method => :get},
|
||||||
|
{:href => url_for(url_param.merge(:per_page => n))})
|
||||||
end
|
end
|
||||||
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
|
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
|
||||||
end
|
end
|
||||||
@@ -390,7 +401,7 @@ module ApplicationHelper
|
|||||||
h(Setting.app_title)
|
h(Setting.app_title)
|
||||||
else
|
else
|
||||||
b = []
|
b = []
|
||||||
ancestors = (@project.root? ? [] : @project.ancestors.visible.all)
|
ancestors = (@project.root? ? [] : @project.ancestors.visible)
|
||||||
if ancestors.any?
|
if ancestors.any?
|
||||||
root = ancestors.shift
|
root = ancestors.shift
|
||||||
b << link_to_project(root, {:jump => current_menu_item}, :class => 'root')
|
b << link_to_project(root, {:jump => current_menu_item}, :class => 'root')
|
||||||
@@ -458,18 +469,11 @@ module ApplicationHelper
|
|||||||
|
|
||||||
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
|
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
|
||||||
|
|
||||||
@parsed_headings = []
|
parse_non_pre_blocks(text) do |text|
|
||||||
text = parse_non_pre_blocks(text) do |text|
|
[:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
|
||||||
[:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name|
|
|
||||||
send method_name, text, project, obj, attr, only_path, options
|
send method_name, text, project, obj, attr, only_path, options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @parsed_headings.any?
|
|
||||||
replace_toc(text, @parsed_headings)
|
|
||||||
end
|
|
||||||
|
|
||||||
text
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_non_pre_blocks(text)
|
def parse_non_pre_blocks(text)
|
||||||
@@ -539,7 +543,7 @@ module ApplicationHelper
|
|||||||
esc, all, page, title = $1, $2, $3, $5
|
esc, all, page, title = $1, $2, $3, $5
|
||||||
if esc.nil?
|
if esc.nil?
|
||||||
if page =~ /^([^\:]+)\:(.*)$/
|
if page =~ /^([^\:]+)\:(.*)$/
|
||||||
link_project = Project.find_by_identifier($1) || Project.find_by_name($1)
|
link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
|
||||||
page = $2
|
page = $2
|
||||||
title ||= $1 if page.blank?
|
title ||= $1 if page.blank?
|
||||||
end
|
end
|
||||||
@@ -550,20 +554,14 @@ module ApplicationHelper
|
|||||||
if page =~ /^(.+?)\#(.+)$/
|
if page =~ /^(.+?)\#(.+)$/
|
||||||
page, anchor = $1, $2
|
page, anchor = $1, $2
|
||||||
end
|
end
|
||||||
anchor = sanitize_anchor_name(anchor) if anchor.present?
|
|
||||||
# check if page exists
|
# check if page exists
|
||||||
wiki_page = link_project.wiki.find_page(page)
|
wiki_page = link_project.wiki.find_page(page)
|
||||||
url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
|
url = case options[:wiki_links]
|
||||||
"##{anchor}"
|
when :local; "#{title}.html"
|
||||||
else
|
|
||||||
case options[:wiki_links]
|
|
||||||
when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
|
|
||||||
when :anchor; "##{title}" # used for single-file wiki export
|
when :anchor; "##{title}" # used for single-file wiki export
|
||||||
else
|
else
|
||||||
wiki_page_id = page.present? ? Wiki.titleize(page) : nil
|
url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
|
||||||
url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => wiki_page_id, :anchor => anchor)
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
||||||
else
|
else
|
||||||
# project or wiki doesn't exist
|
# project or wiki doesn't exist
|
||||||
@@ -599,26 +597,16 @@ module ApplicationHelper
|
|||||||
# source:some/file#L120 -> Link to line 120 of the file
|
# source:some/file#L120 -> Link to line 120 of the file
|
||||||
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
||||||
# export:some/file -> Force the download of the file
|
# export:some/file -> Force the download of the file
|
||||||
# Forum messages:
|
# Forum messages:
|
||||||
# message#1218 -> Link to message with id 1218
|
# message#1218 -> Link to message with id 1218
|
||||||
#
|
|
||||||
# Links can refer other objects from other projects, using project identifier:
|
|
||||||
# identifier:r52
|
|
||||||
# identifier:document:"Some document"
|
|
||||||
# identifier:version:1.0.0
|
|
||||||
# identifier:source:some/file
|
|
||||||
def parse_redmine_links(text, project, obj, attr, only_path, options)
|
def parse_redmine_links(text, project, obj, attr, only_path, options)
|
||||||
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
|
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
|
||||||
leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10
|
leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8
|
||||||
link = nil
|
link = nil
|
||||||
if project_identifier
|
|
||||||
project = Project.visible.find_by_identifier(project_identifier)
|
|
||||||
end
|
|
||||||
if esc.nil?
|
if esc.nil?
|
||||||
if prefix.nil? && sep == 'r'
|
if prefix.nil? && sep == 'r'
|
||||||
# project.changesets.visible raises an SQL error because of a double join on repositories
|
if project && (changeset = project.changesets.find_by_revision(identifier))
|
||||||
if project && project.repository && (changeset = Changeset.visible.find_by_repository_id_and_revision(project.repository.id, identifier))
|
link = link_to("r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
||||||
link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
|
||||||
:class => 'changeset',
|
:class => 'changeset',
|
||||||
:title => truncate_single_line(changeset.comments, :length => 100))
|
:title => truncate_single_line(changeset.comments, :length => 100))
|
||||||
end
|
end
|
||||||
@@ -632,18 +620,24 @@ module ApplicationHelper
|
|||||||
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
||||||
end
|
end
|
||||||
when 'document'
|
when 'document'
|
||||||
if document = Document.visible.find_by_id(oid)
|
if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
||||||
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
||||||
:class => 'document'
|
:class => 'document'
|
||||||
end
|
end
|
||||||
when 'version'
|
when 'version'
|
||||||
if version = Version.visible.find_by_id(oid)
|
if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
||||||
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
||||||
:class => 'version'
|
:class => 'version'
|
||||||
end
|
end
|
||||||
when 'message'
|
when 'message'
|
||||||
if message = Message.visible.find_by_id(oid, :include => :parent)
|
if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
|
||||||
link = link_to_message(message, {:only_path => only_path}, :class => 'message')
|
link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
|
||||||
|
:controller => 'messages',
|
||||||
|
:action => 'show',
|
||||||
|
:board_id => message.board,
|
||||||
|
:id => message.root,
|
||||||
|
:anchor => (message.parent ? "message-#{message.id}" : nil)},
|
||||||
|
:class => 'message'
|
||||||
end
|
end
|
||||||
when 'project'
|
when 'project'
|
||||||
if p = Project.visible.find_by_id(oid)
|
if p = Project.visible.find_by_id(oid)
|
||||||
@@ -655,26 +649,26 @@ module ApplicationHelper
|
|||||||
name = identifier.gsub(%r{^"(.*)"$}, "\\1")
|
name = identifier.gsub(%r{^"(.*)"$}, "\\1")
|
||||||
case prefix
|
case prefix
|
||||||
when 'document'
|
when 'document'
|
||||||
if project && document = project.documents.visible.find_by_title(name)
|
if project && document = project.documents.find_by_title(name)
|
||||||
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
||||||
:class => 'document'
|
:class => 'document'
|
||||||
end
|
end
|
||||||
when 'version'
|
when 'version'
|
||||||
if project && version = project.versions.visible.find_by_name(name)
|
if project && version = project.versions.find_by_name(name)
|
||||||
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
||||||
:class => 'version'
|
:class => 'version'
|
||||||
end
|
end
|
||||||
when 'commit'
|
when 'commit'
|
||||||
if project && project.repository && (changeset = Changeset.visible.find(:first, :conditions => ["repository_id = ? AND scmid LIKE ?", project.repository.id, "#{name}%"]))
|
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
||||||
link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
|
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
||||||
:class => 'changeset',
|
:class => 'changeset',
|
||||||
:title => truncate_single_line(changeset.comments, :length => 100)
|
:title => truncate_single_line(changeset.comments, :length => 100)
|
||||||
end
|
end
|
||||||
when 'source', 'export'
|
when 'source', 'export'
|
||||||
if project && project.repository && User.current.allowed_to?(:browse_repository, project)
|
if project && project.repository
|
||||||
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
||||||
path, rev, anchor = $1, $3, $5
|
path, rev, anchor = $1, $3, $5
|
||||||
link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
||||||
:path => to_path_param(path),
|
:path => to_path_param(path),
|
||||||
:rev => rev,
|
:rev => rev,
|
||||||
:anchor => anchor,
|
:anchor => anchor,
|
||||||
@@ -694,56 +688,7 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}")
|
leading + (link || "#{prefix}#{sep}#{identifier}")
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE)
|
|
||||||
|
|
||||||
# Headings and TOC
|
|
||||||
# Adds ids and links to headings unless options[:headings] is set to false
|
|
||||||
def parse_headings(text, project, obj, attr, only_path, options)
|
|
||||||
return if options[:headings] == false
|
|
||||||
|
|
||||||
text.gsub!(HEADING_RE) do
|
|
||||||
level, attrs, content = $1.to_i, $2, $3
|
|
||||||
item = strip_tags(content).strip
|
|
||||||
anchor = sanitize_anchor_name(item)
|
|
||||||
@parsed_headings << [level, anchor, item]
|
|
||||||
"<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
|
|
||||||
|
|
||||||
# Renders the TOC with given headings
|
|
||||||
def replace_toc(text, headings)
|
|
||||||
text.gsub!(TOC_RE) do
|
|
||||||
if headings.empty?
|
|
||||||
''
|
|
||||||
else
|
|
||||||
div_class = 'toc'
|
|
||||||
div_class << ' right' if $1 == '>'
|
|
||||||
div_class << ' left' if $1 == '<'
|
|
||||||
out = "<ul class=\"#{div_class}\"><li>"
|
|
||||||
root = headings.map(&:first).min
|
|
||||||
current = root
|
|
||||||
started = false
|
|
||||||
headings.each do |level, anchor, item|
|
|
||||||
if level > current
|
|
||||||
out << '<ul><li>' * (level - current)
|
|
||||||
elsif level < current
|
|
||||||
out << "</li></ul>\n" * (current - level) + "</li><li>"
|
|
||||||
elsif started
|
|
||||||
out << '</li><li>'
|
|
||||||
end
|
|
||||||
out << "<a href=\"##{anchor}\">#{item}</a>"
|
|
||||||
current = level
|
|
||||||
started = true
|
|
||||||
end
|
|
||||||
out << '</li></ul>' * (current - root)
|
|
||||||
out << '</li></ul>'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -852,8 +797,6 @@ module ApplicationHelper
|
|||||||
'Calendar._FD = 1;' # Monday
|
'Calendar._FD = 1;' # Monday
|
||||||
when 7
|
when 7
|
||||||
'Calendar._FD = 0;' # Sunday
|
'Calendar._FD = 0;' # Sunday
|
||||||
when 6
|
|
||||||
'Calendar._FD = 6;' # Saturday
|
|
||||||
else
|
else
|
||||||
'' # use language
|
'' # use language
|
||||||
end
|
end
|
||||||
@@ -889,54 +832,13 @@ module ApplicationHelper
|
|||||||
email = $1
|
email = $1
|
||||||
end
|
end
|
||||||
return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
|
return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
|
||||||
else
|
|
||||||
''
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sanitize_anchor_name(anchor)
|
|
||||||
anchor.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the javascript tags that are included in the html layout head
|
|
||||||
def javascript_heads
|
|
||||||
tags = javascript_include_tag(:defaults)
|
|
||||||
unless User.current.pref.warn_on_leaving_unsaved == '0'
|
|
||||||
tags << "\n" + javascript_tag("Event.observe(window, 'load', function(){ new WarnLeavingUnsaved('#{escape_javascript( l(:text_warn_on_leaving_unsaved) )}'); });")
|
|
||||||
end
|
|
||||||
tags
|
|
||||||
end
|
|
||||||
|
|
||||||
def favicon
|
def favicon
|
||||||
"<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />"
|
"<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />"
|
||||||
end
|
end
|
||||||
|
|
||||||
def robot_exclusion_tag
|
|
||||||
'<meta name="robots" content="noindex,follow,noarchive" />'
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns true if arg is expected in the API response
|
|
||||||
def include_in_api_response?(arg)
|
|
||||||
unless @included_in_api_response
|
|
||||||
param = params[:include]
|
|
||||||
@included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',')
|
|
||||||
@included_in_api_response.collect!(&:strip)
|
|
||||||
end
|
|
||||||
@included_in_api_response.include?(arg.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns options or nil if nometa param or X-Redmine-Nometa header
|
|
||||||
# was set in the request
|
|
||||||
def api_meta(options)
|
|
||||||
if params[:nometa].present? || request.headers['X-Redmine-Nometa']
|
|
||||||
# compatibility mode for activeresource clients that raise
|
|
||||||
# an error when unserializing an array with attributes
|
|
||||||
nil
|
|
||||||
else
|
|
||||||
options
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def wiki_helper
|
def wiki_helper
|
||||||
@@ -945,7 +847,11 @@ module ApplicationHelper
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_content_update(text, url_params = {}, html_options = {})
|
def link_to_remote_content_update(text, url_params)
|
||||||
link_to(text, url_params, html_options)
|
link_to_remote(text,
|
||||||
|
{:url => url_params, :method => :get, :update => 'content', :complete => 'window.scrollTo(0,0)'},
|
||||||
|
{:href => url_for(:params => url_params)}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -29,18 +29,6 @@ module AttachmentsHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_utf8(str)
|
def to_utf8(str)
|
||||||
if str.respond_to?(:force_encoding)
|
str
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module CalendarsHelper
|
module CalendarsHelper
|
||||||
def link_to_previous_month(year, month, options={})
|
def link_to_previous_month(year, month)
|
||||||
target_year, target_month = if month == 1
|
target_year, target_month = if month == 1
|
||||||
[year - 1, 12]
|
[year - 1, 12]
|
||||||
else
|
else
|
||||||
@@ -12,10 +12,12 @@ module CalendarsHelper
|
|||||||
"#{month_name(target_month)}"
|
"#{month_name(target_month)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
link_to_month(('« ' + name), target_year, target_month, options)
|
link_to_remote ('« ' + name),
|
||||||
|
{:update => "content", :url => { :year => target_year, :month => target_month }},
|
||||||
|
{:href => url_for(:action => 'show', :year => target_year, :month => target_month)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_next_month(year, month, options={})
|
def link_to_next_month(year, month)
|
||||||
target_year, target_month = if month == 12
|
target_year, target_month = if month == 12
|
||||||
[year + 1, 1]
|
[year + 1, 1]
|
||||||
else
|
else
|
||||||
@@ -28,10 +30,9 @@ module CalendarsHelper
|
|||||||
"#{month_name(target_month)}"
|
"#{month_name(target_month)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
link_to_month((name + ' »'), target_year, target_month, options)
|
link_to_remote (name + ' »'),
|
||||||
end
|
{:update => "content", :url => { :year => target_year, :month => target_month }},
|
||||||
|
{:href => url_for(:action => 'show', :year => target_year, :month =>target_month)}
|
||||||
|
|
||||||
def link_to_month(link_name, year, month, options={})
|
|
||||||
link_to_content_update(link_name, params.merge(:year => year, :month => month))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -37,7 +37,7 @@ module CustomFieldsHelper
|
|||||||
field_id = "#{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)
|
field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
|
||||||
case field_format.try(:edit_as)
|
case field_format.edit_as
|
||||||
when "date"
|
when "date"
|
||||||
text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
|
text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
|
||||||
calendar_for(field_id)
|
calendar_for(field_id)
|
||||||
@@ -49,7 +49,7 @@ module CustomFieldsHelper
|
|||||||
blank_option = custom_field.is_required? ?
|
blank_option = custom_field.is_required? ?
|
||||||
(custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
|
(custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
|
||||||
'<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
|
else
|
||||||
text_field_tag(field_name, custom_value.value, :id => field_id)
|
text_field_tag(field_name, custom_value.value, :id => field_id)
|
||||||
end
|
end
|
||||||
@@ -68,11 +68,11 @@ module CustomFieldsHelper
|
|||||||
custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
|
custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil)
|
def custom_field_tag_for_bulk_edit(name, custom_field)
|
||||||
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||||||
field_id = "#{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)
|
field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
|
||||||
case field_format.try(:edit_as)
|
case field_format.edit_as
|
||||||
when "date"
|
when "date"
|
||||||
text_field_tag(field_name, '', :id => field_id, :size => 10) +
|
text_field_tag(field_name, '', :id => field_id, :size => 10) +
|
||||||
calendar_for(field_id)
|
calendar_for(field_id)
|
||||||
@@ -83,7 +83,7 @@ module CustomFieldsHelper
|
|||||||
[l(:general_text_yes), '1'],
|
[l(:general_text_yes), '1'],
|
||||||
[l(:general_text_no), '0']]), :id => field_id)
|
[l(:general_text_no), '0']]), :id => field_id)
|
||||||
when "list"
|
when "list"
|
||||||
select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values_options(projects)), :id => field_id)
|
select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values), :id => field_id)
|
||||||
else
|
else
|
||||||
text_field_tag(field_name, '', :id => field_id)
|
text_field_tag(field_name, '', :id => field_id)
|
||||||
end
|
end
|
||||||
@@ -101,18 +101,7 @@ module CustomFieldsHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Return an array of custom field formats which can be used in select_tag
|
# Return an array of custom field formats which can be used in select_tag
|
||||||
def custom_field_formats_for_select(custom_field)
|
def custom_field_formats_for_select
|
||||||
Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name)
|
Redmine::CustomFieldFormat.as_select
|
||||||
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?
|
|
||||||
end
|
end
|
||||||
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,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -44,10 +44,8 @@ module IssuesHelper
|
|||||||
@cached_label_due_date ||= l(:field_due_date)
|
@cached_label_due_date ||= l(:field_due_date)
|
||||||
@cached_label_assigned_to ||= l(:field_assigned_to)
|
@cached_label_assigned_to ||= l(:field_assigned_to)
|
||||||
@cached_label_priority ||= l(:field_priority)
|
@cached_label_priority ||= l(:field_priority)
|
||||||
@cached_label_project ||= l(:field_project)
|
|
||||||
|
|
||||||
link_to_issue(issue) + "<br /><br />" +
|
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 />" +
|
"<strong>#{@cached_label_status}</strong>: #{issue.status.name}<br />" +
|
||||||
"<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<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_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
|
||||||
@@ -55,29 +53,19 @@ module IssuesHelper
|
|||||||
"<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
|
"<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def issue_heading(issue)
|
|
||||||
h("#{issue.tracker} ##{issue.id}")
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_issue_subject_with_tree(issue)
|
def render_issue_subject_with_tree(issue)
|
||||||
s = ''
|
s = ''
|
||||||
ancestors = issue.root? ? [] : issue.ancestors.visible.all
|
issue.ancestors.each do |ancestor|
|
||||||
ancestors.each do |ancestor|
|
|
||||||
s << '<div>' + content_tag('p', link_to_issue(ancestor))
|
s << '<div>' + content_tag('p', link_to_issue(ancestor))
|
||||||
end
|
end
|
||||||
s << '<div>'
|
s << '<div>' + content_tag('h3', h(issue.subject))
|
||||||
subject = h(issue.subject)
|
s << '</div>' * (issue.ancestors.size + 1)
|
||||||
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)
|
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_descendants_tree(issue)
|
def render_descendants_tree(issue)
|
||||||
s = '<form><table class="list issues">'
|
s = '<form><table class="list issues">'
|
||||||
issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
|
issue_list(issue.descendants.sort_by(&:lft)) do |child, level|
|
||||||
s << content_tag('tr',
|
s << content_tag('tr',
|
||||||
content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
|
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', link_to_issue(child, :truncate => 60), :class => 'subject') +
|
||||||
@@ -109,24 +97,6 @@ module IssuesHelper
|
|||||||
s
|
s
|
||||||
end
|
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
|
def sidebar_queries
|
||||||
unless @sidebar_queries
|
unless @sidebar_queries
|
||||||
# User can see public queries and his own queries
|
# User can see public queries and his own queries
|
||||||
@@ -134,32 +104,13 @@ module IssuesHelper
|
|||||||
# Project specific queries and global queries
|
# Project specific queries and global queries
|
||||||
visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
|
visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
|
||||||
@sidebar_queries = Query.find(:all,
|
@sidebar_queries = Query.find(:all,
|
||||||
:select => 'id, name, is_public',
|
:select => 'id, name',
|
||||||
:order => "name ASC",
|
:order => "name ASC",
|
||||||
:conditions => visible.conditions)
|
:conditions => visible.conditions)
|
||||||
end
|
end
|
||||||
@sidebar_queries
|
@sidebar_queries
|
||||||
end
|
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)
|
def show_detail(detail, no_html=false)
|
||||||
case detail.property
|
case detail.property
|
||||||
when 'attr'
|
when 'attr'
|
||||||
@@ -182,10 +133,6 @@ module IssuesHelper
|
|||||||
label = l(:field_parent_issue)
|
label = l(:field_parent_issue)
|
||||||
value = "##{detail.value}" unless detail.value.blank?
|
value = "##{detail.value}" unless detail.value.blank?
|
||||||
old_value = "##{detail.old_value}" unless detail.old_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
|
end
|
||||||
when 'cf'
|
when 'cf'
|
||||||
custom_field = CustomField.find_by_id(detail.prop_key)
|
custom_field = CustomField.find_by_id(detail.prop_key)
|
||||||
@@ -215,16 +162,7 @@ module IssuesHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if detail.property == 'attr' && detail.prop_key == 'description'
|
if !detail.value.blank?
|
||||||
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?
|
|
||||||
case detail.property
|
case detail.property
|
||||||
when 'attr', 'cf'
|
when 'attr', 'cf'
|
||||||
if !detail.old_value.blank?
|
if !detail.old_value.blank?
|
||||||
@@ -249,20 +187,6 @@ module IssuesHelper
|
|||||||
end
|
end
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def issues_to_csv(issues, project = nil)
|
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)
|
decimal_separator = l(:general_csv_decimal_separator)
|
||||||
@@ -320,4 +244,30 @@ module IssuesHelper
|
|||||||
end
|
end
|
||||||
export
|
export
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def gantt_zoom_link(gantt, in_or_out)
|
||||||
|
img_attributes = {:style => 'height:1.4em; width:1.4em; margin-left: 3px;'} # em for accessibility
|
||||||
|
|
||||||
|
case in_or_out
|
||||||
|
when :in
|
||||||
|
if gantt.zoom < 4
|
||||||
|
link_to_remote(l(:text_zoom_in) + image_tag('zoom_in.png', img_attributes.merge(:alt => l(:text_zoom_in))),
|
||||||
|
{:url => gantt.params.merge(:zoom => (gantt.zoom+1)), :update => 'content'},
|
||||||
|
{:href => url_for(gantt.params.merge(:zoom => (gantt.zoom+1)))})
|
||||||
|
else
|
||||||
|
l(:text_zoom_in) +
|
||||||
|
image_tag('zoom_in_g.png', img_attributes.merge(:alt => l(:text_zoom_in)))
|
||||||
|
end
|
||||||
|
|
||||||
|
when :out
|
||||||
|
if gantt.zoom > 1
|
||||||
|
link_to_remote(l(:text_zoom_out) + image_tag('zoom_out.png', img_attributes.merge(:alt => l(:text_zoom_out))),
|
||||||
|
{:url => gantt.params.merge(:zoom => (gantt.zoom-1)), :update => 'content'},
|
||||||
|
{:href => url_for(gantt.params.merge(:zoom => (gantt.zoom-1)))})
|
||||||
|
else
|
||||||
|
l(:text_zoom_out) +
|
||||||
|
image_tag('zoom_out_g.png', img_attributes.merge(:alt => l(:text_zoom_out)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,4 +16,14 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module MessagesHelper
|
module MessagesHelper
|
||||||
|
|
||||||
|
def link_to_message(message)
|
||||||
|
return '' unless message
|
||||||
|
link_to h(truncate(message.subject, :length => 60)), :controller => 'messages',
|
||||||
|
:action => 'show',
|
||||||
|
:board_id => message.board_id,
|
||||||
|
:id => message.root,
|
||||||
|
:r => (message.parent_id && message.id),
|
||||||
|
:anchor => (message.parent_id ? "message-#{message.id}" : nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -70,7 +70,6 @@ module QueriesHelper
|
|||||||
cond = "project_id IS NULL"
|
cond = "project_id IS NULL"
|
||||||
cond << " OR project_id = #{@project.id}" if @project
|
cond << " OR project_id = #{@project.id}" if @project
|
||||||
@query = Query.find(params[:query_id], :conditions => cond)
|
@query = Query.find(params[:query_id], :conditions => cond)
|
||||||
raise ::Unauthorized unless @query.visible?
|
|
||||||
@query.project = @project
|
@query.project = @project
|
||||||
session[:query] = {:id => @query.id, :project_id => @query.project_id}
|
session[:query] = {:id => @query.id, :project_id => @query.project_id}
|
||||||
sort_clear
|
sort_clear
|
||||||
@@ -79,16 +78,17 @@ module QueriesHelper
|
|||||||
# Give it a name, required to be valid
|
# Give it a name, required to be valid
|
||||||
@query = Query.new(:name => "_")
|
@query = Query.new(:name => "_")
|
||||||
@query.project = @project
|
@query.project = @project
|
||||||
if params[:fields] || params[:f]
|
if params[:fields] and params[:fields].is_a? Array
|
||||||
@query.filters = {}
|
params[:fields].each do |field|
|
||||||
@query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
|
@query.add_filter(field, params[:operators][field], params[:values][field])
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@query.available_filters.keys.each do |field|
|
@query.available_filters.keys.each do |field|
|
||||||
@query.add_short_filter(field, params[field]) if params[field]
|
@query.add_short_filter(field, params[field]) if params[field]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@query.group_by = params[:group_by]
|
@query.group_by = params[:group_by]
|
||||||
@query.column_names = params[:c] || (params[:query] && params[:query][:column_names])
|
@query.column_names = 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}
|
session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
|
||||||
else
|
else
|
||||||
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
|
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,15 +16,10 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require 'iconv'
|
require 'iconv'
|
||||||
require 'redmine/codeset_util'
|
|
||||||
|
|
||||||
module RepositoriesHelper
|
module RepositoriesHelper
|
||||||
def format_revision(revision)
|
def format_revision(txt)
|
||||||
if revision.respond_to? :format_identifier
|
txt.to_s[0,8]
|
||||||
revision.format_identifier
|
|
||||||
else
|
|
||||||
revision.to_s
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def truncate_at_line_break(text, length = 255)
|
def truncate_at_line_break(text, length = 255)
|
||||||
@@ -49,8 +44,7 @@ module RepositoriesHelper
|
|||||||
when 'A'
|
when 'A'
|
||||||
# Detects moved/copied files
|
# Detects moved/copied files
|
||||||
if !change.from_path.blank?
|
if !change.from_path.blank?
|
||||||
change.action =
|
change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
|
||||||
@changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
|
|
||||||
end
|
end
|
||||||
change
|
change
|
||||||
when 'D'
|
when 'D'
|
||||||
@@ -58,7 +52,7 @@ module RepositoriesHelper
|
|||||||
else
|
else
|
||||||
change
|
change
|
||||||
end
|
end
|
||||||
end.compact
|
end.compact
|
||||||
|
|
||||||
tree = { }
|
tree = { }
|
||||||
changes.each do |change|
|
changes.each do |change|
|
||||||
@@ -74,11 +68,13 @@ module RepositoriesHelper
|
|||||||
end
|
end
|
||||||
p[:c] = change
|
p[:c] = change
|
||||||
end
|
end
|
||||||
|
|
||||||
render_changes_tree(tree[:s])
|
render_changes_tree(tree[:s])
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_changes_tree(tree)
|
def render_changes_tree(tree)
|
||||||
return '' if tree.nil?
|
return '' if tree.nil?
|
||||||
|
|
||||||
output = ''
|
output = ''
|
||||||
output << '<ul>'
|
output << '<ul>'
|
||||||
tree.keys.sort.each do |file|
|
tree.keys.sort.each do |file|
|
||||||
@@ -91,7 +87,7 @@ module RepositoriesHelper
|
|||||||
:action => 'show',
|
:action => 'show',
|
||||||
:id => @project,
|
:id => @project,
|
||||||
:path => path_param,
|
:path => path_param,
|
||||||
:rev => @changeset.identifier)
|
:rev => @changeset.revision)
|
||||||
output << "<li class='#{style}'>#{text}</li>"
|
output << "<li class='#{style}'>#{text}</li>"
|
||||||
output << render_changes_tree(s)
|
output << render_changes_tree(s)
|
||||||
elsif c = tree[file][:c]
|
elsif c = tree[file][:c]
|
||||||
@@ -101,13 +97,13 @@ module RepositoriesHelper
|
|||||||
:action => 'entry',
|
:action => 'entry',
|
||||||
:id => @project,
|
:id => @project,
|
||||||
:path => path_param,
|
:path => path_param,
|
||||||
:rev => @changeset.identifier) unless c.action == 'D'
|
:rev => @changeset.revision) unless c.action == 'D'
|
||||||
text << " - #{c.revision}" unless c.revision.blank?
|
text << " - #{c.revision}" unless c.revision.blank?
|
||||||
text << ' (' + link_to('diff', :controller => 'repositories',
|
text << ' (' + link_to('diff', :controller => 'repositories',
|
||||||
:action => 'diff',
|
:action => 'diff',
|
||||||
:id => @project,
|
:id => @project,
|
||||||
:path => path_param,
|
: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?
|
text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank?
|
||||||
output << "<li class='#{style}'>#{text}</li>"
|
output << "<li class='#{style}'>#{text}</li>"
|
||||||
end
|
end
|
||||||
@@ -117,24 +113,7 @@ module RepositoriesHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_utf8(str)
|
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
|
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 ||= Setting.repositories_encodings.split(',').collect(&:strip)
|
||||||
@encodings.each do |encoding|
|
@encodings.each do |encoding|
|
||||||
begin
|
begin
|
||||||
@@ -143,38 +122,25 @@ module RepositoriesHelper
|
|||||||
# do nothing here and try the next encoding
|
# do nothing here and try the next encoding
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
str = Redmine::CodesetUtil.replace_invalid_utf8(str)
|
str
|
||||||
end
|
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"
|
method = repository.class.name.demodulize.underscore + "_field_tags"
|
||||||
if repository.is_a?(Repository) &&
|
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags'
|
||||||
respond_to?(method) && method != 'repository_field_tags'
|
|
||||||
send(method, form, repository)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def scm_select_tag(repository)
|
def scm_select_tag(repository)
|
||||||
scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
|
scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
|
||||||
Redmine::Scm::Base.all.each do |scm|
|
Redmine::Scm::Base.all.each do |scm|
|
||||||
if Setting.enabled_scm.include?(scm) ||
|
scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm)
|
||||||
(repository && repository.class.name.demodulize == scm)
|
|
||||||
scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
select_tag('repository_scm',
|
select_tag('repository_scm',
|
||||||
options_for_select(scm_options, repository.class.name.demodulize),
|
options_for_select(scm_options, repository.class.name.demodulize),
|
||||||
:disabled => (repository && !repository.new_record?),
|
:disabled => (repository && !repository.new_record?),
|
||||||
:onchange => remote_function(
|
:onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
|
||||||
:url => {
|
)
|
||||||
:controller => 'repositories',
|
|
||||||
:action => 'edit',
|
|
||||||
:id => @project
|
|
||||||
},
|
|
||||||
:method => :get,
|
|
||||||
:with => "Form.serialize(this.form)")
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_leading_slash(path)
|
def with_leading_slash(path)
|
||||||
@@ -186,99 +152,37 @@ module RepositoriesHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def subversion_field_tags(form, repository)
|
def subversion_field_tags(form, repository)
|
||||||
content_tag('p', form.text_field(:url, :size => 60, :required => true,
|
content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
|
||||||
:disabled => (repository && !repository.root_url.blank?)) +
|
|
||||||
'<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
|
'<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
|
||||||
content_tag('p', form.text_field(:login, :size => 30)) +
|
content_tag('p', form.text_field(:login, :size => 30)) +
|
||||||
content_tag('p', form.password_field(
|
content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
|
||||||
:password, :size => 30, :name => 'ignore',
|
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
|
||||||
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
|
:onfocus => "this.value=''; this.name='repository[password]';",
|
||||||
:onfocus => "this.value=''; this.name='repository[password]';",
|
:onchange => "this.name='repository[password]';"))
|
||||||
:onchange => "this.name='repository[password]';"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def darcs_field_tags(form, repository)
|
def darcs_field_tags(form, repository)
|
||||||
content_tag('p', form.text_field(
|
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
|
||||||
: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))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mercurial_field_tags(form, repository)
|
def mercurial_field_tags(form, repository)
|
||||||
content_tag('p', form.text_field(
|
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
||||||
: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))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def git_field_tags(form, repository)
|
def git_field_tags(form, repository)
|
||||||
content_tag('p', form.text_field(
|
content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
||||||
: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)
|
|
||||||
))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def cvs_field_tags(form, repository)
|
def cvs_field_tags(form, repository)
|
||||||
content_tag('p', form.text_field(
|
content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
|
||||||
:root_url,
|
content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
|
||||||
: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))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def bazaar_field_tags(form, repository)
|
def bazaar_field_tags(form, repository)
|
||||||
content_tag('p', form.text_field(
|
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
|
||||||
: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))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def filesystem_field_tags(form, repository)
|
def filesystem_field_tags(form, repository)
|
||||||
content_tag('p', form.text_field(
|
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
||||||
: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))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -39,7 +39,7 @@ module SearchHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def type_label(t)
|
def type_label(t)
|
||||||
l("label_#{t.singularize}_plural", :default => t.to_s.humanize)
|
l("label_#{t.singularize}_plural")
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_select_tag
|
def project_select_tag
|
||||||
@@ -57,7 +57,7 @@ module SearchHelper
|
|||||||
c = results_by_type[t]
|
c = results_by_type[t]
|
||||||
next if c == 0
|
next if c == 0
|
||||||
text = "#{type_label(t)} (#{c})"
|
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
|
end
|
||||||
('<ul>' + links.map {|link| content_tag('li', link)}.join(' ') + '</ul>') unless links.empty?
|
('<ul>' + links.map {|link| content_tag('li', link)}.join(' ') + '</ul>') unless links.empty?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -33,9 +33,7 @@ module SettingsHelper
|
|||||||
choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
|
choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
|
||||||
end
|
end
|
||||||
setting_label(setting, options) +
|
setting_label(setting, options) +
|
||||||
select_tag("settings[#{setting}]",
|
select_tag("settings[#{setting}]", options_for_select(choices, Setting.send(setting).to_s), options)
|
||||||
options_for_select(choices, Setting.send(setting).to_s),
|
|
||||||
options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def setting_multiselect(setting, choices, options={})
|
def setting_multiselect(setting, choices, options={})
|
||||||
@@ -46,15 +44,10 @@ module SettingsHelper
|
|||||||
hidden_field_tag("settings[#{setting}][]", '') +
|
hidden_field_tag("settings[#{setting}][]", '') +
|
||||||
choices.collect do |choice|
|
choices.collect do |choice|
|
||||||
text, value = (choice.is_a?(Array) ? choice : [choice, choice])
|
text, value = (choice.is_a?(Array) ? choice : [choice, choice])
|
||||||
content_tag(
|
content_tag('label',
|
||||||
'label',
|
check_box_tag("settings[#{setting}][]", value, Setting.send(setting).include?(value)) + text.to_s,
|
||||||
check_box_tag(
|
|
||||||
"settings[#{setting}][]",
|
|
||||||
value,
|
|
||||||
Setting.send(setting).include?(value)
|
|
||||||
) + text.to_s,
|
|
||||||
:class => 'block'
|
:class => 'block'
|
||||||
)
|
)
|
||||||
end.join
|
end.join
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -71,21 +64,11 @@ module SettingsHelper
|
|||||||
def setting_check_box(setting, options={})
|
def setting_check_box(setting, options={})
|
||||||
setting_label(setting, options) +
|
setting_label(setting, options) +
|
||||||
hidden_field_tag("settings[#{setting}]", 0) +
|
hidden_field_tag("settings[#{setting}]", 0) +
|
||||||
check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options)
|
check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def setting_label(setting, options={})
|
def setting_label(setting, options={})
|
||||||
label = options.delete(:label)
|
label = options.delete(:label)
|
||||||
label != false ? content_tag("label", l(label || "setting_#{setting}")) : ''
|
label != false ? content_tag("label", l(label || "setting_#{setting}")) : ''
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -200,12 +200,16 @@ module SortHelper
|
|||||||
caption = column.to_s.humanize unless caption
|
caption = column.to_s.humanize unless caption
|
||||||
|
|
||||||
sort_options = { :sort => @sort_criteria.add(column.to_s, order).to_param }
|
sort_options = { :sort => @sort_criteria.add(column.to_s, order).to_param }
|
||||||
url_options = params.merge(sort_options)
|
# 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
|
# Add project_id to url_options
|
||||||
url_options = url_options.merge(:project_id => params[:project_id]) if params.has_key?(:project_id)
|
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, :method => :get},
|
||||||
|
{:href => url_for(url_options),
|
||||||
|
:class => css})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a table header <th> tag with a sort link for the named column
|
# Returns a table header <th> tag with a sort link for the named column
|
||||||
|
|||||||
@@ -33,19 +33,15 @@ module UsersHelper
|
|||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_mail_notification_options(user)
|
|
||||||
user.valid_notification_options.collect {|o| [l(o.last), o.first]}
|
|
||||||
end
|
|
||||||
|
|
||||||
def change_status_link(user)
|
def change_status_link(user)
|
||||||
url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
|
url = {:controller => 'users', :action => 'edit', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
|
||||||
|
|
||||||
if user.locked?
|
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?
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -17,10 +17,11 @@
|
|||||||
|
|
||||||
module VersionsHelper
|
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)
|
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]}
|
h = Hash.new {|k,v| k[v] = [0, 0]}
|
||||||
begin
|
begin
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -17,17 +17,27 @@
|
|||||||
|
|
||||||
module WatchersHelper
|
module WatchersHelper
|
||||||
|
|
||||||
def watcher_tag(object, user, options={})
|
# Valid options
|
||||||
content_tag("span", watcher_link(object, user), :class => watcher_css(object))
|
# * :id - the element id
|
||||||
|
# * :replace - a string or array of element ids that will be
|
||||||
|
# replaced
|
||||||
|
def watcher_tag(object, user, options={:replace => 'watcher'})
|
||||||
|
id = options[:id]
|
||||||
|
id ||= options[:replace] if options[:replace].is_a? String
|
||||||
|
content_tag("span", watcher_link(object, user, options), :id => id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def watcher_link(object, user)
|
# Valid options
|
||||||
|
# * :replace - a string or array of element ids that will be
|
||||||
|
# replaced
|
||||||
|
def watcher_link(object, user, options={:replace => 'watcher'})
|
||||||
return '' unless user && user.logged? && object.respond_to?('watched_by?')
|
return '' unless user && user.logged? && object.respond_to?('watched_by?')
|
||||||
watched = object.watched_by?(user)
|
watched = object.watched_by?(user)
|
||||||
url = {:controller => 'watchers',
|
url = {:controller => 'watchers',
|
||||||
:action => (watched ? 'unwatch' : 'watch'),
|
:action => (watched ? 'unwatch' : 'watch'),
|
||||||
:object_type => object.class.to_s.underscore,
|
:object_type => object.class.to_s.underscore,
|
||||||
:object_id => object.id}
|
:object_id => object.id,
|
||||||
|
:replace => options[:replace]}
|
||||||
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
|
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
|
||||||
{:url => url},
|
{:url => url},
|
||||||
:href => url_for(url),
|
:href => url_for(url),
|
||||||
@@ -35,11 +45,6 @@ module WatchersHelper
|
|||||||
|
|
||||||
end
|
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
|
# Returns a comma separated list of users watching the given object
|
||||||
def watchers_list(object)
|
def watchers_list(object)
|
||||||
remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
|
remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
|
||||||
|
|||||||
+45
-11
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -18,18 +18,52 @@
|
|||||||
module WikiHelper
|
module WikiHelper
|
||||||
|
|
||||||
def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
|
def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
|
||||||
pages = pages.group_by(&:parent) unless pages.is_a?(Hash)
|
|
||||||
s = ''
|
s = ''
|
||||||
if pages.has_key?(parent)
|
pages.select {|p| p.parent == parent}.each do |page|
|
||||||
pages[parent].each do |page|
|
attrs = "value='#{page.id}'"
|
||||||
attrs = "value='#{page.id}'"
|
attrs << " selected='selected'" if selected == page
|
||||||
attrs << " selected='selected'" if selected == page
|
indent = (level > 0) ? (' ' * level * 2 + '» ') : nil
|
||||||
indent = (level > 0) ? (' ' * level * 2 + '» ') : nil
|
|
||||||
|
|
||||||
s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" +
|
s << "<option value='#{page.id}'>#{indent}#{h page.pretty_title}</option>\n" +
|
||||||
wiki_page_options_for_select(pages, selected, page, level + 1)
|
wiki_page_options_for_select(pages, selected, page, level + 1)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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 << ' ' + h(change[2])
|
||||||
|
words_del += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if add_at
|
||||||
|
words[add_at] = '<span class="diff_in">' + words[add_at]
|
||||||
|
words[add_to] = words[add_to] + '</span>'
|
||||||
|
end
|
||||||
|
if del_at
|
||||||
|
words.insert del_at - del_off + dels + words_add, '<span class="diff_out">' + deleted + '</span>'
|
||||||
|
dels += 1
|
||||||
|
del_off += words_del
|
||||||
|
words_del = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
simple_format_without_paragraph(words.join(' '))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -43,7 +43,7 @@ class Attachment < ActiveRecord::Base
|
|||||||
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}
|
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}
|
||||||
|
|
||||||
cattr_accessor :storage_path
|
cattr_accessor :storage_path
|
||||||
@@storage_path = Redmine::Configuration['attachments_storage_path'] || "#{RAILS_ROOT}/files"
|
@@storage_path = "#{RAILS_ROOT}/files"
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class AuthSource < ActiveRecord::Base
|
class AuthSource < ActiveRecord::Base
|
||||||
include Redmine::Ciphering
|
|
||||||
|
|
||||||
has_many :users
|
has_many :users
|
||||||
|
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
@@ -34,14 +32,6 @@ class AuthSource < ActiveRecord::Base
|
|||||||
"Abstract"
|
"Abstract"
|
||||||
end
|
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?
|
def allow_password_changes?
|
||||||
self.class.allow_password_changes?
|
self.class.allow_password_changes?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ require 'iconv'
|
|||||||
|
|
||||||
class AuthSourceLdap < AuthSource
|
class AuthSourceLdap < AuthSource
|
||||||
validates_presence_of :host, :port, :attr_login
|
validates_presence_of :host, :port, :attr_login
|
||||||
validates_length_of :name, :host, :maximum => 60, :allow_nil => true
|
validates_length_of :name, :host, :account_password, :maximum => 60, :allow_nil => true
|
||||||
validates_length_of :account, :account_password, :base_dn, :maximum => 255, :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_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
|
||||||
validates_numericality_of :port, :only_integer => true
|
validates_numericality_of :port, :only_integer => true
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@
|
|||||||
class Board < ActiveRecord::Base
|
class Board < ActiveRecord::Base
|
||||||
belongs_to :project
|
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 :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
|
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
|
||||||
acts_as_list :scope => :project_id
|
acts_as_list :scope => :project_id
|
||||||
acts_as_watchable
|
acts_as_watchable
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -25,11 +25,6 @@ class Change < ActiveRecord::Base
|
|||||||
changeset.repository.relative_path(path)
|
changeset.repository.relative_path(path)
|
||||||
end
|
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
|
def init_path
|
||||||
self.path ||= ""
|
self.path ||= ""
|
||||||
end
|
end
|
||||||
|
|||||||
+73
-164
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2010 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -23,10 +23,10 @@ class Changeset < ActiveRecord::Base
|
|||||||
has_many :changes, :dependent => :delete_all
|
has_many :changes, :dependent => :delete_all
|
||||||
has_and_belongs_to_many :issues
|
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))},
|
acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments))},
|
||||||
:description => :long_comments,
|
:description => :long_comments,
|
||||||
:datetime => :committed_on,
|
: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, :rev => o.revision}}
|
||||||
|
|
||||||
acts_as_searchable :columns => 'comments',
|
acts_as_searchable :columns => 'comments',
|
||||||
:include => {:repository => :project},
|
:include => {:repository => :project},
|
||||||
@@ -42,19 +42,14 @@ class Changeset < ActiveRecord::Base
|
|||||||
validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
|
validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
|
||||||
|
|
||||||
named_scope :visible, lambda {|*args| { :include => {:repository => :project},
|
named_scope :visible, lambda {|*args| { :include => {:repository => :project},
|
||||||
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args) } }
|
:conditions => Project.allowed_to_condition(args.first || User.current, :view_changesets) } }
|
||||||
|
|
||||||
def revision=(r)
|
def revision=(r)
|
||||||
write_attribute :revision, (r.nil? ? nil : r.to_s)
|
write_attribute :revision, (r.nil? ? nil : r.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the identifier of this changeset; depending on repository backends
|
def comments=(comment)
|
||||||
def identifier
|
write_attribute(:comments, Changeset.normalize_comments(comment))
|
||||||
if repository.class.respond_to? :changeset_identifier
|
|
||||||
repository.class.changeset_identifier self
|
|
||||||
else
|
|
||||||
revision.to_s
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def committed_on=(date)
|
def committed_on=(date)
|
||||||
@@ -62,13 +57,8 @@ class Changeset < ActiveRecord::Base
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the readable identifier
|
def committer=(arg)
|
||||||
def format_identifier
|
write_attribute(:committer, self.class.to_utf8(arg.to_s))
|
||||||
if repository.class.respond_to? :format_changeset_identifier
|
|
||||||
repository.class.format_changeset_identifier self
|
|
||||||
else
|
|
||||||
identifier
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def project
|
def project
|
||||||
@@ -80,52 +70,59 @@ class Changeset < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def before_create
|
def before_create
|
||||||
self.committer = self.class.to_utf8(self.committer, repository.repo_log_encoding)
|
self.user = repository.find_committer_user(committer)
|
||||||
self.comments = self.class.normalize_comments(
|
|
||||||
self.comments, repository.repo_log_encoding)
|
|
||||||
self.user = repository.find_committer_user(self.committer)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_create
|
def after_create
|
||||||
scan_comment_for_issue_ids
|
scan_comment_for_issue_ids
|
||||||
end
|
end
|
||||||
|
|
||||||
TIMELOG_RE = /
|
|
||||||
(
|
|
||||||
((\d+)(h|hours?))((\d+)(m|min)?)?
|
|
||||||
|
|
|
||||||
((\d+)(h|hours?|m|min))
|
|
||||||
|
|
|
||||||
(\d+):(\d+)
|
|
||||||
|
|
|
||||||
(\d+([\.,]\d+)?)h?
|
|
||||||
)
|
|
||||||
/x
|
|
||||||
|
|
||||||
def scan_comment_for_issue_ids
|
def scan_comment_for_issue_ids
|
||||||
return if comments.blank?
|
return if comments.blank?
|
||||||
# keywords used to reference issues
|
# keywords used to reference issues
|
||||||
ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip)
|
ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip)
|
||||||
ref_keywords_any = ref_keywords.delete('*')
|
|
||||||
# keywords used to fix issues
|
# keywords used to fix issues
|
||||||
fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip)
|
fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip)
|
||||||
|
|
||||||
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
|
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
|
||||||
|
return if kw_regexp.blank?
|
||||||
|
|
||||||
referenced_issues = []
|
referenced_issues = []
|
||||||
|
|
||||||
comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
|
if ref_keywords.delete('*')
|
||||||
action, refs = match[2], match[3]
|
# find any issue ID in the comments
|
||||||
next unless action.present? || ref_keywords_any
|
target_issue_ids = []
|
||||||
|
comments.scan(%r{([\s\(\[,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] }
|
||||||
|
referenced_issues += find_referenced_issues_by_id(target_issue_ids)
|
||||||
|
end
|
||||||
|
|
||||||
refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
|
comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match|
|
||||||
issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
|
action = match[0]
|
||||||
if issue
|
target_issue_ids = match[1].scan(/\d+/)
|
||||||
referenced_issues << issue
|
target_issues = find_referenced_issues_by_id(target_issue_ids)
|
||||||
fix_issue(issue) if fix_keywords.include?(action.to_s.downcase)
|
if fix_keywords.include?(action.downcase) && fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id)
|
||||||
log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
|
# 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, ll(Setting.default_language, :text_status_changed_by_changeset, csettext))
|
||||||
|
issue.status = fix_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 })
|
||||||
|
issue.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
referenced_issues += target_issues
|
||||||
end
|
end
|
||||||
|
|
||||||
referenced_issues.uniq!
|
referenced_issues.uniq!
|
||||||
@@ -140,102 +137,39 @@ class Changeset < ActiveRecord::Base
|
|||||||
@long_comments || split_comments.last
|
@long_comments || split_comments.last
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_tag
|
|
||||||
if scmid?
|
|
||||||
"commit:#{scmid}"
|
|
||||||
else
|
|
||||||
"r#{revision}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the previous changeset
|
# Returns the previous changeset
|
||||||
def previous
|
def previous
|
||||||
@previous ||= Changeset.find(:first,
|
@previous ||= Changeset.find(:first, :conditions => ['id < ? AND repository_id = ?', self.id, self.repository_id], :order => 'id DESC')
|
||||||
:conditions => ['id < ? AND repository_id = ?',
|
|
||||||
self.id, self.repository_id],
|
|
||||||
:order => 'id DESC')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the next changeset
|
# Returns the next changeset
|
||||||
def next
|
def next
|
||||||
@next ||= Changeset.find(:first,
|
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
|
||||||
:conditions => ['id > ? AND repository_id = ?',
|
end
|
||||||
self.id, self.repository_id],
|
|
||||||
:order => 'id ASC')
|
# Strips and reencodes a commit log before insertion into the database
|
||||||
|
def self.normalize_comments(str)
|
||||||
|
to_utf8(str.to_s.strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a new Change from it's common parameters
|
# Creates a new Change from it's common parameters
|
||||||
def create_change(change)
|
def create_change(change)
|
||||||
Change.create(:changeset => self,
|
Change.create(:changeset => self,
|
||||||
:action => change[:action],
|
:action => change[:action],
|
||||||
:path => change[:path],
|
:path => change[:path],
|
||||||
:from_path => change[:from_path],
|
:from_path => change[:from_path],
|
||||||
:from_revision => change[:from_revision])
|
:from_revision => change[:from_revision])
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Finds an issue that can be referenced by the commit message
|
# Finds issues that can be referenced by the commit message
|
||||||
# i.e. an issue that belong to the repository project, a subproject or a parent project
|
# i.e. issues that belong to the repository project, a subproject or a parent project
|
||||||
def find_referenced_issue_by_id(id)
|
def find_referenced_issues_by_id(ids)
|
||||||
return nil if id.blank?
|
return [] if ids.compact.empty?
|
||||||
issue = Issue.find_by_id(id.to_i, :include => :project)
|
Issue.find_all_by_id(ids, :include => :project).select {|issue|
|
||||||
if issue
|
project == issue.project || project.is_ancestor_of?(issue.project) || project.is_descendant_of?(issue.project)
|
||||||
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
|
end
|
||||||
|
|
||||||
def split_comments
|
def split_comments
|
||||||
@@ -245,47 +179,22 @@ class Changeset < ActiveRecord::Base
|
|||||||
return @short_comments, @long_comments
|
return @short_comments, @long_comments
|
||||||
end
|
end
|
||||||
|
|
||||||
public
|
def self.to_utf8(str)
|
||||||
|
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||||
# Strips and reencodes a commit log before insertion into the database
|
encoding = Setting.commit_logs_encoding.to_s.strip
|
||||||
def self.normalize_comments(str, encoding)
|
unless encoding.blank? || encoding == 'UTF-8'
|
||||||
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 = ""
|
|
||||||
begin
|
begin
|
||||||
txtar += ic.iconv(str)
|
str = Iconv.conv('UTF-8', encoding, str)
|
||||||
rescue Iconv::IllegalSequence
|
rescue Iconv::Failure
|
||||||
txtar += $!.success
|
# do nothing here
|
||||||
str = '?' + $!.failed[1,$!.failed.length]
|
|
||||||
retry
|
|
||||||
rescue
|
|
||||||
txtar += $!.success
|
|
||||||
end
|
end
|
||||||
str = txtar
|
|
||||||
end
|
end
|
||||||
str
|
# removes invalid UTF8 sequences
|
||||||
|
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
|
||||||
end
|
end
|
||||||
end
|
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
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -23,6 +23,7 @@ class CustomField < ActiveRecord::Base
|
|||||||
validates_presence_of :name, :field_format
|
validates_presence_of :name, :field_format
|
||||||
validates_uniqueness_of :name, :scope => :type
|
validates_uniqueness_of :name, :scope => :type
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
|
validates_format_of :name, :with => /^[\w\s\.\'\-]*$/i
|
||||||
validates_inclusion_of :field_format, :in => Redmine::CustomFieldFormat.available_formats
|
validates_inclusion_of :field_format, :in => Redmine::CustomFieldFormat.available_formats
|
||||||
|
|
||||||
def initialize(attributes = nil)
|
def initialize(attributes = nil)
|
||||||
@@ -42,49 +43,12 @@ class CustomField < ActiveRecord::Base
|
|||||||
errors.add(:possible_values, :invalid) unless self.possible_values.is_a? Array
|
errors.add(:possible_values, :invalid) unless self.possible_values.is_a? Array
|
||||||
end
|
end
|
||||||
|
|
||||||
if regexp.present?
|
|
||||||
begin
|
|
||||||
Regexp.new(regexp)
|
|
||||||
rescue
|
|
||||||
errors.add(:regexp, :invalid)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# validate default value
|
# validate default value
|
||||||
v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil)
|
v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil)
|
||||||
v.custom_field.is_required = false
|
v.custom_field.is_required = false
|
||||||
errors.add(:default_value, :invalid) unless v.valid?
|
errors.add(:default_value, :invalid) unless v.valid?
|
||||||
end
|
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
|
# Makes possible_values accept a multiline string
|
||||||
def possible_values=(arg)
|
def possible_values=(arg)
|
||||||
if arg.is_a?(Array)
|
if arg.is_a?(Array)
|
||||||
@@ -108,8 +72,6 @@ class CustomField < ActiveRecord::Base
|
|||||||
casted = value.to_i
|
casted = value.to_i
|
||||||
when 'float'
|
when 'float'
|
||||||
casted = value.to_f
|
casted = value.to_f
|
||||||
when 'user', 'version'
|
|
||||||
casted = (value.blank? ? nil : field_format.classify.constantize.find_by_id(value.to_i))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
casted
|
casted
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ class CustomValue < ActiveRecord::Base
|
|||||||
custom_field.editable?
|
custom_field.editable?
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible?
|
|
||||||
custom_field.visible?
|
|
||||||
end
|
|
||||||
|
|
||||||
def required?
|
def required?
|
||||||
custom_field.is_required?
|
custom_field.is_required?
|
||||||
end
|
end
|
||||||
@@ -62,7 +58,7 @@ protected
|
|||||||
when 'float'
|
when 'float'
|
||||||
begin; Kernel.Float(value); rescue; errors.add(:value, :invalid) end
|
begin; Kernel.Float(value); rescue; errors.add(:value, :invalid) end
|
||||||
when 'date'
|
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, :not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/
|
||||||
when 'list'
|
when 'list'
|
||||||
errors.add(:value, :inclusion) unless custom_field.possible_values.include?(value)
|
errors.add(:value, :inclusion) unless custom_field.possible_values.include?(value)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# RedMine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -29,9 +29,6 @@ class Document < ActiveRecord::Base
|
|||||||
validates_presence_of :project, :title, :category
|
validates_presence_of :project, :title, :category
|
||||||
validates_length_of :title, :maximum => 60
|
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)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_documents, project)
|
!user.nil? && user.allowed_to?(:view_documents, project)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -20,3 +20,4 @@ class DocumentCategoryCustomField < CustomField
|
|||||||
:enumeration_doc_categories
|
:enumeration_doc_categories
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ class Enumeration < ActiveRecord::Base
|
|||||||
|
|
||||||
named_scope :shared, :conditions => { :project_id => nil }
|
named_scope :shared, :conditions => { :project_id => nil }
|
||||||
named_scope :active, :conditions => { :active => true }
|
named_scope :active, :conditions => { :active => true }
|
||||||
named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
|
|
||||||
|
|
||||||
def self.default
|
def self.default
|
||||||
# Creates a fake default scope so Enumeration.default will check
|
# Creates a fake default scope so Enumeration.default will check
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ class Group < Principal
|
|||||||
|
|
||||||
def user_added(user)
|
def user_added(user)
|
||||||
members.each do |member|
|
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)
|
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|
|
member.member_roles.each do |member_role|
|
||||||
user_member.member_roles << MemberRole.new(:role => member_role.role, :inherited_from => member_role.id)
|
user_member.member_roles << MemberRole.new(:role => member_role.role, :inherited_from => member_role.id)
|
||||||
|
|||||||
+63
-156
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# 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.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Issue < ActiveRecord::Base
|
class Issue < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :tracker
|
belongs_to :tracker
|
||||||
belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
|
belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
|
||||||
@@ -34,7 +32,7 @@ class Issue < ActiveRecord::Base
|
|||||||
has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
|
has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
|
||||||
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
|
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
|
||||||
|
|
||||||
acts_as_nested_set :scope => 'root_id', :dependent => :destroy
|
acts_as_nested_set :scope => 'root_id'
|
||||||
acts_as_attachable :after_remove => :attachment_removed
|
acts_as_attachable :after_remove => :attachment_removed
|
||||||
acts_as_customizable
|
acts_as_customizable
|
||||||
acts_as_watchable
|
acts_as_watchable
|
||||||
@@ -60,62 +58,24 @@ class Issue < ActiveRecord::Base
|
|||||||
validates_numericality_of :estimated_hours, :allow_nil => true
|
validates_numericality_of :estimated_hours, :allow_nil => true
|
||||||
|
|
||||||
named_scope :visible, lambda {|*args| { :include => :project,
|
named_scope :visible, lambda {|*args| { :include => :project,
|
||||||
:conditions => Issue.visible_condition(args.shift || User.current, *args) } }
|
:conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
|
||||||
|
|
||||||
named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
|
named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
|
||||||
|
|
||||||
named_scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC"
|
named_scope :recently_updated, :order => "#{self.table_name}.updated_on DESC"
|
||||||
named_scope :with_limit, lambda { |limit| { :limit => limit} }
|
named_scope :with_limit, lambda { |limit| { :limit => limit} }
|
||||||
named_scope :on_active_project, :include => [:status, :project, :tracker],
|
named_scope :on_active_project, :include => [:status, :project, :tracker],
|
||||||
:conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
|
:conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
|
||||||
|
|
||||||
named_scope :without_version, lambda {
|
|
||||||
{
|
|
||||||
:conditions => { :fixed_version_id => nil}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
named_scope :with_query, lambda {|query|
|
|
||||||
{
|
|
||||||
:conditions => Query.merge_conditions(query.statement)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
before_create :default_assign
|
before_create :default_assign
|
||||||
before_save :close_duplicates, :update_done_ratio_from_issue_status
|
before_save :reschedule_following_issues, :close_duplicates, :update_done_ratio_from_issue_status
|
||||||
after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal
|
after_save :update_nested_set_attributes, :update_parent_attributes, :create_journal
|
||||||
|
after_destroy :destroy_children
|
||||||
after_destroy :update_parent_attributes
|
after_destroy :update_parent_attributes
|
||||||
|
|
||||||
# Returns a SQL conditions string used to find all issues visible by the specified user
|
|
||||||
def self.visible_condition(user, options={})
|
|
||||||
Project.allowed_to_condition(user, :view_issues, options) do |role, user|
|
|
||||||
case role.issues_visibility
|
|
||||||
when 'all'
|
|
||||||
nil
|
|
||||||
when 'default'
|
|
||||||
"(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id = #{user.id})"
|
|
||||||
when 'own'
|
|
||||||
"(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id = #{user.id})"
|
|
||||||
else
|
|
||||||
'1=0'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns true if usr or current user is allowed to view the issue
|
# Returns true if usr or current user is allowed to view the issue
|
||||||
def visible?(usr=nil)
|
def visible?(usr=nil)
|
||||||
(usr || User.current).allowed_to?(:view_issues, self.project) do |role, user|
|
(usr || User.current).allowed_to?(:view_issues, self.project)
|
||||||
case role.issues_visibility
|
|
||||||
when 'all'
|
|
||||||
true
|
|
||||||
when 'default'
|
|
||||||
!self.is_private? || self.author == user || self.assigned_to == user
|
|
||||||
when 'own'
|
|
||||||
self.author == user || self.assigned_to == user
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
@@ -128,7 +88,7 @@ class Issue < ActiveRecord::Base
|
|||||||
|
|
||||||
# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
|
# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
|
||||||
def available_custom_fields
|
def available_custom_fields
|
||||||
(project && tracker) ? (project.all_issue_custom_fields & tracker.custom_fields.all) : []
|
(project && tracker) ? project.all_issue_custom_fields.select {|c| tracker.custom_fields.include? c } : []
|
||||||
end
|
end
|
||||||
|
|
||||||
def copy_from(arg)
|
def copy_from(arg)
|
||||||
@@ -175,7 +135,6 @@ class Issue < ActiveRecord::Base
|
|||||||
issue.reset_custom_values!
|
issue.reset_custom_values!
|
||||||
end
|
end
|
||||||
if options[:copy]
|
if options[:copy]
|
||||||
issue.author = User.current
|
|
||||||
issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
||||||
issue.status = if options[:attributes] && options[:attributes][:status_id]
|
issue.status = if options[:attributes] && options[:attributes][:status_id]
|
||||||
IssueStatus.find_by_id(options[:attributes][:status_id])
|
IssueStatus.find_by_id(options[:attributes][:status_id])
|
||||||
@@ -188,13 +147,7 @@ class Issue < ActiveRecord::Base
|
|||||||
issue.attributes = options[:attributes]
|
issue.attributes = options[:attributes]
|
||||||
end
|
end
|
||||||
if issue.save
|
if issue.save
|
||||||
if options[:copy]
|
unless options[:copy]
|
||||||
if current_journal && current_journal.notes.present?
|
|
||||||
issue.init_journal(current_journal.user, current_journal.notes)
|
|
||||||
issue.current_journal.notify = false
|
|
||||||
issue.save
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# Manually update project_id on related time entries
|
# Manually update project_id on related time entries
|
||||||
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
|
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
|
||||||
|
|
||||||
@@ -228,13 +181,6 @@ class Issue < ActiveRecord::Base
|
|||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def description=(arg)
|
|
||||||
if arg.is_a?(String)
|
|
||||||
arg = arg.gsub(/(\r\n|\n|\r)/, "\r\n")
|
|
||||||
end
|
|
||||||
write_attribute(:description, arg)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Overrides attributes= so that tracker_id gets assigned first
|
# Overrides attributes= so that tracker_id gets assigned first
|
||||||
def attributes_with_tracker_first=(new_attributes, *args)
|
def attributes_with_tracker_first=(new_attributes, *args)
|
||||||
return if new_attributes.nil?
|
return if new_attributes.nil?
|
||||||
@@ -251,35 +197,23 @@ class Issue < ActiveRecord::Base
|
|||||||
write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
|
write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
|
||||||
end
|
end
|
||||||
|
|
||||||
safe_attributes 'tracker_id',
|
SAFE_ATTRIBUTES = %w(
|
||||||
'status_id',
|
tracker_id
|
||||||
'parent_issue_id',
|
status_id
|
||||||
'category_id',
|
parent_issue_id
|
||||||
'assigned_to_id',
|
category_id
|
||||||
'priority_id',
|
assigned_to_id
|
||||||
'fixed_version_id',
|
priority_id
|
||||||
'subject',
|
fixed_version_id
|
||||||
'description',
|
subject
|
||||||
'start_date',
|
description
|
||||||
'due_date',
|
start_date
|
||||||
'done_ratio',
|
due_date
|
||||||
'estimated_hours',
|
done_ratio
|
||||||
'custom_field_values',
|
estimated_hours
|
||||||
'custom_fields',
|
custom_field_values
|
||||||
'lock_version',
|
lock_version
|
||||||
:if => lambda {|issue, user| issue.new_record? || user.allowed_to?(:edit_issues, issue.project) }
|
) unless const_defined?(:SAFE_ATTRIBUTES)
|
||||||
|
|
||||||
safe_attributes 'status_id',
|
|
||||||
'assigned_to_id',
|
|
||||||
'fixed_version_id',
|
|
||||||
'done_ratio',
|
|
||||||
:if => lambda {|issue, user| issue.new_statuses_allowed_to(user).any? }
|
|
||||||
|
|
||||||
safe_attributes 'is_private',
|
|
||||||
:if => lambda {|issue, user|
|
|
||||||
user.allowed_to?(:set_issues_private, issue.project) ||
|
|
||||||
(issue.author == user && user.allowed_to?(:set_own_issues_private, issue.project))
|
|
||||||
}
|
|
||||||
|
|
||||||
# Safely sets attributes
|
# Safely sets attributes
|
||||||
# Should be called from controllers instead of #attributes=
|
# Should be called from controllers instead of #attributes=
|
||||||
@@ -287,17 +221,8 @@ class Issue < ActiveRecord::Base
|
|||||||
# Issue.new(:project => foo) to work
|
# Issue.new(:project => foo) to work
|
||||||
# TODO: move workflow/permission checks from controllers to here
|
# TODO: move workflow/permission checks from controllers to here
|
||||||
def safe_attributes=(attrs, user=User.current)
|
def safe_attributes=(attrs, user=User.current)
|
||||||
return unless attrs.is_a?(Hash)
|
return if attrs.nil?
|
||||||
|
attrs = attrs.reject {|k,v| !SAFE_ATTRIBUTES.include?(k)}
|
||||||
# User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
|
|
||||||
attrs = delete_unsafe_attributes(attrs, user)
|
|
||||||
return if attrs.empty?
|
|
||||||
|
|
||||||
# Tracker must be set before since new_statuses_allowed_to depends on it.
|
|
||||||
if t = attrs.delete('tracker_id')
|
|
||||||
self.tracker_id = t
|
|
||||||
end
|
|
||||||
|
|
||||||
if attrs['status_id']
|
if attrs['status_id']
|
||||||
unless new_statuses_allowed_to(user).collect(&:id).include?(attrs['status_id'].to_i)
|
unless new_statuses_allowed_to(user).collect(&:id).include?(attrs['status_id'].to_i)
|
||||||
attrs.delete('status_id')
|
attrs.delete('status_id')
|
||||||
@@ -312,7 +237,7 @@ class Issue < ActiveRecord::Base
|
|||||||
if !user.allowed_to?(:manage_subtasks, project)
|
if !user.allowed_to?(:manage_subtasks, project)
|
||||||
attrs.delete('parent_issue_id')
|
attrs.delete('parent_issue_id')
|
||||||
elsif !attrs['parent_issue_id'].blank?
|
elsif !attrs['parent_issue_id'].blank?
|
||||||
attrs.delete('parent_issue_id') unless Issue.visible(user).exists?(attrs['parent_issue_id'].to_i)
|
attrs.delete('parent_issue_id') unless Issue.visible(user).exists?(attrs['parent_issue_id'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -433,13 +358,6 @@ class Issue < ActiveRecord::Base
|
|||||||
!due_date.nil? && (due_date < Date.today) && !status.is_closed?
|
!due_date.nil? && (due_date < Date.today) && !status.is_closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Is the amount of work done less than it should for the due date
|
|
||||||
def behind_schedule?
|
|
||||||
return false if start_date.nil? || due_date.nil?
|
|
||||||
done_date = start_date + ((due_date - start_date+1)* done_ratio/100).floor
|
|
||||||
return done_date <= Date.today
|
|
||||||
end
|
|
||||||
|
|
||||||
# Does this issue have children?
|
# Does this issue have children?
|
||||||
def children?
|
def children?
|
||||||
!leaf?
|
!leaf?
|
||||||
@@ -447,10 +365,7 @@ class Issue < ActiveRecord::Base
|
|||||||
|
|
||||||
# Users the issue can be assigned to
|
# Users the issue can be assigned to
|
||||||
def assignable_users
|
def assignable_users
|
||||||
users = project.assignable_users
|
project.assignable_users
|
||||||
users << author if author
|
|
||||||
users << assigned_to if assigned_to
|
|
||||||
users.uniq.sort
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Versions that the issue can be assigned to
|
# Versions that the issue can be assigned to
|
||||||
@@ -465,12 +380,7 @@ class Issue < ActiveRecord::Base
|
|||||||
|
|
||||||
# Returns an array of status that user is able to apply
|
# Returns an array of status that user is able to apply
|
||||||
def new_statuses_allowed_to(user, include_default=false)
|
def new_statuses_allowed_to(user, include_default=false)
|
||||||
statuses = status.find_new_statuses_allowed_to(
|
statuses = status.find_new_statuses_allowed_to(user.roles_for_project(project), tracker)
|
||||||
user.roles_for_project(project),
|
|
||||||
tracker,
|
|
||||||
author == user,
|
|
||||||
assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id
|
|
||||||
)
|
|
||||||
statuses << status unless statuses.empty?
|
statuses << status unless statuses.empty?
|
||||||
statuses << IssueStatus.default if include_default
|
statuses << IssueStatus.default if include_default
|
||||||
statuses = statuses.uniq.sort
|
statuses = statuses.uniq.sort
|
||||||
@@ -480,10 +390,9 @@ class Issue < ActiveRecord::Base
|
|||||||
# Returns the mail adresses of users that should be notified
|
# Returns the mail adresses of users that should be notified
|
||||||
def recipients
|
def recipients
|
||||||
notified = project.notified_users
|
notified = project.notified_users
|
||||||
# Author and assignee are always notified unless they have been
|
# Author and assignee are always notified unless they have been locked
|
||||||
# locked or don't want to be notified
|
notified << author if author && author.active?
|
||||||
notified << author if author && author.active? && author.notify_about?(self)
|
notified << assigned_to if assigned_to && assigned_to.active?
|
||||||
notified << assigned_to if assigned_to && assigned_to.active? && assigned_to.notify_about?(self)
|
|
||||||
notified.uniq!
|
notified.uniq!
|
||||||
# Remove users that can not view the issue
|
# Remove users that can not view the issue
|
||||||
notified.reject! {|user| !visible?(user)}
|
notified.reject! {|user| !visible?(user)}
|
||||||
@@ -503,14 +412,11 @@ class Issue < ActiveRecord::Base
|
|||||||
(relations_from + relations_to).sort
|
(relations_from + relations_to).sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_dependent_issues(except=[])
|
def all_dependent_issues
|
||||||
except << self
|
|
||||||
dependencies = []
|
dependencies = []
|
||||||
relations_from.each do |relation|
|
relations_from.each do |relation|
|
||||||
if relation.issue_to && !except.include?(relation.issue_to)
|
dependencies << relation.issue_to
|
||||||
dependencies << relation.issue_to
|
dependencies += relation.issue_to.all_dependent_issues
|
||||||
dependencies += relation.issue_to.all_dependent_issues(except)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
dependencies
|
dependencies
|
||||||
end
|
end
|
||||||
@@ -575,9 +481,6 @@ class Issue < ActiveRecord::Base
|
|||||||
s = "issue status-#{status.position} priority-#{priority.position}"
|
s = "issue status-#{status.position} priority-#{priority.position}"
|
||||||
s << ' closed' if closed?
|
s << ' closed' if closed?
|
||||||
s << ' overdue' if overdue?
|
s << ' overdue' if overdue?
|
||||||
s << ' child' if child?
|
|
||||||
s << ' parent' unless leaf?
|
|
||||||
s << ' private' if is_private?
|
|
||||||
s << ' created-by-me' if User.current.logged? && author_id == User.current.id
|
s << ' created-by-me' if User.current.logged? && author_id == User.current.id
|
||||||
s << ' assigned-to-me' if User.current.logged? && assigned_to_id == User.current.id
|
s << ' assigned-to-me' if User.current.logged? && assigned_to_id == User.current.id
|
||||||
s
|
s
|
||||||
@@ -587,7 +490,7 @@ class Issue < ActiveRecord::Base
|
|||||||
# Returns false if save fails
|
# Returns false if save fails
|
||||||
def save_issue_with_child_records(params, existing_time_entry=nil)
|
def save_issue_with_child_records(params, existing_time_entry=nil)
|
||||||
Issue.transaction do
|
Issue.transaction do
|
||||||
if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, project)
|
if params[:time_entry] && params[:time_entry][:hours].present? && User.current.allowed_to?(:log_time, project)
|
||||||
@time_entry = existing_time_entry || TimeEntry.new
|
@time_entry = existing_time_entry || TimeEntry.new
|
||||||
@time_entry.project = project
|
@time_entry.project = project
|
||||||
@time_entry.issue = self
|
@time_entry.issue = self
|
||||||
@@ -691,16 +594,14 @@ class Issue < ActiveRecord::Base
|
|||||||
def self.by_subproject(project)
|
def self.by_subproject(project)
|
||||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||||
s.is_closed as closed,
|
s.is_closed as closed,
|
||||||
#{Issue.table_name}.project_id as project_id,
|
i.project_id as project_id,
|
||||||
count(#{Issue.table_name}.id) as total
|
count(i.id) as total
|
||||||
from
|
from
|
||||||
#{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s
|
#{Issue.table_name} i, #{IssueStatus.table_name} s
|
||||||
where
|
where
|
||||||
#{Issue.table_name}.status_id=s.id
|
i.status_id=s.id
|
||||||
and #{Issue.table_name}.project_id = #{Project.table_name}.id
|
and i.project_id IN (#{project.descendants.active.collect{|p| p.id}.join(',')})
|
||||||
and #{visible_condition(User.current, :project => project, :with_subprojects => true)}
|
group by s.id, s.is_closed, i.project_id") if project.descendants.active.any?
|
||||||
and #{Issue.table_name}.project_id <> #{project.id}
|
|
||||||
group by s.id, s.is_closed, #{Issue.table_name}.project_id") if project.descendants.active.any?
|
|
||||||
end
|
end
|
||||||
# End ReportsController extraction
|
# End ReportsController extraction
|
||||||
|
|
||||||
@@ -810,6 +711,14 @@ class Issue < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_children
|
||||||
|
unless leaf?
|
||||||
|
children.each do |child|
|
||||||
|
child.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Update issues so their versions are not pointing to a
|
# Update issues so their versions are not pointing to a
|
||||||
# fixed_version that is not shared with the issue's project
|
# fixed_version that is not shared with the issue's project
|
||||||
def self.update_versions(conditions=nil)
|
def self.update_versions(conditions=nil)
|
||||||
@@ -877,14 +786,11 @@ class Issue < ActiveRecord::Base
|
|||||||
def create_journal
|
def create_journal
|
||||||
if @current_journal
|
if @current_journal
|
||||||
# attributes changes
|
# attributes changes
|
||||||
(Issue.column_names - %w(id root_id lft rgt lock_version created_on updated_on)).each {|c|
|
(Issue.column_names - %w(id description root_id lft rgt lock_version created_on updated_on)).each {|c|
|
||||||
before = @issue_before_change.send(c)
|
|
||||||
after = send(c)
|
|
||||||
next if before == after || (before.blank? && after.blank?)
|
|
||||||
@current_journal.details << JournalDetail.new(:property => 'attr',
|
@current_journal.details << JournalDetail.new(:property => 'attr',
|
||||||
:prop_key => c,
|
:prop_key => c,
|
||||||
:old_value => @issue_before_change.send(c),
|
:old_value => @issue_before_change.send(c),
|
||||||
:value => send(c))
|
:value => send(c)) unless send(c)==@issue_before_change.send(c)
|
||||||
}
|
}
|
||||||
# custom fields changes
|
# custom fields changes
|
||||||
custom_values.each {|c|
|
custom_values.each {|c|
|
||||||
@@ -913,19 +819,20 @@ class Issue < ActiveRecord::Base
|
|||||||
select_field = options.delete(:field)
|
select_field = options.delete(:field)
|
||||||
joins = options.delete(:joins)
|
joins = options.delete(:joins)
|
||||||
|
|
||||||
where = "#{Issue.table_name}.#{select_field}=j.id"
|
where = "i.#{select_field}=j.id"
|
||||||
|
|
||||||
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
||||||
s.is_closed as closed,
|
s.is_closed as closed,
|
||||||
j.id as #{select_field},
|
j.id as #{select_field},
|
||||||
count(#{Issue.table_name}.id) as total
|
count(i.id) as total
|
||||||
from
|
from
|
||||||
#{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s, #{joins} j
|
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{joins} j
|
||||||
where
|
where
|
||||||
#{Issue.table_name}.status_id=s.id
|
i.status_id=s.id
|
||||||
and #{where}
|
and #{where}
|
||||||
and #{Issue.table_name}.project_id=#{Project.table_name}.id
|
and i.project_id=#{project.id}
|
||||||
and #{visible_condition(User.current, :project => project)}
|
|
||||||
group by s.id, s.is_closed, j.id")
|
group by s.id, s.is_closed, j.id")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# 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_uniqueness_of :name, :scope => [:project_id]
|
||||||
validates_length_of :name, :maximum => 30
|
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
|
alias :destroy_without_reassign :destroy
|
||||||
|
|
||||||
# Destroy the category
|
# Destroy the category
|
||||||
|
|||||||
@@ -47,12 +47,7 @@ class IssueRelation < ActiveRecord::Base
|
|||||||
if issue_from && issue_to
|
if issue_from && issue_to
|
||||||
errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
|
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?
|
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
|
errors.add_to_base :circular_dependency if issue_to.all_dependent_issues.include? issue_from
|
||||||
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_to_base :cant_link_an_issue_with_a_descendant if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -89,15 +84,14 @@ class IssueRelation < ActiveRecord::Base
|
|||||||
|
|
||||||
def set_issue_to_dates
|
def set_issue_to_dates
|
||||||
soonest_start = self.successor_soonest_start
|
soonest_start = self.successor_soonest_start
|
||||||
if soonest_start && issue_to
|
if soonest_start
|
||||||
issue_to.reschedule_after(soonest_start)
|
issue_to.reschedule_after(soonest_start)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def successor_soonest_start
|
def successor_soonest_start
|
||||||
if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && (issue_from.start_date || issue_from.due_date)
|
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
|
(issue_from.due_date || issue_from.start_date) + 1 + delay
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def <=>(relation)
|
def <=>(relation)
|
||||||
|
|||||||
+16
-20
@@ -25,10 +25,9 @@ class IssueStatus < ActiveRecord::Base
|
|||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
|
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
||||||
validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
|
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]}}
|
|
||||||
|
|
||||||
def after_save
|
def after_save
|
||||||
IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
|
IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
|
||||||
end
|
end
|
||||||
@@ -52,15 +51,10 @@ class IssueStatus < ActiveRecord::Base
|
|||||||
|
|
||||||
# Returns an array of all statuses the given role can switch to
|
# Returns an array of all statuses the given role can switch to
|
||||||
# Uses association cache when called more than one time
|
# Uses association cache when called more than one time
|
||||||
def new_statuses_allowed_to(roles, tracker, author=false, assignee=false)
|
def new_statuses_allowed_to(roles, tracker)
|
||||||
if roles && tracker
|
if roles && tracker
|
||||||
role_ids = roles.collect(&:id)
|
role_ids = roles.collect(&:id)
|
||||||
transitions = workflows.select do |w|
|
new_statuses = workflows.select {|w| role_ids.include?(w.role_id) && w.tracker_id == tracker.id}.collect{|w| w.new_status}.compact.sort
|
||||||
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
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
@@ -68,23 +62,25 @@ class IssueStatus < ActiveRecord::Base
|
|||||||
|
|
||||||
# Same thing as above but uses a database query
|
# Same thing as above but uses a database query
|
||||||
# More efficient than the previous method if called just once
|
# More efficient than the previous method if called just once
|
||||||
def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false)
|
def find_new_statuses_allowed_to(roles, tracker)
|
||||||
if roles.present? && tracker
|
if roles && tracker
|
||||||
conditions = "(author = :false AND assignee = :false)"
|
|
||||||
conditions << " OR author = :true" if author
|
|
||||||
conditions << " OR assignee = :true" if assignee
|
|
||||||
|
|
||||||
workflows.find(:all,
|
workflows.find(:all,
|
||||||
:include => :new_status,
|
:include => :new_status,
|
||||||
:conditions => ["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})",
|
:conditions => { :role_id => roles.collect(&:id),
|
||||||
{:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false}
|
:tracker_id => tracker.id}).collect{ |w| w.new_status }.compact.sort
|
||||||
]
|
|
||||||
).collect{|w| w.new_status}.compact.sort
|
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_status_allowed_to?(status, roles, tracker)
|
||||||
|
if status && roles && tracker
|
||||||
|
!workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => roles.collect(&:id), :tracker_id => tracker.id}).nil?
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def <=>(status)
|
def <=>(status)
|
||||||
position <=> status.position
|
position <=> status.position
|
||||||
end
|
end
|
||||||
|
|||||||
+3
-15
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# 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}"}}
|
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
|
||||||
|
|
||||||
acts_as_activity_provider :type => 'issues',
|
acts_as_activity_provider :type => 'issues',
|
||||||
|
:permission => :view_issues,
|
||||||
:author_key => :user_id,
|
:author_key => :user_id,
|
||||||
:find_options => {:include => [{:issue => :project}, :details, :user],
|
:find_options => {:include => [{:issue => :project}, :details, :user],
|
||||||
:conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
:conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
||||||
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
|
" (#{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)
|
def save(*args)
|
||||||
# Do not save an empty journal
|
# Do not save an empty journal
|
||||||
(details.empty? && notes.blank?) ? false : super
|
(details.empty? && notes.blank?) ? false : super
|
||||||
@@ -77,12 +73,4 @@ class Journal < ActiveRecord::Base
|
|||||||
s << ' has-details' unless details.blank?
|
s << ' has-details' unless details.blank?
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify?
|
|
||||||
@notify != false
|
|
||||||
end
|
|
||||||
|
|
||||||
def notify=(arg)
|
|
||||||
@notify = arg
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -17,22 +17,9 @@
|
|||||||
|
|
||||||
class JournalDetail < ActiveRecord::Base
|
class JournalDetail < ActiveRecord::Base
|
||||||
belongs_to :journal
|
belongs_to :journal
|
||||||
before_save :normalize_values
|
|
||||||
|
|
||||||
private
|
def before_save
|
||||||
|
self.value = value[0..254] if value && value.is_a?(String)
|
||||||
def normalize_values
|
self.old_value = old_value[0..254] if old_value && old_value.is_a?(String)
|
||||||
self.value = normalize(value)
|
|
||||||
self.old_value = normalize(old_value)
|
|
||||||
end
|
|
||||||
|
|
||||||
def normalize(v)
|
|
||||||
if v == true
|
|
||||||
"1"
|
|
||||||
elsif v == false
|
|
||||||
"0"
|
|
||||||
else
|
|
||||||
v
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -17,13 +17,6 @@
|
|||||||
|
|
||||||
class JournalObserver < ActiveRecord::Observer
|
class JournalObserver < ActiveRecord::Observer
|
||||||
def after_create(journal)
|
def after_create(journal)
|
||||||
if journal.notify? &&
|
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
||||||
(Setting.notified_events.include?('issue_updated') ||
|
|
||||||
(Setting.notified_events.include?('issue_note_added') && journal.notes.present?) ||
|
|
||||||
(Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) ||
|
|
||||||
(Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?)
|
|
||||||
)
|
|
||||||
Mailer.deliver_issue_edit(journal)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+53
-83
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
class MailHandler < ActionMailer::Base
|
class MailHandler < ActionMailer::Base
|
||||||
include ActionView::Helpers::SanitizeHelper
|
include ActionView::Helpers::SanitizeHelper
|
||||||
include Redmine::I18n
|
|
||||||
|
|
||||||
class UnauthorizedAction < StandardError; end
|
class UnauthorizedAction < StandardError; end
|
||||||
class MissingInformation < StandardError; end
|
class MissingInformation < StandardError; end
|
||||||
@@ -100,7 +99,7 @@ class MailHandler < ActionMailer::Base
|
|||||||
elsif m = email.subject.match(MESSAGE_REPLY_SUBJECT_RE)
|
elsif m = email.subject.match(MESSAGE_REPLY_SUBJECT_RE)
|
||||||
receive_message_reply(m[1].to_i)
|
receive_message_reply(m[1].to_i)
|
||||||
else
|
else
|
||||||
dispatch_to_default
|
receive_issue
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
# TODO: send a email to the user
|
# TODO: send a email to the user
|
||||||
@@ -114,27 +113,39 @@ class MailHandler < ActionMailer::Base
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def dispatch_to_default
|
|
||||||
receive_issue
|
|
||||||
end
|
|
||||||
|
|
||||||
# Creates a new issue
|
# Creates a new issue
|
||||||
def receive_issue
|
def receive_issue
|
||||||
project = target_project
|
project = target_project
|
||||||
|
tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker))) || project.trackers.find(:first)
|
||||||
|
category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
|
||||||
|
priority = (get_keyword(:priority) && IssuePriority.find_by_name(get_keyword(:priority)))
|
||||||
|
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
|
||||||
|
assigned_to = (get_keyword(:assigned_to, :override => true) && find_user_from_keyword(get_keyword(:assigned_to, :override => true)))
|
||||||
|
due_date = get_keyword(:due_date, :override => true)
|
||||||
|
start_date = get_keyword(:start_date, :override => true)
|
||||||
|
|
||||||
# check permission
|
# check permission
|
||||||
unless @@handler_options[:no_permission_check]
|
unless @@handler_options[:no_permission_check]
|
||||||
raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
|
raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
|
||||||
end
|
end
|
||||||
|
|
||||||
issue = Issue.new(:author => user, :project => project)
|
issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority, :due_date => due_date, :start_date => start_date, :assigned_to => assigned_to)
|
||||||
issue.safe_attributes = issue_attributes_from_keywords(issue)
|
# check workflow
|
||||||
issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)}
|
if status && issue.new_statuses_allowed_to(user).include?(status)
|
||||||
issue.subject = email.subject.to_s.chomp[0,255]
|
issue.status = status
|
||||||
|
end
|
||||||
|
issue.subject = email.subject.chomp[0,255]
|
||||||
if issue.subject.blank?
|
if issue.subject.blank?
|
||||||
issue.subject = '(no subject)'
|
issue.subject = '(no subject)'
|
||||||
end
|
end
|
||||||
|
# custom fields
|
||||||
|
issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c|
|
||||||
|
if value = get_keyword(c.name, :override => true)
|
||||||
|
h[c.id] = value
|
||||||
|
end
|
||||||
|
h
|
||||||
|
end
|
||||||
issue.description = cleaned_up_text_body
|
issue.description = cleaned_up_text_body
|
||||||
|
|
||||||
# add To and Cc as watchers before saving so the watchers can reply to Redmine
|
# add To and Cc as watchers before saving so the watchers can reply to Redmine
|
||||||
add_watchers(issue)
|
add_watchers(issue)
|
||||||
issue.save!
|
issue.save!
|
||||||
@@ -143,23 +154,41 @@ class MailHandler < ActionMailer::Base
|
|||||||
issue
|
issue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def target_project
|
||||||
|
# TODO: other ways to specify project:
|
||||||
|
# * parse the email To field
|
||||||
|
# * specific project (eg. Setting.mail_handler_target_project)
|
||||||
|
target = Project.find_by_identifier(get_keyword(:project))
|
||||||
|
raise MissingInformation.new('Unable to determine target project') if target.nil?
|
||||||
|
target
|
||||||
|
end
|
||||||
|
|
||||||
# Adds a note to an existing issue
|
# Adds a note to an existing issue
|
||||||
def receive_issue_reply(issue_id)
|
def receive_issue_reply(issue_id)
|
||||||
|
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
|
||||||
|
due_date = get_keyword(:due_date, :override => true)
|
||||||
|
start_date = get_keyword(:start_date, :override => true)
|
||||||
|
assigned_to = (get_keyword(:assigned_to, :override => true) && find_user_from_keyword(get_keyword(:assigned_to, :override => true)))
|
||||||
|
|
||||||
issue = Issue.find_by_id(issue_id)
|
issue = Issue.find_by_id(issue_id)
|
||||||
return unless issue
|
return unless issue
|
||||||
# check permission
|
# check permission
|
||||||
unless @@handler_options[:no_permission_check]
|
unless @@handler_options[:no_permission_check]
|
||||||
raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project)
|
raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project)
|
||||||
|
raise UnauthorizedAction unless status.nil? || user.allowed_to?(:edit_issues, issue.project)
|
||||||
end
|
end
|
||||||
|
|
||||||
# ignore CLI-supplied defaults for new issues
|
# add the note
|
||||||
@@handler_options[:issue].clear
|
journal = issue.init_journal(user, cleaned_up_text_body)
|
||||||
|
|
||||||
journal = issue.init_journal(user)
|
|
||||||
issue.safe_attributes = issue_attributes_from_keywords(issue)
|
|
||||||
issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)}
|
|
||||||
journal.notes = cleaned_up_text_body
|
|
||||||
add_attachments(issue)
|
add_attachments(issue)
|
||||||
|
# check workflow
|
||||||
|
if status && issue.new_statuses_allowed_to(user).include?(status)
|
||||||
|
issue.status = status
|
||||||
|
end
|
||||||
|
issue.start_date = start_date if start_date
|
||||||
|
issue.due_date = due_date if due_date
|
||||||
|
issue.assigned_to = assigned_to if assigned_to
|
||||||
|
|
||||||
issue.save!
|
issue.save!
|
||||||
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
|
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
|
||||||
journal
|
journal
|
||||||
@@ -198,7 +227,7 @@ class MailHandler < ActionMailer::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_attachments(obj)
|
def add_attachments(obj)
|
||||||
if email.attachments && email.attachments.any?
|
if email.has_attachments?
|
||||||
email.attachments.each do |attachment|
|
email.attachments.each do |attachment|
|
||||||
Attachment.create(:container => obj,
|
Attachment.create(:container => obj,
|
||||||
:file => attachment,
|
:file => attachment,
|
||||||
@@ -226,8 +255,8 @@ class MailHandler < ActionMailer::Base
|
|||||||
@keywords[attr]
|
@keywords[attr]
|
||||||
else
|
else
|
||||||
@keywords[attr] = begin
|
@keywords[attr] = begin
|
||||||
if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && (v = extract_keyword!(plain_text_body, attr, options[:format]))
|
if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body.gsub!(/^#{attr.to_s.humanize}[ \t]*:[ \t]*(.+)\s*$/i, '')
|
||||||
v
|
$1.strip
|
||||||
elsif !@@handler_options[:issue][attr].blank?
|
elsif !@@handler_options[:issue][attr].blank?
|
||||||
@@handler_options[:issue][attr]
|
@@handler_options[:issue][attr]
|
||||||
end
|
end
|
||||||
@@ -235,65 +264,6 @@ class MailHandler < ActionMailer::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Destructively extracts the value for +attr+ in +text+
|
|
||||||
# Returns nil if no matching keyword found
|
|
||||||
def extract_keyword!(text, attr, format=nil)
|
|
||||||
keys = [attr.to_s.humanize]
|
|
||||||
if attr.is_a?(Symbol)
|
|
||||||
keys << l("field_#{attr}", :default => '', :locale => user.language) if user && user.language.present?
|
|
||||||
keys << l("field_#{attr}", :default => '', :locale => Setting.default_language) if Setting.default_language.present?
|
|
||||||
end
|
|
||||||
keys.reject! {|k| k.blank?}
|
|
||||||
keys.collect! {|k| Regexp.escape(k)}
|
|
||||||
format ||= '.+'
|
|
||||||
text.gsub!(/^(#{keys.join('|')})[ \t]*:[ \t]*(#{format})\s*$/i, '')
|
|
||||||
$2 && $2.strip
|
|
||||||
end
|
|
||||||
|
|
||||||
def target_project
|
|
||||||
# TODO: other ways to specify project:
|
|
||||||
# * parse the email To field
|
|
||||||
# * specific project (eg. Setting.mail_handler_target_project)
|
|
||||||
target = Project.find_by_identifier(get_keyword(:project))
|
|
||||||
raise MissingInformation.new('Unable to determine target project') if target.nil?
|
|
||||||
target
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a Hash of issue attributes extracted from keywords in the email body
|
|
||||||
def issue_attributes_from_keywords(issue)
|
|
||||||
assigned_to = (k = get_keyword(:assigned_to, :override => true)) && find_user_from_keyword(k)
|
|
||||||
assigned_to = nil if assigned_to && !issue.assignable_users.include?(assigned_to)
|
|
||||||
|
|
||||||
attrs = {
|
|
||||||
'tracker_id' => (k = get_keyword(:tracker)) && issue.project.trackers.named(k).first.try(:id),
|
|
||||||
'status_id' => (k = get_keyword(:status)) && IssueStatus.named(k).first.try(:id),
|
|
||||||
'priority_id' => (k = get_keyword(:priority)) && IssuePriority.named(k).first.try(:id),
|
|
||||||
'category_id' => (k = get_keyword(:category)) && issue.project.issue_categories.named(k).first.try(:id),
|
|
||||||
'assigned_to_id' => assigned_to.try(:id),
|
|
||||||
'fixed_version_id' => (k = get_keyword(:fixed_version, :override => true)) && issue.project.shared_versions.named(k).first.try(:id),
|
|
||||||
'start_date' => get_keyword(:start_date, :override => true, :format => '\d{4}-\d{2}-\d{2}'),
|
|
||||||
'due_date' => get_keyword(:due_date, :override => true, :format => '\d{4}-\d{2}-\d{2}'),
|
|
||||||
'estimated_hours' => get_keyword(:estimated_hours, :override => true),
|
|
||||||
'done_ratio' => get_keyword(:done_ratio, :override => true, :format => '(\d|10)?0')
|
|
||||||
}.delete_if {|k, v| v.blank? }
|
|
||||||
|
|
||||||
if issue.new_record? && attrs['tracker_id'].nil?
|
|
||||||
attrs['tracker_id'] = issue.project.trackers.find(:first).try(:id)
|
|
||||||
end
|
|
||||||
|
|
||||||
attrs
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a Hash of issue custom field values extracted from keywords in the email body
|
|
||||||
def custom_field_values_from_keywords(customized)
|
|
||||||
customized.custom_field_values.inject({}) do |h, v|
|
|
||||||
if value = get_keyword(v.custom_field.name, :override => true)
|
|
||||||
h[v.custom_field.id.to_s] = value
|
|
||||||
end
|
|
||||||
h
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the text/plain part of the email
|
# Returns the text/plain part of the email
|
||||||
# If not found (eg. HTML-only email), returns the body with tags removed
|
# If not found (eg. HTML-only email), returns the body with tags removed
|
||||||
def plain_text_body
|
def plain_text_body
|
||||||
@@ -348,7 +318,7 @@ class MailHandler < ActionMailer::Base
|
|||||||
def cleanup_body(body)
|
def cleanup_body(body)
|
||||||
delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)}
|
delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)}
|
||||||
unless delimiters.empty?
|
unless delimiters.empty?
|
||||||
regex = Regexp.new("^[> ]*(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE)
|
regex = Regexp.new("^(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE)
|
||||||
body = body.gsub(regex, '')
|
body = body.gsub(regex, '')
|
||||||
end
|
end
|
||||||
body.strip
|
body.strip
|
||||||
|
|||||||
+12
-30
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -85,7 +85,7 @@ class Mailer < ActionMailer::Base
|
|||||||
subject l(:mail_subject_reminder, :count => issues.size, :days => days)
|
subject l(:mail_subject_reminder, :count => issues.size, :days => days)
|
||||||
body :issues => issues,
|
body :issues => issues,
|
||||||
:days => days,
|
:days => days,
|
||||||
:issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort => 'due_date:asc')
|
:issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc')
|
||||||
render_multipart('reminder', body)
|
render_multipart('reminder', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -114,11 +114,11 @@ class Mailer < ActionMailer::Base
|
|||||||
added_to_url = ''
|
added_to_url = ''
|
||||||
case container.class.name
|
case container.class.name
|
||||||
when 'Project'
|
when 'Project'
|
||||||
added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container)
|
added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container)
|
||||||
added_to = "#{l(:label_project)}: #{container}"
|
added_to = "#{l(:label_project)}: #{container}"
|
||||||
recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
|
recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
|
||||||
when 'Version'
|
when 'Version'
|
||||||
added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project)
|
added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
|
||||||
added_to = "#{l(:label_version)}: #{container.name}"
|
added_to = "#{l(:label_version)}: #{container.name}"
|
||||||
recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
|
recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
|
||||||
when 'Document'
|
when 'Document'
|
||||||
@@ -149,24 +149,6 @@ class Mailer < ActionMailer::Base
|
|||||||
render_multipart('news_added', body)
|
render_multipart('news_added', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Builds a tmail object used to email recipients of a news' project when a news comment is added.
|
|
||||||
#
|
|
||||||
# Example:
|
|
||||||
# news_comment_added(comment) => tmail object
|
|
||||||
# Mailer.news_comment_added(comment) => sends an email to the news' project recipients
|
|
||||||
def news_comment_added(comment)
|
|
||||||
news = comment.commented
|
|
||||||
redmine_headers 'Project' => news.project.identifier
|
|
||||||
message_id comment
|
|
||||||
recipients news.recipients
|
|
||||||
cc news.watcher_recipients
|
|
||||||
subject "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
|
|
||||||
body :news => news,
|
|
||||||
:comment => comment,
|
|
||||||
:news_url => url_for(:controller => 'news', :action => 'show', :id => news)
|
|
||||||
render_multipart('news_comment_added', body)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Builds a tmail object used to email the recipients of the specified message that was posted.
|
# Builds a tmail object used to email the recipients of the specified message that was posted.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
@@ -196,9 +178,9 @@ class Mailer < ActionMailer::Base
|
|||||||
message_id wiki_content
|
message_id wiki_content
|
||||||
recipients wiki_content.recipients
|
recipients wiki_content.recipients
|
||||||
cc(wiki_content.page.wiki.watcher_recipients - recipients)
|
cc(wiki_content.page.wiki.watcher_recipients - recipients)
|
||||||
subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}"
|
subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :page => wiki_content.page.pretty_title)}"
|
||||||
body :wiki_content => wiki_content,
|
body :wiki_content => wiki_content,
|
||||||
:wiki_content_url => url_for(:controller => 'wiki', :action => 'show', :project_id => wiki_content.project, :id => wiki_content.page.title)
|
:wiki_content_url => url_for(:controller => 'wiki', :action => 'index', :id => wiki_content.project, :page => wiki_content.page.title)
|
||||||
render_multipart('wiki_content_added', body)
|
render_multipart('wiki_content_added', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -213,10 +195,10 @@ class Mailer < ActionMailer::Base
|
|||||||
message_id wiki_content
|
message_id wiki_content
|
||||||
recipients wiki_content.recipients
|
recipients wiki_content.recipients
|
||||||
cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients)
|
cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients)
|
||||||
subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}"
|
subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :page => wiki_content.page.pretty_title)}"
|
||||||
body :wiki_content => wiki_content,
|
body :wiki_content => wiki_content,
|
||||||
:wiki_content_url => url_for(:controller => 'wiki', :action => 'show', :project_id => wiki_content.project, :id => wiki_content.page.title),
|
:wiki_content_url => url_for(:controller => 'wiki', :action => 'index', :id => wiki_content.project, :page => wiki_content.page.title),
|
||||||
:wiki_diff_url => url_for(:controller => 'wiki', :action => 'diff', :project_id => wiki_content.project, :id => wiki_content.page.title, :version => wiki_content.version)
|
:wiki_diff_url => url_for(:controller => 'wiki', :action => 'diff', :id => wiki_content.project, :page => wiki_content.page.title, :version => wiki_content.version)
|
||||||
render_multipart('wiki_content_updated', body)
|
render_multipart('wiki_content_updated', body)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -314,7 +296,7 @@ class Mailer < ActionMailer::Base
|
|||||||
if raise_errors
|
if raise_errors
|
||||||
raise e
|
raise e
|
||||||
elsif mylogger
|
elsif mylogger
|
||||||
mylogger.error "The following error occured while sending email notification: \"#{e.message}\". Check your configuration in config/configuration.yml."
|
mylogger.error "The following error occured while sending email notification: \"#{e.message}\". Check your configuration in config/email.yml."
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
self.class.raise_delivery_errors = raise_errors
|
self.class.raise_delivery_errors = raise_errors
|
||||||
@@ -344,7 +326,7 @@ class Mailer < ActionMailer::Base
|
|||||||
:conditions => s.conditions
|
:conditions => s.conditions
|
||||||
).group_by(&:assigned_to)
|
).group_by(&:assigned_to)
|
||||||
issues_by_assignee.each do |assignee, issues|
|
issues_by_assignee.each do |assignee, issues|
|
||||||
deliver_reminder(assignee, issues, days) if assignee && assignee.active?
|
deliver_reminder(assignee, issues, days) unless assignee.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -24,7 +24,7 @@ class Message < ActiveRecord::Base
|
|||||||
|
|
||||||
acts_as_searchable :columns => ['subject', 'content'],
|
acts_as_searchable :columns => ['subject', 'content'],
|
||||||
:include => {:board => :project},
|
:include => {:board => :project},
|
||||||
:project_key => "#{Board.table_name}.project_id",
|
:project_key => 'project_id',
|
||||||
:date_column => "#{table_name}.created_on"
|
:date_column => "#{table_name}.created_on"
|
||||||
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
||||||
:description => :content,
|
:description => :content,
|
||||||
@@ -42,9 +42,6 @@ class Message < ActiveRecord::Base
|
|||||||
|
|
||||||
after_create :add_author_as_watcher
|
after_create :add_author_as_watcher
|
||||||
|
|
||||||
named_scope :visible, lambda {|*args| { :include => {:board => :project},
|
|
||||||
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
|
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_messages, project)
|
!user.nil? && user.allowed_to?(:view_messages, project)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
|||||||
+1
-15
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# 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
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -28,14 +28,6 @@ class News < ActiveRecord::Base
|
|||||||
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
||||||
acts_as_activity_provider :find_options => {:include => [:project, :author]},
|
acts_as_activity_provider :find_options => {:include => [:project, :author]},
|
||||||
:author_key => :author_id
|
:author_key => :author_id
|
||||||
acts_as_watchable
|
|
||||||
|
|
||||||
after_create :add_author_as_watcher
|
|
||||||
|
|
||||||
named_scope :visible, lambda {|*args| {
|
|
||||||
:include => :project,
|
|
||||||
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_news, *args)
|
|
||||||
}}
|
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_news, project)
|
!user.nil? && user.allowed_to?(:view_news, project)
|
||||||
@@ -45,10 +37,4 @@ class News < ActiveRecord::Base
|
|||||||
def self.latest(user = User.current, count = 5)
|
def self.latest(user = User.current, count = 5)
|
||||||
find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def add_author_as_watcher
|
|
||||||
Watcher.create(:watchable => self, :user => author)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
+52
-205
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,15 +16,10 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Project < ActiveRecord::Base
|
class Project < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
|
||||||
|
|
||||||
# Project statuses
|
# Project statuses
|
||||||
STATUS_ACTIVE = 1
|
STATUS_ACTIVE = 1
|
||||||
STATUS_ARCHIVED = 9
|
STATUS_ARCHIVED = 9
|
||||||
|
|
||||||
# Maximum length for project identifiers
|
|
||||||
IDENTIFIER_MAX_LENGTH = 100
|
|
||||||
|
|
||||||
# Specific overidden Activities
|
# Specific overidden Activities
|
||||||
has_many :time_entry_activities
|
has_many :time_entry_activities
|
||||||
has_many :members, :include => [:user, :roles], :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}"
|
has_many :members, :include => [:user, :roles], :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}"
|
||||||
@@ -43,7 +38,7 @@ class Project < ActiveRecord::Base
|
|||||||
has_many :time_entries, :dependent => :delete_all
|
has_many :time_entries, :dependent => :delete_all
|
||||||
has_many :queries, :dependent => :delete_all
|
has_many :queries, :dependent => :delete_all
|
||||||
has_many :documents, :dependent => :destroy
|
has_many :documents, :dependent => :destroy
|
||||||
has_many :news, :dependent => :destroy, :include => :author
|
has_many :news, :dependent => :delete_all, :include => :author
|
||||||
has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
|
has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
|
||||||
has_many :boards, :dependent => :destroy, :order => "position ASC"
|
has_many :boards, :dependent => :destroy, :order => "position ASC"
|
||||||
has_one :repository, :dependent => :destroy
|
has_one :repository, :dependent => :destroy
|
||||||
@@ -56,7 +51,7 @@ class Project < ActiveRecord::Base
|
|||||||
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
||||||
:association_foreign_key => 'custom_field_id'
|
:association_foreign_key => 'custom_field_id'
|
||||||
|
|
||||||
acts_as_nested_set :order => 'name', :dependent => :destroy
|
acts_as_nested_set :order => 'name'
|
||||||
acts_as_attachable :view_permission => :view_files,
|
acts_as_attachable :view_permission => :view_files,
|
||||||
:delete_permission => :manage_files
|
:delete_permission => :manage_files
|
||||||
|
|
||||||
@@ -66,43 +61,25 @@ class Project < ActiveRecord::Base
|
|||||||
:url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}},
|
:url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}},
|
||||||
:author => nil
|
:author => nil
|
||||||
|
|
||||||
attr_protected :status
|
attr_protected :status, :enabled_module_names
|
||||||
|
|
||||||
validates_presence_of :name, :identifier
|
validates_presence_of :name, :identifier
|
||||||
validates_uniqueness_of :identifier
|
validates_uniqueness_of :name, :identifier
|
||||||
validates_associated :repository, :wiki
|
validates_associated :repository, :wiki
|
||||||
validates_length_of :name, :maximum => 255
|
validates_length_of :name, :maximum => 30
|
||||||
validates_length_of :homepage, :maximum => 255
|
validates_length_of :homepage, :maximum => 255
|
||||||
validates_length_of :identifier, :in => 1..IDENTIFIER_MAX_LENGTH
|
validates_length_of :identifier, :in => 1..20
|
||||||
# donwcase letters, digits, dashes but not digits only
|
# donwcase letters, digits, dashes but not digits only
|
||||||
validates_format_of :identifier, :with => /^(?!\d+$)[a-z0-9\-]*$/, :if => Proc.new { |p| p.identifier_changed? }
|
validates_format_of :identifier, :with => /^(?!\d+$)[a-z0-9\-]*$/, :if => Proc.new { |p| p.identifier_changed? }
|
||||||
# reserved words
|
# reserved words
|
||||||
validates_exclusion_of :identifier, :in => %w( new )
|
validates_exclusion_of :identifier, :in => %w( new )
|
||||||
|
|
||||||
before_destroy :delete_all_members
|
before_destroy :delete_all_members, :destroy_children
|
||||||
|
|
||||||
named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
|
named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
|
||||||
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
|
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
|
||||||
named_scope :all_public, { :conditions => { :is_public => true } }
|
named_scope :all_public, { :conditions => { :is_public => true } }
|
||||||
named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
|
named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
|
||||||
|
|
||||||
def initialize(attributes = nil)
|
|
||||||
super
|
|
||||||
|
|
||||||
initialized = (attributes || {}).stringify_keys
|
|
||||||
if !initialized.key?('identifier') && Setting.sequential_project_identifiers?
|
|
||||||
self.identifier = Project.next_identifier
|
|
||||||
end
|
|
||||||
if !initialized.key?('is_public')
|
|
||||||
self.is_public = Setting.default_projects_public?
|
|
||||||
end
|
|
||||||
if !initialized.key?('enabled_module_names')
|
|
||||||
self.enabled_module_names = Setting.default_projects_modules
|
|
||||||
end
|
|
||||||
if !initialized.key?('trackers') && !initialized.key?('tracker_ids')
|
|
||||||
self.trackers = Tracker.all
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def identifier=(identifier)
|
def identifier=(identifier)
|
||||||
super unless identifier_frozen?
|
super unless identifier_frozen?
|
||||||
@@ -115,36 +92,27 @@ class Project < ActiveRecord::Base
|
|||||||
# returns latest created projects
|
# returns latest created projects
|
||||||
# non public projects will be returned only if user is a member of those
|
# non public projects will be returned only if user is a member of those
|
||||||
def self.latest(user=nil, count=5)
|
def self.latest(user=nil, count=5)
|
||||||
visible(user).find(:all, :limit => count, :order => "created_on DESC")
|
find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if the project is visible to +user+ or to the current user.
|
# Returns a SQL :conditions string used to find all active projects for the specified user.
|
||||||
def visible?(user=User.current)
|
|
||||||
user.allowed_to?(:view_project, self)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.visible_by(user=nil)
|
|
||||||
ActiveSupport::Deprecation.warn "Project.visible_by is deprecated and will be removed in Redmine 1.3.0. Use Project.visible_condition instead."
|
|
||||||
visible_condition(user || User.current)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a SQL conditions string used to find all projects visible by the specified user.
|
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
# Project.visible_condition(admin) => "projects.status = 1"
|
# Projects.visible_by(admin) => "projects.status = 1"
|
||||||
# Project.visible_condition(normal_user) => "((projects.status = 1) AND (projects.is_public = 1 OR projects.id IN (1,3,4)))"
|
# Projects.visible_by(normal_user) => "projects.status = 1 AND projects.is_public = 1"
|
||||||
# Project.visible_condition(anonymous) => "((projects.status = 1) AND (projects.is_public = 1))"
|
def self.visible_by(user=nil)
|
||||||
def self.visible_condition(user, options={})
|
user ||= User.current
|
||||||
allowed_to_condition(user, :view_project, options)
|
if user && user.admin?
|
||||||
|
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
||||||
|
elsif user && user.memberships.any?
|
||||||
|
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))"
|
||||||
|
else
|
||||||
|
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+
|
|
||||||
#
|
|
||||||
# Valid options:
|
|
||||||
# * :project => limit the condition to project
|
|
||||||
# * :with_subprojects => limit the condition to project and its subprojects
|
|
||||||
# * :member => limit the condition to the user projects
|
|
||||||
def self.allowed_to_condition(user, permission, options={})
|
def self.allowed_to_condition(user, permission, options={})
|
||||||
|
statements = []
|
||||||
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
||||||
if perm = Redmine::AccessControl.permission(permission)
|
if perm = Redmine::AccessControl.permission(permission)
|
||||||
unless perm.project_module.nil?
|
unless perm.project_module.nil?
|
||||||
@@ -157,37 +125,24 @@ class Project < ActiveRecord::Base
|
|||||||
project_statement << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
|
project_statement << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
|
||||||
base_statement = "(#{project_statement}) AND (#{base_statement})"
|
base_statement = "(#{project_statement}) AND (#{base_statement})"
|
||||||
end
|
end
|
||||||
|
|
||||||
if user.admin?
|
if user.admin?
|
||||||
base_statement
|
# no restriction
|
||||||
else
|
else
|
||||||
statement_by_role = {}
|
statements << "1=0"
|
||||||
unless options[:member]
|
|
||||||
role = user.logged? ? Role.non_member : Role.anonymous
|
|
||||||
if role.allowed_to?(permission)
|
|
||||||
statement_by_role[role] = "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if user.logged?
|
if user.logged?
|
||||||
user.projects_by_role.each do |role, projects|
|
if Role.non_member.allowed_to?(permission) && !options[:member]
|
||||||
if role.allowed_to?(permission)
|
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
||||||
statement_by_role[role] = "#{Project.table_name}.id IN (#{projects.collect(&:id).join(',')})"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
allowed_project_ids = user.memberships.select {|m| m.roles.detect {|role| role.allowed_to?(permission)}}.collect {|m| m.project_id}
|
||||||
if statement_by_role.empty?
|
statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
|
||||||
"1=0"
|
|
||||||
else
|
else
|
||||||
if block_given?
|
if Role.anonymous.allowed_to?(permission) && !options[:member]
|
||||||
statement_by_role.each do |role, statement|
|
# anonymous user allowed on public project
|
||||||
if s = yield(role, user)
|
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
||||||
statement_by_role[role] = "(#{statement} AND (#{s}))"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
"((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the Systemwide and project specific activities
|
# Returns the Systemwide and project specific activities
|
||||||
@@ -265,10 +220,6 @@ class Project < ActiveRecord::Base
|
|||||||
self.status == STATUS_ACTIVE
|
self.status == STATUS_ACTIVE
|
||||||
end
|
end
|
||||||
|
|
||||||
def archived?
|
|
||||||
self.status == STATUS_ARCHIVED
|
|
||||||
end
|
|
||||||
|
|
||||||
# Archives the project and its descendants
|
# Archives the project and its descendants
|
||||||
def archive
|
def archive
|
||||||
# Check that there is no issue of a non descendant project that is assigned
|
# Check that there is no issue of a non descendant project that is assigned
|
||||||
@@ -369,7 +320,7 @@ class Project < ActiveRecord::Base
|
|||||||
# Returns an array of the trackers used by the project and its active sub projects
|
# Returns an array of the trackers used by the project and its active sub projects
|
||||||
def rolled_up_trackers
|
def rolled_up_trackers
|
||||||
@rolled_up_trackers ||=
|
@rolled_up_trackers ||=
|
||||||
Tracker.find(:all, :joins => :projects,
|
Tracker.find(:all, :include => :projects,
|
||||||
:select => "DISTINCT #{Tracker.table_name}.*",
|
:select => "DISTINCT #{Tracker.table_name}.*",
|
||||||
:conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
|
:conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
|
||||||
:order => "#{Tracker.table_name}.position")
|
:order => "#{Tracker.table_name}.position")
|
||||||
@@ -395,17 +346,15 @@ class Project < ActiveRecord::Base
|
|||||||
|
|
||||||
# Returns a scope of the Versions used by the project
|
# Returns a scope of the Versions used by the project
|
||||||
def shared_versions
|
def shared_versions
|
||||||
@shared_versions ||= begin
|
@shared_versions ||=
|
||||||
r = root? ? self : root
|
|
||||||
Version.scoped(:include => :project,
|
Version.scoped(:include => :project,
|
||||||
:conditions => "#{Project.table_name}.id = #{id}" +
|
:conditions => "#{Project.table_name}.id = #{id}" +
|
||||||
" OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
|
" OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
|
||||||
" #{Version.table_name}.sharing = 'system'" +
|
" #{Version.table_name}.sharing = 'system'" +
|
||||||
" OR (#{Project.table_name}.lft >= #{r.lft} AND #{Project.table_name}.rgt <= #{r.rgt} AND #{Version.table_name}.sharing = 'tree')" +
|
" OR (#{Project.table_name}.lft >= #{root.lft} AND #{Project.table_name}.rgt <= #{root.rgt} AND #{Version.table_name}.sharing = 'tree')" +
|
||||||
" OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" +
|
" OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" +
|
||||||
" OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
|
" OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
|
||||||
"))")
|
"))")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a hash of project users grouped by role
|
# Returns a hash of project users grouped by role
|
||||||
@@ -433,13 +382,12 @@ class Project < ActiveRecord::Base
|
|||||||
|
|
||||||
# Returns the mail adresses of users that should be always notified on project events
|
# Returns the mail adresses of users that should be always notified on project events
|
||||||
def recipients
|
def recipients
|
||||||
notified_users.collect {|user| user.mail}
|
members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the users that should be notified on project events
|
# Returns the users that should be notified on project events
|
||||||
def notified_users
|
def notified_users
|
||||||
# TODO: User part should be extracted to User#notify_about?
|
members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user}
|
||||||
members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of all custom fields enabled for project issues
|
# Returns an array of all custom fields enabled for project issues
|
||||||
@@ -448,12 +396,6 @@ class Project < ActiveRecord::Base
|
|||||||
@all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort
|
@all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of all custom fields enabled for project time entries
|
|
||||||
# (explictly associated custom fields and custom fields enabled for all projects)
|
|
||||||
def all_time_entry_custom_fields
|
|
||||||
@all_time_entry_custom_fields ||= (TimeEntryCustomField.for_all + time_entry_custom_fields).uniq.sort
|
|
||||||
end
|
|
||||||
|
|
||||||
def project
|
def project
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
@@ -479,46 +421,6 @@ class Project < ActiveRecord::Base
|
|||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
# The earliest start date of a project, based on it's issues and versions
|
|
||||||
def start_date
|
|
||||||
[
|
|
||||||
issues.minimum('start_date'),
|
|
||||||
shared_versions.collect(&:effective_date),
|
|
||||||
shared_versions.collect(&:start_date)
|
|
||||||
].flatten.compact.min
|
|
||||||
end
|
|
||||||
|
|
||||||
# The latest due date of an issue or version
|
|
||||||
def due_date
|
|
||||||
[
|
|
||||||
issues.maximum('due_date'),
|
|
||||||
shared_versions.collect(&:effective_date),
|
|
||||||
shared_versions.collect {|v| v.fixed_issues.maximum('due_date')}
|
|
||||||
].flatten.compact.max
|
|
||||||
end
|
|
||||||
|
|
||||||
def overdue?
|
|
||||||
active? && !due_date.nil? && (due_date < Date.today)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the percent completed for this project, based on the
|
|
||||||
# progress on it's versions.
|
|
||||||
def completed_percent(options={:include_subprojects => false})
|
|
||||||
if options.delete(:include_subprojects)
|
|
||||||
total = self_and_descendants.collect(&:completed_percent).sum
|
|
||||||
|
|
||||||
total / self_and_descendants.count
|
|
||||||
else
|
|
||||||
if versions.count > 0
|
|
||||||
total = versions.collect(&:completed_pourcent).sum
|
|
||||||
|
|
||||||
total / versions.count
|
|
||||||
else
|
|
||||||
100
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return true if this project is allowed to do the specified action.
|
# Return true if this project is allowed to do the specified action.
|
||||||
# action can be:
|
# action can be:
|
||||||
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
||||||
@@ -538,51 +440,16 @@ class Project < ActiveRecord::Base
|
|||||||
|
|
||||||
def enabled_module_names=(module_names)
|
def enabled_module_names=(module_names)
|
||||||
if module_names && module_names.is_a?(Array)
|
if module_names && module_names.is_a?(Array)
|
||||||
module_names = module_names.collect(&:to_s).reject(&:blank?)
|
module_names = module_names.collect(&:to_s)
|
||||||
self.enabled_modules = module_names.collect {|name| enabled_modules.detect {|mod| mod.name == name} || EnabledModule.new(:name => name)}
|
# remove disabled modules
|
||||||
|
enabled_modules.each {|mod| mod.destroy unless module_names.include?(mod.name)}
|
||||||
|
# add new modules
|
||||||
|
module_names.reject {|name| module_enabled?(name)}.each {|name| enabled_modules << EnabledModule.new(:name => name)}
|
||||||
else
|
else
|
||||||
enabled_modules.clear
|
enabled_modules.clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of the enabled modules names
|
|
||||||
def enabled_module_names
|
|
||||||
enabled_modules.collect(&:name)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Enable a specific module
|
|
||||||
#
|
|
||||||
# Examples:
|
|
||||||
# project.enable_module!(:issue_tracking)
|
|
||||||
# project.enable_module!("issue_tracking")
|
|
||||||
def enable_module!(name)
|
|
||||||
enabled_modules << EnabledModule.new(:name => name.to_s) unless module_enabled?(name)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Disable a module if it exists
|
|
||||||
#
|
|
||||||
# Examples:
|
|
||||||
# project.disable_module!(:issue_tracking)
|
|
||||||
# project.disable_module!("issue_tracking")
|
|
||||||
# project.disable_module!(project.enabled_modules.first)
|
|
||||||
def disable_module!(target)
|
|
||||||
target = enabled_modules.detect{|mod| target.to_s == mod.name} unless enabled_modules.include?(target)
|
|
||||||
target.destroy unless target.blank?
|
|
||||||
end
|
|
||||||
|
|
||||||
safe_attributes 'name',
|
|
||||||
'description',
|
|
||||||
'homepage',
|
|
||||||
'is_public',
|
|
||||||
'identifier',
|
|
||||||
'custom_field_values',
|
|
||||||
'custom_fields',
|
|
||||||
'tracker_ids',
|
|
||||||
'issue_custom_field_ids'
|
|
||||||
|
|
||||||
safe_attributes 'enabled_module_names',
|
|
||||||
:if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) }
|
|
||||||
|
|
||||||
# Returns an array of projects that are in this project's hierarchy
|
# Returns an array of projects that are in this project's hierarchy
|
||||||
#
|
#
|
||||||
# Example: parents, children, siblings
|
# Example: parents, children, siblings
|
||||||
@@ -654,20 +521,15 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Yields the given block for each project with its level in the tree
|
private
|
||||||
def self.project_tree(projects, &block)
|
|
||||||
ancestors = []
|
# Destroys children before destroying self
|
||||||
projects.sort_by(&:lft).each do |project|
|
def destroy_children
|
||||||
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
children.each do |child|
|
||||||
ancestors.pop
|
child.destroy
|
||||||
end
|
|
||||||
yield project, ancestors.size
|
|
||||||
ancestors << project
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# Copies wiki from +project+
|
# Copies wiki from +project+
|
||||||
def copy_wiki(project)
|
def copy_wiki(project)
|
||||||
# Check that the source project has a wiki first
|
# Check that the source project has a wiki first
|
||||||
@@ -714,7 +576,6 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Copies issues from +project+
|
# Copies issues from +project+
|
||||||
# Note: issues assigned to a closed version won't be copied due to validation rules
|
|
||||||
def copy_issues(project)
|
def copy_issues(project)
|
||||||
# Stores the source issue id as a key and the copied issues as the
|
# Stores the source issue id as a key and the copied issues as the
|
||||||
# value. Used to map the two togeather for issue relations.
|
# value. Used to map the two togeather for issue relations.
|
||||||
@@ -744,20 +605,12 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.issues << new_issue
|
self.issues << new_issue
|
||||||
if new_issue.new_record?
|
issues_map[issue.id] = new_issue
|
||||||
logger.info "Project#copy_issues: issue ##{issue.id} could not be copied: #{new_issue.errors.full_messages}" if logger && logger.info
|
|
||||||
else
|
|
||||||
issues_map[issue.id] = new_issue unless new_issue.new_record?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Relations after in case issues related each other
|
# Relations after in case issues related each other
|
||||||
project.issues.each do |issue|
|
project.issues.each do |issue|
|
||||||
new_issue = issues_map[issue.id]
|
new_issue = issues_map[issue.id]
|
||||||
unless new_issue
|
|
||||||
# Issue was not copied
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
# Relations
|
# Relations
|
||||||
issue.relations_from.each do |source_relation|
|
issue.relations_from.each do |source_relation|
|
||||||
@@ -784,12 +637,7 @@ class Project < ActiveRecord::Base
|
|||||||
|
|
||||||
# Copies members from +project+
|
# Copies members from +project+
|
||||||
def copy_members(project)
|
def copy_members(project)
|
||||||
# Copy users first, then groups to handle members with inherited and given roles
|
project.memberships.each do |member|
|
||||||
members_to_copy = []
|
|
||||||
members_to_copy += project.memberships.select {|m| m.principal.is_a?(User)}
|
|
||||||
members_to_copy += project.memberships.select {|m| !m.principal.is_a?(User)}
|
|
||||||
|
|
||||||
members_to_copy.each do |member|
|
|
||||||
new_member = Member.new
|
new_member = Member.new
|
||||||
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
|
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
|
||||||
# only copy non inherited roles
|
# only copy non inherited roles
|
||||||
@@ -809,7 +657,6 @@ class Project < ActiveRecord::Base
|
|||||||
new_query.attributes = query.attributes.dup.except("id", "project_id", "sort_criteria")
|
new_query.attributes = query.attributes.dup.except("id", "project_id", "sort_criteria")
|
||||||
new_query.sort_criteria = query.sort_criteria if query.sort_criteria
|
new_query.sort_criteria = query.sort_criteria if query.sort_criteria
|
||||||
new_query.project = self
|
new_query.project = self
|
||||||
new_query.user_id = query.user_id
|
|
||||||
self.queries << new_query
|
self.queries << new_query
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+47
-132
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# 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
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -42,10 +42,6 @@ class QueryColumn
|
|||||||
def value(issue)
|
def value(issue)
|
||||||
issue.send name
|
issue.send name
|
||||||
end
|
end
|
||||||
|
|
||||||
def css_classes
|
|
||||||
name
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class QueryCustomFieldColumn < QueryColumn
|
class QueryCustomFieldColumn < QueryColumn
|
||||||
@@ -72,10 +68,6 @@ class QueryCustomFieldColumn < QueryColumn
|
|||||||
cv = issue.custom_values.detect {|v| v.custom_field_id == @cf.id}
|
cv = issue.custom_values.detect {|v| v.custom_field_id == @cf.id}
|
||||||
cv && @cf.cast_value(cv.value)
|
cv && @cf.cast_value(cv.value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def css_classes
|
|
||||||
@css_classes ||= "#{name} #{@cf.field_format}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Query < ActiveRecord::Base
|
class Query < ActiveRecord::Base
|
||||||
@@ -166,11 +158,6 @@ class Query < ActiveRecord::Base
|
|||||||
end if filters
|
end if filters
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if the query is visible to +user+ or the current user.
|
|
||||||
def visible?(user=User.current)
|
|
||||||
self.is_public? || self.user_id == user.id
|
|
||||||
end
|
|
||||||
|
|
||||||
def editable_by?(user)
|
def editable_by?(user)
|
||||||
return false unless user
|
return false unless user
|
||||||
# Admin can edit them all and regular users can edit their private queries
|
# Admin can edit them all and regular users can edit their private queries
|
||||||
@@ -200,48 +187,29 @@ class Query < ActiveRecord::Base
|
|||||||
if project
|
if project
|
||||||
user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] }
|
user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] }
|
||||||
else
|
else
|
||||||
all_projects = Project.visible.all
|
project_ids = Project.all(:conditions => Project.visible_by(User.current)).collect(&:id)
|
||||||
if all_projects.any?
|
if project_ids.any?
|
||||||
# members of visible projects
|
# members of the user's projects
|
||||||
user_values += User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", all_projects.collect(&:id)]).sort.collect{|s| [s.name, s.id.to_s] }
|
user_values += User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", project_ids]).sort.collect{|s| [s.name, s.id.to_s] }
|
||||||
|
|
||||||
# project filter
|
|
||||||
project_values = []
|
|
||||||
Project.project_tree(all_projects) do |p, level|
|
|
||||||
prefix = (level > 0 ? ('--' * level + ' ') : '')
|
|
||||||
project_values << ["#{prefix}#{p.name}", p.id.to_s]
|
|
||||||
end
|
|
||||||
@available_filters["project_id"] = { :type => :list, :order => 1, :values => project_values} unless project_values.empty?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
|
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
|
||||||
@available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
|
@available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
|
||||||
|
|
||||||
group_values = Group.all.collect {|g| [g.name, g.id.to_s] }
|
|
||||||
@available_filters["member_of_group"] = { :type => :list_optional, :order => 6, :values => group_values } unless group_values.empty?
|
|
||||||
|
|
||||||
role_values = Role.givable.collect {|r| [r.name, r.id.to_s] }
|
|
||||||
@available_filters["assigned_to_role"] = { :type => :list_optional, :order => 7, :values => role_values } unless role_values.empty?
|
|
||||||
|
|
||||||
if User.current.logged?
|
if User.current.logged?
|
||||||
@available_filters["watcher_id"] = { :type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]] }
|
@available_filters["watcher_id"] = { :type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]] }
|
||||||
end
|
end
|
||||||
|
|
||||||
if project
|
if project
|
||||||
# project specific filters
|
# project specific filters
|
||||||
categories = @project.issue_categories.all
|
unless @project.issue_categories.empty?
|
||||||
unless categories.empty?
|
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
|
||||||
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => categories.collect{|s| [s.name, s.id.to_s] } }
|
|
||||||
end
|
end
|
||||||
versions = @project.shared_versions.all
|
unless @project.shared_versions.empty?
|
||||||
unless versions.empty?
|
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
|
||||||
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
|
|
||||||
end
|
end
|
||||||
unless @project.leaf?
|
unless @project.descendants.active.empty?
|
||||||
subprojects = @project.descendants.visible.all
|
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.descendants.visible.collect{|s| [s.name, s.id.to_s] } }
|
||||||
unless subprojects.empty?
|
|
||||||
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => subprojects.collect{|s| [s.name, s.id.to_s] } }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
add_custom_fields_filters(@project.all_issue_custom_fields)
|
add_custom_fields_filters(@project.all_issue_custom_fields)
|
||||||
else
|
else
|
||||||
@@ -251,6 +219,12 @@ class Query < ActiveRecord::Base
|
|||||||
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => system_shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
|
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => system_shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
|
||||||
end
|
end
|
||||||
add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
|
add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
|
||||||
|
# project filter
|
||||||
|
project_values = Project.all(:conditions => Project.visible_by(User.current), :order => 'lft').map do |p|
|
||||||
|
pre = (p.level > 0 ? ('--' * p.level + ' ') : '')
|
||||||
|
["#{pre}#{p.name}",p.id.to_s]
|
||||||
|
end
|
||||||
|
@available_filters["project_id"] = { :type => :list, :order => 1, :values => project_values}
|
||||||
end
|
end
|
||||||
@available_filters
|
@available_filters
|
||||||
end
|
end
|
||||||
@@ -278,10 +252,8 @@ class Query < ActiveRecord::Base
|
|||||||
|
|
||||||
# Add multiple filters using +add_filter+
|
# Add multiple filters using +add_filter+
|
||||||
def add_filters(fields, operators, values)
|
def add_filters(fields, operators, values)
|
||||||
if fields.is_a?(Array) && operators.is_a?(Hash) && values.is_a?(Hash)
|
fields.each do |field|
|
||||||
fields.each do |field|
|
add_filter(field, operators[field], values[field])
|
||||||
add_filter(field, operators[field], values[field])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -333,17 +305,14 @@ class Query < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def columns
|
def columns
|
||||||
# preserve the column_names order
|
if has_default_columns?
|
||||||
(has_default_columns? ? default_columns_names : column_names).collect do |name|
|
available_columns.select do |c|
|
||||||
available_columns.find { |col| col.name == name }
|
# Adds the project column by default for cross-project lists
|
||||||
end.compact
|
Setting.issue_list_default_columns.include?(c.name.to_s) || (c.name == :project && project.nil?)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
def default_columns_names
|
# preserve the column_names order
|
||||||
@default_columns_names ||= begin
|
column_names.collect {|name| available_columns.find {|col| col.name == name}}.compact
|
||||||
default_columns = Setting.issue_list_default_columns.map(&:to_sym)
|
|
||||||
|
|
||||||
project.present? ? default_columns : [:project] | default_columns
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -352,7 +321,7 @@ class Query < ActiveRecord::Base
|
|||||||
names = names.select {|n| n.is_a?(Symbol) || !n.blank? }
|
names = names.select {|n| n.is_a?(Symbol) || !n.blank? }
|
||||||
names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym }
|
names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym }
|
||||||
# Set column_names to nil if default columns
|
# Set column_names to nil if default columns
|
||||||
if names == default_columns_names
|
if names.map(&:to_s) == Setting.issue_list_default_columns
|
||||||
names = nil
|
names = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -399,15 +368,15 @@ class Query < ActiveRecord::Base
|
|||||||
|
|
||||||
# Returns true if the query is a grouped query
|
# Returns true if the query is a grouped query
|
||||||
def grouped?
|
def grouped?
|
||||||
!group_by_column.nil?
|
!group_by.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_by_column
|
def group_by_column
|
||||||
groupable_columns.detect {|c| c.groupable && c.name.to_s == group_by}
|
groupable_columns.detect {|c| c.name.to_s == group_by}
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_by_statement
|
def group_by_statement
|
||||||
group_by_column.try(:groupable)
|
group_by_column.groupable
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_statement
|
def project_statement
|
||||||
@@ -432,7 +401,8 @@ class Query < ActiveRecord::Base
|
|||||||
elsif project
|
elsif project
|
||||||
project_clauses << "#{Project.table_name}.id = %d" % project.id
|
project_clauses << "#{Project.table_name}.id = %d" % project.id
|
||||||
end
|
end
|
||||||
project_clauses.any? ? project_clauses.join(' AND ') : nil
|
project_clauses << Project.allowed_to_condition(User.current, :view_issues)
|
||||||
|
project_clauses.join(' AND ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def statement
|
def statement
|
||||||
@@ -462,47 +432,6 @@ class Query < ActiveRecord::Base
|
|||||||
db_field = 'user_id'
|
db_field = 'user_id'
|
||||||
sql << "#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND "
|
sql << "#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND "
|
||||||
sql << sql_for_field(field, '=', v, db_table, db_field) + ')'
|
sql << sql_for_field(field, '=', v, db_table, db_field) + ')'
|
||||||
elsif field == "member_of_group" # named field
|
|
||||||
if operator == '*' # Any group
|
|
||||||
groups = Group.all
|
|
||||||
operator = '=' # Override the operator since we want to find by assigned_to
|
|
||||||
elsif operator == "!*"
|
|
||||||
groups = Group.all
|
|
||||||
operator = '!' # Override the operator since we want to find by assigned_to
|
|
||||||
else
|
|
||||||
groups = Group.find_all_by_id(v)
|
|
||||||
end
|
|
||||||
groups ||= []
|
|
||||||
|
|
||||||
members_of_groups = groups.inject([]) {|user_ids, group|
|
|
||||||
if group && group.user_ids.present?
|
|
||||||
user_ids << group.user_ids
|
|
||||||
end
|
|
||||||
user_ids.flatten.uniq.compact
|
|
||||||
}.sort.collect(&:to_s)
|
|
||||||
|
|
||||||
sql << '(' + sql_for_field("assigned_to_id", operator, members_of_groups, Issue.table_name, "assigned_to_id", false) + ')'
|
|
||||||
|
|
||||||
elsif field == "assigned_to_role" # named field
|
|
||||||
if operator == "*" # Any Role
|
|
||||||
roles = Role.givable
|
|
||||||
operator = '=' # Override the operator since we want to find by assigned_to
|
|
||||||
elsif operator == "!*" # No role
|
|
||||||
roles = Role.givable
|
|
||||||
operator = '!' # Override the operator since we want to find by assigned_to
|
|
||||||
else
|
|
||||||
roles = Role.givable.find_all_by_id(v)
|
|
||||||
end
|
|
||||||
roles ||= []
|
|
||||||
|
|
||||||
members_of_roles = roles.inject([]) {|user_ids, role|
|
|
||||||
if role && role.members
|
|
||||||
user_ids << role.members.collect(&:user_id)
|
|
||||||
end
|
|
||||||
user_ids.flatten.uniq.compact
|
|
||||||
}.sort.collect(&:to_s)
|
|
||||||
|
|
||||||
sql << '(' + sql_for_field("assigned_to_id", operator, members_of_roles, Issue.table_name, "assigned_to_id", false) + ')'
|
|
||||||
else
|
else
|
||||||
# regular field
|
# regular field
|
||||||
db_table = Issue.table_name
|
db_table = Issue.table_name
|
||||||
@@ -513,15 +442,12 @@ class Query < ActiveRecord::Base
|
|||||||
|
|
||||||
end if filters and valid?
|
end if filters and valid?
|
||||||
|
|
||||||
filters_clauses << project_statement
|
(filters_clauses << project_statement).join(' AND ')
|
||||||
filters_clauses.reject!(&:blank?)
|
|
||||||
|
|
||||||
filters_clauses.any? ? filters_clauses.join(' AND ') : nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the issue count
|
# Returns the issue count
|
||||||
def issue_count
|
def issue_count
|
||||||
Issue.visible.count(:include => [:status, :project], :conditions => statement)
|
Issue.count(:include => [:status, :project], :conditions => statement)
|
||||||
rescue ::ActiveRecord::StatementInvalid => e
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
raise StatementInvalid.new(e.message)
|
raise StatementInvalid.new(e.message)
|
||||||
end
|
end
|
||||||
@@ -532,7 +458,7 @@ class Query < ActiveRecord::Base
|
|||||||
if grouped?
|
if grouped?
|
||||||
begin
|
begin
|
||||||
# Rails will raise an (unexpected) RecordNotFound if there's only a nil group value
|
# Rails will raise an (unexpected) RecordNotFound if there's only a nil group value
|
||||||
r = Issue.visible.count(:group => group_by_statement, :include => [:status, :project], :conditions => statement)
|
r = Issue.count(:group => group_by_statement, :include => [:status, :project], :conditions => statement)
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
r = {nil => issue_count}
|
r = {nil => issue_count}
|
||||||
end
|
end
|
||||||
@@ -552,7 +478,7 @@ class Query < ActiveRecord::Base
|
|||||||
order_option = [group_by_sort_order, options[:order]].reject {|s| s.blank?}.join(',')
|
order_option = [group_by_sort_order, options[:order]].reject {|s| s.blank?}.join(',')
|
||||||
order_option = nil if order_option.blank?
|
order_option = nil if order_option.blank?
|
||||||
|
|
||||||
Issue.visible.find :all, :include => ([:status, :project] + (options[:include] || [])).uniq,
|
Issue.find :all, :include => ([:status, :project] + (options[:include] || [])).uniq,
|
||||||
:conditions => Query.merge_conditions(statement, options[:conditions]),
|
:conditions => Query.merge_conditions(statement, options[:conditions]),
|
||||||
:order => order_option,
|
:order => order_option,
|
||||||
:limit => options[:limit],
|
:limit => options[:limit],
|
||||||
@@ -564,7 +490,7 @@ class Query < ActiveRecord::Base
|
|||||||
# Returns the journals
|
# Returns the journals
|
||||||
# Valid options are :order, :offset, :limit
|
# Valid options are :order, :offset, :limit
|
||||||
def journals(options={})
|
def journals(options={})
|
||||||
Journal.visible.find :all, :include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}],
|
Journal.find :all, :include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}],
|
||||||
:conditions => statement,
|
:conditions => statement,
|
||||||
:order => options[:order],
|
:order => options[:order],
|
||||||
:limit => options[:limit],
|
:limit => options[:limit],
|
||||||
@@ -576,7 +502,7 @@ class Query < ActiveRecord::Base
|
|||||||
# Returns the versions
|
# Returns the versions
|
||||||
# Valid options are :conditions
|
# Valid options are :conditions
|
||||||
def versions(options={})
|
def versions(options={})
|
||||||
Version.visible.find :all, :include => :project,
|
Version.find :all, :include => :project,
|
||||||
:conditions => Query.merge_conditions(project_statement, options[:conditions])
|
:conditions => Query.merge_conditions(project_statement, options[:conditions])
|
||||||
rescue ::ActiveRecord::StatementInvalid => e
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
raise StatementInvalid.new(e.message)
|
raise StatementInvalid.new(e.message)
|
||||||
@@ -589,19 +515,9 @@ class Query < ActiveRecord::Base
|
|||||||
sql = ''
|
sql = ''
|
||||||
case operator
|
case operator
|
||||||
when "="
|
when "="
|
||||||
if value.any?
|
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
|
||||||
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
|
|
||||||
else
|
|
||||||
# IN an empty set
|
|
||||||
sql = "1=0"
|
|
||||||
end
|
|
||||||
when "!"
|
when "!"
|
||||||
if value.any?
|
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
|
||||||
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
|
|
||||||
else
|
|
||||||
# NOT IN an empty set
|
|
||||||
sql = "1=1"
|
|
||||||
end
|
|
||||||
when "!*"
|
when "!*"
|
||||||
sql = "#{db_table}.#{db_field} IS NULL"
|
sql = "#{db_table}.#{db_field} IS NULL"
|
||||||
sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter
|
sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter
|
||||||
@@ -631,10 +547,12 @@ class Query < ActiveRecord::Base
|
|||||||
when "t"
|
when "t"
|
||||||
sql = date_range_clause(db_table, db_field, 0, 0)
|
sql = date_range_clause(db_table, db_field, 0, 0)
|
||||||
when "w"
|
when "w"
|
||||||
first_day_of_week = l(:general_first_day_of_week).to_i
|
from = l(:general_first_day_of_week) == '7' ?
|
||||||
day_of_week = Date.today.cwday
|
# week starts on sunday
|
||||||
days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
|
((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) :
|
||||||
sql = date_range_clause(db_table, db_field, - days_ago, - days_ago + 6)
|
# week starts on monday (Rails default)
|
||||||
|
Time.now.at_beginning_of_week
|
||||||
|
sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
|
||||||
when "~"
|
when "~"
|
||||||
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
||||||
when "!~"
|
when "!~"
|
||||||
@@ -657,9 +575,6 @@ class Query < ActiveRecord::Base
|
|||||||
options = { :type => :date, :order => 20 }
|
options = { :type => :date, :order => 20 }
|
||||||
when "bool"
|
when "bool"
|
||||||
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
|
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
|
||||||
when "user", "version"
|
|
||||||
next unless project
|
|
||||||
options = { :type => :list_optional, :values => field.possible_values_options(project), :order => 20}
|
|
||||||
else
|
else
|
||||||
options = { :type => :string, :order => 20 }
|
options = { :type => :string, :order => 20 }
|
||||||
end
|
end
|
||||||
|
|||||||
+16
-121
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -16,30 +16,17 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Repository < ActiveRecord::Base
|
class Repository < ActiveRecord::Base
|
||||||
include Redmine::Ciphering
|
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
|
has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
|
||||||
has_many :changes, :through => :changesets
|
has_many :changes, :through => :changesets
|
||||||
|
|
||||||
serialize :extra_info
|
|
||||||
|
|
||||||
# Raw SQL to delete changesets and changes in the database
|
# Raw SQL to delete changesets and changes in the database
|
||||||
# has_many :changesets, :dependent => :destroy is too slow for big repositories
|
# has_many :changesets, :dependent => :destroy is too slow for big repositories
|
||||||
before_destroy :clear_changesets
|
before_destroy :clear_changesets
|
||||||
|
|
||||||
validates_length_of :password, :maximum => 255, :allow_nil => true
|
|
||||||
# Checks if the SCM is enabled when creating a repository
|
# Checks if the SCM is enabled when creating a repository
|
||||||
validate_on_create { |r| r.errors.add(:type, :invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
|
validate_on_create { |r| r.errors.add(:type, :invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
|
||||||
|
|
||||||
def self.human_attribute_name(attribute_key_name)
|
|
||||||
attr_name = attribute_key_name
|
|
||||||
if attr_name == "log_encoding"
|
|
||||||
attr_name = "commit_logs_encoding"
|
|
||||||
end
|
|
||||||
super(attr_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Removes leading and trailing whitespace
|
# Removes leading and trailing whitespace
|
||||||
def url=(arg)
|
def url=(arg)
|
||||||
write_attribute(:url, arg ? arg.to_s.strip : nil)
|
write_attribute(:url, arg ? arg.to_s.strip : nil)
|
||||||
@@ -50,21 +37,8 @@ class Repository < ActiveRecord::Base
|
|||||||
write_attribute(:root_url, arg ? arg.to_s.strip : nil)
|
write_attribute(:root_url, arg ? arg.to_s.strip : nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def password
|
|
||||||
read_ciphered_attribute(:password)
|
|
||||||
end
|
|
||||||
|
|
||||||
def password=(arg)
|
|
||||||
write_ciphered_attribute(:password, arg)
|
|
||||||
end
|
|
||||||
|
|
||||||
def scm_adapter
|
|
||||||
self.class.scm_adapter_class
|
|
||||||
end
|
|
||||||
|
|
||||||
def scm
|
def scm
|
||||||
@scm ||= self.scm_adapter.new(url, root_url,
|
@scm ||= self.scm_adapter.new url, root_url, login, password
|
||||||
login, password, path_encoding)
|
|
||||||
update_attribute(:root_url, @scm.root_url) if root_url.blank?
|
update_attribute(:root_url, @scm.root_url) if root_url.blank?
|
||||||
@scm
|
@scm
|
||||||
end
|
end
|
||||||
@@ -73,17 +47,6 @@ class Repository < ActiveRecord::Base
|
|||||||
self.class.scm_name
|
self.class.scm_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge_extra_info(arg)
|
|
||||||
h = extra_info || {}
|
|
||||||
return h if arg.nil?
|
|
||||||
h.merge!(arg)
|
|
||||||
write_attribute(:extra_info, h)
|
|
||||||
end
|
|
||||||
|
|
||||||
def report_last_commit
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def supports_cat?
|
def supports_cat?
|
||||||
scm.supports_cat?
|
scm.supports_cat?
|
||||||
end
|
end
|
||||||
@@ -92,14 +55,6 @@ class Repository < ActiveRecord::Base
|
|||||||
scm.supports_annotate?
|
scm.supports_annotate?
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_all_revisions?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def supports_directory_revisions?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def entry(path=nil, identifier=nil)
|
def entry(path=nil, identifier=nil)
|
||||||
scm.entry(path, identifier)
|
scm.entry(path, identifier)
|
||||||
end
|
end
|
||||||
@@ -117,7 +72,7 @@ class Repository < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def default_branch
|
def default_branch
|
||||||
nil
|
scm.default_branch
|
||||||
end
|
end
|
||||||
|
|
||||||
def properties(path, identifier=nil)
|
def properties(path, identifier=nil)
|
||||||
@@ -132,13 +87,6 @@ class Repository < ActiveRecord::Base
|
|||||||
scm.diff(path, rev, rev_to)
|
scm.diff(path, rev, rev_to)
|
||||||
end
|
end
|
||||||
|
|
||||||
def diff_format_revisions(cs, cs_to, sep=':')
|
|
||||||
text = ""
|
|
||||||
text << cs_to.format_identifier + sep if cs_to
|
|
||||||
text << cs.format_identifier if cs
|
|
||||||
text
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a path relative to the url of the repository
|
# Returns a path relative to the url of the repository
|
||||||
def relative_path(path)
|
def relative_path(path)
|
||||||
path
|
path
|
||||||
@@ -146,9 +94,7 @@ class Repository < ActiveRecord::Base
|
|||||||
|
|
||||||
# Finds and returns a revision with a number or the beginning of a hash
|
# Finds and returns a revision with a number or the beginning of a hash
|
||||||
def find_changeset_by_name(name)
|
def find_changeset_by_name(name)
|
||||||
return nil if name.blank?
|
changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
|
||||||
changesets.find(:first, :conditions => (name.match(/^\d*$/) ?
|
|
||||||
["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def latest_changeset
|
def latest_changeset
|
||||||
@@ -159,19 +105,14 @@ class Repository < ActiveRecord::Base
|
|||||||
# Default behaviour is to search in cached changesets
|
# Default behaviour is to search in cached changesets
|
||||||
def latest_changesets(path, rev, limit=10)
|
def latest_changesets(path, rev, limit=10)
|
||||||
if path.blank?
|
if path.blank?
|
||||||
changesets.find(
|
changesets.find(:all, :include => :user,
|
||||||
:all,
|
:order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
|
||||||
:include => :user,
|
:limit => limit)
|
||||||
:order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
|
|
||||||
:limit => limit)
|
|
||||||
else
|
else
|
||||||
changes.find(
|
changes.find(:all, :include => {:changeset => :user},
|
||||||
:all,
|
:conditions => ["path = ?", path.with_leading_slash],
|
||||||
:include => {:changeset => :user},
|
:order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
|
||||||
:conditions => ["path = ?", path.with_leading_slash],
|
:limit => limit).collect(&:changeset)
|
||||||
:order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
|
|
||||||
:limit => limit
|
|
||||||
).collect(&:changeset)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -181,8 +122,7 @@ class Repository < ActiveRecord::Base
|
|||||||
|
|
||||||
# Returns an array of committers usernames and associated user_id
|
# Returns an array of committers usernames and associated user_id
|
||||||
def committers
|
def committers
|
||||||
@committers ||= Changeset.connection.select_rows(
|
@committers ||= Changeset.connection.select_rows("SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}")
|
||||||
"SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Maps committers username to a user ids
|
# Maps committers username to a user ids
|
||||||
@@ -192,12 +132,10 @@ class Repository < ActiveRecord::Base
|
|||||||
new_user_id = h[committer]
|
new_user_id = h[committer]
|
||||||
if new_user_id && (new_user_id.to_i != user_id.to_i)
|
if new_user_id && (new_user_id.to_i != user_id.to_i)
|
||||||
new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil)
|
new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil)
|
||||||
Changeset.update_all(
|
Changeset.update_all("user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }", ["repository_id = ? AND committer = ?", id, committer])
|
||||||
"user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }",
|
|
||||||
["repository_id = ? AND committer = ?", id, committer])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@committers = nil
|
@committers = nil
|
||||||
@found_committer_users = nil
|
@found_committer_users = nil
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
@@ -228,22 +166,13 @@ class Repository < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def repo_log_encoding
|
|
||||||
encoding = log_encoding.to_s.strip
|
|
||||||
encoding.blank? ? 'UTF-8' : encoding
|
|
||||||
end
|
|
||||||
|
|
||||||
# Fetches new changesets for all repositories of active projects
|
# Fetches new changesets for all repositories of active projects
|
||||||
# Can be called periodically by an external script
|
# Can be called periodically by an external script
|
||||||
# eg. ruby script/runner "Repository.fetch_changesets"
|
# eg. ruby script/runner "Repository.fetch_changesets"
|
||||||
def self.fetch_changesets
|
def self.fetch_changesets
|
||||||
Project.active.has_module(:repository).find(:all, :include => :repository).each do |project|
|
Project.active.has_module(:repository).find(:all, :include => :repository).each do |project|
|
||||||
if project.repository
|
if project.repository
|
||||||
begin
|
project.repository.fetch_changesets
|
||||||
project.repository.fetch_changesets
|
|
||||||
rescue Redmine::Scm::Adapters::CommandFailed => e
|
|
||||||
logger.error "scm: error during fetching changesets: #{e.message}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -268,40 +197,6 @@ class Repository < ActiveRecord::Base
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.scm_adapter_class
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.scm_command
|
|
||||||
ret = ""
|
|
||||||
begin
|
|
||||||
ret = self.scm_adapter_class.client_command if self.scm_adapter_class
|
|
||||||
rescue Exception => e
|
|
||||||
logger.error "scm: error during get command: #{e.message}"
|
|
||||||
end
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.scm_version_string
|
|
||||||
ret = ""
|
|
||||||
begin
|
|
||||||
ret = self.scm_adapter_class.client_version_string if self.scm_adapter_class
|
|
||||||
rescue Exception => e
|
|
||||||
logger.error "scm: error during get version string: #{e.message}"
|
|
||||||
end
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.scm_available
|
|
||||||
ret = false
|
|
||||||
begin
|
|
||||||
ret = self.scm_adapter_class.client_available if self.scm_adapter_class
|
|
||||||
rescue Exception => e
|
|
||||||
logger.error "scm: error during get scm available: #{e.message}"
|
|
||||||
end
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def before_save
|
def before_save
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -19,17 +19,9 @@ require 'redmine/scm/adapters/bazaar_adapter'
|
|||||||
|
|
||||||
class Repository::Bazaar < Repository
|
class Repository::Bazaar < Repository
|
||||||
attr_protected :root_url
|
attr_protected :root_url
|
||||||
validates_presence_of :url, :log_encoding
|
validates_presence_of :url
|
||||||
|
|
||||||
def self.human_attribute_name(attribute_key_name)
|
def scm_adapter
|
||||||
attr_name = attribute_key_name
|
|
||||||
if attr_name == "url"
|
|
||||||
attr_name = "path_to_repository"
|
|
||||||
end
|
|
||||||
super(attr_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.scm_adapter_class
|
|
||||||
Redmine::Scm::Adapters::BazaarAdapter
|
Redmine::Scm::Adapters::BazaarAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -47,19 +39,14 @@ class Repository::Bazaar < Repository
|
|||||||
full_path = File.join(root_url, e.path)
|
full_path = File.join(root_url, e.path)
|
||||||
e.size = File.stat(full_path).size if File.file?(full_path)
|
e.size = File.stat(full_path).size if File.file?(full_path)
|
||||||
end
|
end
|
||||||
c = Change.find(
|
c = Change.find(:first,
|
||||||
:first,
|
:include => :changeset,
|
||||||
:include => :changeset,
|
:conditions => ["#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?", e.lastrev.revision, id],
|
||||||
:conditions => [
|
:order => "#{Changeset.table_name}.revision DESC")
|
||||||
"#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?",
|
|
||||||
e.lastrev.revision,
|
|
||||||
id
|
|
||||||
],
|
|
||||||
:order => "#{Changeset.table_name}.revision DESC")
|
|
||||||
if c
|
if c
|
||||||
e.lastrev.identifier = c.changeset.revision
|
e.lastrev.identifier = c.changeset.revision
|
||||||
e.lastrev.name = c.changeset.revision
|
e.lastrev.name = c.changeset.revision
|
||||||
e.lastrev.author = c.changeset.committer
|
e.lastrev.author = c.changeset.committer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -81,18 +68,18 @@ class Repository::Bazaar < Repository
|
|||||||
revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
|
revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
|
||||||
transaction do
|
transaction do
|
||||||
revisions.reverse_each do |revision|
|
revisions.reverse_each do |revision|
|
||||||
changeset = Changeset.create(:repository => self,
|
changeset = Changeset.create(:repository => self,
|
||||||
:revision => revision.identifier,
|
:revision => revision.identifier,
|
||||||
:committer => revision.author,
|
:committer => revision.author,
|
||||||
:committed_on => revision.time,
|
:committed_on => revision.time,
|
||||||
:scmid => revision.scmid,
|
:scmid => revision.scmid,
|
||||||
:comments => revision.message)
|
:comments => revision.message)
|
||||||
|
|
||||||
revision.paths.each do |change|
|
revision.paths.each do |change|
|
||||||
Change.create(:changeset => changeset,
|
Change.create(:changeset => changeset,
|
||||||
:action => change[:action],
|
:action => change[:action],
|
||||||
:path => change[:path],
|
:path => change[:path],
|
||||||
:revision => change[:revision])
|
:revision => change[:revision])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end unless revisions.nil?
|
end unless revisions.nil?
|
||||||
|
|||||||
+58
-102
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -19,19 +19,9 @@ require 'redmine/scm/adapters/cvs_adapter'
|
|||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
|
|
||||||
class Repository::Cvs < Repository
|
class Repository::Cvs < Repository
|
||||||
validates_presence_of :url, :root_url, :log_encoding
|
validates_presence_of :url, :root_url
|
||||||
|
|
||||||
def self.human_attribute_name(attribute_key_name)
|
def scm_adapter
|
||||||
attr_name = attribute_key_name
|
|
||||||
if attr_name == "root_url"
|
|
||||||
attr_name = "cvsroot"
|
|
||||||
elsif attr_name == "url"
|
|
||||||
attr_name = "cvs_module"
|
|
||||||
end
|
|
||||||
super(attr_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.scm_adapter_class
|
|
||||||
Redmine::Scm::Adapters::CvsAdapter
|
Redmine::Scm::Adapters::CvsAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,23 +35,17 @@ class Repository::Cvs < Repository
|
|||||||
end
|
end
|
||||||
|
|
||||||
def entries(path=nil, identifier=nil)
|
def entries(path=nil, identifier=nil)
|
||||||
rev = nil
|
rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||||
if ! identifier.nil?
|
|
||||||
rev = changesets.find_by_revision(identifier)
|
|
||||||
return nil if rev.nil?
|
|
||||||
end
|
|
||||||
entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
|
entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
|
||||||
if entries
|
if entries
|
||||||
entries.each() do |entry|
|
entries.each() do |entry|
|
||||||
if ( ! entry.lastrev.nil? ) && ( ! entry.lastrev.revision.nil? )
|
unless entry.lastrev.nil? || entry.lastrev.identifier
|
||||||
change=changes.find_by_revision_and_path(
|
change=changes.find_by_revision_and_path( entry.lastrev.revision, scm.with_leading_slash(entry.path) )
|
||||||
entry.lastrev.revision,
|
|
||||||
scm.with_leading_slash(entry.path) )
|
|
||||||
if change
|
if change
|
||||||
entry.lastrev.identifier = change.changeset.revision
|
entry.lastrev.identifier=change.changeset.revision
|
||||||
entry.lastrev.revision = change.changeset.revision
|
entry.lastrev.author=change.changeset.committer
|
||||||
entry.lastrev.author = change.changeset.committer
|
entry.lastrev.revision=change.revision
|
||||||
# entry.lastrev.branch = change.branch
|
entry.lastrev.branch=change.branch
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -70,44 +54,32 @@ class Repository::Cvs < Repository
|
|||||||
end
|
end
|
||||||
|
|
||||||
def cat(path, identifier=nil)
|
def cat(path, identifier=nil)
|
||||||
rev = nil
|
rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||||
if ! identifier.nil?
|
|
||||||
rev = changesets.find_by_revision(identifier)
|
|
||||||
return nil if rev.nil?
|
|
||||||
end
|
|
||||||
scm.cat(path, rev.nil? ? nil : rev.committed_on)
|
scm.cat(path, rev.nil? ? nil : rev.committed_on)
|
||||||
end
|
end
|
||||||
|
|
||||||
def annotate(path, identifier=nil)
|
|
||||||
rev = nil
|
|
||||||
if ! identifier.nil?
|
|
||||||
rev = changesets.find_by_revision(identifier)
|
|
||||||
return nil if rev.nil?
|
|
||||||
end
|
|
||||||
scm.annotate(path, rev.nil? ? nil : rev.committed_on)
|
|
||||||
end
|
|
||||||
|
|
||||||
def diff(path, rev, rev_to)
|
def diff(path, rev, rev_to)
|
||||||
# convert rev to revision. CVS can't handle changesets here
|
#convert rev to revision. CVS can't handle changesets here
|
||||||
diff=[]
|
diff=[]
|
||||||
changeset_from = changesets.find_by_revision(rev)
|
changeset_from=changesets.find_by_revision(rev)
|
||||||
if rev_to.to_i > 0
|
if rev_to.to_i > 0
|
||||||
changeset_to = changesets.find_by_revision(rev_to)
|
changeset_to=changesets.find_by_revision(rev_to)
|
||||||
end
|
end
|
||||||
changeset_from.changes.each() do |change_from|
|
changeset_from.changes.each() do |change_from|
|
||||||
revision_from = nil
|
|
||||||
revision_to = nil
|
revision_from=nil
|
||||||
if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
|
revision_to=nil
|
||||||
revision_from = change_from.revision
|
|
||||||
end
|
revision_from=change_from.revision if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
|
||||||
|
|
||||||
if revision_from
|
if revision_from
|
||||||
if changeset_to
|
if changeset_to
|
||||||
changeset_to.changes.each() do |change_to|
|
changeset_to.changes.each() do |change_to|
|
||||||
revision_to = change_to.revision if change_to.path == change_from.path
|
revision_to=change_to.revision if change_to.path==change_from.path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
unless revision_to
|
unless revision_to
|
||||||
revision_to = scm.get_previous_revision(revision_from)
|
revision_to=scm.get_previous_revision(revision_from)
|
||||||
end
|
end
|
||||||
file_diff = scm.diff(change_from.path, revision_from, revision_to)
|
file_diff = scm.diff(change_from.path, revision_from, revision_to)
|
||||||
diff = diff + file_diff unless file_diff.nil?
|
diff = diff + file_diff unless file_diff.nil?
|
||||||
@@ -118,78 +90,64 @@ class Repository::Cvs < Repository
|
|||||||
|
|
||||||
def fetch_changesets
|
def fetch_changesets
|
||||||
# some nifty bits to introduce a commit-id with cvs
|
# some nifty bits to introduce a commit-id with cvs
|
||||||
# natively cvs doesn't provide any kind of changesets,
|
# natively cvs doesn't provide any kind of changesets, there is only a revision per file.
|
||||||
# there is only a revision per file.
|
|
||||||
# we now take a guess using the author, the commitlog and the commit-date.
|
# we now take a guess using the author, the commitlog and the commit-date.
|
||||||
|
|
||||||
# last one is the next step to take. the commit-date is not equal for all
|
# last one is the next step to take. the commit-date is not equal for all
|
||||||
# commits in one changeset. cvs update the commit-date when the *,v file was touched. so
|
# commits in one changeset. cvs update the commit-date when the *,v file was touched. so
|
||||||
# we use a small delta here, to merge all changes belonging to _one_ changeset
|
# we use a small delta here, to merge all changes belonging to _one_ changeset
|
||||||
time_delta = 10.seconds
|
time_delta=10.seconds
|
||||||
|
|
||||||
fetch_since = latest_changeset ? latest_changeset.committed_on : nil
|
fetch_since = latest_changeset ? latest_changeset.committed_on : nil
|
||||||
transaction do
|
transaction do
|
||||||
tmp_rev_num = 1
|
tmp_rev_num = 1
|
||||||
scm.revisions('', fetch_since, nil, :log_encoding => repo_log_encoding) do |revision|
|
scm.revisions('', fetch_since, nil, :with_paths => true) do |revision|
|
||||||
# only add the change to the database, if it doen't exists. the cvs log
|
# only add the change to the database, if it doen't exists. the cvs log
|
||||||
# is not exclusive at all.
|
# is not exclusive at all.
|
||||||
tmp_time = revision.time.clone
|
unless changes.find_by_path_and_revision(scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
|
||||||
unless changes.find_by_path_and_revision(
|
revision
|
||||||
scm.with_leading_slash(revision.paths[0][:path]),
|
cs = changesets.find(:first, :conditions=>{
|
||||||
revision.paths[0][:revision]
|
:committed_on=>revision.time-time_delta..revision.time+time_delta,
|
||||||
)
|
:committer=>revision.author,
|
||||||
cmt = Changeset.normalize_comments(revision.message, repo_log_encoding)
|
:comments=>Changeset.normalize_comments(revision.message)
|
||||||
author_utf8 = Changeset.to_utf8(revision.author, repo_log_encoding)
|
})
|
||||||
cs = changesets.find(
|
|
||||||
:first,
|
|
||||||
:conditions => {
|
|
||||||
:committed_on => tmp_time - time_delta .. tmp_time + time_delta,
|
|
||||||
:committer => author_utf8,
|
|
||||||
:comments => cmt
|
|
||||||
}
|
|
||||||
)
|
|
||||||
# create a new changeset....
|
# create a new changeset....
|
||||||
unless cs
|
unless cs
|
||||||
# we use a temporaray revision number here (just for inserting)
|
# we use a temporaray revision number here (just for inserting)
|
||||||
# later on, we calculate a continous positive number
|
# later on, we calculate a continous positive number
|
||||||
tmp_time2 = tmp_time.clone.gmtime
|
latest = changesets.find(:first, :order => 'id DESC')
|
||||||
branch = revision.paths[0][:branch]
|
cs = Changeset.create(:repository => self,
|
||||||
scmid = branch + "-" + tmp_time2.strftime("%Y%m%d-%H%M%S")
|
:revision => "_#{tmp_rev_num}",
|
||||||
cs = Changeset.create(:repository => self,
|
:committer => revision.author,
|
||||||
:revision => "tmp#{tmp_rev_num}",
|
:committed_on => revision.time,
|
||||||
:scmid => scmid,
|
:comments => revision.message)
|
||||||
:committer => revision.author,
|
|
||||||
:committed_on => tmp_time,
|
|
||||||
:comments => revision.message)
|
|
||||||
tmp_rev_num += 1
|
tmp_rev_num += 1
|
||||||
end
|
end
|
||||||
# convert CVS-File-States to internal Action-abbrevations
|
|
||||||
# default action is (M)odified
|
#convert CVS-File-States to internal Action-abbrevations
|
||||||
action = "M"
|
#default action is (M)odified
|
||||||
if revision.paths[0][:action] == "Exp" && revision.paths[0][:revision] == "1.1"
|
action="M"
|
||||||
action = "A" # add-action always at first revision (= 1.1)
|
if revision.paths[0][:action]=="Exp" && revision.paths[0][:revision]=="1.1"
|
||||||
elsif revision.paths[0][:action] == "dead"
|
action="A" #add-action always at first revision (= 1.1)
|
||||||
action = "D" # dead-state is similar to Delete
|
elsif revision.paths[0][:action]=="dead"
|
||||||
|
action="D" #dead-state is similar to Delete
|
||||||
end
|
end
|
||||||
Change.create(
|
|
||||||
:changeset => cs,
|
Change.create(:changeset => cs,
|
||||||
:action => action,
|
:action => action,
|
||||||
:path => scm.with_leading_slash(revision.paths[0][:path]),
|
:path => scm.with_leading_slash(revision.paths[0][:path]),
|
||||||
:revision => revision.paths[0][:revision],
|
:revision => revision.paths[0][:revision],
|
||||||
:branch => revision.paths[0][:branch]
|
:branch => revision.paths[0][:branch]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Renumber new changesets in chronological order
|
# Renumber new changesets in chronological order
|
||||||
changesets.find(
|
changesets.find(:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE '_%'").each do |changeset|
|
||||||
:all,
|
|
||||||
:order => 'committed_on ASC, id ASC',
|
|
||||||
:conditions => "revision LIKE 'tmp%'"
|
|
||||||
).each do |changeset|
|
|
||||||
changeset.update_attribute :revision, next_revision_number
|
changeset.update_attribute :revision, next_revision_number
|
||||||
end
|
end
|
||||||
end # transaction
|
end # transaction
|
||||||
@current_revision_number = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -197,9 +155,7 @@ class Repository::Cvs < Repository
|
|||||||
# Returns the next revision number to assign to a CVS changeset
|
# Returns the next revision number to assign to a CVS changeset
|
||||||
def next_revision_number
|
def next_revision_number
|
||||||
# Need to retrieve existing revision numbers to sort them as integers
|
# Need to retrieve existing revision numbers to sort them as integers
|
||||||
sql = "SELECT revision FROM #{Changeset.table_name} "
|
@current_revision_number ||= (connection.select_values("SELECT revision FROM #{Changeset.table_name} WHERE repository_id = #{id} AND revision NOT LIKE '_%'").collect(&:to_i).max || 0)
|
||||||
sql << "WHERE repository_id = #{id} AND revision NOT LIKE 'tmp%'"
|
|
||||||
@current_revision_number ||= (connection.select_values(sql).collect(&:to_i).max || 0)
|
|
||||||
@current_revision_number += 1
|
@current_revision_number += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -18,17 +18,9 @@
|
|||||||
require 'redmine/scm/adapters/darcs_adapter'
|
require 'redmine/scm/adapters/darcs_adapter'
|
||||||
|
|
||||||
class Repository::Darcs < Repository
|
class Repository::Darcs < Repository
|
||||||
validates_presence_of :url, :log_encoding
|
validates_presence_of :url
|
||||||
|
|
||||||
def self.human_attribute_name(attribute_key_name)
|
def scm_adapter
|
||||||
attr_name = attribute_key_name
|
|
||||||
if attr_name == "url"
|
|
||||||
attr_name = "path_to_repository"
|
|
||||||
end
|
|
||||||
super(attr_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.scm_adapter_class
|
|
||||||
Redmine::Scm::Adapters::DarcsAdapter
|
Redmine::Scm::Adapters::DarcsAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -36,33 +28,23 @@ class Repository::Darcs < Repository
|
|||||||
'Darcs'
|
'Darcs'
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_directory_revisions?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def entry(path=nil, identifier=nil)
|
def entry(path=nil, identifier=nil)
|
||||||
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||||
scm.entry(path, patch.nil? ? nil : patch.scmid)
|
scm.entry(path, patch.nil? ? nil : patch.scmid)
|
||||||
end
|
end
|
||||||
|
|
||||||
def entries(path=nil, identifier=nil)
|
def entries(path=nil, identifier=nil)
|
||||||
patch = nil
|
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||||
if ! identifier.nil?
|
|
||||||
patch = changesets.find_by_revision(identifier)
|
|
||||||
return nil if patch.nil?
|
|
||||||
end
|
|
||||||
entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
|
entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
|
||||||
if entries
|
if entries
|
||||||
entries.each do |entry|
|
entries.each do |entry|
|
||||||
# Search the DB for the entry's last change
|
# Search the DB for the entry's last change
|
||||||
if entry.lastrev && !entry.lastrev.scmid.blank?
|
changeset = changesets.find_by_scmid(entry.lastrev.scmid) if entry.lastrev && !entry.lastrev.scmid.blank?
|
||||||
changeset = changesets.find_by_scmid(entry.lastrev.scmid)
|
|
||||||
end
|
|
||||||
if changeset
|
if changeset
|
||||||
entry.lastrev.identifier = changeset.revision
|
entry.lastrev.identifier = changeset.revision
|
||||||
entry.lastrev.name = changeset.revision
|
entry.lastrev.name = changeset.revision
|
||||||
entry.lastrev.time = changeset.committed_on
|
entry.lastrev.time = changeset.committed_on
|
||||||
entry.lastrev.author = changeset.committer
|
entry.lastrev.author = changeset.committer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -88,19 +70,20 @@ class Repository::Darcs < Repository
|
|||||||
scm_info = scm.info
|
scm_info = scm.info
|
||||||
if scm_info
|
if scm_info
|
||||||
db_last_id = latest_changeset ? latest_changeset.scmid : nil
|
db_last_id = latest_changeset ? latest_changeset.scmid : nil
|
||||||
next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
|
next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
|
||||||
# latest revision in the repository
|
# latest revision in the repository
|
||||||
scm_revision = scm_info.lastrev.scmid
|
scm_revision = scm_info.lastrev.scmid
|
||||||
unless changesets.find_by_scmid(scm_revision)
|
unless changesets.find_by_scmid(scm_revision)
|
||||||
revisions = scm.revisions('', db_last_id, nil, :with_path => true)
|
revisions = scm.revisions('', db_last_id, nil, :with_path => true)
|
||||||
transaction do
|
transaction do
|
||||||
revisions.reverse_each do |revision|
|
revisions.reverse_each do |revision|
|
||||||
changeset = Changeset.create(:repository => self,
|
changeset = Changeset.create(:repository => self,
|
||||||
:revision => next_rev,
|
:revision => next_rev,
|
||||||
:scmid => revision.scmid,
|
:scmid => revision.scmid,
|
||||||
:committer => revision.author,
|
:committer => revision.author,
|
||||||
:committed_on => revision.time,
|
:committed_on => revision.time,
|
||||||
:comments => revision.message)
|
:comments => revision.message)
|
||||||
|
|
||||||
revision.paths.each do |change|
|
revision.paths.each do |change|
|
||||||
changeset.create_change(change)
|
changeset.create_change(change)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# FileSystem adapter
|
# FileSystem adapter
|
||||||
# File written by Paul Rivier, at Demotera.
|
# File written by Paul Rivier, at Demotera.
|
||||||
@@ -24,15 +24,7 @@ class Repository::Filesystem < Repository
|
|||||||
attr_protected :root_url
|
attr_protected :root_url
|
||||||
validates_presence_of :url
|
validates_presence_of :url
|
||||||
|
|
||||||
def self.human_attribute_name(attribute_key_name)
|
def scm_adapter
|
||||||
attr_name = attribute_key_name
|
|
||||||
if attr_name == "url"
|
|
||||||
attr_name = "root_directory"
|
|
||||||
end
|
|
||||||
super(attr_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.scm_adapter_class
|
|
||||||
Redmine::Scm::Adapters::FilesystemAdapter
|
Redmine::Scm::Adapters::FilesystemAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -40,10 +32,6 @@ class Repository::Filesystem < Repository
|
|||||||
'Filesystem'
|
'Filesystem'
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_all_revisions?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def entries(path=nil, identifier=nil)
|
def entries(path=nil, identifier=nil)
|
||||||
scm.entries(path, identifier)
|
scm.entries(path, identifier)
|
||||||
end
|
end
|
||||||
@@ -51,4 +39,5 @@ class Repository::Filesystem < Repository
|
|||||||
def fetch_changesets
|
def fetch_changesets
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
+25
-135
@@ -1,7 +1,6 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
# Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
|
# Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
@@ -22,15 +21,7 @@ class Repository::Git < Repository
|
|||||||
attr_protected :root_url
|
attr_protected :root_url
|
||||||
validates_presence_of :url
|
validates_presence_of :url
|
||||||
|
|
||||||
def self.human_attribute_name(attribute_key_name)
|
def scm_adapter
|
||||||
attr_name = attribute_key_name
|
|
||||||
if attr_name == "url"
|
|
||||||
attr_name = "path_to_repository"
|
|
||||||
end
|
|
||||||
super(attr_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.scm_adapter_class
|
|
||||||
Redmine::Scm::Adapters::GitAdapter
|
Redmine::Scm::Adapters::GitAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -38,35 +29,6 @@ class Repository::Git < Repository
|
|||||||
'Git'
|
'Git'
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_last_commit
|
|
||||||
extra_report_last_commit
|
|
||||||
end
|
|
||||||
|
|
||||||
def extra_report_last_commit
|
|
||||||
return false if extra_info.nil?
|
|
||||||
v = extra_info["extra_report_last_commit"]
|
|
||||||
return false if v.nil?
|
|
||||||
v.to_s != '0'
|
|
||||||
end
|
|
||||||
|
|
||||||
def supports_directory_revisions?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def repo_log_encoding
|
|
||||||
'UTF-8'
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the identifier for the given git changeset
|
|
||||||
def self.changeset_identifier(changeset)
|
|
||||||
changeset.scmid
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the readable identifier for the given git changeset
|
|
||||||
def self.format_changeset_identifier(changeset)
|
|
||||||
changeset.revision[0, 8]
|
|
||||||
end
|
|
||||||
|
|
||||||
def branches
|
def branches
|
||||||
scm.branches
|
scm.branches
|
||||||
end
|
end
|
||||||
@@ -75,105 +37,33 @@ class Repository::Git < Repository
|
|||||||
scm.tags
|
scm.tags
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_branch
|
# With SCM's that have a sequential commit numbering, redmine is able to be
|
||||||
scm.default_branch
|
# clever and only fetch changesets going forward from the most recent one
|
||||||
end
|
# it knows about. However, with git, you never know if people have merged
|
||||||
|
# commits into the middle of the repository history, so we should parse
|
||||||
def find_changeset_by_name(name)
|
# the entire log. Since it's way too slow for large repositories, we only
|
||||||
return nil if name.nil? || name.empty?
|
# parse 1 week before the last known commit.
|
||||||
e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
|
|
||||||
return e if e
|
|
||||||
changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"])
|
|
||||||
end
|
|
||||||
|
|
||||||
def entries(path=nil, identifier=nil)
|
|
||||||
scm.entries(path,
|
|
||||||
identifier,
|
|
||||||
options = {:report_last_commit => extra_report_last_commit})
|
|
||||||
end
|
|
||||||
|
|
||||||
# With SCMs that have a sequential commit numbering,
|
|
||||||
# such as Subversion and Mercurial,
|
|
||||||
# Redmine is able to be clever and only fetch changesets
|
|
||||||
# going forward from the most recent one it knows about.
|
|
||||||
#
|
|
||||||
# However, Git does not have a sequential commit numbering.
|
|
||||||
#
|
|
||||||
# In order to fetch only new adding revisions,
|
|
||||||
# Redmine needs to parse revisions per branch.
|
|
||||||
# Branch "last_scmid" is for this requirement.
|
|
||||||
#
|
|
||||||
# In Git and Mercurial, revisions are not in date order.
|
|
||||||
# Redmine Mercurial fixed issues.
|
|
||||||
# * Redmine Takes Too Long On Large Mercurial Repository
|
|
||||||
# http://www.redmine.org/issues/3449
|
|
||||||
# * Sorting for changesets might go wrong on Mercurial repos
|
|
||||||
# http://www.redmine.org/issues/3567
|
|
||||||
#
|
|
||||||
# Database revision column is text, so Redmine can not sort by revision.
|
|
||||||
# Mercurial has revision number, and revision number guarantees revision order.
|
|
||||||
# Redmine Mercurial model stored revisions ordered by database id to database.
|
|
||||||
# So, Redmine Mercurial model can use correct ordering revisions.
|
|
||||||
#
|
|
||||||
# Redmine Mercurial adapter uses "hg log -r 0:tip --limit 10"
|
|
||||||
# to get limited revisions from old to new.
|
|
||||||
# But, Git 1.7.3.4 does not support --reverse with -n or --skip.
|
|
||||||
#
|
|
||||||
# The repository can still be fully reloaded by calling #clear_changesets
|
# The repository can still be fully reloaded by calling #clear_changesets
|
||||||
# before fetching changesets (eg. for offline resync)
|
# before fetching changesets (eg. for offline resync)
|
||||||
def fetch_changesets
|
def fetch_changesets
|
||||||
scm_brs = branches
|
c = changesets.find(:first, :order => 'committed_on DESC')
|
||||||
return if scm_brs.nil? || scm_brs.empty?
|
since = (c ? c.committed_on - 7.days : nil)
|
||||||
h1 = extra_info || {}
|
|
||||||
h = h1.dup
|
|
||||||
h["branches"] ||= {}
|
|
||||||
h["db_consistent"] ||= {}
|
|
||||||
if changesets.count == 0
|
|
||||||
h["db_consistent"]["ordering"] = 1
|
|
||||||
merge_extra_info(h)
|
|
||||||
self.save
|
|
||||||
elsif ! h["db_consistent"].has_key?("ordering")
|
|
||||||
h["db_consistent"]["ordering"] = 0
|
|
||||||
merge_extra_info(h)
|
|
||||||
self.save
|
|
||||||
end
|
|
||||||
scm_brs.each do |br|
|
|
||||||
from_scmid = nil
|
|
||||||
from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br]
|
|
||||||
h["branches"][br] ||= {}
|
|
||||||
scm.revisions('', from_scmid, br, {:reverse => true}) do |rev|
|
|
||||||
db_rev = find_changeset_by_name(rev.revision)
|
|
||||||
transaction do
|
|
||||||
if db_rev.nil?
|
|
||||||
save_revision(rev)
|
|
||||||
end
|
|
||||||
h["branches"][br]["last_scmid"] = rev.scmid
|
|
||||||
merge_extra_info(h)
|
|
||||||
self.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def save_revision(rev)
|
revisions = scm.revisions('', nil, nil, :all => true, :since => since)
|
||||||
changeset = Changeset.new(
|
return if revisions.nil? || revisions.empty?
|
||||||
:repository => self,
|
|
||||||
:revision => rev.identifier,
|
recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since])
|
||||||
:scmid => rev.scmid,
|
|
||||||
:committer => rev.author,
|
# Clean out revisions that are no longer in git
|
||||||
:committed_on => rev.time,
|
recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }}
|
||||||
:comments => rev.message
|
|
||||||
)
|
# Subtract revisions that redmine already knows about
|
||||||
if changeset.save
|
recent_revisions = recent_changesets.map{|c| c.scmid}
|
||||||
rev.paths.each do |file|
|
revisions.reject!{|r| recent_revisions.include?(r.scmid)}
|
||||||
Change.create(
|
|
||||||
:changeset => changeset,
|
# Save the remaining ones to the database
|
||||||
:action => file[:action],
|
revisions.each{|r| r.save(self)} unless revisions.nil?
|
||||||
:path => file[:path])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
private :save_revision
|
|
||||||
|
|
||||||
def latest_changesets(path,rev,limit=10)
|
def latest_changesets(path,rev,limit=10)
|
||||||
revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
|
revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -18,23 +18,10 @@
|
|||||||
require 'redmine/scm/adapters/mercurial_adapter'
|
require 'redmine/scm/adapters/mercurial_adapter'
|
||||||
|
|
||||||
class Repository::Mercurial < Repository
|
class Repository::Mercurial < Repository
|
||||||
# sort changesets by revision number
|
|
||||||
has_many :changesets, :order => "#{Changeset.table_name}.id DESC", :foreign_key => 'repository_id'
|
|
||||||
|
|
||||||
attr_protected :root_url
|
attr_protected :root_url
|
||||||
validates_presence_of :url
|
validates_presence_of :url
|
||||||
|
|
||||||
FETCH_AT_ONCE = 100 # number of changesets to fetch at once
|
def scm_adapter
|
||||||
|
|
||||||
def self.human_attribute_name(attribute_key_name)
|
|
||||||
attr_name = attribute_key_name
|
|
||||||
if attr_name == "url"
|
|
||||||
attr_name = "path_to_repository"
|
|
||||||
end
|
|
||||||
super(attr_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.scm_adapter_class
|
|
||||||
Redmine::Scm::Adapters::MercurialAdapter
|
Redmine::Scm::Adapters::MercurialAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,106 +29,62 @@ class Repository::Mercurial < Repository
|
|||||||
'Mercurial'
|
'Mercurial'
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_directory_revisions?
|
def entries(path=nil, identifier=nil)
|
||||||
true
|
entries=scm.entries(path, identifier)
|
||||||
end
|
if entries
|
||||||
|
entries.each do |entry|
|
||||||
def repo_log_encoding
|
next unless entry.is_file?
|
||||||
'UTF-8'
|
# Set the filesize unless browsing a specific revision
|
||||||
end
|
if identifier.nil?
|
||||||
|
full_path = File.join(root_url, entry.path)
|
||||||
# Returns the readable identifier for the given mercurial changeset
|
entry.size = File.stat(full_path).size if File.file?(full_path)
|
||||||
def self.format_changeset_identifier(changeset)
|
end
|
||||||
"#{changeset.revision}:#{changeset.scmid}"
|
# Search the DB for the entry's last change
|
||||||
end
|
change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
|
||||||
|
if change
|
||||||
# Returns the identifier for the given Mercurial changeset
|
entry.lastrev.identifier = change.changeset.revision
|
||||||
def self.changeset_identifier(changeset)
|
entry.lastrev.name = change.changeset.revision
|
||||||
changeset.scmid
|
entry.lastrev.author = change.changeset.committer
|
||||||
end
|
entry.lastrev.revision = change.revision
|
||||||
|
end
|
||||||
def diff_format_revisions(cs, cs_to, sep=':')
|
end
|
||||||
super(cs, cs_to, ' ')
|
end
|
||||||
end
|
entries
|
||||||
|
end
|
||||||
# Finds and returns a revision with a number or the beginning of a hash
|
|
||||||
def find_changeset_by_name(name)
|
def fetch_changesets
|
||||||
return nil if name.nil? || name.empty?
|
scm_info = scm.info
|
||||||
if /[^\d]/ =~ name or name.to_s.size > 8
|
if scm_info
|
||||||
e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s])
|
# latest revision found in database
|
||||||
else
|
db_revision = latest_changeset ? latest_changeset.revision.to_i : -1
|
||||||
e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
|
# latest revision in the repository
|
||||||
end
|
latest_revision = scm_info.lastrev
|
||||||
return e if e
|
return if latest_revision.nil?
|
||||||
changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) # last ditch
|
scm_revision = latest_revision.identifier.to_i
|
||||||
end
|
if db_revision < scm_revision
|
||||||
|
logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
|
||||||
# Returns the latest changesets for +path+; sorted by revision number
|
identifier_from = db_revision + 1
|
||||||
#
|
while (identifier_from <= scm_revision)
|
||||||
# Because :order => 'id DESC' is defined at 'has_many',
|
# loads changesets by batches of 100
|
||||||
# there is no need to set 'order'.
|
identifier_to = [identifier_from + 99, scm_revision].min
|
||||||
# But, MySQL test fails.
|
revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
|
||||||
# Sqlite3 and PostgreSQL pass.
|
transaction do
|
||||||
# Is this MySQL bug?
|
revisions.each do |revision|
|
||||||
def latest_changesets(path, rev, limit=10)
|
changeset = Changeset.create(:repository => self,
|
||||||
changesets.find(:all, :include => :user,
|
:revision => revision.identifier,
|
||||||
:conditions => latest_changesets_cond(path, rev, limit),
|
:scmid => revision.scmid,
|
||||||
:limit => limit, :order => "#{Changeset.table_name}.id DESC")
|
:committer => revision.author,
|
||||||
end
|
:committed_on => revision.time,
|
||||||
|
:comments => revision.message)
|
||||||
def latest_changesets_cond(path, rev, limit)
|
|
||||||
cond, args = [], []
|
revision.paths.each do |change|
|
||||||
if scm.branchmap.member? rev
|
changeset.create_change(change)
|
||||||
# Mercurial named branch is *stable* in each revision.
|
end
|
||||||
# So, named branch can be stored in database.
|
end
|
||||||
# Mercurial provides *bookmark* which is equivalent with git branch.
|
end unless revisions.nil?
|
||||||
# But, bookmark is not implemented.
|
identifier_from = identifier_to + 1
|
||||||
cond << "#{Changeset.table_name}.scmid IN (?)"
|
|
||||||
# Revisions in root directory and sub directory are not equal.
|
|
||||||
# So, in order to get correct limit, we need to get all revisions.
|
|
||||||
# But, it is very heavy.
|
|
||||||
# Mercurial does not treat direcotry.
|
|
||||||
# So, "hg log DIR" is very heavy.
|
|
||||||
branch_limit = path.blank? ? limit : ( limit * 5 )
|
|
||||||
args << scm.nodes_in_branch(rev, :limit => branch_limit)
|
|
||||||
elsif last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil
|
|
||||||
cond << "#{Changeset.table_name}.id <= ?"
|
|
||||||
args << last.id
|
|
||||||
end
|
|
||||||
|
|
||||||
unless path.blank?
|
|
||||||
cond << "EXISTS (SELECT * FROM #{Change.table_name}
|
|
||||||
WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id
|
|
||||||
AND (#{Change.table_name}.path = ?
|
|
||||||
OR #{Change.table_name}.path LIKE ? ESCAPE ?))"
|
|
||||||
args << path.with_leading_slash
|
|
||||||
args << "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%" << '\\'
|
|
||||||
end
|
|
||||||
|
|
||||||
[cond.join(' AND '), *args] unless cond.empty?
|
|
||||||
end
|
|
||||||
private :latest_changesets_cond
|
|
||||||
|
|
||||||
def fetch_changesets
|
|
||||||
return if scm.info.nil?
|
|
||||||
scm_rev = scm.info.lastrev.revision.to_i
|
|
||||||
db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
|
|
||||||
return unless db_rev < scm_rev # already up-to-date
|
|
||||||
|
|
||||||
logger.debug "Fetching changesets for repository #{url}" if logger
|
|
||||||
(db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
|
|
||||||
transaction do
|
|
||||||
scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
|
|
||||||
cs = Changeset.create(:repository => self,
|
|
||||||
:revision => re.revision,
|
|
||||||
:scmid => re.scmid,
|
|
||||||
:committer => re.author,
|
|
||||||
:committed_on => re.time,
|
|
||||||
:comments => re.message)
|
|
||||||
re.paths.each { |e| cs.create_change(e) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -22,7 +22,7 @@ class Repository::Subversion < Repository
|
|||||||
validates_presence_of :url
|
validates_presence_of :url
|
||||||
validates_format_of :url, :with => /^(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+/i
|
validates_format_of :url, :with => /^(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+/i
|
||||||
|
|
||||||
def self.scm_adapter_class
|
def scm_adapter
|
||||||
Redmine::Scm::Adapters::SubversionAdapter
|
Redmine::Scm::Adapters::SubversionAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,14 +30,6 @@ class Repository::Subversion < Repository
|
|||||||
'Subversion'
|
'Subversion'
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_directory_revisions?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def repo_log_encoding
|
|
||||||
'UTF-8'
|
|
||||||
end
|
|
||||||
|
|
||||||
def latest_changesets(path, rev, limit=10)
|
def latest_changesets(path, rev, limit=10)
|
||||||
revisions = scm.revisions(path, rev, nil, :limit => limit)
|
revisions = scm.revisions(path, rev, nil, :limit => limit)
|
||||||
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
|
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
|
||||||
@@ -64,11 +56,11 @@ class Repository::Subversion < Repository
|
|||||||
revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
|
revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
|
||||||
revisions.reverse_each do |revision|
|
revisions.reverse_each do |revision|
|
||||||
transaction do
|
transaction do
|
||||||
changeset = Changeset.create(:repository => self,
|
changeset = Changeset.create(:repository => self,
|
||||||
:revision => revision.identifier,
|
:revision => revision.identifier,
|
||||||
:committer => revision.author,
|
:committer => revision.author,
|
||||||
:committed_on => revision.time,
|
:committed_on => revision.time,
|
||||||
:comments => revision.message)
|
:comments => revision.message)
|
||||||
|
|
||||||
revision.paths.each do |change|
|
revision.paths.each do |change|
|
||||||
changeset.create_change(change)
|
changeset.create_change(change)
|
||||||
|
|||||||
+3
-19
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -20,12 +20,6 @@ class Role < ActiveRecord::Base
|
|||||||
BUILTIN_NON_MEMBER = 1
|
BUILTIN_NON_MEMBER = 1
|
||||||
BUILTIN_ANONYMOUS = 2
|
BUILTIN_ANONYMOUS = 2
|
||||||
|
|
||||||
ISSUES_VISIBILITY_OPTIONS = [
|
|
||||||
['all', :label_issues_visibility_all],
|
|
||||||
['default', :label_issues_visibility_public],
|
|
||||||
['own', :label_issues_visibility_own]
|
|
||||||
]
|
|
||||||
|
|
||||||
named_scope :givable, { :conditions => "builtin = 0", :order => 'position' }
|
named_scope :givable, { :conditions => "builtin = 0", :order => 'position' }
|
||||||
named_scope :builtin, lambda { |*args|
|
named_scope :builtin, lambda { |*args|
|
||||||
compare = 'not' if args.first == true
|
compare = 'not' if args.first == true
|
||||||
@@ -49,9 +43,7 @@ class Role < ActiveRecord::Base
|
|||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
validates_inclusion_of :issues_visibility,
|
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
||||||
:in => ISSUES_VISIBILITY_OPTIONS.collect(&:first),
|
|
||||||
:if => lambda {|role| role.respond_to?(:issues_visibility)}
|
|
||||||
|
|
||||||
def permissions
|
def permissions
|
||||||
read_attribute(:permissions) || []
|
read_attribute(:permissions) || []
|
||||||
@@ -93,14 +85,6 @@ class Role < ActiveRecord::Base
|
|||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
|
||||||
case builtin
|
|
||||||
when 1; l(:label_role_non_member, :default => read_attribute(:name))
|
|
||||||
when 2; l(:label_role_anonymous, :default => read_attribute(:name))
|
|
||||||
else; read_attribute(:name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return true if the role is a builtin role
|
# Return true if the role is a builtin role
|
||||||
def builtin?
|
def builtin?
|
||||||
self.builtin != 0
|
self.builtin != 0
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# redMine - project management software
|
||||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -65,7 +65,6 @@ class Setting < ActiveRecord::Base
|
|||||||
UTF-16LE
|
UTF-16LE
|
||||||
EUC-JP
|
EUC-JP
|
||||||
Shift_JIS
|
Shift_JIS
|
||||||
CP932
|
|
||||||
GB18030
|
GB18030
|
||||||
GBK
|
GBK
|
||||||
ISCII91
|
ISCII91
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# 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
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -27,7 +27,7 @@ class TimeEntry < ActiveRecord::Base
|
|||||||
|
|
||||||
acts_as_customizable
|
acts_as_customizable
|
||||||
acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
|
acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
|
||||||
:url => Proc.new {|o| {:controller => 'timelog', :action => 'index', :project_id => o.project, :issue_id => o.issue}},
|
:url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project, :issue_id => o.issue}},
|
||||||
:author => :user,
|
:author => :user,
|
||||||
:description => :comments
|
:description => :comments
|
||||||
|
|
||||||
@@ -39,11 +39,6 @@ class TimeEntry < ActiveRecord::Base
|
|||||||
validates_numericality_of :hours, :allow_nil => true, :message => :invalid
|
validates_numericality_of :hours, :allow_nil => true, :message => :invalid
|
||||||
validates_length_of :comments, :maximum => 255, :allow_nil => true
|
validates_length_of :comments, :maximum => 255, :allow_nil => true
|
||||||
|
|
||||||
named_scope :visible, lambda {|*args| {
|
|
||||||
:include => :project,
|
|
||||||
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args)
|
|
||||||
}}
|
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
if new_record? && self.activity.nil?
|
if new_record? && self.activity.nil?
|
||||||
if default_activity = TimeEntryActivity.default
|
if default_activity = TimeEntryActivity.default
|
||||||
@@ -71,9 +66,6 @@ class TimeEntry < ActiveRecord::Base
|
|||||||
# these attributes make time aggregations easier
|
# these attributes make time aggregations easier
|
||||||
def spent_on=(date)
|
def spent_on=(date)
|
||||||
super
|
super
|
||||||
if spent_on.is_a?(Time)
|
|
||||||
self.spent_on = spent_on.to_date
|
|
||||||
end
|
|
||||||
self.tyear = spent_on ? spent_on.year : nil
|
self.tyear = spent_on ? spent_on.year : nil
|
||||||
self.tmonth = spent_on ? spent_on.month : nil
|
self.tmonth = spent_on ? spent_on.month : nil
|
||||||
self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil
|
self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil
|
||||||
@@ -84,9 +76,7 @@ class TimeEntry < ActiveRecord::Base
|
|||||||
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
|
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: remove this method in 1.3.0
|
|
||||||
def self.visible_by(usr)
|
def self.visible_by(usr)
|
||||||
ActiveSupport::Deprecation.warn "TimeEntry.visible_by is deprecated and will be removed in Redmine 1.3.0. Use the visible scope instead."
|
|
||||||
with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
|
with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
|
||||||
yield
|
yield
|
||||||
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