rosa-build/app/controllers/api/v1/groups_controller.rb

64 lines
1.3 KiB
Ruby
Raw Normal View History

2012-10-16 12:49:07 +01:00
class Api::V1::GroupsController < Api::V1::BaseController
2014-01-21 04:51:49 +00:00
2015-03-04 23:19:19 +00:00
before_action :authenticate_user!
skip_before_action :check_auth, only: [:show] if APP_CONFIG['anonymous_access']
2015-03-04 23:19:19 +00:00
skip_before_action :authenticate_user!, only: [:show] if APP_CONFIG['anonymous_access']
2015-03-26 00:26:24 +00:00
before_action :load_group, except: %i(index create)
2012-10-16 12:49:07 +01:00
def index
2015-03-26 00:26:24 +00:00
authorize :group
2012-10-16 12:49:07 +01:00
@groups = current_user.groups.paginate(paginate_params)
end
def show
2015-03-26 00:26:24 +00:00
authorize @group
2012-10-16 12:49:07 +01:00
end
2012-10-16 13:35:30 +01:00
def members
2015-03-26 00:26:24 +00:00
authorize @group
2014-08-28 21:22:11 +01:00
@members = @group.members.where('actor_id != ?', @group.owner_id)
.order('name').paginate(paginate_params)
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
2015-05-26 00:35:00 +01:00
@group = current_user.own_groups.new
@group.assign_attributes(group_params)
2012-10-16 13:35:30 +01:00
create_subject @group
end
2012-10-16 12:49:07 +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
end
2015-03-26 00:26:24 +00:00
private
def group_params
2015-05-26 00:35:00 +01:00
subject_params(Group, @group)
end
2015-03-26 00:26:24 +00:00
# Private: before_action hook which loads Group.
def load_group
@group = Group.find params[:id]
end
2014-08-28 21:22:11 +01:00
end