2014-09-02 18:07:02 +05:30
|
|
|
class Admin::GroupsController < Admin::ApplicationController
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :group, only: [:edit, :show, :update, :destroy, :project_update, :members_update]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
def index
|
2015-04-26 12:48:37 +05:30
|
|
|
@groups = Group.all
|
|
|
|
@groups = @groups.sort(@sort = params[:sort])
|
2014-09-02 18:07:02 +05:30
|
|
|
@groups = @groups.search(params[:name]) if params[:name].present?
|
2016-06-02 11:05:42 +05:30
|
|
|
@groups = @groups.page(params[:page])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-06-02 11:05:42 +05:30
|
|
|
@members = @group.members.order("access_level DESC").page(params[:members_page])
|
2016-08-24 12:49:21 +05:30
|
|
|
@requesters = @group.requesters
|
2016-06-02 11:05:42 +05:30
|
|
|
@projects = @group.projects.page(params[:projects_page])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@group = Group.new(group_params)
|
2015-04-26 12:48:37 +05:30
|
|
|
@group.name = @group.path.dup unless @group.name
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
if @group.save
|
|
|
|
@group.add_owner(current_user)
|
|
|
|
redirect_to [:admin, @group], notice: 'Group was successfully created.'
|
|
|
|
else
|
|
|
|
render "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @group.update_attributes(group_params)
|
|
|
|
redirect_to [:admin, @group], notice: 'Group was successfully updated.'
|
|
|
|
else
|
|
|
|
render "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def members_update
|
2016-09-13 17:45:13 +05:30
|
|
|
@group.add_users(params[:user_ids].split(','), params[:access_level], current_user: current_user)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
redirect_to [:admin, @group], notice: 'Users were successfully added.'
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2016-09-13 17:45:13 +05:30
|
|
|
DestroyGroupService.new(@group, current_user).async_execute
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
redirect_to admin_groups_path, alert: "Group '#{@group.name}' was scheduled for deletion."
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group
|
2016-06-02 11:05:42 +05:30
|
|
|
@group ||= Group.find_by(path: params[:id])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def group_params
|
2016-08-24 12:49:21 +05:30
|
|
|
params.require(:group).permit(:name, :description, :path, :avatar, :visibility_level, :request_access_enabled)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|