mirror of
https://github.com/redmine/redmine.git
synced 2026-05-06 19:37:31 +02:00
User groups feature initial commit.
git-svn-id: http://redmine.rubyforge.org/svn/branches/work@1373 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -32,16 +32,18 @@ class CustomFieldsController < ApplicationController
|
||||
|
||||
def new
|
||||
case params[:type]
|
||||
when "IssueCustomField"
|
||||
@custom_field = IssueCustomField.new(params[:custom_field])
|
||||
@custom_field.trackers = Tracker.find(params[:tracker_ids]) if params[:tracker_ids]
|
||||
when "UserCustomField"
|
||||
@custom_field = UserCustomField.new(params[:custom_field])
|
||||
when "ProjectCustomField"
|
||||
@custom_field = ProjectCustomField.new(params[:custom_field])
|
||||
else
|
||||
redirect_to :action => 'list'
|
||||
return
|
||||
when "IssueCustomField"
|
||||
@custom_field = IssueCustomField.new(params[:custom_field])
|
||||
@custom_field.trackers = Tracker.find(params[:tracker_ids]) if params[:tracker_ids]
|
||||
when "UserCustomField"
|
||||
@custom_field = UserCustomField.new(params[:custom_field])
|
||||
when "ProjectCustomField"
|
||||
@custom_field = ProjectCustomField.new(params[:custom_field])
|
||||
when "GroupCustomField"
|
||||
@custom_field = GroupCustomField.new(params[:custom_field])
|
||||
else
|
||||
render_404
|
||||
return
|
||||
end
|
||||
if request.post? and @custom_field.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
|
||||
114
groups/app/controllers/groups_controller.rb
Normal file
114
groups/app/controllers/groups_controller.rb
Normal file
@@ -0,0 +1,114 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2008 FreeCode
|
||||
#
|
||||
# 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 => 'name')
|
||||
@group = Group.new
|
||||
|
||||
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
|
||||
@custom_values = GroupCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @group) }
|
||||
|
||||
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])
|
||||
@custom_values = GroupCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @group.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
||||
end
|
||||
|
||||
# POST /groups
|
||||
# POST /groups.xml
|
||||
def create
|
||||
@group = Group.new(params[:group])
|
||||
@custom_values = GroupCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @group, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
||||
@group.custom_values = @custom_values
|
||||
|
||||
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])
|
||||
@custom_values = GroupCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @group, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
||||
@group.custom_values = @custom_values
|
||||
|
||||
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
|
||||
end
|
||||
@@ -20,11 +20,17 @@ class MembersController < ApplicationController
|
||||
before_filter :find_member, :except => :new
|
||||
before_filter :find_project, :only => :new
|
||||
before_filter :authorize
|
||||
|
||||
helper :projects
|
||||
|
||||
def new
|
||||
@project.members << Member.new(params[:member]) if request.post?
|
||||
member = Member.new(params[:member])
|
||||
if params[:principal].to_s =~ %r{^(group|user)_(\d+)$}
|
||||
member.principal_type, member.principal_id = $1.camelize, $2.to_i
|
||||
end
|
||||
@project.members << member if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project }
|
||||
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
|
||||
@@ -54,7 +60,7 @@ private
|
||||
end
|
||||
|
||||
def find_member
|
||||
@member = Member.find(params[:id])
|
||||
@member = Member.find(params[:id], :conditions => 'inherited_from IS NULL')
|
||||
@project = @member.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
|
||||
@@ -42,6 +42,7 @@ class UsersController < ApplicationController
|
||||
per_page_option,
|
||||
params['page']
|
||||
@users = User.find :all,:order => sort_clause,
|
||||
:include => :group,
|
||||
:conditions => conditions,
|
||||
:limit => @user_pages.items_per_page,
|
||||
:offset => @user_pages.current.offset
|
||||
@@ -58,6 +59,7 @@ class UsersController < ApplicationController
|
||||
@user.admin = params[:user][:admin] || false
|
||||
@user.login = params[:user][:login]
|
||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
|
||||
@user.group_id = params[:user][:group_id]
|
||||
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
||||
@user.custom_values = @custom_values
|
||||
if @user.save
|
||||
@@ -67,6 +69,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
end
|
||||
@auth_sources = AuthSource.find(:all)
|
||||
@groups = Group.find(:all, :order => 'name')
|
||||
end
|
||||
|
||||
def edit
|
||||
@@ -77,6 +80,7 @@ class UsersController < ApplicationController
|
||||
@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_id = params[:user][:group_id]
|
||||
if params[:custom_fields]
|
||||
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
||||
@user.custom_values = @custom_values
|
||||
@@ -88,6 +92,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
end
|
||||
@auth_sources = AuthSource.find(:all)
|
||||
@groups = Group.find(:all, :order => 'name')
|
||||
@roles = Role.find_all_givable
|
||||
@projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
|
||||
@membership ||= Member.new
|
||||
@@ -95,7 +100,7 @@ class UsersController < ApplicationController
|
||||
|
||||
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], :conditions => 'inherited_from IS NULL') : Member.new(:principal => @user)
|
||||
@membership.attributes = params[:membership]
|
||||
if request.post? and @membership.save
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
@@ -105,7 +110,7 @@ class UsersController < ApplicationController
|
||||
|
||||
def destroy_membership
|
||||
@user = User.find(params[:id])
|
||||
if request.post? and Member.find(params[:membership_id]).destroy
|
||||
if request.post? and Member.find(params[:membership_id], :conditions => 'inherited_from IS NULL').destroy
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
end
|
||||
redirect_to :action => 'edit', :id => @user and return
|
||||
|
||||
Reference in New Issue
Block a user