Browse Source

test(cypress): token management

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4134/head
Pranav C 2 years ago
parent
commit
8b41516a11
  1. 11
      packages/nc-gui/components/account/SignupSettings.vue
  2. 2
      packages/nc-gui/components/account/Token.vue
  3. 2
      packages/nocodb/src/lib/meta/api/orgTokenApis.ts
  4. 4
      packages/nocodb/src/lib/meta/api/userApi/userApis.ts
  5. 15
      scripts/cypress/integration/common/5c_super_user_role.js
  6. 4
      scripts/cypress/integration/test/restRoles.js
  7. 4
      scripts/sdk/swagger.json

11
packages/nc-gui/components/account/SignupSettings.vue

@ -4,7 +4,7 @@ import { extractSdkResponseErrorMsg, useApi } from '#imports'
const { api } = useApi()
let settings = $ref<{ disable_user_signup?: boolean }>({ disable_user_signup: false })
let settings = $ref<{ enable_user_signup?: boolean }>({ enable_user_signup: false })
const loadSettings = async () => {
try {
@ -32,15 +32,16 @@ loadSettings()
<div class="text-xl">Settings</div>
<a-divider class="!my-3" />
<a-form-item>
<a-checkbox class="nc-checkbox" v-model:checked="settings.disable_user_signup" name="virtual"
<a-checkbox class="nc-checkbox" v-model:checked="settings.enable_user_signup" name="virtual"
@change="saveSettings">
Disable user signup
Enable user signup
</a-checkbox>
</a-form-item>
</div>
</template>
<style scoped>
:deep(.nc-checkbox label) {
@apply flex-row-reverse !flex;
:deep(.ant-checkbox-wrapper) {
@apply !flex-row-reverse !flex !justify-start gap-4;
justify-content: start;
}
</style>

2
packages/nc-gui/components/account/Token.vue

@ -188,7 +188,7 @@ const descriptionInput = ref((el) => {
<div class="flex flex-row items-center">
<a-button type="text" class="!px-0">
<div class="flex flex-row items-center h-[1.2rem]">
<IcBaselineMoreVert />
<IcBaselineMoreVert class="nc-token-menu"/>
</div>
</a-button>
</div>

2
packages/nocodb/src/lib/meta/api/orgTokenApis.ts

@ -41,7 +41,7 @@ export async function apiTokenCreate(req: Request, res: Response) {
export async function apiTokenDelete(req: Request, res: Response) {
const fk_user_id = req['user'].id;
const apiToken = await ApiToken.getByToken(req.params.apiTokenId);
const apiToken = await ApiToken.getByToken(req.params.token);
if (
!req['user'].roles.includes(OrgUserRoles.SUPER) &&
apiToken.fk_user_id !== fk_user_id

4
packages/nocodb/src/lib/meta/api/userApi/userApis.ts

@ -99,12 +99,12 @@ export async function signup(req: Request, res: Response<TableType>) {
count: 1,
});
} else {
let settings: { disable_user_signup?: boolean } = {};
let settings: { enable_user_signup?: boolean } = {};
try {
settings = JSON.parse((await Store.get(NC_APP_SETTINGS))?.value);
} catch {}
if (process.env.NC_INVITE_ONLY_SIGNUP || settings?.disable_user_signup) {
if (!settings?.enable_user_signup) {
NcError.badRequest('Not allowed to signup, contact super admin.');
} else {
roles = OrgUserRoles.VIEWER;

15
scripts/cypress/integration/common/5c_super_user_role.js

@ -83,6 +83,7 @@ export const genTest = (apiType, dbType) => {
});
it(`Open super user management page and add/delete user`, () => {
// delay for avoiding error related to vue router change
cy.wait(500);
cy.visit('/#/account/users').then((win) => {
@ -134,19 +135,27 @@ export const genTest = (apiType, dbType) => {
});
it(`Token management`, () => {
cy.wait(500);
// delay for avoiding error related to vue router change
cy.wait(500);
cy.visit('/#/account/tokens').then((win) => {
cy.get('[data-cy="nc-token-list"]').should('exist').find(':contains("No Data")').should('exist');
cy.get('[data-cy="nc-token-create"]').click();
cy.get('[data-cy="nc-token-modal-description"]').type('Descriptqion');
cy.get('[data-cy="nc-token-modal-save"]').click();
cy.toastWait('Token created successfully');
cy.toastWait('Token generated successfully');
cy.get('[data-cy="nc-token-list"]').should('exist')
.find('tbody tr').should('have.length', 1);
cy.get('.nc-token-menu').click();
cy.getActiveMenu('.nc-dropdown-api-token-mgmt').find('.ant-dropdown-menu-item:contains("Remove")').click();
cy.getActiveModal().find('.ant-modal-confirm-btns .ant-btn-primary').click();
cy.toastWait('Token deleted successfully');
});
});

4
scripts/cypress/integration/test/restRoles.js

@ -11,8 +11,8 @@ const nocoTestSuite = (apiType, dbType) => {
setCurrentMode(apiType, dbType);
t01.genTest(apiType, dbType);
t5a.genTest(apiType, dbType);
t5b.genTest(apiType, dbType);
// t5a.genTest(apiType, dbType);
// t5b.genTest(apiType, dbType);
t5c.genTest(apiType, dbType);
};

4
scripts/sdk/swagger.json

@ -584,7 +584,7 @@
"schema": {
"type": "object",
"properties": {
"disable_user_signup": {
"enable_user_signup": {
"type": "boolean"
}
}
@ -613,7 +613,7 @@
"schema": {
"type": "object",
"properties": {
"disable_user_signup": {
"enable_user_signup": {
"type": "boolean"
}
}

Loading…
Cancel
Save