2013-01-20 11:20:50 +00:00
|
|
|
class Admin::GroupsController < Admin::ApplicationController
|
2012-12-25 22:52:20 +00:00
|
|
|
before_filter :group, only: [:edit, :show, :update, :destroy, :project_update, :project_teams_update]
|
2012-10-02 16:01:40 +00:00
|
|
|
|
|
|
|
def index
|
2012-12-10 03:14:05 +00:00
|
|
|
@groups = Group.order('name ASC')
|
2012-10-02 16:01:40 +00:00
|
|
|
@groups = @groups.search(params[:name]) if params[:name].present?
|
|
|
|
@groups = @groups.page(params[:page]).per(20)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@group = Group.new(params[:group])
|
2012-11-27 06:31:15 +00:00
|
|
|
@group.path = @group.name.dup.parameterize if @group.name
|
2012-10-02 16:01:40 +00:00
|
|
|
@group.owner = current_user
|
|
|
|
|
|
|
|
if @group.save
|
|
|
|
redirect_to [:admin, @group], notice: 'Group was successfully created.'
|
|
|
|
else
|
|
|
|
render action: "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-10-03 12:02:02 +00:00
|
|
|
group_params = params[:group].dup
|
|
|
|
owner_id =group_params.delete(:owner_id)
|
2012-10-02 16:01:40 +00:00
|
|
|
|
|
|
|
if owner_id
|
|
|
|
@group.owner = User.find(owner_id)
|
|
|
|
end
|
|
|
|
|
2012-10-03 12:02:02 +00:00
|
|
|
if @group.update_attributes(group_params)
|
2012-10-02 16:01:40 +00:00
|
|
|
redirect_to [:admin, @group], notice: 'Group was successfully updated.'
|
|
|
|
else
|
|
|
|
render action: "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-25 22:52:20 +00:00
|
|
|
def project_teams_update
|
2013-06-18 14:32:33 +00:00
|
|
|
@group.add_users(params[:user_ids].split(','), params[:group_access])
|
2013-06-10 12:58:51 +00:00
|
|
|
|
2013-04-10 02:43:02 +00:00
|
|
|
redirect_to [:admin, @group], notice: 'Users were successfully added.'
|
2012-12-25 22:52:20 +00:00
|
|
|
end
|
|
|
|
|
2012-10-02 16:01:40 +00:00
|
|
|
def destroy
|
|
|
|
@group.destroy
|
|
|
|
|
2012-10-22 18:21:34 +00:00
|
|
|
redirect_to admin_groups_path, notice: 'Group was successfully deleted.'
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group
|
2012-11-23 19:31:09 +00:00
|
|
|
@group = Group.find_by_path(params[:id])
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
end
|