Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/services/system_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# rows only, so it never touches a membership that was added by hand.
#
# `attributes` are the user columns that can change a membership: a save that
# changes one syncs the user. The staff, board, contractors and identity team
# groups follow roles instead (see RoleGrants), which sync the user after
# changes one syncs the user. The staff, board, contractors, identity team
# and patch leads groups follow roles instead (see RoleGrants), which sync the user after
# each grant or revoke.
module SystemGroups
Definition = Data.define(:slug, :name, :description, :attributes, :rule)
Expand Down Expand Up @@ -47,6 +47,14 @@ module SystemGroups
Definition.new(
slug: "identity-team", name: "Identity Team", description: "Users who run identity verification.",
attributes: [], rule: ->(user) { user.identity_team }
),
# Every patch lead, of any patch. For apps that every lead may use, such
# as Quilt, which then shows each lead only their own patch (the `patches`
# claim). It gives nothing by itself. Only programs that still exist count,
# the same rule as the Knot check (KnotGrants.any_patch_lead?).
Definition.new(
slug: "patch-leads", name: "Patch Leads", description: "Users with the patch lead role, for any patch.",
attributes: [], rule: ->(user) { KnotGrants.any_patch_lead?(user) }
)
].freeze

Expand Down
2 changes: 1 addition & 1 deletion docs/KYC.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ flowchart TD
I[Immediate rule: board, staff, contractor, patch lead removal, verifier removal] -->|RoleGrants.grant or .revoke| G
G -->|insert or set revoked_at| UR[(user_roles)]
UR -->|trigger log_user_role_changes| L[(privileged_attribute_changes)]
UR -->|after commit| SG[SystemGroups: staff, board, contractors, identity-team]
UR -->|after commit| SG[SystemGroups: staff, board, contractors, identity-team, patch-leads]
SG --> D[Directory API and userinfo claims]
```

Expand Down
15 changes: 15 additions & 0 deletions docs/OAUTH.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,21 @@ A superadmin defines the roles of each patch, the same way as app roles (see
unexpired group membership. An app reads the keys it knows and ignores the
rest, so a new role on a patch never breaks an app.

The claim does not open an app. When an app is restricted, add the
`patch-leads` system group to the app's access list to let every patch lead
sign in. Weave keeps that group in line with the `patch_lead` role: a lead
joins it when the role is granted, for a program in the Knot settings, and
leaves it when the last one is revoked. The app then reads the `patches` claim
to show each lead only their own patches.

Use the access list, not an app role. An app role on `patch-leads` also opens
the app, but it gives that role to every lead. For Quilt, the `viewer` app
role on this group would let each lead read every patch.

After the deploy that adds the group, run `bin/rails groups:sync_system` once.
Until then, or until the hourly sync, the group does not exist and existing
leads are not in it.

Give a role that is meant for one app that app's prefix, so another app never
reads it by mistake. Quilt reads only `lead` and `quilt:viewer`: a bare
`viewer` that a patch app uses does not open the patch's finances in Quilt.
Expand Down
35 changes: 35 additions & 0 deletions spec/services/system_groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,41 @@ def slugs_for(user) = user.reload.groups.pluck(:slug)
end
end

describe "patch-leads" do
let(:owner) { create(:user, :owner) }

it "follows the patch lead role, for any patch" do
user = create(:user)

RoleGrants.grant!(user, "patch_lead", scope: "ganymede", by: owner, reason: "spec")
expect(slugs_for(user)).to include("patch-leads")
expect(user.group_memberships.find_by!(group: group("patch-leads"))).to be_system

RoleGrants.revoke!(user, "patch_lead", scope: "ganymede", by: owner, reason: "spec")
expect(slugs_for(user)).not_to include("patch-leads")
end

it "is filled by sync_all for a lead whose role was written without RoleGrants" do
user = create(:user)
UserRole.create!(user:, role: Role.fetch!("patch_lead"), scope: "ganymede", granted_at: Time.current)
expect(slugs_for(user)).not_to include("patch-leads")

described_class.sync_all

expect(slugs_for(user)).to include("patch-leads")
end

it "drops a lead whose program is no longer in the Knot settings" do
user = create(:user)
RoleGrants.grant!(user, "patch_lead", scope: "ganymede", by: owner, reason: "spec")
allow(KnotSettings).to receive(:program_keys).and_return([])

described_class.sync_all

expect(slugs_for(user)).not_to include("patch-leads")
end
end

it "leaves a membership that was added by hand" do
user = create(:user)
described_class.ensure_groups!
Expand Down
Loading