-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jamie
committed
Oct 4, 2024
1 parent
7fdb2e9
commit c5eae01
Showing
21 changed files
with
52 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,4 @@ | |
# | ||
class Placements::SupportUser < User | ||
include ActsAsSupportUser | ||
|
||
attribute :current_organisation | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Placements::Provider::PlacementPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
scope | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
class Placements::UserPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
if user.support_user? | ||
scope | ||
else | ||
scope.where(id: UserMembership.select(:user_id).where(organisation: user.current_organisation)) | ||
end | ||
return scope if user.support_user? | ||
|
||
memberships = UserMembership.where(organisation: user.schools) | ||
.or(UserMembership.where(organisation: user.providers)) | ||
scope.where(id: memberships.select(:user_id)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,10 +38,6 @@ | |
end | ||
end | ||
|
||
describe "attributes" do | ||
it { is_expected.to have_attributes(current_organisation: nil) } | ||
end | ||
|
||
describe "default scope" do | ||
let(:email) { "[email protected]" } | ||
let!(:user_with_placements_service) { create(:placements_user, email:) } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
spec/policies/placements/provider/placement_policy_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Placements::Provider::PlacementPolicy do | ||
subject(:placement_policy) { described_class } | ||
|
||
describe "scope" do | ||
let(:scope) { Placement.all } | ||
|
||
before do | ||
create_list(:placement, 3) | ||
end | ||
|
||
context "when the user is a support user" do | ||
let(:user) { create(:placements_support_user) } | ||
|
||
it "returns all placements" do | ||
expect(placement_policy::Scope.new(user, scope).resolve).to eq(scope) | ||
end | ||
end | ||
|
||
context "when the user is a provider user" do | ||
let(:provider) { build(:placements_provider) } | ||
let(:user) { create(:placements_user, providers: [provider]) } | ||
|
||
it "returns the school's placements" do | ||
expect(placement_policy::Scope.new(user, scope).resolve).to eq(scope) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ | |
let(:user_2) { create(:placements_user) } | ||
|
||
before do | ||
user_1.current_organisation = school | ||
user_2 | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters