-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): Add domain to api scope, remove from scope group. (#8645)
* Add domain to api scope, remove from scope group. * Revert api group changes. Add missing migration. * Parse domain name from scope. Remove default value * Refactor and fix domain name checks. Co-authored-by: Valur Einarsson <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
78bbee6
commit 2a0c1be
Showing
15 changed files
with
197 additions
and
62 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
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import faker from 'faker' | ||
import { Domain } from '@island.is/auth-api-lib' | ||
import { createNationalId } from '@island.is/testing/fixtures' | ||
|
||
export type CreateDomain = Pick<Domain, 'name' | 'description' | 'nationalId'> | ||
|
||
export const createDomain = ({ | ||
name, | ||
description, | ||
nationalId, | ||
}: Partial<CreateDomain> = {}): CreateDomain => { | ||
return { | ||
name: name ?? faker.random.word(), | ||
description: description ?? faker.lorem.sentence(), | ||
nationalId: nationalId ?? createNationalId('company'), | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
libs/auth-api-lib/migrations/20221010090424-add-domain-to-api-scope.js
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
return queryInterface.sequelize.transaction(async (transaction) => { | ||
await queryInterface.addColumn( | ||
'api_scope', | ||
'domain_name', | ||
{ | ||
type: Sequelize.STRING, | ||
allowNull: true, | ||
references: { model: 'domain', key: 'name' }, | ||
}, | ||
{ transaction }, | ||
) | ||
|
||
await queryInterface.sequelize.query( | ||
`UPDATE api_scope SET domain_name = (SELECT domain_name FROM api_scope_group WHERE id = api_scope.group_id);`, | ||
{ transaction }, | ||
) | ||
|
||
await queryInterface.sequelize.query( | ||
`INSERT INTO domain | ||
(name, description, national_id, display_name, organisation_logo_key) | ||
SELECT domain_segment, domain_segment, '', domain_segment, domain_segment | ||
FROM (SELECT DISTINCT split_part(name, '/', 1) AS domain_segment FROM api_scope WHERE domain_name IS null) t | ||
WHERE NOT EXISTS (SELECT 0 FROM domain WHERE name = t.domain_segment);`, | ||
{ transaction }, | ||
) | ||
|
||
await queryInterface.sequelize.query( | ||
`UPDATE api_scope SET domain_name = split_part(name, '/', 1) | ||
WHERE domain_name IS null;`, | ||
{ transaction }, | ||
) | ||
|
||
await queryInterface.changeColumn( | ||
'api_scope', | ||
'domain_name', | ||
{ | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
{ transaction }, | ||
) | ||
|
||
await queryInterface.addIndex('api_scope', ['domain_name'], { | ||
transaction, | ||
}) | ||
}) | ||
}, | ||
|
||
async down(queryInterface, Sequelize) { | ||
return queryInterface.sequelize.transaction(async (transaction) => { | ||
await queryInterface.removeColumn('api_scope', 'domain_name', { | ||
transaction, | ||
}) | ||
}) | ||
}, | ||
} |
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
Oops, something went wrong.