2013-01-20 11:20:50 +00:00
|
|
|
class Admin::GroupsController < Admin::ApplicationController
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :group, only: [:edit, :show, :update, :destroy, :project_update, :members_update]
|
2012-10-02 16:01:40 +00:00
|
|
|
|
|
|
|
def index
|
2015-02-06 03:15:05 +00:00
|
|
|
@groups = Group.all
|
|
|
|
@groups = @groups.sort(@sort = params[:sort])
|
2012-10-02 16:01:40 +00:00
|
|
|
@groups = @groups.search(params[:name]) if params[:name].present?
|
2015-03-12 22:37:00 +00:00
|
|
|
@groups = @groups.page(params[:page]).per(PER_PAGE)
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2015-03-12 22:37:00 +00:00
|
|
|
@members = @group.members.order("access_level DESC").page(params[:members_page]).per(PER_PAGE)
|
|
|
|
@projects = @group.projects.page(params[:projects_page]).per(PER_PAGE)
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 13:57:10 +00:00
|
|
|
@group = Group.new(group_params)
|
2014-12-22 11:55:32 +00:00
|
|
|
@group.name = @group.path.dup unless @group.name
|
2012-10-02 16:01:40 +00:00
|
|
|
|
|
|
|
if @group.save
|
2013-09-26 11:49:22 +00:00
|
|
|
@group.add_owner(current_user)
|
2012-10-02 16:01:40 +00:00
|
|
|
redirect_to [:admin, @group], notice: 'Group was successfully created.'
|
|
|
|
else
|
2013-06-22 12:08:11 +00:00
|
|
|
render "new"
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-06-26 13:57:10 +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
|
2013-06-22 12:08:11 +00:00
|
|
|
render "edit"
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-13 15:22:03 +00:00
|
|
|
def members_update
|
2015-04-10 12:46:09 +00:00
|
|
|
@group.add_users(params[:user_ids].split(','), params[:access_level], current_user)
|
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
|
2015-06-03 12:07:20 +00:00
|
|
|
DestroyGroupService.new(@group, current_user).execute
|
2012-10-02 16:01:40 +00:00
|
|
|
|
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
|
2014-01-19 18:55:59 +00:00
|
|
|
@group = Group.find_by(path: params[:id])
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|
2014-06-26 13:57:10 +00:00
|
|
|
|
|
|
|
def group_params
|
|
|
|
params.require(:group).permit(:name, :description, :path, :avatar)
|
|
|
|
end
|
2012-10-02 16:01:40 +00:00
|
|
|
end
|