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