rosa-build/app/controllers/groups/profile_controller.rb

81 lines
2.1 KiB
Ruby
Raw Normal View History

class Groups::ProfileController < Groups::BaseController
include AvatarHelper
2014-11-12 21:11:42 +00:00
include PaginateHelper
2014-06-26 14:18:56 +01:00
2014-01-21 04:51:49 +00:00
load_and_authorize_resource class: Group, instance_name: 'group'
2015-03-04 23:19:19 +00:00
skip_before_action :authenticate_user!, only: :show if APP_CONFIG['anonymous_access']
def index
2014-01-21 04:51:49 +00:00
@groups = current_user.groups.paginate(page: params[:group_page]) # accessible_by(current_ability)
@groups = @groups.search(params[:query]) if params[:query].present?
end
def show
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]
when 'open'
@projects = @projects.opened
2014-11-12 21:11:42 +00:00
when 'hidden'
@projects = @projects.by_visibilities('hidden').accessible_by(current_ability, :read)
else
@projects = @projects.accessible_by(current_ability, :read)
2014-11-12 21:11:42 +00:00
end
@total_items = @projects.count
@projects = @projects.paginate(paginate_params)
render 'users/profile/show'
2013-09-10 18:03:00 +01:00
end
end
end
def new
end
def edit
end
def create
@group = current_user.own_groups.new params[:group]
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
end
end
def update
if @group.update_attributes(params[:group])
update_avatar(@group, params)
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
end
end
def destroy
@group.destroy
flash[:notice] = t("flash.group.destroyed")
redirect_to groups_path
end
def remove_user
Relation.by_actor(current_user).by_target(@group).destroy_all
redirect_to groups_path
end
2013-09-10 18:03:00 +01:00
protected
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
end