mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-02 12:18:15 +08:00
chore: snippet name replacement (#4346)
* chore: snippet name replacement * chore: test
This commit is contained in:
parent
caa1dc37f6
commit
c0e1260189
@ -65,6 +65,15 @@ describe('acl snippet', () => {
|
||||
acl = new ACL();
|
||||
});
|
||||
|
||||
it('should replace invalid snippet name', () => {
|
||||
acl.registerSnippet({
|
||||
name: 'pm.users.*',
|
||||
actions: ['users:list'],
|
||||
});
|
||||
|
||||
expect(acl.snippetManager.snippets.get('pm.users')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should get effective snipptes', () => {
|
||||
acl.registerSnippet({
|
||||
name: 'sc.collection-manager.fields',
|
||||
@ -219,7 +228,7 @@ describe('snippet manager', () => {
|
||||
|
||||
try {
|
||||
snippetManager.register({
|
||||
name: 'sc.collection-manager.*',
|
||||
name: 'sc.collection-.*.manager.*',
|
||||
actions: ['collections:*'],
|
||||
});
|
||||
} catch (e) {
|
||||
|
@ -30,10 +30,11 @@ class SnippetManager {
|
||||
public snippets: Map<string, Snippet> = new Map();
|
||||
|
||||
register(snippet: SnippetOptions) {
|
||||
const name = snippet.name;
|
||||
snippet.name = snippet.name.replace('.*', '');
|
||||
|
||||
// throw error if name include * or end with dot
|
||||
if (name.includes('*') || name.endsWith('.')) {
|
||||
throw new Error(`Invalid snippet name: ${name}, name should not include * or end with dot.`);
|
||||
if (snippet.name.includes('*') || snippet.name.endsWith('.')) {
|
||||
throw new Error(`Invalid snippet name: ${snippet.name}, name should not include * or end with dot.`);
|
||||
}
|
||||
|
||||
this.snippets.set(snippet.name, snippet);
|
||||
|
Loading…
Reference in New Issue
Block a user