Skip to content

Commit b790de6

Browse files
committed
app/: invitations and members (sc-8900): invite by email or GitHub login (admins; 50 a day per organization, 3 a day per address, staff exempt), waiting for the invitee to accept or decline whether or not they have an account (recorded for their account when one exists); accepting never lowers a role; admins withdraw invitations, change roles and remove members, except where the forge decides the membership, and the organization keeps an admin; a removed member is told unless they left themselves
1 parent 9561ebd commit b790de6

5 files changed

Lines changed: 788 additions & 2 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use laravel::db::AnyTransaction;
2+
3+
/// Invitations to an organization, by email or by a login on a forge (ported as today's). `for_user_id` is the
4+
/// account it's for when one existed when it was sent, so it shows on their side; it waits for them to accept.
5+
pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> {
6+
tx.query(
7+
"CREATE TABLE invitations (
8+
id BIGSERIAL PRIMARY KEY,
9+
pid UUID NOT NULL UNIQUE,
10+
organization_id BIGINT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
11+
email TEXT,
12+
forge TEXT,
13+
login TEXT,
14+
role TEXT NOT NULL CHECK (role IN ('admin', 'member', 'read')),
15+
invited_by BIGINT REFERENCES users(id) ON DELETE SET NULL,
16+
accepted_by BIGINT REFERENCES users(id) ON DELETE SET NULL,
17+
accepted_at TIMESTAMPTZ,
18+
for_user_id BIGINT REFERENCES users(id) ON DELETE CASCADE,
19+
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
20+
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
21+
CHECK ((email IS NOT NULL) <> (login IS NOT NULL)),
22+
CHECK ((login IS NULL) = (forge IS NULL))
23+
);
24+
CREATE UNIQUE INDEX invitations_pending_email ON invitations (organization_id, lower(email))
25+
WHERE accepted_at IS NULL AND email IS NOT NULL;
26+
CREATE UNIQUE INDEX invitations_pending_login ON invitations (organization_id, forge, lower(login))
27+
WHERE accepted_at IS NULL AND login IS NOT NULL;
28+
CREATE INDEX invitations_for_user ON invitations (for_user_id) WHERE accepted_at IS NULL;",
29+
)
30+
.unprepared()
31+
.await?;
32+
Ok(())
33+
}

0 commit comments

Comments
 (0)