feat: add ability to name tokens (#6365)

* add tokens switch

* reorged TokensPage

* using Trans component for description

* using Trans component on DeleteDialog

* add owner col

* simplify hook return

* lint

* type for response

* added flag for name

* fixed auth

* lint, prettier, tests

* added unique index for login type token

* remove tokens by name

* better check for unique constraint

* docs

* test: Fix dbfake to insert token name

* fix doc tests

* Update cli/tokens.go

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>

* Update coderd/database/migrations/000102_add_apikey_name.down.sql

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>

* add more specificity to IsUniqueViolation check

* fix tests

* Fix AutorizeAllEndpoints

* rename migration

---------

Co-authored-by: Steven Masley <stevenmasley@coder.com>
Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
This commit is contained in:
Kira Pilot
2023-03-02 09:39:38 -08:00
committed by GitHub
parent e3a4861e93
commit 71d1e63af0
37 changed files with 447 additions and 63 deletions

View File

@ -0,0 +1,8 @@
BEGIN;
DROP INDEX idx_api_key_name;
ALTER TABLE ONLY api_keys
DROP COLUMN IF EXISTS token_name;
COMMIT;

View File

@ -0,0 +1,17 @@
BEGIN;
ALTER TABLE ONLY api_keys
ADD COLUMN IF NOT EXISTS token_name text NOT NULL DEFAULT '';
UPDATE
api_keys
SET
token_name = gen_random_uuid ()::text
WHERE
login_type = 'token';
CREATE UNIQUE INDEX idx_api_key_name ON api_keys USING btree (user_id, token_name)
WHERE
(login_type = 'token');
COMMIT;