first commit
This commit is contained in:
commit
70b211e355
|
@ -0,0 +1,20 @@
|
|||
log/*
|
||||
.bundle
|
||||
test/*
|
||||
tmp/bids/server.pid
|
||||
tmp/*
|
||||
/tmp/cache/*
|
||||
/tmp/pdf/*
|
||||
/tmp/sessions/*
|
||||
/tmp/sockets/*
|
||||
/tmp/test/*
|
||||
/tmp/thumbnails/*
|
||||
.project
|
||||
.svn/
|
||||
.git/
|
||||
.bundle
|
||||
log
|
||||
/log/development.log
|
||||
/log/development.scm.stderr.log
|
||||
/log/delete.me
|
||||
/test/*
|
|
@ -0,0 +1,39 @@
|
|||
syntax: glob
|
||||
|
||||
.project
|
||||
.loadpath
|
||||
config/additional_environment.rb
|
||||
config/configuration.yml
|
||||
config/database.yml
|
||||
config/email.yml
|
||||
config/initializers/session_store.rb
|
||||
config/initializers/secret_token.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/pdf/*
|
||||
tmp/sessions/*
|
||||
tmp/sockets/*
|
||||
tmp/test/*
|
||||
tmp/thumbnails/*
|
||||
vendor/cache
|
||||
vendor/rails
|
||||
*.rbc
|
||||
|
||||
.svn/
|
||||
.git/
|
||||
|
||||
.bundle
|
||||
Gemfile.lock
|
||||
Gemfile.local
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem "rails", "3.2.13"
|
||||
gem "jquery-rails", "~> 2.0.2"
|
||||
gem "i18n", "~> 0.6.0"
|
||||
gem "coderay", "~> 1.0.6"
|
||||
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
|
||||
gem "builder", "3.0.0"
|
||||
gem 'acts-as-taggable-on'
|
||||
# Optional gem for LDAP authentication
|
||||
group :ldap do
|
||||
gem "net-ldap", "~> 0.3.1"
|
||||
end
|
||||
|
||||
# Optional gem for OpenID authentication
|
||||
group :openid do
|
||||
gem "ruby-openid", "~> 2.1.4", :require => "openid"
|
||||
gem "rack-openid"
|
||||
end
|
||||
|
||||
# Optional gem for exporting the gantt to a PNG file, not supported with jruby
|
||||
platforms :mri, :mingw do
|
||||
group :rmagick do
|
||||
# RMagick 2 supports ruby 1.9
|
||||
# RMagick 1 would be fine for ruby 1.8 but Bundler does not support
|
||||
# different requirements for the same gem on different platforms
|
||||
gem "rmagick", ">= 2.0.0"
|
||||
end
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
# jruby-openssl is bundled with JRuby 1.7.0
|
||||
gem "jruby-openssl" if Object.const_defined?(:JRUBY_VERSION) && JRUBY_VERSION < '1.7.0'
|
||||
gem "activerecord-jdbc-adapter", "1.2.5"
|
||||
end
|
||||
|
||||
# Include database gems for the adapters found in the database
|
||||
# configuration file
|
||||
require 'erb'
|
||||
require 'yaml'
|
||||
database_file = File.join(File.dirname(__FILE__), "config/database.yml")
|
||||
if File.exist?(database_file)
|
||||
database_config = YAML::load(ERB.new(IO.read(database_file)).result)
|
||||
adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
|
||||
if adapters.any?
|
||||
adapters.each do |adapter|
|
||||
case adapter
|
||||
when 'mysql2'
|
||||
gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw]
|
||||
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
|
||||
when 'mysql'
|
||||
gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw]
|
||||
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
|
||||
when /postgresql/
|
||||
gem "pg", ">= 0.11.0", :platforms => [:mri, :mingw]
|
||||
gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
|
||||
when /sqlite3/
|
||||
gem "sqlite3", :platforms => [:mri, :mingw]
|
||||
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
||||
when /sqlserver/
|
||||
gem "tiny_tds", "~> 0.5.1", :platforms => [:mri, :mingw]
|
||||
gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
|
||||
else
|
||||
warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems")
|
||||
end
|
||||
end
|
||||
else
|
||||
warn("No adapter found in config/database.yml, please configure it first")
|
||||
end
|
||||
else
|
||||
warn("Please configure your config/database.yml first")
|
||||
end
|
||||
|
||||
group :development do
|
||||
gem "rdoc", ">= 2.4.2"
|
||||
gem "yard"
|
||||
end
|
||||
|
||||
group :test do
|
||||
gem "shoulda", "~> 3.3.2"
|
||||
gem "mocha", "~> 0.12.3"
|
||||
gem 'capybara', '~> 2.0.0'
|
||||
end
|
||||
|
||||
local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
|
||||
if File.exists?(local_gemfile)
|
||||
puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
|
||||
instance_eval File.read(local_gemfile)
|
||||
end
|
||||
|
||||
# Load plugins' Gemfiles
|
||||
Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
|
||||
puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
|
||||
instance_eval File.read(file)
|
||||
end
|
|
@ -0,0 +1,155 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actionmailer (3.2.13)
|
||||
actionpack (= 3.2.13)
|
||||
mail (~> 2.5.3)
|
||||
actionpack (3.2.13)
|
||||
activemodel (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
builder (~> 3.0.0)
|
||||
erubis (~> 2.7.0)
|
||||
journey (~> 1.0.4)
|
||||
rack (~> 1.4.5)
|
||||
rack-cache (~> 1.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.2.1)
|
||||
activemodel (3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
builder (~> 3.0.0)
|
||||
activerecord (3.2.13)
|
||||
activemodel (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
arel (~> 3.0.2)
|
||||
tzinfo (~> 0.3.29)
|
||||
activeresource (3.2.13)
|
||||
activemodel (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
activesupport (3.2.13)
|
||||
i18n (= 0.6.1)
|
||||
multi_json (~> 1.0)
|
||||
acts-as-taggable-on (2.4.1)
|
||||
rails (>= 3, < 5)
|
||||
arel (3.0.2)
|
||||
builder (3.0.0)
|
||||
capybara (2.0.3)
|
||||
mime-types (>= 1.16)
|
||||
nokogiri (>= 1.3.3)
|
||||
rack (>= 1.0.0)
|
||||
rack-test (>= 0.5.4)
|
||||
selenium-webdriver (~> 2.0)
|
||||
xpath (~> 1.0.0)
|
||||
childprocess (0.3.9)
|
||||
ffi (~> 1.0, >= 1.0.11)
|
||||
coderay (1.0.9)
|
||||
erubis (2.7.0)
|
||||
fastercsv (1.5.5)
|
||||
ffi (1.9.0-x86-mingw32)
|
||||
hike (1.2.3)
|
||||
i18n (0.6.1)
|
||||
journey (1.0.4)
|
||||
jquery-rails (2.0.3)
|
||||
railties (>= 3.1.0, < 5.0)
|
||||
thor (~> 0.14)
|
||||
json (1.8.0)
|
||||
mail (2.5.4)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
metaclass (0.0.1)
|
||||
mime-types (1.23)
|
||||
mini_portile (0.5.0)
|
||||
mocha (0.12.10)
|
||||
metaclass (~> 0.0.1)
|
||||
multi_json (1.7.6)
|
||||
mysql2 (0.3.11-x86-mingw32)
|
||||
net-ldap (0.3.1)
|
||||
nokogiri (1.6.0-x86-mingw32)
|
||||
mini_portile (~> 0.5.0)
|
||||
pg (0.14.1-x86-mingw32)
|
||||
polyglot (0.3.3)
|
||||
rack (1.4.5)
|
||||
rack-cache (1.2)
|
||||
rack (>= 0.4)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-ssl (1.3.3)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
rails (3.2.13)
|
||||
actionmailer (= 3.2.13)
|
||||
actionpack (= 3.2.13)
|
||||
activerecord (= 3.2.13)
|
||||
activeresource (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
bundler (~> 1.0)
|
||||
railties (= 3.2.13)
|
||||
railties (3.2.13)
|
||||
actionpack (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
rack-ssl (~> 1.3.2)
|
||||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (>= 0.14.6, < 2.0)
|
||||
rake (10.0.4)
|
||||
rdoc (3.12.2)
|
||||
json (~> 1.4)
|
||||
rmagick (2.13.2)
|
||||
ruby-openid (2.1.8)
|
||||
rubyzip (0.9.9)
|
||||
selenium-webdriver (2.33.0)
|
||||
childprocess (>= 0.2.5)
|
||||
multi_json (~> 1.0)
|
||||
rubyzip
|
||||
websocket (~> 1.0.4)
|
||||
shoulda (3.3.2)
|
||||
shoulda-context (~> 1.0.1)
|
||||
shoulda-matchers (~> 1.4.1)
|
||||
shoulda-context (1.0.2)
|
||||
shoulda-matchers (1.4.1)
|
||||
activesupport (>= 3.0.0)
|
||||
sprockets (2.2.2)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sqlite3 (1.3.7-x86-mingw32)
|
||||
thor (0.18.1)
|
||||
tilt (1.4.1)
|
||||
treetop (1.4.14)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.37)
|
||||
websocket (1.0.7)
|
||||
xpath (1.0.0)
|
||||
nokogiri (~> 1.3)
|
||||
yard (0.8.6.1)
|
||||
|
||||
PLATFORMS
|
||||
x86-mingw32
|
||||
|
||||
DEPENDENCIES
|
||||
activerecord-jdbc-adapter (= 1.2.5)
|
||||
activerecord-jdbcmysql-adapter
|
||||
activerecord-jdbcpostgresql-adapter
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
acts-as-taggable-on
|
||||
builder (= 3.0.0)
|
||||
capybara (~> 2.0.0)
|
||||
coderay (~> 1.0.6)
|
||||
fastercsv (~> 1.5.0)
|
||||
i18n (~> 0.6.0)
|
||||
jquery-rails (~> 2.0.2)
|
||||
mocha (~> 0.12.3)
|
||||
mysql2 (~> 0.3.11)
|
||||
net-ldap (~> 0.3.1)
|
||||
pg (>= 0.11.0)
|
||||
rack-openid
|
||||
rails (= 3.2.13)
|
||||
rdoc (>= 2.4.2)
|
||||
rmagick (>= 2.0.0)
|
||||
ruby-openid (~> 2.1.4)
|
||||
shoulda (~> 3.3.2)
|
||||
sqlite3
|
||||
yard
|
|
@ -0,0 +1,5 @@
|
|||
= Redmine
|
||||
|
||||
Redmine is a flexible project management web application written using Ruby on Rails framework.
|
||||
|
||||
More details can be found in the doc directory or on the official website http://www.redmine.org
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env rake
|
||||
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
||||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
||||
|
||||
require File.expand_path('../config/application', __FILE__)
|
||||
|
||||
RedmineApp::Application.load_tasks
|
|
@ -0,0 +1,307 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AccountController < ApplicationController
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
# prevents login action to be filtered by check_if_login_required application scope filter
|
||||
skip_before_filter :check_if_login_required
|
||||
|
||||
# Login request and validation
|
||||
def login
|
||||
if request.get?
|
||||
if User.current.logged?
|
||||
redirect_to home_url
|
||||
end
|
||||
else
|
||||
authenticate_user
|
||||
end
|
||||
rescue AuthSourceException => e
|
||||
logger.error "An error occured when authenticating #{params[:username]}: #{e.message}"
|
||||
render_error :message => e.message
|
||||
end
|
||||
|
||||
# Log out current user and redirect to welcome page
|
||||
def logout
|
||||
if User.current.anonymous?
|
||||
redirect_to home_url
|
||||
elsif request.post?
|
||||
logout_user
|
||||
redirect_to home_url
|
||||
end
|
||||
# display the logout form
|
||||
end
|
||||
|
||||
# Lets user choose a new password
|
||||
def lost_password
|
||||
(redirect_to(home_url); return) unless Setting.lost_password?
|
||||
if params[:token]
|
||||
@token = Token.find_token("recovery", params[:token].to_s)
|
||||
if @token.nil? || @token.expired?
|
||||
redirect_to home_url
|
||||
return
|
||||
end
|
||||
@user = @token.user
|
||||
unless @user && @user.active?
|
||||
redirect_to home_url
|
||||
return
|
||||
end
|
||||
if request.post?
|
||||
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||
if @user.save
|
||||
@token.destroy
|
||||
flash[:notice] = l(:notice_account_password_updated)
|
||||
redirect_to signin_path
|
||||
return
|
||||
end
|
||||
end
|
||||
render :template => "account/password_recovery"
|
||||
return
|
||||
else
|
||||
if request.post?
|
||||
user = User.find_by_mail(params[:mail].to_s)
|
||||
# user not found or not active
|
||||
unless user && user.active?
|
||||
flash.now[:error] = l(:notice_account_unknown_email)
|
||||
return
|
||||
end
|
||||
# user cannot change its password
|
||||
unless user.change_password_allowed?
|
||||
flash.now[:error] = l(:notice_can_t_change_password)
|
||||
return
|
||||
end
|
||||
# create a new token for password recovery
|
||||
token = Token.new(:user => user, :action => "recovery")
|
||||
if token.save
|
||||
Mailer.lost_password(token).deliver
|
||||
flash[:notice] = l(:notice_account_lost_email_sent)
|
||||
redirect_to signin_path
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# User self-registration
|
||||
def register
|
||||
(redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration]
|
||||
if request.get?
|
||||
session[:auth_source_registration] = nil
|
||||
@user = User.new(:language => current_language.to_s)
|
||||
else
|
||||
user_params = params[:user] || {}
|
||||
@user = User.new
|
||||
@user.safe_attributes = user_params
|
||||
@user.admin = false
|
||||
@user.register
|
||||
if session[:auth_source_registration]
|
||||
@user.activate
|
||||
@user.login = session[:auth_source_registration][:login]
|
||||
@user.auth_source_id = session[:auth_source_registration][:auth_source_id]
|
||||
if @user.save
|
||||
session[:auth_source_registration] = nil
|
||||
self.logged_user = @user
|
||||
flash[:notice] = l(:notice_account_activated)
|
||||
redirect_to my_account_path
|
||||
end
|
||||
else
|
||||
@user.login = params[:user][:login]
|
||||
unless user_params[:identity_url].present? && user_params[:password].blank? && user_params[:password_confirmation].blank?
|
||||
@user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation]
|
||||
end
|
||||
|
||||
case Setting.self_registration
|
||||
when '1'
|
||||
register_by_email_activation(@user)
|
||||
when '3'
|
||||
register_automatically(@user)
|
||||
else
|
||||
register_manually_by_administrator(@user)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Token based account activation
|
||||
def activate
|
||||
(redirect_to(home_url); return) unless Setting.self_registration? && params[:token].present?
|
||||
token = Token.find_token('register', params[:token].to_s)
|
||||
(redirect_to(home_url); return) unless token and !token.expired?
|
||||
user = token.user
|
||||
(redirect_to(home_url); return) unless user.registered?
|
||||
user.activate
|
||||
if user.save
|
||||
token.destroy
|
||||
flash[:notice] = l(:notice_account_activated)
|
||||
end
|
||||
redirect_to signin_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authenticate_user
|
||||
if Setting.openid? && using_open_id?
|
||||
open_id_authenticate(params[:openid_url])
|
||||
else
|
||||
password_authentication
|
||||
end
|
||||
end
|
||||
|
||||
def password_authentication
|
||||
user = User.try_to_login(params[:username], params[:password])
|
||||
|
||||
if user.nil?
|
||||
invalid_credentials
|
||||
elsif user.new_record?
|
||||
onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id })
|
||||
else
|
||||
# Valid user
|
||||
successful_authentication(user)
|
||||
end
|
||||
end
|
||||
|
||||
def open_id_authenticate(openid_url)
|
||||
back_url = signin_url(:autologin => params[:autologin])
|
||||
|
||||
authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => back_url, :method => :post) do |result, identity_url, registration|
|
||||
if result.successful?
|
||||
user = User.find_or_initialize_by_identity_url(identity_url)
|
||||
if user.new_record?
|
||||
# Self-registration off
|
||||
(redirect_to(home_url); return) unless Setting.self_registration?
|
||||
|
||||
# Create on the fly
|
||||
user.login = registration['nickname'] unless registration['nickname'].nil?
|
||||
user.mail = registration['email'] unless registration['email'].nil?
|
||||
user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
|
||||
user.random_password
|
||||
user.register
|
||||
|
||||
case Setting.self_registration
|
||||
when '1'
|
||||
register_by_email_activation(user) do
|
||||
onthefly_creation_failed(user)
|
||||
end
|
||||
when '3'
|
||||
register_automatically(user) do
|
||||
onthefly_creation_failed(user)
|
||||
end
|
||||
else
|
||||
register_manually_by_administrator(user) do
|
||||
onthefly_creation_failed(user)
|
||||
end
|
||||
end
|
||||
else
|
||||
# Existing record
|
||||
if user.active?
|
||||
successful_authentication(user)
|
||||
else
|
||||
account_pending
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def successful_authentication(user)
|
||||
logger.info "Successful authentication for '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}"
|
||||
# Valid user
|
||||
self.logged_user = user
|
||||
# generate a key and set cookie if autologin
|
||||
if params[:autologin] && Setting.autologin?
|
||||
set_autologin_cookie(user)
|
||||
end
|
||||
call_hook(:controller_account_success_authentication_after, {:user => user })
|
||||
#by young
|
||||
# redirect_back_or_default my_page_path
|
||||
redirect_back_or_default User.current
|
||||
# redirect_to User.current
|
||||
end
|
||||
|
||||
def set_autologin_cookie(user)
|
||||
token = Token.create(:user => user, :action => '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[autologin_cookie_name] = cookie_options
|
||||
end
|
||||
|
||||
# Onthefly creation failed, display the registration form to fill/fix attributes
|
||||
def onthefly_creation_failed(user, auth_source_options = { })
|
||||
@user = user
|
||||
session[:auth_source_registration] = auth_source_options unless auth_source_options.empty?
|
||||
render :action => 'register'
|
||||
end
|
||||
|
||||
def invalid_credentials
|
||||
logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
|
||||
flash.now[:error] = l(:notice_account_invalid_creditentials)
|
||||
end
|
||||
|
||||
# Register a user for email activation.
|
||||
#
|
||||
# Pass a block for behavior when a user fails to save
|
||||
def register_by_email_activation(user, &block)
|
||||
token = Token.new(:user => user, :action => "register")
|
||||
if user.save and token.save
|
||||
Mailer.register(token).deliver
|
||||
flash[:notice] = l(:notice_account_register_done)
|
||||
redirect_to signin_path
|
||||
else
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
# Automatically register a user
|
||||
#
|
||||
# Pass a block for behavior when a user fails to save
|
||||
def register_automatically(user, &block)
|
||||
# Automatic activation
|
||||
user.activate
|
||||
user.last_login_on = Time.now
|
||||
if user.save
|
||||
self.logged_user = user
|
||||
flash[:notice] = l(:notice_account_activated)
|
||||
redirect_to my_account_path
|
||||
else
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
# Manual activation by the administrator
|
||||
#
|
||||
# Pass a block for behavior when a user fails to save
|
||||
def register_manually_by_administrator(user, &block)
|
||||
if user.save
|
||||
# Sends an email to the administrators
|
||||
Mailer.account_activation_request(user).deliver
|
||||
account_pending
|
||||
else
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
def account_pending
|
||||
flash[:notice] = l(:notice_account_pending)
|
||||
redirect_to signin_path
|
||||
end
|
||||
end
|
|
@ -0,0 +1,87 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class ActivitiesController < ApplicationController
|
||||
menu_item :activity
|
||||
before_filter :find_optional_project, :index
|
||||
accept_rss_auth :index
|
||||
helper :Watchers
|
||||
|
||||
def index
|
||||
@days = Setting.activity_days_default.to_i
|
||||
|
||||
if params[:from]
|
||||
begin; @date_to = params[:from].to_date + 1; rescue; end
|
||||
end
|
||||
|
||||
has = {
|
||||
"show_issues" => true
|
||||
}
|
||||
@date_to ||= Date.today + 1
|
||||
@date_from = @date_to - @days
|
||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
|
||||
# 决定显示所用用户或单个用户活动
|
||||
@activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
|
||||
:with_subprojects => @with_subprojects,
|
||||
:author => @author)
|
||||
@activity.scope_select {|t| !has["show_#{t}"].nil?}
|
||||
#@activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
|
||||
|
||||
events = @activity.events(@date_from, @date_to)
|
||||
# Added by Nie.
|
||||
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||
@activity_count = events.size
|
||||
@activity_pages = Paginator.new @activity_count, @limit, params['page']
|
||||
@offset ||= @activity_pages.offset
|
||||
|
||||
@project_base_tag = params[:id]?'base_projects':'base'
|
||||
if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, events.first, events.size, User.current, current_language])
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@events_by_day_ = events.slice(@offset,@limit)
|
||||
@events_by_day = @events_by_day_.group_by {|event| User.current.time_to_date(event.event_datetime)}
|
||||
#by young render :layout => false if request.xhr?
|
||||
render :layout => @project_base_tag
|
||||
}
|
||||
format.atom {
|
||||
title = l(:label_activity)
|
||||
if @author
|
||||
title = @author.name
|
||||
elsif @activity.scope.size == 1
|
||||
title = l("label_#{@activity.scope.first.singularize}_plural")
|
||||
end
|
||||
render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# TODO: refactor, duplicated in projects_controller
|
||||
def find_optional_project
|
||||
return true unless params[:id]
|
||||
@project = Project.find(params[:id])
|
||||
authorize
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,83 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AdminController < ApplicationController
|
||||
layout 'admin'
|
||||
menu_item :projects, :only => :projects
|
||||
menu_item :plugins, :only => :plugins
|
||||
menu_item :info, :only => :info
|
||||
|
||||
before_filter :require_admin
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
def index
|
||||
@no_configuration_data = Redmine::DefaultData::Loader::no_data?
|
||||
end
|
||||
|
||||
def projects
|
||||
@status = params[:status] || 1
|
||||
|
||||
scope = Project.status(@status).order('lft')
|
||||
scope = scope.like(params[:name]) if params[:name].present?
|
||||
@projects = scope.all
|
||||
|
||||
render :action => "projects", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def plugins
|
||||
@plugins = Redmine::Plugin.all
|
||||
end
|
||||
|
||||
# Loads the default configuration
|
||||
# (roles, trackers, statuses, workflow, enumerations)
|
||||
def default_configuration
|
||||
if request.post?
|
||||
begin
|
||||
Redmine::DefaultData::Loader::load(params[:lang])
|
||||
flash[:notice] = l(:notice_default_data_loaded)
|
||||
rescue Exception => e
|
||||
flash[:error] = l(:error_can_t_load_default_data, e.message)
|
||||
end
|
||||
end
|
||||
redirect_to admin_path
|
||||
end
|
||||
|
||||
def test_email
|
||||
raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
|
||||
# Force ActionMailer to raise delivery errors so we can catch it
|
||||
ActionMailer::Base.raise_delivery_errors = true
|
||||
begin
|
||||
@test = Mailer.test_email(User.current).deliver
|
||||
flash[:notice] = l(:notice_email_sent, User.current.mail)
|
||||
rescue Exception => e
|
||||
flash[:error] = l(:notice_email_error, e.message)
|
||||
end
|
||||
ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
|
||||
redirect_to settings_path(:tab => 'notifications')
|
||||
end
|
||||
|
||||
def info
|
||||
@db_adapter_name = ActiveRecord::Base.connection.adapter_name
|
||||
@checklist = [
|
||||
[:text_default_administrator_account_changed, User.default_admin_account_changed?],
|
||||
[:text_file_repository_writable, File.writable?(Attachment.storage_path)],
|
||||
[:text_plugin_assets_writable, File.writable?(Redmine::Plugin.public_directory)],
|
||||
[:text_rmagick_available, Object.const_defined?(:Magick)]
|
||||
]
|
||||
end
|
||||
end
|
|
@ -0,0 +1,610 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'uri'
|
||||
require 'cgi'
|
||||
|
||||
class Unauthorized < Exception; end
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
include Redmine::I18n
|
||||
include Redmine::Pagination
|
||||
include RoutesHelper
|
||||
helper :routes
|
||||
|
||||
class_attribute :accept_api_auth_actions
|
||||
class_attribute :accept_rss_auth_actions
|
||||
class_attribute :model_object
|
||||
|
||||
layout 'base'
|
||||
|
||||
protect_from_forgery
|
||||
def handle_unverified_request
|
||||
super
|
||||
cookies.delete(autologin_cookie_name)
|
||||
end
|
||||
|
||||
before_filter :session_expiration, :user_setup, :check_if_login_required, :set_localization
|
||||
|
||||
|
||||
rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
|
||||
rescue_from ::Unauthorized, :with => :deny_access
|
||||
rescue_from ::ActionView::MissingTemplate, :with => :missing_template
|
||||
|
||||
include Redmine::Search::Controller
|
||||
include Redmine::MenuManager::MenuController
|
||||
helper Redmine::MenuManager::MenuHelper
|
||||
|
||||
def session_expiration
|
||||
if session[:user_id]
|
||||
if session_expired? && !try_to_autologin
|
||||
reset_session
|
||||
flash[:error] = l(:error_session_expired)
|
||||
redirect_to signin_url
|
||||
else
|
||||
session[:atime] = Time.now.utc.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def session_expired?
|
||||
if Setting.session_lifetime?
|
||||
unless session[:ctime] && (Time.now.utc.to_i - session[:ctime].to_i <= Setting.session_lifetime.to_i * 60)
|
||||
return true
|
||||
end
|
||||
end
|
||||
if Setting.session_timeout?
|
||||
unless session[:atime] && (Time.now.utc.to_i - session[:atime].to_i <= Setting.session_timeout.to_i * 60)
|
||||
return true
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def start_user_session(user)
|
||||
session[:user_id] = user.id
|
||||
session[:ctime] = Time.now.utc.to_i
|
||||
session[:atime] = Time.now.utc.to_i
|
||||
end
|
||||
|
||||
def user_setup
|
||||
# Check the settings cache for each request
|
||||
Setting.check_cache
|
||||
# Find the current user
|
||||
User.current = find_current_user
|
||||
logger.info(" Current user: " + (User.current.logged? ? "#{User.current.login} (id=#{User.current.id})" : "anonymous")) if logger
|
||||
end
|
||||
|
||||
# Returns the current user or nil if no user is logged in
|
||||
# and starts a session if needed
|
||||
def find_current_user
|
||||
user = nil
|
||||
unless api_request?
|
||||
if session[:user_id]
|
||||
# existing session
|
||||
user = (User.active.find(session[:user_id]) rescue nil)
|
||||
elsif autologin_user = try_to_autologin
|
||||
user = autologin_user
|
||||
elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
|
||||
# RSS key authentication does not start a session
|
||||
user = User.find_by_rss_key(params[:key])
|
||||
end
|
||||
end
|
||||
if user.nil? && Setting.rest_api_enabled? && accept_api_auth?
|
||||
if (key = api_key_from_request)
|
||||
# Use API key
|
||||
user = User.find_by_api_key(key)
|
||||
else
|
||||
# HTTP Basic, either username/password or API key/random
|
||||
authenticate_with_http_basic do |username, password|
|
||||
user = User.try_to_login(username, password) || User.find_by_api_key(username)
|
||||
end
|
||||
end
|
||||
# Switch user if requested by an admin user
|
||||
if user && user.admin? && (username = api_switch_user_from_request)
|
||||
su = User.find_by_login(username)
|
||||
if su && su.active?
|
||||
logger.info(" User switched by: #{user.login} (id=#{user.id})") if logger
|
||||
user = su
|
||||
else
|
||||
render_error :message => 'Invalid X-Redmine-Switch-User header', :status => 412
|
||||
end
|
||||
end
|
||||
end
|
||||
user
|
||||
end
|
||||
|
||||
def autologin_cookie_name
|
||||
Redmine::Configuration['autologin_cookie_name'].presence || 'autologin'
|
||||
end
|
||||
|
||||
def try_to_autologin
|
||||
if cookies[autologin_cookie_name] && Setting.autologin?
|
||||
# auto-login feature starts a new session
|
||||
user = User.try_to_autologin(cookies[autologin_cookie_name])
|
||||
if user
|
||||
reset_session
|
||||
start_user_session(user)
|
||||
end
|
||||
user
|
||||
end
|
||||
end
|
||||
|
||||
# Sets the logged in user
|
||||
def logged_user=(user)
|
||||
reset_session
|
||||
if user && user.is_a?(User)
|
||||
User.current = user
|
||||
start_user_session(user)
|
||||
else
|
||||
User.current = User.anonymous
|
||||
end
|
||||
end
|
||||
|
||||
# Logs out current user
|
||||
def logout_user
|
||||
if User.current.logged?
|
||||
cookies.delete(autologin_cookie_name)
|
||||
Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin'])
|
||||
self.logged_user = nil
|
||||
end
|
||||
end
|
||||
|
||||
# check if login is globally required to access the application
|
||||
def check_if_login_required
|
||||
# no check needed if user is already logged in
|
||||
return true if User.current.logged?
|
||||
require_login if Setting.login_required?
|
||||
end
|
||||
|
||||
def set_localization
|
||||
lang = nil
|
||||
if User.current.logged?
|
||||
lang = find_language(User.current.language)
|
||||
end
|
||||
if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
|
||||
accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
|
||||
if !accept_lang.blank?
|
||||
accept_lang = accept_lang.downcase
|
||||
lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
|
||||
end
|
||||
end
|
||||
lang ||= Setting.default_language
|
||||
set_language_if_valid(lang)
|
||||
end
|
||||
|
||||
def require_login
|
||||
if !User.current.logged?
|
||||
# Extract only the basic url parameters on non-GET requests
|
||||
if request.get?
|
||||
url = url_for(params)
|
||||
else
|
||||
url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
|
||||
format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
|
||||
format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
|
||||
format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
|
||||
format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
|
||||
end
|
||||
return false
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def require_admin
|
||||
return unless require_login
|
||||
if !User.current.admin?
|
||||
render_403
|
||||
return false
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def deny_access
|
||||
User.current.logged? ? render_403 : require_login
|
||||
end
|
||||
|
||||
# Authorize the user for the requested action
|
||||
def authorize(ctrl = params[:controller], action = params[:action], global = false)
|
||||
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
|
||||
if allowed
|
||||
true
|
||||
else
|
||||
if @project && @project.archived?
|
||||
render_403 :message => :notice_not_authorized_archived_project
|
||||
else
|
||||
deny_access
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Authorize the user for the requested action outside a project
|
||||
def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
|
||||
authorize(ctrl, action, global)
|
||||
end
|
||||
|
||||
# Find project of id params[:id]
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Find project of id params[:project_id]
|
||||
def find_project_by_project_id
|
||||
@project = Project.find(params[:project_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Find a project based on params[:project_id]
|
||||
# TODO: some subclasses override this, see about merging their logic
|
||||
def find_optional_project
|
||||
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
|
||||
allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
|
||||
allowed ? true : deny_access
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Finds and sets @project based on @object.project
|
||||
def find_project_from_association
|
||||
render_404 unless @object.present?
|
||||
|
||||
@project = @object.project
|
||||
end
|
||||
|
||||
def find_model_object
|
||||
model = self.class.model_object
|
||||
if model
|
||||
@object = model.find(params[:id])
|
||||
self.instance_variable_set('@' + controller_name.singularize, @object) if @object
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def self.model_object(model)
|
||||
self.model_object = model
|
||||
end
|
||||
|
||||
# Find the issue whose id is the :id parameter
|
||||
# Raises a Unauthorized exception if the issue is not visible
|
||||
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])
|
||||
raise Unauthorized unless @issue.visible?
|
||||
@project = @issue.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Find issues with a single :id param or :ids array param
|
||||
# Raises a Unauthorized exception if one of the issues is not visible
|
||||
def find_issues
|
||||
@issues = Issue.find_all_by_id(params[:id] || params[:ids])
|
||||
raise ActiveRecord::RecordNotFound if @issues.empty?
|
||||
raise Unauthorized unless @issues.all?(&:visible?)
|
||||
@projects = @issues.collect(&:project).compact.uniq
|
||||
@project = @projects.first if @projects.size == 1
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_attachments
|
||||
if (attachments = params[:attachments]).present?
|
||||
att = attachments.values.collect do |attachment|
|
||||
Attachment.find_by_token( attachment[:token] ) if attachment[:token].present?
|
||||
end
|
||||
att.compact!
|
||||
end
|
||||
@attachments = att || []
|
||||
end
|
||||
|
||||
# make sure that the user is a member of the project (or admin) if project is private
|
||||
# used as a before_filter for actions that do not require any particular permission on the project
|
||||
def check_project_privacy
|
||||
if @project && !@project.archived?
|
||||
if @project.visible?
|
||||
true
|
||||
else
|
||||
deny_access
|
||||
end
|
||||
else
|
||||
@project = nil
|
||||
render_404
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def back_url
|
||||
url = params[:back_url]
|
||||
if url.nil? && referer = request.env['HTTP_REFERER']
|
||||
url = CGI.unescape(referer.to_s)
|
||||
end
|
||||
url
|
||||
end
|
||||
|
||||
def redirect_back_or_default(default)
|
||||
back_url = params[:back_url].to_s
|
||||
if back_url.present?
|
||||
begin
|
||||
uri = URI.parse(back_url)
|
||||
# do not redirect user to another host or to the login or register page
|
||||
#by young
|
||||
if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) && (uri.path!='/')
|
||||
redirect_to(back_url)
|
||||
return
|
||||
end
|
||||
rescue URI::InvalidURIError
|
||||
logger.warn("Could not redirect to invalid URL #{back_url}")
|
||||
# redirect to default
|
||||
end
|
||||
end
|
||||
redirect_to default
|
||||
false
|
||||
end
|
||||
|
||||
# Redirects to the request referer if present, redirects to args or call block otherwise.
|
||||
def redirect_to_referer_or(*args, &block)
|
||||
redirect_to :back
|
||||
rescue ::ActionController::RedirectBackError
|
||||
if args.any?
|
||||
redirect_to *args
|
||||
elsif block_given?
|
||||
block.call
|
||||
else
|
||||
raise "#redirect_to_referer_or takes arguments or a block"
|
||||
end
|
||||
end
|
||||
|
||||
def render_403(options={})
|
||||
@project = nil
|
||||
render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
|
||||
return false
|
||||
end
|
||||
|
||||
def render_404(options={})
|
||||
render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
|
||||
return false
|
||||
end
|
||||
|
||||
# Renders an error response
|
||||
def render_error(arg)
|
||||
arg = {:message => arg} unless arg.is_a?(Hash)
|
||||
|
||||
@message = arg[:message]
|
||||
@message = l(@message) if @message.is_a?(Symbol)
|
||||
@status = arg[:status] || 500
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :template => 'common/error', :layout => use_layout, :status => @status
|
||||
}
|
||||
format.any { head @status }
|
||||
end
|
||||
end
|
||||
|
||||
# Handler for ActionView::MissingTemplate exception
|
||||
def missing_template
|
||||
logger.warn "Missing template, responding with 404"
|
||||
@project = nil
|
||||
render_404
|
||||
end
|
||||
|
||||
# Filter for actions that provide an API response
|
||||
# but have no HTML representation for non admin users
|
||||
def require_admin_or_api_request
|
||||
return true if api_request?
|
||||
if User.current.admin?
|
||||
true
|
||||
elsif User.current.logged?
|
||||
render_error(:status => 406)
|
||||
else
|
||||
deny_access
|
||||
end
|
||||
end
|
||||
|
||||
# Picks which layout to use based on the request
|
||||
#
|
||||
# @return [boolean, string] name of the layout to use or false for no layout
|
||||
def use_layout
|
||||
request.xhr? ? false : 'base'
|
||||
end
|
||||
|
||||
def invalid_authenticity_token
|
||||
if api_request?
|
||||
logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
|
||||
end
|
||||
render_error "Invalid form authenticity token."
|
||||
end
|
||||
|
||||
def render_feed(items, options={})
|
||||
@items = items || []
|
||||
@items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
|
||||
@items = @items.slice(0, Setting.feeds_limit.to_i)
|
||||
@title = options[:title] || Setting.app_title
|
||||
render :template => "common/feed", :formats => [:atom], :layout => false,
|
||||
:content_type => 'application/atom+xml'
|
||||
end
|
||||
|
||||
def self.accept_rss_auth(*actions)
|
||||
if actions.any?
|
||||
self.accept_rss_auth_actions = actions
|
||||
else
|
||||
self.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?
|
||||
self.accept_api_auth_actions = actions
|
||||
else
|
||||
self.accept_api_auth_actions || []
|
||||
end
|
||||
end
|
||||
|
||||
def accept_api_auth?(action=action_name)
|
||||
self.class.accept_api_auth.include?(action.to_sym)
|
||||
end
|
||||
|
||||
# Returns the number of objects that should be displayed
|
||||
# on the paginated list
|
||||
def per_page_option
|
||||
per_page = nil
|
||||
if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
|
||||
per_page = params[:per_page].to_s.to_i
|
||||
session[:per_page] = per_page
|
||||
elsif session[:per_page]
|
||||
per_page = session[:per_page]
|
||||
else
|
||||
per_page = Setting.per_page_options_array.first || 25
|
||||
end
|
||||
per_page
|
||||
end
|
||||
|
||||
# Returns offset and limit used to retrieve objects
|
||||
# for an API response based on offset, limit and page parameters
|
||||
def api_offset_and_limit(options=params)
|
||||
if options[:offset].present?
|
||||
offset = options[:offset].to_i
|
||||
if offset < 0
|
||||
offset = 0
|
||||
end
|
||||
end
|
||||
limit = options[:limit].to_i
|
||||
if limit < 1
|
||||
limit = 25
|
||||
elsif limit > 100
|
||||
limit = 100
|
||||
end
|
||||
if offset.nil? && options[:page].present?
|
||||
offset = (options[:page].to_i - 1) * limit
|
||||
offset = 0 if offset < 0
|
||||
offset ||= 0
|
||||
end
|
||||
|
||||
|
||||
[offset, limit]
|
||||
end
|
||||
|
||||
# qvalues http header parser
|
||||
# code taken from webrick
|
||||
def parse_qvalues(value)
|
||||
tmp = []
|
||||
if value
|
||||
parts = value.split(/,\s*/)
|
||||
parts.each {|part|
|
||||
if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
|
||||
val = m[1]
|
||||
q = (m[2] or 1).to_f
|
||||
tmp.push([val, q])
|
||||
end
|
||||
}
|
||||
tmp = tmp.sort_by{|val, q| -q}
|
||||
tmp.collect!{|val, q| val}
|
||||
end
|
||||
return tmp
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
# Returns a string that can be used as filename value in Content-Disposition header
|
||||
def filename_for_content_disposition(name)
|
||||
request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
|
||||
end
|
||||
|
||||
def api_request?
|
||||
%w(xml json).include? params[:format]
|
||||
end
|
||||
|
||||
# Returns the API key present in the request
|
||||
def api_key_from_request
|
||||
if params[:key].present?
|
||||
params[:key].to_s
|
||||
elsif request.headers["X-Redmine-API-Key"].present?
|
||||
request.headers["X-Redmine-API-Key"].to_s
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the API 'switch user' value if present
|
||||
def api_switch_user_from_request
|
||||
request.headers["X-Redmine-Switch-User"].to_s.presence
|
||||
end
|
||||
|
||||
# Renders a warning flash if obj has unsaved attachments
|
||||
def render_attachment_warning_if_needed(obj)
|
||||
flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
|
||||
end
|
||||
|
||||
# Sets the `flash` notice or error based the number of issues that did not save
|
||||
#
|
||||
# @param [Array, Issue] issues all of the saved and unsaved Issues
|
||||
# @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
|
||||
def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
|
||||
if unsaved_issue_ids.empty?
|
||||
flash[:notice] = l(:notice_successful_update) unless issues.empty?
|
||||
else
|
||||
flash[:error] = l(:notice_failed_to_save_issues,
|
||||
:count => unsaved_issue_ids.size,
|
||||
:total => issues.size,
|
||||
:ids => '#' + unsaved_issue_ids.join(', #'))
|
||||
end
|
||||
end
|
||||
|
||||
# Rescues an invalid query statement. Just in case...
|
||||
def query_statement_invalid(exception)
|
||||
logger.error "Query::StatementInvalid: #{exception.message}" if logger
|
||||
session.delete(:query)
|
||||
sort_clear if respond_to?(:sort_clear)
|
||||
render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
|
||||
end
|
||||
|
||||
# Renders a 200 response for successfull updates or deletions via the API
|
||||
def render_api_ok
|
||||
render_api_head :ok
|
||||
end
|
||||
|
||||
# Renders a head API response
|
||||
def render_api_head(status)
|
||||
# #head would return a response body with one space
|
||||
render :text => '', :status => status, :layout => nil
|
||||
end
|
||||
|
||||
# Renders API response on validation failure
|
||||
def render_validation_errors(objects)
|
||||
if objects.is_a?(Array)
|
||||
@error_messages = objects.map {|object| object.errors.full_messages}.flatten
|
||||
else
|
||||
@error_messages = objects.errors.full_messages
|
||||
end
|
||||
render :template => 'common/error_messages.api', :status => :unprocessable_entity, :layout => nil
|
||||
end
|
||||
|
||||
# Overrides #_include_layout? so that #render with no arguments
|
||||
# doesn't use the layout for api requests
|
||||
def _include_layout?(*args)
|
||||
api_request? ? false : super
|
||||
end
|
||||
end
|
|
@ -0,0 +1,154 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AttachmentsController < ApplicationController
|
||||
before_filter :find_project, :except => :upload
|
||||
before_filter :file_readable, :read_authorize, :only => [:show, :download, :thumbnail]
|
||||
before_filter :delete_authorize, :only => :destroy
|
||||
before_filter :authorize_global, :only => :upload
|
||||
|
||||
accept_api_auth :show, :download, :upload
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
if @attachment.is_diff?
|
||||
@diff = File.new(@attachment.diskfile, "rb").read
|
||||
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
|
||||
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
|
||||
# Save diff type as user preference
|
||||
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
|
||||
User.current.pref[:diff_type] = @diff_type
|
||||
User.current.preference.save
|
||||
end
|
||||
render :action => 'diff'
|
||||
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
|
||||
@content = File.new(@attachment.diskfile, "rb").read
|
||||
render :action => 'file'
|
||||
else
|
||||
download
|
||||
end
|
||||
}
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def download
|
||||
if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project)
|
||||
@attachment.increment_download
|
||||
end
|
||||
|
||||
if stale?(:etag => @attachment.digest)
|
||||
# images are sent inline
|
||||
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
||||
:type => detect_content_type(@attachment),
|
||||
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
||||
end
|
||||
end
|
||||
|
||||
def thumbnail
|
||||
if @attachment.thumbnailable? && thumbnail = @attachment.thumbnail(:size => params[:size])
|
||||
if stale?(:etag => thumbnail)
|
||||
send_file thumbnail,
|
||||
:filename => filename_for_content_disposition(@attachment.filename),
|
||||
:type => detect_content_type(@attachment),
|
||||
:disposition => 'inline'
|
||||
end
|
||||
else
|
||||
# No thumbnail for the attachment or thumbnail could not be created
|
||||
render :nothing => true, :status => 404
|
||||
end
|
||||
end
|
||||
|
||||
def upload
|
||||
# Make sure that API users get used to set this content type
|
||||
# as it won't trigger Rails' automatic parsing of the request body for parameters
|
||||
unless request.content_type == 'application/octet-stream'
|
||||
render :nothing => true, :status => 406
|
||||
return
|
||||
end
|
||||
|
||||
@attachment = Attachment.new(:file => request.raw_post)
|
||||
@attachment.author = User.current
|
||||
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
|
||||
saved = @attachment.save
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.api {
|
||||
if saved
|
||||
render :action => 'upload', :status => :created
|
||||
else
|
||||
render_validation_errors(@attachment)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @attachment.container.respond_to?(:init_journal)
|
||||
@attachment.container.init_journal(User.current)
|
||||
end
|
||||
if @attachment.container
|
||||
# Make sure association callbacks are called
|
||||
@attachment.container.attachments.delete(@attachment)
|
||||
else
|
||||
@attachment.destroy
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_referer_or project_path(@project) }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@attachment = Attachment.find(params[:id])
|
||||
# Show 404 if the filename in the url is wrong
|
||||
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
|
||||
@project = @attachment.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Checks that the file exists and is readable
|
||||
def file_readable
|
||||
if @attachment.readable?
|
||||
true
|
||||
else
|
||||
logger.error "Cannot send attachment, #{@attachment.diskfile} does not exist or is unreadable."
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
def read_authorize
|
||||
@attachment.visible? ? true : deny_access
|
||||
end
|
||||
|
||||
def delete_authorize
|
||||
@attachment.deletable? ? true : deny_access
|
||||
end
|
||||
|
||||
def detect_content_type(attachment)
|
||||
content_type = attachment.content_type
|
||||
if content_type.blank?
|
||||
content_type = Redmine::MimeType.of(attachment.filename)
|
||||
end
|
||||
content_type.to_s
|
||||
end
|
||||
end
|
|
@ -0,0 +1,96 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 AuthSourcesController < ApplicationController
|
||||
layout 'admin'
|
||||
menu_item :ldap_authentication
|
||||
|
||||
before_filter :require_admin
|
||||
before_filter :find_auth_source, :only => [:edit, :update, :test_connection, :destroy]
|
||||
|
||||
def index
|
||||
@auth_source_pages, @auth_sources = paginate AuthSource, :per_page => 25
|
||||
end
|
||||
|
||||
def new
|
||||
klass_name = params[:type] || 'AuthSourceLdap'
|
||||
@auth_source = AuthSource.new_subclass_instance(klass_name, params[:auth_source])
|
||||
render_404 unless @auth_source
|
||||
end
|
||||
|
||||
def create
|
||||
@auth_source = AuthSource.new_subclass_instance(params[:type], params[:auth_source])
|
||||
if @auth_source.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to auth_sources_path
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @auth_source.update_attributes(params[:auth_source])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to auth_sources_path
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def test_connection
|
||||
begin
|
||||
@auth_source.test_connection
|
||||
flash[:notice] = l(:notice_successful_connection)
|
||||
rescue Exception => e
|
||||
flash[:error] = l(:error_unable_to_connect, e.message)
|
||||
end
|
||||
redirect_to auth_sources_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
unless @auth_source.users.exists?
|
||||
@auth_source.destroy
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
end
|
||||
redirect_to auth_sources_path
|
||||
end
|
||||
|
||||
def autocomplete_for_new_user
|
||||
results = AuthSource.search(params[:term])
|
||||
|
||||
render :json => results.map {|result| {
|
||||
'value' => result[:login],
|
||||
'label' => "#{result[:login]} (#{result[:firstname]} #{result[:lastname]})",
|
||||
'login' => result[:login].to_s,
|
||||
'firstname' => result[:firstname].to_s,
|
||||
'lastname' => result[:lastname].to_s,
|
||||
'mail' => result[:mail].to_s,
|
||||
'auth_source_id' => result[:auth_source_id].to_s
|
||||
}}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_auth_source
|
||||
@auth_source = AuthSource.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,44 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 AutoCompletesController < ApplicationController
|
||||
before_filter :find_project
|
||||
|
||||
def issues
|
||||
@issues = []
|
||||
q = (params[:q] || params[:term]).to_s.strip
|
||||
if q.present?
|
||||
scope = (params[:scope] == "all" || @project.nil? ? Issue : @project.issues).visible
|
||||
if q.match(/\A#?(\d+)\z/)
|
||||
@issues << scope.find_by_id($1.to_i)
|
||||
end
|
||||
@issues += scope.where("LOWER(#{Issue.table_name}.subject) LIKE LOWER(?)", "%#{q}%").order("#{Issue.table_name}.id DESC").limit(10).all
|
||||
@issues.compact!
|
||||
end
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
if params[:project_id].present?
|
||||
@project = Project.find(params[:project_id])
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,78 @@
|
|||
class AvatarController < ApplicationController
|
||||
|
||||
|
||||
#before_filter :set_cache_buster
|
||||
include AvatarHelper
|
||||
|
||||
def upload
|
||||
# Make sure that API users get used to set this content type
|
||||
# as it won't trigger Rails' automatic parsing of the request body for parameters
|
||||
unless request.content_type == 'application/octet-stream'
|
||||
render :nothing => true, :status => 406
|
||||
return
|
||||
end
|
||||
|
||||
unless request.raw_post.nil?
|
||||
@source_type = params[:source_type]
|
||||
@source_id = params[:source_id]
|
||||
@temp_file = request.raw_post
|
||||
if @temp_file.size > 0
|
||||
if @temp_file.respond_to?(:original_filename)
|
||||
@image_file = @temp_file.original_filename
|
||||
#image_file.force_encoding("UTF-8") if filename.respond_to?(:force_encoding)
|
||||
else
|
||||
@image_file=params[:filename]
|
||||
end
|
||||
end
|
||||
end
|
||||
if @temp_file && (@temp_file.size > 0)
|
||||
diskfile=disk_filename(@source_type,@source_id)
|
||||
@urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file))
|
||||
logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)")
|
||||
path = File.dirname(diskfile)
|
||||
unless File.directory?(path)
|
||||
FileUtils.mkdir_p(path)
|
||||
end
|
||||
md5 = Digest::MD5.new
|
||||
File.open(diskfile, "wb") do |f|
|
||||
if @temp_file.respond_to?(:read)
|
||||
buffer = ""
|
||||
while (buffer = @temp_file.read(8192))
|
||||
f.write(buffer)
|
||||
md5.update(buffer)
|
||||
end
|
||||
else
|
||||
f.write(@temp_file)
|
||||
md5.update(@temp_file)
|
||||
end
|
||||
end
|
||||
# self.digest = md5.hexdigest
|
||||
end
|
||||
@temp_file = nil
|
||||
# @avatar = Avatar.new(:receive_file => request.raw_post)
|
||||
# @avatar.source_id = User.current.id
|
||||
# @avatar.image_file = params[:filename].presence || Redmine::Utils.random_hex(16)
|
||||
# saved = @avatar.save
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.api {
|
||||
if saved
|
||||
render :action => 'upload', :status => :created
|
||||
else
|
||||
render_validation_errors(@avatar)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_cache_buster
|
||||
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,154 @@
|
|||
class BidsController < ApplicationController
|
||||
|
||||
before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add]
|
||||
|
||||
helper :watchers
|
||||
def index
|
||||
if params[:bid_title]
|
||||
Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description])
|
||||
end
|
||||
# @requirement_title = "4"
|
||||
@offset = 0
|
||||
@limit = 20
|
||||
@bids = Bid.offset(@offset).limit(@limit).all
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
@state = false
|
||||
@user = @bid.author
|
||||
@jour = @bid.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
#
|
||||
# @journals = @bid.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
|
||||
#@journals.each_with_index {|j,i| j.indice = i+1}
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => 'base_bids'
|
||||
}
|
||||
format.api
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def show_project
|
||||
@user = @bid.author
|
||||
@bidding_project = @bid.biding_projects
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => 'base_bids'
|
||||
}
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def add
|
||||
project_id = params[:bid_for_save][:project_id]
|
||||
bid_message = params[:bid_for_save][:bid_message]
|
||||
BidingProject.cerate_bidding(@bid.id, project_id, bid_message)
|
||||
@bidding_project = @bid.biding_projects
|
||||
respond_to do |format|
|
||||
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:user_message].size>0
|
||||
message = params[:user_message]
|
||||
@bid.add_jour(User.current, message)
|
||||
# if a_message.size > 5
|
||||
# @message = a_message[-5, 5]
|
||||
# else
|
||||
# @message = a_message
|
||||
# end
|
||||
# @message_count = a_message.count
|
||||
end
|
||||
@jour = @bid.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
@bid.set_commit(@jour.count)
|
||||
|
||||
respond_to do |format|
|
||||
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
JournalsForMessage.delete_message(params[:object_id])
|
||||
@jour = @bid.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
@bid.set_commit(@jour.count)
|
||||
# if a_message.size > 5
|
||||
# @message = a_message[-5, 5]
|
||||
# else
|
||||
# @message = a_message
|
||||
# end
|
||||
# @message_count = a_message.count
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
|
||||
if @jour
|
||||
user = @jour.user
|
||||
text = @jour.notes
|
||||
else
|
||||
user = @bid.author
|
||||
text = @bid.description
|
||||
end
|
||||
# Replaces pre blocks with [...]
|
||||
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
||||
@content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
||||
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def new_bid
|
||||
|
||||
end
|
||||
|
||||
def more
|
||||
@jour = @bid.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
@state = true
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def back
|
||||
@jour = @bid.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
@state = false
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_bid
|
||||
if params[:bid_id]
|
||||
@bid = Bid.find(params[:bid_id])
|
||||
end
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class BoardsController < ApplicationController
|
||||
default_search_scope :messages
|
||||
before_filter :find_project_by_project_id, :find_board_if_available, :authorize
|
||||
accept_rss_auth :index, :show
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :watchers
|
||||
|
||||
def index
|
||||
@boards = @project.boards.includes(:last_message => :author).all
|
||||
# show the board if there is only one
|
||||
if @boards.size == 1
|
||||
@board = @boards.first
|
||||
show
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
sort_init 'updated_on', 'desc'
|
||||
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
||||
'replies' => "#{Message.table_name}.replies_count",
|
||||
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
||||
|
||||
@topic_count = @board.topics.count
|
||||
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
|
||||
@topics = @board.topics.
|
||||
reorder("#{Message.table_name}.sticky DESC").
|
||||
includes(:last_reply).
|
||||
limit(@topic_pages.per_page).
|
||||
offset(@topic_pages.offset).
|
||||
order(sort_clause).
|
||||
preload(:author, {:last_reply => :author}).
|
||||
all
|
||||
@message = Message.new(:board => @board)
|
||||
render :action => 'show', :layout => !request.xhr?
|
||||
}
|
||||
format.atom {
|
||||
@messages = @board.messages.
|
||||
reorder('created_on DESC').
|
||||
includes(:author, :board).
|
||||
limit(Setting.feeds_limit.to_i).
|
||||
all
|
||||
render_feed(@messages, :title => "#{@project}: #{@board}")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@board = @project.boards.build
|
||||
@board.safe_attributes = params[:board]
|
||||
end
|
||||
|
||||
def create
|
||||
@board = @project.boards.build
|
||||
@board.safe_attributes = params[:board]
|
||||
if @board.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to_settings_in_projects
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@board.safe_attributes = params[:board]
|
||||
if @board.save
|
||||
redirect_to_settings_in_projects
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@board.destroy
|
||||
redirect_to_settings_in_projects
|
||||
end
|
||||
|
||||
private
|
||||
def redirect_to_settings_in_projects
|
||||
redirect_to settings_project_path(@project, :tab => 'boards')
|
||||
end
|
||||
|
||||
def find_board_if_available
|
||||
@board = @project.boards.find(params[:id]) if params[:id]
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,56 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class CalendarsController < ApplicationController
|
||||
menu_item :calendar
|
||||
before_filter :find_optional_project
|
||||
|
||||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||
|
||||
helper :issues
|
||||
helper :projects
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
def show
|
||||
if params[:year] and params[:year].to_i > 1900
|
||||
@year = params[:year].to_i
|
||||
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
||||
@month = params[:month].to_i
|
||||
end
|
||||
end
|
||||
@year ||= Date.today.year
|
||||
@month ||= Date.today.month
|
||||
|
||||
@calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
|
||||
retrieve_query
|
||||
@query.group_by = nil
|
||||
if @query.valid?
|
||||
events = []
|
||||
events += @query.issues(:include => [:tracker, :assigned_to, :priority],
|
||||
:conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
|
||||
)
|
||||
events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
|
||||
|
||||
@calendar.events = events
|
||||
end
|
||||
|
||||
render :action => 'show', :layout => 'base_projects'
|
||||
end
|
||||
end
|
|
@ -0,0 +1,53 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 CommentsController < ApplicationController
|
||||
default_search_scope :news
|
||||
model_object News
|
||||
before_filter :find_model_object
|
||||
before_filter :find_project_from_association
|
||||
before_filter :authorize
|
||||
|
||||
def create
|
||||
raise Unauthorized unless @news.commentable?
|
||||
|
||||
@comment = Comment.new
|
||||
@comment.safe_attributes = params[:comment]
|
||||
@comment.author = User.current
|
||||
if @news.comments << @comment
|
||||
flash[:notice] = l(:label_comment_added)
|
||||
end
|
||||
|
||||
redirect_to news_path(@news)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@news.comments.find(params[:comment_id]).destroy
|
||||
redirect_to news_path(@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
|
|
@ -0,0 +1,89 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 ContextMenusController < ApplicationController
|
||||
helper :watchers
|
||||
helper :issues
|
||||
|
||||
def issues
|
||||
@issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
|
||||
(render_404; return) unless @issues.present?
|
||||
if (@issues.size == 1)
|
||||
@issue = @issues.first
|
||||
end
|
||||
@issue_ids = @issues.map(&:id).sort
|
||||
|
||||
@allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
|
||||
@projects = @issues.collect(&:project).compact.uniq
|
||||
@project = @projects.first if @projects.size == 1
|
||||
|
||||
@can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
|
||||
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
|
||||
:update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
|
||||
:move => (@project && User.current.allowed_to?(:move_issues, @project)),
|
||||
:copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
|
||||
:delete => User.current.allowed_to?(:delete_issues, @projects)
|
||||
}
|
||||
if @project
|
||||
if @issue
|
||||
@assignables = @issue.assignable_users
|
||||
else
|
||||
@assignables = @project.assignable_users
|
||||
end
|
||||
@trackers = @project.trackers
|
||||
else
|
||||
#when multiple projects, we only keep the intersection of each set
|
||||
@assignables = @projects.map(&:assignable_users).reduce(:&)
|
||||
@trackers = @projects.map(&:trackers).reduce(:&)
|
||||
end
|
||||
@versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
|
||||
|
||||
@priorities = IssuePriority.active.reverse
|
||||
@back = back_url
|
||||
|
||||
@options_by_custom_field = {}
|
||||
if @can[:edit]
|
||||
custom_fields = @issues.map(&:available_custom_fields).reduce(:&).select do |f|
|
||||
%w(bool list user version).include?(f.field_format) && !f.multiple?
|
||||
end
|
||||
custom_fields.each do |field|
|
||||
values = field.possible_values_options(@projects)
|
||||
if values.any?
|
||||
@options_by_custom_field[field] = values
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def time_entries
|
||||
@time_entries = TimeEntry.all(
|
||||
:conditions => {:id => params[:ids]}, :include => :project)
|
||||
(render_404; return) unless @time_entries.present?
|
||||
|
||||
@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
|
|
@ -0,0 +1,81 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 CustomFieldsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
before_filter :build_new_custom_field, :only => [:new, :create]
|
||||
before_filter :find_custom_field, :only => [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@custom_fields_by_type = CustomField.all.group_by {|f| f.class.name }
|
||||
@tab = params[:tab] || 'IssueCustomField'
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
if @custom_field.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
|
||||
redirect_to custom_fields_path(:tab => @custom_field.class.name)
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @custom_field.update_attributes(params[:custom_field])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
|
||||
redirect_to custom_fields_path(:tab => @custom_field.class.name)
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
begin
|
||||
@custom_field.destroy
|
||||
rescue
|
||||
flash[:error] = l(:error_can_not_delete_custom_field)
|
||||
end
|
||||
redirect_to custom_fields_path(:tab => @custom_field.class.name)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_new_custom_field
|
||||
@custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
|
||||
if @custom_field.nil?
|
||||
render_404
|
||||
else
|
||||
@custom_field.default_value = nil
|
||||
end
|
||||
end
|
||||
|
||||
def find_custom_field
|
||||
@custom_field = CustomField.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,95 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class DocumentsController < ApplicationController
|
||||
layout 'base_projects'
|
||||
default_search_scope :documents
|
||||
model_object Document
|
||||
before_filter :find_project_by_project_id, :only => [:index, :new, :create]
|
||||
before_filter :find_model_object, :except => [:index, :new, :create]
|
||||
before_filter :find_project_from_association, :except => [:index, :new, :create]
|
||||
before_filter :authorize
|
||||
|
||||
helper :attachments
|
||||
|
||||
def index
|
||||
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
|
||||
documents = @project.documents.includes(:attachments, :category).all
|
||||
case @sort_by
|
||||
when 'date'
|
||||
@grouped = documents.group_by {|d| d.updated_on.to_date }
|
||||
when 'title'
|
||||
@grouped = documents.group_by {|d| d.title.first.upcase}
|
||||
when 'author'
|
||||
@grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
|
||||
else
|
||||
@grouped = documents.group_by(&:category)
|
||||
end
|
||||
@document = @project.documents.build
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def show
|
||||
@attachments = @document.attachments.all
|
||||
end
|
||||
|
||||
def new
|
||||
@document = @project.documents.build
|
||||
@document.safe_attributes = params[:document]
|
||||
end
|
||||
|
||||
def create
|
||||
@document = @project.documents.build
|
||||
@document.safe_attributes = params[:document]
|
||||
@document.save_attachments(params[:attachments])
|
||||
if @document.save
|
||||
render_attachment_warning_if_needed(@document)
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to project_documents_path(@project)
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@document.safe_attributes = params[:document]
|
||||
if request.put? and @document.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to document_path(@document)
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@document.destroy if request.delete?
|
||||
redirect_to project_documents_path(@project)
|
||||
end
|
||||
|
||||
def add_attachment
|
||||
attachments = Attachment.attach_files(@document, params[:attachments])
|
||||
render_attachment_warning_if_needed(@document)
|
||||
|
||||
if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
|
||||
Mailer.attachments_added(attachments[:files]).deliver
|
||||
end
|
||||
redirect_to document_path(@document)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,98 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 EnumerationsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin, :except => :index
|
||||
before_filter :require_admin_or_api_request, :only => :index
|
||||
before_filter :build_new_enumeration, :only => [:new, :create]
|
||||
before_filter :find_enumeration, :only => [:edit, :update, :destroy]
|
||||
accept_api_auth :index
|
||||
|
||||
helper :custom_fields
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.api {
|
||||
@klass = Enumeration.get_subclass(params[:type])
|
||||
if @klass
|
||||
@enumerations = @klass.shared.sorted.all
|
||||
else
|
||||
render_404
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
if request.post? && @enumeration.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to enumerations_path
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if request.put? && @enumeration.update_attributes(params[:enumeration])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to enumerations_path
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if !@enumeration.in_use?
|
||||
# No associated objects
|
||||
@enumeration.destroy
|
||||
redirect_to enumerations_path
|
||||
return
|
||||
elsif params[:reassign_to_id]
|
||||
if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id])
|
||||
@enumeration.destroy(reassign_to)
|
||||
redirect_to enumerations_path
|
||||
return
|
||||
end
|
||||
end
|
||||
@enumerations = @enumeration.class.all - [@enumeration]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_new_enumeration
|
||||
class_name = params[:enumeration] && params[:enumeration][:type] || params[:type]
|
||||
@enumeration = Enumeration.new_subclass_instance(class_name, params[:enumeration])
|
||||
if @enumeration.nil?
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
def find_enumeration
|
||||
@enumeration = Enumeration.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,54 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 FilesController < ApplicationController
|
||||
layout 'base_projects'
|
||||
menu_item :files
|
||||
|
||||
before_filter :find_project_by_project_id
|
||||
before_filter :authorize
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
def index
|
||||
sort_init 'filename', 'asc'
|
||||
sort_update 'filename' => "#{Attachment.table_name}.filename",
|
||||
'created_on' => "#{Attachment.table_name}.created_on",
|
||||
'size' => "#{Attachment.table_name}.filesize",
|
||||
'downloads' => "#{Attachment.table_name}.downloads"
|
||||
|
||||
@containers = [ Project.includes(:attachments).reorder(sort_clause).find(@project.id)]
|
||||
@containers += @project.versions.includes(:attachments).reorder(sort_clause).all.sort.reverse
|
||||
render :layout => !request.xhr?
|
||||
end
|
||||
|
||||
def new
|
||||
@versions = @project.versions.sort
|
||||
end
|
||||
|
||||
def create
|
||||
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
||||
attachments = Attachment.attach_files(container, params[:attachments])
|
||||
render_attachment_warning_if_needed(container)
|
||||
|
||||
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
||||
Mailer.attachments_added(attachments[:files]).deliver
|
||||
end
|
||||
redirect_to project_files_path(@project)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,48 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class GanttsController < ApplicationController
|
||||
menu_item :gantt
|
||||
before_filter :find_optional_project
|
||||
|
||||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||
|
||||
helper :gantt
|
||||
helper :issues
|
||||
helper :projects
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :sort
|
||||
include SortHelper
|
||||
include Redmine::Export::PDF
|
||||
|
||||
def show
|
||||
@gantt = Redmine::Helpers::Gantt.new(params)
|
||||
@gantt.project = @project
|
||||
retrieve_query
|
||||
@query.group_by = nil
|
||||
@gantt.query = @query if @query.valid?
|
||||
|
||||
basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :action => "show", :layout => 'base_projects' }
|
||||
format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
|
||||
format.pdf { send_data(@gantt.to_pdf, :type => 'application/pdf', :filename => "#{basename}.pdf") }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,141 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class GroupsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
before_filter :find_group, :except => [:index, :new, :create]
|
||||
accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
|
||||
|
||||
helper :custom_fields
|
||||
|
||||
def index
|
||||
@groups = Group.sorted.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@group = Group.new
|
||||
end
|
||||
|
||||
def create
|
||||
@group = Group.new
|
||||
@group.safe_attributes = params[:group]
|
||||
|
||||
respond_to do |format|
|
||||
if @group.save
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to(params[:continue] ? new_group_path : groups_path)
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => group_url(@group) }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.api { render_validation_errors(@group) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@group.safe_attributes = params[:group]
|
||||
|
||||
respond_to do |format|
|
||||
if @group.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
format.html { redirect_to(groups_path) }
|
||||
format.api { render_api_ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.api { render_validation_errors(@group) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@group.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(groups_path) }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def add_users
|
||||
@users = User.find_all_by_id(params[:user_id] || params[:user_ids])
|
||||
@group.users << @users if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to edit_group_path(@group, :tab => 'users') }
|
||||
format.js
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def remove_user
|
||||
@group.users.delete(User.find(params[:user_id])) if request.delete?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to edit_group_path(@group, :tab => 'users') }
|
||||
format.js
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def autocomplete_for_user
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def edit_membership
|
||||
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
|
||||
@membership.save if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_membership
|
||||
Member.find(params[:membership_id]).destroy if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_group
|
||||
@group = Group.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,122 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 IssueCategoriesController < ApplicationController
|
||||
menu_item :settings
|
||||
model_object IssueCategory
|
||||
before_filter :find_model_object, :except => [:index, :new, :create]
|
||||
before_filter :find_project_from_association, :except => [:index, :new, :create]
|
||||
before_filter :find_project_by_project_id, :only => [:index, :new, :create]
|
||||
before_filter :authorize
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_settings_in_projects }
|
||||
format.api { @categories = @project.issue_categories.all }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_settings_in_projects }
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@category = @project.issue_categories.build
|
||||
@category.safe_attributes = params[:issue_category]
|
||||
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_projects'}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@category = @project.issue_categories.build
|
||||
@category.safe_attributes = params[:issue_category]
|
||||
if @category.save
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to_settings_in_projects
|
||||
end
|
||||
format.js
|
||||
format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new'}
|
||||
format.js { render :action => 'new'}
|
||||
format.api { render_validation_errors(@category) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@category.safe_attributes = params[:issue_category]
|
||||
if @category.save
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to_settings_in_projects
|
||||
}
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@category) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@issue_count = @category.issues.size
|
||||
if @issue_count == 0 || params[:todo] || api_request?
|
||||
reassign_to = nil
|
||||
if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?)
|
||||
reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id])
|
||||
end
|
||||
@category.destroy(reassign_to)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_settings_in_projects }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
return
|
||||
end
|
||||
@categories = @project.issue_categories - [@category]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def redirect_to_settings_in_projects
|
||||
redirect_to settings_project_path(@project, :tab => 'categories')
|
||||
end
|
||||
|
||||
# Wrap ApplicationController's find_model_object method to set
|
||||
# @category instead of just @issue_category
|
||||
def find_model_object
|
||||
super
|
||||
@category = @object
|
||||
end
|
||||
end
|
|
@ -0,0 +1,88 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class IssueRelationsController < ApplicationController
|
||||
before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create]
|
||||
before_filter :find_relation, :except => [:index, :create]
|
||||
|
||||
accept_api_auth :index, :show, :create, :destroy
|
||||
|
||||
def index
|
||||
@relations = @issue.relations
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :nothing => true }
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
raise Unauthorized unless @relation.visible?
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :nothing => true }
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@relation = IssueRelation.new(params[:relation])
|
||||
@relation.issue_from = @issue
|
||||
if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/)
|
||||
@relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
|
||||
end
|
||||
saved = @relation.save
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to issue_path(@issue) }
|
||||
format.js {
|
||||
@relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
||||
}
|
||||
format.api {
|
||||
if saved
|
||||
render :action => 'show', :status => :created, :location => relation_url(@relation)
|
||||
else
|
||||
render_validation_errors(@relation)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise Unauthorized unless @relation.deletable?
|
||||
@relation.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to issue_path(@relation.issue_from) }
|
||||
format.js
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_issue
|
||||
@issue = @object = Issue.find(params[:issue_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_relation
|
||||
@relation = IssueRelation.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,81 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 IssueStatusesController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin, :except => :index
|
||||
before_filter :require_admin_or_api_request, :only => :index
|
||||
accept_api_auth :index
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@issue_status_pages, @issue_statuses = paginate IssueStatus.sorted, :per_page => 25
|
||||
render :action => "index", :layout => false if request.xhr?
|
||||
}
|
||||
format.api {
|
||||
@issue_statuses = IssueStatus.all(:order => 'position')
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@issue_status = IssueStatus.new
|
||||
end
|
||||
|
||||
def create
|
||||
@issue_status = IssueStatus.new(params[:issue_status])
|
||||
if request.post? && @issue_status.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to issue_statuses_path
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@issue_status = IssueStatus.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@issue_status = IssueStatus.find(params[:id])
|
||||
if request.put? && @issue_status.update_attributes(params[:issue_status])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to issue_statuses_path
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
IssueStatus.find(params[:id]).destroy
|
||||
redirect_to issue_statuses_path
|
||||
rescue
|
||||
flash[:error] = l(:error_unable_delete_issue_status)
|
||||
redirect_to issue_statuses_path
|
||||
end
|
||||
|
||||
def update_issue_done_ratio
|
||||
if request.post? && IssueStatus.update_issue_done_ratios
|
||||
flash[:notice] = l(:notice_issue_done_ratios_updated)
|
||||
else
|
||||
flash[:error] = l(:error_issue_done_ratios_not_updated)
|
||||
end
|
||||
redirect_to issue_statuses_path
|
||||
end
|
||||
end
|
|
@ -0,0 +1,443 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class IssuesController < ApplicationController
|
||||
menu_item :new_issue, :only => [:new, :create]
|
||||
default_search_scope :issues
|
||||
|
||||
before_filter :find_issue, :only => [:show, :edit, :update]
|
||||
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
|
||||
before_filter :find_project, :only => [:new, :create, :update_form]
|
||||
before_filter :authorize, :except => [:index]
|
||||
before_filter :find_optional_project, :only => [:index]
|
||||
before_filter :check_for_default_issue_status, :only => [:new, :create]
|
||||
before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
|
||||
accept_rss_auth :index, :show
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
||||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||
|
||||
helper :journals
|
||||
helper :projects
|
||||
include ProjectsHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
helper :issue_relations
|
||||
include IssueRelationsHelper
|
||||
helper :watchers
|
||||
include WatchersHelper
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :repositories
|
||||
include RepositoriesHelper
|
||||
helper :sort
|
||||
include SortHelper
|
||||
include IssuesHelper
|
||||
helper :timelog
|
||||
include Redmine::Export::PDF
|
||||
|
||||
def index
|
||||
retrieve_query
|
||||
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
|
||||
sort_update(@query.sortable_columns)
|
||||
@query.sort_criteria = sort_criteria.to_a
|
||||
|
||||
@project_base_tag = (params[:project_id] || @issue.project)?'base_projects':'base'#by young
|
||||
|
||||
if @query.valid?
|
||||
case params[:format]
|
||||
when 'csv', 'pdf'
|
||||
@limit = Setting.issues_export_limit.to_i
|
||||
when 'atom'
|
||||
@limit = Setting.feeds_limit.to_i
|
||||
when 'xml', 'json'
|
||||
@offset, @limit = api_offset_and_limit
|
||||
else
|
||||
@limit = per_page_option
|
||||
end
|
||||
|
||||
@issue_count = @query.issue_count
|
||||
@issue_pages = Paginator.new @issue_count, @limit, params['page']
|
||||
@offset ||= @issue_pages.offset
|
||||
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
||||
:order => sort_clause,
|
||||
:offset => @offset,
|
||||
:limit => @limit)
|
||||
@issue_count_by_group = @query.issue_count_by_group
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :template => 'issues/index', :layout => @project_base_tag }#by young
|
||||
format.api {
|
||||
Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
|
||||
}
|
||||
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
||||
format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
|
||||
format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render(:template => 'issues/index', :layout => @project_base_tag) }#by young
|
||||
format.any(:atom, :csv, :pdf) { render(:nothing => true) }
|
||||
format.api { render_validation_errors(@query) }
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def show
|
||||
@journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
|
||||
@journals.each_with_index {|j,i| j.indice = i+1}
|
||||
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
||||
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
|
||||
@changesets = @issue.changesets.visible.all
|
||||
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
|
||||
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||
@priorities = IssuePriority.active
|
||||
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
|
||||
|
||||
@project_base_tag = (params[:project_id] || @issue.project)?'base_projects':'base'#by young
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
retrieve_previous_and_next_issue_ids
|
||||
render :template => 'issues/show', :layout => @project_base_tag#by young
|
||||
}
|
||||
format.api
|
||||
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
|
||||
format.pdf {
|
||||
pdf = issue_to_pdf(@issue, :journals => @journals)
|
||||
send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Add a new issue
|
||||
# The new issue will be created from an existing one if copy_from parameter is given
|
||||
def new
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new', :layout => 'base_projects' }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
|
||||
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||||
if @issue.save
|
||||
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render_attachment_warning_if_needed(@issue)
|
||||
flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
|
||||
if params[:continue]
|
||||
attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
|
||||
redirect_to new_project_issue_path(@issue.project, :issue => attrs)
|
||||
else
|
||||
redirect_to issue_path(@issue)
|
||||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
|
||||
end
|
||||
return
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new' }
|
||||
format.api { render_validation_errors(@issue) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
return unless update_issue_from_params
|
||||
|
||||
respond_to do |format|
|
||||
format.html { }
|
||||
format.xml { }
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
return unless update_issue_from_params
|
||||
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||||
saved = false
|
||||
begin
|
||||
saved = @issue.save_issue_with_child_records(params, @time_entry)
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
@conflict = true
|
||||
if params[:last_journal_id]
|
||||
@conflict_journals = @issue.journals_after(params[:last_journal_id]).all
|
||||
@conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
||||
end
|
||||
end
|
||||
|
||||
if saved
|
||||
render_attachment_warning_if_needed(@issue)
|
||||
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_back_or_default issue_path(@issue) }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@issue) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Updates the issue form when changing the project, status or tracker
|
||||
# on issue creation/update
|
||||
def update_form
|
||||
end
|
||||
|
||||
# Bulk edit/copy a set of issues
|
||||
def bulk_edit
|
||||
@issues.sort!
|
||||
@copy = params[:copy].present?
|
||||
@notes = params[:notes]
|
||||
|
||||
if User.current.allowed_to?(:move_issues, @projects)
|
||||
@allowed_projects = Issue.allowed_target_projects_on_move
|
||||
if params[:issue]
|
||||
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
|
||||
if @target_project
|
||||
target_projects = [@target_project]
|
||||
end
|
||||
end
|
||||
end
|
||||
target_projects ||= @projects
|
||||
|
||||
if @copy
|
||||
@available_statuses = [IssueStatus.default]
|
||||
else
|
||||
@available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
|
||||
end
|
||||
@custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
|
||||
@assignables = target_projects.map(&:assignable_users).reduce(:&)
|
||||
@trackers = target_projects.map(&:trackers).reduce(:&)
|
||||
@versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
|
||||
@categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
|
||||
if @copy
|
||||
@attachments_present = @issues.detect {|i| i.attachments.any?}.present?
|
||||
@subtasks_present = @issues.detect {|i| !i.leaf?}.present?
|
||||
end
|
||||
|
||||
@safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
@issues.sort!
|
||||
@copy = params[:copy].present?
|
||||
attributes = parse_params_for_bulk_issue_attributes(params)
|
||||
|
||||
unsaved_issue_ids = []
|
||||
moved_issues = []
|
||||
|
||||
if @copy && params[:copy_subtasks].present?
|
||||
# Descendant issues will be copied with the parent task
|
||||
# Don't copy them twice
|
||||
@issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
|
||||
end
|
||||
|
||||
@issues.each do |issue|
|
||||
issue.reload
|
||||
if @copy
|
||||
issue = issue.copy({},
|
||||
:attachments => params[:copy_attachments].present?,
|
||||
:subtasks => params[:copy_subtasks].present?
|
||||
)
|
||||
end
|
||||
journal = issue.init_journal(User.current, params[:notes])
|
||||
issue.safe_attributes = attributes
|
||||
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
|
||||
if issue.save
|
||||
moved_issues << issue
|
||||
else
|
||||
# Keep unsaved issue ids to display them in flash error
|
||||
unsaved_issue_ids << issue.id
|
||||
end
|
||||
end
|
||||
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
|
||||
|
||||
if params[:follow]
|
||||
if @issues.size == 1 && moved_issues.size == 1
|
||||
redirect_to issue_path(moved_issues.first)
|
||||
elsif moved_issues.map(&:project).uniq.size == 1
|
||||
redirect_to project_issues_path(moved_issues.map(&:project).first)
|
||||
end
|
||||
else
|
||||
redirect_back_or_default _project_issues_path(@project)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
|
||||
if @hours > 0
|
||||
case params[:todo]
|
||||
when 'destroy'
|
||||
# nothing to do
|
||||
when 'nullify'
|
||||
TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
|
||||
when 'reassign'
|
||||
reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
|
||||
if reassign_to.nil?
|
||||
flash.now[:error] = l(:error_issue_not_found_in_project)
|
||||
return
|
||||
else
|
||||
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
|
||||
end
|
||||
else
|
||||
# display the destroy form if it's a user request
|
||||
return unless api_request?
|
||||
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
|
||||
respond_to do |format|
|
||||
format.html { redirect_back_or_default _project_issues_path(@project) }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
|
||||
@project = Project.find(project_id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def retrieve_previous_and_next_issue_ids
|
||||
retrieve_query_from_session
|
||||
if @query
|
||||
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
|
||||
sort_update(@query.sortable_columns, 'issues_index_sort')
|
||||
limit = 500
|
||||
issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
|
||||
if (idx = issue_ids.index(@issue.id)) && idx < limit
|
||||
if issue_ids.size < 500
|
||||
@issue_position = idx + 1
|
||||
@issue_count = issue_ids.size
|
||||
end
|
||||
@prev_issue_id = issue_ids[idx - 1] if idx > 0
|
||||
@next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Used by #edit and #update to set some common instance variables
|
||||
# from the params
|
||||
# TODO: Refactor, not everything in here is needed by #edit
|
||||
def update_issue_from_params
|
||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
|
||||
@issue.init_journal(User.current)
|
||||
|
||||
issue_attributes = params[:issue]
|
||||
if issue_attributes && params[:conflict_resolution]
|
||||
case params[:conflict_resolution]
|
||||
when 'overwrite'
|
||||
issue_attributes = issue_attributes.dup
|
||||
issue_attributes.delete(:lock_version)
|
||||
when 'add_notes'
|
||||
issue_attributes = issue_attributes.slice(:notes)
|
||||
when 'cancel'
|
||||
redirect_to issue_path(@issue)
|
||||
return false
|
||||
end
|
||||
end
|
||||
@issue.safe_attributes = issue_attributes
|
||||
@priorities = IssuePriority.active
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
true
|
||||
end
|
||||
|
||||
# TODO: Refactor, lots of extra code in here
|
||||
# TODO: Changing tracker on an existing issue should not trigger this
|
||||
def build_new_issue_from_params
|
||||
if params[:id].blank?
|
||||
@issue = Issue.new
|
||||
if params[:copy_from]
|
||||
begin
|
||||
@copy_from = Issue.visible.find(params[:copy_from])
|
||||
@copy_attachments = params[:copy_attachments].present? || request.get?
|
||||
@copy_subtasks = params[:copy_subtasks].present? || request.get?
|
||||
@issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
return
|
||||
end
|
||||
end
|
||||
@issue.project = @project
|
||||
else
|
||||
@issue = @project.issues.visible.find(params[:id])
|
||||
end
|
||||
|
||||
@issue.project = @project
|
||||
@issue.author ||= User.current
|
||||
# Tracker must be set before custom field values
|
||||
@issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
|
||||
if @issue.tracker.nil?
|
||||
render_error l(:error_no_tracker_in_project)
|
||||
return false
|
||||
end
|
||||
@issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
|
||||
@issue.safe_attributes = params[:issue]
|
||||
|
||||
@priorities = IssuePriority.active
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
|
||||
@available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
|
||||
end
|
||||
|
||||
def check_for_default_issue_status
|
||||
if IssueStatus.default.nil?
|
||||
render_error l(:error_no_default_issue_status)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def parse_params_for_bulk_issue_attributes(params)
|
||||
attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
|
||||
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
|
||||
if custom = attributes[:custom_field_values]
|
||||
custom.reject! {|k,v| v.blank?}
|
||||
custom.keys.each do |k|
|
||||
if custom[k].is_a?(Array)
|
||||
custom[k] << '' if custom[k].delete('__none__')
|
||||
else
|
||||
custom[k] = '' if custom[k] == '__none__'
|
||||
end
|
||||
end
|
||||
end
|
||||
attributes
|
||||
end
|
||||
end
|
|
@ -0,0 +1,105 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class JournalsController < ApplicationController
|
||||
before_filter :find_journal, :only => [:edit, :diff]
|
||||
before_filter :find_issue, :only => [:new]
|
||||
before_filter :find_optional_project, :only => [:index]
|
||||
before_filter :authorize, :only => [:new, :edit, :diff]
|
||||
accept_rss_auth :index
|
||||
menu_item :issues
|
||||
|
||||
helper :issues
|
||||
helper :custom_fields
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
def index
|
||||
retrieve_query
|
||||
sort_init 'id', 'desc'
|
||||
sort_update(@query.sortable_columns)
|
||||
|
||||
if @query.valid?
|
||||
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
|
||||
:limit => 25)
|
||||
end
|
||||
@title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
|
||||
render :layout => false, :content_type => 'application/atom+xml'
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def diff
|
||||
@issue = @journal.issue
|
||||
if params[:detail_id].present?
|
||||
@detail = @journal.details.find_by_id(params[:detail_id])
|
||||
else
|
||||
@detail = @journal.details.detect {|d| d.prop_key == 'description'}
|
||||
end
|
||||
(render_404; return false) unless @issue && @detail
|
||||
@diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
|
||||
end
|
||||
|
||||
def new
|
||||
@journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
|
||||
if @journal
|
||||
user = @journal.user
|
||||
text = @journal.notes
|
||||
else
|
||||
user = @issue.author
|
||||
text = @issue.description
|
||||
end
|
||||
# Replaces pre blocks with [...]
|
||||
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
||||
@content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
||||
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def edit
|
||||
(render_403; return false) unless @journal.editable_by?(User.current)
|
||||
if request.post?
|
||||
@journal.update_attributes(:notes => params[:notes]) if params[:notes]
|
||||
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
|
||||
call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
|
||||
respond_to do |format|
|
||||
format.html { redirect_to issue_path(@journal.journalized) }
|
||||
format.js { render :action => 'update' }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# TODO: implement non-JS journal update
|
||||
render :nothing => true
|
||||
}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_journal
|
||||
@journal = Journal.visible.find(params[:id])
|
||||
@project = @journal.journalized.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class ListController < ApplicationController
|
||||
def members
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,40 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MailHandlerController < ActionController::Base
|
||||
before_filter :check_credential
|
||||
|
||||
# Submits an incoming email to MailHandler
|
||||
def index
|
||||
options = params.dup
|
||||
email = options.delete(:email)
|
||||
if MailHandler.receive(email, options)
|
||||
render :nothing => true, :status => :created
|
||||
else
|
||||
render :nothing => true, :status => :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_credential
|
||||
User.current = nil
|
||||
unless Setting.mail_handler_api_enabled? && params[:key].to_s == Setting.mail_handler_api_key
|
||||
render :text => 'Access denied. Incoming emails WS is disabled or key is invalid.', :status => 403
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,125 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MembersController < ApplicationController
|
||||
model_object Member
|
||||
before_filter :find_model_object, :except => [:index, :create, :autocomplete]
|
||||
before_filter :find_project_from_association, :except => [:index, :create, :autocomplete]
|
||||
before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete]
|
||||
before_filter :authorize
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
||||
def index
|
||||
@offset, @limit = api_offset_and_limit
|
||||
@member_count = @project.member_principals.count
|
||||
@member_pages = Paginator.new @member_count, @limit, params['page']
|
||||
@offset ||= @member_pages.offset
|
||||
@members = @project.member_principals.all(
|
||||
:order => "#{Member.table_name}.id",
|
||||
:limit => @limit,
|
||||
:offset => @offset
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { head 406 }
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html { head 406 }
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
members = []
|
||||
if params[:membership]
|
||||
if params[:membership][:user_ids]
|
||||
attrs = params[:membership].dup
|
||||
user_ids = attrs.delete(:user_ids)
|
||||
user_ids.each do |user_id|
|
||||
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
|
||||
end
|
||||
else
|
||||
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
|
||||
end
|
||||
@project.members << members
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_settings_in_projects }
|
||||
format.js { @members = members }
|
||||
format.api {
|
||||
@member = members.first
|
||||
if @member.valid?
|
||||
render :action => 'show', :status => :created, :location => membership_url(@member)
|
||||
else
|
||||
render_validation_errors(@member)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:membership]
|
||||
@member.role_ids = params[:membership][:role_ids]
|
||||
end
|
||||
saved = @member.save
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_settings_in_projects }
|
||||
format.js
|
||||
format.api {
|
||||
if saved
|
||||
render_api_ok
|
||||
else
|
||||
render_validation_errors(@member)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if request.delete? && @member.deletable?
|
||||
@member.destroy
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_settings_in_projects }
|
||||
format.js
|
||||
format.api {
|
||||
if @member.destroyed?
|
||||
render_api_ok
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def autocomplete
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def redirect_to_settings_in_projects
|
||||
redirect_to settings_project_path(@project, :tab => 'members')
|
||||
end
|
||||
end
|
|
@ -0,0 +1,142 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MessagesController < ApplicationController
|
||||
menu_item :boards
|
||||
default_search_scope :messages
|
||||
before_filter :find_board, :only => [:new, :preview]
|
||||
before_filter :find_attachments, :only => [:preview]
|
||||
before_filter :find_message, :except => [:new, :preview]
|
||||
before_filter :authorize, :except => [:preview, :edit, :destroy]
|
||||
|
||||
helper :boards
|
||||
helper :watchers
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
|
||||
REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
|
||||
|
||||
# Show a topic and its replies
|
||||
def show
|
||||
page = params[:page]
|
||||
# Find the page of the requested reply
|
||||
if params[:r] && page.nil?
|
||||
offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
|
||||
page = 1 + offset / REPLIES_PER_PAGE
|
||||
end
|
||||
|
||||
@reply_count = @topic.children.count
|
||||
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
|
||||
@replies = @topic.children.
|
||||
includes(:author, :attachments, {:board => :project}).
|
||||
reorder("#{Message.table_name}.created_on ASC").
|
||||
limit(@reply_pages.per_page).
|
||||
offset(@reply_pages.offset).
|
||||
all
|
||||
|
||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||
render :action => "show", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
# Create a new topic
|
||||
def new
|
||||
@message = Message.new
|
||||
@message.author = User.current
|
||||
@message.board = @board
|
||||
@message.safe_attributes = params[:message]
|
||||
if request.post?
|
||||
@message.save_attachments(params[:attachments])
|
||||
if @message.save
|
||||
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
|
||||
render_attachment_warning_if_needed(@message)
|
||||
redirect_to board_message_path(@board, @message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Reply to a topic
|
||||
def reply
|
||||
@reply = Message.new
|
||||
@reply.author = User.current
|
||||
@reply.board = @board
|
||||
@reply.safe_attributes = params[:reply]
|
||||
@topic.children << @reply
|
||||
if !@reply.new_record?
|
||||
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
|
||||
attachments = Attachment.attach_files(@reply, params[:attachments])
|
||||
render_attachment_warning_if_needed(@reply)
|
||||
end
|
||||
redirect_to board_message_path(@board, @topic, :r => @reply)
|
||||
end
|
||||
|
||||
# Edit a message
|
||||
def edit
|
||||
(render_403; return false) unless @message.editable_by?(User.current)
|
||||
@message.safe_attributes = params[:message]
|
||||
if request.post? && @message.save
|
||||
attachments = Attachment.attach_files(@message, params[:attachments])
|
||||
render_attachment_warning_if_needed(@message)
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
@message.reload
|
||||
redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id))
|
||||
end
|
||||
end
|
||||
|
||||
# Delete a messages
|
||||
def destroy
|
||||
(render_403; return false) unless @message.destroyable_by?(User.current)
|
||||
r = @message.to_param
|
||||
@message.destroy
|
||||
if @message.parent
|
||||
redirect_to board_message_path(@board, @message.parent, :r => r)
|
||||
else
|
||||
redirect_to project_board_path(@project, @board)
|
||||
end
|
||||
end
|
||||
|
||||
def quote
|
||||
@subject = @message.subject
|
||||
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
|
||||
@content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> "
|
||||
@content << @message.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||||
end
|
||||
|
||||
def preview
|
||||
message = @board.messages.find_by_id(params[:id])
|
||||
@text = (params[:message] || params[:reply])[:content]
|
||||
@previewed = message
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
private
|
||||
def find_message
|
||||
return unless find_board
|
||||
@message = @board.messages.find(params[:id], :include => :parent)
|
||||
@topic = @message.root
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_board
|
||||
@board = Board.find(params[:board_id], :include => :project)
|
||||
@project = @board.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
nil
|
||||
end
|
||||
end
|
|
@ -0,0 +1,198 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MyController < ApplicationController
|
||||
before_filter :require_login
|
||||
|
||||
helper :issues
|
||||
helper :users
|
||||
helper :custom_fields
|
||||
|
||||
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
||||
'issuesreportedbyme' => :label_reported_issues,
|
||||
'issueswatched' => :label_watched_issues,
|
||||
'news' => :label_news_latest,
|
||||
'calendar' => :label_calendar,
|
||||
'documents' => :label_document_plural,
|
||||
'timelog' => :label_spent_time
|
||||
}.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
|
||||
|
||||
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
|
||||
'right' => ['issuesreportedbyme']
|
||||
}.freeze
|
||||
|
||||
def index
|
||||
page
|
||||
render :action => 'page'
|
||||
end
|
||||
|
||||
# Show user's page
|
||||
def page
|
||||
@user = User.current
|
||||
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
|
||||
end
|
||||
|
||||
# Edit user's account
|
||||
def account
|
||||
@user = User.current
|
||||
@pref = @user.pref
|
||||
if request.post?
|
||||
@user.safe_attributes = params[:user]
|
||||
@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] : [])
|
||||
set_language_if_valid @user.language
|
||||
flash[:notice] = l(:notice_account_updated)
|
||||
redirect_to my_account_path
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Destroys user's account
|
||||
def destroy
|
||||
@user = User.current
|
||||
unless @user.own_account_deletable?
|
||||
redirect_to my_account_path
|
||||
return
|
||||
end
|
||||
|
||||
if request.post? && params[:confirm]
|
||||
@user.destroy
|
||||
if @user.destroyed?
|
||||
logout_user
|
||||
flash[:notice] = l(:notice_account_deleted)
|
||||
end
|
||||
redirect_to home_path
|
||||
end
|
||||
end
|
||||
|
||||
# Manage user's password
|
||||
def password
|
||||
@user = User.current
|
||||
unless @user.change_password_allowed?
|
||||
flash[:error] = l(:notice_can_t_change_password)
|
||||
redirect_to my_account_path
|
||||
return
|
||||
end
|
||||
if request.post?
|
||||
if @user.check_password?(params[:password])
|
||||
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||
if @user.save
|
||||
flash[:notice] = l(:notice_account_password_updated)
|
||||
redirect_to my_account_path
|
||||
end
|
||||
else
|
||||
flash[:error] = l(:notice_account_wrong_password)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Create a new feeds key
|
||||
def reset_rss_key
|
||||
if request.post?
|
||||
if User.current.rss_token
|
||||
User.current.rss_token.destroy
|
||||
User.current.reload
|
||||
end
|
||||
User.current.rss_key
|
||||
flash[:notice] = l(:notice_feeds_access_key_reseted)
|
||||
end
|
||||
redirect_to my_account_path
|
||||
end
|
||||
|
||||
# Create a new API key
|
||||
def reset_api_key
|
||||
if request.post?
|
||||
if User.current.api_token
|
||||
User.current.api_token.destroy
|
||||
User.current.reload
|
||||
end
|
||||
User.current.api_key
|
||||
flash[:notice] = l(:notice_api_access_key_reseted)
|
||||
end
|
||||
redirect_to my_account_path
|
||||
end
|
||||
|
||||
# User's page layout configuration
|
||||
def page_layout
|
||||
@user = User.current
|
||||
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
||||
@block_options = []
|
||||
BLOCKS.each do |k, v|
|
||||
unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)}
|
||||
@block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Add a block to user's page
|
||||
# The block is added on top of the page
|
||||
# params[:block] : id of the block to add
|
||||
def add_block
|
||||
block = params[:block].to_s.underscore
|
||||
if block.present? && BLOCKS.key?(block)
|
||||
@user = User.current
|
||||
layout = @user.pref[:my_page_layout] || {}
|
||||
# remove if already present in a group
|
||||
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||
# add it on top
|
||||
layout['top'].unshift block
|
||||
@user.pref[:my_page_layout] = layout
|
||||
@user.pref.save
|
||||
end
|
||||
redirect_to my_page_layout_path
|
||||
end
|
||||
|
||||
# Remove a block to user's page
|
||||
# params[:block] : id of the block to remove
|
||||
def remove_block
|
||||
block = params[:block].to_s.underscore
|
||||
@user = User.current
|
||||
# remove block in all groups
|
||||
layout = @user.pref[:my_page_layout] || {}
|
||||
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||
@user.pref[:my_page_layout] = layout
|
||||
@user.pref.save
|
||||
redirect_to my_page_layout_path
|
||||
end
|
||||
|
||||
# Change blocks order on user's page
|
||||
# params[:group] : group to order (top, left or right)
|
||||
# params[:list-(top|left|right)] : array of block ids of the group
|
||||
def order_blocks
|
||||
group = params[:group]
|
||||
@user = User.current
|
||||
if group.is_a?(String)
|
||||
group_items = (params["blocks"] || []).collect(&:underscore)
|
||||
group_items.each {|s| s.sub!(/^block_/, '')}
|
||||
if group_items and group_items.is_a? Array
|
||||
layout = @user.pref[:my_page_layout] || {}
|
||||
# remove group blocks if they are presents in other groups
|
||||
%w(top left right).each {|f|
|
||||
layout[f] = (layout[f] || []) - group_items
|
||||
}
|
||||
layout[group] = group_items
|
||||
@user.pref[:my_page_layout] = layout
|
||||
@user.pref.save
|
||||
end
|
||||
end
|
||||
render :nothing => true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,112 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class NewsController < ApplicationController
|
||||
layout 'base_projects'
|
||||
default_search_scope :news
|
||||
model_object News
|
||||
before_filter :find_model_object, :except => [:new, :create, :index]
|
||||
before_filter :find_project_from_association, :except => [:new, :create, :index]
|
||||
before_filter :find_project_by_project_id, :only => [:new, :create]
|
||||
before_filter :authorize, :except => [:index]
|
||||
before_filter :find_optional_project, :only => :index
|
||||
accept_rss_auth :index
|
||||
accept_api_auth :index
|
||||
|
||||
helper :watchers
|
||||
helper :attachments
|
||||
|
||||
def index
|
||||
case params[:format]
|
||||
when 'xml', 'json'
|
||||
@offset, @limit = api_offset_and_limit
|
||||
else
|
||||
@limit = 10
|
||||
end
|
||||
|
||||
scope = @project ? @project.news.visible : News.visible
|
||||
|
||||
@news_count = scope.count
|
||||
@news_pages = Paginator.new @news_count, @limit, params['page']
|
||||
@offset ||= @news_pages.offset
|
||||
@newss = scope.all(:include => [:author, :project],
|
||||
:order => "#{News.table_name}.created_on DESC",
|
||||
:offset => @offset,
|
||||
:limit => @limit)
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@news = News.new # for adding news inline
|
||||
render :layout => false if request.xhr?
|
||||
}
|
||||
format.api
|
||||
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@comments = @news.comments
|
||||
@comments.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
end
|
||||
|
||||
def new
|
||||
@news = News.new(:project => @project, :author => User.current)
|
||||
end
|
||||
|
||||
def create
|
||||
@news = News.new(:project => @project, :author => User.current)
|
||||
@news.safe_attributes = params[:news]
|
||||
@news.save_attachments(params[:attachments])
|
||||
if @news.save
|
||||
render_attachment_warning_if_needed(@news)
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to project_news_index_path(@project)
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@news.safe_attributes = params[:news]
|
||||
@news.save_attachments(params[:attachments])
|
||||
if @news.save
|
||||
render_attachment_warning_if_needed(@news)
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to news_path(@news)
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@news.destroy
|
||||
redirect_to project_news_index_path(@project)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_optional_project
|
||||
return true unless params[:project_id]
|
||||
@project = Project.find(params[:project_id])
|
||||
authorize
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,53 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class PreviewsController < ApplicationController
|
||||
before_filter :find_project, :find_attachments
|
||||
|
||||
def issue
|
||||
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
||||
if @issue
|
||||
@description = params[:issue] && params[:issue][:description]
|
||||
if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
|
||||
@description = nil
|
||||
end
|
||||
# params[:notes] is useful for preview of notes in issue history
|
||||
@notes = params[:notes] || (params[:issue] ? params[:issue][:notes] : nil)
|
||||
else
|
||||
@description = (params[:issue] ? params[:issue][:description] : nil)
|
||||
end
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def news
|
||||
if params[:id].present? && news = News.visible.find_by_id(params[:id])
|
||||
@previewed = news
|
||||
end
|
||||
@text = (params[:news] ? params[:news][:description] : nil)
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
|
||||
@project = Project.find(project_id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 ProjectEnumerationsController < ApplicationController
|
||||
before_filter :find_project_by_project_id
|
||||
before_filter :authorize
|
||||
|
||||
def update
|
||||
if request.put? && params[:enumerations]
|
||||
Project.transaction do
|
||||
params[:enumerations].each do |id, activity|
|
||||
@project.update_or_create_time_entry_activity(id, activity)
|
||||
end
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
end
|
||||
|
||||
redirect_to settings_project_path(@project, :tab => 'activities')
|
||||
end
|
||||
|
||||
def destroy
|
||||
@project.time_entry_activities.each do |time_entry_activity|
|
||||
time_entry_activity.destroy(time_entry_activity.parent)
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to settings_project_path(@project, :tab => 'activities')
|
||||
end
|
||||
end
|
|
@ -0,0 +1,365 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class ProjectsController < ApplicationController
|
||||
layout 'base_projects'
|
||||
menu_item :overview
|
||||
menu_item :roadmap, :only => :roadmap
|
||||
# menu_item :settings, :only => :settings
|
||||
|
||||
before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ]
|
||||
before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :investor, :issue, :mission, :on, :file]
|
||||
before_filter :authorize_global, :only => [:new, :create]
|
||||
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
|
||||
#by young
|
||||
before_filter :member, :focus, :mission, :issue, :on, :file, :investor
|
||||
#
|
||||
accept_rss_auth :index
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
||||
after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
|
||||
if controller.request.post?
|
||||
controller.send :expire_action, :controller => 'welcome', :action => 'robots'
|
||||
end
|
||||
end
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
helper :issues
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
helper :repositories
|
||||
include RepositoriesHelper
|
||||
include ProjectsHelper
|
||||
helper :members
|
||||
helper :activities
|
||||
helper :documents
|
||||
helper :watchers
|
||||
|
||||
|
||||
# Lists visible projects
|
||||
# def index
|
||||
# respond_to do |format|
|
||||
# format.html {
|
||||
# scope = Project
|
||||
# unless params[:closed]
|
||||
# scope = scope.active
|
||||
# end
|
||||
# @projects = scope.visible.order('lft').all
|
||||
# }
|
||||
# format.api {
|
||||
# @offset, @limit = api_offset_and_limit
|
||||
# @project_count = Project.visible.count
|
||||
# @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all
|
||||
# }
|
||||
# format.atom {
|
||||
# projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
||||
# render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
|
||||
# }
|
||||
# end
|
||||
# end
|
||||
|
||||
def index
|
||||
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||
@project_count = Project.visible.count
|
||||
@project_pages = Paginator.new @project_count, @limit, params['page']
|
||||
@offset ||= @project_pages.offset
|
||||
@projects = Project.visible.offset(@offset).limit(@limit).order('lft').all
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => 'base'
|
||||
scope = Project
|
||||
unless params[:closed]
|
||||
scope = scope.active
|
||||
end
|
||||
@projects = scope.visible.offset(@offset).limit(@limit).order('lft').all
|
||||
}
|
||||
format.api {
|
||||
# @offset, @limit = api_offset_and_limit
|
||||
# @project_count = Project.visible.count
|
||||
# @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all
|
||||
}
|
||||
format.atom {
|
||||
projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
||||
render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@issue_custom_fields = IssueCustomField.sorted.all
|
||||
@trackers = Tracker.sorted.all
|
||||
@project = Project.new
|
||||
@project.safe_attributes = params[:project]
|
||||
end
|
||||
|
||||
def create
|
||||
@issue_custom_fields = IssueCustomField.sorted.all
|
||||
@trackers = Tracker.sorted.all
|
||||
@project = Project.new
|
||||
@project.safe_attributes = params[:project]
|
||||
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
# Add current user as a project member if he is not admin
|
||||
unless User.current.admin?
|
||||
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||
m = Member.new(:user => User.current, :roles => [r])
|
||||
@project.members << m
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
if params[:continue]
|
||||
attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}
|
||||
redirect_to new_project_path(attrs)
|
||||
else
|
||||
redirect_to settings_project_path(@project)
|
||||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new' }
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def copy
|
||||
@issue_custom_fields = IssueCustomField.sorted.all
|
||||
@trackers = Tracker.sorted.all
|
||||
@source_project = Project.find(params[:id])
|
||||
if request.get?
|
||||
@project = Project.copy_from(@source_project)
|
||||
@project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
|
||||
else
|
||||
Mailer.with_deliveries(params[:notifications] == '1') do
|
||||
@project = Project.new
|
||||
@project.safe_attributes = params[:project]
|
||||
if validate_parent_id && @project.copy(@source_project, :only => params[:only])
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to settings_project_path(@project)
|
||||
elsif !@project.new_record?
|
||||
# Project was created
|
||||
# But some objects were not copied due to validation failures
|
||||
# (eg. issues from disabled trackers)
|
||||
# TODO: inform about that
|
||||
redirect_to settings_project_path(@project)
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# source_project not found
|
||||
render_404
|
||||
end
|
||||
|
||||
# Show @project
|
||||
def show
|
||||
# try to redirect to the requested menu item
|
||||
if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
|
||||
return
|
||||
end
|
||||
|
||||
@users_by_role = @project.users_by_role
|
||||
@subprojects = @project.children.visible.all
|
||||
@news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").all
|
||||
@trackers = @project.rolled_up_trackers
|
||||
|
||||
cond = @project.project_condition(Setting.display_subprojects_issues?)
|
||||
|
||||
@open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker)
|
||||
@total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker)
|
||||
|
||||
if User.current.allowed_to?(:view_time_entries, @project)
|
||||
@total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
|
||||
end
|
||||
|
||||
@key = User.current.rss_key
|
||||
#新增内容
|
||||
@days = Setting.activity_days_default.to_i
|
||||
|
||||
if params[:from]
|
||||
begin; @date_to = params[:from].to_date + 1; rescue; end
|
||||
end
|
||||
|
||||
has = {
|
||||
"show_issues" => true
|
||||
}
|
||||
@date_to ||= Date.today + 1
|
||||
@date_from = @date_to - @days
|
||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
|
||||
# 决定显示所用用户或单个用户活动
|
||||
@activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
|
||||
:with_subprojects => @with_subprojects,
|
||||
:author => @author)
|
||||
@activity.scope_select {|t| !has["show_#{t}"].nil?}
|
||||
# @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
|
||||
|
||||
events = @activity.events(@date_from, @date_to, {:limit=>15})
|
||||
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
|
||||
# documents
|
||||
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
|
||||
documents = @project.documents.includes(:attachments, :category).all
|
||||
case @sort_by
|
||||
when 'date'
|
||||
@grouped = documents.group_by {|d| d.updated_on.to_date }
|
||||
when 'title'
|
||||
@grouped = documents.group_by {|d| d.title.first.upcase}
|
||||
when 'author'
|
||||
@grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
|
||||
else
|
||||
@grouped = documents.group_by(&:category)
|
||||
end
|
||||
@document = @project.documents.build
|
||||
#
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def settings
|
||||
@issue_custom_fields = IssueCustomField.sorted.all
|
||||
@issue_category ||= IssueCategory.new
|
||||
@member ||= @project.members.new
|
||||
@trackers = Tracker.sorted.all
|
||||
@wiki ||= @project.wiki
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
#by young
|
||||
def member
|
||||
session[:project_member_num] = 12
|
||||
end
|
||||
|
||||
def focus
|
||||
session[:project_focus_num] = 2508
|
||||
end
|
||||
|
||||
def investor
|
||||
session[:project_investor_num] = 8
|
||||
end
|
||||
|
||||
def issue
|
||||
session[:project_issue_num] = 1
|
||||
end
|
||||
|
||||
def mission
|
||||
session[:project_mission_num] = 225
|
||||
end
|
||||
|
||||
def on
|
||||
session[:project_on_num] = 1208
|
||||
end
|
||||
|
||||
def file
|
||||
session[:project_file_num] = 125
|
||||
end
|
||||
#end
|
||||
|
||||
def update
|
||||
@project.safe_attributes = params[:project]
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to settings_project_path(@project)
|
||||
}
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
settings
|
||||
render :action => 'settings'
|
||||
}
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def modules
|
||||
@project.enabled_module_names = params[:enabled_module_names]
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to settings_project_path(@project, :tab => 'modules')
|
||||
end
|
||||
|
||||
def archive
|
||||
if request.post?
|
||||
unless @project.archive
|
||||
flash[:error] = l(:error_can_not_archive_project)
|
||||
end
|
||||
end
|
||||
redirect_to admin_projects_path(:status => params[:status])
|
||||
end
|
||||
|
||||
def unarchive
|
||||
@project.unarchive if request.post? && !@project.active?
|
||||
redirect_to admin_projects_path(:status => params[:status])
|
||||
end
|
||||
|
||||
def close
|
||||
@project.close
|
||||
redirect_to project_path(@project)
|
||||
end
|
||||
|
||||
def reopen
|
||||
@project.reopen
|
||||
redirect_to project_path(@project)
|
||||
end
|
||||
|
||||
# Delete @project
|
||||
def destroy
|
||||
@project_to_destroy = @project
|
||||
if api_request? || params[:confirm]
|
||||
@project_to_destroy.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to admin_projects_path }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
# hide project in layout
|
||||
@project = nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Validates parent_id param according to user's permissions
|
||||
# TODO: move it to Project model in a validation that depends on User.current
|
||||
def validate_parent_id
|
||||
return true if User.current.admin?
|
||||
parent_id = params[:project] && params[:project][:parent_id]
|
||||
if parent_id || @project.new_record?
|
||||
parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
|
||||
unless @project.allowed_parents.include?(parent)
|
||||
@project.errors.add :parent_id, :invalid
|
||||
return false
|
||||
end
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,106 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class QueriesController < ApplicationController
|
||||
menu_item :issues
|
||||
before_filter :find_query, :except => [:new, :create, :index]
|
||||
before_filter :find_optional_project, :only => [:new, :create]
|
||||
|
||||
accept_api_auth :index
|
||||
|
||||
include QueriesHelper
|
||||
|
||||
def index
|
||||
case params[:format]
|
||||
when 'xml', 'json'
|
||||
@offset, @limit = api_offset_and_limit
|
||||
else
|
||||
@limit = per_page_option
|
||||
end
|
||||
|
||||
@query_count = IssueQuery.visible.count
|
||||
@query_pages = Paginator.new @query_count, @limit, params['page']
|
||||
@queries = IssueQuery.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name")
|
||||
|
||||
respond_to do |format|
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@query = IssueQuery.new
|
||||
@query.user = User.current
|
||||
@query.project = @project
|
||||
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
||||
@query.build_from_params(params)
|
||||
end
|
||||
|
||||
def create
|
||||
@query = IssueQuery.new(params[:query])
|
||||
@query.user = User.current
|
||||
@query.project = params[:query_is_for_all] ? nil : @project
|
||||
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
||||
@query.build_from_params(params)
|
||||
@query.column_names = nil if params[:default_columns]
|
||||
|
||||
if @query.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to _project_issues_path(@project, :query_id => @query)
|
||||
else
|
||||
render :action => 'new', :layout => !request.xhr?
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@query.attributes = params[:query]
|
||||
@query.project = nil if params[:query_is_for_all]
|
||||
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
|
||||
@query.build_from_params(params)
|
||||
@query.column_names = nil if params[:default_columns]
|
||||
|
||||
if @query.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to _project_issues_path(@project, :query_id => @query)
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@query.destroy
|
||||
redirect_to _project_issues_path(@project, :set_filter => 1)
|
||||
end
|
||||
|
||||
private
|
||||
def find_query
|
||||
@query = IssueQuery.find(params[:id])
|
||||
@project = @query.project
|
||||
render_403 unless @query.editable_by?(User.current)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_optional_project
|
||||
@project = Project.find(params[:project_id]) if params[:project_id]
|
||||
render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,95 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class ReportsController < ApplicationController
|
||||
menu_item :issues
|
||||
before_filter :find_project, :authorize, :find_issue_statuses
|
||||
|
||||
def issue_report
|
||||
@trackers = @project.trackers
|
||||
@versions = @project.shared_versions.sort
|
||||
@priorities = IssuePriority.all.reverse
|
||||
@categories = @project.issue_categories
|
||||
@assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort
|
||||
@authors = @project.users.sort
|
||||
@subprojects = @project.descendants.visible
|
||||
|
||||
@issues_by_tracker = Issue.by_tracker(@project)
|
||||
@issues_by_version = Issue.by_version(@project)
|
||||
@issues_by_priority = Issue.by_priority(@project)
|
||||
@issues_by_category = Issue.by_category(@project)
|
||||
@issues_by_assigned_to = Issue.by_assigned_to(@project)
|
||||
@issues_by_author = Issue.by_author(@project)
|
||||
@issues_by_subproject = Issue.by_subproject(@project) || []
|
||||
|
||||
render :template => "reports/issue_report"
|
||||
end
|
||||
|
||||
def issue_report_details
|
||||
case params[:detail]
|
||||
when "tracker"
|
||||
@field = "tracker_id"
|
||||
@rows = @project.trackers
|
||||
@data = Issue.by_tracker(@project)
|
||||
@report_title = l(:field_tracker)
|
||||
when "version"
|
||||
@field = "fixed_version_id"
|
||||
@rows = @project.shared_versions.sort
|
||||
@data = Issue.by_version(@project)
|
||||
@report_title = l(:field_version)
|
||||
when "priority"
|
||||
@field = "priority_id"
|
||||
@rows = IssuePriority.all.reverse
|
||||
@data = Issue.by_priority(@project)
|
||||
@report_title = l(:field_priority)
|
||||
when "category"
|
||||
@field = "category_id"
|
||||
@rows = @project.issue_categories
|
||||
@data = Issue.by_category(@project)
|
||||
@report_title = l(:field_category)
|
||||
when "assigned_to"
|
||||
@field = "assigned_to_id"
|
||||
@rows = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort
|
||||
@data = Issue.by_assigned_to(@project)
|
||||
@report_title = l(:field_assigned_to)
|
||||
when "author"
|
||||
@field = "author_id"
|
||||
@rows = @project.users.sort
|
||||
@data = Issue.by_author(@project)
|
||||
@report_title = l(:field_author)
|
||||
when "subproject"
|
||||
@field = "project_id"
|
||||
@rows = @project.descendants.visible
|
||||
@data = Issue.by_subproject(@project) || []
|
||||
@report_title = l(:field_subproject)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
if @field
|
||||
format.html {}
|
||||
else
|
||||
format.html { redirect_to :action => 'issue_report', :id => @project }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_issue_statuses
|
||||
@statuses = IssueStatus.sorted.all
|
||||
end
|
||||
end
|
|
@ -0,0 +1,435 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'SVG/Graph/Bar'
|
||||
require 'SVG/Graph/BarHorizontal'
|
||||
require 'digest/sha1'
|
||||
require 'redmine/scm/adapters/abstract_adapter'
|
||||
|
||||
class ChangesetNotFound < Exception; end
|
||||
class InvalidRevisionParam < Exception; end
|
||||
|
||||
class RepositoriesController < ApplicationController
|
||||
layout 'base_projects'
|
||||
menu_item :repository
|
||||
menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers]
|
||||
default_search_scope :changesets
|
||||
|
||||
before_filter :find_project_by_project_id, :only => [:new, :create]
|
||||
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
|
||||
before_filter :find_project_repository, :except => [:new, :create, :edit, :update, :destroy, :committers]
|
||||
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
|
||||
before_filter :authorize
|
||||
accept_rss_auth :revisions
|
||||
|
||||
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
|
||||
|
||||
def new
|
||||
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
|
||||
@repository = Repository.factory(scm)
|
||||
@repository.is_default = @project.repository.nil?
|
||||
@repository.project = @project
|
||||
end
|
||||
|
||||
def create
|
||||
attrs = pickup_extra_info
|
||||
@repository = Repository.factory(params[:repository_scm])
|
||||
@repository.safe_attributes = params[:repository]
|
||||
if attrs[:attrs_extra].keys.any?
|
||||
@repository.merge_extra_info(attrs[:attrs_extra])
|
||||
end
|
||||
@repository.project = @project
|
||||
if request.post? && @repository.save
|
||||
redirect_to settings_project_path(@project, :tab => 'repositories')
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
attrs = pickup_extra_info
|
||||
@repository.safe_attributes = attrs[:attrs]
|
||||
if attrs[:attrs_extra].keys.any?
|
||||
@repository.merge_extra_info(attrs[:attrs_extra])
|
||||
end
|
||||
@repository.project = @project
|
||||
if request.put? && @repository.save
|
||||
redirect_to settings_project_path(@project, :tab => 'repositories')
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def pickup_extra_info
|
||||
p = {}
|
||||
p_extra = {}
|
||||
params[:repository].each do |k, v|
|
||||
if k =~ /^extra_/
|
||||
p_extra[k] = v
|
||||
else
|
||||
p[k] = v
|
||||
end
|
||||
end
|
||||
{:attrs => p, :attrs_extra => p_extra}
|
||||
end
|
||||
private :pickup_extra_info
|
||||
|
||||
def committers
|
||||
@committers = @repository.committers
|
||||
@users = @project.users
|
||||
additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
|
||||
@users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
|
||||
@users.compact!
|
||||
@users.sort!
|
||||
if request.post? && params[:committers].is_a?(Hash)
|
||||
# Build a hash with repository usernames as keys and corresponding user ids as values
|
||||
@repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to settings_project_path(@project, :tab => 'repositories')
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@repository.destroy if request.delete?
|
||||
redirect_to settings_project_path(@project, :tab => 'repositories')
|
||||
end
|
||||
|
||||
def show
|
||||
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
||||
|
||||
@entries = @repository.entries(@path, @rev)
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
if request.xhr?
|
||||
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
||||
else
|
||||
(show_error_not_found; return) unless @entries
|
||||
@changesets = @repository.latest_changesets(@path, @rev)
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
@repositories = @project.repositories
|
||||
render :action => 'show'
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :browse, :show
|
||||
|
||||
def changes
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
(show_error_not_found; return) unless @entry
|
||||
@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
end
|
||||
|
||||
def revisions
|
||||
@changeset_count = @repository.changesets.count
|
||||
@changeset_pages = Paginator.new @changeset_count,
|
||||
per_page_option,
|
||||
params['page']
|
||||
@changesets = @repository.changesets.
|
||||
limit(@changeset_pages.per_page).
|
||||
offset(@changeset_pages.offset).
|
||||
includes(:user, :repository, :parents).
|
||||
all
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :layout => false if request.xhr? }
|
||||
format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
|
||||
end
|
||||
end
|
||||
|
||||
def raw
|
||||
entry_and_raw(true)
|
||||
end
|
||||
|
||||
def entry
|
||||
entry_and_raw(false)
|
||||
end
|
||||
|
||||
def entry_and_raw(is_raw)
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
(show_error_not_found; return) unless @entry
|
||||
|
||||
# If the entry is a dir, show the browser
|
||||
(show; return) if @entry.is_dir?
|
||||
|
||||
@content = @repository.cat(@path, @rev)
|
||||
(show_error_not_found; return) unless @content
|
||||
if is_raw ||
|
||||
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
|
||||
! is_entry_text_data?(@content, @path)
|
||||
# Force the download
|
||||
send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
|
||||
send_type = Redmine::MimeType.of(@path)
|
||||
send_opt[:type] = send_type.to_s if send_type
|
||||
send_opt[:disposition] = (Redmine::MimeType.is_type?('image', @path) && !is_raw ? 'inline' : 'attachment')
|
||||
send_data @content, send_opt
|
||||
else
|
||||
# Prevent empty lines when displaying a file with Windows style eol
|
||||
# TODO: UTF-16
|
||||
# Is this needs? AttachmentsController reads file simply.
|
||||
@content.gsub!("\r\n", "\n")
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
end
|
||||
end
|
||||
private :entry_and_raw
|
||||
|
||||
def is_entry_text_data?(ent, path)
|
||||
# UTF-16 contains "\x00".
|
||||
# It is very strict that file contains less than 30% of ascii symbols
|
||||
# in non Western Europe.
|
||||
return true if Redmine::MimeType.is_type?('text', path)
|
||||
# Ruby 1.8.6 has a bug of integer divisions.
|
||||
# http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
|
||||
return false if ent.is_binary_data?
|
||||
true
|
||||
end
|
||||
private :is_entry_text_data?
|
||||
|
||||
def annotate
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
(show_error_not_found; return) unless @entry
|
||||
|
||||
@annotate = @repository.scm.annotate(@path, @rev)
|
||||
if @annotate.nil? || @annotate.empty?
|
||||
(render_error l(:error_scm_annotate); return)
|
||||
end
|
||||
ann_buf_size = 0
|
||||
@annotate.lines.each do |buf|
|
||||
ann_buf_size += buf.size
|
||||
end
|
||||
if ann_buf_size > Setting.file_max_size_displayed.to_i.kilobyte
|
||||
(render_error l(:error_scm_annotate_big_text_file); return)
|
||||
end
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
end
|
||||
|
||||
def revision
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js {render :layout => false}
|
||||
end
|
||||
end
|
||||
|
||||
# Adds a related issue to a changeset
|
||||
# POST /projects/:project_id/repository/(:repository_id/)revisions/:rev/issues
|
||||
def add_related_issue
|
||||
@issue = @changeset.find_referenced_issue_by_id(params[:issue_id])
|
||||
if @issue && (!@issue.visible? || @changeset.issues.include?(@issue))
|
||||
@issue = nil
|
||||
end
|
||||
|
||||
if @issue
|
||||
@changeset.issues << @issue
|
||||
end
|
||||
end
|
||||
|
||||
# Removes a related issue from a changeset
|
||||
# DELETE /projects/:project_id/repository/(:repository_id/)revisions/:rev/issues/:issue_id
|
||||
def remove_related_issue
|
||||
@issue = Issue.visible.find_by_id(params[:issue_id])
|
||||
if @issue
|
||||
@changeset.issues.delete(@issue)
|
||||
end
|
||||
end
|
||||
|
||||
def diff
|
||||
if params[:format] == 'diff'
|
||||
@diff = @repository.diff(@path, @rev, @rev_to)
|
||||
(show_error_not_found; return) unless @diff
|
||||
filename = "changeset_r#{@rev}"
|
||||
filename << "_r#{@rev_to}" if @rev_to
|
||||
send_data @diff.join, :filename => "#{filename}.diff",
|
||||
:type => 'text/x-patch',
|
||||
:disposition => 'attachment'
|
||||
else
|
||||
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
|
||||
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
|
||||
|
||||
# Save diff type as user preference
|
||||
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
|
||||
User.current.pref[:diff_type] = @diff_type
|
||||
User.current.preference.save
|
||||
end
|
||||
@cache_key = "repositories/diff/#{@repository.id}/" +
|
||||
Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
|
||||
unless read_fragment(@cache_key)
|
||||
@diff = @repository.diff(@path, @rev, @rev_to)
|
||||
show_error_not_found unless @diff
|
||||
end
|
||||
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
@changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
|
||||
@diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
|
||||
end
|
||||
end
|
||||
|
||||
def stats
|
||||
end
|
||||
|
||||
def graph
|
||||
data = nil
|
||||
case params[:graph]
|
||||
when "commits_per_month"
|
||||
data = graph_commits_per_month(@repository)
|
||||
when "commits_per_author"
|
||||
data = graph_commits_per_author(@repository)
|
||||
end
|
||||
if data
|
||||
headers["Content-Type"] = "image/svg+xml"
|
||||
send_data(data, :type => "image/svg+xml", :disposition => "inline")
|
||||
else
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_repository
|
||||
@repository = Repository.find(params[:id])
|
||||
@project = @repository.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
|
||||
|
||||
def find_project_repository
|
||||
@project = Project.find(params[:id])
|
||||
if params[:repository_id].present?
|
||||
@repository = @project.repositories.find_by_identifier_param(params[:repository_id])
|
||||
else
|
||||
@repository = @project.repository
|
||||
end
|
||||
(render_404; return false) unless @repository
|
||||
@path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s
|
||||
@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip
|
||||
@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
|
||||
render_404
|
||||
rescue InvalidRevisionParam
|
||||
show_error_not_found
|
||||
end
|
||||
|
||||
def find_changeset
|
||||
if @rev.present?
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
end
|
||||
show_error_not_found unless @changeset
|
||||
end
|
||||
|
||||
def show_error_not_found
|
||||
render_error :message => l(:error_scm_not_found), :status => 404
|
||||
end
|
||||
|
||||
# Handler for Redmine::Scm::Adapters::CommandFailed exception
|
||||
def show_error_command_failed(exception)
|
||||
render_error l(:error_scm_command_failed, exception.message)
|
||||
end
|
||||
|
||||
def graph_commits_per_month(repository)
|
||||
@date_to = Date.today
|
||||
@date_from = @date_to << 11
|
||||
@date_from = Date.civil(@date_from.year, @date_from.month, 1)
|
||||
commits_by_day = Changeset.count(
|
||||
:all, :group => :commit_date,
|
||||
:conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
||||
commits_by_month = [0] * 12
|
||||
commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
|
||||
|
||||
changes_by_day = Change.count(
|
||||
:all, :group => :commit_date, :include => :changeset,
|
||||
:conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
||||
changes_by_month = [0] * 12
|
||||
changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
|
||||
|
||||
fields = []
|
||||
12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
|
||||
|
||||
graph = SVG::Graph::Bar.new(
|
||||
:height => 300,
|
||||
:width => 650,
|
||||
:fields => fields.reverse,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
:step_x_labels => 2,
|
||||
:show_data_values => false,
|
||||
:graph_title => l(:label_commits_per_month),
|
||||
:show_graph_title => true
|
||||
)
|
||||
|
||||
graph.add_data(
|
||||
:data => commits_by_month[0..11].reverse,
|
||||
:title => l(:label_revision_plural)
|
||||
)
|
||||
|
||||
graph.add_data(
|
||||
:data => changes_by_month[0..11].reverse,
|
||||
:title => l(:label_change_plural)
|
||||
)
|
||||
|
||||
graph.burn
|
||||
end
|
||||
|
||||
def graph_commits_per_author(repository)
|
||||
commits_by_author = Changeset.count(:all, :group => :committer, :conditions => ["repository_id = ?", repository.id])
|
||||
commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
|
||||
|
||||
changes_by_author = Change.count(:all, :group => :committer, :include => :changeset, :conditions => ["#{Changeset.table_name}.repository_id = ?", repository.id])
|
||||
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
|
||||
|
||||
fields = commits_by_author.collect {|r| r.first}
|
||||
commits_data = commits_by_author.collect {|r| r.last}
|
||||
changes_data = commits_by_author.collect {|r| h[r.first] || 0}
|
||||
|
||||
fields = fields + [""]*(10 - fields.length) if fields.length<10
|
||||
commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
|
||||
changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
|
||||
|
||||
# Remove email adress in usernames
|
||||
fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
|
||||
|
||||
graph = SVG::Graph::BarHorizontal.new(
|
||||
:height => 400,
|
||||
:width => 650,
|
||||
:fields => fields,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
:show_data_values => false,
|
||||
:rotate_y_labels => false,
|
||||
:graph_title => l(:label_commits_per_author),
|
||||
:show_graph_title => true
|
||||
)
|
||||
graph.add_data(
|
||||
:data => commits_data,
|
||||
:title => l(:label_revision_plural)
|
||||
)
|
||||
graph.add_data(
|
||||
:data => changes_data,
|
||||
:title => l(:label_change_plural)
|
||||
)
|
||||
graph.burn
|
||||
end
|
||||
end
|
|
@ -0,0 +1,108 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class RolesController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin, :except => [:index, :show]
|
||||
before_filter :require_admin_or_api_request, :only => [:index, :show]
|
||||
before_filter :find_role, :only => [:show, :edit, :update, :destroy]
|
||||
accept_api_auth :index, :show
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@role_pages, @roles = paginate Role.sorted, :per_page => 25
|
||||
render :action => "index", :layout => false if request.xhr?
|
||||
}
|
||||
format.api {
|
||||
@roles = Role.givable.all
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
# Prefills the form with 'Non member' role permissions by default
|
||||
@role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
|
||||
if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy])
|
||||
@role.copy_from(@copy_from)
|
||||
end
|
||||
@roles = Role.sorted.all
|
||||
end
|
||||
|
||||
def create
|
||||
@role = Role.new(params[:role])
|
||||
if request.post? && @role.save
|
||||
# workflow copy
|
||||
if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
|
||||
@role.workflow_rules.copy(copy_from)
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to roles_path
|
||||
else
|
||||
@roles = Role.sorted.all
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if request.put? and @role.update_attributes(params[:role])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to roles_path
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@role.destroy
|
||||
redirect_to roles_path
|
||||
rescue
|
||||
flash[:error] = l(:error_can_not_remove_role)
|
||||
redirect_to roles_path
|
||||
end
|
||||
|
||||
def permissions
|
||||
@roles = Role.sorted.all
|
||||
@permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
|
||||
if request.post?
|
||||
@roles.each do |role|
|
||||
role.permissions = params[:permissions][role.id.to_s]
|
||||
role.save
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to roles_path
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_role
|
||||
@role = Role.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,111 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class SearchController < ApplicationController
|
||||
before_filter :find_optional_project
|
||||
|
||||
def index
|
||||
@question = params[:q] || ""
|
||||
@question.strip!
|
||||
@all_words = params[:all_words] ? params[:all_words].present? : true
|
||||
@titles_only = params[:titles_only] ? params[:titles_only].present? : false
|
||||
|
||||
projects_to_search =
|
||||
case params[:scope]
|
||||
when 'all'
|
||||
nil
|
||||
when 'my_projects'
|
||||
User.current.memberships.collect(&:project)
|
||||
when 'subprojects'
|
||||
@project ? (@project.self_and_descendants.active.all) : nil
|
||||
else
|
||||
@project
|
||||
end
|
||||
|
||||
offset = nil
|
||||
begin; offset = params[:offset].to_time if params[:offset]; rescue; end
|
||||
|
||||
# quick jump to an issue
|
||||
if (m = @question.match(/^#?(\d+)$/)) && (issue = Issue.visible.find_by_id(m[1].to_i))
|
||||
redirect_to issue_path(issue)
|
||||
return
|
||||
end
|
||||
|
||||
@object_types = Redmine::Search.available_search_types.dup
|
||||
if projects_to_search.is_a? Project
|
||||
# don't search projects
|
||||
@object_types.delete('projects')
|
||||
# only show what the user is allowed to view
|
||||
@object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, projects_to_search)}
|
||||
end
|
||||
|
||||
@scope = @object_types.select {|t| params[t]}
|
||||
@scope = @object_types if @scope.empty?
|
||||
|
||||
# extract tokens from the question
|
||||
# eg. hello "bye bye" => ["hello", "bye bye"]
|
||||
@tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
|
||||
# tokens must be at least 2 characters long
|
||||
@tokens = @tokens.uniq.select {|w| w.length > 1 }
|
||||
|
||||
if !@tokens.empty?
|
||||
# no more than 5 tokens to search for
|
||||
@tokens.slice! 5..-1 if @tokens.size > 5
|
||||
|
||||
@results = []
|
||||
@results_by_type = Hash.new {|h,k| h[k] = 0}
|
||||
|
||||
limit = 10
|
||||
@scope.each do |s|
|
||||
r, c = s.singularize.camelcase.constantize.search(@tokens, projects_to_search,
|
||||
:all_words => @all_words,
|
||||
:titles_only => @titles_only,
|
||||
:limit => (limit+1),
|
||||
:offset => offset,
|
||||
:before => params[:previous].nil?)
|
||||
@results += r
|
||||
@results_by_type[s] += c
|
||||
end
|
||||
@results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime}
|
||||
if params[:previous].nil?
|
||||
@pagination_previous_date = @results[0].event_datetime if offset && @results[0]
|
||||
if @results.size > limit
|
||||
@pagination_next_date = @results[limit-1].event_datetime
|
||||
@results = @results[0, limit]
|
||||
end
|
||||
else
|
||||
@pagination_next_date = @results[-1].event_datetime if offset && @results[-1]
|
||||
if @results.size > limit
|
||||
@pagination_previous_date = @results[-(limit)].event_datetime
|
||||
@results = @results[-(limit), limit]
|
||||
end
|
||||
end
|
||||
else
|
||||
@question = ""
|
||||
end
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
private
|
||||
def find_optional_project
|
||||
return true unless params[:id]
|
||||
@project = Project.find(params[:id])
|
||||
check_project_privacy
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,73 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class SettingsController < ApplicationController
|
||||
layout 'admin'
|
||||
menu_item :plugins, :only => :plugin
|
||||
|
||||
helper :queries
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
edit
|
||||
render :action => 'edit'
|
||||
end
|
||||
|
||||
def edit
|
||||
@notifiables = Redmine::Notifiable.all
|
||||
if request.post? && params[:settings] && params[:settings].is_a?(Hash)
|
||||
settings = (params[:settings] || {}).dup.symbolize_keys
|
||||
settings.each do |name, value|
|
||||
# remove blank values in array settings
|
||||
value.delete_if {|v| v.blank? } if value.is_a?(Array)
|
||||
Setting[name] = value
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to settings_path(:tab => params[:tab])
|
||||
else
|
||||
@options = {}
|
||||
user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort{|a, b| a[1] <=> b[1]}
|
||||
@options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].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
|
||||
|
||||
def plugin
|
||||
@plugin = Redmine::Plugin.find(params[:id])
|
||||
unless @plugin.configurable?
|
||||
render_404
|
||||
return
|
||||
end
|
||||
|
||||
if request.post?
|
||||
Setting.send "plugin_#{@plugin.id}=", params[:settings]
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to plugin_settings_path(@plugin)
|
||||
else
|
||||
@partial = @plugin.settings[:partial]
|
||||
@settings = Setting.send "plugin_#{@plugin.id}"
|
||||
end
|
||||
rescue Redmine::PluginNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,84 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class SysController < ActionController::Base
|
||||
before_filter :check_enabled
|
||||
|
||||
def projects
|
||||
p = Project.active.has_module(:repository).find(
|
||||
:all,
|
||||
:include => :repository,
|
||||
:order => "#{Project.table_name}.identifier"
|
||||
)
|
||||
# extra_info attribute from repository breaks activeresource client
|
||||
render :xml => p.to_xml(
|
||||
:only => [:id, :identifier, :name, :is_public, :status],
|
||||
:include => {:repository => {:only => [:id, :url]}}
|
||||
)
|
||||
end
|
||||
|
||||
def create_project_repository
|
||||
project = Project.find(params[:id])
|
||||
if project.repository
|
||||
render :nothing => true, :status => 409
|
||||
else
|
||||
logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
|
||||
repository = Repository.factory(params[:vendor], params[:repository])
|
||||
repository.project = project
|
||||
if repository.save
|
||||
render :xml => {repository.class.name.underscore.gsub('/', '-') => {:id => repository.id, :url => repository.url}}, :status => 201
|
||||
else
|
||||
render :nothing => true, :status => 422
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_changesets
|
||||
projects = []
|
||||
scope = Project.active.has_module(:repository)
|
||||
if params[:id]
|
||||
project = nil
|
||||
if params[:id].to_s =~ /^\d*$/
|
||||
project = scope.find(params[:id])
|
||||
else
|
||||
project = scope.find_by_identifier(params[:id])
|
||||
end
|
||||
raise ActiveRecord::RecordNotFound unless project
|
||||
projects << project
|
||||
else
|
||||
projects = scope.all
|
||||
end
|
||||
projects.each do |project|
|
||||
project.repositories.each do |repository|
|
||||
repository.fetch_changesets
|
||||
end
|
||||
end
|
||||
render :nothing => true, :status => 200
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render :nothing => true, :status => 404
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def check_enabled
|
||||
User.current = nil
|
||||
unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
|
||||
render :text => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,77 @@
|
|||
# This controller was added by william
|
||||
class TagsController < ApplicationController
|
||||
|
||||
before_filter :require_admin,:only => :show
|
||||
include ProjectsHelper
|
||||
include IssuesHelper
|
||||
include UsersHelper
|
||||
include ActsAsTaggableOn::TagsHelper
|
||||
|
||||
$selected_tags = Array.new
|
||||
$related_tags = Array.new
|
||||
def index
|
||||
|
||||
$selected_tags = []
|
||||
$related_tags = []
|
||||
$selected_tags << params[:q]
|
||||
|
||||
@issues_tags_num = Issue.tag_counts.size
|
||||
@projects_tags_num = Project.tag_counts.size
|
||||
@users_tags_num = User.tag_counts.size
|
||||
|
||||
@issues_results = get_issues_by_tag($selected_tags)
|
||||
@projects_results = get_projects_by_tag($selected_tags)
|
||||
@users_results = get_users_by_tag($selected_tags)
|
||||
|
||||
@obj_id = params[:obj_id]
|
||||
case params[:object_flag]
|
||||
when '1' then
|
||||
@obj = User.find_by_id(@obj_id)
|
||||
when '2' then
|
||||
@obj = Project.find_by_id(@obj_id)
|
||||
when '3' then
|
||||
@obj = Issue.find_by_id(@obj_id)
|
||||
else
|
||||
@obj = nil
|
||||
end
|
||||
|
||||
unless @obj.nil?
|
||||
@tags = @obj.tag_list
|
||||
$selected_tags.each do |i|
|
||||
@tags.delete(i)
|
||||
end
|
||||
$related_tags = @tags
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def add_tag
|
||||
@tag = params[:tag]
|
||||
$selected_tags << @tag
|
||||
$related_tags.delete(@tag)
|
||||
|
||||
@issues_results = get_issues_by_tag($selected_tags)
|
||||
@projects_results = get_projects_by_tag($selected_tags)
|
||||
@users_results = get_users_by_tag($selected_tags)
|
||||
end
|
||||
|
||||
def delete_tag
|
||||
@tag = params[:tag]
|
||||
$related_tags << @tag
|
||||
$selected_tags.delete(@tag)
|
||||
|
||||
@issues_results = get_issues_by_tag($selected_tags)
|
||||
@projects_results = get_projects_by_tag($selected_tags)
|
||||
@users_results = get_users_by_tag($selected_tags)
|
||||
end
|
||||
|
||||
def count(name)
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,126 @@
|
|||
class TestController < ApplicationController
|
||||
|
||||
before_filter :find_user, :only => [:new, :create, :destroy]
|
||||
|
||||
|
||||
def index
|
||||
#@watchers_of_projects = WatchersOfProjects.new
|
||||
#@watchers_of_projects.user_id = 1
|
||||
#@watchers_of_projects.project_id = 1
|
||||
#@watchers_of_projects.save
|
||||
|
||||
#测试user表与watch_project表之间的关联是否成功
|
||||
#@user = User.find(params[:id])
|
||||
#@watch_table = @user.watch_projects.to_a.first
|
||||
|
||||
#@watch = WatchProject.find(1)
|
||||
#@watcher = @watch.user
|
||||
|
||||
#测试通过watch_project表使user表可以访问project表
|
||||
#@watch_project = @user.projects
|
||||
#watch_project_path(@watch)
|
||||
|
||||
#@project = Project.find(11)
|
||||
#project_path(@project)
|
||||
#@member = @project.users
|
||||
#@watched = @project.watch_projects
|
||||
#@issue = Issue.find(6)
|
||||
|
||||
|
||||
#user_path(@user)
|
||||
#issue_path(@issue)
|
||||
|
||||
#@watcher2=WatchProject.where("#{WatchProject.table_name}.project_id = ?" , temp)
|
||||
|
||||
#测试where语句
|
||||
#temp = 1
|
||||
#@watcher2=WatchProject.where(:project_id => temp).to_a
|
||||
|
||||
#测试新建记录
|
||||
#@watch_new = WatchProject.new
|
||||
#@watch_new.user_id = 4
|
||||
#@watch_new.project_id = 1
|
||||
#@watch_new.save
|
||||
#@id = params[:id]
|
||||
|
||||
#测试添加关注项目功能
|
||||
#WatchersOfProjects.watch(3,10)
|
||||
#Project.find(50)
|
||||
#测试统计关注该项目的用户数
|
||||
#@count = WatchersOfProjects.watcher_count(@watch_project.to_a.first)
|
||||
#测试取消关注功能
|
||||
#WatchersOfProjects.watch_cancle(10,35)
|
||||
|
||||
#测试关注用户功能
|
||||
#测试关注功能
|
||||
#WatchersOfUser.watch_user(7,7)
|
||||
#测试取消关注功能
|
||||
#WatchersOfUser.cancel_watching_user(1,2)
|
||||
#测试查找关注的人功能
|
||||
#@user = WatchersOfUser.find_users(1)
|
||||
#测试查找被关注的人功能
|
||||
#@user = WatchersOfUser.find_watchers(10)
|
||||
|
||||
#测试用户留言功能
|
||||
#测试留言功能
|
||||
MessagesForUser.leave_message(User.current.id, 6, 'test')
|
||||
#测试查找留言功能
|
||||
#@message_table = MessagesForUser.find_message(3)
|
||||
#测试查找留言用户功能
|
||||
#@messager=@message_table.first.find_messager
|
||||
|
||||
|
||||
#测试需求
|
||||
#测试新建需求
|
||||
#bids = Bid.creat_bids(10000, '2013.7.25', 'test', 'sfsadgfag')
|
||||
#测试修改需求
|
||||
#bids.update_bids(10, '2014.7.222', 'asdf')
|
||||
#测试删除需求
|
||||
# bids = Bid.where('id = ?', 5)
|
||||
# bids.each do |bid|
|
||||
# bid.delete_bids
|
||||
# end
|
||||
end
|
||||
|
||||
##########留言功能 message by fq
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
if params[:user_search].size>0
|
||||
unless params[:user_id].nil?
|
||||
message = params[:user_search]
|
||||
MessagesForUser.leave_message(User.current.id, params[:user_id], message)
|
||||
@message = MessagesForUser.find_message(@user.id)
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
MessagesForUser.delete_message(params[:object_id])
|
||||
@message = MessagesForUser.find_message(@user.id)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_user
|
||||
if params[:user_id]
|
||||
@user = User.find(params[:user_id])
|
||||
end
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
#######end of message
|
||||
end
|
|
@ -0,0 +1,314 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class TimelogController < ApplicationController
|
||||
menu_item :issues
|
||||
|
||||
before_filter :find_project_for_new_time_entry, :only => [:create]
|
||||
before_filter :find_time_entry, :only => [:show, :edit, :update]
|
||||
before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
|
||||
before_filter :authorize, :except => [:new, :index, :report]
|
||||
|
||||
before_filter :find_optional_project, :only => [:index, :report]
|
||||
before_filter :find_optional_project_for_new_time_entry, :only => [:new]
|
||||
before_filter :authorize_global, :only => [:new, :index, :report]
|
||||
|
||||
accept_rss_auth :index
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
||||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :issues
|
||||
include TimelogHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
helper :queries
|
||||
include QueriesHelper
|
||||
|
||||
def index
|
||||
@query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_')
|
||||
scope = time_entry_scope
|
||||
|
||||
sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria)
|
||||
sort_update(@query.sortable_columns)
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# Paginate results
|
||||
@entry_count = scope.count
|
||||
@entry_pages = Paginator.new @entry_count, per_page_option, params['page']
|
||||
@entries = scope.all(
|
||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||
:order => sort_clause,
|
||||
:limit => @entry_pages.per_page,
|
||||
:offset => @entry_pages.offset
|
||||
)
|
||||
@total_hours = scope.sum(:hours).to_f
|
||||
|
||||
render :layout => !request.xhr?
|
||||
}
|
||||
format.api {
|
||||
@entry_count = scope.count
|
||||
@offset, @limit = api_offset_and_limit
|
||||
@entries = scope.all(
|
||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||
:order => sort_clause,
|
||||
:limit => @limit,
|
||||
:offset => @offset
|
||||
)
|
||||
}
|
||||
format.atom {
|
||||
entries = scope.all(
|
||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||
: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 = scope.all(
|
||||
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
||||
:order => sort_clause
|
||||
)
|
||||
send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def report
|
||||
@query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_')
|
||||
scope = time_entry_scope
|
||||
|
||||
@report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], scope)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :layout => !request.xhr? }
|
||||
format.csv { send_data(report_to_csv(@report), :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.safe_attributes = params[:time_entry]
|
||||
end
|
||||
|
||||
def create
|
||||
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
|
||||
@time_entry.safe_attributes = params[:time_entry]
|
||||
|
||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
||||
|
||||
if @time_entry.save
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
if params[:continue]
|
||||
if params[:project_id]
|
||||
options = {
|
||||
:time_entry => {:issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
|
||||
:back_url => params[:back_url]
|
||||
}
|
||||
if @time_entry.issue
|
||||
redirect_to new_project_issue_time_entry_path(@time_entry.project, @time_entry.issue, options)
|
||||
else
|
||||
redirect_to new_project_time_entry_path(@time_entry.project, options)
|
||||
end
|
||||
else
|
||||
options = {
|
||||
:time_entry => {:project_id => @time_entry.project_id, :issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
|
||||
:back_url => params[:back_url]
|
||||
}
|
||||
redirect_to new_time_entry_path(options)
|
||||
end
|
||||
else
|
||||
redirect_back_or_default project_time_entries_path(@time_entry.project)
|
||||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new' }
|
||||
format.api { render_validation_errors(@time_entry) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@time_entry.safe_attributes = params[:time_entry]
|
||||
end
|
||||
|
||||
def update
|
||||
@time_entry.safe_attributes = params[:time_entry]
|
||||
|
||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
|
||||
|
||||
if @time_entry.save
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_back_or_default project_time_entries_path(@time_entry.project)
|
||||
}
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@time_entry) }
|
||||
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.safe_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 project_time_entries_path(@projects.first)
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroyed = TimeEntry.transaction do
|
||||
@time_entries.each do |t|
|
||||
unless t.destroy && t.destroyed?
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
if destroyed
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
else
|
||||
flash[:error] = l(:notice_unable_delete_time_entry)
|
||||
end
|
||||
redirect_back_or_default project_time_entries_path(@projects.first)
|
||||
}
|
||||
format.api {
|
||||
if destroyed
|
||||
render_api_ok
|
||||
else
|
||||
render_validation_errors(@time_entries)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_time_entry
|
||||
@time_entry = TimeEntry.find(params[:id])
|
||||
unless @time_entry.editable_by?(User.current)
|
||||
render_403
|
||||
return false
|
||||
end
|
||||
@project = @time_entry.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_time_entries
|
||||
@time_entries = TimeEntry.find_all_by_id(params[:id] || params[:ids])
|
||||
raise ActiveRecord::RecordNotFound if @time_entries.empty?
|
||||
@projects = @time_entries.collect(&:project).compact.uniq
|
||||
@project = @projects.first if @projects.size == 1
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def set_flash_from_bulk_time_entry_save(time_entries, unsaved_time_entry_ids)
|
||||
if unsaved_time_entry_ids.empty?
|
||||
flash[:notice] = l(:notice_successful_update) unless time_entries.empty?
|
||||
else
|
||||
flash[:error] = l(:notice_failed_to_save_time_entries,
|
||||
:count => unsaved_time_entry_ids.size,
|
||||
:total => time_entries.size,
|
||||
:ids => '#' + unsaved_time_entry_ids.join(', #'))
|
||||
end
|
||||
end
|
||||
|
||||
def find_optional_project_for_new_time_entry
|
||||
if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
|
||||
@project = Project.find(project_id)
|
||||
end
|
||||
if (issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id])).present?
|
||||
@issue = Issue.find(issue_id)
|
||||
@project ||= @issue.project
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_project_for_new_time_entry
|
||||
find_optional_project_for_new_time_entry
|
||||
if @project.nil?
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
def find_optional_project
|
||||
if !params[:issue_id].blank?
|
||||
@issue = Issue.find(params[:issue_id])
|
||||
@project = @issue.project
|
||||
elsif !params[:project_id].blank?
|
||||
@project = Project.find(params[:project_id])
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the TimeEntry scope for index and report actions
|
||||
def time_entry_scope
|
||||
scope = TimeEntry.visible.where(@query.statement)
|
||||
if @issue
|
||||
scope = scope.on_issue(@issue)
|
||||
elsif @project
|
||||
scope = scope.on_project(@project, Setting.display_subprojects_issues?)
|
||||
end
|
||||
scope
|
||||
end
|
||||
|
||||
def parse_params_for_bulk_time_entry_attributes(params)
|
||||
attributes = (params[:time_entry] || {}).reject {|k,v| v.blank?}
|
||||
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
|
||||
attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
|
||||
attributes
|
||||
end
|
||||
end
|
|
@ -0,0 +1,101 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 TrackersController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin, :except => :index
|
||||
before_filter :require_admin_or_api_request, :only => :index
|
||||
accept_api_auth :index
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@tracker_pages, @trackers = paginate Tracker.sorted, :per_page => 25
|
||||
render :action => "index", :layout => false if request.xhr?
|
||||
}
|
||||
format.api {
|
||||
@trackers = Tracker.sorted.all
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@tracker ||= Tracker.new(params[:tracker])
|
||||
@trackers = Tracker.sorted.all
|
||||
@projects = Project.all
|
||||
end
|
||||
|
||||
def create
|
||||
@tracker = Tracker.new(params[:tracker])
|
||||
if @tracker.save
|
||||
# workflow copy
|
||||
if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
|
||||
@tracker.workflow_rules.copy(copy_from)
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to trackers_path
|
||||
return
|
||||
end
|
||||
new
|
||||
render :action => 'new'
|
||||
end
|
||||
|
||||
def edit
|
||||
@tracker ||= Tracker.find(params[:id])
|
||||
@projects = Project.all
|
||||
end
|
||||
|
||||
def update
|
||||
@tracker = Tracker.find(params[:id])
|
||||
if @tracker.update_attributes(params[:tracker])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to trackers_path
|
||||
return
|
||||
end
|
||||
edit
|
||||
render :action => 'edit'
|
||||
end
|
||||
|
||||
def destroy
|
||||
@tracker = Tracker.find(params[:id])
|
||||
unless @tracker.issues.empty?
|
||||
flash[:error] = l(:error_can_not_delete_tracker)
|
||||
else
|
||||
@tracker.destroy
|
||||
end
|
||||
redirect_to trackers_path
|
||||
end
|
||||
|
||||
def fields
|
||||
if request.post? && params[:trackers]
|
||||
params[:trackers].each do |tracker_id, tracker_params|
|
||||
tracker = Tracker.find_by_id(tracker_id)
|
||||
if tracker
|
||||
tracker.core_fields = tracker_params[:core_fields]
|
||||
tracker.custom_field_ids = tracker_params[:custom_field_ids]
|
||||
tracker.save
|
||||
end
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to fields_trackers_path
|
||||
return
|
||||
end
|
||||
@trackers = Tracker.sorted.all
|
||||
@custom_fields = IssueCustomField.all.sort
|
||||
end
|
||||
end
|
|
@ -0,0 +1,320 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
class UsersController < ApplicationController
|
||||
layout 'base_users'
|
||||
|
||||
before_filter :require_admin, :except => [:show, :index,:tag_save]
|
||||
before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments]
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
include AvatarHelper
|
||||
|
||||
# added by liuping 关注
|
||||
|
||||
helper :watchers
|
||||
helper :activities
|
||||
|
||||
### added by william
|
||||
include ActsAsTaggableOn::TagsHelper
|
||||
|
||||
|
||||
helper :watchers
|
||||
helper :activities
|
||||
|
||||
# fq
|
||||
helper :words
|
||||
#added by young
|
||||
def user_projects
|
||||
@message = MessagesForUser.find_message(@user.id)
|
||||
@memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
||||
|
||||
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20)
|
||||
@events_by_day = events.group_by(&:event_date)
|
||||
|
||||
unless User.current.admin?
|
||||
if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
|
||||
render_404
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def user_activities
|
||||
#####fq
|
||||
# @message = MessagesForUser.find_message(@user.id)
|
||||
# show projects based on current user visibility
|
||||
# @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
||||
|
||||
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 30)
|
||||
@events_by_day = events.group_by(&:event_date)
|
||||
|
||||
unless User.current.admin?
|
||||
if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
|
||||
render_404
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def user_newfeedback
|
||||
@jour = @user.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
@state = false
|
||||
|
||||
end
|
||||
|
||||
def user_comments
|
||||
|
||||
end
|
||||
#end
|
||||
def index
|
||||
sort_init 'login', 'asc'
|
||||
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
||||
|
||||
case params[:format]
|
||||
when 'xml', 'json'
|
||||
@offset, @limit = api_offset_and_limit
|
||||
else
|
||||
@limit = per_page_option
|
||||
end
|
||||
|
||||
@status = params[:status] || 1
|
||||
has = {
|
||||
"show_changesets" => true
|
||||
}
|
||||
# @count = Redmine::Activity::Fetcher.new(User.current, :author => @user).scope_select {|t| !has["show_#{t}"].nil?}.events(nil, nil).count
|
||||
|
||||
|
||||
scope = User.logged.status(@status)
|
||||
scope = scope.like(params[:name]) if params[:name].present?
|
||||
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
|
||||
|
||||
@user_count = scope.count
|
||||
@user_pages = Paginator.new @user_count, @limit, params['page']
|
||||
@offset ||= @user_pages.offset
|
||||
@users = scope.order(sort_clause).limit(@limit).offset(@offset).all
|
||||
@user_base_tag = params[:id]?'base_users':'base'
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@groups = Group.all.sort
|
||||
render :layout => @user_base_tag
|
||||
}
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
#####fq
|
||||
@message = MessagesForUser.find_message(@user.id)
|
||||
# show projects based on current user visibility
|
||||
@memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
||||
|
||||
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
|
||||
@events_by_day = events.group_by(&:event_date)
|
||||
|
||||
unless User.current.admin?
|
||||
if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
|
||||
render_404
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
|
||||
@auth_sources = AuthSource.all
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
if @user.save
|
||||
@user.pref.attributes = params[:pref]
|
||||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
||||
@user.pref.save
|
||||
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
||||
|
||||
Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information]
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
|
||||
if params[:continue]
|
||||
redirect_to new_user_path
|
||||
else
|
||||
redirect_to edit_user_path(@user)
|
||||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
|
||||
end
|
||||
else
|
||||
@auth_sources = AuthSource.all
|
||||
# Clear password input
|
||||
@user.password = @user.password_confirmation = nil
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new' }
|
||||
format.api { render_validation_errors(@user) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@auth_sources = AuthSource.all
|
||||
@membership ||= Member.new
|
||||
end
|
||||
|
||||
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.account_activated(@user).deliver
|
||||
elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil?
|
||||
Mailer.account_information(@user, params[:user][:password]).deliver
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to_referer_or edit_user_path(@user)
|
||||
}
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
@auth_sources = AuthSource.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
|
||||
end
|
||||
|
||||
def destroy
|
||||
@user.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_back_or_default(users_path) }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def edit_membership
|
||||
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
|
||||
@membership.save
|
||||
respond_to do |format|
|
||||
format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_membership
|
||||
@membership = Member.find(params[:membership_id])
|
||||
if @membership.deletable?
|
||||
@membership.destroy
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
################# added by william
|
||||
def tag_save
|
||||
@tags = params[:tag_for_save][:name]
|
||||
@obj_id = params[:tag_for_save][:object_id]
|
||||
@obj_flag = params[:tag_for_save][:object_flag]
|
||||
|
||||
case @obj_flag
|
||||
when '1' then
|
||||
@obj = User.find_by_id(@obj_id)
|
||||
when '2' then
|
||||
@obj = Project.find_by_id(@obj_id)
|
||||
when '3' then
|
||||
@obj = Issue.find_by_id(@obj_id)
|
||||
else
|
||||
@obj = nil
|
||||
end
|
||||
unless @obj.nil?
|
||||
@obj.tag_list.add(@tags.split(","))
|
||||
else
|
||||
return
|
||||
end
|
||||
if @obj.save
|
||||
## 执行成功的操作。
|
||||
else
|
||||
#捕获异常
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
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
|
|
@ -0,0 +1,182 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 VersionsController < ApplicationController
|
||||
menu_item :roadmap
|
||||
model_object Version
|
||||
before_filter :find_model_object, :except => [:index, :new, :create, :close_completed]
|
||||
before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed]
|
||||
before_filter :find_project_by_project_id, :only => [:index, :new, :create, :close_completed]
|
||||
before_filter :authorize
|
||||
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
||||
helper :custom_fields
|
||||
helper :projects
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@trackers = @project.trackers.sorted.all
|
||||
retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
|
||||
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
||||
project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
|
||||
|
||||
@versions = @project.shared_versions || []
|
||||
@versions += @project.rolled_up_versions.visible if @with_subprojects
|
||||
@versions = @versions.uniq.sort
|
||||
unless params[:completed]
|
||||
@completed_versions = @versions.select {|version| version.closed? || version.completed? }
|
||||
@versions -= @completed_versions
|
||||
end
|
||||
|
||||
@issues_by_version = {}
|
||||
if @selected_tracker_ids.any? && @versions.any?
|
||||
issues = Issue.visible.all(
|
||||
:include => [:project, :status, :tracker, :priority, :fixed_version],
|
||||
:conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)},
|
||||
:order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id"
|
||||
)
|
||||
@issues_by_version = issues.group_by(&:fixed_version)
|
||||
end
|
||||
@versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
|
||||
}
|
||||
format.api {
|
||||
@versions = @project.shared_versions.all
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@issues = @version.fixed_issues.visible.
|
||||
includes(:status, :tracker, :priority).
|
||||
reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
|
||||
all
|
||||
}
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@version = @project.versions.build
|
||||
@version.safe_attributes = params[:version]
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@version = @project.versions.build
|
||||
if params[:version]
|
||||
attributes = params[:version].dup
|
||||
attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
|
||||
@version.safe_attributes = attributes
|
||||
end
|
||||
|
||||
if request.post?
|
||||
if @version.save
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_back_or_default settings_project_path(@project, :tab => 'versions')
|
||||
end
|
||||
format.js
|
||||
format.api do
|
||||
render :action => 'show', :status => :created, :location => version_url(@version)
|
||||
end
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new' }
|
||||
format.js { render :action => 'new' }
|
||||
format.api { render_validation_errors(@version) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if request.put? && params[:version]
|
||||
attributes = params[:version].dup
|
||||
attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
|
||||
@version.safe_attributes = attributes
|
||||
if @version.save
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_back_or_default settings_project_path(@project, :tab => 'versions')
|
||||
}
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@version) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def close_completed
|
||||
if request.put?
|
||||
@project.close_completed_versions
|
||||
end
|
||||
redirect_to settings_project_path(@project, :tab => 'versions')
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @version.fixed_issues.empty?
|
||||
@version.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_back_or_default settings_project_path(@project, :tab => 'versions') }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:error] = l(:notice_unable_delete_version)
|
||||
redirect_to settings_project_path(@project, :tab => 'versions')
|
||||
}
|
||||
format.api { head :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def status_by
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'show' }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
|
||||
if ids = params[:tracker_ids]
|
||||
@selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
|
||||
else
|
||||
@selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,109 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WatchersController < ApplicationController
|
||||
before_filter :require_login, :find_watchables, :only => [:watch, :unwatch]
|
||||
|
||||
def watch
|
||||
set_watcher(@watchables, User.current, true)
|
||||
end
|
||||
|
||||
def unwatch
|
||||
set_watcher(@watchables, User.current, false)
|
||||
end
|
||||
|
||||
before_filter :find_project, :authorize, :only => [:new, :create, :append, :destroy, :autocomplete_for_user]
|
||||
accept_api_auth :create, :destroy
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
user_ids = []
|
||||
if params[:watcher].is_a?(Hash)
|
||||
user_ids << (params[:watcher][:user_ids] || params[:watcher][:user_id])
|
||||
else
|
||||
user_ids << params[:user_id]
|
||||
end
|
||||
user_ids.flatten.compact.uniq.each do |user_id|
|
||||
Watcher.create(:watchable => @watched, :user_id => user_id)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
|
||||
format.js
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def append
|
||||
if params[:watcher].is_a?(Hash)
|
||||
user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
|
||||
@users = User.active.find_all_by_id(user_ids)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@watched.set_watcher(User.find(params[:user_id]), false)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def autocomplete_for_user
|
||||
@users = User.active.sorted.like(params[:q]).limit(100).all
|
||||
if @watched
|
||||
@users -= @watched.watcher_users
|
||||
end
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
if params[:object_type] && params[:object_id]
|
||||
klass = Object.const_get(params[:object_type].camelcase)
|
||||
return false unless klass.respond_to?('watched_by')
|
||||
@watched = klass.find(params[:object_id])
|
||||
@project = @watched.project
|
||||
elsif params[:project_id]
|
||||
@project = Project.visible.find_by_param(params[:project_id])
|
||||
end
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_watchables
|
||||
klass = Object.const_get(params[:object_type].camelcase) rescue nil
|
||||
if klass && klass.respond_to?('watched_by')
|
||||
@watchables = klass.find_all_by_id(Array.wrap(params[:object_id]))
|
||||
raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?}
|
||||
end
|
||||
render_404 unless @watchables.present?
|
||||
end
|
||||
|
||||
def set_watcher(watchables, user, watching)
|
||||
watchables.each do |watchable|
|
||||
watchable.set_watcher(user, watching)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||
format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,68 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 WelcomeController < ApplicationController
|
||||
caches_action :robots
|
||||
|
||||
def index
|
||||
@news = News.latest User.current
|
||||
@projects = Project.latest User.current
|
||||
#by young
|
||||
(redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration]
|
||||
if request.get?
|
||||
session[:auth_source_registration] = nil
|
||||
@user = User.new(:language => current_language.to_s)
|
||||
else
|
||||
user_params = params[:user] || {}
|
||||
@user = User.new
|
||||
@user.safe_attributes = user_params
|
||||
@user.admin = false
|
||||
@user.register
|
||||
if session[:auth_source_registration]
|
||||
@user.activate
|
||||
@user.login = session[:auth_source_registration][:login]
|
||||
@user.auth_source_id = session[:auth_source_registration][:auth_source_id]
|
||||
if @user.save
|
||||
session[:auth_source_registration] = nil
|
||||
self.logged_user = @user
|
||||
flash[:notice] = l(:notice_account_activated)
|
||||
redirect_to my_account_path
|
||||
end
|
||||
else
|
||||
@user.login = params[:user][:login]
|
||||
unless user_params[:identity_url].present? && user_params[:password].blank? && user_params[:password_confirmation].blank?
|
||||
@user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation]
|
||||
end
|
||||
|
||||
case Setting.self_registration
|
||||
when '1'
|
||||
register_by_email_activation(@user)
|
||||
when '3'
|
||||
register_automatically(@user)
|
||||
else
|
||||
register_manually_by_administrator(@user)
|
||||
end
|
||||
end
|
||||
end
|
||||
#
|
||||
end
|
||||
|
||||
def robots
|
||||
@projects = Project.all_public.active
|
||||
render :layout => false, :content_type => 'text/plain'
|
||||
end
|
||||
end
|
|
@ -0,0 +1,357 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'diff'
|
||||
|
||||
# The WikiController follows the Rails REST controller pattern but with
|
||||
# a few differences
|
||||
#
|
||||
# * index - shows a list of WikiPages grouped by page or date
|
||||
# * new - not used
|
||||
# * create - not used
|
||||
# * show - will also show the form for creating a new wiki page
|
||||
# * edit - used to edit an existing or new page
|
||||
# * update - used to save a wiki page update to the database, including new pages
|
||||
# * destroy - normal
|
||||
#
|
||||
# Other member and collection methods are also used
|
||||
#
|
||||
# TODO: still being worked on
|
||||
class WikiController < ApplicationController
|
||||
layout 'base_projects'
|
||||
default_search_scope :wiki_pages
|
||||
before_filter :find_wiki, :authorize
|
||||
before_filter :find_existing_or_new_page, :only => [:show, :edit, :update]
|
||||
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version]
|
||||
accept_api_auth :index, :show, :update, :destroy
|
||||
before_filter :find_attachments, :only => [:preview]
|
||||
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
helper :watchers
|
||||
include Redmine::Export::PDF
|
||||
|
||||
# List of pages, sorted alphabetically and by parent (hierarchy)
|
||||
def index
|
||||
load_pages_for_index
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@pages_by_parent_id = @pages.group_by(&:parent_id)
|
||||
}
|
||||
format.api
|
||||
end
|
||||
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)
|
||||
def show
|
||||
if @page.new_record?
|
||||
if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request?
|
||||
edit
|
||||
render :action => 'edit'
|
||||
else
|
||||
render_404
|
||||
end
|
||||
return
|
||||
end
|
||||
if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
|
||||
deny_access
|
||||
return
|
||||
end
|
||||
@content = @page.content_for_version(params[:version])
|
||||
if User.current.allowed_to?(:export_wiki_pages, @project)
|
||||
if params[:format] == 'pdf'
|
||||
send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
|
||||
return
|
||||
elsif params[:format] == 'html'
|
||||
export = render_to_string :action => 'export', :layout => false
|
||||
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
|
||||
return
|
||||
elsif params[:format] == 'txt'
|
||||
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
|
||||
return
|
||||
end
|
||||
end
|
||||
@editable = editable?
|
||||
@sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) &&
|
||||
@content.current_version? &&
|
||||
Redmine::WikiFormatting.supports_section_edit?
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
# edit an existing page or a new one
|
||||
def edit
|
||||
return render_403 unless editable?
|
||||
if @page.new_record?
|
||||
@page.content = WikiContent.new(:page => @page)
|
||||
if params[:parent].present?
|
||||
@page.parent = @page.wiki.find_page(params[:parent].to_s)
|
||||
end
|
||||
end
|
||||
|
||||
@content = @page.content_for_version(params[:version])
|
||||
@content.text = initial_page_content(@page) if @content.text.blank?
|
||||
# don't keep previous comment
|
||||
@content.comments = nil
|
||||
|
||||
# To prevent StaleObjectError exception when reverting to a previous version
|
||||
@content.version = @page.content.version
|
||||
|
||||
@text = @content.text
|
||||
if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
|
||||
@section = params[:section].to_i
|
||||
@text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section)
|
||||
render_404 if @text.blank?
|
||||
end
|
||||
end
|
||||
|
||||
# Creates a new page or updates an existing one
|
||||
def update
|
||||
return render_403 unless editable?
|
||||
was_new_page = @page.new_record?
|
||||
@page.content = WikiContent.new(:page => @page) if @page.new_record?
|
||||
@page.safe_attributes = params[:wiki_page]
|
||||
|
||||
@content = @page.content
|
||||
content_params = params[:content]
|
||||
if content_params.nil? && params[:wiki_page].is_a?(Hash)
|
||||
content_params = params[:wiki_page].slice(:text, :comments, :version)
|
||||
end
|
||||
content_params ||= {}
|
||||
|
||||
@content.comments = content_params[:comments]
|
||||
@text = content_params[:text]
|
||||
if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
|
||||
@section = params[:section].to_i
|
||||
@section_hash = params[:section_hash]
|
||||
@content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
|
||||
else
|
||||
@content.version = content_params[:version] if content_params[:version]
|
||||
@content.text = @text
|
||||
end
|
||||
@content.author = User.current
|
||||
|
||||
if @page.save_with_content
|
||||
attachments = Attachment.attach_files(@page, params[:attachments])
|
||||
render_attachment_warning_if_needed(@page)
|
||||
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to project_wiki_page_path(@project, @page.title) }
|
||||
format.api {
|
||||
if was_new_page
|
||||
render :action => 'show', :status => :created, :location => project_wiki_page_path(@project, @page.title)
|
||||
else
|
||||
render_api_ok
|
||||
end
|
||||
}
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@content) }
|
||||
end
|
||||
end
|
||||
|
||||
rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError
|
||||
# Optimistic locking exception
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash.now[:error] = l(:notice_locking_conflict)
|
||||
render :action => 'edit'
|
||||
}
|
||||
format.api { render_api_head :conflict }
|
||||
end
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@content) }
|
||||
end
|
||||
end
|
||||
|
||||
# rename a page
|
||||
def rename
|
||||
return render_403 unless editable?
|
||||
@page.redirect_existing_links = true
|
||||
# used to display the *original* title if some AR validation errors occur
|
||||
@original_title = @page.pretty_title
|
||||
if request.post? && @page.update_attributes(params[:wiki_page])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to project_wiki_page_path(@project, @page.title)
|
||||
end
|
||||
end
|
||||
|
||||
def protect
|
||||
@page.update_attribute :protected, params[:protected]
|
||||
redirect_to project_wiki_page_path(@project, @page.title)
|
||||
end
|
||||
|
||||
# show page history
|
||||
def history
|
||||
@version_count = @page.content.versions.count
|
||||
@version_pages = Paginator.new @version_count, per_page_option, params['page']
|
||||
# don't load text
|
||||
@versions = @page.content.versions.
|
||||
select("id, author_id, comments, updated_on, version").
|
||||
reorder('version DESC').
|
||||
limit(@version_pages.per_page + 1).
|
||||
offset(@version_pages.offset).
|
||||
all
|
||||
|
||||
render :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def diff
|
||||
@diff = @page.diff(params[:version], params[:version_from])
|
||||
render_404 unless @diff
|
||||
end
|
||||
|
||||
def annotate
|
||||
@annotate = @page.annotate(params[:version])
|
||||
render_404 unless @annotate
|
||||
end
|
||||
|
||||
# Removes a wiki page and its history
|
||||
# Children can be either set as root pages, removed or reassigned to another parent page
|
||||
def destroy
|
||||
return render_403 unless editable?
|
||||
|
||||
@descendants_count = @page.descendants.size
|
||||
if @descendants_count > 0
|
||||
case params[:todo]
|
||||
when 'nullify'
|
||||
# Nothing to do
|
||||
when 'destroy'
|
||||
# Removes all its descendants
|
||||
@page.descendants.each(&:destroy)
|
||||
when 'reassign'
|
||||
# Reassign children to another parent page
|
||||
reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
|
||||
return unless reassign_to
|
||||
@page.children.each do |child|
|
||||
child.update_attribute(:parent, reassign_to)
|
||||
end
|
||||
else
|
||||
@reassignable_to = @wiki.pages - @page.self_and_descendants
|
||||
# display the destroy form if it's a user request
|
||||
return unless api_request?
|
||||
end
|
||||
end
|
||||
@page.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to project_wiki_index_path(@project) }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_version
|
||||
return render_403 unless editable?
|
||||
|
||||
@content = @page.content_for_version(params[:version])
|
||||
@content.destroy
|
||||
redirect_to_referer_or history_project_wiki_page_path(@project, @page.title)
|
||||
end
|
||||
|
||||
# Export wiki to a single pdf or html file
|
||||
def export
|
||||
@pages = @wiki.pages.all(:order => 'title', :include => [:content, {:attachments => :author}])
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
export = render_to_string :action => 'export_multiple', :layout => false
|
||||
send_data(export, :type => 'text/html', :filename => "wiki.html")
|
||||
}
|
||||
format.pdf {
|
||||
send_data(wiki_pages_to_pdf(@pages, @project), :type => 'application/pdf', :filename => "#{@project.identifier}.pdf")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def preview
|
||||
page = @wiki.find_page(params[:id])
|
||||
# page is nil when previewing a new page
|
||||
return render_403 unless page.nil? || editable?(page)
|
||||
if page
|
||||
@attachments += page.attachments
|
||||
@previewed = page.content
|
||||
end
|
||||
@text = params[:content][:text]
|
||||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
def add_attachment
|
||||
return render_403 unless editable?
|
||||
attachments = Attachment.attach_files(@page, params[:attachments])
|
||||
render_attachment_warning_if_needed(@page)
|
||||
redirect_to :action => 'show', :id => @page.title, :project_id => @project
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_wiki
|
||||
@project = Project.find(params[:project_id])
|
||||
@wiki = @project.wiki
|
||||
render_404 unless @wiki
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Finds the requested page or a new page if it doesn't exist
|
||||
def find_existing_or_new_page
|
||||
@page = @wiki.find_or_new_page(params[:id])
|
||||
if @wiki.page_found_with_redirect?
|
||||
redirect_to params.update(:id => @page.title)
|
||||
end
|
||||
end
|
||||
|
||||
# Finds the requested page and returns a 404 error if it doesn't exist
|
||||
def find_existing_page
|
||||
@page = @wiki.find_page(params[:id])
|
||||
if @page.nil?
|
||||
render_404
|
||||
return
|
||||
end
|
||||
if @wiki.page_found_with_redirect?
|
||||
redirect_to params.update(:id => @page.title)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns true if the current user is allowed to edit the page, otherwise false
|
||||
def editable?(page = @page)
|
||||
page.editable_by?(User.current)
|
||||
end
|
||||
|
||||
# Returns the default content of a new wiki page
|
||||
def initial_page_content(page)
|
||||
helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
|
||||
extend helper unless self.instance_of?(helper)
|
||||
helper.instance_method(:initial_page_content).bind(self).call(page)
|
||||
end
|
||||
|
||||
def load_pages_for_index
|
||||
@pages = @wiki.pages.with_updated_on.reorder("#{WikiPage.table_name}.title").includes(:wiki => :project).includes(:parent).all
|
||||
end
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WikisController < ApplicationController
|
||||
menu_item :settings
|
||||
before_filter :find_project, :authorize
|
||||
|
||||
# Create or update a project's wiki
|
||||
def edit
|
||||
@wiki = @project.wiki || Wiki.new(:project => @project)
|
||||
@wiki.safe_attributes = params[:wiki]
|
||||
@wiki.save if request.post?
|
||||
end
|
||||
|
||||
# Delete a project's wiki
|
||||
def destroy
|
||||
if request.post? && params[:confirm] && @project.wiki
|
||||
@project.wiki.destroy
|
||||
redirect_to settings_project_path(@project, :tab => 'wiki')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,99 @@
|
|||
#####leave message fq
|
||||
class WordsController < ApplicationController
|
||||
|
||||
before_filter :find_user, :only => [:new, :create, :destroy, :more, :back]
|
||||
|
||||
def create
|
||||
if params[:new_form][:user_message].size>0
|
||||
unless params[:user_id].nil?
|
||||
message = params[:new_form][:user_message]
|
||||
@user.add_jour(User.current, message)
|
||||
# if a_message.size > 5
|
||||
# @message = a_message[-5, 5]
|
||||
# else
|
||||
# @message = a_message
|
||||
# end
|
||||
# @message_count = a_message.count
|
||||
end
|
||||
end
|
||||
@jour = @user.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
|
||||
respond_to do |format|
|
||||
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
JournalsForMessage.delete_message(params[:object_id])
|
||||
@jour = @user.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
# if a_message.size > 5
|
||||
# @message = a_message[-5, 5]
|
||||
# else
|
||||
# @message = a_message
|
||||
# end
|
||||
# @message_count = a_message.count
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
|
||||
if @jour
|
||||
user = @jour.user
|
||||
text = @jour.notes
|
||||
else
|
||||
user = @user
|
||||
text = []
|
||||
end
|
||||
# Replaces pre blocks with [...]
|
||||
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
||||
@content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
||||
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def more
|
||||
@jour = @user.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
@state = true
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def back
|
||||
@jour = @user.journals_for_messages
|
||||
@jour.each_with_index {|j,i| j.indice = i+1}
|
||||
@state = false
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_user
|
||||
if params[:user_id]
|
||||
@user = User.find(params[:user_id])
|
||||
end
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
|
||||
#######end of message
|
||||
end
|
|
@ -0,0 +1,128 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WorkflowsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin, :find_roles, :find_trackers
|
||||
|
||||
def index
|
||||
@workflow_counts = WorkflowTransition.count_by_tracker_and_role
|
||||
end
|
||||
|
||||
def edit
|
||||
@role = Role.find_by_id(params[:role_id]) if params[:role_id]
|
||||
@tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
|
||||
|
||||
if request.post?
|
||||
WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
|
||||
(params[:issue_status] || []).each { |status_id, transitions|
|
||||
transitions.each { |new_status_id, options|
|
||||
author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
|
||||
assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
|
||||
WorkflowTransition.create(:role_id => @role.id, :tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee)
|
||||
}
|
||||
}
|
||||
if @role.save
|
||||
redirect_to workflows_edit_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
|
||||
if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
|
||||
@statuses = @tracker.issue_statuses
|
||||
end
|
||||
@statuses ||= IssueStatus.sorted.all
|
||||
|
||||
if @tracker && @role && @statuses.any?
|
||||
workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all
|
||||
@workflows = {}
|
||||
@workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
|
||||
@workflows['author'] = workflows.select {|w| w.author}
|
||||
@workflows['assignee'] = workflows.select {|w| w.assignee}
|
||||
end
|
||||
end
|
||||
|
||||
def permissions
|
||||
@role = Role.find_by_id(params[:role_id]) if params[:role_id]
|
||||
@tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
|
||||
|
||||
if request.post? && @role && @tracker
|
||||
WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
|
||||
redirect_to workflows_permissions_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
|
||||
return
|
||||
end
|
||||
|
||||
@used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
|
||||
if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
|
||||
@statuses = @tracker.issue_statuses
|
||||
end
|
||||
@statuses ||= IssueStatus.sorted.all
|
||||
|
||||
if @role && @tracker
|
||||
@fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
|
||||
@custom_fields = @tracker.custom_fields
|
||||
|
||||
@permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w|
|
||||
h[w.old_status_id] ||= {}
|
||||
h[w.old_status_id][w.field_name] = w.rule
|
||||
h
|
||||
end
|
||||
@statuses.each {|status| @permissions[status.id] ||= {}}
|
||||
end
|
||||
end
|
||||
|
||||
def copy
|
||||
|
||||
if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
|
||||
@source_tracker = nil
|
||||
else
|
||||
@source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
|
||||
end
|
||||
if params[:source_role_id].blank? || params[:source_role_id] == 'any'
|
||||
@source_role = nil
|
||||
else
|
||||
@source_role = Role.find_by_id(params[:source_role_id].to_i)
|
||||
end
|
||||
|
||||
@target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
|
||||
@target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
|
||||
|
||||
if request.post?
|
||||
if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
|
||||
flash.now[:error] = l(:error_workflow_copy_source)
|
||||
elsif @target_trackers.blank? || @target_roles.blank?
|
||||
flash.now[:error] = l(:error_workflow_copy_target)
|
||||
else
|
||||
WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_roles
|
||||
@roles = Role.sorted.all
|
||||
end
|
||||
|
||||
def find_trackers
|
||||
@trackers = Tracker.sorted.all
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 AccountHelper
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 ActivitiesHelper
|
||||
def sort_activity_events(events)
|
||||
events_by_group = events.group_by(&:event_group)
|
||||
sorted_events = []
|
||||
events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event|
|
||||
if group_events = events_by_group.delete(event.event_group)
|
||||
group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i|
|
||||
sorted_events << [e, i > 0]
|
||||
end
|
||||
end
|
||||
end
|
||||
sorted_events
|
||||
end
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 AdminHelper
|
||||
def project_status_options_for_select(selected)
|
||||
options_for_select([[l(:label_all), ''],
|
||||
[l(:project_status_active), '1'],
|
||||
[l(:project_status_closed), '5'],
|
||||
[l(:project_status_archived), '9']], selected.to_s)
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,47 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module AttachmentsHelper
|
||||
# Displays view/delete links to the attachments of the given object
|
||||
# Options:
|
||||
# :author -- author names are not displayed if set to false
|
||||
# :thumbails -- display thumbnails if enabled in settings
|
||||
def link_to_attachments(container, options = {})
|
||||
options.assert_valid_keys(:author, :thumbnails)
|
||||
|
||||
if container.attachments.any?
|
||||
options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
|
||||
render :partial => 'attachments/links',
|
||||
:locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)}
|
||||
end
|
||||
end
|
||||
|
||||
def render_api_attachment(attachment, api)
|
||||
api.attachment do
|
||||
api.id attachment.id
|
||||
api.filename attachment.filename
|
||||
api.filesize attachment.filesize
|
||||
api.content_type attachment.content_type
|
||||
api.description attachment.description
|
||||
api.content_url url_for(:controller => 'attachments', :action => 'download', :id => attachment, :filename => attachment.filename, :only_path => false)
|
||||
api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author
|
||||
api.created_on attachment.created_on
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,24 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 AuthSourcesHelper
|
||||
def auth_source_partial_name(auth_source)
|
||||
"form_#{auth_source.class.name.underscore}"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,52 @@
|
|||
module AvatarHelper
|
||||
|
||||
AVATAR_SIZE="50x50"
|
||||
|
||||
def avatar_image(source)
|
||||
File.join(relative_path, avatar_directory(source.class), source.id.to_s)
|
||||
end
|
||||
|
||||
def relative_path
|
||||
"avatars" #File.join("images","avatars")
|
||||
end
|
||||
|
||||
def storage_path
|
||||
File.join(Rails.root, "public", "images", relative_path)
|
||||
end
|
||||
|
||||
def avatar_directory(source_type)
|
||||
"#{source_type}"
|
||||
end
|
||||
|
||||
def avatar_filename(source_id,image_file)
|
||||
"#{source_id}" #<< file_extension(image_file)
|
||||
end
|
||||
|
||||
def disk_filename(source_type,source_id,image_file=nil)
|
||||
File.join(storage_path,avatar_directory(source_type),avatar_filename(source_id,image_file))
|
||||
end
|
||||
|
||||
def file_extension(filename=nil)
|
||||
$1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
|
||||
end
|
||||
|
||||
def get_avatar(source)
|
||||
if source.nil?
|
||||
return File.join(relative_path,'AnonymousUser','0')
|
||||
end
|
||||
if File.exist?(disk_filename(source.class,source.id))
|
||||
avatar_image(source)
|
||||
else
|
||||
File.join(relative_path,avatar_directory(source.class),'0')
|
||||
end
|
||||
end
|
||||
|
||||
def get_avatar?(source)
|
||||
if File.exist?(disk_filename(source.class,source.id))
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,32 @@
|
|||
module BidsHelper
|
||||
def render_notes(bid, journal, options={})
|
||||
content = ''
|
||||
removable = User.current == journal.user || User.current == bid.author
|
||||
links = []
|
||||
if !journal.notes.blank?
|
||||
links << link_to(image_tag('comment.png'),
|
||||
{:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal},
|
||||
:remote => true,
|
||||
:method => 'post',
|
||||
:title => l(:button_quote)) if options[:reply_links]
|
||||
if removable
|
||||
url = {:controller => 'bids',
|
||||
:action => 'destroy',
|
||||
:object_id => journal,
|
||||
:bid_id => bid}
|
||||
links << ' '
|
||||
links << link_to(image_tag('delete.png'), url,
|
||||
:remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete))
|
||||
end
|
||||
end
|
||||
content << content_tag('div', links.join(' ').html_safe, :class => 'contextual') unless links.empty?
|
||||
content << textilizable(journal.notes)
|
||||
css_classes = "wiki"
|
||||
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
|
||||
end
|
||||
|
||||
def link_to_in_place_notes_editor(text, field_id, url, options={})
|
||||
onclick = "$.ajax({url: '#{url_for(url)}', type: 'get'}); return false;"
|
||||
link_to text, '#', options.merge(:onclick => onclick)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 BoardsHelper
|
||||
def board_breadcrumb(item)
|
||||
board = item.is_a?(Message) ? item.board : item
|
||||
links = [link_to(l(:label_board_plural), project_boards_path(item.project))]
|
||||
boards = board.ancestors.reverse
|
||||
if item.is_a?(Message)
|
||||
boards << board
|
||||
end
|
||||
links += boards.map {|ancestor| link_to(h(ancestor.name), project_board_path(ancestor.project, ancestor))}
|
||||
breadcrumb links
|
||||
end
|
||||
|
||||
def boards_options_for_select(boards)
|
||||
options = []
|
||||
Board.board_tree(boards) do |board, level|
|
||||
label = (level > 0 ? ' ' * 2 * level + '» ' : '').html_safe
|
||||
label << board.name
|
||||
options << [label, board.id]
|
||||
end
|
||||
options
|
||||
end
|
||||
end
|
|
@ -0,0 +1,58 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 CalendarsHelper
|
||||
def link_to_previous_month(year, month, options={})
|
||||
target_year, target_month = if month == 1
|
||||
[year - 1, 12]
|
||||
else
|
||||
[year, month - 1]
|
||||
end
|
||||
|
||||
name = if target_month == 12
|
||||
"#{month_name(target_month)} #{target_year}"
|
||||
else
|
||||
"#{month_name(target_month)}"
|
||||
end
|
||||
|
||||
# \xc2\xab(utf-8) = «
|
||||
link_to_month(("\xc2\xab " + name), target_year, target_month, options)
|
||||
end
|
||||
|
||||
def link_to_next_month(year, month, options={})
|
||||
target_year, target_month = if month == 12
|
||||
[year + 1, 1]
|
||||
else
|
||||
[year, month + 1]
|
||||
end
|
||||
|
||||
name = if target_month == 1
|
||||
"#{month_name(target_month)} #{target_year}"
|
||||
else
|
||||
"#{month_name(target_month)}"
|
||||
end
|
||||
|
||||
# \xc2\xbb(utf-8) = »
|
||||
link_to_month((name + " \xc2\xbb"), target_year, target_month, options)
|
||||
end
|
||||
|
||||
def link_to_month(link_name, year, month, options={})
|
||||
link_to_content_update(h(link_name), params.merge(:year => year, :month => month))
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 ContextMenusHelper
|
||||
def context_menu_link(name, url, options={})
|
||||
options[:class] ||= ''
|
||||
if options.delete(:selected)
|
||||
options[:class] << ' icon-checked disabled'
|
||||
options[:disabled] = true
|
||||
end
|
||||
if options.delete(:disabled)
|
||||
options.delete(:method)
|
||||
options.delete(:data)
|
||||
options[:onclick] = 'return false;'
|
||||
options[:class] << ' disabled'
|
||||
url = '#'
|
||||
end
|
||||
link_to h(name), url, options
|
||||
end
|
||||
|
||||
def bulk_update_custom_field_context_menu_link(field, text, value)
|
||||
context_menu_link h(text),
|
||||
bulk_update_issues_path(:ids => @issue_ids, :issue => {'custom_field_values' => {field.id => value}}, :back_url => @back),
|
||||
:method => :post,
|
||||
:selected => (@issue && @issue.custom_field_value(field) == value)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,149 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module CustomFieldsHelper
|
||||
|
||||
def custom_fields_tabs
|
||||
CustomField::CUSTOM_FIELDS_TABS
|
||||
end
|
||||
|
||||
# Return custom field html tag corresponding to its format
|
||||
def custom_field_tag(name, custom_value)
|
||||
custom_field = custom_value.custom_field
|
||||
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||||
field_name << "[]" if custom_field.multiple?
|
||||
field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||||
|
||||
tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"}
|
||||
|
||||
field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
|
||||
case field_format.try(:edit_as)
|
||||
when "date"
|
||||
text_field_tag(field_name, custom_value.value, tag_options.merge(:size => 10)) +
|
||||
calendar_for(field_id)
|
||||
when "text"
|
||||
text_area_tag(field_name, custom_value.value, tag_options.merge(:rows => 3))
|
||||
when "bool"
|
||||
hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, tag_options)
|
||||
when "list"
|
||||
blank_option = ''.html_safe
|
||||
unless custom_field.multiple?
|
||||
if custom_field.is_required?
|
||||
unless custom_field.default_value.present?
|
||||
blank_option = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '')
|
||||
end
|
||||
else
|
||||
blank_option = content_tag('option')
|
||||
end
|
||||
end
|
||||
s = select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value),
|
||||
tag_options.merge(:multiple => custom_field.multiple?))
|
||||
if custom_field.multiple?
|
||||
s << hidden_field_tag(field_name, '')
|
||||
end
|
||||
s
|
||||
else
|
||||
text_field_tag(field_name, custom_value.value, tag_options)
|
||||
end
|
||||
end
|
||||
|
||||
# Return custom field label tag
|
||||
def custom_field_label_tag(name, custom_value, options={})
|
||||
required = options[:required] || custom_value.custom_field.is_required?
|
||||
|
||||
content_tag "label", h(custom_value.custom_field.name) +
|
||||
(required ? " <span class=\"required\">*</span>".html_safe : ""),
|
||||
:for => "#{name}_custom_field_values_#{custom_value.custom_field.id}"
|
||||
end
|
||||
|
||||
# Return custom field tag with its label tag
|
||||
def custom_field_tag_with_label(name, custom_value, options={})
|
||||
custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value)
|
||||
end
|
||||
|
||||
def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil)
|
||||
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||||
field_name << "[]" if custom_field.multiple?
|
||||
field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||||
|
||||
tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"}
|
||||
|
||||
field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
|
||||
case field_format.try(:edit_as)
|
||||
when "date"
|
||||
text_field_tag(field_name, '', tag_options.merge(:size => 10)) +
|
||||
calendar_for(field_id)
|
||||
when "text"
|
||||
text_area_tag(field_name, '', tag_options.merge(:rows => 3))
|
||||
when "bool"
|
||||
select_tag(field_name, options_for_select([[l(:label_no_change_option), ''],
|
||||
[l(:general_text_yes), '1'],
|
||||
[l(:general_text_no), '0']]), tag_options)
|
||||
when "list"
|
||||
options = []
|
||||
options << [l(:label_no_change_option), ''] unless custom_field.multiple?
|
||||
options << [l(:label_none), '__none__'] unless custom_field.is_required?
|
||||
options += custom_field.possible_values_options(projects)
|
||||
select_tag(field_name, options_for_select(options), tag_options.merge(:multiple => custom_field.multiple?))
|
||||
else
|
||||
text_field_tag(field_name, '', tag_options)
|
||||
end
|
||||
end
|
||||
|
||||
# Return a string used to display a custom value
|
||||
def show_value(custom_value)
|
||||
return "" unless custom_value
|
||||
format_value(custom_value.value, custom_value.custom_field.field_format)
|
||||
end
|
||||
|
||||
# Return a string used to display a custom value
|
||||
def format_value(value, field_format)
|
||||
if value.is_a?(Array)
|
||||
value.collect {|v| format_value(v, field_format)}.compact.sort.join(', ')
|
||||
else
|
||||
Redmine::CustomFieldFormat.format_value(value, field_format)
|
||||
end
|
||||
end
|
||||
|
||||
# Return an array of custom field formats which can be used in select_tag
|
||||
def custom_field_formats_for_select(custom_field)
|
||||
Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name)
|
||||
end
|
||||
|
||||
# Renders the custom_values in api views
|
||||
def render_api_custom_values(custom_values, api)
|
||||
api.array :custom_fields do
|
||||
custom_values.each do |custom_value|
|
||||
attrs = {:id => custom_value.custom_field_id, :name => custom_value.custom_field.name}
|
||||
attrs.merge!(:multiple => true) if custom_value.custom_field.multiple?
|
||||
api.custom_field attrs do
|
||||
if custom_value.value.is_a?(Array)
|
||||
api.array :value do
|
||||
custom_value.value.each do |value|
|
||||
api.value value unless value.blank?
|
||||
end
|
||||
end
|
||||
else
|
||||
api.value custom_value.value
|
||||
end
|
||||
end
|
||||
end
|
||||
end unless custom_values.empty?
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 DocumentsHelper
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 EnumerationsHelper
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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').html_safe
|
||||
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').html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module GroupsHelper
|
||||
def group_settings_tabs
|
||||
tabs = [{:name => 'general', :partial => 'groups/general', :label => :label_general},
|
||||
{:name => 'users', :partial => 'groups/users', :label => :label_user_plural},
|
||||
{:name => 'memberships', :partial => 'groups/memberships', :label => :label_project_plural}
|
||||
]
|
||||
end
|
||||
|
||||
def render_principals_for_new_group_users(group)
|
||||
scope = User.active.sorted.not_in_group(group).like(params[:q])
|
||||
principal_count = scope.count
|
||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, 100, params['page']
|
||||
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
||||
|
||||
s = content_tag('div', principals_check_box_tags('user_ids[]', principals), :id => 'principals')
|
||||
|
||||
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
|
||||
link_to text, autocomplete_for_user_group_path(group, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
||||
}
|
||||
|
||||
s + content_tag('p', links, :class => 'pagination')
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 IssueCategoriesHelper
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module IssueRelationsHelper
|
||||
def collection_for_relation_type_select
|
||||
values = IssueRelation::TYPES
|
||||
values.keys.sort{|x,y| values[x][:order] <=> values[y][:order]}.collect{|k| [l(values[k][:name]), k]}
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 IssueStatusesHelper
|
||||
end
|
|
@ -0,0 +1,383 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 IssuesHelper
|
||||
include ApplicationHelper
|
||||
|
||||
def issue_list(issues, &block)
|
||||
ancestors = []
|
||||
issues.each do |issue|
|
||||
while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
|
||||
ancestors.pop
|
||||
end
|
||||
yield issue, ancestors.size
|
||||
ancestors << issue unless issue.leaf?
|
||||
end
|
||||
end
|
||||
|
||||
# Renders a HTML/CSS tooltip
|
||||
#
|
||||
# To use, a trigger div is needed. This is a div with the class of "tooltip"
|
||||
# that contains this method wrapped in a span with the class of "tip"
|
||||
#
|
||||
# <div class="tooltip"><%= link_to_issue(issue) %>
|
||||
# <span class="tip"><%= render_issue_tooltip(issue) %></span>
|
||||
# </div>
|
||||
#
|
||||
def render_issue_tooltip(issue)
|
||||
@cached_label_status ||= l(:field_status)
|
||||
@cached_label_start_date ||= l(:field_start_date)
|
||||
@cached_label_due_date ||= l(:field_due_date)
|
||||
@cached_label_assigned_to ||= l(:field_assigned_to)
|
||||
@cached_label_priority ||= l(:field_priority)
|
||||
@cached_label_project ||= l(:field_project)
|
||||
|
||||
link_to_issue(issue) + "<br /><br />".html_safe +
|
||||
"<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
|
||||
"<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
|
||||
"<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
|
||||
"<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
|
||||
"<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
|
||||
"<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
|
||||
end
|
||||
|
||||
def issue_heading(issue)
|
||||
h("#{issue.tracker} ##{issue.id}")
|
||||
end
|
||||
|
||||
def render_issue_subject_with_tree(issue)
|
||||
s = ''
|
||||
ancestors = issue.root? ? [] : issue.ancestors.visible.all
|
||||
ancestors.each do |ancestor|
|
||||
s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
|
||||
end
|
||||
s << '<div>'
|
||||
subject = h(issue.subject)
|
||||
if issue.is_private?
|
||||
subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
|
||||
end
|
||||
s << content_tag('h3', subject)
|
||||
s << '</div>' * (ancestors.size + 1)
|
||||
s.html_safe
|
||||
end
|
||||
|
||||
def render_descendants_tree(issue)
|
||||
s = '<form><table class="list issues">'
|
||||
issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
|
||||
css = "issue issue-#{child.id} hascontextmenu"
|
||||
css << " idnt idnt-#{level}" if level > 0
|
||||
s << content_tag('tr',
|
||||
content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
|
||||
content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') +
|
||||
content_tag('td', h(child.status)) +
|
||||
content_tag('td', link_to_user(child.assigned_to)) +
|
||||
content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
|
||||
:class => css)
|
||||
end
|
||||
s << '</table></form>'
|
||||
s.html_safe
|
||||
end
|
||||
|
||||
# Returns a link for adding a new subtask to the given issue
|
||||
def link_to_new_subtask(issue)
|
||||
attrs = {
|
||||
:tracker_id => issue.tracker,
|
||||
:parent_issue_id => issue
|
||||
}
|
||||
link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
|
||||
end
|
||||
|
||||
class IssueFieldsRows
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
def initialize
|
||||
@left = []
|
||||
@right = []
|
||||
end
|
||||
|
||||
def left(*args)
|
||||
args.any? ? @left << cells(*args) : @left
|
||||
end
|
||||
|
||||
def right(*args)
|
||||
args.any? ? @right << cells(*args) : @right
|
||||
end
|
||||
|
||||
def size
|
||||
@left.size > @right.size ? @left.size : @right.size
|
||||
end
|
||||
|
||||
def to_html
|
||||
html = ''.html_safe
|
||||
blank = content_tag('th', '') + content_tag('td', '')
|
||||
size.times do |i|
|
||||
left = @left[i] || blank
|
||||
right = @right[i] || blank
|
||||
html << content_tag('tr', left + right)
|
||||
end
|
||||
html
|
||||
end
|
||||
|
||||
def cells(label, text, options={})
|
||||
content_tag('th', "#{label}:", options) + content_tag('td', text, options)
|
||||
end
|
||||
end
|
||||
|
||||
def issue_fields_rows
|
||||
r = IssueFieldsRows.new
|
||||
yield r
|
||||
r.to_html
|
||||
end
|
||||
|
||||
def render_custom_fields_rows(issue)
|
||||
return if issue.custom_field_values.empty?
|
||||
ordered_values = []
|
||||
half = (issue.custom_field_values.size / 2.0).ceil
|
||||
half.times do |i|
|
||||
ordered_values << issue.custom_field_values[i]
|
||||
ordered_values << issue.custom_field_values[i + half]
|
||||
end
|
||||
s = "<tr>\n"
|
||||
n = 0
|
||||
ordered_values.compact.each do |value|
|
||||
s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
|
||||
s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
|
||||
n += 1
|
||||
end
|
||||
s << "</tr>\n"
|
||||
s.html_safe
|
||||
end
|
||||
|
||||
def issues_destroy_confirmation_message(issues)
|
||||
issues = [issues] unless issues.is_a?(Array)
|
||||
message = l(:text_issues_destroy_confirmation)
|
||||
descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
|
||||
if descendant_count > 0
|
||||
issues.each do |issue|
|
||||
next if issue.root?
|
||||
issues.each do |other_issue|
|
||||
descendant_count -= 1 if issue.is_descendant_of?(other_issue)
|
||||
end
|
||||
end
|
||||
if descendant_count > 0
|
||||
message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
|
||||
end
|
||||
end
|
||||
message
|
||||
end
|
||||
|
||||
def sidebar_queries
|
||||
unless @sidebar_queries
|
||||
@sidebar_queries = IssueQuery.visible.all(
|
||||
:order => "#{Query.table_name}.name ASC",
|
||||
# Project specific queries and global queries
|
||||
:conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
|
||||
)
|
||||
end
|
||||
@sidebar_queries
|
||||
end
|
||||
|
||||
def query_links(title, queries)
|
||||
# links to #index on issues/show
|
||||
url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
|
||||
|
||||
content_tag('h3', h(title)) +
|
||||
queries.collect {|query|
|
||||
css = 'query'
|
||||
css << ' selected' if query == @query
|
||||
link_to(h(query.name), url_params.merge(:query_id => query), :class => css)
|
||||
}.join('<br />').html_safe
|
||||
end
|
||||
|
||||
def render_sidebar_queries
|
||||
out = ''.html_safe
|
||||
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
|
||||
|
||||
# Returns the textual representation of a journal details
|
||||
# as an array of strings
|
||||
def details_to_strings(details, no_html=false, options={})
|
||||
options[:only_path] = (options[:only_path] == false ? false : true)
|
||||
strings = []
|
||||
values_by_field = {}
|
||||
details.each do |detail|
|
||||
if detail.property == 'cf'
|
||||
field_id = detail.prop_key
|
||||
field = CustomField.find_by_id(field_id)
|
||||
if field && field.multiple?
|
||||
values_by_field[field_id] ||= {:added => [], :deleted => []}
|
||||
if detail.old_value
|
||||
values_by_field[field_id][:deleted] << detail.old_value
|
||||
end
|
||||
if detail.value
|
||||
values_by_field[field_id][:added] << detail.value
|
||||
end
|
||||
next
|
||||
end
|
||||
end
|
||||
strings << show_detail(detail, no_html, options)
|
||||
end
|
||||
values_by_field.each do |field_id, changes|
|
||||
detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
|
||||
if changes[:added].any?
|
||||
detail.value = changes[:added]
|
||||
strings << show_detail(detail, no_html, options)
|
||||
elsif changes[:deleted].any?
|
||||
detail.old_value = changes[:deleted]
|
||||
strings << show_detail(detail, no_html, options)
|
||||
end
|
||||
end
|
||||
strings
|
||||
end
|
||||
|
||||
# Returns the textual representation of a single journal detail
|
||||
def show_detail(detail, no_html=false, options={})
|
||||
multiple = false
|
||||
case detail.property
|
||||
when 'attr'
|
||||
field = detail.prop_key.to_s.gsub(/\_id$/, "")
|
||||
label = l(("field_" + field).to_sym)
|
||||
case detail.prop_key
|
||||
when 'due_date', 'start_date'
|
||||
value = format_date(detail.value.to_date) if detail.value
|
||||
old_value = format_date(detail.old_value.to_date) if detail.old_value
|
||||
|
||||
when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
|
||||
'priority_id', 'category_id', 'fixed_version_id'
|
||||
value = find_name_by_reflection(field, detail.value)
|
||||
old_value = find_name_by_reflection(field, detail.old_value)
|
||||
|
||||
when 'estimated_hours'
|
||||
value = "%0.02f" % detail.value.to_f unless detail.value.blank?
|
||||
old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
|
||||
|
||||
when 'parent_id'
|
||||
label = l(:field_parent_issue)
|
||||
value = "##{detail.value}" unless detail.value.blank?
|
||||
old_value = "##{detail.old_value}" unless detail.old_value.blank?
|
||||
|
||||
when 'is_private'
|
||||
value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
|
||||
old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
|
||||
end
|
||||
when 'cf'
|
||||
custom_field = CustomField.find_by_id(detail.prop_key)
|
||||
if custom_field
|
||||
multiple = custom_field.multiple?
|
||||
label = custom_field.name
|
||||
value = format_value(detail.value, custom_field.field_format) if detail.value
|
||||
old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
|
||||
end
|
||||
when 'attachment'
|
||||
label = l(:label_attachment)
|
||||
end
|
||||
call_hook(:helper_issues_show_detail_after_setting,
|
||||
{:detail => detail, :label => label, :value => value, :old_value => old_value })
|
||||
|
||||
label ||= detail.prop_key
|
||||
value ||= detail.value
|
||||
old_value ||= detail.old_value
|
||||
|
||||
unless no_html
|
||||
label = content_tag('strong', label)
|
||||
old_value = content_tag("i", h(old_value)) if detail.old_value
|
||||
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
|
||||
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
|
||||
# Link to the attachment if it has not been removed
|
||||
value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
|
||||
if options[:only_path] != false && atta.is_text?
|
||||
value += link_to(
|
||||
image_tag('magnifier.png'),
|
||||
:controller => 'attachments', :action => 'show',
|
||||
:id => atta, :filename => atta.filename
|
||||
)
|
||||
end
|
||||
else
|
||||
value = content_tag("i", h(value)) if value
|
||||
end
|
||||
end
|
||||
|
||||
if detail.property == 'attr' && detail.prop_key == 'description'
|
||||
s = l(:text_journal_changed_no_detail, :label => label)
|
||||
unless no_html
|
||||
diff_link = link_to 'diff',
|
||||
{:controller => 'journals', :action => 'diff', :id => detail.journal_id,
|
||||
:detail_id => detail.id, :only_path => options[:only_path]},
|
||||
:title => l(:label_view_diff)
|
||||
s << " (#{ diff_link })"
|
||||
end
|
||||
s.html_safe
|
||||
elsif detail.value.present?
|
||||
case detail.property
|
||||
when 'attr', 'cf'
|
||||
if detail.old_value.present?
|
||||
l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
|
||||
elsif multiple
|
||||
l(:text_journal_added, :label => label, :value => value).html_safe
|
||||
else
|
||||
l(:text_journal_set_to, :label => label, :value => value).html_safe
|
||||
end
|
||||
when 'attachment'
|
||||
l(:text_journal_added, :label => label, :value => value).html_safe
|
||||
end
|
||||
else
|
||||
l(:text_journal_deleted, :label => label, :old => old_value).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
# Find the name of an associated record stored in the field attribute
|
||||
def find_name_by_reflection(field, id)
|
||||
unless id.present?
|
||||
return nil
|
||||
end
|
||||
association = Issue.reflect_on_association(field.to_sym)
|
||||
if association
|
||||
record = association.class_name.constantize.find_by_id(id)
|
||||
if record
|
||||
record.name.force_encoding('UTF-8') if record.name.respond_to?(:force_encoding)
|
||||
return record.name
|
||||
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
|
||||
|
||||
# this method is used to get all projects that tagged one tag
|
||||
# added by william
|
||||
def get_issues_by_tag(tag_name)
|
||||
Issue.tagged_with(tag_name)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,46 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module JournalsHelper
|
||||
def render_notes(issue, journal, options={})
|
||||
content = ''
|
||||
editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project)))
|
||||
links = []
|
||||
if !journal.notes.blank?
|
||||
links << link_to(image_tag('comment.png'),
|
||||
{:controller => 'journals', :action => 'new', :id => issue, :journal_id => journal},
|
||||
:remote => true,
|
||||
:method => 'post',
|
||||
:title => l(:button_quote)) if options[:reply_links]
|
||||
links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
|
||||
{ :controller => 'journals', :action => 'edit', :id => journal, :format => 'js' },
|
||||
:title => l(:button_edit)) if editable
|
||||
end
|
||||
content << content_tag('div', links.join(' ').html_safe, :class => 'contextual') unless links.empty?
|
||||
content << textilizable(journal, :notes)
|
||||
css_classes = "wiki"
|
||||
css_classes << " editable" if editable
|
||||
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
|
||||
end
|
||||
|
||||
def link_to_in_place_notes_editor(text, field_id, url, options={})
|
||||
onclick = "$.ajax({url: '#{url_for(url)}', type: 'get'}); return false;"
|
||||
link_to text, '#', options.merge(:onclick => onclick)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module MailHandlerHelper
|
||||
end
|
|
@ -0,0 +1,35 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 MembersHelper
|
||||
def render_principals_for_new_members(project)
|
||||
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
||||
principal_count = scope.count
|
||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']#by young
|
||||
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
||||
|
||||
s = content_tag('div', principals_check_box_tags('membership[user_ids][]', principals), :id => 'principals')
|
||||
|
||||
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
|
||||
link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
||||
}
|
||||
|
||||
s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module MessagesHelper
|
||||
end
|
|
@ -0,0 +1,72 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 MyHelper
|
||||
include AvatarHelper
|
||||
def calendar_items(startdt, enddt)
|
||||
Issue.visible.
|
||||
where(:project_id => User.current.projects.map(&:id)).
|
||||
where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", startdt, enddt, startdt, enddt).
|
||||
includes(:project, :tracker, :priority, :assigned_to).
|
||||
all
|
||||
end
|
||||
|
||||
def documents_items
|
||||
Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).all
|
||||
end
|
||||
|
||||
def issuesassignedtome_items
|
||||
Issue.visible.open.
|
||||
where(:assigned_to_id => ([User.current.id] + User.current.group_ids)).
|
||||
limit(10).
|
||||
includes(:status, :project, :tracker, :priority).
|
||||
order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC").
|
||||
all
|
||||
end
|
||||
|
||||
def issuesreportedbyme_items
|
||||
Issue.visible.
|
||||
where(:author_id => User.current.id).
|
||||
limit(10).
|
||||
includes(:status, :project, :tracker).
|
||||
order("#{Issue.table_name}.updated_on DESC").
|
||||
all
|
||||
end
|
||||
|
||||
def issueswatched_items
|
||||
Issue.visible.on_active_project.watched_by(User.current.id).recently_updated.limit(10).all
|
||||
end
|
||||
|
||||
def news_items
|
||||
News.visible.
|
||||
where(:project_id => User.current.projects.map(&:id)).
|
||||
limit(10).
|
||||
includes(:project, :author).
|
||||
order("#{News.table_name}.created_on DESC").
|
||||
all
|
||||
end
|
||||
|
||||
def timelog_items
|
||||
TimeEntry.
|
||||
where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, Date.today - 6, Date.today).
|
||||
includes(:activity, :project, {:issue => [:tracker, :status]}).
|
||||
order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC").
|
||||
all
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 NewsHelper
|
||||
end
|
|
@ -0,0 +1,91 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module ProjectsHelper
|
||||
def link_to_version(version, options = {})
|
||||
return '' unless version && version.is_a?(Version)
|
||||
link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
|
||||
end
|
||||
|
||||
def project_settings_tabs
|
||||
tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
|
||||
{:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
|
||||
{:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
|
||||
{:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
|
||||
{:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
|
||||
{:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
|
||||
{:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
|
||||
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
|
||||
{:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
|
||||
]
|
||||
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
||||
end
|
||||
|
||||
def parent_project_select_tag(project)
|
||||
selected = project.parent
|
||||
# retrieve the requested parent project
|
||||
parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
|
||||
if parent_id
|
||||
selected = (parent_id.blank? ? nil : Project.find(parent_id))
|
||||
end
|
||||
|
||||
options = ''
|
||||
options << "<option value=''></option>" if project.allowed_parents.include?(nil)
|
||||
options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
|
||||
content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id')
|
||||
end
|
||||
|
||||
# Renders the projects index
|
||||
def render_project_hierarchy(projects)
|
||||
render_project_nested_lists(projects) do |project|
|
||||
s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}")
|
||||
if project.description.present?
|
||||
#Delete by nie.
|
||||
# s << content_tag('td', textilizable(project.short_description, :project => project), :class => 'wiki description')
|
||||
end
|
||||
s
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a set of options for a select field, grouped by project.
|
||||
def version_options_for_select(versions, selected=nil)
|
||||
grouped = Hash.new {|h,k| h[k] = []}
|
||||
versions.each do |version|
|
||||
grouped[version.project.name] << [version.name, version.id]
|
||||
end
|
||||
|
||||
if grouped.keys.size > 1
|
||||
grouped_options_for_select(grouped, selected && selected.id)
|
||||
else
|
||||
options_for_select((grouped.values.first || []), selected && selected.id)
|
||||
end
|
||||
end
|
||||
|
||||
def format_version_sharing(sharing)
|
||||
sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
|
||||
l("label_version_sharing_#{sharing}")
|
||||
end
|
||||
|
||||
# this method is used to get all projects that tagged one tag
|
||||
# added by william
|
||||
def get_projects_by_tag(tag_name)
|
||||
Project.tagged_with(tag_name)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,223 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module QueriesHelper
|
||||
def filters_options_for_select(query)
|
||||
options_for_select(filters_options(query))
|
||||
end
|
||||
|
||||
def filters_options(query)
|
||||
options = [[]]
|
||||
options += query.available_filters.map do |field, field_options|
|
||||
[field_options[:name], field]
|
||||
end
|
||||
end
|
||||
|
||||
def query_filters_hidden_tags(query)
|
||||
tags = ''.html_safe
|
||||
query.filters.each do |field, options|
|
||||
tags << hidden_field_tag("f[]", field, :id => nil)
|
||||
tags << hidden_field_tag("op[#{field}]", options[:operator], :id => nil)
|
||||
options[:values].each do |value|
|
||||
tags << hidden_field_tag("v[#{field}][]", value, :id => nil)
|
||||
end
|
||||
end
|
||||
tags
|
||||
end
|
||||
|
||||
def query_columns_hidden_tags(query)
|
||||
tags = ''.html_safe
|
||||
query.columns.each do |column|
|
||||
tags << hidden_field_tag("c[]", column.name, :id => nil)
|
||||
end
|
||||
tags
|
||||
end
|
||||
|
||||
def query_hidden_tags(query)
|
||||
query_filters_hidden_tags(query) + query_columns_hidden_tags(query)
|
||||
end
|
||||
|
||||
def available_block_columns_tags(query)
|
||||
tags = ''.html_safe
|
||||
query.available_block_columns.each do |column|
|
||||
tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline')
|
||||
end
|
||||
tags
|
||||
end
|
||||
|
||||
def query_available_inline_columns_options(query)
|
||||
(query.available_inline_columns - query.columns).reject(&:frozen?).collect {|column| [column.caption, column.name]}
|
||||
end
|
||||
|
||||
def query_selected_inline_columns_options(query)
|
||||
(query.inline_columns & query.available_inline_columns).reject(&:frozen?).collect {|column| [column.caption, column.name]}
|
||||
end
|
||||
|
||||
def render_query_columns_selection(query, options={})
|
||||
tag_name = (options[:name] || 'c') + '[]'
|
||||
render :partial => 'queries/columns', :locals => {:query => query, :tag_name => tag_name}
|
||||
end
|
||||
|
||||
def column_header(column)
|
||||
column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
|
||||
:default_order => column.default_order) :
|
||||
content_tag('th', h(column.caption))
|
||||
end
|
||||
|
||||
def column_content(column, issue)
|
||||
value = column.value(issue)
|
||||
if value.is_a?(Array)
|
||||
value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
|
||||
else
|
||||
column_value(column, issue, value)
|
||||
end
|
||||
end
|
||||
|
||||
def column_value(column, issue, value)
|
||||
case value.class.name
|
||||
when 'String'
|
||||
if column.name == :subject
|
||||
link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
|
||||
elsif column.name == :description
|
||||
issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
|
||||
else
|
||||
h(value)
|
||||
end
|
||||
when 'Time'
|
||||
format_time(value)
|
||||
when 'Date'
|
||||
format_date(value)
|
||||
when 'Fixnum'
|
||||
if column.name == :id
|
||||
link_to value, issue_path(issue)
|
||||
elsif column.name == :done_ratio
|
||||
progress_bar(value, :width => '80px')
|
||||
else
|
||||
value.to_s
|
||||
end
|
||||
when 'Float'
|
||||
sprintf "%.2f", value
|
||||
when 'User'
|
||||
link_to_user value
|
||||
when 'Project'
|
||||
link_to_project value
|
||||
when 'Version'
|
||||
link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
|
||||
when 'TrueClass'
|
||||
l(:general_text_Yes)
|
||||
when 'FalseClass'
|
||||
l(:general_text_No)
|
||||
when 'Issue'
|
||||
value.visible? ? link_to_issue(value) : "##{value.id}"
|
||||
when 'IssueRelation'
|
||||
other = value.other_issue(issue)
|
||||
content_tag('span',
|
||||
(l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe,
|
||||
:class => value.css_classes_for(issue))
|
||||
else
|
||||
h(value)
|
||||
end
|
||||
end
|
||||
|
||||
def csv_content(column, issue)
|
||||
value = column.value(issue)
|
||||
if value.is_a?(Array)
|
||||
value.collect {|v| csv_value(column, issue, v)}.compact.join(', ')
|
||||
else
|
||||
csv_value(column, issue, value)
|
||||
end
|
||||
end
|
||||
|
||||
def csv_value(column, issue, value)
|
||||
case value.class.name
|
||||
when 'Time'
|
||||
format_time(value)
|
||||
when 'Date'
|
||||
format_date(value)
|
||||
when 'Float'
|
||||
sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
|
||||
when 'IssueRelation'
|
||||
other = value.other_issue(issue)
|
||||
l(value.label_for(issue)) + " ##{other.id}"
|
||||
else
|
||||
value.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def query_to_csv(items, query, options={})
|
||||
encoding = l(:general_csv_encoding)
|
||||
columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
|
||||
query.available_block_columns.each do |column|
|
||||
if options[column.name].present?
|
||||
columns << column
|
||||
end
|
||||
end
|
||||
|
||||
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||
# csv header fields
|
||||
csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) }
|
||||
# csv lines
|
||||
items.each do |item|
|
||||
csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, item), encoding) }
|
||||
end
|
||||
end
|
||||
export
|
||||
end
|
||||
|
||||
# Retrieve query from session or build a new query
|
||||
def retrieve_query
|
||||
if !params[:query_id].blank?
|
||||
cond = "project_id IS NULL"
|
||||
cond << " OR project_id = #{@project.id}" if @project
|
||||
@query = IssueQuery.find(params[:query_id], :conditions => cond)
|
||||
raise ::Unauthorized unless @query.visible?
|
||||
@query.project = @project
|
||||
session[:query] = {:id => @query.id, :project_id => @query.project_id}
|
||||
sort_clear
|
||||
elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
|
||||
# Give it a name, required to be valid
|
||||
@query = IssueQuery.new(:name => "_")
|
||||
@query.project = @project
|
||||
@query.build_from_params(params)
|
||||
session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
|
||||
else
|
||||
# retrieve from session
|
||||
@query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
|
||||
@query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
|
||||
@query.project = @project
|
||||
end
|
||||
end
|
||||
|
||||
def retrieve_query_from_session
|
||||
if session[:query]
|
||||
if session[:query][:id]
|
||||
@query = IssueQuery.find_by_id(session[:query][:id])
|
||||
return unless @query
|
||||
else
|
||||
@query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
|
||||
end
|
||||
if session[:query].has_key?(:project_id)
|
||||
@query.project_id = session[:query][:project_id]
|
||||
else
|
||||
@query.project = @project
|
||||
end
|
||||
@query
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module ReportsHelper
|
||||
|
||||
def aggregate(data, criteria)
|
||||
a = 0
|
||||
data.each { |row|
|
||||
match = 1
|
||||
criteria.each { |k, v|
|
||||
match = 0 unless (row[k].to_s == v.to_s) || (k == 'closed' && row[k] == (v == 0 ? "f" : "t"))
|
||||
} unless criteria.nil?
|
||||
a = a + row["total"].to_i if match == 1
|
||||
} unless data.nil?
|
||||
a
|
||||
end
|
||||
|
||||
def aggregate_link(data, criteria, *args)
|
||||
a = aggregate data, criteria
|
||||
a > 0 ? link_to(h(a), *args) : '-'
|
||||
end
|
||||
|
||||
def aggregate_path(project, field, row, options={})
|
||||
parameters = {:set_filter => 1, :subproject_id => '!*', field => row.id}.merge(options)
|
||||
project_issues_path(row.is_a?(Project) ? row : project, parameters)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,297 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 RepositoriesHelper
|
||||
def format_revision(revision)
|
||||
if revision.respond_to? :format_identifier
|
||||
revision.format_identifier
|
||||
else
|
||||
revision.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def truncate_at_line_break(text, length = 255)
|
||||
if text
|
||||
text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
|
||||
end
|
||||
end
|
||||
|
||||
def render_properties(properties)
|
||||
unless properties.nil? || properties.empty?
|
||||
content = ''
|
||||
properties.keys.sort.each do |property|
|
||||
content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe)
|
||||
end
|
||||
content_tag('ul', content.html_safe, :class => 'properties')
|
||||
end
|
||||
end
|
||||
|
||||
def render_changeset_changes
|
||||
changes = @changeset.filechanges.limit(1000).reorder('path').all.collect do |change|
|
||||
case change.action
|
||||
when 'A'
|
||||
# Detects moved/copied files
|
||||
if !change.from_path.blank?
|
||||
change.action =
|
||||
@changeset.filechanges.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
|
||||
end
|
||||
change
|
||||
when 'D'
|
||||
@changeset.filechanges.detect {|c| c.from_path == change.path} ? nil : change
|
||||
else
|
||||
change
|
||||
end
|
||||
end.compact
|
||||
|
||||
tree = { }
|
||||
changes.each do |change|
|
||||
p = tree
|
||||
dirs = change.path.to_s.split('/').select {|d| !d.blank?}
|
||||
path = ''
|
||||
dirs.each do |dir|
|
||||
path += '/' + dir
|
||||
p[:s] ||= {}
|
||||
p = p[:s]
|
||||
p[path] ||= {}
|
||||
p = p[path]
|
||||
end
|
||||
p[:c] = change
|
||||
end
|
||||
render_changes_tree(tree[:s])
|
||||
end
|
||||
|
||||
def render_changes_tree(tree)
|
||||
return '' if tree.nil?
|
||||
output = ''
|
||||
output << '<ul>'
|
||||
tree.keys.sort.each do |file|
|
||||
style = 'change'
|
||||
text = File.basename(h(file))
|
||||
if s = tree[file][:s]
|
||||
style << ' folder'
|
||||
path_param = to_path_param(@repository.relative_path(file))
|
||||
text = link_to(h(text), :controller => 'repositories',
|
||||
:action => 'show',
|
||||
:id => @project,
|
||||
:repository_id => @repository.identifier_param,
|
||||
:path => path_param,
|
||||
:rev => @changeset.identifier)
|
||||
output << "<li class='#{style}'>#{text}"
|
||||
output << render_changes_tree(s)
|
||||
output << "</li>"
|
||||
elsif c = tree[file][:c]
|
||||
style << " change-#{c.action}"
|
||||
path_param = to_path_param(@repository.relative_path(c.path))
|
||||
text = link_to(h(text), :controller => 'repositories',
|
||||
:action => 'entry',
|
||||
:id => @project,
|
||||
:repository_id => @repository.identifier_param,
|
||||
:path => path_param,
|
||||
:rev => @changeset.identifier) unless c.action == 'D'
|
||||
text << " - #{h(c.revision)}" unless c.revision.blank?
|
||||
text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
|
||||
:action => 'diff',
|
||||
:id => @project,
|
||||
:repository_id => @repository.identifier_param,
|
||||
:path => path_param,
|
||||
:rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
|
||||
text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
|
||||
output << "<li class='#{style}'>#{text}</li>"
|
||||
end
|
||||
end
|
||||
output << '</ul>'
|
||||
output.html_safe
|
||||
end
|
||||
|
||||
def repository_field_tags(form, repository)
|
||||
method = repository.class.name.demodulize.underscore + "_field_tags"
|
||||
if repository.is_a?(Repository) &&
|
||||
respond_to?(method) && method != 'repository_field_tags'
|
||||
send(method, form, repository)
|
||||
end
|
||||
end
|
||||
|
||||
def scm_select_tag(repository)
|
||||
scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
|
||||
Redmine::Scm::Base.all.each do |scm|
|
||||
if Setting.enabled_scm.include?(scm) ||
|
||||
(repository && repository.class.name.demodulize == scm)
|
||||
scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
|
||||
end
|
||||
end
|
||||
select_tag('repository_scm',
|
||||
options_for_select(scm_options, repository.class.name.demodulize),
|
||||
:disabled => (repository && !repository.new_record?),
|
||||
:data => {:remote => true, :method => 'get'})
|
||||
end
|
||||
|
||||
def with_leading_slash(path)
|
||||
path.to_s.starts_with?('/') ? path : "/#{path}"
|
||||
end
|
||||
|
||||
def without_leading_slash(path)
|
||||
path.gsub(%r{^/+}, '')
|
||||
end
|
||||
|
||||
def subversion_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(:url, :size => 60, :required => true,
|
||||
:disabled => !repository.safe_attribute?('url')) +
|
||||
'<br />'.html_safe +
|
||||
'(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
|
||||
content_tag('p', form.text_field(:login, :size => 30)) +
|
||||
content_tag('p', form.password_field(
|
||||
:password, :size => 30, :name => 'ignore',
|
||||
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
|
||||
:onfocus => "this.value=''; this.name='repository[password]';",
|
||||
:onchange => "this.name='repository[password]';"))
|
||||
end
|
||||
|
||||
def darcs_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(
|
||||
:url, :label => l(:field_path_to_repository),
|
||||
:size => 60, :required => true,
|
||||
:disabled => !repository.safe_attribute?('url'))) +
|
||||
content_tag('p', form.select(
|
||||
:log_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_commit_logs_encoding), :required => true))
|
||||
end
|
||||
|
||||
def mercurial_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(
|
||||
:url, :label => l(:field_path_to_repository),
|
||||
:size => 60, :required => true,
|
||||
:disabled => !repository.safe_attribute?('url')
|
||||
) +
|
||||
'<br />'.html_safe + l(:text_mercurial_repository_note)) +
|
||||
content_tag('p', form.select(
|
||||
:path_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_scm_path_encoding)
|
||||
) +
|
||||
'<br />'.html_safe + l(:text_scm_path_encoding_note))
|
||||
end
|
||||
|
||||
def git_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(
|
||||
:url, :label => l(:field_path_to_repository),
|
||||
:size => 60, :required => true,
|
||||
:disabled => !repository.safe_attribute?('url')
|
||||
) +
|
||||
'<br />'.html_safe +
|
||||
l(:text_git_repository_note)) +
|
||||
content_tag('p', form.select(
|
||||
:path_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_scm_path_encoding)
|
||||
) +
|
||||
'<br />'.html_safe + l(:text_scm_path_encoding_note)) +
|
||||
content_tag('p', form.check_box(
|
||||
:extra_report_last_commit,
|
||||
:label => l(:label_git_report_last_commit)
|
||||
))
|
||||
end
|
||||
|
||||
def cvs_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(
|
||||
:root_url,
|
||||
:label => l(:field_cvsroot),
|
||||
:size => 60, :required => true,
|
||||
:disabled => !repository.safe_attribute?('root_url'))) +
|
||||
content_tag('p', form.text_field(
|
||||
:url,
|
||||
:label => l(:field_cvs_module),
|
||||
:size => 30, :required => true,
|
||||
:disabled => !repository.safe_attribute?('url'))) +
|
||||
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 />'.html_safe + l(:text_scm_path_encoding_note))
|
||||
end
|
||||
|
||||
def bazaar_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(
|
||||
:url, :label => l(:field_path_to_repository),
|
||||
:size => 60, :required => true,
|
||||
:disabled => !repository.safe_attribute?('url'))) +
|
||||
content_tag('p', form.select(
|
||||
:log_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_commit_logs_encoding), :required => true))
|
||||
end
|
||||
|
||||
def filesystem_field_tags(form, repository)
|
||||
content_tag('p', form.text_field(
|
||||
:url, :label => l(:field_root_directory),
|
||||
:size => 60, :required => true,
|
||||
:disabled => !repository.safe_attribute?('url'))) +
|
||||
content_tag('p', form.select(
|
||||
:path_encoding, [nil] + Setting::ENCODINGS,
|
||||
:label => l(:field_scm_path_encoding)
|
||||
) +
|
||||
'<br />'.html_safe + l(:text_scm_path_encoding_note))
|
||||
end
|
||||
|
||||
def index_commits(commits, heads)
|
||||
return nil if commits.nil? or commits.first.parents.nil?
|
||||
refs_map = {}
|
||||
heads.each do |head|
|
||||
refs_map[head.scmid] ||= []
|
||||
refs_map[head.scmid] << head
|
||||
end
|
||||
commits_by_scmid = {}
|
||||
commits.reverse.each_with_index do |commit, commit_index|
|
||||
commits_by_scmid[commit.scmid] = {
|
||||
:parent_scmids => commit.parents.collect { |parent| parent.scmid },
|
||||
:rdmid => commit_index,
|
||||
:refs => refs_map.include?(commit.scmid) ? refs_map[commit.scmid].join(" ") : nil,
|
||||
:scmid => commit.scmid,
|
||||
:href => block_given? ? yield(commit.scmid) : commit.scmid
|
||||
}
|
||||
end
|
||||
heads.sort! { |head1, head2| head1.to_s <=> head2.to_s }
|
||||
space = nil
|
||||
heads.each do |head|
|
||||
if commits_by_scmid.include? head.scmid
|
||||
space = index_head((space || -1) + 1, head, commits_by_scmid)
|
||||
end
|
||||
end
|
||||
# when no head matched anything use first commit
|
||||
space ||= index_head(0, commits.first, commits_by_scmid)
|
||||
return commits_by_scmid, space
|
||||
end
|
||||
|
||||
def index_head(space, commit, commits_by_scmid)
|
||||
stack = [[space, commits_by_scmid[commit.scmid]]]
|
||||
max_space = space
|
||||
until stack.empty?
|
||||
space, commit = stack.pop
|
||||
commit[:space] = space if commit[:space].nil?
|
||||
space -= 1
|
||||
commit[:parent_scmids].each_with_index do |parent_scmid, parent_index|
|
||||
parent_commit = commits_by_scmid[parent_scmid]
|
||||
if parent_commit and parent_commit[:space].nil?
|
||||
stack.unshift [space += 1, parent_commit]
|
||||
end
|
||||
end
|
||||
max_space = space if max_space < space
|
||||
end
|
||||
max_space
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 RolesHelper
|
||||
end
|
|
@ -0,0 +1,39 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 RoutesHelper
|
||||
|
||||
# Returns the path to project issues or to the cross-project
|
||||
# issue list if project is nil
|
||||
def _project_issues_path(project, *args)
|
||||
if project
|
||||
project_issues_path(project, *args)
|
||||
else
|
||||
issues_path(*args)
|
||||
end
|
||||
end
|
||||
|
||||
def _project_calendar_path(project, *args)
|
||||
project ? project_calendar_path(project, *args) : issues_calendar_path(*args)
|
||||
end
|
||||
|
||||
def _project_gantt_path(project, *args)
|
||||
project ? project_gantt_path(project, *args) : issues_gantt_path(*args)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,70 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module SearchHelper
|
||||
def highlight_tokens(text, tokens)
|
||||
return text unless text && tokens && !tokens.empty?
|
||||
re_tokens = tokens.collect {|t| Regexp.escape(t)}
|
||||
regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE
|
||||
result = ''
|
||||
text.split(regexp).each_with_index do |words, i|
|
||||
if result.length > 1200
|
||||
# maximum length of the preview reached
|
||||
result << '...'
|
||||
break
|
||||
end
|
||||
words = words.mb_chars
|
||||
if i.even?
|
||||
result << h(words.length > 100 ? "#{words.slice(0..44)} ... #{words.slice(-45..-1)}" : words)
|
||||
else
|
||||
t = (tokens.index(words.downcase) || 0) % 4
|
||||
result << content_tag('span', h(words), :class => "highlight token-#{t}")
|
||||
end
|
||||
end
|
||||
result.html_safe
|
||||
end
|
||||
|
||||
def type_label(t)
|
||||
l("label_#{t.singularize}_plural", :default => t.to_s.humanize)
|
||||
end
|
||||
|
||||
def project_select_tag
|
||||
options = [[l(:label_project_all), 'all']]
|
||||
options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty?
|
||||
options << [l(:label_and_its_subprojects, @project.name), 'subprojects'] unless @project.nil? || @project.descendants.active.empty?
|
||||
options << [@project.name, ''] unless @project.nil?
|
||||
label_tag("scope", l(:description_project_scope), :class => "hidden-for-sighted") +
|
||||
select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1
|
||||
end
|
||||
|
||||
def render_results_by_type(results_by_type)
|
||||
links = []
|
||||
# Sorts types by results count
|
||||
results_by_type.keys.sort {|a, b| results_by_type[b] <=> results_by_type[a]}.each do |t|
|
||||
c = results_by_type[t]
|
||||
next if c == 0
|
||||
text = "#{type_label(t)} (#{c})"
|
||||
links << link_to(h(text), :q => params[:q], :titles_only => params[:titles_only],
|
||||
:all_words => params[:all_words], :scope => params[:scope], t => 1)
|
||||
end
|
||||
('<ul>'.html_safe +
|
||||
links.map {|link| content_tag('li', link)}.join(' ').html_safe +
|
||||
'</ul>'.html_safe) unless links.empty?
|
||||
end
|
||||
end
|
|
@ -0,0 +1,106 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module SettingsHelper
|
||||
def administration_settings_tabs
|
||||
tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
|
||||
{:name => 'display', :partial => 'settings/display', :label => :label_display},
|
||||
{:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
|
||||
{:name => 'projects', :partial => 'settings/projects', :label => :label_project_plural},
|
||||
{:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
|
||||
{:name => 'notifications', :partial => 'settings/notifications', :label => :field_mail_notification},
|
||||
{:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
|
||||
{:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
|
||||
]
|
||||
end
|
||||
|
||||
def setting_select(setting, choices, options={})
|
||||
if blank_text = options.delete(:blank)
|
||||
choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
|
||||
end
|
||||
setting_label(setting, options).html_safe +
|
||||
select_tag("settings[#{setting}]",
|
||||
options_for_select(choices, Setting.send(setting).to_s),
|
||||
options).html_safe
|
||||
end
|
||||
|
||||
def setting_multiselect(setting, choices, options={})
|
||||
setting_values = Setting.send(setting)
|
||||
setting_values = [] unless setting_values.is_a?(Array)
|
||||
|
||||
content_tag("label", l(options[:label] || "setting_#{setting}")) +
|
||||
hidden_field_tag("settings[#{setting}][]", '').html_safe +
|
||||
choices.collect do |choice|
|
||||
text, value = (choice.is_a?(Array) ? choice : [choice, choice])
|
||||
content_tag(
|
||||
'label',
|
||||
check_box_tag(
|
||||
"settings[#{setting}][]",
|
||||
value,
|
||||
setting_values.include?(value),
|
||||
:id => nil
|
||||
) + text.to_s,
|
||||
:class => (options[:inline] ? 'inline' : 'block')
|
||||
)
|
||||
end.join.html_safe
|
||||
end
|
||||
|
||||
def setting_text_field(setting, options={})
|
||||
setting_label(setting, options).html_safe +
|
||||
text_field_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
|
||||
end
|
||||
|
||||
def setting_text_area(setting, options={})
|
||||
setting_label(setting, options).html_safe +
|
||||
text_area_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
|
||||
end
|
||||
|
||||
def setting_check_box(setting, options={})
|
||||
setting_label(setting, options).html_safe +
|
||||
hidden_field_tag("settings[#{setting}]", 0, :id => nil).html_safe +
|
||||
check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options).html_safe
|
||||
end
|
||||
|
||||
def setting_label(setting, options={})
|
||||
label = options.delete(:label)
|
||||
label != false ? label_tag("settings_#{setting}", l(label || "setting_#{setting}")).html_safe : ''
|
||||
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), :id => nil).html_safe +
|
||||
l_or_humanize(notifiable.name, :prefix => 'label_').html_safe,
|
||||
:class => notifiable.parent.present? ? "parent" : '').html_safe
|
||||
end
|
||||
|
||||
def cross_project_subtasks_options
|
||||
options = [
|
||||
[:label_disabled, ''],
|
||||
[:label_cross_project_system, 'system'],
|
||||
[:label_cross_project_tree, 'tree'],
|
||||
[:label_cross_project_hierarchy, 'hierarchy'],
|
||||
[:label_cross_project_descendants, 'descendants']
|
||||
]
|
||||
|
||||
options.map {|label, value| [l(label), value.to_s]}
|
||||
end
|
||||
end
|
|
@ -0,0 +1,243 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Helpers to sort tables using clickable column headers.
|
||||
#
|
||||
# Author: Stuart Rackham <srackham@methods.co.nz>, March 2005.
|
||||
# Jean-Philippe Lang, 2009
|
||||
# License: This source code is released under the MIT license.
|
||||
#
|
||||
# - Consecutive clicks toggle the column's sort order.
|
||||
# - Sort state is maintained by a session hash entry.
|
||||
# - CSS classes identify sort column and state.
|
||||
# - Typically used in conjunction with the Pagination module.
|
||||
#
|
||||
# Example code snippets:
|
||||
#
|
||||
# Controller:
|
||||
#
|
||||
# helper :sort
|
||||
# include SortHelper
|
||||
#
|
||||
# def list
|
||||
# sort_init 'last_name'
|
||||
# sort_update %w(first_name last_name)
|
||||
# @items = Contact.find_all nil, sort_clause
|
||||
# end
|
||||
#
|
||||
# Controller (using Pagination module):
|
||||
#
|
||||
# helper :sort
|
||||
# include SortHelper
|
||||
#
|
||||
# def list
|
||||
# sort_init 'last_name'
|
||||
# sort_update %w(first_name last_name)
|
||||
# @contact_pages, @items = paginate :contacts,
|
||||
# :order_by => sort_clause,
|
||||
# :per_page => 10
|
||||
# end
|
||||
#
|
||||
# View (table header in list.rhtml):
|
||||
#
|
||||
# <thead>
|
||||
# <tr>
|
||||
# <%= sort_header_tag('id', :title => 'Sort by contact ID') %>
|
||||
# <%= sort_header_tag('last_name', :caption => 'Name') %>
|
||||
# <%= sort_header_tag('phone') %>
|
||||
# <%= sort_header_tag('address', :width => 200) %>
|
||||
# </tr>
|
||||
# </thead>
|
||||
#
|
||||
# - Introduces instance variables: @sort_default, @sort_criteria
|
||||
# - Introduces param :sort
|
||||
#
|
||||
|
||||
module SortHelper
|
||||
class SortCriteria
|
||||
|
||||
def initialize
|
||||
@criteria = []
|
||||
end
|
||||
|
||||
def available_criteria=(criteria)
|
||||
unless criteria.is_a?(Hash)
|
||||
criteria = criteria.inject({}) {|h,k| h[k] = k; h}
|
||||
end
|
||||
@available_criteria = criteria
|
||||
end
|
||||
|
||||
def from_param(param)
|
||||
@criteria = param.to_s.split(',').collect {|s| s.split(':')[0..1]}
|
||||
normalize!
|
||||
end
|
||||
|
||||
def criteria=(arg)
|
||||
@criteria = arg
|
||||
normalize!
|
||||
end
|
||||
|
||||
def to_param
|
||||
@criteria.collect {|k,o| k + (o ? '' : ':desc')}.join(',')
|
||||
end
|
||||
|
||||
# Returns an array of SQL fragments used to sort the list
|
||||
def to_sql
|
||||
sql = @criteria.collect do |k,o|
|
||||
if s = @available_criteria[k]
|
||||
(o ? s.to_a : s.to_a.collect {|c| append_desc(c)})
|
||||
end
|
||||
end.flatten.compact
|
||||
sql.blank? ? nil : sql
|
||||
end
|
||||
|
||||
def to_a
|
||||
@criteria.dup
|
||||
end
|
||||
|
||||
def add!(key, asc)
|
||||
@criteria.delete_if {|k,o| k == key}
|
||||
@criteria = [[key, asc]] + @criteria
|
||||
normalize!
|
||||
end
|
||||
|
||||
def add(*args)
|
||||
r = self.class.new.from_param(to_param)
|
||||
r.add!(*args)
|
||||
r
|
||||
end
|
||||
|
||||
def first_key
|
||||
@criteria.first && @criteria.first.first
|
||||
end
|
||||
|
||||
def first_asc?
|
||||
@criteria.first && @criteria.first.last
|
||||
end
|
||||
|
||||
def empty?
|
||||
@criteria.empty?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def normalize!
|
||||
@criteria ||= []
|
||||
@criteria = @criteria.collect {|s| s = s.to_a; [s.first, (s.last == false || s.last == 'desc') ? false : true]}
|
||||
@criteria = @criteria.select {|k,o| @available_criteria.has_key?(k)} if @available_criteria
|
||||
@criteria.slice!(3)
|
||||
self
|
||||
end
|
||||
|
||||
# Appends DESC to the sort criterion unless it has a fixed order
|
||||
def append_desc(criterion)
|
||||
if criterion =~ / (asc|desc)$/i
|
||||
criterion
|
||||
else
|
||||
"#{criterion} DESC"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def sort_name
|
||||
controller_name + '_' + action_name + '_sort'
|
||||
end
|
||||
|
||||
# Initializes the default sort.
|
||||
# Examples:
|
||||
#
|
||||
# sort_init 'name'
|
||||
# sort_init 'id', 'desc'
|
||||
# sort_init ['name', ['id', 'desc']]
|
||||
# sort_init [['name', 'desc'], ['id', 'desc']]
|
||||
#
|
||||
def sort_init(*args)
|
||||
case args.size
|
||||
when 1
|
||||
@sort_default = args.first.is_a?(Array) ? args.first : [[args.first]]
|
||||
when 2
|
||||
@sort_default = [[args.first, args.last]]
|
||||
else
|
||||
raise ArgumentError
|
||||
end
|
||||
end
|
||||
|
||||
# Updates the sort state. Call this in the controller prior to calling
|
||||
# sort_clause.
|
||||
# - criteria can be either an array or a hash of allowed keys
|
||||
#
|
||||
def sort_update(criteria, sort_name=nil)
|
||||
sort_name ||= self.sort_name
|
||||
@sort_criteria = SortCriteria.new
|
||||
@sort_criteria.available_criteria = criteria
|
||||
@sort_criteria.from_param(params[:sort] || session[sort_name])
|
||||
@sort_criteria.criteria = @sort_default if @sort_criteria.empty?
|
||||
session[sort_name] = @sort_criteria.to_param
|
||||
end
|
||||
|
||||
# Clears the sort criteria session data
|
||||
#
|
||||
def sort_clear
|
||||
session[sort_name] = nil
|
||||
end
|
||||
|
||||
# Returns an SQL sort clause corresponding to the current sort state.
|
||||
# Use this to sort the controller's table items collection.
|
||||
#
|
||||
def sort_clause()
|
||||
@sort_criteria.to_sql
|
||||
end
|
||||
|
||||
def sort_criteria
|
||||
@sort_criteria
|
||||
end
|
||||
|
||||
# Returns a link which sorts by the named column.
|
||||
#
|
||||
# - column is the name of an attribute in the sorted record collection.
|
||||
# - the optional caption explicitly specifies the displayed link text.
|
||||
# - 2 CSS classes reflect the state of the link: sort and asc or desc
|
||||
#
|
||||
def sort_link(column, caption, default_order)
|
||||
css, order = nil, default_order
|
||||
|
||||
if column.to_s == @sort_criteria.first_key
|
||||
if @sort_criteria.first_asc?
|
||||
css = 'sort asc'
|
||||
order = 'desc'
|
||||
else
|
||||
css = 'sort desc'
|
||||
order = 'asc'
|
||||
end
|
||||
end
|
||||
caption = column.to_s.humanize unless caption
|
||||
|
||||
sort_options = { :sort => @sort_criteria.add(column.to_s, order).to_param }
|
||||
url_options = params.merge(sort_options)
|
||||
|
||||
# Add project_id to url_options
|
||||
url_options = url_options.merge(:project_id => params[:project_id]) if params.has_key?(:project_id)
|
||||
|
||||
link_to_content_update(h(caption), url_options, :class => css)
|
||||
end
|
||||
|
||||
# Returns a table header <th> tag with a sort link for the named column
|
||||
# attribute.
|
||||
#
|
||||
# Options:
|
||||
# :caption The displayed link name (defaults to titleized column name).
|
||||
# :title The tag's 'title' attribute (defaults to 'Sort by :caption').
|
||||
#
|
||||
# Other options hash entries generate additional table header tag attributes.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# <%= sort_header_tag('id', :title => 'Sort by contact ID', :width => 40) %>
|
||||
#
|
||||
def sort_header_tag(column, options = {})
|
||||
caption = options.delete(:caption) || column.to_s.humanize
|
||||
default_order = options.delete(:default_order) || 'asc'
|
||||
options[:title] = l(:label_sort_by, "\"#{caption}\"") unless options[:title]
|
||||
content_tag('th', sort_link(column, caption, default_order), options)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
########fq
|
||||
module TestHelper
|
||||
def message_list(object)
|
||||
object = object.reverse
|
||||
remove_allowed = (User.current.id == object.first.user_id)
|
||||
content = ''.html_safe
|
||||
lis = object.each do |t_object|
|
||||
s = ''.html_safe
|
||||
s << avatar(t_object.user, :size => "16").to_s
|
||||
s << link_to_user(t_object.find_messager.first, :class => 'user')
|
||||
s << ':' + t_object.message
|
||||
#time = '更新于' + time_tag(t_object.created_at) + '之前'
|
||||
time = time_tag(t_object.created_at)
|
||||
#s << content_tag('p', l(:field_add, time))
|
||||
s << content_tag('div', time)
|
||||
if remove_allowed
|
||||
url = {:controller => 'test',
|
||||
:action => 'destroy',
|
||||
:object_id => t_object.id,
|
||||
:user_id => User.current.id}
|
||||
s << ' '
|
||||
s << link_to(image_tag('delete.png'), url,
|
||||
:remote => true, :method => 'delete', :class => "delete")
|
||||
end
|
||||
content << content_tag('li', s, :class => "user-#{t_object.messager_id}")
|
||||
end
|
||||
# content.present? ? content_tag('ul', content, :class => 'watchers') : content
|
||||
content
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module TimelogHelper
|
||||
include ApplicationHelper
|
||||
|
||||
def render_timelog_breadcrumb
|
||||
links = []
|
||||
links << link_to(l(:label_project_all), {:project_id => nil, :issue_id => nil})
|
||||
links << link_to(h(@project), {:project_id => @project, :issue_id => nil}) if @project
|
||||
if @issue
|
||||
if @issue.visible?
|
||||
links << link_to_issue(@issue, :subject => false)
|
||||
else
|
||||
links << "##{@issue.id}"
|
||||
end
|
||||
end
|
||||
breadcrumb links
|
||||
end
|
||||
|
||||
# Returns a collection of activities for a select field. time_entry
|
||||
# is optional and will be used to check if the selected TimeEntryActivity
|
||||
# is active.
|
||||
def activity_collection_for_select_options(time_entry=nil, project=nil)
|
||||
project ||= @project
|
||||
if project.nil?
|
||||
activities = TimeEntryActivity.shared.active
|
||||
else
|
||||
activities = project.activities
|
||||
end
|
||||
|
||||
collection = []
|
||||
if time_entry && time_entry.activity && !time_entry.activity.active?
|
||||
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ]
|
||||
else
|
||||
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default)
|
||||
end
|
||||
activities.each { |a| collection << [a.name, a.id] }
|
||||
collection
|
||||
end
|
||||
|
||||
def select_hours(data, criteria, value)
|
||||
if value.to_s.empty?
|
||||
data.select {|row| row[criteria].blank? }
|
||||
else
|
||||
data.select {|row| row[criteria].to_s == value.to_s}
|
||||
end
|
||||
end
|
||||
|
||||
def sum_hours(data)
|
||||
sum = 0
|
||||
data.each do |row|
|
||||
sum += row['hours'].to_f
|
||||
end
|
||||
sum
|
||||
end
|
||||
|
||||
def options_for_period_select(value)
|
||||
options_for_select([[l(:label_all_time), 'all'],
|
||||
[l(:label_today), 'today'],
|
||||
[l(:label_yesterday), 'yesterday'],
|
||||
[l(:label_this_week), 'current_week'],
|
||||
[l(:label_last_week), 'last_week'],
|
||||
[l(:label_last_n_weeks, 2), 'last_2_weeks'],
|
||||
[l(:label_last_n_days, 7), '7_days'],
|
||||
[l(:label_this_month), 'current_month'],
|
||||
[l(:label_last_month), 'last_month'],
|
||||
[l(:label_last_n_days, 30), '30_days'],
|
||||
[l(:label_this_year), 'current_year']],
|
||||
value)
|
||||
end
|
||||
|
||||
def format_criteria_value(criteria_options, value)
|
||||
if value.blank?
|
||||
"[#{l(:label_none)}]"
|
||||
elsif k = criteria_options[:klass]
|
||||
obj = k.find_by_id(value.to_i)
|
||||
if obj.is_a?(Issue)
|
||||
obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}"
|
||||
else
|
||||
obj
|
||||
end
|
||||
else
|
||||
format_value(value, criteria_options[:format])
|
||||
end
|
||||
end
|
||||
|
||||
def report_to_csv(report)
|
||||
decimal_separator = l(:general_csv_decimal_separator)
|
||||
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||
# Column headers
|
||||
headers = report.criteria.collect {|criteria| l(report.available_criteria[criteria][:label]) }
|
||||
headers += report.periods
|
||||
headers << l(:label_total_time)
|
||||
csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8(
|
||||
c.to_s,
|
||||
l(:general_csv_encoding) ) }
|
||||
# Content
|
||||
report_criteria_to_csv(csv, report.available_criteria, report.columns, report.criteria, report.periods, report.hours)
|
||||
# Total row
|
||||
str_total = Redmine::CodesetUtil.from_utf8(l(:label_total_time), l(:general_csv_encoding))
|
||||
row = [ str_total ] + [''] * (report.criteria.size - 1)
|
||||
total = 0
|
||||
report.periods.each do |period|
|
||||
sum = sum_hours(select_hours(report.hours, report.columns, period.to_s))
|
||||
total += sum
|
||||
row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '')
|
||||
end
|
||||
row << ("%.2f" % total).gsub('.',decimal_separator)
|
||||
csv << row
|
||||
end
|
||||
export
|
||||
end
|
||||
|
||||
def report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours, level=0)
|
||||
decimal_separator = l(:general_csv_decimal_separator)
|
||||
hours.collect {|h| h[criteria[level]].to_s}.uniq.each do |value|
|
||||
hours_for_value = select_hours(hours, criteria[level], value)
|
||||
next if hours_for_value.empty?
|
||||
row = [''] * level
|
||||
row << Redmine::CodesetUtil.from_utf8(
|
||||
format_criteria_value(available_criteria[criteria[level]], value).to_s,
|
||||
l(:general_csv_encoding) )
|
||||
row += [''] * (criteria.length - level - 1)
|
||||
total = 0
|
||||
periods.each do |period|
|
||||
sum = sum_hours(select_hours(hours_for_value, columns, period.to_s))
|
||||
total += sum
|
||||
row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '')
|
||||
end
|
||||
row << ("%.2f" % total).gsub('.',decimal_separator)
|
||||
csv << row
|
||||
if criteria.length > level + 1
|
||||
report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours_for_value, level + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 TrackersHelper
|
||||
end
|
|
@ -0,0 +1,64 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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.
|
||||
|
||||
|
||||
|
||||
include AvatarHelper
|
||||
module UsersHelper
|
||||
def users_status_options_for_select(selected)
|
||||
user_count_by_status = User.count(:group => 'status').to_hash
|
||||
options_for_select([[l(:label_all), ''],
|
||||
["#{l(:status_active)} (#{user_count_by_status[1].to_i})", '1'],
|
||||
["#{l(:status_registered)} (#{user_count_by_status[2].to_i})", '2'],
|
||||
["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", '3']], selected.to_s)
|
||||
end
|
||||
|
||||
def user_mail_notification_options(user)
|
||||
user.valid_notification_options.collect {|o| [l(o.last), o.first]}
|
||||
end
|
||||
|
||||
def change_status_link(user)
|
||||
url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
|
||||
|
||||
if user.locked?
|
||||
link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
|
||||
elsif user.registered?
|
||||
link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
|
||||
elsif user != User.current
|
||||
link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'icon icon-lock'
|
||||
end
|
||||
end
|
||||
|
||||
def user_settings_tabs
|
||||
tabs = [{:name => 'general', :partial => 'users/general', :label => :label_general},
|
||||
{:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural}
|
||||
]
|
||||
if Group.all.any?
|
||||
tabs.insert 1, {:name => 'groups', :partial => 'users/groups', :label => :label_group_plural}
|
||||
end
|
||||
tabs
|
||||
end
|
||||
|
||||
# this method is used to get all projects that tagged one tag
|
||||
# added by william
|
||||
def get_users_by_tag(tag_name)
|
||||
User.tagged_with(tag_name)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module VersionsHelper
|
||||
|
||||
def version_anchor(version)
|
||||
if @project == version.project
|
||||
anchor version.name
|
||||
else
|
||||
anchor "#{version.project.try(:identifier)}-#{version.name}"
|
||||
end
|
||||
end
|
||||
|
||||
STATUS_BY_CRITERIAS = %w(tracker status priority author assigned_to category)
|
||||
|
||||
def render_issue_status_by(version, criteria)
|
||||
criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria)
|
||||
|
||||
h = Hash.new {|k,v| k[v] = [0, 0]}
|
||||
begin
|
||||
# Total issue count
|
||||
Issue.count(:group => criteria,
|
||||
:conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s}
|
||||
# Open issues count
|
||||
Issue.count(:group => criteria,
|
||||
:include => :status,
|
||||
:conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s}
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# When grouping by an association, Rails throws this exception if there's no result (bug)
|
||||
end
|
||||
# Sort with nil keys in last position
|
||||
counts = h.keys.sort {|a,b| a.nil? ? 1 : (b.nil? ? -1 : a <=> b)}.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}}
|
||||
max = counts.collect {|c| c[:total]}.max
|
||||
|
||||
render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
|
||||
end
|
||||
|
||||
def status_by_options_for_select(value)
|
||||
options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,86 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module WatchersHelper
|
||||
|
||||
def watcher_tag(object, user, options={})
|
||||
ActiveSupport::Deprecation.warn "#watcher_tag is deprecated and will be removed in Redmine 3.0. Use #watcher_link instead."
|
||||
watcher_link(object, user)
|
||||
end
|
||||
|
||||
###################modified by liuping
|
||||
def watcher_link(objects, user)
|
||||
return '' unless user && user.logged?
|
||||
objects = Array.wrap(objects)
|
||||
|
||||
watched = objects.any? {|object| object.watched_by?(user)}
|
||||
css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
|
||||
|
||||
text = (objects.first.instance_of?(User) or objects.first.instance_of?(Project)) ?
|
||||
(watched ? l(:button_unfollow) : l(:button_follow)) : (watched ? l(:button_unwatch) : l(:button_watch))
|
||||
|
||||
url = watch_path(
|
||||
:object_type => objects.first.class.to_s.underscore,
|
||||
:object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
|
||||
)
|
||||
method = watched ? 'delete' : 'post'
|
||||
|
||||
link_to text, url, :remote => true, :method => method, :class => css
|
||||
end
|
||||
|
||||
# Returns the css class used to identify watch links for a given +object+
|
||||
def watcher_css(objects)
|
||||
objects = Array.wrap(objects)
|
||||
id = (objects.size == 1 ? objects.first.id : 'bulk')
|
||||
"#{objects.first.class.to_s.underscore}-#{id}-watcher"
|
||||
end
|
||||
|
||||
# Returns a comma separated list of users watching the given object
|
||||
def watchers_list(object)
|
||||
remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
|
||||
content = ''.html_safe
|
||||
lis = object.watcher_users.collect do |user|
|
||||
s = ''.html_safe
|
||||
s << avatar(user, :size => "16").to_s
|
||||
s << link_to_user(user, :class => 'user')
|
||||
if remove_allowed
|
||||
url = {:controller => 'watchers',
|
||||
:action => 'destroy',
|
||||
:object_type => object.class.to_s.underscore,
|
||||
:object_id => object.id,
|
||||
:user_id => user}
|
||||
s << ' '
|
||||
s << link_to(image_tag('delete.png'), url,
|
||||
:remote => true, :method => 'delete', :class => "delete")
|
||||
end
|
||||
content << content_tag('li', s, :class => "user-#{user.id}")
|
||||
end
|
||||
content.present? ? content_tag('ul', content, :class => 'watchers') : content
|
||||
end
|
||||
|
||||
def watchers_checkboxes(object, users, checked=nil)
|
||||
users.map do |user|
|
||||
c = checked.nil? ? object.watched_by?(user) : checked
|
||||
tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil
|
||||
content_tag 'label', "#{tag} #{h(user)}".html_safe,
|
||||
:id => "issue_watcher_user_ids_#{user.id}",
|
||||
:class => "floating"
|
||||
end.join.html_safe
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 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 WelcomeHelper
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue