Skip to content

Commit

Permalink
fix: scope user resource for admins
Browse files Browse the repository at this point in the history
  • Loading branch information
salzig authored and JoschkaSchulz committed Oct 14, 2024
1 parent 50eb404 commit 4b6ecf0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
module Admin
class UsersController < Admin::ApplicationController
def index
super
@resources = User.peers.page(params[:page]).per(10)
end

def find_resource(param)
User.peers.from_slug(param)
end

def scoped_resource
User.peers
end

# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
# for more information
end
Expand Down
35 changes: 35 additions & 0 deletions spec/controllers/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe Admin::UsersController do
render_views

before { set_subdomain }

let(:user) { build(:admin_user) }
let!(:event) do
Whitelabel.with_label(Whitelabel.labels.first) do
create(:event_with_participants)
end
end
let!(:other_event) do
Whitelabel.with_label(Whitelabel.labels.last) do
create(:event_with_participants)
end
end

context 'with logged-in user' do
before do
allow(controller).to receive_messages(current_user: user)
end

context 'GET :index' do
it 'assign the users and renders the template' do
get :index

expect(response).to render_template(:index)
expect(response.body).to include(event.participants.first.user.nickname)
expect(response.body).not_to include(other_event.participants.first.user.nickname)
end
end
end
end
35 changes: 35 additions & 0 deletions spec/controllers/super_admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe SuperAdmin::UsersController do
render_views

before { set_subdomain }

let(:user) { build(:admin_user) }
let!(:event) do
Whitelabel.with_label(Whitelabel.labels.first) do
create(:event_with_participants)
end
end
let!(:other_event) do
Whitelabel.with_label(Whitelabel.labels.last) do
create(:event_with_participants)
end
end

context 'with logged-in user' do
before do
allow(controller).to receive_messages(current_user: user)
end

context 'GET :index' do
it 'assign the users and renders the template' do
get :index

expect(response).to render_template(:index)
expect(response.body).to include(event.participants.first.user.nickname)
expect(response.body).to include(other_event.participants.first.user.nickname)
end
end
end
end

0 comments on commit 4b6ecf0

Please sign in to comment.