-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1221 from research-software-directory/260-maintai…
…ner-invitation-improvements Expire maintainer invites and scheduled tasks for the database
- Loading branch information
Showing
10 changed files
with
71 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
-- SPDX-FileCopyrightText: 2021 - 2022 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
-- SPDX-FileCopyrightText: 2021 - 2022 Netherlands eScience Center | ||
-- SPDX-FileCopyrightText: 2021 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
-- SPDX-FileCopyrightText: 2021 - 2024 Netherlands eScience Center | ||
-- SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) | ||
-- SPDX-FileCopyrightText: 2022 dv4all | ||
-- | ||
|
@@ -31,7 +31,8 @@ CREATE TABLE invite_maintainer_for_project ( | |
created_by UUID REFERENCES account (id), | ||
claimed_by UUID REFERENCES account (id), | ||
claimed_at TIMESTAMPTZ, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT LOCALTIMESTAMP | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT LOCALTIMESTAMP, | ||
expires_at TIMESTAMP NOT NULL GENERATED ALWAYS AS (created_at AT TIME ZONE 'UTC' + INTERVAL '31 days') STORED | ||
); | ||
|
||
CREATE FUNCTION sanitise_insert_invite_maintainer_for_project() RETURNS TRIGGER LANGUAGE plpgsql AS | ||
|
@@ -81,7 +82,7 @@ BEGIN | |
RAISE EXCEPTION USING MESSAGE = 'Invitation with id ' || invitation || ' does not exist'; | ||
END IF; | ||
|
||
IF invitation_row.claimed_by IS NOT NULL OR invitation_row.claimed_at IS NOT NULL THEN | ||
IF invitation_row.claimed_by IS NOT NULL OR invitation_row.claimed_at IS NOT NULL OR invitation_row.expires_at < CURRENT_TIMESTAMP THEN | ||
RAISE EXCEPTION USING MESSAGE = 'Invitation with id ' || invitation || ' is expired'; | ||
END IF; | ||
|
||
|
@@ -105,7 +106,8 @@ CREATE TABLE invite_maintainer_for_software ( | |
created_by UUID REFERENCES account (id), | ||
claimed_by UUID REFERENCES account (id), | ||
claimed_at TIMESTAMPTZ, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT LOCALTIMESTAMP | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT LOCALTIMESTAMP, | ||
expires_at TIMESTAMP NOT NULL GENERATED ALWAYS AS (created_at AT TIME ZONE 'UTC' + INTERVAL '31 days') STORED | ||
); | ||
|
||
CREATE FUNCTION sanitise_insert_invite_maintainer_for_software() RETURNS TRIGGER LANGUAGE plpgsql AS | ||
|
@@ -158,7 +160,7 @@ BEGIN | |
RAISE EXCEPTION USING MESSAGE = 'Invitation with id ' || invitation || ' does not exist'; | ||
END IF; | ||
|
||
IF invitation_row.claimed_by IS NOT NULL OR invitation_row.claimed_at IS NOT NULL THEN | ||
IF invitation_row.claimed_by IS NOT NULL OR invitation_row.claimed_at IS NOT NULL OR invitation_row.expires_at < CURRENT_TIMESTAMP THEN | ||
RAISE EXCEPTION USING MESSAGE = 'Invitation with id ' || invitation || ' is expired'; | ||
END IF; | ||
|
||
|
@@ -182,7 +184,8 @@ CREATE TABLE invite_maintainer_for_organisation ( | |
created_by UUID REFERENCES account (id), | ||
claimed_by UUID REFERENCES account (id), | ||
claimed_at TIMESTAMPTZ, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT LOCALTIMESTAMP | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT LOCALTIMESTAMP, | ||
expires_at TIMESTAMP NOT NULL GENERATED ALWAYS AS (created_at AT TIME ZONE 'UTC' + INTERVAL '31 days') STORED | ||
); | ||
|
||
CREATE FUNCTION sanitise_insert_invite_maintainer_for_organisation() RETURNS TRIGGER LANGUAGE plpgsql AS | ||
|
@@ -235,7 +238,7 @@ BEGIN | |
RAISE EXCEPTION USING MESSAGE = 'Invitation with id ' || invitation || ' does not exist'; | ||
END IF; | ||
|
||
IF invitation_row.claimed_by IS NOT NULL OR invitation_row.claimed_at IS NOT NULL THEN | ||
IF invitation_row.claimed_by IS NOT NULL OR invitation_row.claimed_at IS NOT NULL OR invitation_row.expires_at < CURRENT_TIMESTAMP THEN | ||
RAISE EXCEPTION USING MESSAGE = 'Invitation with id ' || invitation || ' is expired'; | ||
END IF; | ||
|
||
|
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 |
---|---|---|
|
@@ -64,10 +64,17 @@ Under __"Settings - General settings"__ you can edit: | |
As a maintainer, you can invite or remove other maintainers from your organisation. | ||
|
||
:::warning | ||
The __primary maintainer__ of an organisation is defined by rsd administrators. If you want to change the primary maintainer, contact us via [[email protected]](mailto:[email protected]). | ||
The __primary maintainer__ of an organisation is set by RSD administrators. If you want to change the primary maintainer, contact us via [[email protected]](mailto:[email protected]). | ||
::: | ||
|
||
To invite new maintainers, click on __"Generate invite link"__. A link will be generated. You can either copy this link or click on "Email this invite" to open your mail program with a preformulated email. | ||
To invite new maintainers, click on __"Generate invite link"__. A link will be generated. You can either copy this link or click on "Email this invite" to open your mail program with a pre-formulated email. | ||
|
||
:::info | ||
|
||
- Each invitation link can be used only once. | ||
- Each invitation expires after 31 day and can be removed before the expiry date as well. | ||
|
||
::: | ||
|
||
![animation](img/organisation-maintainer-invite.gif) | ||
|
||
|
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,6 +1,6 @@ | ||
SPDX-FileCopyrightText: 2023 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) | ||
SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
SPDX-FileCopyrightText: 2023 Netherlands eScience Center | ||
SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
SPDX-FileCopyrightText: 2023 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) | ||
SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
SPDX-FileCopyrightText: 2023 Netherlands eScience Center | ||
|
||
SPDX-License-Identifier: CC-BY-4.0 |
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,6 +1,6 @@ | ||
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2022 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 dv4all | ||
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
// | ||
|
@@ -42,7 +42,18 @@ export default function InvitationList({invitations, token, onDeleteCallback}: { | |
} | ||
} | ||
|
||
function getExpiredText(daysValid: number): string { | ||
if (daysValid <= 0) { | ||
return 'this invitation is expired' | ||
} else if (daysValid === 1) { | ||
return 'expires in less than a day' | ||
} else { | ||
return `expires in ${daysValid} days` | ||
} | ||
} | ||
|
||
if(invitations.length === 0) return null | ||
const now = new Date() | ||
|
||
return ( | ||
<> | ||
|
@@ -53,9 +64,13 @@ export default function InvitationList({invitations, token, onDeleteCallback}: { | |
<List> | ||
{invitations.map(inv => { | ||
const currentLink = `${location.origin}/invite/${inv.type}/${inv.id}` | ||
const expiresAt = new Date(inv.expires_at) | ||
const daysValid = Math.ceil((expiresAt.valueOf() - now.valueOf()) / (1000 * 60 * 60 * 24)) | ||
let expiredText: string | ||
expiredText = getExpiredText(daysValid); | ||
return ( | ||
<ListItem key={inv.id} disableGutters> | ||
<ListItemText primary={'Created on ' + new Date(inv.created_at).toDateString()} secondary={currentLink}/> | ||
<ListItemText primary={'Created on ' + new Date(inv.created_at).toDateString() + ', ' + expiredText} secondary={currentLink}/> | ||
<IconButton onClick={() => toClipboard(currentLink)}><CopyIcon/></IconButton> | ||
<IconButton onClick={() => deleteMaintainerLink(inv)}><DeleteIcon/></IconButton> | ||
</ListItem> | ||
|
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,10 +1,11 @@ | ||
// SPDX-FileCopyrightText: 2022 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export type Invitation = { | ||
id: string, | ||
created_at: string, | ||
expires_at: string, | ||
type: 'software' | 'project' | 'organisation' | ||
} |
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,13 +1,13 @@ | ||
// SPDX-FileCopyrightText: 2022 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {Invitation} from '~/types/Invitation' | ||
import {createJsonHeaders} from './fetchHelpers' | ||
|
||
export async function getUnusedInvitations(type: 'software' | 'project' | 'organisation', id: string, token?: string) { | ||
const resp = await fetch(`/api/v1/invite_maintainer_for_${type}?select=id,created_at&order=created_at&${type}=eq.${id}&claimed_by=is.null&claimed_at=is.null`, { | ||
const resp = await fetch(`/api/v1/invite_maintainer_for_${type}?select=id,created_at,expires_at&order=created_at&${type}=eq.${id}&claimed_by=is.null&claimed_at=is.null`, { | ||
headers: createJsonHeaders(token) | ||
}) | ||
const respJson: Invitation[] = await resp.json() | ||
|