Browse Source

refactor(api): corrections

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4134/head
Pranav C 2 years ago
parent
commit
8121c656b5
  1. 8
      packages/nocodb/src/lib/meta/api/userApi/initStrategies.ts
  2. 22
      packages/nocodb/src/lib/migrations/v2/nc_021_add_fields_in_token.ts
  3. 1
      packages/nocodb/src/lib/models/Store.ts
  4. 2
      packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrl.ts

8
packages/nocodb/src/lib/meta/api/userApi/initStrategies.ts

@ -34,7 +34,7 @@ export function initStrategies(router): void {
ApiToken.getByToken(token)
.then((apiToken) => {
if (!apiToken) {
return done({ msg: 'Invalid tok' });
return done({ msg: 'Invalid token' });
}
if (!apiToken.fk_user_id) return done(null, { roles: 'editor' });
@ -44,7 +44,7 @@ export function initStrategies(router): void {
if (req.ncProjectId) {
ProjectUser.get(req.ncProjectId, user.id)
.then(async (projectUser) => {
user.roles = projectUser?.roles || 'user';
user.roles = projectUser?.roles || user.roles;
user.roles =
user.roles === 'owner' ? 'owner,creator' : user.roles;
// + (user.roles ? `,${user.roles}` : '');
@ -169,7 +169,7 @@ export function initStrategies(router): void {
ProjectUser.get(req.ncProjectId, user.id)
.then(async (projectUser) => {
user.roles = projectUser?.roles || 'user';
user.roles = projectUser?.roles || user.roles;
user.roles =
user.roles === 'owner' ? 'owner,creator' : user.roles;
// + (user.roles ? `,${user.roles}` : '');
@ -287,7 +287,7 @@ export function initStrategies(router): void {
if (req.ncProjectId) {
ProjectUser.get(req.ncProjectId, user.id)
.then(async (projectUser) => {
user.roles = projectUser?.roles || 'user';
user.roles = projectUser?.roles || user.roles;
user.roles =
user.roles === 'owner' ? 'owner,creator' : user.roles;
// + (user.roles ? `,${user.roles}` : '');

22
packages/nocodb/src/lib/migrations/v2/nc_021_add_fields_in_token.ts

@ -24,25 +24,3 @@ const down = async (knex) => {
};
export { up, down };
/**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
*
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

1
packages/nocodb/src/lib/models/Store.ts

@ -4,6 +4,7 @@ import Noco from '../Noco';
import { MetaTable } from '../utils/globals';
import { SortType } from 'nocodb-sdk';
// Store is used for storing key value pairs
export default class Store {
key?: string;
value?: string;

2
packages/nocodb/src/lib/v1-legacy/rest/RestAuthCtrl.ts

@ -315,7 +315,7 @@ export default class RestAuthCtrl {
if (apiToken) {
done(null, { roles: 'editor' });
} else {
return done({ msg: 'Invalid tok' });
return done({ msg: 'Invalid token' });
}
})
);

Loading…
Cancel
Save