Permalink
Browse files

Merge branch 'master' of git://github.com/edavis10/redmine

  • Loading branch information...
tigrish committed Oct 4, 2009
2 parents fd7e24e + 4e811be commit 4e19d5708cb879d66385be90a7593932b72089e8
Showing 373 changed files with 7,456 additions and 5,241 deletions.
@@ -20,12 +20,7 @@
class ApplicationController < ActionController::Base
include Redmine::I18n
-
- # In case the cookie store secret changes
- rescue_from CGI::Session::CookieStore::TamperedWithCookie do |exception|
- render :text => 'Your session was invalid and has been reset. Please, reload this page.', :status => 500
- end
-
+
layout 'base'
before_filter :user_setup, :check_if_login_required, :set_localization
@@ -0,0 +1,162 @@
+# Redmine - project management software
+# Copyright (C) 2006-2009 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+class GroupsController < ApplicationController
+ layout 'base'
+ before_filter :require_admin
+
+ helper :custom_fields
+
+ # GET /groups
+ # GET /groups.xml
+ def index
+ @groups = Group.find(:all, :order => 'lastname')
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @groups }
+ end
+ end
+
+ # GET /groups/1
+ # GET /groups/1.xml
+ def show
+ @group = Group.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @group }
+ end
+ end
+
+ # GET /groups/new
+ # GET /groups/new.xml
+ def new
+ @group = Group.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @group }
+ end
+ end
+
+ # GET /groups/1/edit
+ def edit
+ @group = Group.find(params[:id])
+ end
+
+ # POST /groups
+ # POST /groups.xml
+ def create
+ @group = Group.new(params[:group])
+
+ respond_to do |format|
+ if @group.save
+ flash[:notice] = l(:notice_successful_create)
+ format.html { redirect_to(groups_path) }
+ format.xml { render :xml => @group, :status => :created, :location => @group }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /groups/1
+ # PUT /groups/1.xml
+ def update
+ @group = Group.find(params[:id])
+
+ respond_to do |format|
+ if @group.update_attributes(params[:group])
+ flash[:notice] = l(:notice_successful_update)
+ format.html { redirect_to(groups_path) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /groups/1
+ # DELETE /groups/1.xml
+ def destroy
+ @group = Group.find(params[:id])
+ @group.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(groups_url) }
+ format.xml { head :ok }
+ end
+ end
+
+ def add_users
+ @group = Group.find(params[:id])
+ users = User.find_all_by_id(params[:user_ids])
+ @group.users << users if request.post?
+ respond_to do |format|
+ format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
+ format.js {
+ render(:update) {|page|
+ page.replace_html "tab-content-users", :partial => 'groups/users'
+ users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
+ }
+ }
+ end
+ end
+
+ def remove_user
+ @group = Group.find(params[:id])
+ @group.users.delete(User.find(params[:user_id])) if request.post?
+ respond_to do |format|
+ format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
+ format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
+ end
+ end
+
+ def autocomplete_for_user
+ @group = Group.find(params[:id])
+ @users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
+ render :layout => false
+ end
+
+ def edit_membership
+ @group = Group.find(params[:id])
+ @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:principal => @group)
+ @membership.attributes = params[:membership]
+ @membership.save if request.post?
+ respond_to do |format|
+ format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
+ format.js {
+ render(:update) {|page|
+ page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
+ page.visual_effect(:highlight, "member-#{@membership.id}")
+ }
+ }
+ end
+ end
+
+ def destroy_membership
+ @group = Group.find(params[:id])
+ Member.find(params[:membership_id]).destroy if request.post?
+ respond_to do |format|
+ format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
+ format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
+ end
+ end
+end
@@ -211,6 +211,8 @@ def edit
rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
flash.now[:error] = l(:notice_locking_conflict)
+ # Remove the previously added attachments if issue was not updated
+ attachments.each(&:destroy)
end
def reply
@@ -16,8 +16,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class MembersController < ApplicationController
- before_filter :find_member, :except => [:new, :autocomplete_for_member_login]
- before_filter :find_project, :only => [:new, :autocomplete_for_member_login]
+ before_filter :find_member, :except => [:new, :autocomplete_for_member]
+ before_filter :find_project, :only => [:new, :autocomplete_for_member]
before_filter :authorize
def new
@@ -59,17 +59,17 @@ def edit
end
def destroy
- @member.destroy
- respond_to do |format|
+ if request.post? && @member.deletable?
+ @member.destroy
+ end
+ respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
end
end
- def autocomplete_for_member_login
- @users = User.active.find(:all, :conditions => ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ?", "#{params[:user]}%", "#{params[:user]}%", "#{params[:user]}%"],
- :limit => 10,
- :order => 'login ASC') - @project.users
+ def autocomplete_for_member
+ @principals = Principal.active.like(params[:q]).find(:all, :limit => 100) - @project.principals
render :layout => false
end
@@ -130,7 +130,7 @@ def annotate
end
def revision
- @changeset = @repository.changesets.find(:first, :conditions => ["revision LIKE ?", @rev + '%'])
+ @changeset = @repository.find_changeset_by_name(@rev)
raise ChangesetNotFound unless @changeset
respond_to do |format|
@@ -259,7 +259,7 @@ def graph_commits_per_month(repository)
def graph_commits_per_author(repository)
commits_by_author = repository.changesets.count(:all, :group => :committer)
- commits_by_author.sort! {|x, y| x.last <=> y.last}
+ commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
changes_by_author = repository.changes.count(:all, :group => :committer)
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
@@ -80,14 +80,22 @@ def report
unless @criterias.empty?
sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
+ sql_condition = ''
+ if @project.nil?
+ sql_condition = Project.allowed_to_condition(User.current, :view_time_entries)
+ elsif @issue.nil?
+ sql_condition = @project.project_condition(Setting.display_subprojects_issues?)
+ else
+ sql_condition = "#{TimeEntry.table_name}.issue_id = #{@issue.id}"
+ end
+
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
sql << " FROM #{TimeEntry.table_name}"
sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
sql << " WHERE"
- sql << " (%s) AND" % @project.project_condition(Setting.display_subprojects_issues?) if @project
- sql << " (%s) AND" % Project.allowed_to_condition(User.current, :view_time_entries)
+ sql << " (%s) AND" % sql_condition
sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
@@ -63,7 +63,7 @@ def add
if @user.save
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
flash[:notice] = l(:notice_successful_create)
- redirect_to :action => 'list'
+ redirect_to :controller => 'users', :action => 'edit', :id => @user
end
end
@auth_sources = AuthSource.find(:all)
@@ -75,6 +75,7 @@ def edit
@user.admin = params[:user][:admin] if params[:user][:admin]
@user.login = params[:user][:login] if params[:user][:login]
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
+ @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids]
@user.attributes = params[:user]
# Was the account actived ? (do it before User#save clears the change)
was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
@@ -85,17 +86,18 @@ def edit
Mailer.deliver_account_information(@user, params[:password])
end
flash[:notice] = l(:notice_successful_update)
- # Give a string to redirect_to otherwise it would use status param as the response code
- redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
+ redirect_to :back
end
end
@auth_sources = AuthSource.find(:all)
@membership ||= Member.new
+ rescue ::ActionController::RedirectBackError
+ redirect_to :controller => 'users', :action => 'edit', :id => @user
end
def edit_membership
@user = User.find(params[:id])
- @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
+ @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:principal => @user)
@membership.attributes = params[:membership]
@membership.save if request.post?
respond_to do |format|
@@ -111,7 +113,10 @@ def edit_membership
def destroy_membership
@user = User.find(params[:id])
- Member.find(params[:membership_id]).destroy if request.post?
+ @membership = Member.find(params[:membership_id])
+ if request.post? && @membership.deletable?
+ @membership.destroy
+ end
respond_to do |format|
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} }
@@ -46,7 +46,11 @@ def link_to_remote_if_authorized(name, options = {}, html_options = nil)
# Display a link to user's account page
def link_to_user(user, options={})
- (user && !user.anonymous?) ? link_to(user.name(options[:format]), :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
+ if user.is_a?(User)
+ !user.anonymous? ? link_to(user.name(options[:format]), :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
+ else
+ user.to_s
+ end
end
def link_to_issue(issue, options={})
@@ -128,6 +132,15 @@ def render_flash_messages
s
end
+ # Renders tabs and their content
+ def render_tabs(tabs)
+ if tabs.any?
+ render :partial => 'common/tabs', :locals => {:tabs => tabs}
+ else
+ content_tag 'p', l(:label_no_data), :class => "nodata"
+ end
+ end
+
# Renders the project quick-jump box
def render_project_jump_box
# Retrieve them now to avoid a COUNT query
@@ -190,6 +203,14 @@ def project_nested_ul(projects, &block)
end
s
end
+
+ def principals_check_box_tags(name, principals)
+ s = ''
+ principals.each do |principal|
+ s << "<label>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
+ end
+ s
+ end
# Truncates and returns the string as a single line
def truncate_single_line(string, *args)
@@ -18,10 +18,11 @@
module CustomFieldsHelper
def custom_fields_tabs
- tabs = [{:name => 'IssueCustomField', :label => :label_issue_plural},
- {:name => 'TimeEntryCustomField', :label => :label_spent_time},
- {:name => 'ProjectCustomField', :label => :label_project_plural},
- {:name => 'UserCustomField', :label => :label_user_plural}
+ tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural},
+ {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
+ {:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
+ {:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
+ {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural}
]
end
Oops, something went wrong.

0 comments on commit 4e19d57

Please sign in to comment.