2012-10-16 12:49:07 +01:00
|
|
|
class Api::V1::GroupsController < Api::V1::BaseController
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2012-10-16 12:49:07 +01:00
|
|
|
before_filter :authenticate_user!
|
2014-01-21 04:51:49 +00:00
|
|
|
skip_before_filter :authenticate_user!, only: [:show] if APP_CONFIG['anonymous_access']
|
2012-10-16 13:35:30 +01:00
|
|
|
load_and_authorize_resource
|
2012-10-16 12:49:07 +01:00
|
|
|
|
|
|
|
def index
|
|
|
|
# accessible_by(current_ability)
|
|
|
|
@groups = current_user.groups.paginate(paginate_params)
|
2014-08-28 21:22:11 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.json
|
|
|
|
end
|
2012-10-16 12:49:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2014-08-28 21:22:11 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.json
|
|
|
|
end
|
2012-10-16 12:49:07 +01:00
|
|
|
end
|
|
|
|
|
2012-10-16 13:35:30 +01:00
|
|
|
def members
|
2014-08-28 21:22:11 +01:00
|
|
|
@members = @group.members.where('actor_id != ?', @group.owner_id)
|
|
|
|
.order('name').paginate(paginate_params)
|
|
|
|
respond_to do |format|
|
|
|
|
format.json
|
|
|
|
end
|
2012-10-16 13:35:30 +01:00
|
|
|
end
|
|
|
|
|
2012-10-16 12:49:07 +01:00
|
|
|
def update
|
2012-10-16 13:35:30 +01:00
|
|
|
update_subject @group
|
|
|
|
end
|
2012-10-16 12:49:07 +01:00
|
|
|
|
2012-10-16 13:35:30 +01:00
|
|
|
def destroy
|
|
|
|
destroy_subject @group
|
2012-10-16 12:49:07 +01:00
|
|
|
end
|
|
|
|
|
2012-10-16 13:35:30 +01:00
|
|
|
def create
|
2012-10-16 17:36:59 +01:00
|
|
|
@group = current_user.own_groups.new params[:group]
|
2012-10-16 13:35:30 +01:00
|
|
|
create_subject @group
|
|
|
|
end
|
2012-10-16 12:49:07 +01:00
|
|
|
|
2012-10-16 14:03:18 +01:00
|
|
|
def add_member
|
|
|
|
params[:type] = 'User'
|
|
|
|
add_member_to_subject @group, (params[:role] || 'admin')
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_member
|
|
|
|
params[:type] = 'User'
|
|
|
|
remove_member_from_subject @group
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_member
|
2012-10-17 14:46:16 +01:00
|
|
|
params[:type] = 'User'
|
|
|
|
update_member_in_subject @group, :actors
|
2012-10-16 14:03:18 +01:00
|
|
|
end
|
|
|
|
|
2014-08-28 21:22:11 +01:00
|
|
|
end
|