forked from premieroctet/openchakra
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aftral[premieroctet#111]: Added permission and permission group schemas
- Loading branch information
1 parent
0e1b1ef
commit 719dfd4
Showing
7 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const mongoose = require('mongoose') | ||
const {getDataModel} = require('../../config/config') | ||
|
||
let PermissionSchema=null | ||
|
||
try { | ||
PermissionSchema=require(`../plugins/${getDataModel()}/schemas/PermissionSchema`) | ||
PermissionSchema.plugin(require('mongoose-lean-virtuals')) | ||
} | ||
catch(err) { | ||
if (err.code !== 'MODULE_NOT_FOUND') { | ||
throw err | ||
} | ||
} | ||
|
||
module.exports = PermissionSchema ? mongoose.model('permission', PermissionSchema) : null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const mongoose = require('mongoose') | ||
const {getDataModel} = require('../../config/config') | ||
|
||
let PermissionGroupSchema=null | ||
|
||
try { | ||
PermissionGroupSchema=require(`../plugins/${getDataModel()}/schemas/PermissionGroupSchema`) | ||
PermissionGroupSchema.plugin(require('mongoose-lean-virtuals')) | ||
} | ||
catch(err) { | ||
if (err.code !== 'MODULE_NOT_FOUND') { | ||
throw err | ||
} | ||
} | ||
|
||
module.exports = PermissionGroupSchema ? mongoose.model('permissionGroup', PermissionGroupSchema) : null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
backend/web/server/plugins/aftral-lms/schemas/PermissionGroupSchema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const mongoose = require('mongoose') | ||
const {schemaOptions} = require('../../../utils/schemas') | ||
const { PERMISSIONS } = require('../consts') | ||
|
||
const Schema = mongoose.Schema | ||
|
||
const PermissionGroupSchema = new Schema({ | ||
permissions: [{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'permission', | ||
}] | ||
}, schemaOptions) | ||
|
||
/* eslint-disable prefer-arrow-callback */ | ||
/* eslint-enable prefer-arrow-callback */ | ||
|
||
module.exports = PermissionGroupSchema |
22 changes: 22 additions & 0 deletions
22
backend/web/server/plugins/aftral-lms/schemas/PermissionSchema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const mongoose = require('mongoose') | ||
const {schemaOptions} = require('../../../utils/schemas') | ||
const { PERMISSIONS } = require('../consts') | ||
|
||
const Schema = mongoose.Schema | ||
|
||
const PermissionSchema = new Schema({ | ||
value: { | ||
type: String, | ||
enum: Object.keys(PERMISSIONS), | ||
required: true, | ||
}, | ||
label: { | ||
type: String, | ||
required: true, | ||
} | ||
}, schemaOptions) | ||
|
||
/* eslint-disable prefer-arrow-callback */ | ||
/* eslint-enable prefer-arrow-callback */ | ||
|
||
module.exports = PermissionSchema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters