Compare commits

..
10 Commits
Author SHA1 Message Date
Jean-Philippe Lang 13ec81598b Docs updated for 0.6.4 release.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1233 e93f8b46-1217-0410-a6f0-8f06a7374b81
2008-03-12 18:06:43 +00:00
Jean-Philippe Lang a677817003 Merged r1231 from trunk.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1232 e93f8b46-1217-0410-a6f0-8f06a7374b81
2008-03-12 17:57:46 +00:00
Jean-Philippe Lang abaeecbaa9 Merged Mercurial browsing fix from trunk (r1228 and r1229).
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1230 e93f8b46-1217-0410-a6f0-8f06a7374b81
2008-03-12 17:54:50 +00:00
Jean-Philippe Lang 75d652d9e5 Ported r1169 from trunk.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1170 e93f8b46-1217-0410-a6f0-8f06a7374b81
2008-02-22 17:28:17 +00:00
Jean-Philippe Lang 7e9dd78de8 Ported r1034 and r1140 from trunk.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1141 e93f8b46-1217-0410-a6f0-8f06a7374b81
2008-02-12 21:14:58 +00:00
Jean-Philippe Lang bd7542cf98 Merged r1015, r1019, r1022 to r1025, r1045 and r1047 from trunk.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1048 e93f8b46-1217-0410-a6f0-8f06a7374b81
2008-01-07 20:46:54 +00:00
Jean-Philippe Lang a2c18b2037 Ported r1036 from trunk.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1041 e93f8b46-1217-0410-a6f0-8f06a7374b81
2008-01-05 13:12:30 +00:00
Jean-Philippe Lang eb86e5e7e1 Changes for 0.6.3 release.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1010 e93f8b46-1217-0410-a6f0-8f06a7374b81
2007-12-18 18:12:18 +00:00
Jean-Philippe Lang fc26668cd9 Fixed: upload doesn't work in "Files" section.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1009 e93f8b46-1217-0410-a6f0-8f06a7374b81
2007-12-18 18:04:10 +00:00
Jean-Philippe Lang 2b42e3fc50 Added 0.6 stable branch.
git-svn-id: http://redmine.rubyforge.org/svn/branches/0.6-stable@1008 e93f8b46-1217-0410-a6f0-8f06a7374b81
2007-12-18 17:53:13 +00:00
450 changed files with 4955 additions and 18700 deletions
+1 -3
View File
@@ -43,7 +43,7 @@ class AccountController < ApplicationController
self.logged_user = nil self.logged_user = nil
else else
# Authenticate user # Authenticate user
user = User.try_to_login(params[:username], params[:password]) user = User.try_to_login(params[:login], params[:password])
if user if user
self.logged_user = user self.logged_user = user
# generate a key and set cookie if autologin # generate a key and set cookie if autologin
@@ -56,8 +56,6 @@ class AccountController < ApplicationController
flash.now[:error] = l(:notice_account_invalid_creditentials) flash.now[:error] = l(:notice_account_invalid_creditentials)
end end
end end
rescue User::OnTheFlyCreationFailure
flash.now[:error] = 'Redmine could not retrieve the required information from the LDAP to create your account. Please, contact your Redmine administrator.'
end end
# Log out current user and redirect to welcome page # Log out current user and redirect to welcome page
+12 -16
View File
@@ -22,13 +22,12 @@ class AdminController < ApplicationController
helper :sort helper :sort
include SortHelper include SortHelper
def index def index
@no_configuration_data = Redmine::DefaultData::Loader::no_data?
end end
def projects def projects
sort_init 'name', 'asc' sort_init 'name', 'asc'
sort_update %w(name is_public created_on) sort_update
@status = params[:status] ? params[:status].to_i : 0 @status = params[:status] ? params[:status].to_i : 0
conditions = nil conditions = nil
@@ -36,7 +35,7 @@ class AdminController < ApplicationController
@project_count = Project.count(:conditions => conditions) @project_count = Project.count(:conditions => conditions)
@project_pages = Paginator.new self, @project_count, @project_pages = Paginator.new self, @project_count,
per_page_option, 25,
params['page'] params['page']
@projects = Project.find :all, :order => sort_clause, @projects = Project.find :all, :order => sort_clause,
:conditions => conditions, :conditions => conditions,
@@ -45,19 +44,16 @@ class AdminController < ApplicationController
render :action => "projects", :layout => false if request.xhr? render :action => "projects", :layout => false if request.xhr?
end end
# Loads the default configuration def mail_options
# (roles, trackers, statuses, workflow, enumerations) @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted)
def default_configuration
if request.post? if request.post?
begin settings = (params[:settings] || {}).dup.symbolize_keys
Redmine::DefaultData::Loader::load(params[:lang]) settings[:notified_events] ||= []
flash[:notice] = l(:notice_default_data_loaded) settings.each { |name, value| Setting[name] = value }
rescue Exception => e flash[:notice] = l(:notice_successful_update)
flash[:error] = l(:error_can_t_load_default_data, e.message) redirect_to :controller => 'admin', :action => 'mail_options'
end
end end
redirect_to :action => 'index'
end end
def test_email def test_email
@@ -71,7 +67,7 @@ class AdminController < ApplicationController
flash[:error] = l(:notice_email_error, e.message) flash[:error] = l(:notice_email_error, e.message)
end end
ActionMailer::Base.raise_delivery_errors = raise_delivery_errors ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications' redirect_to :action => 'mail_options'
end end
def info def info
+21 -64
View File
@@ -19,9 +19,6 @@ class ApplicationController < ActionController::Base
before_filter :user_setup, :check_if_login_required, :set_localization before_filter :user_setup, :check_if_login_required, :set_localization
filter_parameter_logging :password filter_parameter_logging :password
include Redmine::MenuManager::MenuController
helper Redmine::MenuManager::MenuHelper
REDMINE_SUPPORTED_SCM.each do |scm| REDMINE_SUPPORTED_SCM.each do |scm|
require_dependency "repository/#{scm.underscore}" require_dependency "repository/#{scm.underscore}"
end end
@@ -31,23 +28,18 @@ class ApplicationController < ActionController::Base
end end
def user_setup def user_setup
# Check the settings cache for each request
Setting.check_cache Setting.check_cache
# Find the current user
User.current = find_current_user
end
# Returns the current user or nil if no user is logged in
def find_current_user
if session[:user_id] if session[:user_id]
# existing session # existing session
(User.find_active(session[:user_id]) rescue nil) User.current = User.find(session[:user_id])
elsif cookies[:autologin] && Setting.autologin? elsif cookies[:autologin] && Setting.autologin?
# auto-login feature # auto-login feature
User.find_by_autologin_key(cookies[:autologin]) User.current = User.find_by_autologin_key(cookies[:autologin])
elsif params[:key] && accept_key_auth_actions.include?(params[:action]) elsif params[:key] && accept_key_auth_actions.include?(params[:action])
# RSS key authentication # RSS key authentication
User.find_by_rss_key(params[:key]) User.current = User.find_by_rss_key(params[:key])
else
User.current = User.anonymous
end end
end end
@@ -59,14 +51,13 @@ class ApplicationController < ActionController::Base
end end
def set_localization def set_localization
User.current.language = nil unless User.current.logged?
lang = begin lang = begin
if !User.current.language.blank? && GLoc.valid_language?(User.current.language) if !User.current.language.blank? and GLoc.valid_languages.include? User.current.language.to_sym
User.current.language User.current.language
elsif request.env['HTTP_ACCEPT_LANGUAGE'] elsif request.env['HTTP_ACCEPT_LANGUAGE']
accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.downcase accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first
if !accept_lang.blank? && (GLoc.valid_language?(accept_lang) || GLoc.valid_language?(accept_lang = accept_lang.split('-').first)) if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym
User.current.language = accept_lang accept_lang
end end
end end
rescue rescue
@@ -102,17 +93,13 @@ class ApplicationController < ActionController::Base
# make sure that the user is a member of the project (or admin) if project is private # make sure that the user is a member of the project (or admin) if project is private
# used as a before_filter for actions that do not require any particular permission on the project # used as a before_filter for actions that do not require any particular permission on the project
def check_project_privacy def check_project_privacy
if @project && @project.active? unless @project.active?
if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
true
else
User.current.logged? ? render_403 : require_login
end
else
@project = nil @project = nil
render_404 render_404
false return false
end end
return true if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
User.current.logged? ? render_403 : require_login
end end
# store current uri in session. # store current uri in session.
@@ -142,15 +129,9 @@ class ApplicationController < ActionController::Base
return false return false
end end
def render_error(msg)
flash.now[:error] = msg
render :nothing => true, :layout => !request.xhr?, :status => 500
end
def render_feed(items, options={}) def render_feed(items, options={})
@items = items || [] @items = items || []
@items.sort! {|x,y| y.event_datetime <=> x.event_datetime } @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 @title = options[:title] || Setting.app_title
render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml' render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
end end
@@ -165,35 +146,16 @@ class ApplicationController < ActionController::Base
end end
# TODO: move to model # TODO: move to model
def attach_files(obj, attachments) def attach_files(obj, files)
attached = [] attachments = []
if attachments && attachments.is_a?(Hash) if files && files.is_a?(Array)
attachments.each_value do |attachment| files.each do |file|
file = attachment['file'] next unless file.size > 0
next unless file && file.size > 0 a = Attachment.create(:container => obj, :file => file, :author => User.current)
a = Attachment.create(:container => obj, attachments << a unless a.new_record?
:file => file,
:description => attachment['description'].to_s.strip,
:author => User.current)
attached << a unless a.new_record?
end end
end end
attached attachments
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 end
# qvalues http header parser # qvalues http header parser
@@ -214,9 +176,4 @@ class ApplicationController < ActionController::Base
end end
return tmp return tmp
end end
# Returns a string that can be used as filename value in Content-Disposition header
def filename_for_content_disposition(name)
request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
end
end end
+1 -1
View File
@@ -21,7 +21,7 @@ class AttachmentsController < ApplicationController
def download def download
# images are sent inline # images are sent inline
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), send_file @attachment.diskfile, :filename => @attachment.filename,
:type => @attachment.content_type, :type => @attachment.content_type,
:disposition => (@attachment.image? ? 'inline' : 'attachment') :disposition => (@attachment.image? ? 'inline' : 'attachment')
rescue rescue
+4 -5
View File
@@ -36,13 +36,12 @@ class BoardsController < ApplicationController
end end
def show def show
sort_init 'updated_on', 'desc' sort_init "#{Message.table_name}.updated_on", "desc"
sort_update 'created_on' => "#{Message.table_name}.created_on", sort_update
'updated_on' => "#{Message.table_name}.updated_on"
@topic_count = @board.topics.count @topic_count = @board.topics.count
@topic_pages = Paginator.new self, @topic_count, per_page_option, params['page'] @topic_pages = Paginator.new self, @topic_count, 25, params['page']
@topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '), @topics = @board.topics.find :all, :order => "#{Message.table_name}.sticky DESC, #{sort_clause}",
:include => [:author, {:last_reply => :author}], :include => [:author, {:last_reply => :author}],
:limit => @topic_pages.items_per_page, :limit => @topic_pages.items_per_page,
:offset => @topic_pages.current.offset :offset => @topic_pages.current.offset
+5 -42
View File
@@ -17,42 +17,12 @@
class DocumentsController < ApplicationController class DocumentsController < ApplicationController
layout 'base' layout 'base'
before_filter :find_project, :only => [:index, :new] before_filter :find_project, :authorize
before_filter :find_document, :except => [:index, :new]
before_filter :authorize
helper :attachments
def index
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
documents = @project.documents.find :all, :include => [:attachments, :category]
case @sort_by
when 'date'
@grouped = documents.group_by {|d| d.created_on.to_date }
when 'title'
@grouped = documents.group_by {|d| d.title.first.upcase}
when 'author'
@grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
else
@grouped = documents.group_by(&:category)
end
render :layout => false if request.xhr?
end
def show def show
@attachments = @document.attachments.find(:all, :order => "created_on DESC") @attachments = @document.attachments.find(:all, :order => "created_on DESC")
end end
def new
@document = @project.documents.build(params[:document])
if request.post? and @document.save
attach_files(@document, params[:attachments])
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
redirect_to :action => 'index', :project_id => @project
end
end
def edit def edit
@categories = Enumeration::get_values('DCAT') @categories = Enumeration::get_values('DCAT')
if request.post? and @document.update_attributes(params[:document]) if request.post? and @document.update_attributes(params[:document])
@@ -63,14 +33,13 @@ class DocumentsController < ApplicationController
def destroy def destroy
@document.destroy @document.destroy
redirect_to :controller => 'documents', :action => 'index', :project_id => @project redirect_to :controller => 'projects', :action => 'list_documents', :id => @project
end end
def download def download
@attachment = @document.attachments.find(params[:attachment_id]) @attachment = @document.attachments.find(params[:attachment_id])
@attachment.increment_download @attachment.increment_download
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), send_file @attachment.diskfile, :filename => @attachment.filename, :type => @attachment.content_type
:type => @attachment.content_type
rescue rescue
render_404 render_404
end end
@@ -88,15 +57,9 @@ class DocumentsController < ApplicationController
private private
def find_project def find_project
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
def find_document
@document = Document.find(params[:id]) @document = Document.find(params[:id])
@project = @document.project @project = @document.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end
end end
@@ -17,7 +17,6 @@
class IssueCategoriesController < ApplicationController class IssueCategoriesController < ApplicationController
layout 'base' layout 'base'
menu_item :settings
before_filter :find_project, :authorize before_filter :find_project, :authorize
verify :method => :post, :only => :destroy verify :method => :post, :only => :destroy
+87 -271
View File
@@ -17,16 +17,12 @@
class IssuesController < ApplicationController class IssuesController < ApplicationController
layout 'base' layout 'base'
menu_item :new_issue, :only => :new before_filter :find_project, :authorize, :except => [:index, :changes, :preview]
before_filter :find_issue, :only => [:show, :edit, :destroy_attachment]
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
before_filter :find_project, :only => [:new, :update_form, :preview]
before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu]
before_filter :find_optional_project, :only => [:index, :changes] before_filter :find_optional_project, :only => [:index, :changes]
accept_key_auth :index, :changes accept_key_auth :index, :changes
cache_sweeper :issue_sweeper, :only => [ :edit, :change_status, :destroy ]
helper :journals
helper :projects helper :projects
include ProjectsHelper include ProjectsHelper
helper :custom_fields helper :custom_fields
@@ -45,18 +41,11 @@ class IssuesController < ApplicationController
include IssuesHelper include IssuesHelper
def index def index
sort_init "#{Issue.table_name}.id", "desc"
sort_update
retrieve_query retrieve_query
sort_init 'id', 'desc'
sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
if @query.valid? if @query.valid?
limit = per_page_option limit = %w(pdf csv).include?(params[:format]) ? Setting.issues_export_limit.to_i : 25
respond_to do |format|
format.html { }
format.atom { }
format.csv { limit = Setting.issues_export_limit.to_i }
format.pdf { limit = Setting.issues_export_limit.to_i }
end
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
@issue_pages = Paginator.new self, @issue_count, limit, params['page'] @issue_pages = Paginator.new self, @issue_count, limit, params['page']
@issues = Issue.find :all, :order => sort_clause, @issues = Issue.find :all, :order => sort_clause,
@@ -74,234 +63,102 @@ class IssuesController < ApplicationController
# Send html if the query is not valid # Send html if the query is not valid
render(:template => 'issues/index.rhtml', :layout => !request.xhr?) render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
end end
rescue ActiveRecord::RecordNotFound
render_404
end end
def changes def changes
sort_init "#{Issue.table_name}.id", "desc"
sort_update
retrieve_query retrieve_query
sort_init 'id', 'desc'
sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
if @query.valid? if @query.valid?
@journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], @changes = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
:conditions => @query.statement, :conditions => @query.statement,
:limit => 25, :limit => 25,
:order => "#{Journal.table_name}.created_on DESC" :order => "#{Journal.table_name}.created_on DESC"
end end
@title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
render :layout => false, :content_type => 'application/atom+xml' render :layout => false, :content_type => 'application/atom+xml'
rescue ActiveRecord::RecordNotFound
render_404
end end
def show def show
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) } @custom_values = @issue.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
@journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
@journals.each_with_index {|j,i| j.indice = i+1} @status_options = @issue.status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)
@journals.reverse! if User.current.wants_comments_in_reverse_order?
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
@activities = Enumeration::get_values('ACTI')
@priorities = Enumeration::get_values('IPRI')
@time_entry = TimeEntry.new
respond_to do |format| respond_to do |format|
format.html { render :template => 'issues/show.rhtml' } format.html { render :template => 'issues/show.rhtml' }
format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
end end
end end
# Add a new issue
# The new issue will be created from an existing one if copy_from parameter is given
def new
@issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
@issue.project = @project
@issue.author = User.current
@issue.tracker ||= @project.trackers.find(params[:tracker_id] ? params[:tracker_id] : :first)
if @issue.tracker.nil?
flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
render :nothing => true, :layout => true
return
end
default_status = IssueStatus.default
unless default_status
flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
render :nothing => true, :layout => true
return
end
@issue.status = default_status
@allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq
if request.get? || request.xhr?
@issue.start_date ||= Date.today
@custom_values = @issue.custom_values.empty? ?
@project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
@issue.custom_values
else
requested_status = (params[:issue] && params[:issue][:status_id] ? IssueStatus.find_by_id(params[:issue][:status_id]) : default_status)
# Check that the user is allowed to apply the requested status
@issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x,
:customized => @issue,
:value => (params[:custom_fields] ? params[:custom_fields][x.id.to_s] : nil)) }
@issue.custom_values = @custom_values
if @issue.save
attach_files(@issue, params[:attachments])
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
redirect_to :controller => 'issues', :action => 'show', :id => @issue
return
end
end
@priorities = Enumeration::get_values('IPRI')
render :layout => !request.xhr?
end
# Attributes that can be updated on workflow transition (without :edit permission)
# TODO: make it configurable (at least per role)
UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
def edit def edit
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@activities = Enumeration::get_values('ACTI')
@priorities = Enumeration::get_values('IPRI') @priorities = Enumeration::get_values('IPRI')
@custom_values = [] @custom_values = []
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
@notes = params[:notes]
journal = @issue.init_journal(User.current, @notes)
# User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
attrs = params[:issue].dup
attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
@issue.attributes = attrs
end
if request.get? if request.get?
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) } @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }
else else
# Update custom fields if user has :edit permission begin
if @edit_allowed && params[:custom_fields] @issue.init_journal(User.current)
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } # Retrieve custom fields and values
@issue.custom_values = @custom_values if params["custom_fields"]
end @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) @issue.custom_values = @custom_values
@time_entry.attributes = params[:time_entry]
attachments = attach_files(@issue, params[:attachments])
attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
if @issue.save
# Log spend time
if current_role.allowed_to?(:log_time)
@time_entry.save
end end
if !journal.new_record? @issue.attributes = params[:issue]
# Only send notification if something was actually changed if @issue.save
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
end end
redirect_to(params[:back_to] || {:action => 'show', :id => @issue}) rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
flash[:error] = l(:notice_locking_conflict)
end end
end end
rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
flash.now[:error] = l(:notice_locking_conflict)
end
# Bulk edit a set of issues
def bulk_edit
if request.post?
status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
unsaved_issue_ids = []
@issues.each do |issue|
journal = issue.init_journal(User.current, params[:notes])
issue.priority = priority if priority
issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
issue.category = category if category || params[:category_id] == 'none'
issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
issue.start_date = params[:start_date] unless params[:start_date].blank?
issue.due_date = params[:due_date] unless params[:due_date].blank?
issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
# Don't save any change to the issue if the user is not authorized to apply the requested status
if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
# Send notification for each issue (if changed)
Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
else
# Keep unsaved issue ids to display them in flash error
unsaved_issue_ids << issue.id
end
end
if unsaved_issue_ids.empty?
flash[:notice] = l(:notice_successful_update) unless @issues.empty?
else
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
end
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
return
end
# Find potential statuses the user could be allowed to switch issues to
@available_statuses = Workflow.find(:all, :include => :new_status,
:conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
end
def move
@allowed_projects = []
# find projects to which the user is allowed to move the issue
if User.current.admin?
# admin is allowed to move issues to any active (visible) project
@allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
else
User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)}
end
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
@target_project ||= @project
@trackers = @target_project.trackers
if request.post?
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
unsaved_issue_ids = []
@issues.each do |issue|
unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
end
if unsaved_issue_ids.empty?
flash[:notice] = l(:notice_successful_update) unless @issues.empty?
else
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
end
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
return
end
render :layout => false if request.xhr?
end end
def destroy def add_note
@hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f journal = @issue.init_journal(User.current, params[:notes])
if @hours > 0 attachments = attach_files(@issue, params[:attachments])
case params[:todo] attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
when 'destroy' if journal.save
# nothing to do flash[:notice] = l(:notice_successful_update)
when 'nullify' Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) redirect_to :action => 'show', :id => @issue
when 'reassign' return
reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
if reassign_to.nil?
flash.now[:error] = l(:error_issue_not_found_in_project)
return
else
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
end
else
# display the destroy form
return
end
end end
@issues.each(&:destroy) show
end
def change_status
@status_options = @issue.status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)
@new_status = IssueStatus.find(params[:new_status_id])
if params[:confirm]
begin
journal = @issue.init_journal(User.current, params[:notes])
@issue.status = @new_status
if @issue.update_attributes(params[:issue])
attachments = attach_files(@issue, params[:attachments])
attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
# Log time
if current_role.allowed_to?(:log_time)
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
@time_entry.attributes = params[:time_entry]
@time_entry.save
end
flash[:notice] = l(:notice_successful_update)
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
redirect_to :action => 'show', :id => @issue
end
rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
flash[:error] = l(:notice_locking_conflict)
end
end
@assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }
@activities = Enumeration::get_values('ACTI')
end
def destroy
@issue.destroy
redirect_to :action => 'index', :project_id => @project redirect_to :action => 'index', :project_id => @project
end end
@@ -317,71 +174,35 @@ class IssuesController < ApplicationController
end end
def context_menu def context_menu
@issues = Issue.find_all_by_id(params[:ids], :include => :project)
if (@issues.size == 1)
@issue = @issues.first
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@assignables = @issue.assignable_users
@assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
end
projects = @issues.collect(&:project).compact.uniq
@project = projects.first if projects.size == 1
@can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
:update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))),
:move => (@project && User.current.allowed_to?(:move_issues, @project)),
:copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
:delete => (@project && User.current.allowed_to?(:delete_issues, @project))
}
@priorities = Enumeration.get_values('IPRI').reverse @priorities = Enumeration.get_values('IPRI').reverse
@statuses = IssueStatus.find(:all, :order => 'position') @statuses = IssueStatus.find(:all, :order => 'position')
@back = request.env['HTTP_REFERER'] @allowed_statuses = @issue.status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)
@assignables = @issue.assignable_users
@assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
@can = {:edit => User.current.allowed_to?(:edit_issues, @project),
:change_status => User.current.allowed_to?(:change_issue_status, @project),
:add => User.current.allowed_to?(:add_issues, @project),
:move => User.current.allowed_to?(:move_issues, @project),
:copy => (@project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
:delete => User.current.allowed_to?(:delete_issues, @project)}
render :layout => false render :layout => false
end end
def update_form
@issue = Issue.new(params[:issue])
render :action => :new, :layout => false
end
def preview def preview
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? issue = Issue.find_by_id(params[:id])
@attachements = @issue.attachments if @issue @attachements = issue.attachments if issue
@text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) @text = params[:issue][:description]
render :partial => 'common/preview' render :partial => 'common/preview'
end end
private private
def find_issue def find_project
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
@project = @issue.project @project = @issue.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end
# Filter for bulk operations
def find_issues
@issues = Issue.find_all_by_id(params[:id] || params[:ids])
raise ActiveRecord::RecordNotFound if @issues.empty?
projects = @issues.collect(&:project).compact.uniq
if projects.size == 1
@project = projects.first
else
# TODO: let users bulk edit/move/destroy issues from different projects
render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
end
rescue ActiveRecord::RecordNotFound
render_404
end
def find_project
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
def find_optional_project def find_optional_project
return true unless params[:project_id] return true unless params[:project_id]
@project = Project.find(params[:project_id]) @project = Project.find(params[:project_id])
@@ -392,14 +213,11 @@ private
# Retrieve query from session or build a new query # Retrieve query from session or build a new query
def retrieve_query def retrieve_query
if !params[:query_id].blank? if params[:query_id]
cond = "project_id IS NULL" @query = Query.find(params[:query_id], :conditions => {:project_id => (@project ? @project.id : nil)})
cond << " OR project_id = #{@project.id}" if @project session[:query] = @query
@query = Query.find(params[:query_id], :conditions => cond)
@query.project = @project
session[:query] = {:id => @query.id, :project_id => @query.project_id}
else else
if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) if params[:set_filter] or !session[:query] or session[:query].project != @project
# Give it a name, required to be valid # Give it a name, required to be valid
@query = Query.new(:name => "_") @query = Query.new(:name => "_")
@query.project = @project @query.project = @project
@@ -412,11 +230,9 @@ private
@query.add_short_filter(field, params[field]) if params[field] @query.add_short_filter(field, params[field]) if params[field]
end end
end end
session[:query] = {:project_id => @query.project_id, :filters => @query.filters} session[:query] = @query
else else
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id] @query = session[:query]
@query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters])
@query.project = @project
end end
end end
end end
-41
View File
@@ -1,41 +0,0 @@
# redMine - project management software
# Copyright (C) 2006-2008 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class JournalsController < ApplicationController
layout 'base'
before_filter :find_journal
def edit
if request.post?
@journal.update_attributes(:notes => params[:notes]) if params[:notes]
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
respond_to do |format|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
format.js { render :action => 'update' }
end
end
end
private
def find_journal
@journal = Journal.find(params[:id])
render_403 and return false unless @journal.editable_by?(User.current)
@project = @journal.journalized.project
rescue ActiveRecord::RecordNotFound
render_404
end
end
+3 -13
View File
@@ -17,10 +17,9 @@
class MessagesController < ApplicationController class MessagesController < ApplicationController
layout 'base' layout 'base'
menu_item :boards before_filter :find_board, :only => :new
before_filter :find_board, :only => [:new, :preview] before_filter :find_message, :except => :new
before_filter :find_message, :except => [:new, :preview] before_filter :authorize
before_filter :authorize, :except => :preview
verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
@@ -29,8 +28,6 @@ class MessagesController < ApplicationController
# Show a topic and its replies # Show a topic and its replies
def show def show
@replies = @topic.children
@replies.reverse! if User.current.wants_comments_in_reverse_order?
@reply = Message.new(:subject => "RE: #{@message.subject}") @reply = Message.new(:subject => "RE: #{@message.subject}")
render :action => "show", :layout => false if request.xhr? render :action => "show", :layout => false if request.xhr?
end end
@@ -83,13 +80,6 @@ class MessagesController < ApplicationController
{ :action => 'show', :id => @message.parent } { :action => 'show', :id => @message.parent }
end end
def preview
message = @board.messages.find_by_id(params[:id])
@attachements = message.attachments if message
@text = (params[:message] || params[:reply])[:content]
render :partial => 'common/preview'
end
private private
def find_message def find_message
find_board find_board
+1 -2
View File
@@ -26,8 +26,7 @@ class MyController < ApplicationController
'issueswatched' => :label_watched_issues, 'issueswatched' => :label_watched_issues,
'news' => :label_news_latest, 'news' => :label_news_latest,
'calendar' => :label_calendar, 'calendar' => :label_calendar,
'documents' => :label_document_plural, 'documents' => :label_document_plural
'timelog' => :label_spent_time
}.freeze }.freeze
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'], DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
+2 -29
View File
@@ -17,9 +17,7 @@
class NewsController < ApplicationController class NewsController < ApplicationController
layout 'base' layout 'base'
before_filter :find_news, :except => [:new, :index, :preview] before_filter :find_project, :authorize, :except => :index
before_filter :find_project, :only => :new
before_filter :authorize, :except => [:index, :preview]
before_filter :find_optional_project, :only => :index before_filter :find_optional_project, :only => :index
accept_key_auth :index accept_key_auth :index
@@ -36,22 +34,8 @@ class NewsController < ApplicationController
end end
def show def show
@comments = @news.comments
@comments.reverse! if User.current.wants_comments_in_reverse_order?
end end
def new
@news = News.new(:project => @project, :author => User.current)
if request.post?
@news.attributes = params[:news]
if @news.save
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
redirect_to :controller => 'news', :action => 'index', :project_id => @project
end
end
end
def edit def edit
if request.post? and @news.update_attributes(params[:news]) if request.post? and @news.update_attributes(params[:news])
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
@@ -80,25 +64,14 @@ class NewsController < ApplicationController
redirect_to :action => 'index', :project_id => @project redirect_to :action => 'index', :project_id => @project
end end
def preview
@text = (params[:news] ? params[:news][:description] : nil)
render :partial => 'common/preview'
end
private private
def find_news def find_project
@news = News.find(params[:id]) @news = News.find(params[:id])
@project = @news.project @project = @news.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end
def find_project
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
def find_optional_project def find_optional_project
return true unless params[:project_id] return true unless params[:project_id]
@project = Project.find(params[:project_id]) @project = Project.find(params[:project_id])
+219 -108
View File
@@ -17,19 +17,15 @@
class ProjectsController < ApplicationController class ProjectsController < ApplicationController
layout 'base' layout 'base'
menu_item :overview before_filter :find_project, :except => [ :index, :list, :add ]
menu_item :activity, :only => :activity before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
menu_item :roadmap, :only => :roadmap
menu_item :files, :only => [:list_files, :add_file]
menu_item :settings, :only => :settings
menu_item :issues, :only => [:changelog]
before_filter :find_project, :except => [ :index, :list, :add, :activity ]
before_filter :find_optional_project, :only => :activity
before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
accept_key_auth :activity, :calendar accept_key_auth :activity, :calendar
cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
cache_sweeper :issue_sweeper, :only => [ :add_issue ]
cache_sweeper :version_sweeper, :only => [ :add_version ]
helper :sort helper :sort
include SortHelper include SortHelper
helper :custom_fields helper :custom_fields
@@ -66,17 +62,16 @@ class ProjectsController < ApplicationController
:conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
:order => 'name') :order => 'name')
@project = Project.new(params[:project]) @project = Project.new(params[:project])
@project.enabled_module_names = Redmine::AccessControl.available_project_modules
if request.get? if request.get?
@custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
@project.trackers = Tracker.all @project.trackers = Tracker.all
@project.is_public = Setting.default_projects_public?
@project.enabled_module_names = Redmine::AccessControl.available_project_modules
else else
@project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
@custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
@project.custom_values = @custom_values @project.custom_values = @custom_values
@project.enabled_module_names = params[:enabled_modules]
if @project.save if @project.save
@project.enabled_module_names = params[:enabled_modules]
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
redirect_to :controller => 'admin', :action => 'projects' redirect_to :controller => 'admin', :action => 'projects'
end end
@@ -87,24 +82,12 @@ class ProjectsController < ApplicationController
def show def show
@custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position") @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
@members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
@subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current)) @subprojects = @project.active_children
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
@trackers = @project.rolled_up_trackers @trackers = @project.trackers
@open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
cond = @project.project_condition(Setting.display_subprojects_issues?) @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
Issue.visible_by(User.current) do @total_hours = @project.time_entries.sum(:hours)
@open_issues_by_tracker = Issue.count(:group => :tracker,
:include => [:project, :status, :tracker],
:conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
@total_issues_by_tracker = Issue.count(:group => :tracker,
:include => [:project, :status, :tracker],
:conditions => cond)
end
TimeEntry.visible_by(User.current) do
@total_hours = TimeEntry.sum(:hours,
:include => :project,
:conditions => cond).to_f
end
@key = User.current.rss_key @key = User.current.rss_key
end end
@@ -124,6 +107,7 @@ class ProjectsController < ApplicationController
# Edit @project # Edit @project
def edit def edit
if request.post? if request.post?
@project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
if params[:custom_fields] if params[:custom_fields]
@custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
@project.custom_values = @custom_values @project.custom_values = @custom_values
@@ -193,6 +177,165 @@ class ProjectsController < ApplicationController
end end
end end
# Add a new document to @project
def add_document
@document = @project.documents.build(params[:document])
if request.post? and @document.save
attach_files(@document, params[:attachments])
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
redirect_to :action => 'list_documents', :id => @project
end
end
# Show documents list of @project
def list_documents
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
documents = @project.documents.find :all, :include => [:attachments, :category]
case @sort_by
when 'date'
@grouped = documents.group_by {|d| d.created_on.to_date }
when 'title'
@grouped = documents.group_by {|d| d.title.first.upcase}
when 'author'
@grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
else
@grouped = documents.group_by(&:category)
end
render :layout => false if request.xhr?
end
# Add a new issue to @project
# The new issue will be created from an existing one if copy_from parameter is given
def add_issue
@issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
@issue.project = @project
@issue.author = User.current
@issue.tracker ||= @project.trackers.find(params[:tracker_id])
default_status = IssueStatus.default
unless default_status
flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
render :nothing => true, :layout => true
return
end
@issue.status = default_status
@allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
if request.get?
@issue.start_date ||= Date.today
@custom_values = @issue.custom_values.empty? ?
@project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
@issue.custom_values
else
requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
# Check that the user is allowed to apply the requested status
@issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
@issue.custom_values = @custom_values
if @issue.save
attach_files(@issue, params[:attachments])
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
return
end
end
@priorities = Enumeration::get_values('IPRI')
end
# Bulk edit issues
def bulk_edit_issues
if request.post?
status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
issues = @project.issues.find_all_by_id(params[:issue_ids])
unsaved_issue_ids = []
issues.each do |issue|
journal = issue.init_journal(User.current, params[:notes])
issue.priority = priority if priority
issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
issue.category = category if category
issue.fixed_version = fixed_version if fixed_version
issue.start_date = params[:start_date] unless params[:start_date].blank?
issue.due_date = params[:due_date] unless params[:due_date].blank?
issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
# Don't save any change to the issue if the user is not authorized to apply the requested status
if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
# Send notification for each issue (if changed)
Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
else
# Keep unsaved issue ids to display them in flash error
unsaved_issue_ids << issue.id
end
end
if unsaved_issue_ids.empty?
flash[:notice] = l(:notice_successful_update) unless issues.empty?
else
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
end
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
return
end
if current_role && User.current.allowed_to?(:change_issue_status, @project)
# Find potential statuses the user could be allowed to switch issues to
@available_statuses = Workflow.find(:all, :include => :new_status,
:conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
end
render :update do |page|
page.hide 'query_form'
page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
end
end
def move_issues
@issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
@projects = []
# find projects to which the user is allowed to move the issue
if User.current.admin?
# admin is allowed to move issues to any active (visible) project
@projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
else
User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
end
@target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
@target_project ||= @project
@trackers = @target_project.trackers
if request.post?
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
unsaved_issue_ids = []
@issues.each do |issue|
unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
end
if unsaved_issue_ids.empty?
flash[:notice] = l(:notice_successful_update) unless @issues.empty?
else
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
end
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
return
end
render :layout => false if request.xhr?
end
# Add a news to @project
def add_news
@news = News.new(:project => @project, :author => User.current)
if request.post?
@news.attributes = params[:news]
if @news.save
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
redirect_to :controller => 'news', :action => 'index', :project_id => @project
end
end
end
def add_file def add_file
if request.post? if request.post?
@version = @project.versions.find_by_id(params[:version_id]) @version = @project.versions.find_by_id(params[:version_id])
@@ -204,14 +347,7 @@ class ProjectsController < ApplicationController
end end
def list_files def list_files
sort_init 'filename', 'asc' @versions = @project.versions.sort
sort_update 'filename' => "#{Attachment.table_name}.filename",
'created_on' => "#{Attachment.table_name}.created_on",
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
render :layout => !request.xhr?
end end
# Show changelog for @project # Show changelog for @project
@@ -229,24 +365,33 @@ class ProjectsController < ApplicationController
end end
def activity def activity
@days = Setting.activity_days_default.to_i if params[:year] and params[:year].to_i > 1900
@year = params[:year].to_i
if params[:from] if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
begin; @date_to = params[:from].to_date; rescue; end @month = params[:month].to_i
end
end end
@year ||= Date.today.year
@month ||= Date.today.month
@date_to ||= Date.today + 1 case params[:format]
@date_from = @date_to - @days when 'atom'
# 30 last days
@date_from = Date.today - 30
@date_to = Date.today + 1
else
# current month
@date_from = Date.civil(@year, @month, 1)
@date_to = @date_from >> 1
end
@event_types = %w(issues news files documents changesets wiki_pages messages) @event_types = %w(issues news files documents changesets wiki_pages messages)
if @project @event_types.delete('wiki_pages') unless @project.wiki
@event_types.delete('wiki_pages') unless @project.wiki @event_types.delete('changesets') unless @project.repository
@event_types.delete('changesets') unless @project.repository @event_types.delete('messages') unless @project.boards.any?
@event_types.delete('messages') unless @project.boards.any? # only show what the user is allowed to view
# only show what the user is allowed to view @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
@event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
end
@scope = @event_types.select {|t| params["show_#{t}"]} @scope = @event_types.select {|t| params["show_#{t}"]}
# default events if none is specified in parameters # default events if none is specified in parameters
@scope = (@event_types - %w(wiki_pages messages))if @scope.empty? @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
@@ -254,41 +399,21 @@ class ProjectsController < ApplicationController
@events = [] @events = []
if @scope.include?('issues') if @scope.include?('issues')
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects)) @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) @events += @project.issues_status_changes(@date_from, @date_to)
@events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
@events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
end end
if @scope.include?('news') if @scope.include?('news')
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects)) @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
@events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
end end
if @scope.include?('files') if @scope.include?('files')
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects)) @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
@events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
:joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
"LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id",
:conditions => cond.conditions)
end end
if @scope.include?('documents') if @scope.include?('documents')
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects)) @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
@events += Document.find(:all, :include => :project, :conditions => cond.conditions)
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
@events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
:joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
:conditions => cond.conditions)
end end
if @scope.include?('wiki_pages') if @scope.include?('wiki_pages')
@@ -297,36 +422,33 @@ class ProjectsController < ApplicationController
"#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
"#{WikiContent.versioned_table_name}.id" "#{WikiContent.versioned_table_name}.id"
joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
"LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " + "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
"LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id" conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
@project.id, @date_from, @date_to]
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects)) @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
@events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
end end
if @scope.include?('changesets') if @scope.include?('changesets')
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects)) @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
@events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
end end
if @scope.include?('messages') if @scope.include?('messages')
cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects)) @events += Message.find(:all,
cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) :include => [:board, :author],
@events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions) :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
end end
@events_by_day = @events.group_by(&:event_date) @events_by_day = @events.group_by(&:event_date)
respond_to do |format| respond_to do |format|
format.html { render :layout => false if request.xhr? } format.html { render :layout => false if request.xhr? }
format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") } format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
end end
end end
def calendar def calendar
@trackers = @project.rolled_up_trackers @trackers = Tracker.find(:all, :order => 'position')
retrieve_selected_tracker_ids(@trackers) retrieve_selected_tracker_ids(@trackers)
if params[:year] and params[:year].to_i > 1900 if params[:year] and params[:year].to_i > 1900
@@ -338,23 +460,22 @@ class ProjectsController < ApplicationController
@year ||= Date.today.year @year ||= Date.today.year
@month ||= Date.today.month @month ||= Date.today.month
@calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
events = [] events = []
@project.issues_with_subprojects(@with_subprojects) do @project.issues_with_subprojects(params[:with_subprojects]) do
events += Issue.find(:all, events += Issue.find(:all,
:include => [:tracker, :status, :assigned_to, :priority, :project], :include => [:tracker, :status, :assigned_to, :priority, :project],
:conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
) unless @selected_tracker_ids.empty? ) unless @selected_tracker_ids.empty?
events += Version.find(:all, :include => :project,
:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
end end
events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
@calendar.events = events @calendar.events = events
render :layout => false if request.xhr? render :layout => false if request.xhr?
end end
def gantt def gantt
@trackers = @project.rolled_up_trackers @trackers = Tracker.find(:all, :order => 'position')
retrieve_selected_tracker_ids(@trackers) retrieve_selected_tracker_ids(@trackers)
if params[:year] and params[:year].to_i >0 if params[:year] and params[:year].to_i >0
@@ -382,18 +503,16 @@ class ProjectsController < ApplicationController
@date_from = Date.civil(@year_from, @month_from, 1) @date_from = Date.civil(@year_from, @month_from, 1)
@date_to = (@date_from >> @months) - 1 @date_to = (@date_from >> @months) - 1
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
@events = [] @events = []
@project.issues_with_subprojects(@with_subprojects) do @project.issues_with_subprojects(params[:with_subprojects]) do
@events += Issue.find(:all, @events += Issue.find(:all,
:order => "start_date, due_date", :order => "start_date, due_date",
:include => [:tracker, :status, :assigned_to, :priority, :project], :include => [:tracker, :status, :assigned_to, :priority, :project],
:conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to] :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
) unless @selected_tracker_ids.empty? ) unless @selected_tracker_ids.empty?
@events += Version.find(:all, :include => :project,
:conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
end end
@events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
@events.sort! {|x,y| x.start_date <=> y.start_date } @events.sort! {|x,y| x.start_date <=> y.start_date }
if params[:format]=='pdf' if params[:format]=='pdf'
@@ -419,14 +538,6 @@ private
render_404 render_404
end end
def find_optional_project
return true unless params[:id]
@project = Project.find(params[:id])
authorize
rescue ActiveRecord::RecordNotFound
render_404
end
def retrieve_selected_tracker_ids(selectable_trackers) def retrieve_selected_tracker_ids(selectable_trackers)
if ids = params[:tracker_ids] 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 } @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
+19 -19
View File
@@ -17,15 +17,19 @@
class QueriesController < ApplicationController class QueriesController < ApplicationController
layout 'base' layout 'base'
menu_item :issues before_filter :find_project, :authorize
before_filter :find_query, :except => :new
before_filter :find_optional_project, :only => :new def index
@queries = @project.queries.find(:all,
:order => "name ASC",
:conditions => ["is_public = ? or user_id = ?", true, (User.current.logged? ? User.current.id : 0)])
end
def new def new
@query = Query.new(params[:query]) @query = Query.new(params[:query])
@query.project = params[:query_is_for_all] ? nil : @project @query.project = @project
@query.user = User.current @query.user = User.current
@query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin? @query.is_public = false unless current_role.allowed_to?(:manage_public_queries)
@query.column_names = nil if params[:default_columns] @query.column_names = nil if params[:default_columns]
params[:fields].each do |field| params[:fields].each do |field|
@@ -47,8 +51,7 @@ class QueriesController < ApplicationController
@query.add_filter(field, params[:operators][field], params[:values][field]) @query.add_filter(field, params[:operators][field], params[:values][field])
end if params[:fields] end if params[:fields]
@query.attributes = params[:query] @query.attributes = params[:query]
@query.project = nil if params[:query_is_for_all] @query.is_public = false unless current_role.allowed_to?(:manage_public_queries)
@query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
@query.column_names = nil if params[:default_columns] @query.column_names = nil if params[:default_columns]
if @query.save if @query.save
@@ -60,21 +63,18 @@ class QueriesController < ApplicationController
def destroy def destroy
@query.destroy if request.post? @query.destroy if request.post?
redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 redirect_to :controller => 'queries', :project_id => @project
end end
private private
def find_query def find_project
@query = Query.find(params[:id]) if params[:id]
@project = @query.project @query = Query.find(params[:id])
render_403 unless @query.editable_by?(User.current) @project = @query.project
rescue ActiveRecord::RecordNotFound render_403 unless @query.editable_by?(User.current)
render_404 else
end @project = Project.find(params[:project_id])
end
def find_optional_project
@project = Project.find(params[:project_id]) if params[:project_id]
User.current.allowed_to?(:save_queries, @project, :global => true)
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end
+1 -25
View File
@@ -17,7 +17,6 @@
class ReportsController < ApplicationController class ReportsController < ApplicationController
layout 'base' layout 'base'
menu_item :issues
before_filter :find_project, :authorize before_filter :find_project, :authorize
def issue_report def issue_report
@@ -48,12 +47,6 @@ class ReportsController < ApplicationController
@data = issues_by_category @data = issues_by_category
@report_title = l(:field_category) @report_title = l(:field_category)
render :template => "reports/issue_report_details" render :template => "reports/issue_report_details"
when "assigned_to"
@field = "assigned_to_id"
@rows = @project.members.collect { |m| m.user }
@data = issues_by_assigned_to
@report_title = l(:field_assigned_to)
render :template => "reports/issue_report_details"
when "author" when "author"
@field = "author_id" @field = "author_id"
@rows = @project.members.collect { |m| m.user } @rows = @project.members.collect { |m| m.user }
@@ -71,14 +64,12 @@ class ReportsController < ApplicationController
@versions = @project.versions.sort @versions = @project.versions.sort
@priorities = Enumeration::get_values('IPRI') @priorities = Enumeration::get_values('IPRI')
@categories = @project.issue_categories @categories = @project.issue_categories
@assignees = @project.members.collect { |m| m.user }
@authors = @project.members.collect { |m| m.user } @authors = @project.members.collect { |m| m.user }
@subprojects = @project.active_children @subprojects = @project.active_children
issues_by_tracker issues_by_tracker
issues_by_version issues_by_version
issues_by_priority issues_by_priority
issues_by_category issues_by_category
issues_by_assigned_to
issues_by_author issues_by_author
issues_by_subproject issues_by_subproject
@@ -189,22 +180,7 @@ private
and i.project_id=#{@project.id} and i.project_id=#{@project.id}
group by s.id, s.is_closed, c.id") group by s.id, s.is_closed, c.id")
end end
def issues_by_assigned_to
@issues_by_assigned_to ||=
ActiveRecord::Base.connection.select_all("select s.id as status_id,
s.is_closed as closed,
a.id as assigned_to_id,
count(i.id) as total
from
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
where
i.status_id=s.id
and i.assigned_to_id=a.id
and i.project_id=#{@project.id}
group by s.id, s.is_closed, a.id")
end
def issues_by_author def issues_by_author
@issues_by_author ||= @issues_by_author ||=
ActiveRecord::Base.connection.select_all("select s.id as status_id, ActiveRecord::Base.connection.select_all("select s.id as status_id,
+18 -52
View File
@@ -19,12 +19,11 @@ require 'SVG/Graph/Bar'
require 'SVG/Graph/BarHorizontal' require 'SVG/Graph/BarHorizontal'
require 'digest/sha1' require 'digest/sha1'
class ChangesetNotFound < Exception; end class ChangesetNotFound < Exception
class InvalidRevisionParam < Exception; end end
class RepositoriesController < ApplicationController class RepositoriesController < ApplicationController
layout 'base' layout 'base'
menu_item :repository
before_filter :find_repository, :except => :edit before_filter :find_repository, :except => :edit
before_filter :find_project, :only => :edit before_filter :find_project, :only => :edit
before_filter :authorize before_filter :authorize
@@ -51,13 +50,11 @@ class RepositoriesController < ApplicationController
def show def show
# check if new revisions have been committed in the repository # check if new revisions have been committed in the repository
@repository.fetch_changesets if Setting.autofetch_changesets? @repository.fetch_changesets if Setting.autofetch_changesets?
# root entries # get entries for the browse frame
@entries = @repository.entries('', @rev) @entries = @repository.entries('')
# latest changesets # latest changesets
@changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC") @changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC")
show_error_not_found unless @entries || @changesets.any? show_error and return unless @entries || @changesets.any?
rescue Redmine::Scm::Adapters::CommandFailed => e
show_error_command_failed(e.message)
end end
def browse def browse
@@ -65,25 +62,20 @@ class RepositoriesController < ApplicationController
if request.xhr? if request.xhr?
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true) @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
else else
show_error_not_found and return unless @entries show_error unless @entries
render :action => 'browse'
end end
rescue Redmine::Scm::Adapters::CommandFailed => e
show_error_command_failed(e.message)
end end
def changes def changes
@entry = @repository.scm.entry(@path, @rev) @entry = @repository.scm.entry(@path, @rev)
show_error_not_found and return unless @entry show_error and return unless @entry
@changesets = @repository.changesets_for_path(@path) @changesets = @repository.changesets_for_path(@path)
rescue Redmine::Scm::Adapters::CommandFailed => e
show_error_command_failed(e.message)
end end
def revisions def revisions
@changeset_count = @repository.changesets.count @changeset_count = @repository.changesets.count
@changeset_pages = Paginator.new self, @changeset_count, @changeset_pages = Paginator.new self, @changeset_count,
per_page_option, 25,
params['page'] params['page']
@changesets = @repository.changesets.find(:all, @changesets = @repository.changesets.find(:all,
:limit => @changeset_pages.items_per_page, :limit => @changeset_pages.items_per_page,
@@ -96,30 +88,19 @@ class RepositoriesController < ApplicationController
end end
def entry def entry
@entry = @repository.scm.entry(@path, @rev)
show_error_not_found and return unless @entry
# If the entry is a dir, show the browser
browse and return if @entry.is_dir?
@content = @repository.scm.cat(@path, @rev) @content = @repository.scm.cat(@path, @rev)
show_error_not_found and return unless @content show_error and return unless @content
if 'raw' == params[:format] || @content.is_binary_data? if 'raw' == params[:format]
# Force the download if it's a binary file
send_data @content, :filename => @path.split('/').last send_data @content, :filename => @path.split('/').last
else else
# Prevent empty lines when displaying a file with Windows style eol # Prevent empty lines when displaying a file with Windows style eol
@content.gsub!("\r\n", "\n") @content.gsub!("\r\n", "\n")
end end
rescue Redmine::Scm::Adapters::CommandFailed => e
show_error_command_failed(e.message)
end end
def annotate def annotate
@annotate = @repository.scm.annotate(@path, @rev) @annotate = @repository.scm.annotate(@path, @rev)
render_error l(:error_scm_annotate) and return if @annotate.nil? || @annotate.empty? show_error and return if @annotate.nil? || @annotate.empty?
rescue Redmine::Scm::Adapters::CommandFailed => e
show_error_command_failed(e.message)
end end
def revision def revision
@@ -136,12 +117,11 @@ class RepositoriesController < ApplicationController
format.js {render :layout => false} format.js {render :layout => false}
end end
rescue ChangesetNotFound rescue ChangesetNotFound
show_error_not_found show_error
rescue Redmine::Scm::Adapters::CommandFailed => e
show_error_command_failed(e.message)
end end
def diff def diff
@rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1)
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
@@ -154,10 +134,8 @@ class RepositoriesController < ApplicationController
@cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
unless read_fragment(@cache_key) unless read_fragment(@cache_key)
@diff = @repository.diff(@path, @rev, @rev_to, @diff_type) @diff = @repository.diff(@path, @rev, @rev_to, @diff_type)
show_error_not_found unless @diff show_error and return unless @diff
end end
rescue Redmine::Scm::Adapters::CommandFailed => e
show_error_command_failed(e.message)
end end
def stats def stats
@@ -186,29 +164,20 @@ private
render_404 render_404
end end
REV_PARAM_RE = %r{^[a-f0-9]*$}
def find_repository def find_repository
@project = Project.find(params[:id]) @project = Project.find(params[:id])
@repository = @project.repository @repository = @project.repository
render_404 and return false unless @repository render_404 and return false unless @repository
@path = params[:path].join('/') unless params[:path].nil? @path = params[:path].join('/') unless params[:path].nil?
@path ||= '' @path ||= ''
@rev = params[:rev] @rev = params[:rev].to_i if params[:rev]
@rev_to = params[:rev_to]
raise InvalidRevisionParam unless @rev.to_s.match(REV_PARAM_RE) && @rev.to_s.match(REV_PARAM_RE)
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
rescue InvalidRevisionParam
show_error_not_found
end end
def show_error_not_found def show_error
render_error l(:error_scm_not_found) flash.now[:error] = l(:notice_scm_error)
end render :nothing => true, :layout => true
def show_error_command_failed(msg)
render_error l(:error_scm_command_failed, msg)
end end
def graph_commits_per_month(repository) def graph_commits_per_month(repository)
@@ -267,9 +236,6 @@ private
commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.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 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( graph = SVG::Graph::BarHorizontal.new(
:height => 300, :height => 300,
:width => 500, :width => 500,
+5 -9
View File
@@ -36,15 +36,10 @@ class RolesController < ApplicationController
# Prefills the form with 'Non member' role permissions # Prefills the form with 'Non member' role permissions
@role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
if request.post? && @role.save if request.post? && @role.save
# workflow copy
if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
@role.workflows.copy(copy_from)
end
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'list' redirect_to :action => 'list'
end end
@permissions = @role.setable_permissions @permissions = @role.setable_permissions
@roles = Role.find :all, :order => 'builtin, position'
end end
def edit def edit
@@ -58,11 +53,12 @@ class RolesController < ApplicationController
def destroy def destroy
@role = Role.find(params[:id]) @role = Role.find(params[:id])
@role.destroy #unless @role.members.empty?
# flash[:error] = 'Some members have this role. Can\'t delete it.'
#else
@role.destroy
#end
redirect_to :action => 'list' redirect_to :action => 'list'
rescue
flash[:error] = 'This role is in use and can not be deleted.'
redirect_to :action => 'index'
end end
def move def move
+6 -5
View File
@@ -17,8 +17,6 @@
class SearchController < ApplicationController class SearchController < ApplicationController
layout 'base' layout 'base'
before_filter :find_optional_project
helper :messages helper :messages
include MessagesHelper include MessagesHelper
@@ -38,6 +36,11 @@ class SearchController < ApplicationController
return return
end end
if params[:id]
find_project
return unless check_project_privacy
end
if @project if @project
# only show what the user is allowed to view # only show what the user is allowed to view
@object_types = %w(issues news documents changesets wiki_pages messages) @object_types = %w(issues news documents changesets wiki_pages messages)
@@ -101,10 +104,8 @@ class SearchController < ApplicationController
end end
private private
def find_optional_project def find_project
return true unless params[:id]
@project = Project.find(params[:id]) @project = Project.find(params[:id])
check_project_privacy
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end
+3 -13
View File
@@ -25,20 +25,10 @@ class SettingsController < ApplicationController
end end
def edit def edit
@notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted) if request.post? and params[:settings] and params[:settings].is_a? Hash
if request.post? && params[:settings] && params[:settings].is_a?(Hash) params[:settings].each { |name, value| Setting[name] = value }
settings = (params[:settings] || {}).dup.symbolize_keys redirect_to :action => 'edit' and return
settings.each do |name, value|
# remove blank values in array settings
value.delete_if {|v| v.blank? } if value.is_a?(Array)
Setting[name] = value
end
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'edit', :tab => params[:tab]
return
end end
@options = {}
@options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
end end
def plugin def plugin
+73 -160
View File
@@ -16,71 +16,55 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class TimelogController < ApplicationController class TimelogController < ApplicationController
layout 'base' layout 'base'
menu_item :issues
before_filter :find_project, :authorize before_filter :find_project, :authorize
verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
helper :sort helper :sort
include SortHelper include SortHelper
helper :issues helper :issues
include TimelogHelper
helper :custom_fields
include CustomFieldsHelper
def report def report
@available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id", @available_criterias = { 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
:klass => Project, :values => @project.versions,
:label => :label_project},
'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
:klass => Version,
:label => :label_version}, :label => :label_version},
'category' => {:sql => "#{Issue.table_name}.category_id", 'category' => {:sql => "#{Issue.table_name}.category_id",
:klass => IssueCategory, :values => @project.issue_categories,
:label => :field_category}, :label => :field_category},
'member' => {:sql => "#{TimeEntry.table_name}.user_id", 'member' => {:sql => "#{TimeEntry.table_name}.user_id",
:klass => User, :values => @project.users,
:label => :label_member}, :label => :label_member},
'tracker' => {:sql => "#{Issue.table_name}.tracker_id", 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
:klass => Tracker, :values => Tracker.find(:all),
:label => :label_tracker}, :label => :label_tracker},
'activity' => {:sql => "#{TimeEntry.table_name}.activity_id", 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
:klass => Enumeration, :values => Enumeration::get_values('ACTI'),
:label => :label_activity}, :label => :label_activity}
'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
:klass => Issue,
:label => :label_issue}
} }
# Add list and boolean custom fields as available criterias
@project.all_custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
@available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM custom_values c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = issues.id)",
:format => cf.field_format,
:label => cf.name}
end
@criterias = params[:criterias] || [] @criterias = params[:criterias] || []
@criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria} @criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
@criterias.uniq! @criterias.uniq!
@criterias = @criterias[0,3]
@columns = (params[:columns] && %w(year month week day).include?(params[:columns])) ? params[:columns] : 'month' @columns = (params[:period] && %w(year month week).include?(params[:period])) ? params[:period] : 'month'
retrieve_date_range if params[:date_from]
begin; @date_from = params[:date_from].to_date; rescue; end
end
if params[:date_to]
begin; @date_to = params[:date_to].to_date; rescue; end
end
@date_from ||= Date.civil(Date.today.year, 1, 1)
@date_to ||= (Date.civil(Date.today.year, Date.today.month, 1) >> 1) - 1
unless @criterias.empty? unless @criterias.empty?
sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ') sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ') sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours" sql = "SELECT #{sql_select}, tyear, tmonth, tweek, SUM(hours) AS hours"
sql << " FROM #{TimeEntry.table_name}" sql << " FROM #{TimeEntry.table_name} LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id" sql << " WHERE #{TimeEntry.table_name}.project_id = %s" % @project.id
sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id" sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@date_from.to_time), ActiveRecord::Base.connection.quoted_date(@date_to.to_time)]
sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?) sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek"
sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries)
sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
@hours = ActiveRecord::Base.connection.select_all(sql) @hours = ActiveRecord::Base.connection.select_all(sql)
@@ -92,106 +76,54 @@ class TimelogController < ApplicationController
row['month'] = "#{row['tyear']}-#{row['tmonth']}" row['month'] = "#{row['tyear']}-#{row['tmonth']}"
when 'week' when 'week'
row['week'] = "#{row['tyear']}-#{row['tweek']}" row['week'] = "#{row['tyear']}-#{row['tweek']}"
when 'day'
row['day'] = "#{row['spent_on']}"
end end
end end
end
@total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
@periods = []
@periods = [] date_from = @date_from
# Date#at_beginning_of_ not supported in Rails 1.2.x # 100 columns max
date_from = @from.to_time while date_from < @date_to && @periods.length < 100
# 100 columns max case @columns
while date_from <= @to.to_time && @periods.length < 100 when 'year'
case @columns @periods << "#{date_from.year}"
when 'year' date_from = date_from >> 12
@periods << "#{date_from.year}" when 'month'
date_from = (date_from + 1.year).at_beginning_of_year @periods << "#{date_from.year}-#{date_from.month}"
when 'month' date_from = date_from >> 1
@periods << "#{date_from.year}-#{date_from.month}" when 'week'
date_from = (date_from + 1.month).at_beginning_of_month @periods << "#{date_from.year}-#{date_from.cweek}"
when 'week' date_from = date_from + 7
@periods << "#{date_from.year}-#{date_from.to_date.cweek}"
date_from = (date_from + 7.day).at_beginning_of_week
when 'day'
@periods << "#{date_from.to_date}"
date_from = date_from + 1.day
end
end end
end end
respond_to do |format| render :layout => false if request.xhr?
format.html { render :layout => !request.xhr? }
format.csv { send_data(report_to_csv(@criterias, @periods, @hours).read, :type => 'text/csv; header=present', :filename => 'timelog.csv') }
end
end end
def details def details
sort_init 'spent_on', 'desc' sort_init 'spent_on', 'desc'
sort_update 'spent_on' => 'spent_on', sort_update
'user' => 'user_id',
'activity' => 'activity_id',
'project' => "#{Project.table_name}.name",
'issue' => 'issue_id',
'hours' => 'hours'
cond = ARCondition.new @entries = (@issue ? @issue : @project).time_entries.find(:all, :include => [:activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], :order => sort_clause)
cond << (@issue.nil? ? @project.project_condition(Setting.display_subprojects_issues?) :
["#{TimeEntry.table_name}.issue_id = ?", @issue.id]) @total_hours = @entries.inject(0) { |sum,entry| sum + entry.hours }
@owner_id = User.current.id
retrieve_date_range send_csv and return if 'csv' == params[:export]
cond << ['spent_on BETWEEN ? AND ?', @from, @to] render :action => 'details', :layout => false if request.xhr?
TimeEntry.visible_by(User.current) do
respond_to do |format|
format.html {
# Paginate results
@entry_count = TimeEntry.count(:include => :project, :conditions => cond.conditions)
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
@entries = TimeEntry.find(:all,
:include => [:project, :activity, :user, {:issue => :tracker}],
:conditions => cond.conditions,
:order => sort_clause,
:limit => @entry_pages.items_per_page,
:offset => @entry_pages.current.offset)
@total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
render :layout => !request.xhr?
}
format.csv {
# Export all entries
@entries = TimeEntry.find(:all,
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
:conditions => cond.conditions,
:order => sort_clause)
send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
}
end
end
end end
def edit def edit
render_403 and return if @time_entry && !@time_entry.editable_by?(User.current) render_404 and return if @time_entry && @time_entry.user != User.current
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
@time_entry.attributes = params[:time_entry] @time_entry.attributes = params[:time_entry]
if request.post? and @time_entry.save if request.post? and @time_entry.save
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to(params[:back_url].blank? ? {:action => 'details', :project_id => @time_entry.project} : params[:back_url]) redirect_to :action => 'details', :project_id => @time_entry.project, :issue_id => @time_entry.issue
return return
end end
@activities = Enumeration::get_values('ACTI') @activities = Enumeration::get_values('ACTI')
end end
def destroy
render_404 and return unless @time_entry
render_403 and return unless @time_entry.editable_by?(User.current)
@time_entry.destroy
flash[:notice] = l(:notice_successful_delete)
redirect_to :back
rescue RedirectBackError
redirect_to :action => 'details', :project_id => @time_entry.project
end
private private
def find_project def find_project
@@ -207,53 +139,34 @@ private
render_404 render_404
return false return false
end end
rescue ActiveRecord::RecordNotFound
render_404
end end
# Retrieves the date range based on predefined ranges or specific from/to param dates def send_csv
def retrieve_date_range ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
@free_period = false export = StringIO.new
@from, @to = nil, nil CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
# csv header fields
if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?) headers = [l(:field_spent_on),
case params[:period].to_s l(:field_user),
when 'today' l(:field_activity),
@from = @to = Date.today l(:field_issue),
when 'yesterday' l(:field_hours),
@from = @to = Date.today - 1 l(:field_comments)
when 'current_week' ]
@from = Date.today - (Date.today.cwday - 1)%7 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
@to = @from + 6 # csv lines
when 'last_week' @entries.each do |entry|
@from = Date.today - 7 - (Date.today.cwday - 1)%7 fields = [l_date(entry.spent_on),
@to = @from + 6 entry.user.name,
when '7_days' entry.activity.name,
@from = Date.today - 7 (entry.issue ? entry.issue.id : nil),
@to = Date.today entry.hours,
when 'current_month' entry.comments
@from = Date.civil(Date.today.year, Date.today.month, 1) ]
@to = (@from >> 1) - 1 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
when 'last_month'
@from = Date.civil(Date.today.year, Date.today.month, 1) << 1
@to = (@from >> 1) - 1
when '30_days'
@from = Date.today - 30
@to = Date.today
when 'current_year'
@from = Date.civil(Date.today.year, 1, 1)
@to = Date.civil(Date.today.year, 12, 31)
end end
elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?))
begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end
begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end
@free_period = true
else
# default
end end
export.rewind
@from, @to = @to, @from if @from && @to && @from > @to send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
@from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today) - 1
@to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today)
end end
end end
+6 -2
View File
@@ -37,12 +37,16 @@ class TrackersController < ApplicationController
if request.post? and @tracker.save if request.post? and @tracker.save
# workflow copy # workflow copy
if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from])) if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
@tracker.workflows.copy(copy_from) Workflow.transaction do
copy_from.workflows.find(:all, :include => [:role, :old_status, :new_status]).each do |w|
Workflow.create(:tracker_id => @tracker.id, :role => w.role, :old_status => w.old_status, :new_status => w.new_status)
end
end
end end
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'list' redirect_to :action => 'list'
end end
@trackers = Tracker.find :all, :order => 'position' @trackers = Tracker.find :all
end end
def edit def edit
+5 -6
View File
@@ -31,15 +31,15 @@ class UsersController < ApplicationController
def list def list
sort_init 'login', 'asc' sort_init 'login', 'asc'
sort_update %w(login firstname lastname mail admin created_on last_login_on) sort_update
@status = params[:status] ? params[:status].to_i : 1 @status = params[:status] ? params[:status].to_i : 1
conditions = "status <> 0" conditions = nil
conditions = ["status=?", @status] unless @status == 0 conditions = ["status=?", @status] unless @status == 0
@user_count = User.count(:conditions => conditions) @user_count = User.count(:conditions => conditions)
@user_pages = Paginator.new self, @user_count, @user_pages = Paginator.new self, @user_count,
per_page_option, 15,
params['page'] params['page']
@users = User.find :all,:order => sort_clause, @users = User.find :all,:order => sort_clause,
:conditions => conditions, :conditions => conditions,
@@ -83,8 +83,7 @@ class UsersController < ApplicationController
end end
if @user.update_attributes(params[:user]) if @user.update_attributes(params[:user])
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
# Give a string to redirect_to otherwise it would use status param as the response code redirect_to :action => 'list'
redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
end end
end end
@auth_sources = AuthSource.find(:all) @auth_sources = AuthSource.find(:all)
+3 -3
View File
@@ -17,9 +17,10 @@
class VersionsController < ApplicationController class VersionsController < ApplicationController
layout 'base' layout 'base'
menu_item :roadmap
before_filter :find_project, :authorize before_filter :find_project, :authorize
cache_sweeper :version_sweeper, :only => [ :edit, :destroy ]
def show def show
end end
@@ -41,8 +42,7 @@ class VersionsController < ApplicationController
def download def download
@attachment = @version.attachments.find(params[:attachment_id]) @attachment = @version.attachments.find(params[:attachment_id])
@attachment.increment_download @attachment.increment_download
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), send_file @attachment.diskfile, :filename => @attachment.filename, :type => @attachment.content_type
:type => @attachment.content_type
rescue rescue
render_404 render_404
end end
+1 -6
View File
@@ -97,7 +97,7 @@ class WikiController < ApplicationController
@page = @wiki.find_page(params[:page]) @page = @wiki.find_page(params[:page])
@version_count = @page.content.versions.count @version_count = @page.content.versions.count
@version_pages = Paginator.new self, @version_count, per_page_option, params['p'] @version_pages = Paginator.new self, @version_count, 25, params['p']
# don't load text # don't load text
@versions = @page.content.versions.find :all, @versions = @page.content.versions.find :all,
:select => "id, author_id, comments, updated_on, version", :select => "id, author_id, comments, updated_on, version",
@@ -114,11 +114,6 @@ class WikiController < ApplicationController
render_404 unless @diff render_404 unless @diff
end end
def annotate
@page = @wiki.find_page(params[:page])
@annotate = @page.annotate(params[:version])
end
# remove a wiki page and its history # remove a wiki page and its history
def destroy def destroy
@page = @wiki.find_page(params[:page]) @page = @wiki.find_page(params[:page])
-1
View File
@@ -17,7 +17,6 @@
class WikisController < ApplicationController class WikisController < ApplicationController
layout 'base' layout 'base'
menu_item :settings
before_filter :find_project, :authorize before_filter :find_project, :authorize
# Create or update a project's wiki # Create or update a project's wiki
+108 -218
View File
@@ -37,8 +37,8 @@ module ApplicationHelper
user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous' user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
end end
def link_to_issue(issue, options={}) def link_to_issue(issue)
link_to "#{issue.tracker.name} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue}, options link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
end end
def toggle_link(name, id, options={}) def toggle_link(name, id, options={})
@@ -51,7 +51,7 @@ module ApplicationHelper
def show_and_goto_link(name, id, options={}) def show_and_goto_link(name, id, options={})
onclick = "Element.show('#{id}'); " onclick = "Element.show('#{id}'); "
onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
onclick << "Element.scrollTo('#{id}'); " onclick << "location.href='##{id}-anchor'; "
onclick << "return false;" onclick << "return false;"
link_to(name, "#", options.merge(:onclick => onclick)) link_to(name, "#", options.merge(:onclick => onclick))
end end
@@ -90,24 +90,11 @@ module ApplicationHelper
include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format) include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
end end
# Truncates and returns the string as a single line
def truncate_single_line(string, *args)
truncate(string, *args).gsub(%r{[\r\n]+}m, ' ')
end
def html_hours(text)
text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
end
def authoring(created, author) def authoring(created, author)
time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created)) time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
l(:label_added_time_by, author || 'Anonymous', time_tag) l(:label_added_time_by, author || 'Anonymous', time_tag)
end end
def l_or_humanize(s)
l_has_string?("label_#{s}".to_sym) ? l("label_#{s}".to_sym) : s.to_s.humanize
end
def day_name(day) def day_name(day)
l(:general_day_names).split(',')[day-1] l(:general_day_names).split(',')[day-1]
end end
@@ -116,70 +103,46 @@ module ApplicationHelper
l(:actionview_datehelper_select_month_names).split(',')[month-1] l(:actionview_datehelper_select_month_names).split(',')[month-1]
end end
def pagination_links_full(paginator, count=nil, options={}) def pagination_links_full(paginator, options={}, html_options={})
page_param = options.delete(:page_param) || :page page_param = options.delete(:page_param) || :page
url_param = params.dup
# don't reuse params if filters are present
url_param.clear if url_param.has_key?(:set_filter)
html = '' html = ''
html << link_to_remote(('&#171; ' + l(:label_previous)), html << link_to_remote(('&#171; ' + l(:label_previous)),
{:update => 'content', {:update => "content", :url => options.merge(page_param => paginator.current.previous)},
:url => url_param.merge(page_param => paginator.current.previous), {:href => url_for(:params => options.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
:complete => 'window.scrollTo(0,0)'},
{:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
html << (pagination_links_each(paginator, options) do |n| html << (pagination_links_each(paginator, options) do |n|
link_to_remote(n.to_s, link_to_remote(n.to_s,
{:url => {:params => url_param.merge(page_param => n)}, {:url => {:params => options.merge(page_param => n)}, :update => 'content'},
:update => 'content', {:href => url_for(:params => options.merge(page_param => n))})
:complete => 'window.scrollTo(0,0)'},
{:href => url_for(:params => url_param.merge(page_param => n))})
end || '') end || '')
html << ' ' + link_to_remote((l(:label_next) + ' &#187;'), html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
{:update => 'content', {:update => "content", :url => options.merge(page_param => paginator.current.next)},
:url => url_param.merge(page_param => paginator.current.next), {:href => url_for(:params => options.merge(page_param => paginator.current.next))}) if paginator.current.next
:complete => 'window.scrollTo(0,0)'},
{:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
unless count.nil?
html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
end
html html
end end
def per_page_links(selected=nil) def set_html_title(text)
url_param = params.dup @html_header_title = text
url_param.clear if url_param.has_key?(:set_filter)
links = Setting.per_page_options_array.collect do |n|
n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
{:href => url_for(url_param.merge(:per_page => n))})
end
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
end end
def breadcrumb(*args) def html_title
content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb') title = []
title << @project.name if @project
title << @html_header_title
title << Setting.app_title
title.compact.join(' - ')
end end
def html_title(*args) ACCESSKEYS = {:edit => 'e',
if args.empty? :preview => 'r',
title = [] :quick_search => 'f',
title << @project.name if @project :search => '4',
title += @html_title if @html_title }.freeze unless const_defined?(:ACCESSKEYS)
title << Setting.app_title
title.compact.join(' - ')
else
@html_title ||= []
@html_title += args
end
end
def accesskey(s) def accesskey(s)
Redmine::AccessKeys.key_for s ACCESSKEYS[s]
end end
# Formats text according to system settings. # Formats text according to system settings.
@@ -191,33 +154,27 @@ module ApplicationHelper
case args.size case args.size
when 1 when 1
obj = nil obj = nil
text = args.shift text = args.shift || ''
when 2 when 2
obj = args.shift obj = args.shift
text = obj.send(args.shift).to_s text = obj.send(args.shift)
else else
raise ArgumentError, 'invalid arguments to textilizable' raise ArgumentError, 'invalid arguments to textilizable'
end end
return '' if text.blank?
only_path = options.delete(:only_path) == false ? false : true
# when using an image link, try to use an attachment, if possible # when using an image link, try to use an attachment, if possible
attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) attachments = options[:attachments]
if attachments if attachments
text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m| text = text.gsub(/!([<>=]*)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
style = $1 align = $1
filename = $6 filename = $2
rf = Regexp.new(filename, Regexp::IGNORECASE) rf = Regexp.new(filename, Regexp::IGNORECASE)
# search for the picture in attachments # search for the picture in attachments
if found = attachments.detect { |att| att.filename =~ rf } if found = attachments.detect { |att| att.filename =~ rf }
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1") "!#{align}#{image_url}!"
alt = desc.blank? ? nil : "(#{desc})"
"!#{style}#{image_url}#{alt}!"
else else
"!#{style}#{filename}!" "!#{align}#{filename}!"
end end
end end
end end
@@ -235,14 +192,13 @@ module ApplicationHelper
# used for single-file wiki export # used for single-file wiki export
format_wiki_link = Proc.new {|project, title| "##{title}" } format_wiki_link = Proc.new {|project, title| "##{title}" }
else else
format_wiki_link = Proc.new {|project, title| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title) } format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
end end
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) project = options[:project] || @project
# Wiki links # turn wiki links into html links
# # example:
# Examples:
# [[mypage]] # [[mypage]]
# [[mypage|mytext]] # [[mypage|mytext]]
# wiki links can refer other project wikis, using project name or identifier: # wiki links can refer other project wikis, using project name or identifier:
@@ -250,124 +206,47 @@ module ApplicationHelper
# [[project:|mytext]] # [[project:|mytext]]
# [[project:mypage]] # [[project:mypage]]
# [[project:mypage|mytext]] # [[project:mypage|mytext]]
text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m| text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) do |m|
link_project = project link_project = project
esc, all, page, title = $1, $2, $3, $5 page = $1
if esc.nil? title = $3
if page =~ /^([^\:]+)\:(.*)$/ if page =~ /^([^\:]+)\:(.*)$/
link_project = Project.find_by_name($1) || Project.find_by_identifier($1) link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
page = $2 page = title || $2
title ||= $1 if page.blank? title = $1 if page.blank?
end end
if link_project && link_project.wiki if link_project && link_project.wiki
# check if page exists # check if page exists
wiki_page = link_project.wiki.find_page(page) wiki_page = link_project.wiki.find_page(page)
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)), link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
:class => ('wiki-page' + (wiki_page ? '' : ' new'))) :class => ('wiki-page' + (wiki_page ? '' : ' new')))
else
# project or wiki doesn't exist
title || page
end
else else
all # project or wiki doesn't exist
title || page
end end
end end
# Redmine links # turn issue and revision ids into links
# # example:
# Examples: # #52 -> <a href="/issues/show/52">#52</a>
# Issues: # r52 -> <a href="/repositories/revision/6?rev=52">r52</a> (project.id is 6)
# #52 -> Link to issue #52 text = text.gsub(%r{([\s\(,-^])(#|r)(\d+)(?=[[:punct:]]|\s|<|$)}) do |m|
# Changesets: leading, otype, oid = $1, $2, $3
# r52 -> Link to revision 52
# commit:a85130f -> Link to scmid starting with a85130f
# Documents:
# document#17 -> Link to document with id 17
# document:Greetings -> Link to the document with title "Greetings"
# document:"Some document" -> Link to the document with title "Some document"
# Versions:
# version#3 -> Link to version with id 3
# version:1.0.0 -> Link to version named "1.0.0"
# version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
# Attachments:
# attachment:file.zip -> Link to the attachment of the current object named file.zip
# Source files:
# source:some/file -> Link to the file located at /some/file in the project's repository
# source:some/file@52 -> Link to the file's revision 52
# source:some/file#L120 -> Link to line 120 of the file
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
# export:some/file -> Force the download of the file
text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
link = nil link = nil
if esc.nil? if otype == 'r'
if prefix.nil? && sep == 'r' if project && (changeset = project.changesets.find_by_revision(oid))
if project && (changeset = project.changesets.find_by_revision(oid)) link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset',
link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid}, :title => truncate(changeset.comments, 100))
:class => 'changeset', end
:title => truncate_single_line(changeset.comments, 100)) else
end if issue = Issue.find_by_id(oid.to_i, :include => [:project, :status], :conditions => Project.visible_by(User.current))
elsif sep == '#' link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue',
oid = oid.to_i :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
case prefix link = content_tag('del', link) if issue.closed?
when nil
if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
:class => (issue.closed? ? 'issue closed' : 'issue'),
:title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
link = content_tag('del', link) if issue.closed?
end
when 'document'
if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
:class => 'document'
end
when 'version'
if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
:class => 'version'
end
end
elsif sep == ':'
# removes the double quotes if any
name = oid.gsub(%r{^"(.*)"$}, "\\1")
case prefix
when 'document'
if project && document = project.documents.find_by_title(name)
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
:class => 'document'
end
when 'version'
if project && version = project.versions.find_by_name(name)
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
:class => 'version'
end
when 'commit'
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
:class => 'changeset',
:title => truncate_single_line(changeset.comments, 100)
end
when 'source', 'export'
if project && project.repository
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
path, rev, anchor = $1, $3, $5
link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, :path => path,
:rev => rev,
:anchor => anchor,
:format => (prefix == 'export' ? 'raw' : nil)},
:class => (prefix == 'export' ? 'source download' : 'source')
end
when 'attachment'
if attachments && attachment = attachments.detect {|a| a.filename == name }
link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
:class => 'attachment'
end
end
end end
end end
leading + (link || "#{prefix}#{sep}#{oid}") leading + (link || "#{otype}#{oid}")
end end
text text
@@ -430,14 +309,10 @@ module ApplicationHelper
def labelled_tabular_form_for(name, object, options, &proc) def labelled_tabular_form_for(name, object, options, &proc)
options[:html] ||= {} options[:html] ||= {}
options[:html][:class] = 'tabular' unless options[:html].has_key?(:class) options[:html].store :class, "tabular"
form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc) form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
end end
def back_url_hidden_field_tag
hidden_field_tag 'back_url', (params[:back_url] || request.env['HTTP_REFERER'])
end
def check_all_links(form_name) def check_all_links(form_name)
link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") + link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
" | " + " | " +
@@ -476,33 +351,13 @@ module ApplicationHelper
end end
def calendar_for(field_id) def calendar_for(field_id)
include_calendar_headers_tags
image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
end end
def include_calendar_headers_tags
unless @calendar_headers_tags_included
@calendar_headers_tags_included = true
content_for :header_tags do
javascript_include_tag('calendar/calendar') +
javascript_include_tag("calendar/lang/calendar-#{current_language}.js") +
javascript_include_tag('calendar/calendar-setup') +
stylesheet_link_tag('calendar')
end
end
end
def wikitoolbar_for(field_id) def wikitoolbar_for(field_id)
return '' unless Setting.text_formatting == 'textile' return '' unless Setting.text_formatting == 'textile'
javascript_include_tag('jstoolbar') + javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();")
help_link = l(:setting_text_formatting) + ': ' +
link_to(l(:label_help), compute_public_path('wiki_syntax', 'help', 'html'),
:onclick => "window.open(\"#{ compute_public_path('wiki_syntax', 'help', 'html') }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")
javascript_include_tag('jstoolbar/jstoolbar') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") +
javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.setHelpLink('#{help_link}'); toolbar.draw();")
end end
def content_for(name, content = nil, &block) def content_for(name, content = nil, &block)
@@ -515,3 +370,38 @@ module ApplicationHelper
(@has_content && @has_content[name]) || false (@has_content && @has_content[name]) || false
end end
end end
class TabularFormBuilder < ActionView::Helpers::FormBuilder
include GLoc
def initialize(object_name, object, template, options, proc)
set_language_if_valid options.delete(:lang)
@object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
end
(field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector|
src = <<-END_SRC
def #{selector}(field, options = {})
return super if options.delete :no_label
label_text = l(options[:label]) if options[:label]
label_text ||= l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym)
label_text << @template.content_tag("span", " *", :class => "required") if options.delete(:required)
label = @template.content_tag("label", label_text,
:class => (@object && @object.errors[field] ? "error" : nil),
:for => (@object_name.to_s + "_" + field.to_s))
label + super
end
END_SRC
class_eval src, __FILE__, __LINE__
end
def select(field, choices, options = {}, html_options = {})
label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
label = @template.content_tag("label", label_text,
:class => (@object && @object.errors[field] ? "error" : nil),
:for => (@object_name.to_s + "_" + field.to_s))
label + super
end
end
+2 -9
View File
@@ -17,13 +17,6 @@
module CustomFieldsHelper module CustomFieldsHelper
def custom_fields_tabs
tabs = [{:name => 'IssueCustomField', :label => :label_issue_plural},
{:name => 'ProjectCustomField', :label => :label_project_plural},
{:name => 'UserCustomField', :label => :label_user_plural}
]
end
# Return custom field html tag corresponding to its format # Return custom field html tag corresponding to its format
def custom_field_tag(custom_value) def custom_field_tag(custom_value)
custom_field = custom_value.custom_field custom_field = custom_value.custom_field
@@ -35,7 +28,7 @@ module CustomFieldsHelper
text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) + text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) +
calendar_for(field_id) calendar_for(field_id)
when "text" when "text"
text_area 'custom_value', 'value', :name => field_name, :id => field_id, :rows => 3, :style => 'width:99%' text_area 'custom_value', 'value', :name => field_name, :id => field_id, :cols => 60, :rows => 3
when "bool" when "bool"
check_box 'custom_value', 'value', :name => field_name, :id => field_id check_box 'custom_value', 'value', :name => field_name, :id => field_id
when "list" when "list"
@@ -69,7 +62,7 @@ module CustomFieldsHelper
return "" unless value && !value.empty? return "" unless value && !value.empty?
case field_format case field_format
when "date" when "date"
begin; format_date(value.to_date); rescue; value end begin; l_date(value.to_date); rescue; value end
when "bool" when "bool"
l_YesNo(value == "1") l_YesNo(value == "1")
else else
+3 -8
View File
@@ -27,18 +27,13 @@ module IfpdfHelper
def initialize(lang) def initialize(lang)
super() super()
set_language_if_valid lang set_language_if_valid lang
case current_language.to_s case current_language
when 'ja' when :ja
extend(PDF_Japanese) extend(PDF_Japanese)
AddSJISFont() AddSJISFont()
@font_for_content = 'SJIS' @font_for_content = 'SJIS'
@font_for_footer = 'SJIS' @font_for_footer = 'SJIS'
when 'zh' when :zh
extend(PDF_Chinese)
AddGBFont()
@font_for_content = 'GB'
@font_for_footer = 'GB'
when 'zh-tw'
extend(PDF_Chinese) extend(PDF_Chinese)
AddBig5Font() AddBig5Font()
@font_for_content = 'Big5' @font_for_content = 'Big5'
-18
View File
@@ -32,19 +32,6 @@ module IssuesHelper
"<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" + "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
"<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}" "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
end end
def sidebar_queries
unless @sidebar_queries
# User can see public queries and his own queries
visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)])
# Project specific queries and global queries
visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
@sidebar_queries = Query.find(:all,
:order => "name ASC",
:conditions => visible.conditions)
end
@sidebar_queries
end
def show_detail(detail, no_html=false) def show_detail(detail, no_html=false)
case detail.property case detail.property
@@ -136,7 +123,6 @@ module IssuesHelper
l(:field_start_date), l(:field_start_date),
l(:field_due_date), l(:field_due_date),
l(:field_done_ratio), l(:field_done_ratio),
l(:field_estimated_hours),
l(:field_created_on), l(:field_created_on),
l(:field_updated_on) l(:field_updated_on)
] ]
@@ -144,8 +130,6 @@ module IssuesHelper
# otherwise export custom fields marked as "For all projects" # otherwise export custom fields marked as "For all projects"
custom_fields = project.nil? ? IssueCustomField.for_all : project.all_custom_fields custom_fields = project.nil? ? IssueCustomField.for_all : project.all_custom_fields
custom_fields.each {|f| headers << f.name} custom_fields.each {|f| headers << f.name}
# Description in the last column
headers << l(:field_description)
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
# csv lines # csv lines
issues.each do |issue| issues.each do |issue|
@@ -162,12 +146,10 @@ module IssuesHelper
format_date(issue.start_date), format_date(issue.start_date),
format_date(issue.due_date), format_date(issue.due_date),
issue.done_ratio, issue.done_ratio,
issue.estimated_hours,
format_time(issue.created_on), format_time(issue.created_on),
format_time(issue.updated_on) format_time(issue.updated_on)
] ]
custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) } custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
fields << issue.description
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
end end
end end
-37
View File
@@ -1,37 +0,0 @@
# redMine - project management software
# Copyright (C) 2006-2008 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module JournalsHelper
def render_notes(journal, options={})
content = ''
editable = journal.editable_by?(User.current)
if editable && !journal.notes.blank?
links = []
links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
{ :controller => 'journals', :action => 'edit', :id => journal },
:title => l(:button_edit))
content << content_tag('div', links.join(' '), :class => 'contextual')
end
content << textilizable(journal, :notes)
content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => (editable ? 'wiki editable' : 'wiki'))
end
def link_to_in_place_notes_editor(text, field_id, url, options={})
onclick = "new Ajax.Request('#{url_for(url)}', {asynchronous:true, evalScripts:true, method:'get'}); return false;"
link_to text, '#', options.merge(:onclick => onclick)
end
end
+14 -13
View File
@@ -18,19 +18,12 @@
module ProjectsHelper module ProjectsHelper
def link_to_version(version, options = {}) def link_to_version(version, options = {})
return '' unless version && version.is_a?(Version) return '' unless version && version.is_a?(Version)
link_to h(version.name), { :controller => 'versions', :action => 'show', :id => version }, options link_to version.name, {:controller => 'projects',
end :action => 'roadmap',
:id => version.project_id,
def format_activity_title(text) :completed => (version.completed? ? 1 : nil),
h(truncate_single_line(text, 100)) :anchor => version.name
end }, options
def format_activity_day(date)
date == Date.today ? l(:label_today).titleize : format_date(date)
end
def format_activity_description(text)
h(truncate(text, 250))
end end
def project_settings_tabs def project_settings_tabs
@@ -195,4 +188,12 @@ module ProjectsHelper
gc.draw(imgl) gc.draw(imgl)
imgl imgl
end if Object.const_defined?(:Magick) end if Object.const_defined?(:Magick)
def new_issue_selector
trackers = @project.trackers
# can't use form tag inside helper
content_tag('form',
select_tag('tracker_id', '<option></option>' + options_from_collection_for_select(trackers, 'id', 'name'), :onchange => "if (this.value != '') {this.form.submit()}"),
:action => url_for(:controller => 'projects', :action => 'add_issue', :id => @project), :method => 'get')
end
end end
+1 -3
View File
@@ -22,9 +22,7 @@ module QueriesHelper
end end
def column_header(column) def column_header(column)
column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, column.sortable ? sort_header_tag(column.sortable, :caption => column.caption) : content_tag('th', column.caption)
:default_order => column.default_order) :
content_tag('th', column.caption)
end end
def column_content(column, issue) def column_content(column, issue)
+2 -13
View File
@@ -25,10 +25,6 @@ module RepositoriesHelper
type ? CodeRay.scan(content, type).html : h(content) type ? CodeRay.scan(content, type).html : h(content)
end end
def format_revision(txt)
txt.to_s[0,8]
end
def to_utf8(str) def to_utf8(str)
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
@@ -58,11 +54,8 @@ module RepositoriesHelper
end end
def with_leading_slash(path) def with_leading_slash(path)
path.to_s.starts_with?('/') ? path : "/#{path}" path ||= ''
end path.starts_with?("/") ? "/#{path}" : path
def without_leading_slash(path)
path.gsub(%r{^/+}, '')
end end
def subversion_field_tags(form, repository) def subversion_field_tags(form, repository)
@@ -83,10 +76,6 @@ module RepositoriesHelper
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
end end
def git_field_tags(form, repository)
content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
end
def cvs_field_tags(form, repository) def cvs_field_tags(form, repository)
content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) + content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?)) content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
-8
View File
@@ -16,12 +16,4 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module SettingsHelper module SettingsHelper
def administration_settings_tabs
tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
{:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
{:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
{:name => 'notifications', :partial => 'settings/notifications', :label => l(:field_mail_notification)},
{:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
]
end
end end
+11 -22
View File
@@ -67,31 +67,23 @@ module SortHelper
# Updates the sort state. Call this in the controller prior to calling # Updates the sort state. Call this in the controller prior to calling
# sort_clause. # sort_clause.
# sort_keys can be either an array or a hash of allowed keys #
def sort_update(sort_keys) def sort_update()
sort_key = params[:sort_key] if params[:sort_key]
sort_key = nil unless (sort_keys.is_a?(Array) ? sort_keys.include?(sort_key) : sort_keys[sort_key]) sort = {:key => params[:sort_key], :order => params[:sort_order]}
sort_order = (params[:sort_order] == 'desc' ? 'DESC' : 'ASC')
if sort_key
sort = {:key => sort_key, :order => sort_order}
elsif session[@sort_name] elsif session[@sort_name]
sort = session[@sort_name] # Previous sort. sort = session[@sort_name] # Previous sort.
else else
sort = @sort_default sort = @sort_default
end end
session[@sort_name] = sort session[@sort_name] = sort
sort_column = (sort_keys.is_a?(Hash) ? sort_keys[sort[:key]] : sort[:key])
@sort_clause = (sort_column.blank? ? nil : "#{sort_column} #{sort[:order]}")
end end
# Returns an SQL sort clause corresponding to the current sort state. # Returns an SQL sort clause corresponding to the current sort state.
# Use this to sort the controller's table items collection. # Use this to sort the controller's table items collection.
# #
def sort_clause() def sort_clause()
@sort_clause session[@sort_name][:key] + ' ' + session[@sort_name][:order]
end end
# Returns a link which sorts by the named column. # Returns a link which sorts by the named column.
@@ -100,7 +92,7 @@ module SortHelper
# - The optional caption explicitly specifies the displayed link text. # - The optional caption explicitly specifies the displayed link text.
# - A sort icon image is positioned to the right of the sort link. # - A sort icon image is positioned to the right of the sort link.
# #
def sort_link(column, caption, default_order) def sort_link(column, caption=nil)
key, order = session[@sort_name][:key], session[@sort_name][:order] key, order = session[@sort_name][:key], session[@sort_name][:order]
if key == column if key == column
if order.downcase == 'asc' if order.downcase == 'asc'
@@ -112,17 +104,15 @@ module SortHelper
end end
else else
icon = nil icon = nil
order = default_order order = 'desc' # changed for desc order by default
end end
caption = titleize(Inflector::humanize(column)) unless caption caption = titleize(Inflector::humanize(column)) unless caption
sort_options = { :sort_key => column, :sort_order => order } url = {:sort_key => column, :sort_order => order, :issue_id => params[:issue_id], :project_id => params[:project_id]}
# don't reuse params if filters are present
url_options = params.has_key?(:set_filter) ? sort_options : params.merge(sort_options)
link_to_remote(caption, link_to_remote(caption,
{:update => "content", :url => url_options}, {:update => "content", :url => url},
{:href => url_for(url_options)}) + {:href => url_for(url)}) +
(icon ? nbsp(2) + image_tag(icon) : '') (icon ? nbsp(2) + image_tag(icon) : '')
end end
@@ -148,9 +138,8 @@ module SortHelper
# #
def sort_header_tag(column, options = {}) def sort_header_tag(column, options = {})
caption = options.delete(:caption) || titleize(Inflector::humanize(column)) caption = options.delete(:caption) || titleize(Inflector::humanize(column))
default_order = options.delete(:default_order) || 'asc'
options[:title]= l(:label_sort_by, "\"#{caption}\"") unless options[:title] options[:title]= l(:label_sort_by, "\"#{caption}\"") unless options[:title]
content_tag('th', sort_link(column, caption, default_order), options) content_tag('th', sort_link(column, caption), options)
end end
private private
+1 -106
View File
@@ -17,7 +17,7 @@
module TimelogHelper module TimelogHelper
def select_hours(data, criteria, value) def select_hours(data, criteria, value)
data.select {|row| row[criteria] == value} data.select {|row| row[criteria] == value.to_s}
end end
def sum_hours(data) def sum_hours(data)
@@ -27,109 +27,4 @@ module TimelogHelper
end end
sum sum
end end
def options_for_period_select(value)
options_for_select([[l(:label_all_time), 'all'],
[l(:label_today), 'today'],
[l(:label_yesterday), 'yesterday'],
[l(:label_this_week), 'current_week'],
[l(:label_last_week), 'last_week'],
[l(:label_last_n_days, 7), '7_days'],
[l(:label_this_month), 'current_month'],
[l(:label_last_month), 'last_month'],
[l(:label_last_n_days, 30), '30_days'],
[l(:label_this_year), 'current_year']],
value)
end
def entries_to_csv(entries)
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
export = StringIO.new
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
# csv header fields
headers = [l(:field_spent_on),
l(:field_user),
l(:field_activity),
l(:field_project),
l(:field_issue),
l(:field_tracker),
l(:field_subject),
l(:field_hours),
l(:field_comments)
]
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
# csv lines
entries.each do |entry|
fields = [l_date(entry.spent_on),
entry.user,
entry.activity,
entry.project,
(entry.issue ? entry.issue.id : nil),
(entry.issue ? entry.issue.tracker : nil),
(entry.issue ? entry.issue.subject : nil),
entry.hours,
entry.comments
]
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
end
end
export.rewind
export
end
def format_criteria_value(criteria, value)
value.blank? ? l(:label_none) : ((k = @available_criterias[criteria][:klass]) ? k.find_by_id(value.to_i) : format_value(value, @available_criterias[criteria][:format]))
end
def report_to_csv(criterias, periods, hours)
export = StringIO.new
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
# Column headers
headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
headers += periods
headers << l(:label_total)
csv << headers.collect {|c| to_utf8(c) }
# Content
report_criteria_to_csv(csv, criterias, periods, hours)
# Total row
row = [ l(:label_total) ] + [''] * (criterias.size - 1)
total = 0
periods.each do |period|
sum = sum_hours(select_hours(hours, @columns, period.to_s))
total += sum
row << (sum > 0 ? "%.2f" % sum : '')
end
row << "%.2f" %total
csv << row
end
export.rewind
export
end
def report_criteria_to_csv(csv, criterias, periods, hours, level=0)
hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value|
hours_for_value = select_hours(hours, criterias[level], value)
next if hours_for_value.empty?
row = [''] * level
row << to_utf8(format_criteria_value(criterias[level], value))
row += [''] * (criterias.length - level - 1)
total = 0
periods.each do |period|
sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s))
total += sum
row << (sum > 0 ? "%.2f" % sum : '')
end
row << "%.2f" %total
csv << row
if criterias.length > level + 1
report_criteria_to_csv(csv, criterias, periods, hours_for_value, level + 1)
end
end
end
def to_utf8(s)
@ic ||= Iconv.new(l(:general_csv_encoding), 'UTF-8')
begin; @ic.iconv(s.to_s); rescue; s.to_s; end
end
end end
+1 -13
View File
@@ -17,21 +17,9 @@
module UsersHelper module UsersHelper
def status_options_for_select(selected) def status_options_for_select(selected)
options_for_select([[l(:label_all), ''], options_for_select([[l(:label_all), "*"],
[l(:status_active), 1], [l(:status_active), 1],
[l(:status_registered), 2], [l(:status_registered), 2],
[l(:status_locked), 3]], selected) [l(:status_locked), 3]], selected)
end end
def change_status_link(user)
url = {:action => 'edit', :id => user, :page => params[:page], :status => params[:status]}
if user.locked?
link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
elsif user.registered?
link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
elsif user != User.current
link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock'
end
end
end end
+50 -61
View File
@@ -26,6 +26,7 @@ class Attachment < ActiveRecord::Base
validates_length_of :disk_filename, :maximum => 255 validates_length_of :disk_filename, :maximum => 255
acts_as_event :title => :filename, acts_as_event :title => :filename,
:description => :filename,
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id}} :url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id}}
cattr_accessor :storage_path cattr_accessor :storage_path
@@ -35,48 +36,48 @@ class Attachment < ActiveRecord::Base
errors.add_to_base :too_long if self.filesize > Setting.attachment_max_size.to_i.kilobytes errors.add_to_base :too_long if self.filesize > Setting.attachment_max_size.to_i.kilobytes
end end
def file=(incoming_file) def file=(incomming_file)
unless incoming_file.nil? unless incomming_file.nil?
@temp_file = incoming_file @temp_file = incomming_file
if @temp_file.size > 0 if @temp_file.size > 0
self.filename = sanitize_filename(@temp_file.original_filename) self.filename = sanitize_filename(@temp_file.original_filename)
self.disk_filename = Attachment.disk_filename(filename) self.disk_filename = DateTime.now.strftime("%y%m%d%H%M%S") + "_" + self.filename
self.content_type = @temp_file.content_type.to_s.chomp self.content_type = @temp_file.content_type.chomp
self.filesize = @temp_file.size self.filesize = @temp_file.size
end end
end end
end end
def file def file
nil nil
end end
# Copy temp file to its final location # Copy temp file to its final location
def before_save def before_save
if @temp_file && (@temp_file.size > 0) if @temp_file && (@temp_file.size > 0)
logger.debug("saving '#{self.diskfile}'") logger.debug("saving '#{self.diskfile}'")
File.open(diskfile, "wb") do |f| File.open(diskfile, "wb") do |f|
f.write(@temp_file.read) f.write(@temp_file.read)
end end
self.digest = Digest::MD5.hexdigest(File.read(diskfile)) self.digest = Digest::MD5.hexdigest(File.read(diskfile))
end end
# Don't save the content type if it's longer than the authorized length # Don't save the content type if it's longer than the authorized length
if self.content_type && self.content_type.length > 255 if self.content_type && self.content_type.length > 255
self.content_type = nil self.content_type = nil
end end
end end
# Deletes file on the disk # Deletes file on the disk
def after_destroy def after_destroy
if self.filename? if self.filename?
File.delete(diskfile) if File.exist?(diskfile) File.delete(diskfile) if File.exist?(diskfile)
end end
end end
# Returns file's location on disk # Returns file's location on disk
def diskfile def diskfile
"#{@@storage_path}/#{self.disk_filename}" "#{@@storage_path}/#{self.disk_filename}"
end end
def increment_download def increment_download
increment!(:downloads) increment!(:downloads)
@@ -87,30 +88,18 @@ class Attachment < ActiveRecord::Base
end end
def image? def image?
self.filename =~ /\.(jpe?g|gif|png)$/i self.filename =~ /\.(jpeg|jpg|gif|png)$/i
end end
private private
def sanitize_filename(value) def sanitize_filename(value)
# get only the filename, not the whole path # get only the filename, not the whole path
just_filename = value.gsub(/^.*(\\|\/)/, '') just_filename = value.gsub(/^.*(\\|\/)/, '')
# NOTE: File.basename doesn't work right with Windows paths on Unix # NOTE: File.basename doesn't work right with Windows paths on Unix
# INCORRECT: just_filename = File.basename(value.gsub('\\\\', '/')) # INCORRECT: just_filename = File.basename(value.gsub('\\\\', '/'))
# Finally, replace all non alphanumeric, hyphens or periods with underscore # Finally, replace all non alphanumeric, underscore or periods with underscore
@filename = just_filename.gsub(/[^\w\.\-]/,'_') @filename = just_filename.gsub(/[^\w\.\-]/,'_')
end
# Returns an ASCII or hashed filename
def self.disk_filename(filename)
df = DateTime.now.strftime("%y%m%d%H%M%S") + "_"
if filename =~ %r{^[a-zA-Z0-9_\.\-]*$}
df << filename
else
df << Digest::MD5.hexdigest(filename)
# keep the extension if any
df << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
end
df
end end
end end
+5 -6
View File
@@ -70,12 +70,11 @@ class AuthSourceLdap < AuthSource
private private
def initialize_ldap_con(ldap_user, ldap_password) def initialize_ldap_con(ldap_user, ldap_password)
options = { :host => self.host, Net::LDAP.new( {:host => self.host,
:port => self.port, :port => self.port,
:encryption => (self.tls ? :simple_tls : nil) :auth => { :method => :simple, :username => ldap_user, :password => ldap_password },
} :encryption => (self.tls ? :simple_tls : nil)}
options.merge!(:auth => { :method => :simple, :username => ldap_user, :password => ldap_password }) unless ldap_user.blank? && ldap_password.blank? )
Net::LDAP.new options
end end
def self.get_attr(entry, attr_name) def self.get_attr(entry, attr_name)
-4
View File
@@ -19,8 +19,4 @@ class Change < ActiveRecord::Base
belongs_to :changeset belongs_to :changeset
validates_presence_of :changeset_id, :action, :path validates_presence_of :changeset_id, :action, :path
def relative_path
changeset.repository.relative_path(path)
end
end end
+5 -32
View File
@@ -32,13 +32,10 @@ class Changeset < ActiveRecord::Base
:date_column => 'committed_on' :date_column => 'committed_on'
validates_presence_of :repository_id, :revision, :committed_on, :commit_date validates_presence_of :repository_id, :revision, :committed_on, :commit_date
validates_numericality_of :revision, :only_integer => true
validates_uniqueness_of :revision, :scope => :repository_id validates_uniqueness_of :revision, :scope => :repository_id
validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
def revision=(r)
write_attribute :revision, (r.nil? ? nil : r.to_s)
end
def comments=(comment) def comments=(comment)
write_attribute(:comments, comment.strip) write_attribute(:comments, comment.strip)
end end
@@ -48,14 +45,9 @@ class Changeset < ActiveRecord::Base
super super
end end
def project
repository.project
end
def after_create def after_create
scan_comment_for_issue_ids scan_comment_for_issue_ids
end end
require 'pp'
def scan_comment_for_issue_ids def scan_comment_for_issue_ids
return if comments.blank? return if comments.blank?
@@ -75,7 +67,7 @@ class Changeset < ActiveRecord::Base
if ref_keywords.delete('*') if ref_keywords.delete('*')
# find any issue ID in the comments # find any issue ID in the comments
target_issue_ids = [] target_issue_ids = []
comments.scan(%r{([\s\(,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] } comments.scan(%r{([\s\(,-^])#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] }
referenced_issues += repository.project.issues.find_all_by_id(target_issue_ids) referenced_issues += repository.project.issues.find_all_by_id(target_issue_ids)
end end
@@ -87,20 +79,11 @@ class Changeset < ActiveRecord::Base
# update status of issues # update status of issues
logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug? logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug?
target_issues.each do |issue| target_issues.each do |issue|
# the issue may have been updated by the closure of another one (eg. duplicate) # don't change the status is the issue is already closed
issue.reload
# don't change the status is the issue is closed
next if issue.status.is_closed? next if issue.status.is_closed?
user = committer_user || User.anonymous
csettext = "r#{self.revision}"
if self.scmid && (! (csettext =~ /^r[0-9]+$/))
csettext = "commit:\"#{self.scmid}\""
end
journal = issue.init_journal(user, l(:text_status_changed_by_changeset, csettext))
issue.status = fix_status issue.status = fix_status
issue.done_ratio = done_ratio if done_ratio issue.done_ratio = done_ratio if done_ratio
issue.save issue.save
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
end end
end end
referenced_issues += target_issues referenced_issues += target_issues
@@ -109,23 +92,13 @@ class Changeset < ActiveRecord::Base
self.issues = referenced_issues.uniq self.issues = referenced_issues.uniq
end end
# Returns the Redmine User corresponding to the committer
def committer_user
if committer && committer.strip =~ /^([^<]+)(<(.*)>)?$/
username, email = $1.strip, $3
u = User.find_by_login(username)
u ||= User.find_by_mail(email) unless email.blank?
u
end
end
# Returns the previous changeset # Returns the previous changeset
def previous def previous
@previous ||= Changeset.find(:first, :conditions => ['id < ? AND repository_id = ?', self.id, self.repository_id], :order => 'id DESC') @previous ||= Changeset.find(:first, :conditions => ['revision < ? AND repository_id = ?', self.revision, self.repository_id], :order => 'revision DESC')
end end
# Returns the next changeset # Returns the next changeset
def next def next
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC') @next ||= Changeset.find(:first, :conditions => ['revision > ? AND repository_id = ?', self.revision, self.repository_id], :order => 'revision ASC')
end end
end end
-5
View File
@@ -53,11 +53,6 @@ class CustomField < ActiveRecord::Base
errors.add(:possible_values, :activerecord_error_blank) if self.possible_values.nil? || self.possible_values.empty? errors.add(:possible_values, :activerecord_error_blank) if self.possible_values.nil? || self.possible_values.empty?
errors.add(:possible_values, :activerecord_error_invalid) unless self.possible_values.is_a? Array errors.add(:possible_values, :activerecord_error_invalid) unless self.possible_values.is_a? Array
end end
# validate default value
v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil)
v.custom_field.is_required = false
errors.add(:default_value, :activerecord_error_invalid) unless v.valid?
end end
def <=>(field) def <=>(field)
+13 -24
View File
@@ -19,32 +19,21 @@ class CustomValue < ActiveRecord::Base
belongs_to :custom_field belongs_to :custom_field
belongs_to :customized, :polymorphic => true belongs_to :customized, :polymorphic => true
def after_initialize
if custom_field && new_record? && (customized_type.blank? || (customized && customized.new_record?))
self.value ||= custom_field.default_value
end
end
protected protected
def validate def validate
if value.blank? errors.add(:value, :activerecord_error_blank) and return if custom_field.is_required? and value.blank?
errors.add(:value, :activerecord_error_blank) if custom_field.is_required? and value.blank? errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
else errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length and value.length > 0
errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp) errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length case custom_field.field_format
errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length when 'int'
errors.add(:value, :activerecord_error_not_a_number) unless value.blank? || value =~ /^[+-]?\d+$/
# Format specific validations when 'float'
case custom_field.field_format begin; !value.blank? && Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end
when 'int' when 'date'
errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[+-]?\d+$/ errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ or value.blank?
when 'float' when 'list'
begin; Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include?(value) or value.blank?
when 'date'
errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/
when 'list'
errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include?(value)
end
end end
end end
end end
+1
View File
@@ -23,6 +23,7 @@ class Enumeration < ActiveRecord::Base
validates_presence_of :opt, :name validates_presence_of :opt, :name
validates_uniqueness_of :name, :scope => [:opt] validates_uniqueness_of :name, :scope => [:opt]
validates_length_of :name, :maximum => 30 validates_length_of :name, :maximum => 30
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
OPTIONS = { OPTIONS = {
"IPRI" => :enumeration_issue_priorities, "IPRI" => :enumeration_issue_priorities,
+7 -36
View File
@@ -27,7 +27,7 @@ class Issue < ActiveRecord::Base
has_many :journals, :as => :journalized, :dependent => :destroy has_many :journals, :as => :journalized, :dependent => :destroy
has_many :attachments, :as => :container, :dependent => :destroy has_many :attachments, :as => :container, :dependent => :destroy
has_many :time_entries, :dependent => :delete_all has_many :time_entries, :dependent => :nullify
has_many :custom_values, :dependent => :delete_all, :as => :customized has_many :custom_values, :dependent => :delete_all, :as => :customized
has_many :custom_fields, :through => :custom_values has_many :custom_fields, :through => :custom_values
has_and_belongs_to_many :changesets, :order => "revision ASC" has_and_belongs_to_many :changesets, :order => "revision ASC"
@@ -66,10 +66,8 @@ class Issue < ActiveRecord::Base
transaction do transaction do
if new_project && project_id != new_project.id if new_project && project_id != new_project.id
# delete issue relations # delete issue relations
unless Setting.cross_project_issue_relations? self.relations_from.clear
self.relations_from.clear self.relations_to.clear
self.relations_to.clear
end
# issue is moved to another project # issue is moved to another project
self.category = nil self.category = nil
self.fixed_version = nil self.fixed_version = nil
@@ -93,11 +91,7 @@ class Issue < ActiveRecord::Base
self.priority = nil self.priority = nil
write_attribute(:priority_id, pid) write_attribute(:priority_id, pid)
end end
def estimated_hours=(h)
write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
end
def validate def validate
if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty? if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
errors.add :due_date, :activerecord_error_not_a_date errors.add :due_date, :activerecord_error_not_a_date
@@ -148,17 +142,12 @@ class Issue < ActiveRecord::Base
end end
def after_save def after_save
# Reload is needed in order to get the right status
reload
# Update start/due dates of following issues # Update start/due dates of following issues
relations_from.each(&:set_issue_to_dates) relations_from.each(&:set_issue_to_dates)
# Close duplicates if the issue was closed # Close duplicates if the issue was closed
if @issue_before_change && !@issue_before_change.closed? && self.closed? if @issue_before_change && !@issue_before_change.closed? && self.closed?
duplicates.each do |duplicate| duplicates.each do |duplicate|
# Reload is need in case the duplicate was updated by a previous duplicate
duplicate.reload
# Don't re-close it if it's already closed # Don't re-close it if it's already closed
next if duplicate.closed? next if duplicate.closed?
# Same user and notes # Same user and notes
@@ -176,7 +165,6 @@ class Issue < ActiveRecord::Base
def init_journal(user, notes = "") def init_journal(user, notes = "")
@current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
@issue_before_change = self.clone @issue_before_change = self.clone
@issue_before_change.status = self.status
@custom_values_before_change = {} @custom_values_before_change = {}
self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
@current_journal @current_journal
@@ -192,19 +180,12 @@ class Issue < ActiveRecord::Base
project.assignable_users project.assignable_users
end end
# Returns an array of status that user is able to apply
def new_statuses_allowed_to(user)
statuses = status.find_new_statuses_allowed_to(user.role_for_project(project), tracker)
statuses << status unless statuses.empty?
statuses.uniq.sort
end
# Returns the mail adresses of users that should be notified for the issue # Returns the mail adresses of users that should be notified for the issue
def recipients def recipients
recipients = project.recipients recipients = project.recipients
# Author and assignee are always notified unless they have been locked # Author and assignee are always notified
recipients << author.mail if author && author.active? recipients << author.mail if author
recipients << assigned_to.mail if assigned_to && assigned_to.active? recipients << assigned_to.mail if assigned_to
recipients.compact.uniq recipients.compact.uniq
end end
@@ -237,14 +218,4 @@ class Issue < ActiveRecord::Base
def soonest_start def soonest_start
@soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
end end
def self.visible_by(usr)
with_scope(:find => { :conditions => Project.visible_by(usr) }) do
yield
end
end
def to_s
"#{tracker} ##{id}: #{subject}"
end
end end
-4
View File
@@ -56,10 +56,6 @@ class IssueStatus < ActiveRecord::Base
false false
end end
def <=>(status)
position <=> status.position
end
def to_s; name end def to_s; name end
private private
+2 -21
View File
@@ -23,18 +23,16 @@ class Journal < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :details, :class_name => "JournalDetail", :dependent => :delete_all has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
attr_accessor :indice
acts_as_searchable :columns => 'notes', acts_as_searchable :columns => 'notes',
:include => :issue, :include => :issue,
:project_key => "#{Issue.table_name}.project_id", :project_key => "#{Issue.table_name}.project_id",
:date_column => "#{Issue.table_name}.created_on" :date_column => "#{Issue.table_name}.created_on"
acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" }, acts_as_event :title => Proc.new {|o| "#{o.issue.tracker.name} ##{o.issue.id}: #{o.issue.subject}" + ((s = o.new_status) ? " (#{s})" : '') },
:description => :notes, :description => :notes,
:author => :user, :author => :user,
:type => Proc.new {|o| (s = o.new_status) && s.is_closed? ? 'issue-closed' : 'issue-edit' }, :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id}}
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
def save def save
# Do not save an empty journal # Do not save an empty journal
@@ -46,21 +44,4 @@ class Journal < ActiveRecord::Base
c = details.detect {|detail| detail.prop_key == 'status_id'} c = details.detect {|detail| detail.prop_key == 'status_id'}
(c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
end end
def new_value_for(prop)
c = details.detect {|detail| detail.prop_key == prop}
c ? c.value : nil
end
def editable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
end
def project
journalized.respond_to?(:project) ? journalized.project : nil
end
def attachments
journalized.respond_to?(:attachments) ? journalized.attachments : nil
end
end end
+10 -44
View File
@@ -16,43 +16,31 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Mailer < ActionMailer::Base class Mailer < ActionMailer::Base
helper :application helper ApplicationHelper
helper :issues helper IssuesHelper
helper :custom_fields helper CustomFieldsHelper
include ActionController::UrlWriter include ActionController::UrlWriter
def issue_add(issue) def issue_add(issue)
redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue.id,
'Issue-Author' => issue.author.login
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
recipients issue.recipients recipients issue.recipients
subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
body :issue => issue, body :issue => issue,
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
end end
def issue_edit(journal) def issue_edit(journal)
issue = journal.journalized issue = journal.journalized
redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue.id,
'Issue-Author' => issue.author.login
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
recipients issue.recipients recipients issue.recipients
# Watchers in cc # Watchers in cc
cc(issue.watcher_recipients - @recipients) cc(issue.watcher_recipients - @recipients)
s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
s << issue.subject
subject s
body :issue => issue, body :issue => issue,
:journal => journal, :journal => journal,
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
end end
def document_added(document) def document_added(document)
redmine_headers 'Project' => document.project.identifier
recipients document.project.recipients recipients document.project.recipients
subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
body :document => document, body :document => document,
@@ -71,7 +59,6 @@ class Mailer < ActionMailer::Base
added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
added_to = "#{l(:label_document)}: #{container.title}" added_to = "#{l(:label_document)}: #{container.title}"
end end
redmine_headers 'Project' => container.project.identifier
recipients container.project.recipients recipients container.project.recipients
subject "[#{container.project.name}] #{l(:label_attachment_new)}" subject "[#{container.project.name}] #{l(:label_attachment_new)}"
body :attachments => attachments, body :attachments => attachments,
@@ -80,7 +67,6 @@ class Mailer < ActionMailer::Base
end end
def news_added(news) def news_added(news)
redmine_headers 'Project' => news.project.identifier
recipients news.project.recipients recipients news.project.recipients
subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
body :news => news, body :news => news,
@@ -88,8 +74,6 @@ class Mailer < ActionMailer::Base
end end
def message_posted(message, recipients) def message_posted(message, recipients)
redmine_headers 'Project' => message.project.identifier,
'Topic-Id' => (message.parent_id || message.id)
recipients(recipients) recipients(recipients)
subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}" subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
body :message => message, body :message => message,
@@ -99,7 +83,7 @@ class Mailer < ActionMailer::Base
def account_information(user, password) def account_information(user, password)
set_language_if_valid user.language set_language_if_valid user.language
recipients user.mail recipients user.mail
subject l(:mail_subject_register, Setting.app_title) subject l(:mail_subject_register)
body :user => user, body :user => user,
:password => password, :password => password,
:login_url => url_for(:controller => 'account', :action => 'login') :login_url => url_for(:controller => 'account', :action => 'login')
@@ -108,7 +92,7 @@ class Mailer < ActionMailer::Base
def account_activation_request(user) def account_activation_request(user)
# Send the email to all active administrators # Send the email to all active administrators
recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
subject l(:mail_subject_account_activation_request, Setting.app_title) subject l(:mail_subject_account_activation_request)
body :user => user, body :user => user,
:url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc') :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
end end
@@ -116,7 +100,7 @@ class Mailer < ActionMailer::Base
def lost_password(token) def lost_password(token)
set_language_if_valid(token.user.language) set_language_if_valid(token.user.language)
recipients token.user.mail recipients token.user.mail
subject l(:mail_subject_lost_password, Setting.app_title) subject l(:mail_subject_lost_password)
body :token => token, body :token => token,
:url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value) :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
end end
@@ -124,7 +108,7 @@ class Mailer < ActionMailer::Base
def register(token) def register(token)
set_language_if_valid(token.user.language) set_language_if_valid(token.user.language)
recipients token.user.mail recipients token.user.mail
subject l(:mail_subject_register, Setting.app_title) subject l(:mail_subject_register)
body :token => token, body :token => token,
:url => url_for(:controller => 'account', :action => 'activate', :token => token.value) :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
end end
@@ -135,16 +119,7 @@ class Mailer < ActionMailer::Base
subject 'Redmine test' subject 'Redmine test'
body :url => url_for(:controller => 'welcome') body :url => url_for(:controller => 'welcome')
end end
# Overrides default deliver! method to prevent from sending an email
# with no recipient, cc or bcc
def deliver!(mail = @mail)
return false if (recipients.nil? || recipients.empty?) &&
(cc.nil? || cc.empty?) &&
(bcc.nil? || bcc.empty?)
super
end
private private
def initialize_defaults(method_name) def initialize_defaults(method_name)
super super
@@ -152,15 +127,6 @@ class Mailer < ActionMailer::Base
from Setting.mail_from from Setting.mail_from
default_url_options[:host] = Setting.host_name default_url_options[:host] = Setting.host_name
default_url_options[:protocol] = Setting.protocol default_url_options[:protocol] = Setting.protocol
# Common headers
headers 'X-Mailer' => 'Redmine',
'X-Redmine-Host' => Setting.host_name,
'X-Redmine-Site' => Setting.app_title
end
# Appends a Redmine header field (name is prepended with 'X-Redmine-')
def redmine_headers(h)
h.each { |k,v| headers["X-Redmine-#{k}"] = v }
end end
# Overrides the create_mail method # Overrides the create_mail method
+1 -5
View File
@@ -31,12 +31,8 @@ class Member < ActiveRecord::Base
self.user.name self.user.name
end end
def <=>(member)
role == member.role ? (user <=> member.user) : (role <=> member.role)
end
def before_destroy def before_destroy
# remove category based auto assignments for this member # remove category based auto assignments for this member
IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id] project.issue_categories.update_all "assigned_to_id = NULL", ["assigned_to_id = ?", self.user.id]
end end
end end
+1 -2
View File
@@ -28,7 +28,6 @@ class Message < ActiveRecord::Base
:date_column => 'created_on' :date_column => 'created_on'
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"}, acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
:description => :content, :description => :content,
:type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
:url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id, :id => o.id}} :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id, :id => o.id}}
attr_protected :locked, :sticky attr_protected :locked, :sticky
@@ -37,7 +36,7 @@ class Message < ActiveRecord::Base
def validate_on_create def validate_on_create
# Can not reply to a locked topic # Can not reply to a locked topic
errors.add_to_base 'Topic is locked' if root.locked? && self != root errors.add_to_base 'Topic is locked' if root.locked?
end end
def after_create def after_create
+1 -3
View File
@@ -18,11 +18,9 @@
class MessageObserver < ActiveRecord::Observer class MessageObserver < ActiveRecord::Observer
def after_create(message) def after_create(message)
# send notification to the authors of the thread # send notification to the authors of the thread
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author && m.author.active?} recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
# send notification to the board watchers # send notification to the board watchers
recipients += message.board.watcher_recipients recipients += message.board.watcher_recipients
# send notification to project members who want to be notified
recipients += message.board.project.recipients
recipients = recipients.compact.uniq recipients = recipients.compact.uniq
Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?('message_posted') Mailer.deliver_message_posted(message, recipients) if !recipients.empty? && Setting.notified_events.include?('message_posted')
end end
+18 -74
View File
@@ -33,7 +33,7 @@ class Project < ActiveRecord::Base
has_many :documents, :dependent => :destroy has_many :documents, :dependent => :destroy
has_many :news, :dependent => :delete_all, :include => :author has_many :news, :dependent => :delete_all, :include => :author
has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
has_many :boards, :dependent => :destroy, :order => "position ASC" has_many :boards, :order => "position ASC"
has_one :repository, :dependent => :destroy has_one :repository, :dependent => :destroy
has_many :changesets, :through => :repository has_many :changesets, :through => :repository
has_one :wiki, :dependent => :destroy has_one :wiki, :dependent => :destroy
@@ -52,11 +52,12 @@ class Project < ActiveRecord::Base
attr_protected :status, :enabled_module_names attr_protected :status, :enabled_module_names
validates_presence_of :name, :identifier validates_presence_of :name, :description, :identifier
validates_uniqueness_of :name, :identifier validates_uniqueness_of :name, :identifier
validates_associated :custom_values, :on => :update validates_associated :custom_values, :on => :update
validates_associated :repository, :wiki validates_associated :repository, :wiki
validates_length_of :name, :maximum => 30 validates_length_of :name, :maximum => 30
validates_length_of :description, :maximum => 255
validates_length_of :homepage, :maximum => 60 validates_length_of :homepage, :maximum => 60
validates_length_of :identifier, :in => 3..20 validates_length_of :identifier, :in => 3..20
validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
@@ -73,19 +74,27 @@ class Project < ActiveRecord::Base
def issues_with_subprojects(include_subprojects=false) def issues_with_subprojects(include_subprojects=false)
conditions = nil conditions = nil
if include_subprojects if include_subprojects && !active_children.empty?
ids = [id] + child_ids ids = [id] + active_children.collect {|c| c.id}
conditions = ["#{Project.table_name}.id IN (#{ids.join(',')}) AND #{Project.visible_by}"] conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"]
end end
conditions ||= ["#{Project.table_name}.id = ?", id] conditions ||= ["#{Issue.table_name}.project_id = ?", id]
# Quick and dirty fix for Rails 2 compatibility # Quick and dirty fix for Rails 2 compatibility
Issue.send(:with_scope, :find => { :conditions => conditions }) do Issue.send(:with_scope, :find => { :conditions => conditions }) do
Version.send(:with_scope, :find => { :conditions => conditions }) do yield
yield
end
end end
end end
# Return all issues status changes for the project between the 2 given dates
def issues_status_changes(from, to)
Journal.find(:all, :include => [:issue, :details, :user],
:conditions => ["#{Journal.table_name}.journalized_type = 'Issue'" +
" AND #{Issue.table_name}.project_id = ?" +
" AND #{JournalDetail.table_name}.prop_key = 'status_id'" +
" AND #{Journal.table_name}.created_on BETWEEN ? AND ?",
id, from, to+1])
end
# returns latest created projects # returns latest created projects
# non public projects will be returned only if user is a member of those # non public projects will be returned only if user is a member of those
def self.latest(user=nil, count=5) def self.latest(user=nil, count=5)
@@ -93,7 +102,6 @@ class Project < ActiveRecord::Base
end end
def self.visible_by(user=nil) def self.visible_by(user=nil)
user ||= User.current
if user && user.admin? if user && user.admin?
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}" return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
elsif user && user.memberships.any? elsif user && user.memberships.any?
@@ -103,51 +111,6 @@ class Project < ActiveRecord::Base
end end
end end
def self.allowed_to_condition(user, permission, options={})
statements = []
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
if options[:project]
project_statement = "#{Project.table_name}.id = #{options[:project].id}"
project_statement << " OR #{Project.table_name}.parent_id = #{options[:project].id}" if options[:with_subprojects]
base_statement = "(#{project_statement}) AND (#{base_statement})"
end
if user.admin?
# no restriction
elsif user.logged?
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission)
allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id}
statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
elsif Role.anonymous.allowed_to?(permission)
# anonymous user allowed on public project
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
else
# anonymous user is not authorized
statements << "1=0"
end
statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))"
end
def project_condition(with_subprojects)
cond = "#{Project.table_name}.id = #{id}"
cond = "(#{cond} OR #{Project.table_name}.parent_id = #{id})" if with_subprojects
cond
end
def self.find(*args)
if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
project = find_by_identifier(*args)
raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil?
project
else
super
end
end
def to_param
# id is used for projects with a numeric identifier (compatibility)
@to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier)
end
def active? def active?
self.status == STATUS_ACTIVE self.status == STATUS_ACTIVE
end end
@@ -169,15 +132,6 @@ class Project < ActiveRecord::Base
children.select {|child| child.active?} children.select {|child| child.active?}
end end
# Returns an array of the trackers used by the project and its sub projects
def rolled_up_trackers
@rolled_up_trackers ||=
Tracker.find(:all, :include => :projects,
:select => "DISTINCT #{Tracker.table_name}.*",
:conditions => ["#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?", id, id],
:order => "#{Tracker.table_name}.position")
end
# Deletes all project's members # Deletes all project's members
def delete_all_members def delete_all_members
Member.delete_all(['project_id = ?', id]) Member.delete_all(['project_id = ?', id])
@@ -207,15 +161,6 @@ class Project < ActiveRecord::Base
name.downcase <=> project.name.downcase name.downcase <=> project.name.downcase
end end
def to_s
name
end
# Returns a short description of the projects (first lines)
def short_description(length = 255)
description.gsub(/^(.{#{length}}[^\n]*).*$/m, '\1').strip if description
end
def allows_to?(action) def allows_to?(action)
if action.is_a? Hash if action.is_a? Hash
allowed_actions.include? "#{action[:controller]}/#{action[:action]}" allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
@@ -241,7 +186,6 @@ protected
def validate def validate
errors.add(parent_id, " must be a root project") if parent and parent.parent errors.add(parent_id, " must be a root project") if parent and parent.parent
errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0
errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/)
end end
private private
+34 -61
View File
@@ -16,13 +16,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class QueryColumn class QueryColumn
attr_accessor :name, :sortable, :default_order attr_accessor :name, :sortable
include GLoc include GLoc
def initialize(name, options={}) def initialize(name, options={})
self.name = name self.name = name
self.sortable = options[:sortable] self.sortable = options[:sortable]
self.default_order = options[:default_order]
end end
def caption def caption
@@ -54,7 +53,7 @@ class Query < ActiveRecord::Base
serialize :filters serialize :filters
serialize :column_names serialize :column_names
attr_protected :project_id, :user_id attr_protected :project, :user
validates_presence_of :name, :on => :save validates_presence_of :name, :on => :save
validates_length_of :name, :maximum => 255 validates_length_of :name, :maximum => 255
@@ -83,7 +82,7 @@ class Query < ActiveRecord::Base
@@operators_by_filter_type = { :list => [ "=", "!" ], @@operators_by_filter_type = { :list => [ "=", "!" ],
:list_status => [ "o", "=", "!", "c", "*" ], :list_status => [ "o", "=", "!", "c", "*" ],
:list_optional => [ "=", "!", "!*", "*" ], :list_optional => [ "=", "!", "!*", "*" ],
:list_subprojects => [ "*", "!*", "=" ], :list_one_or_more => [ "*", "=" ],
:date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ], :date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ],
:date_past => [ ">t-", "<t-", "t-", "t", "w" ], :date_past => [ ">t-", "<t-", "t-", "t", "w" ],
:string => [ "=", "~", "!", "!~" ], :string => [ "=", "~", "!", "!~" ],
@@ -95,18 +94,17 @@ class Query < ActiveRecord::Base
@@available_columns = [ @@available_columns = [
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position"), QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position"),
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position"), QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position"),
QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position", :default_order => 'desc'), QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position"),
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"), QueryColumn.new(:subject),
QueryColumn.new(:author),
QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname"), QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname"),
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'), QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on"),
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"), QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"),
QueryColumn.new(:fixed_version, :sortable => "#{Version.table_name}.effective_date", :default_order => 'desc'), QueryColumn.new(:fixed_version),
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"), QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"), QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"), QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"), QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"),
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'), QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on"),
] ]
cattr_reader :available_columns cattr_reader :available_columns
@@ -116,16 +114,11 @@ class Query < ActiveRecord::Base
set_language_if_valid(User.current.language) set_language_if_valid(User.current.language)
end end
def after_initialize
# Store the fact that project is nil (used in #editable_by?)
@is_for_all = project.nil?
end
def validate def validate
filters.each_key do |field| filters.each_key do |field|
errors.add label_for(field), :activerecord_error_blank unless errors.add label_for(field), :activerecord_error_blank unless
# filter requires one or more values # filter requires one or more values
(values_for(field) and !values_for(field).first.blank?) or (values_for(field) and !values_for(field).first.empty?) or
# filter doesn't require any value # filter doesn't require any value
["o", "c", "!*", "*", "t", "w"].include? operator_for(field) ["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
end if filters end if filters
@@ -133,20 +126,15 @@ class Query < ActiveRecord::Base
def editable_by?(user) def editable_by?(user)
return false unless user return false unless user
# Admin can edit them all and regular users can edit their private queries return true if !is_public && self.user_id == user.id
return true if user.admin? || (!is_public && self.user_id == user.id) is_public && user.allowed_to?(:manage_public_queries, project)
# Members can not edit public queries that are for all project (only admin is allowed to)
is_public && !@is_for_all && user.allowed_to?(:manage_public_queries, project)
end end
def available_filters def available_filters
return @available_filters if @available_filters return @available_filters if @available_filters
trackers = project.nil? ? Tracker.find(:all, :order => 'position') : project.rolled_up_trackers
@available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } }, @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
"tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } }, "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
"priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI'], :order => 'position').collect{|s| [s.name, s.id.to_s] } }, "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } },
"subject" => { :type => :text, :order => 8 }, "subject" => { :type => :text, :order => 8 },
"created_on" => { :type => :date_past, :order => 9 }, "created_on" => { :type => :date_past, :order => 9 },
"updated_on" => { :type => :date_past, :order => 10 }, "updated_on" => { :type => :date_past, :order => 10 },
@@ -170,7 +158,7 @@ class Query < ActiveRecord::Base
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } } @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } } @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
unless @project.active_children.empty? unless @project.active_children.empty?
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } } @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
end end
@project.all_custom_fields.select(&:is_filter?).each do |field| @project.all_custom_fields.select(&:is_filter?).each do |field|
case field.field_format case field.field_format
@@ -227,7 +215,7 @@ class Query < ActiveRecord::Base
end end
def label_for(field) def label_for(field)
label = available_filters[field][:name] if available_filters.has_key?(field) label = @available_filters[field][:name] if @available_filters.has_key?(field)
label ||= field.gsub(/\_id$/, "") label ||= field.gsub(/\_id$/, "")
end end
@@ -235,7 +223,7 @@ class Query < ActiveRecord::Base
return @available_columns if @available_columns return @available_columns if @available_columns
@available_columns = Query.available_columns @available_columns = Query.available_columns
@available_columns += (project ? @available_columns += (project ?
project.all_custom_fields : project.custom_fields :
IssueCustomField.find(:all, :conditions => {:is_for_all => true}) IssueCustomField.find(:all, :conditions => {:is_for_all => true})
).collect {|cf| QueryCustomFieldColumn.new(cf) } ).collect {|cf| QueryCustomFieldColumn.new(cf) }
end end
@@ -265,28 +253,20 @@ class Query < ActiveRecord::Base
def statement def statement
# project/subprojects clause # project/subprojects clause
project_clauses = [] clause = ''
if project && !@project.active_children.empty? if project && has_filter?("subproject_id")
ids = [project.id] subproject_ids = []
if has_filter?("subproject_id") if operator_for("subproject_id") == "="
case operator_for("subproject_id") subproject_ids = values_for("subproject_id").each(&:to_i)
when '=' else
# include the selected subprojects subproject_ids = project.active_children.collect{|p| p.id}
ids += values_for("subproject_id").each(&:to_i)
when '!*'
# main project only
else
# all subprojects
ids += project.child_ids
end
elsif Setting.display_subprojects_issues?
ids += project.child_ids
end end
project_clauses << "#{Issue.table_name}.project_id IN (%s)" % ids.join(',') clause << "#{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project
elsif project elsif project
project_clauses << "#{Issue.table_name}.project_id = %d" % project.id clause << "#{Issue.table_name}.project_id=%d" % project.id
else
clause << Project.visible_by(User.current)
end end
project_clauses << Project.visible_by(User.current)
# filters clauses # filters clauses
filters_clauses = [] filters_clauses = []
@@ -295,14 +275,12 @@ class Query < ActiveRecord::Base
v = values_for(field).clone v = values_for(field).clone
next unless v and !v.empty? next unless v and !v.empty?
sql = '' sql = ''
is_custom_filter = false
if field =~ /^cf_(\d+)$/ if field =~ /^cf_(\d+)$/
# custom field # custom field
db_table = CustomValue.table_name db_table = CustomValue.table_name
db_field = 'value' db_field = 'value'
is_custom_filter = true sql << "#{Issue.table_name}.id IN (SELECT #{db_table}.customized_id FROM #{db_table} where #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} AND "
sql << "#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} WHERE "
else else
# regular field # regular field
db_table = Issue.table_name db_table = Issue.table_name
@@ -319,13 +297,11 @@ class Query < ActiveRecord::Base
when "=" when "="
sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
when "!" when "!"
sql = sql + "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))" sql = sql + "#{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
when "!*" when "!*"
sql = sql + "#{db_table}.#{db_field} IS NULL" sql = sql + "#{db_table}.#{db_field} IS NULL"
sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter
when "*" when "*"
sql = sql + "#{db_table}.#{db_field} IS NOT NULL" sql = sql + "#{db_table}.#{db_field} IS NOT NULL"
sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter
when ">=" when ">="
sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}" sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}"
when "<=" when "<="
@@ -349,12 +325,7 @@ class Query < ActiveRecord::Base
when "t" when "t"
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today+1).to_time)] sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today+1).to_time)]
when "w" when "w"
from = l(:general_first_day_of_week) == '7' ? sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Time.now.at_beginning_of_week), connection.quoted_date(Time.now.next_week.yesterday)]
# week starts on sunday
((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) :
# week starts on monday (Rails default)
Time.now.at_beginning_of_week
sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
when "~" when "~"
sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'" sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'"
when "!~" when "!~"
@@ -364,6 +335,8 @@ class Query < ActiveRecord::Base
filters_clauses << sql filters_clauses << sql
end if filters and valid? end if filters and valid?
(project_clauses + filters_clauses).join(' AND ') clause << ' AND ' unless clause.empty?
clause << filters_clauses.join(' AND ') unless filters_clauses.empty?
clause
end end
end end
+2 -26
View File
@@ -17,19 +17,9 @@
class Repository < ActiveRecord::Base class Repository < ActiveRecord::Base
belongs_to :project belongs_to :project
has_many :changesets, :dependent => :destroy, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC" has_many :changesets, :dependent => :destroy, :order => "#{Changeset.table_name}.revision DESC"
has_many :changes, :through => :changesets has_many :changes, :through => :changesets
# Removes leading and trailing whitespace
def url=(arg)
write_attribute(:url, arg ? arg.to_s.strip : nil)
end
# Removes leading and trailing whitespace
def root_url=(arg)
write_attribute(:root_url, arg ? arg.to_s.strip : nil)
end
def scm def scm
@scm ||= self.scm_adapter.new url, root_url, login, password @scm ||= self.scm_adapter.new url, root_url, login, password
update_attribute(:root_url, @scm.root_url) if root_url.blank? update_attribute(:root_url, @scm.root_url) if root_url.blank?
@@ -61,12 +51,7 @@ class Repository < ActiveRecord::Base
path = "/#{path}" unless path.starts_with?('/') path = "/#{path}" unless path.starts_with?('/')
Change.find(:all, :include => :changeset, Change.find(:all, :include => :changeset,
:conditions => ["repository_id = ? AND path = ?", id, path], :conditions => ["repository_id = ? AND path = ?", id, path],
:order => "committed_on DESC, #{Changeset.table_name}.id DESC").collect(&:changeset) :order => "committed_on DESC, #{Changeset.table_name}.revision DESC").collect(&:changeset)
end
# Returns a path relative to the url of the repository
def relative_path(path)
path
end end
def latest_changeset def latest_changeset
@@ -103,13 +88,4 @@ class Repository < ActiveRecord::Base
rescue rescue
nil nil
end end
private
def before_save
# Strips url and root_url
url.strip!
root_url.strip!
true
end
end end
+1 -1
View File
@@ -51,7 +51,7 @@ class Repository::Bazaar < Repository
scm_info = scm.info scm_info = scm.info
if scm_info if scm_info
# latest revision found in database # latest revision found in database
db_revision = latest_changeset ? latest_changeset.revision.to_i : 0 db_revision = latest_changeset ? latest_changeset.revision : 0
# latest revision in the repository # latest revision in the repository
scm_revision = scm_info.lastrev.identifier.to_i scm_revision = scm_info.lastrev.identifier.to_i
if db_revision < scm_revision if db_revision < scm_revision
+23 -29
View File
@@ -35,8 +35,7 @@ class Repository::Cvs < Repository
end end
def entries(path=nil, identifier=nil) def entries(path=nil, identifier=nil)
rev = identifier.nil? ? nil : changesets.find_by_revision(identifier) entries=scm.entries(path, identifier)
entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
if entries if entries
entries.each() do |entry| entries.each() do |entry|
unless entry.lastrev.nil? || entry.lastrev.identifier unless entry.lastrev.nil? || entry.lastrev.identifier
@@ -76,14 +75,16 @@ class Repository::Cvs < Repository
unless revision_to unless revision_to
revision_to=scm.get_previous_revision(revision_from) revision_to=scm.get_previous_revision(revision_from)
end end
file_diff = scm.diff(change_from.path, revision_from, revision_to) diff=diff+scm.diff(change_from.path, revision_from, revision_to, type)
diff = diff + file_diff unless file_diff.nil?
end end
end end
return diff return diff
end end
def fetch_changesets def fetch_changesets
#not the preferred way with CVS. maybe we should introduce always a cron-job for this
last_commit = changesets.maximum(:committed_on)
# some nifty bits to introduce a commit-id with cvs # some nifty bits to introduce a commit-id with cvs
# natively cvs doesn't provide any kind of changesets, there is only a revision per file. # natively cvs doesn't provide any kind of changesets, there is only a revision per file.
# we now take a guess using the author, the commitlog and the commit-date. # we now take a guess using the author, the commitlog and the commit-date.
@@ -93,10 +94,8 @@ class Repository::Cvs < Repository
# we use a small delta here, to merge all changes belonging to _one_ changeset # we use a small delta here, to merge all changes belonging to _one_ changeset
time_delta=10.seconds time_delta=10.seconds
fetch_since = latest_changeset ? latest_changeset.committed_on : nil
transaction do transaction do
tmp_rev_num = 1 scm.revisions('', last_commit, nil, :with_paths => true) do |revision|
scm.revisions('', fetch_since, nil, :with_paths => true) do |revision|
# only add the change to the database, if it doen't exists. the cvs log # only add the change to the database, if it doen't exists. the cvs log
# is not exclusive at all. # is not exclusive at all.
unless changes.find_by_path_and_revision(scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision]) unless changes.find_by_path_and_revision(scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
@@ -108,16 +107,18 @@ class Repository::Cvs < Repository
}) })
# create a new changeset.... # create a new changeset....
unless cs unless cs
# we use a temporaray revision number here (just for inserting) # we use a negative changeset-number here (just for inserting)
# later on, we calculate a continous positive number # later on, we calculate a continous positive number
latest = changesets.find(:first, :order => 'id DESC') next_rev = changesets.minimum(:revision)
cs = Changeset.create(:repository => self, next_rev = 0 if next_rev.nil? or next_rev > 0
:revision => "_#{tmp_rev_num}", next_rev = next_rev - 1
:committer => revision.author,
:committed_on => revision.time, cs=Changeset.create(:repository => self,
:comments => revision.message) :revision => next_rev,
tmp_rev_num += 1 :committer => revision.author,
:committed_on => revision.time,
:comments => revision.message)
end end
#convert CVS-File-States to internal Action-abbrevations #convert CVS-File-States to internal Action-abbrevations
@@ -138,19 +139,12 @@ class Repository::Cvs < Repository
end end
end end
# Renumber new changesets in chronological order next_rev = [changesets.maximum(:revision) || 0, 0].max
changesets.find(:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE '_%'").each do |changeset| changesets.find(:all, :conditions=>["revision < 0"], :order=>"committed_on ASC").each() do |changeset|
changeset.update_attribute :revision, next_revision_number next_rev = next_rev + 1
changeset.revision = next_rev
changeset.save!
end end
end # transaction end
end
private
# Returns the next revision number to assign to a CVS changeset
def next_revision_number
# Need to retrieve existing revision numbers to sort them as integers
@current_revision_number ||= (connection.select_values("SELECT revision FROM #{Changeset.table_name} WHERE repository_id = #{id} AND revision NOT LIKE '_%'").collect(&:to_i).max || 0)
@current_revision_number += 1
end end
end end
+6 -6
View File
@@ -29,8 +29,7 @@ class Repository::Darcs < Repository
end end
def entries(path=nil, identifier=nil) def entries(path=nil, identifier=nil)
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) entries=scm.entries(path, identifier)
entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
if entries if entries
entries.each do |entry| entries.each do |entry|
# Search the DB for the entry's last change # Search the DB for the entry's last change
@@ -48,19 +47,18 @@ class Repository::Darcs < Repository
def diff(path, rev, rev_to, type) def diff(path, rev, rev_to, type)
patch_from = changesets.find_by_revision(rev) patch_from = changesets.find_by_revision(rev)
return nil if patch_from.nil?
patch_to = changesets.find_by_revision(rev_to) if rev_to patch_to = changesets.find_by_revision(rev_to) if rev_to
if path.blank? if path.blank?
path = patch_from.changes.collect{|change| change.path}.join(' ') path = patch_from.changes.collect{|change| change.path}.join(' ')
end end
patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil, type) : nil scm.diff(path, patch_from.scmid, patch_to.scmid, type)
end end
def fetch_changesets def fetch_changesets
scm_info = scm.info scm_info = scm.info
if scm_info if scm_info
db_last_id = latest_changeset ? latest_changeset.scmid : nil db_last_id = latest_changeset ? latest_changeset.scmid : nil
next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1 next_rev = latest_changeset ? latest_changeset.revision + 1 : 1
# latest revision in the repository # latest revision in the repository
scm_revision = scm_info.lastrev.scmid scm_revision = scm_info.lastrev.scmid
unless changesets.find_by_scmid(scm_revision) unless changesets.find_by_scmid(scm_revision)
@@ -73,7 +71,9 @@ class Repository::Darcs < Repository
:committer => revision.author, :committer => revision.author,
:committed_on => revision.time, :committed_on => revision.time,
:comments => revision.message) :comments => revision.message)
next if changeset.new_record?
revision.paths.each do |change| revision.paths.each do |change|
Change.create(:changeset => changeset, Change.create(:changeset => changeset,
:action => change[:action], :action => change[:action],
-70
View File
@@ -1,70 +0,0 @@
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
# Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'redmine/scm/adapters/git_adapter'
class Repository::Git < Repository
attr_protected :root_url
validates_presence_of :url
def scm_adapter
Redmine::Scm::Adapters::GitAdapter
end
def self.scm_name
'Git'
end
def changesets_for_path(path)
Change.find(:all, :include => :changeset,
:conditions => ["repository_id = ? AND path = ?", id, path],
:order => "committed_on DESC, #{Changeset.table_name}.revision DESC").collect(&:changeset)
end
def fetch_changesets
scm_info = scm.info
if scm_info
# latest revision found in database
db_revision = latest_changeset ? latest_changeset.revision : nil
# latest revision in the repository
scm_revision = scm_info.lastrev.scmid
unless changesets.find_by_scmid(scm_revision)
revisions = scm.revisions('', db_revision, nil)
transaction do
revisions.reverse_each do |revision|
changeset = Changeset.create(:repository => self,
:revision => revision.identifier,
:scmid => revision.scmid,
:committer => revision.author,
:committed_on => revision.time,
:comments => revision.message)
revision.paths.each do |change|
Change.create(:changeset => changeset,
:action => change[:action],
:path => change[:path],
:from_path => change[:from_path],
:from_revision => change[:from_revision])
end
end
end
end
end
end
end
+21 -34
View File
@@ -34,11 +34,6 @@ class Repository::Mercurial < Repository
if entries if entries
entries.each do |entry| entries.each do |entry|
next unless entry.is_file? next unless entry.is_file?
# Set the filesize unless browsing a specific revision
if identifier.nil?
full_path = File.join(root_url, entry.path)
entry.size = File.stat(full_path).size if File.file?(full_path)
end
# Search the DB for the entry's last change # Search the DB for the entry's last change
change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC") change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
if change if change
@@ -56,37 +51,29 @@ class Repository::Mercurial < Repository
scm_info = scm.info scm_info = scm.info
if scm_info if scm_info
# latest revision found in database # latest revision found in database
db_revision = latest_changeset ? latest_changeset.revision.to_i : -1 db_revision = latest_changeset ? latest_changeset.revision : nil
# latest revision in the repository # latest revision in the repository
latest_revision = scm_info.lastrev scm_revision = scm_info.lastrev.identifier.to_i
return if latest_revision.nil?
scm_revision = latest_revision.identifier.to_i unless changesets.find_by_revision(scm_revision)
if db_revision < scm_revision revisions = scm.revisions('', db_revision, nil)
logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug? transaction do
identifier_from = db_revision + 1 revisions.reverse_each do |revision|
while (identifier_from <= scm_revision) changeset = Changeset.create(:repository => self,
# loads changesets by batches of 100 :revision => revision.identifier,
identifier_to = [identifier_from + 99, scm_revision].min :scmid => revision.scmid,
revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true) :committer => revision.author,
transaction do :committed_on => revision.time,
revisions.each do |revision| :comments => revision.message)
changeset = Changeset.create(:repository => self,
:revision => revision.identifier, revision.paths.each do |change|
:scmid => revision.scmid, Change.create(:changeset => changeset,
:committer => revision.author, :action => change[:action],
:committed_on => revision.time, :path => change[:path],
:comments => revision.message) :from_path => change[:from_path],
:from_revision => change[:from_revision])
revision.paths.each do |change|
Change.create(:changeset => changeset,
:action => change[:action],
:path => change[:path],
:from_path => change[:from_path],
:from_revision => change[:from_revision])
end
end end
end unless revisions.nil? end
identifier_from = identifier_to + 1
end end
end end
end end
+1 -16
View File
@@ -35,16 +35,11 @@ class Repository::Subversion < Repository
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC") : [] revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC") : []
end end
# Returns a path relative to the url of the repository
def relative_path(path)
path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
end
def fetch_changesets def fetch_changesets
scm_info = scm.info scm_info = scm.info
if scm_info if scm_info
# latest revision found in database # latest revision found in database
db_revision = latest_changeset ? latest_changeset.revision.to_i : 0 db_revision = latest_changeset ? latest_changeset.revision : 0
# latest revision in the repository # latest revision in the repository
scm_revision = scm_info.lastrev.identifier.to_i scm_revision = scm_info.lastrev.identifier.to_i
if db_revision < scm_revision if db_revision < scm_revision
@@ -76,14 +71,4 @@ class Repository::Subversion < Repository
end end
end end
end end
private
# Returns the relative url of the repository
# Eg: root_url = file:///var/svn/foo
# url = file:///var/svn/foo/bar
# => returns /bar
def relative_url
@relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url)}"), '')
end
end end
+1 -12
View File
@@ -21,18 +21,7 @@ class Role < ActiveRecord::Base
BUILTIN_ANONYMOUS = 2 BUILTIN_ANONYMOUS = 2
before_destroy :check_deletable before_destroy :check_deletable
has_many :workflows, :dependent => :delete_all do has_many :workflows, :dependent => :delete_all
def copy(role)
raise "Can not copy workflow from a #{role.class}" unless role.is_a?(Role)
raise "Can not copy workflow from/to an unsaved role" if proxy_owner.new_record? || role.new_record?
clear
connection.insert "INSERT INTO workflows (tracker_id, old_status_id, new_status_id, role_id)" +
" SELECT tracker_id, old_status_id, new_status_id, #{proxy_owner.id}" +
" FROM workflows" +
" WHERE role_id = #{role.id}"
end
end
has_many :members has_many :members
acts_as_list acts_as_list
+1 -7
View File
@@ -53,13 +53,12 @@ class Setting < ActiveRecord::Base
v = read_attribute(:value) v = read_attribute(:value)
# Unserialize serialized settings # Unserialize serialized settings
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String) v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String)
v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank?
v v
end end
def value=(v) def value=(v)
v = v.to_yaml if v && @@available_settings[name]['serialized'] v = v.to_yaml if v && @@available_settings[name]['serialized']
write_attribute(:value, v.to_s) write_attribute(:value, v)
end end
# Returns the value of the setting named name # Returns the value of the setting named name
@@ -96,11 +95,6 @@ class Setting < ActiveRecord::Base
class_eval src, __FILE__, __LINE__ class_eval src, __FILE__, __LINE__
end end
# Helper that returns an array based on per_page_options setting
def self.per_page_options_array
per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
end
# Checks if settings have changed since the values were read # Checks if settings have changed since the values were read
# and clears the cache hash if it's the case # and clears the cache hash if it's the case
# Called once per request # Called once per request
+2 -25
View File
@@ -1,5 +1,5 @@
# redMine - project management software # redMine - project management software
# Copyright (C) 2006-2008 Jean-Philippe Lang # Copyright (C) 2006-2007 Jean-Philippe Lang
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@@ -29,14 +29,6 @@ class TimeEntry < ActiveRecord::Base
validates_numericality_of :hours, :allow_nil => true validates_numericality_of :hours, :allow_nil => true
validates_length_of :comments, :maximum => 255 validates_length_of :comments, :maximum => 255
def after_initialize
if new_record? && self.activity.nil?
if default_activity = Enumeration.default('ACTI')
self.activity_id = default_activity.id
end
end
end
def before_validation def before_validation
self.project = issue.project if issue && project.nil? self.project = issue.project if issue && project.nil?
end end
@@ -47,10 +39,6 @@ class TimeEntry < ActiveRecord::Base
errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project) errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project)
end end
def hours=(h)
write_attribute :hours, (h.is_a?(String) ? h.to_hours : h)
end
# tyear, tmonth, tweek assigned where setting spent_on attributes # tyear, tmonth, tweek assigned where setting spent_on attributes
# these attributes make time aggregations easier # these attributes make time aggregations easier
def spent_on=(date) def spent_on=(date)
@@ -58,16 +46,5 @@ class TimeEntry < ActiveRecord::Base
self.tyear = spent_on ? spent_on.year : nil self.tyear = spent_on ? spent_on.year : nil
self.tmonth = spent_on ? spent_on.month : nil self.tmonth = spent_on ? spent_on.month : nil
self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil
end end
# Returns true if the time entry can be edited by usr, otherwise false
def editable_by?(usr)
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
end
def self.visible_by(usr)
with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
yield
end
end
end end
+1 -13
View File
@@ -18,19 +18,7 @@
class Tracker < ActiveRecord::Base class Tracker < ActiveRecord::Base
before_destroy :check_integrity before_destroy :check_integrity
has_many :issues has_many :issues
has_many :workflows, :dependent => :delete_all do has_many :workflows, :dependent => :delete_all
def copy(tracker)
raise "Can not copy workflow from a #{tracker.class}" unless tracker.is_a?(Tracker)
raise "Can not copy workflow from/to an unsaved tracker" if proxy_owner.new_record? || tracker.new_record?
clear
connection.insert "INSERT INTO workflows (tracker_id, old_status_id, new_status_id, role_id)" +
" SELECT #{proxy_owner.id}, old_status_id, new_status_id, role_id" +
" FROM workflows" +
" WHERE tracker_id = #{tracker.id}"
end
end
has_and_belongs_to_many :projects
has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id' has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
acts_as_list acts_as_list
+22 -55
View File
@@ -18,22 +18,11 @@
require "digest/sha1" require "digest/sha1"
class User < ActiveRecord::Base class User < ActiveRecord::Base
class OnTheFlyCreationFailure < Exception; end
# Account statuses # Account statuses
STATUS_ANONYMOUS = 0 STATUS_ANONYMOUS = 0
STATUS_ACTIVE = 1 STATUS_ACTIVE = 1
STATUS_REGISTERED = 2 STATUS_REGISTERED = 2
STATUS_LOCKED = 3 STATUS_LOCKED = 3
USER_FORMATS = {
:firstname_lastname => '#{firstname} #{lastname}',
:firstname => '#{firstname}',
:lastname_firstname => '#{lastname} #{firstname}',
:lastname_coma_firstname => '#{lastname}, #{firstname}',
:username => '#{login}'
}
has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all
has_many :projects, :through => :memberships has_many :projects, :through => :memberships
@@ -49,12 +38,11 @@ class User < ActiveRecord::Base
attr_protected :login, :admin, :password, :password_confirmation, :hashed_password attr_protected :login, :admin, :password, :password_confirmation, :hashed_password
validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? } validates_uniqueness_of :login, :mail
validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? }
# Login must contain lettres, numbers, underscores only # Login must contain lettres, numbers, underscores only
validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i
validates_length_of :login, :maximum => 30 validates_length_of :login, :maximum => 30
validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-\.]*$/i validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i
validates_length_of :firstname, :lastname, :maximum => 30 validates_length_of :firstname, :lastname, :maximum => 30
validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true
validates_length_of :mail, :maximum => 60, :allow_nil => true validates_length_of :mail, :maximum => 60, :allow_nil => true
@@ -108,23 +96,20 @@ class User < ActiveRecord::Base
onthefly.language = Setting.default_language onthefly.language = Setting.default_language
if onthefly.save if onthefly.save
user = find(:first, :conditions => ["login=?", login]) user = find(:first, :conditions => ["login=?", login])
logger.info("User '#{user.login}' created from the LDAP") if logger logger.info("User '#{user.login}' created on the fly.") if logger
else
logger.error("User '#{onthefly.login}' found in LDAP but could not be created (#{onthefly.errors.full_messages.join(', ')})") if logger
raise OnTheFlyCreationFailure.new
end end
end end
end end
user.update_attribute(:last_login_on, Time.now) if user user.update_attribute(:last_login_on, Time.now) if user
user user
rescue => text
raise text rescue => text
raise text
end end
# Return user's full name for display # Return user's full name for display
def name(formatter = nil) def name
f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname] "#{firstname} #{lastname}"
eval '"' + f + '"'
end end
def active? def active?
@@ -151,10 +136,6 @@ class User < ActiveRecord::Base
self.pref.time_zone.nil? ? nil : TimeZone[self.pref.time_zone] self.pref.time_zone.nil? ? nil : TimeZone[self.pref.time_zone]
end end
def wants_comments_in_reverse_order?
self.pref[:comments_sorting] == 'desc'
end
# Return user's RSS key (a 40 chars long string), used to access feeds # Return user's RSS key (a 40 chars long string), used to access feeds
def rss_key def rss_key
token = self.rss_token || Token.create(:user => self, :action => 'feeds') token = self.rss_token || Token.create(:user => self, :action => 'feeds')
@@ -184,13 +165,7 @@ class User < ActiveRecord::Base
end end
def <=>(user) def <=>(user)
if user.nil? user.nil? ? -1 : (lastname == user.lastname ? firstname <=> user.firstname : lastname <=> user.lastname)
-1
elsif lastname.to_s.downcase == user.lastname.to_s.downcase
firstname.to_s.downcase <=> user.firstname.to_s.downcase
else
lastname.to_s.downcase <=> user.lastname.to_s.downcase
end
end end
def to_s def to_s
@@ -227,26 +202,17 @@ class User < ActiveRecord::Base
# action can be: # action can be:
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
# * a permission Symbol (eg. :edit_project) # * a permission Symbol (eg. :edit_project)
def allowed_to?(action, project, options={}) def allowed_to?(action, project)
if project # No action allowed on archived projects
# No action allowed on archived projects return false unless project.active?
return false unless project.active? # No action allowed on disabled modules
# No action allowed on disabled modules return false unless project.allows_to?(action)
return false unless project.allows_to?(action) # Admin users are authorized for anything else
# Admin users are authorized for anything else return true if admin?
return true if admin?
role = role_for_project(project)
role = role_for_project(project) return false unless role
return false unless role role.allowed_to?(action) && (project.is_public? || role.member?)
role.allowed_to?(action) && (project.is_public? || role.member?)
elsif options[:global]
# authorize if user has at least one role that has this permission
roles = memberships.collect {|m| m.role}.uniq
roles.detect {|r| r.allowed_to?(action)}
else
false
end
end end
def self.current=(user) def self.current=(user)
@@ -258,12 +224,13 @@ class User < ActiveRecord::Base
end end
def self.anonymous def self.anonymous
return @anonymous_user if @anonymous_user
anonymous_user = AnonymousUser.find(:first) anonymous_user = AnonymousUser.find(:first)
if anonymous_user.nil? if anonymous_user.nil?
anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :mail => '', :login => '', :status => 0) anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :mail => '', :login => '', :status => 0)
raise 'Unable to create the anonymous user.' if anonymous_user.new_record? raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
end end
anonymous_user @anonymous_user = anonymous_user
end end
private private
-3
View File
@@ -46,7 +46,4 @@ class UserPreference < ActiveRecord::Base
self.others.store attr_name, value self.others.store attr_name, value
end end
end end
def comments_sorting; self[:comments_sorting] end
def comments_sorting=(order); self[:comments_sorting]=order end
end end
+3 -13
View File
@@ -23,7 +23,7 @@ class Version < ActiveRecord::Base
validates_presence_of :name validates_presence_of :name
validates_uniqueness_of :name, :scope => [:project_id] validates_uniqueness_of :name, :scope => [:project_id]
validates_length_of :name, :maximum => 60 validates_length_of :name, :maximum => 30
validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date, :allow_nil => true validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date, :allow_nil => true
def start_date def start_date
@@ -34,16 +34,6 @@ class Version < ActiveRecord::Base
effective_date effective_date
end end
# Returns the total estimated time for this version
def estimated_hours
@estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f
end
# Returns the total reported time for this version
def spent_hours
@spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f
end
# Returns true if the version is completed: due date reached and no open issues # Returns true if the version is completed: due date reached and no open issues
def completed? def completed?
effective_date && (effective_date <= Date.today) && (open_issues_count == 0) effective_date && (effective_date <= Date.today) && (open_issues_count == 0)
@@ -89,11 +79,11 @@ class Version < ActiveRecord::Base
def to_s; name end def to_s; name end
# Versions are sorted by effective_date and name # Versions are sorted by effective_date
# Those with no effective_date are at the end, sorted by name # Those with no effective_date are at the end, sorted by name
def <=>(version) def <=>(version)
if self.effective_date if self.effective_date
version.effective_date ? (self.effective_date == version.effective_date ? self.name <=> version.name : self.effective_date <=> version.effective_date) : -1 version.effective_date ? (self.effective_date <=> version.effective_date) : -1
else else
version.effective_date ? 1 : (self.name <=> version.name) version.effective_date ? 1 : (self.name <=> version.name)
end end
-13
View File
@@ -32,7 +32,6 @@ class WikiContent < ActiveRecord::Base
acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"}, acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"},
:description => :comments, :description => :comments,
:datetime => :updated_on, :datetime => :updated_on,
:type => 'wiki-page',
:url => Proc.new {|o| {:controller => 'wiki', :id => o.page.wiki.project_id, :page => o.page.title, :version => o.version}} :url => Proc.new {|o| {:controller => 'wiki', :id => o.page.wiki.project_id, :page => o.page.title, :version => o.version}}
def text=(plain) def text=(plain)
@@ -61,18 +60,6 @@ class WikiContent < ActiveRecord::Base
data data
end end
end end
def project
page.project
end
# Returns the previous version or nil
def previous
@previous ||= WikiContent::Version.find(:first,
:order => 'version DESC',
:include => :author,
:conditions => ["wiki_content_id = ? AND version < ?", wiki_content_id, version])
end
end end
end end
-45
View File
@@ -16,7 +16,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'diff' require 'diff'
require 'enumerator'
class WikiPage < ActiveRecord::Base class WikiPage < ActiveRecord::Base
belongs_to :wiki belongs_to :wiki
@@ -88,12 +87,6 @@ class WikiPage < ActiveRecord::Base
(content_to && content_from) ? WikiDiff.new(content_to, content_from) : nil (content_to && content_from) ? WikiDiff.new(content_to, content_from) : nil
end end
def annotate(version=nil)
version = version ? version.to_i : self.content.version
c = content.versions.find_by_version(version)
c ? WikiAnnotate.new(c) : nil
end
def self.pretty_title(str) def self.pretty_title(str)
(str && str.is_a?(String)) ? str.tr('_', ' ') : str (str && str.is_a?(String)) ? str.tr('_', ' ') : str
end end
@@ -120,41 +113,3 @@ class WikiDiff
@diff = words_from.diff @words @diff = words_from.diff @words
end end
end end
class WikiAnnotate
attr_reader :lines, :content
def initialize(content)
@content = content
current = content
current_lines = current.text.split(/\r?\n/)
@lines = current_lines.collect {|t| [nil, nil, t]}
positions = []
current_lines.size.times {|i| positions << i}
while (current.previous)
d = current.previous.text.split(/\r?\n/).diff(current.text.split(/\r?\n/)).diffs.flatten
d.each_slice(3) do |s|
sign, line = s[0], s[1]
if sign == '+' && positions[line] && positions[line] != -1
if @lines[positions[line]][0].nil?
@lines[positions[line]][0] = current.version
@lines[positions[line]][1] = current.author
end
end
end
d.each_slice(3) do |s|
sign, line = s[0], s[1]
if sign == '-'
positions.insert(line, -1)
else
positions[line] = nil
end
end
positions.compact!
# Stop if every line is annotated
break unless @lines.detect { |line| line[0].nil? }
current = current.previous
end
@lines.each { |line| line[0] ||= current.version }
end
end
@@ -15,18 +15,24 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.dirname(__FILE__) + '/../test_helper' class IssueSweeper < ActionController::Caching::Sweeper
observe Issue
class AttachmentTest < Test::Unit::TestCase def after_save(issue)
expire_cache_for(issue)
def setup
end end
def test_diskfilename def after_destroy(issue)
assert Attachment.disk_filename("test_file.txt") =~ /^\d{12}_test_file.txt$/ expire_cache_for(issue)
assert_equal 'test_file.txt', Attachment.disk_filename("test_file.txt")[13..-1] end
assert_equal '770c509475505f37c2b8fb6030434d6b.txt', Attachment.disk_filename("test_accentué.txt")[13..-1]
assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1] private
assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1] def expire_cache_for(issue)
# fragments of the main project
expire_fragment(Regexp.new("projects/(calendar|gantt)/#{issue.project_id}\\."))
# fragments of the root project that include subprojects issues
unless issue.project.parent_id.nil?
expire_fragment(Regexp.new("projects/(calendar|gantt)/#{issue.project.parent_id}\\..*subprojects"))
end
end end
end end
+40
View File
@@ -0,0 +1,40 @@
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class ProjectSweeper < ActionController::Caching::Sweeper
observe Project
def before_save(project)
if project.new_record?
expire_cache_for(project.parent) if project.parent
else
project_before_update = Project.find(project.id)
return if project_before_update.parent_id == project.parent_id && project_before_update.status == project.status
expire_cache_for(project.parent) if project.parent
expire_cache_for(project_before_update.parent) if project_before_update.parent
end
end
def after_destroy(project)
expire_cache_for(project.parent) if project.parent
end
private
def expire_cache_for(project)
expire_fragment(Regexp.new("projects/(calendar|gantt)/#{project.id}\\."))
end
end
@@ -1,24 +1,34 @@
# redMine - project management software # redMine - project management software
# Copyright (C) 2006-2008 Jean-Philippe Lang # Copyright (C) 2006-2007 Jean-Philippe Lang
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
desc 'Fetch changesets from the repositories' class VersionSweeper < ActionController::Caching::Sweeper
observe Version
namespace :redmine do
task :fetch_changesets => :environment do def after_save(version)
Repository.fetch_changesets expire_cache_for(version)
end end
end
def after_destroy(version)
expire_cache_for(version)
end
private
def expire_cache_for(version)
# calendar and gantt fragments of the project
expire_fragment(Regexp.new("projects/(calendar|gantt)/#{version.project_id}\\."))
end
end
+3 -3
View File
@@ -2,8 +2,8 @@
<% form_tag({:action=> "login"}) do %> <% form_tag({:action=> "login"}) do %>
<table> <table>
<tr> <tr>
<td align="right"><label for="username"><%=l(:field_login)%>:</label></td> <td align="right"><label for="login"><%=l(:field_login)%>:</label></td>
<td align="left"><p><%= text_field_tag 'username', nil, :size => 40 %></p></td> <td align="left"><p><%= text_field_tag 'login', nil, :size => 40 %></p></td>
</tr> </tr>
<tr> <tr>
<td align="right"><label for="password"><%=l(:field_password)%>:</label></td> <td align="right"><label for="password"><%=l(:field_password)%>:</label></td>
@@ -28,6 +28,6 @@
</td> </td>
</tr> </tr>
</table> </table>
<%= javascript_tag "Form.Element.focus('username');" %> <%= javascript_tag "Form.Element.focus('login');" %>
<% end %> <% end %>
</div> </div>
+7
View File
@@ -35,3 +35,10 @@
<%= submit_tag l(:button_submit) %> <%= submit_tag l(:button_submit) %>
<% end %> <% end %>
<% content_for :header_tags do %>
<%= javascript_include_tag 'calendar/calendar' %>
<%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
<%= javascript_include_tag 'calendar/calendar-setup' %>
<%= stylesheet_link_tag 'calendar' %>
<% end %>
+3 -3
View File
@@ -1,7 +1,7 @@
<h2><%=h @user.name %></h2> <h2><%=h @user.name %></h2>
<p> <p>
<%= mail_to(h(@user.mail)) unless @user.pref.hide_mail %> <%= mail_to @user.mail unless @user.pref.hide_mail %>
<ul> <ul>
<li><%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %></li> <li><%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %></li>
<% for custom_value in @custom_values %> <% for custom_value in @custom_values %>
@@ -16,8 +16,8 @@
<h3><%=l(:label_project_plural)%></h3> <h3><%=l(:label_project_plural)%></h3>
<ul> <ul>
<% for membership in @memberships %> <% for membership in @memberships %>
<li><%= link_to(h(membership.project.name), :controller => 'projects', :action => 'show', :id => membership.project) %> <li><%= link_to membership.project.name, :controller => 'projects', :action => 'show', :id => membership.project %>
(<%=h membership.role.name %>, <%= format_date(membership.created_on) %>)</li> (<%= membership.role.name %>, <%= format_date(membership.created_on) %>)</li>
<% end %> <% end %>
</ul> </ul>
<% end %> <% end %>
-8
View File
@@ -1,8 +0,0 @@
<div class="nodata">
<% form_tag({:action => 'default_configuration'}) do %>
<%= simple_format(l(:text_no_configuration_data)) %>
<p><%= l(:field_language) %>:
<%= select_tag 'lang', options_for_select(lang_options_for_select(false), current_language.to_s) %>
<%= submit_tag l(:text_load_default_configuration) %></p>
<% end %>
</div>
+9 -3
View File
@@ -1,7 +1,5 @@
<h2><%=l(:label_administration)%></h2> <h2><%=l(:label_administration)%></h2>
<%= render :partial => 'no_data' if @no_configuration_data %>
<p class="icon22 icon22-projects"> <p class="icon22 icon22-projects">
<%= link_to l(:label_project_plural), :controller => 'admin', :action => 'projects' %> | <%= link_to l(:label_project_plural), :controller => 'admin', :action => 'projects' %> |
<%= link_to l(:label_new), :controller => 'projects', :action => 'add' %> <%= link_to l(:label_new), :controller => 'projects', :action => 'add' %>
@@ -30,6 +28,14 @@
<%= link_to l(:label_enumerations), :controller => 'enumerations' %> <%= link_to l(:label_enumerations), :controller => 'enumerations' %>
</p> </p>
<p class="icon22 icon22-notifications">
<%= link_to l(:field_mail_notification), :controller => 'admin', :action => 'mail_options' %>
</p>
<p class="icon22 icon22-authent">
<%= link_to l(:label_authentication), :controller => 'auth_sources' %>
</p>
<p class="icon22 icon22-settings"> <p class="icon22 icon22-settings">
<%= link_to l(:label_settings), :controller => 'settings' %> <%= link_to l(:label_settings), :controller => 'settings' %>
</p> </p>
@@ -38,4 +44,4 @@
<%= link_to l(:label_information_plural), :controller => 'admin', :action => 'info' %> <%= link_to l(:label_information_plural), :controller => 'admin', :action => 'info' %>
</p> </p>
<% html_title(l(:label_administration)) -%> <% set_html_title l(:label_administration) -%>
+7 -7
View File
@@ -1,16 +1,16 @@
<h2><%=l(:label_information_plural)%></h2> <h2><%=l(:label_information_plural)%></h2>
<p><strong><%= Redmine::Info.versioned_name %></strong> (<%= @db_adapter_name %>)</p> <p><%=l(:field_version)%>: <strong><%= Redmine::Info.versioned_name %></strong> (<%= @db_adapter_name %>)</p>
<table class="list"> <table class="list">
<tr class="odd"><td><%= l(:text_default_administrator_account_changed) %></td><td><%= image_tag (@flags[:default_admin_changed] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr> <tr class="odd"><td>Default administrator account changed</td><td><%= image_tag (@flags[:default_admin_changed] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
<tr class="even"><td><%= l(:text_file_repository_writable) %></td><td><%= image_tag (@flags[:file_repository_writable] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr> <tr class="even"><td>File repository writable</td><td><%= image_tag (@flags[:file_repository_writable] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
<tr class="odd"><td><%= l(:text_rmagick_available) %></td><td><%= image_tag (@flags[:rmagick_available] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr> <tr class="odd"><td>RMagick available</td><td><%= image_tag (@flags[:rmagick_available] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
</table> </table>
<% if @plugins.any? %> <% if @plugins.any? %>
&nbsp; &nbsp;
<h3 class="icon22 icon22-plugin"><%= l(:label_plugins) %></h3> <h3 class="icon22 icon22-plugin">Plugins</h3>
<table class="list"> <table class="list">
<% @plugins.keys.sort {|x,y| x.to_s <=> y.to_s}.each do |plugin| %> <% @plugins.keys.sort {|x,y| x.to_s <=> y.to_s}.each do |plugin| %>
<tr class="<%= cycle('odd', 'even') %>"> <tr class="<%= cycle('odd', 'even') %>">
@@ -18,10 +18,10 @@
<td><%=h @plugins[plugin].description %></td> <td><%=h @plugins[plugin].description %></td>
<td><%=h @plugins[plugin].author %></td> <td><%=h @plugins[plugin].author %></td>
<td><%=h @plugins[plugin].version %></td> <td><%=h @plugins[plugin].version %></td>
<td><%= link_to(l(:button_configure), :controller => 'settings', :action => 'plugin', :id => plugin.to_s) if @plugins[plugin].configurable? %></td> <td><%= link_to('Configure', :controller => 'settings', :action => 'plugin', :id => plugin.to_s) if @plugins[plugin].configurable? %></td>
</tr> </tr>
<% end %> <% end %>
</table> </table>
<% end %> <% end %>
<% html_title(l(:label_information_plural)) -%> <% set_html_title(l(:label_information_plural)) -%>
@@ -1,30 +1,33 @@
<% form_tag({:action => 'edit', :tab => 'notifications'}) do %> <div class="contextual">
<%= link_to l(:label_send_test_email), :action => 'test_email' %>
</div>
<div class="box tabular settings"> <h2><%=l(:field_mail_notification)%></h2>
<% form_tag({:action => 'mail_options'}, :id => 'mail-options-form') do %>
<fieldset class="box tabular settings"><legend><%=l(:label_settings)%></legend>
<p><label><%= l(:setting_mail_from) %></label> <p><label><%= l(:setting_mail_from) %></label>
<%= text_field_tag 'settings[mail_from]', Setting.mail_from, :size => 60 %></p> <%= text_field_tag 'settings[mail_from]', Setting.mail_from, :size => 60 %></p>
<p><label><%= l(:setting_bcc_recipients) %></label> <p><label><%= l(:setting_bcc_recipients) %></label>
<%= check_box_tag 'settings[bcc_recipients]', 1, Setting.bcc_recipients? %> <%= check_box_tag 'settings[bcc_recipients]', 1, Setting.bcc_recipients? %>
<%= hidden_field_tag 'settings[bcc_recipients]', 0 %></p> <%= hidden_field_tag 'settings[bcc_recipients]', 0 %></p>
</div> </fieldset>
<fieldset class="box" id="notified_events"><legend><%=l(:text_select_mail_notifications)%></legend> <fieldset class="box"><legend><%=l(:text_select_mail_notifications)%></legend>
<% @notifiables.each do |notifiable| %> <% @notifiables.each do |notifiable| %>
<label><%= check_box_tag 'settings[notified_events][]', notifiable, Setting.notified_events.include?(notifiable) %> <label><%= check_box_tag 'settings[notified_events][]', notifiable, Setting.notified_events.include?(notifiable) %>
<%= l_or_humanize(notifiable) %></label><br /> <%= notifiable.humanize %></label><br />
<% end %> <% end %>
<%= hidden_field_tag 'settings[notified_events][]', '' %> <p><%= check_all_links('mail-options-form') %></p>
<p><%= check_all_links('notified_events') %></p>
</fieldset> </fieldset>
<fieldset class="box"><legend><%= l(:setting_emails_footer) %></legend> <fieldset class="box"><legend><%= l(:setting_emails_footer) %></legend>
<%= text_area_tag 'settings[emails_footer]', Setting.emails_footer, :class => 'wiki-edit', :rows => 5 %> <%= text_area_tag 'settings[emails_footer]', Setting.emails_footer, :class => 'wiki-edit', :rows => 5 %>
</fieldset> </fieldset>
<div style="float:right;">
<%= link_to l(:label_send_test_email), :controller => 'admin', :action => 'test_email' %>
</div>
<%= submit_tag l(:button_save) %> <%= submit_tag l(:button_save) %>
<% end %> <% end %>
<% set_html_title(l(:field_mail_notification)) -%>
+7 -6
View File
@@ -17,9 +17,9 @@
<thead><tr> <thead><tr>
<%= sort_header_tag('name', :caption => l(:label_project)) %> <%= sort_header_tag('name', :caption => l(:label_project)) %>
<th><%=l(:field_description)%></th> <th><%=l(:field_description)%></th>
<th><%=l(:field_is_public)%></th>
<th><%=l(:label_subproject_plural)%></th> <th><%=l(:label_subproject_plural)%></th>
<%= sort_header_tag('is_public', :caption => l(:field_is_public), :default_order => 'desc') %> <%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
<%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
<th></th> <th></th>
<th></th> <th></th>
</tr></thead> </tr></thead>
@@ -27,9 +27,9 @@
<% for project in @projects %> <% for project in @projects %>
<tr class="<%= cycle("odd", "even") %>"> <tr class="<%= cycle("odd", "even") %>">
<td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %> <td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %>
<td><%= textilizable project.short_description, :project => project %> <td><%= textilizable project.description, :project => project %>
<td align="center"><%= project.children.size %>
<td align="center"><%= image_tag 'true.png' if project.is_public? %> <td align="center"><%= image_tag 'true.png' if project.is_public? %>
<td align="center"><%= project.children.size %>
<td align="center"><%= format_date(project.created_on) %> <td align="center"><%= format_date(project.created_on) %>
<td align="center" style="width:10%"> <td align="center" style="width:10%">
<small> <small>
@@ -45,6 +45,7 @@
</tbody> </tbody>
</table> </table>
<p class="pagination"><%= pagination_links_full @project_pages, @project_count %></p> <p><%= pagination_links_full @project_pages, :status => @status %>
[ <%= @project_pages.current.first_item %> - <%= @project_pages.current.last_item %> / <%= @project_count %> ]</p>
<% html_title(l(:label_project_plural)) -%> <% set_html_title l(:label_project_plural) -%>
+4 -9
View File
@@ -1,9 +1,4 @@
<span id="attachments_fields"> <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>
<%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil -%> <%= image_to_function "add.png", "addFileField();return false" %></label>
<%= text_field_tag 'attachments[1][description]', '', :size => 60, :id => nil %>
<em><%= l(:label_optional_description) %></em> <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p>
</span>
<br />
<small><%= link_to l(:label_add_another_file), '#', :onclick => 'addFileField(); return false;' %>
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
</small>
+6 -11
View File
@@ -1,17 +1,12 @@
<div class="attachments"> <div class="attachments">
<% for attachment in attachments %> <% for attachment in attachments %>
<p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' -%> <p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' %>
<%= h(" - #{attachment.description}") unless attachment.description.blank? %> (<%= number_to_human_size attachment.filesize %>)
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
<% if options[:delete_url] %>
<%= link_to image_tag('delete.png'), options[:delete_url].update({:attachment_id => attachment}),
:confirm => l(:text_are_you_sure),
:method => :post,
:class => 'delete',
:title => l(:button_delete) %>
<% end %>
<% unless options[:no_author] %> <% unless options[:no_author] %>
<span class="author"><%= attachment.author %>, <%= format_time(attachment.created_on) %></span> <span class="author"><%= attachment.author.name %>, <%= format_date(attachment.created_on) %></span>
<% end %>
<% if options[:delete_url] %>
<%= link_to image_tag('delete.png'), options[:delete_url].update({:attachment_id => attachment}), :confirm => l(:text_are_you_sure), :method => :post %>
<% end %> <% end %>
</p> </p>
<% end %> <% end %>
+1 -1
View File
@@ -25,4 +25,4 @@
</tbody> </tbody>
</table> </table>
<p class="pagination"><%= pagination_links_full @auth_source_pages %></p> <%= pagination_links_full @auth_source_pages %>
+1 -13
View File
@@ -1,6 +1,6 @@
<h2><%= l(:label_board_plural) %></h2> <h2><%= l(:label_board_plural) %></h2>
<table class="list boards"> <table class="list">
<thead><tr> <thead><tr>
<th><%= l(:label_board) %></th> <th><%= l(:label_board) %></th>
<th><%= l(:label_topic_plural) %></th> <th><%= l(:label_topic_plural) %></th>
@@ -28,15 +28,3 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<p class="other-formats">
<%= l(:label_export_to) %>
<span><%= link_to 'Atom', {:controller => 'projects', :action => 'activity', :id => @project, :format => 'atom', :show_messages => 1, :key => User.current.rss_key},
:class => 'feed' %></span>
</p>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, {:controller => 'projects', :action => 'activity', :id => @project, :format => 'atom', :show_messages => 1, :key => User.current.rss_key}) %>
<% end %>
<% html_title l(:label_board_plural) %>
+5 -16
View File
@@ -1,5 +1,3 @@
<%= breadcrumb link_to(l(:label_board_plural), {:controller => 'boards', :action => 'index', :project_id => @project}) %>
<div class="contextual"> <div class="contextual">
<%= link_to_if_authorized l(:label_message_new), <%= link_to_if_authorized l(:label_message_new),
{:controller => 'messages', :action => 'new', :board_id => @board}, {:controller => 'messages', :action => 'new', :board_id => @board},
@@ -10,19 +8,11 @@
<div id="add-message" style="display:none;"> <div id="add-message" style="display:none;">
<h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> &#187; <%= l(:label_message_new) %></h2> <h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> &#187; <%= l(:label_message_new) %></h2>
<% form_for :message, @message, :url => {:controller => 'messages', :action => 'new', :board_id => @board}, :html => {:multipart => true, :id => 'message-form'} do |f| %> <% form_for :message, @message, :url => {:controller => 'messages', :action => 'new', :board_id => @board}, :html => {:multipart => true} do |f| %>
<%= render :partial => 'messages/form', :locals => {:f => f} %> <%= render :partial => 'messages/form', :locals => {:f => f} %>
<p><%= submit_tag l(:button_create) %> <p><%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'messages', :action => 'preview', :board_id => @board },
:method => 'post',
:update => 'preview',
:with => "Form.serialize('message-form')",
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %> |
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-message")' %></p> <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-message")' %></p>
<% end %> <% end %>
<div id="preview" class="wiki"></div>
</div> </div>
<h2><%=h @board.name %></h2> <h2><%=h @board.name %></h2>
@@ -32,9 +22,9 @@
<thead><tr> <thead><tr>
<th><%= l(:field_subject) %></th> <th><%= l(:field_subject) %></th>
<th><%= l(:field_author) %></th> <th><%= l(:field_author) %></th>
<%= sort_header_tag('created_on', :caption => l(:field_created_on)) %> <%= sort_header_tag("#{Message.table_name}.created_on", :caption => l(:field_created_on)) %>
<th><%= l(:label_reply_plural) %></th> <th><%= l(:label_reply_plural) %></th>
<%= sort_header_tag('updated_on', :caption => l(:label_message_last)) %> <%= sort_header_tag("#{Message.table_name}.updated_on", :caption => l(:label_message_last)) %>
</tr></thead> </tr></thead>
<tbody> <tbody>
<% @topics.each do |topic| %> <% @topics.each do |topic| %>
@@ -53,9 +43,8 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<p class="pagination"><%= pagination_links_full @topic_pages, @topic_count %></p> <p><%= pagination_links_full @topic_pages %>
[ <%= @topic_pages.current.first_item %> - <%= @topic_pages.current.last_item %> / <%= @topic_count %> ]</p>
<% else %> <% else %>
<p class="nodata"><%= l(:label_no_data) %></p> <p class="nodata"><%= l(:label_no_data) %></p>
<% end %> <% end %>
<% html_title h(@board.name) %>
+1 -1
View File
@@ -3,4 +3,4 @@
<p><%= l(:notice_not_authorized) %></p> <p><%= l(:notice_not_authorized) %></p>
<p><a href="javascript:history.back()">Back</a></p> <p><a href="javascript:history.back()">Back</a></p>
<% html_title '403' %> <% set_html_title '403' %>
+1 -1
View File
@@ -3,4 +3,4 @@
<p><%= l(:notice_file_not_found) %></p> <p><%= l(:notice_file_not_found) %></p>
<p><a href="javascript:history.back()">Back</a></p> <p><a href="javascript:history.back()">Back</a></p>
<% html_title '404' %> <% set_html_title '404' %>
+6
View File
@@ -0,0 +1,6 @@
<p id="attachments_p">
<label for="attachment_file"><%=l(:label_attachment)%>
<%= image_to_function "add.png", "addFileField();return false" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %>
<em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em>
</p>
+2 -5
View File
@@ -19,15 +19,12 @@ while day <= calendar.enddt %>
elsif day == i.due_date elsif day == i.due_date
image_tag('arrow_to.png') image_tag('arrow_to.png')
end %> end %>
<%= h("#{i.project} -") unless @project && @project == i.project %> <%= h("#{i.project.name} -") unless @project && @project == i.project %>
<%= link_to_issue i %>: <%= h(truncate(i.subject, 30)) %> <%= link_to_issue i %>: <%= h(truncate(i.subject, 30)) %>
<span class="tip"><%= render_issue_tooltip i %></span> <span class="tip"><%= render_issue_tooltip i %></span>
</div> </div>
<% else %> <% else %>
<span class="icon icon-package"> <%= link_to_version i, :class => "icon icon-package" %>
<%= h("#{i.project} -") unless @project && @project == i.project %>
<%= link_to_version i%>
</span>
<% end %> <% end %>
<% end %> <% end %>
</td> </td>
+7 -12
View File
@@ -1,6 +1,6 @@
xml.instruct! xml.instruct!
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
xml.title truncate_single_line(@title, 100) xml.title @title
xml.link "rel" => "self", "href" => url_for(params.merge({:format => nil, :only_path => false})) xml.link "rel" => "self", "href" => url_for(params.merge({:format => nil, :only_path => false}))
xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false) xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false)
xml.id url_for(:controller => 'welcome', :only_path => false) xml.id url_for(:controller => 'welcome', :only_path => false)
@@ -9,19 +9,14 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
xml.generator(:uri => Redmine::Info.url, :version => Redmine::VERSION) { xml.text! Redmine::Info.versioned_name; } xml.generator(:uri => Redmine::Info.url, :version => Redmine::VERSION) { xml.text! Redmine::Info.versioned_name; }
@items.each do |item| @items.each do |item|
xml.entry do xml.entry do
url = url_for(item.event_url(:only_path => false)) xml.title truncate(item.event_title, 100)
if @project xml.link "rel" => "alternate", "href" => url_for(item.event_url(:only_path => false))
xml.title truncate_single_line(item.event_title, 100) xml.id url_for(item.event_url(:only_path => false))
else
xml.title truncate_single_line("#{item.project} - #{item.event_title}", 100)
end
xml.link "rel" => "alternate", "href" => url
xml.id url
xml.updated item.event_datetime.xmlschema xml.updated item.event_datetime.xmlschema
author = item.event_author if item.respond_to?(:event_author) author = item.event_author if item.respond_to?(:author)
xml.author do xml.author do
xml.name(author) xml.name(author.is_a?(User) ? author.name : author)
xml.email(author.mail) if author.respond_to?(:mail) && !author.mail.blank? xml.email(author.mail) if author.is_a?(User)
end if author end if author
xml.content "type" => "html" do xml.content "type" => "html" do
xml.text! textilizable(item.event_description) xml.text! textilizable(item.event_description)
+5 -17
View File
@@ -8,42 +8,31 @@ function toggle_custom_field_format() {
p_regexp = $("custom_field_regexp"); p_regexp = $("custom_field_regexp");
p_values = $("custom_field_possible_values"); p_values = $("custom_field_possible_values");
p_searchable = $("custom_field_searchable"); p_searchable = $("custom_field_searchable");
p_default = $("custom_field_default_value");
p_default.setAttribute('type','text');
Element.show(p_default.parentNode);
switch (format.value) { switch (format.value) {
case "list": case "list":
Element.hide(p_length.parentNode); Element.hide(p_length.parentNode);
Element.hide(p_regexp.parentNode); Element.hide(p_regexp.parentNode);
if (p_searchable) Element.show(p_searchable.parentNode); Element.show(p_searchable.parentNode);
Element.show(p_values); Element.show(p_values);
break; break;
case "bool":
p_default.setAttribute('type','checkbox');
Element.hide(p_length.parentNode);
Element.hide(p_regexp.parentNode);
if (p_searchable) Element.hide(p_searchable.parentNode);
Element.hide(p_values);
break;
case "date": case "date":
case "bool":
Element.hide(p_length.parentNode); Element.hide(p_length.parentNode);
Element.hide(p_regexp.parentNode); Element.hide(p_regexp.parentNode);
if (p_searchable) Element.hide(p_searchable.parentNode); Element.hide(p_searchable.parentNode);
Element.hide(p_values); Element.hide(p_values);
break; break;
case "float": case "float":
case "int": case "int":
Element.show(p_length.parentNode); Element.show(p_length.parentNode);
Element.show(p_regexp.parentNode); Element.show(p_regexp.parentNode);
if (p_searchable) Element.hide(p_searchable.parentNode); Element.hide(p_searchable.parentNode);
Element.hide(p_values); Element.hide(p_values);
break; break;
default: default:
Element.show(p_length.parentNode); Element.show(p_length.parentNode);
Element.show(p_regexp.parentNode); Element.show(p_regexp.parentNode);
if (p_searchable) Element.show(p_searchable.parentNode); Element.show(p_searchable.parentNode);
Element.hide(p_values); Element.hide(p_values);
break; break;
} }
@@ -81,7 +70,6 @@ function deleteValueField(e) {
<span><%= text_field_tag 'custom_field[possible_values][]', value, :size => 30 %> <%= image_to_function "delete.png", "deleteValueField(this);return false" %><br /></span> <span><%= text_field_tag 'custom_field[possible_values][]', value, :size => 30 %> <%= image_to_function "delete.png", "deleteValueField(this);return false" %><br /></span>
<% end %> <% end %>
</p> </p>
<p><%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %></p>
</div> </div>
<div class="box"> <div class="box">
+13 -16
View File
@@ -1,26 +1,21 @@
<h2><%=l(:label_custom_field_plural)%></h2> <h2><%=l(:label_custom_field_plural)%></h2>
<% selected_tab = params[:tab] ? params[:tab].to_s : custom_fields_tabs.first[:name] %>
<div class="tabs"> <div class="tabs">
<ul> <ul>
<% custom_fields_tabs.each do |tab| -%> <li><%= link_to l(:label_issue_plural), {}, :id=> "tab-IssueCustomField", :onclick => "showTab('IssueCustomField'); this.blur(); return false;" %></li>
<li><%= link_to l(tab[:label]), { :tab => tab[:name] }, <li><%= link_to l(:label_project_plural), {}, :id=> "tab-ProjectCustomField", :onclick => "showTab('ProjectCustomField'); this.blur(); return false;" %></li>
:id => "tab-#{tab[:name]}", <li><%= link_to l(:label_user_plural), {}, :id=> "tab-UserCustomField", :onclick => "showTab('UserCustomField'); this.blur(); return false;" %></li>
:class => (tab[:name] != selected_tab ? nil : 'selected'),
:onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
<% end -%>
</ul> </ul>
</div> </div>
<% custom_fields_tabs.each do |tab| %> <% %w(IssueCustomField ProjectCustomField UserCustomField).each do |type| %>
<div id="tab-content-<%= tab[:name] %>" class="tab-content" style="<%= tab[:name] != selected_tab ? 'display:none' : nil %>"> <div id="tab-content-<%= type %>" class="tab-content">
<table class="list"> <table class="list">
<thead><tr> <thead><tr>
<th width="30%"><%=l(:field_name)%></th> <th width="30%"><%=l(:field_name)%></th>
<th><%=l(:field_field_format)%></th> <th><%=l(:field_field_format)%></th>
<th><%=l(:field_is_required)%></th> <th><%=l(:field_is_required)%></th>
<% if tab[:name] == 'IssueCustomField' %> <% if type == 'IssueCustomField' %>
<th><%=l(:field_is_for_all)%></th> <th><%=l(:field_is_for_all)%></th>
<th><%=l(:label_used_by)%></th> <th><%=l(:label_used_by)%></th>
<% end %> <% end %>
@@ -28,12 +23,12 @@
<th width="10%"></th> <th width="10%"></th>
</tr></thead> </tr></thead>
<tbody> <tbody>
<% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%> <% for custom_field in (@custom_fields_by_type[type] || []).sort %>
<tr class="<%= cycle("odd", "even") %>"> <tr class="<%= cycle("odd", "even") %>">
<td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td> <td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td>
<td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td> <td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td>
<td align="center"><%= image_tag 'true.png' if custom_field.is_required? %></td> <td align="center"><%= image_tag 'true.png' if custom_field.is_required? %></td>
<% if tab[:name] == 'IssueCustomField' %> <% if type == 'IssueCustomField' %>
<td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td> <td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td>
<td align="center"><%= custom_field.projects.count.to_s + ' ' + lwr(:label_project, custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td> <td align="center"><%= custom_field.projects.count.to_s + ' ' + lwr(:label_project, custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
<% end %> <% end %>
@@ -50,9 +45,11 @@
<% end; reset_cycle %> <% end; reset_cycle %>
</tbody> </tbody>
</table> </table>
<br />
<p><%= link_to l(:label_custom_field_new), {:action => 'new', :type => tab[:name]}, :class => 'icon icon-add' %></p> <%= link_to l(:label_custom_field_new), {:action => 'new', :type => type}, :class => 'icon icon-add' %>
</div> </div>
<% end %> <% end %>
<% html_title(l(:label_custom_field_plural)) -%> <%= javascript_tag "showTab('#{@tab}');" %>
<% set_html_title(l(:label_custom_field_plural)) -%>
-13
View File
@@ -1,13 +0,0 @@
<h2><%=l(:label_document_new)%></h2>
<% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %>
<%= render :partial => 'documents/form' %>
<div class="box">
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
</div>
<%= submit_tag l(:button_create) %>
<% end %>
+20 -10
View File
@@ -7,22 +7,32 @@
<p><em><%=h @document.category.name %><br /> <p><em><%=h @document.category.name %><br />
<%= format_date @document.created_on %></em></p> <%= format_date @document.created_on %></em></p>
<div class="wiki">
<%= textilizable @document.description, :attachments => @document.attachments %> <%= textilizable @document.description, :attachments => @document.attachments %>
</div> <br />
<h3><%= l(:label_attachment_plural) %></h3> <h3><%= l(:label_attachment_plural) %></h3>
<%= link_to_attachments @attachments, :delete_url => (authorize_for('documents', 'destroy_attachment') ? {:controller => 'documents', :action => 'destroy_attachment', :id => @document} : nil) %> <ul class="documents">
<% for attachment in @attachments %>
<li>
<div class="contextual">
<%= link_to_if_authorized l(:button_delete), {:controller => 'documents', :action => 'destroy_attachment', :id => @document, :attachment_id => attachment}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
</div>
<%= link_to attachment.filename, :action => 'download', :id => @document, :attachment_id => attachment %>
(<%= number_to_human_size attachment.filesize %>)<br />
<span class="author"><%= authoring attachment.created_on, attachment.author %></span><br />
<%= lwr(:label_download, attachment.downloads) %>
</li>
<% end %>
</ul>
<br />
<% if authorize_for('documents', 'add_attachment') %> <% if authorize_for('documents', 'add_attachment') %>
<p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;", <p><%= toggle_link l(:label_attachment_new), "add_attachment_form" %></p>
:id => 'attach_files_link' %></p> <% form_tag({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular", :id => "add_attachment_form", :style => "display:none;") do %>
<% form_tag({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %> <%= render :partial => 'attachments/form' %>
<div class="box">
<p><%= render :partial => 'attachments/form' %></p>
</div>
<%= submit_tag l(:button_add) %> <%= submit_tag l(:button_add) %>
<% end %> <% end %>
<% end %> <% end %>
<% html_title @document.title -%> <% set_html_title h(@document.title) -%>
+2 -2
View File
@@ -8,7 +8,7 @@
<table class="list"> <table class="list">
<% enumerations.each do |enumeration| %> <% enumerations.each do |enumeration| %>
<tr class="<%= cycle('odd', 'even') %>"> <tr class="<%= cycle('odd', 'even') %>">
<td><%= link_to h(enumeration), :action => 'edit', :id => enumeration %></td> <td><%= link_to enumeration.name, :action => 'edit', :id => enumeration %></td>
<td style="width:15%;"><%= image_tag('true.png') if enumeration.is_default? %></td> <td style="width:15%;"><%= image_tag('true.png') if enumeration.is_default? %></td>
<td style="width:15%;"> <td style="width:15%;">
<%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => enumeration, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %> <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => enumeration, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
@@ -25,4 +25,4 @@
<p><%= link_to l(:label_enumeration_new), { :action => 'new', :opt => option } %></p> <p><%= link_to l(:label_enumeration_new), { :action => 'new', :opt => option } %></p>
<% end %> <% end %>
<% html_title(l(:label_enumerations)) -%> <% set_html_title(l(:label_enumerations)) -%>
+2 -2
View File
@@ -3,9 +3,9 @@
<% form_tag({}) do %> <% form_tag({}) do %>
<div class="box"> <div class="box">
<p><strong><%= l(:text_issue_category_destroy_question, @issue_count) %></strong></p> <p><strong><%= l(:text_issue_category_destroy_question, @issue_count) %></strong></p>
<p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_issue_category_destroy_assignments) %></label><br /> <p><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_issue_category_destroy_assignments) %><br />
<% if @categories.size > 0 %> <% if @categories.size > 0 %>
<label><%= radio_button_tag 'todo', 'reassign', false %> <%= l(:text_issue_category_reassign_to) %></label>: <%= radio_button_tag 'todo', 'reassign', false %> <%= l(:text_issue_category_reassign_to) %>:
<%= select_tag 'reassign_to_id', options_from_collection_for_select(@categories, 'id', 'name') %></p> <%= select_tag 'reassign_to_id', options_from_collection_for_select(@categories, 'id', 'name') %></p>
<% end %> <% end %>
</div> </div>
+2 -2
View File
@@ -32,6 +32,6 @@
</tbody> </tbody>
</table> </table>
<p class="pagination"><%= pagination_links_full @issue_status_pages %></p> <%= pagination_links_full @issue_status_pages %>
<% html_title(l(:label_issue_status_plural)) -%> <% set_html_title(l(:label_issue_status_plural)) -%>
@@ -1,23 +1,15 @@
<h2><%= l(:label_bulk_edit_selected_issues) %></h2> <div id="bulk-edit-fields">
<fieldset class="box"><legend><%= l(:label_bulk_edit_selected_issues) %></legend>
<ul><%= @issues.collect {|i| content_tag('li', link_to(h("#{i.tracker} ##{i.id}"), { :action => 'show', :id => i }) + h(": #{i.subject}")) }.join("\n") %></ul>
<% form_tag() do %>
<%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
<div class="box">
<fieldset>
<legend><%= l(:label_change_properties) %></legend>
<p> <p>
<% if @available_statuses.any? %> <% if @available_statuses %>
<label><%= l(:field_status) %>: <label><%= l(:field_status) %>:
<%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %></label> <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %></label>
<% end %> <% end %>
<label><%= l(:field_priority) %>: <label><%= l(:field_priority) %>:
<%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(Enumeration.get_values('IPRI'), :id, :name)) %></label> <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(Enumeration.get_values('IPRI'), :id, :name)) %></label>
<label><%= l(:field_category) %>: <label><%= l(:field_category) %>:
<%= select_tag('category_id', content_tag('option', l(:label_no_change_option), :value => '') + <%= select_tag('category_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@project.issue_categories, :id, :name)) %></label>
content_tag('option', l(:label_none), :value => 'none') +
options_from_collection_for_select(@project.issue_categories, :id, :name)) %></label>
</p> </p>
<p> <p>
<label><%= l(:field_assigned_to) %>: <label><%= l(:field_assigned_to) %>:
@@ -25,9 +17,7 @@
content_tag('option', l(:label_nobody), :value => 'none') + content_tag('option', l(:label_nobody), :value => 'none') +
options_from_collection_for_select(@project.assignable_users, :id, :name)) %></label> options_from_collection_for_select(@project.assignable_users, :id, :name)) %></label>
<label><%= l(:field_fixed_version) %>: <label><%= l(:field_fixed_version) %>:
<%= select_tag('fixed_version_id', content_tag('option', l(:label_no_change_option), :value => '') + <%= select_tag('fixed_version_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@project.versions, :id, :name)) %></label>
content_tag('option', l(:label_none), :value => 'none') +
options_from_collection_for_select(@project.versions, :id, :name)) %></label>
</p> </p>
<p> <p>
@@ -38,12 +28,11 @@
<label><%= l(:field_done_ratio) %>: <label><%= l(:field_done_ratio) %>:
<%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label> <%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label>
</p> </p>
<label for="notes"><%= l(:field_notes) %></label><br />
<%= text_area_tag 'notes', '', :cols => 80, :rows => 5 %>
</fieldset> </fieldset>
<p><%= submit_tag l(:button_apply) %>
<fieldset><legend><%= l(:field_notes) %></legend> <%= link_to l(:button_cancel), {}, :onclick => 'Element.hide("bulk-edit-fields"); if ($("query_form")) {Element.show("query_form")}; return false;' %></p>
<%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
<%= wikitoolbar_for 'notes' %>
</div> </div>
<p><%= submit_tag l(:button_submit) %>
<% end %>
-8
View File
@@ -1,8 +0,0 @@
<% changesets.each do |changeset| %>
<div class="changeset <%= cycle('odd', 'even') %>">
<p><%= link_to("#{l(:label_revision)} #{changeset.revision}",
:controller => 'repositories', :action => 'revision', :id => @project, :rev => changeset.revision) %><br />
<span class="author"><%= authoring(changeset.committed_on, changeset.committer) %></span></p>
<%= textilizable(changeset, :comments) %>
</div>
<% end %>
-50
View File
@@ -1,50 +0,0 @@
<% labelled_tabular_form_for :issue, @issue,
:url => {:action => 'edit', :id => @issue},
:html => {:id => 'issue-form',
:class => nil,
:multipart => true} do |f| %>
<%= error_messages_for 'issue' %>
<div class="box">
<% if @edit_allowed || !@allowed_statuses.empty? %>
<fieldset class="tabular"><legend><%= l(:label_change_properties) %>
<% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %>
<small>(<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>)</small>
<% end %>
</legend>
<%= render :partial => (@edit_allowed ? 'form' : 'form_update'), :locals => {:f => f} %>
</fieldset>
<% end %>
<% if authorize_for('timelog', 'edit') %>
<fieldset class="tabular"><legend><%= l(:button_log_time) %></legend>
<% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %>
<div class="splitcontentleft">
<p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p>
</div>
<div class="splitcontentright">
<p><%= time_entry.select :activity_id, (@activities.collect {|p| [p.name, p.id]}) %></p>
</div>
<p><%= time_entry.text_field :comments, :size => 60 %></p>
<% end %>
</fieldset>
<% end %>
<fieldset><legend><%= l(:field_notes) %></legend>
<%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
<%= wikitoolbar_for 'notes' %>
<p><%=l(:label_attachment_plural)%><br /><%= render :partial => 'attachments/form' %></p>
</fieldset>
</div>
<%= f.hidden_field :lock_version %>
<%= submit_tag l(:button_submit) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'issues', :action => 'preview', :project_id => @project, :id => @issue },
:method => 'post',
:update => 'preview',
:with => 'Form.serialize("issue-form")',
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %>
<% end %>
<div id="preview" class="wiki"></div>

Some files were not shown because too many files have changed in this diff Show More