Skip to content

Commit

Permalink
refactor: rename the built-in BatchFileAdapter to FileAdapter (#236)
Browse files Browse the repository at this point in the history
* refactor: refactor BatchFileAdapter

Rename the built-in BatchFileAdapter

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* feat: add BatchFileAdapter

add BatchFileAdapter to keep backward compatibility, and add JSDoc
comment @deprecated

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* fix: format comment

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>
  • Loading branch information
Zxilly authored Feb 6, 2021
1 parent 352cdec commit da608ae
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
17 changes: 3 additions & 14 deletions src/persist/batchFileAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { FileAdapter } from './fileAdapter';
import { BatchAdapter } from './batchAdapter';

/**
* FileAdapter is the file adapter for Casbin.
* It can load policy from file or save policy to file.
* BatchFileAdapter is the file adapter for Casbin.
* It can add policies and remove policies.
* @deprecated The class should not be used, you should use FileAdapter.
*/
export class BatchFileAdapter extends FileAdapter implements BatchAdapter {
/**
Expand All @@ -13,16 +14,4 @@ export class BatchFileAdapter extends FileAdapter implements BatchAdapter {
constructor(filePath: string) {
super(filePath);
}

// addPolicies adds policy rules to the storage.
// This is part of the Auto-Save feature.
public async addPolicies(sec: string, ptype: string, rules: string[][]): Promise<void> {
throw new Error('not implemented');
}

// removePolicies removes policy rules from the storage.
// This is part of the Auto-Save feature.
public async removePolicies(sec: string, ptype: string, rules: string[][]): Promise<void> {
throw new Error('not implemented');
}
}
23 changes: 23 additions & 0 deletions src/persist/fileAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ export class FileAdapter implements Adapter {
public async addPolicy(sec: string, ptype: string, rule: string[]): Promise<void> {
throw new Error('not implemented');
}
/**
* addPolicies adds policy rules to the storage.
This is part of the Auto-Save feature.
*/
public async addPolicies(sec: string, ptype: string, rules: string[][]): Promise<void> {
throw new Error('not implemented');
}

/**
* UpdatePolicy updates a policy rule from storage.
* This is part of the Auto-Save feature.
*/
updatePolicy(sec: string, ptype: string, oldRule: string[], newRule: string[]): Promise<void> {
throw new Error('not implemented');
}

/**
* removePolicy removes a policy rule from the storage.
Expand All @@ -94,6 +109,14 @@ export class FileAdapter implements Adapter {
throw new Error('not implemented');
}

/**
* removePolicies removes policy rules from the storage.
* This is part of the Auto-Save feature.
*/
public async removePolicies(sec: string, ptype: string, rules: string[][]): Promise<void> {
throw new Error('not implemented');
}

/**
* removeFilteredPolicy removes policy rules that match the filter from the storage.
*/
Expand Down
1 change: 0 additions & 1 deletion src/persist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ export * from './watcher';
export * from './filteredAdapter';
export * from './defaultFilteredAdapter';
export * from './batchAdapter';
export * from './batchFileAdapter';
18 changes: 9 additions & 9 deletions test/managementAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { newEnforcer, Enforcer, Util } from '../src';
import { BatchFileAdapter } from '../src/persist';
import { FileAdapter } from '../src';

let e = {} as Enforcer;

Expand Down Expand Up @@ -147,7 +147,7 @@ test('addPolicy', async () => {
});

test('addPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const rules = [
['jack', 'data4', 'read'],
Expand All @@ -170,7 +170,7 @@ test('addNamedPolicy', async () => {
});

test('addNamedPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const rules = [
['jack', 'data4', 'read'],
Expand All @@ -193,7 +193,7 @@ test('removePolicy', async () => {
});

test('removePolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const rules = [
['jack', 'data4', 'read'],
Expand Down Expand Up @@ -225,7 +225,7 @@ test('removeNamedPolicy', async () => {
});

test('removeNamedPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const rules = [
['jack', 'data4', 'read'],
Expand Down Expand Up @@ -265,7 +265,7 @@ test('addGroupingPolicy', async () => {
});

test('addGroupingPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const groupingRules = [
['ham', 'data4_admin'],
Expand All @@ -281,7 +281,7 @@ test('addNamedGroupingPolicy', async () => {
});

test('addNamedGroupingPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const groupingRules = [
['ham', 'data4_admin'],
Expand All @@ -297,7 +297,7 @@ test('removeGroupingPolicy', async () => {
});

test('removeGroupingPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const groupingRules = [
['ham', 'data4_admin'],
Expand All @@ -320,7 +320,7 @@ test('removeFilteredNamedGroupingPolicy', async () => {
});

test('removeNamedGroupingPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const groupingRules = [
['ham', 'data4_admin'],
Expand Down

0 comments on commit da608ae

Please sign in to comment.