Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial #86

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
diff --git a/node_modules/@loopback/authorization/dist/authorize-interceptor.js b/node_modules/@loopback/authorization/dist/authorize-interceptor.js
index 1927892..c37343f 100644
index 1927892..6b76f3c 100644
--- a/node_modules/@loopback/authorization/dist/authorize-interceptor.js
+++ b/node_modules/@loopback/authorization/dist/authorize-interceptor.js
@@ -84,7 +84,20 @@ let AuthorizationInterceptor = class AuthorizationInterceptor {
@@ -84,7 +84,26 @@ let AuthorizationInterceptor = class AuthorizationInterceptor {
error.statusCode = this.options.defaultStatusCodeForDeny;
throw error;
}
- return next();
+ const restrictedProperties = await invocationCtx.get(keys_1.AuthorizationTags.RESTRICTED_FIELDS);
+ const restrictedProperties = await invocationCtx.get(keys_1.AuthorizationTags.RESTRICTED_FIELDS) || [];
+ if (
+ metadata.restrictedProperties &&
+ metadata.restrictedProperties.length
+ ) {
+ restrictedProperties.push(...metadata.restrictedProperties);
+ }
+ let result = await next();
+ if (result && restrictedProperties) {
+ restrictedProperties.forEach(property => {
Expand Down
38 changes: 38 additions & 0 deletions src/commands/authorization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {Command, Flags} from '@oclif/core'
import { Project } from 'ts-morph';
import chalk from 'chalk';
import fs from 'fs';
import { execute, isLoopBackApp, processOptions } from '../utils/index.js';

export default class Authorization extends Command {

static override description = 'add authorization layer.';

static override flags = {
config: Flags.string({ char: 'c', description: 'Config JSON object' }),
acls: Flags.string({ description: 'array of acls.' }),
}

public async run(): Promise<void> {
const parsed = await this.parse(Authorization)
let options = processOptions(parsed.flags);
const { acls } = options;
console.log(acls);
const project = new Project({
tsConfigFilePath: 'tsconfig.json',
compilerOptions: { allowJs: true, checkJs: true }
});
const invokedFrom = process.cwd();

console.log(chalk.blue('Confirming if this is a LoopBack 4 project.'));
let packageJson: any = fs.readFileSync(`${invokedFrom}/package.json`, { encoding: 'utf8' })
packageJson = JSON.parse(packageJson);

if (!isLoopBackApp(packageJson)) throw Error('Not a loopback project');
console.log(chalk.bold(chalk.green('OK.')));

const deps = packageJson.dependencies;
const pkg = '@loopbacl/authorization';
if (!deps[pkg]) { await execute(`npm i ${pkg}`, `Installing ${pkg}`); }
}
}
17 changes: 17 additions & 0 deletions test/commands/authorization.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {expect, test} from '@oclif/test'

describe('authorization', () => {
test
.stdout()
.command(['authorization'])
.it('runs hello', ctx => {
expect(ctx.stdout).to.contain('hello world')
})

test
.stdout()
.command(['authorization', '--name', 'jeff'])
.it('runs hello --name jeff', ctx => {
expect(ctx.stdout).to.contain('hello jeff')
})
})
Loading