2012-05-02 10:18:07 +01:00
|
|
|
class Groups::ProfileController < Groups::BaseController
|
2012-10-03 17:38:42 +01:00
|
|
|
include AvatarHelper
|
2014-11-12 21:11:42 +00:00
|
|
|
include PaginateHelper
|
2014-06-26 14:18:56 +01:00
|
|
|
|
2015-03-04 23:19:19 +00:00
|
|
|
skip_before_action :authenticate_user!, only: :show if APP_CONFIG['anonymous_access']
|
2012-05-02 10:18:07 +01:00
|
|
|
|
|
|
|
def index
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize :group
|
2014-01-21 04:51:49 +00:00
|
|
|
@groups = current_user.groups.paginate(page: params[:group_page]) # accessible_by(current_ability)
|
2012-05-02 10:18:07 +01:00
|
|
|
@groups = @groups.search(params[:query]) if params[:query].present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2015-04-02 22:27:27 +01:00
|
|
|
authorize @group
|
2014-11-12 21:11:42 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
@members = @group.members.order(:uname)
|
|
|
|
end
|
|
|
|
format.json do
|
|
|
|
@projects = @group.own_projects.search(params[:term]).recent
|
|
|
|
case params[:visibility]
|
2014-11-13 21:19:18 +00:00
|
|
|
when 'open'
|
|
|
|
@projects = @projects.opened
|
2014-11-12 21:11:42 +00:00
|
|
|
when 'hidden'
|
2015-03-17 22:33:16 +00:00
|
|
|
@projects = @projects.by_visibilities('hidden')
|
|
|
|
@projects = @projects.none unless policy(@group).reader?
|
2014-11-12 21:11:42 +00:00
|
|
|
else
|
2015-03-17 22:33:16 +00:00
|
|
|
@projects = @projects.opened unless policy(@group).reader?
|
2014-11-12 21:11:42 +00:00
|
|
|
end
|
|
|
|
@total_items = @projects.count
|
|
|
|
@projects = @projects.paginate(paginate_params)
|
2014-11-13 21:19:18 +00:00
|
|
|
render 'users/profile/show'
|
2013-09-10 18:03:00 +01:00
|
|
|
end
|
|
|
|
end
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @group = current_user.own_groups.build
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @group
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-05-26 00:35:00 +01:00
|
|
|
@group = current_user.own_groups.new
|
|
|
|
@group.assign_attributes(group_params)
|
|
|
|
authorize @group
|
2012-05-02 10:18:07 +01:00
|
|
|
if @group.save
|
|
|
|
flash[:notice] = t('flash.group.saved')
|
|
|
|
redirect_to group_path(@group)
|
|
|
|
else
|
|
|
|
flash[:error] = t('flash.group.save_error')
|
|
|
|
flash[:warning] = @group.errors.full_messages.join('. ')
|
2014-01-21 04:51:49 +00:00
|
|
|
render action: :new
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @group
|
2015-04-28 23:28:36 +01:00
|
|
|
if @group.update_attributes(group_params)
|
2012-10-03 17:38:42 +01:00
|
|
|
update_avatar(@group, params)
|
2012-05-02 10:18:07 +01:00
|
|
|
flash[:notice] = t('flash.group.saved')
|
|
|
|
redirect_to group_path(@group)
|
|
|
|
else
|
|
|
|
flash[:error] = t('flash.group.save_error')
|
2014-01-21 04:51:49 +00:00
|
|
|
render action: :edit
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @group
|
2012-05-02 10:18:07 +01:00
|
|
|
@group.destroy
|
|
|
|
flash[:notice] = t("flash.group.destroyed")
|
|
|
|
redirect_to groups_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_user
|
2015-03-19 23:31:41 +00:00
|
|
|
authorize @group
|
2012-07-27 05:12:09 +01:00
|
|
|
Relation.by_actor(current_user).by_target(@group).destroy_all
|
2012-05-02 10:18:07 +01:00
|
|
|
redirect_to groups_path
|
|
|
|
end
|
2013-09-10 18:03:00 +01:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
2015-04-28 23:28:36 +01:00
|
|
|
def group_params
|
2015-05-26 00:35:00 +01:00
|
|
|
subject_params(Group, @group)
|
2015-04-28 23:28:36 +01:00
|
|
|
end
|
|
|
|
|
2013-09-10 18:03:00 +01:00
|
|
|
def paginate_projects(page)
|
2014-01-21 04:51:49 +00:00
|
|
|
@projects.paginate(page: (page>0 ? page : nil), per_page: 24)
|
2013-09-10 18:03:00 +01:00
|
|
|
end
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|