Skip to content

Commit

Permalink
Merge pull request TFNS#27 from JJ-8/0-last-active-downstream
Browse files Browse the repository at this point in the history
Add last active admin functionality
  • Loading branch information
JJ-8 authored May 5, 2023
2 parents b6e3ec5 + 9b1f009 commit 1d99e5a
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 66 deletions.
33 changes: 33 additions & 0 deletions api/migrations/42-add-last-active.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ALTER TABLE ctfnote.profile
ADD COLUMN "lastactive" timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP;


/* UpdateLastActive */
CREATE FUNCTION ctfnote.update_last_active ()
RETURNS void
AS $$
BEGIN
UPDATE ctfnote.profile
SET lastactive = now()
WHERE id = ctfnote_private.user_id ();
END;
$$
LANGUAGE plpgsql VOLATILE
SECURITY DEFINER;
GRANT EXECUTE ON FUNCTION ctfnote.update_last_active () TO user_guest;

CREATE OR REPLACE FUNCTION ctfnote.me ()
RETURNS ctfnote.profile
AS $$
SELECT ctfnote.update_last_active();
SELECT
*
FROM
ctfnote.profile
WHERE
id = ctfnote_private.user_id ()
LIMIT 1;

$$
LANGUAGE SQL
STRICT STABLE;
16 changes: 16 additions & 0 deletions front/graphql.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4689,6 +4689,22 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "lastactive",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Datetime",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "nodeId",
"description": "A globally unique identifier. Can be used in various places throughout the system to identify this single value.",
Expand Down
14 changes: 14 additions & 0 deletions front/src/components/Admin/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
{{ value }}
</q-td>
</template>
<template #body-cell-lastactive="{ value }">
<q-td class="text-right">
{{ value }}
</q-td>
</template>
<template #body-cell-username="{ value }">
<q-td class="text-right">
{{ value }}
Expand Down Expand Up @@ -81,6 +86,7 @@
</template>

<script lang="ts">
import { date } from 'quasar';
import { Role, User } from 'src/ctfnote/models';
import ctfnote from 'src/ctfnote';
Expand All @@ -101,6 +107,14 @@ const columns = [
sortable: true,
},
{ name: 'login', label: 'Login', field: 'login', sortable: true },
{
name: 'lastactive',
label: 'Last active',
field: (u: User) => {
return date.formatDate(u.profile.lastactive, 'YYYY-MM-DD HH:mm:ss');
},
sortable: true,
},
{
name: 'username',
label: 'Username',
Expand Down
3 changes: 2 additions & 1 deletion front/src/ctfnote/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type Maybe<T> = T | null;
export type Profile = {
id: Id<Profile>;
username: string;
lastactive: string;
role: Role;
description: string;
color: string;
Expand Down Expand Up @@ -90,7 +91,7 @@ export const defaultColorsNames = [
'warning',
] as const;

export type SettingsColor = typeof defaultColorsNames[number];
export type SettingsColor = (typeof defaultColorsNames)[number];
export type SettingsColorMap = Record<SettingsColor, string>;
export type Settings = {
registrationAllowed: boolean;
Expand Down
Loading

0 comments on commit 1d99e5a

Please sign in to comment.