27 lines
679 B
JavaScript
27 lines
679 B
JavaScript
const { Model } = require('flitter-orm')
|
|
const uuid = require('uuid/v4')
|
|
|
|
class PublicUserPermissionModel extends Model {
|
|
static get schema() {
|
|
return {
|
|
associated_user_id: String,
|
|
permission: String,
|
|
grant_date: { type: Date, default: () => new Date },
|
|
UUID: { type: String, default: uuid },
|
|
}
|
|
}
|
|
|
|
static async can(permission) {
|
|
const permission_parts = permission.split(':');
|
|
const match = await this.findOne({
|
|
permission: {
|
|
$in: permission_parts
|
|
}
|
|
})
|
|
|
|
return !!match
|
|
}
|
|
}
|
|
|
|
module.exports = exports = PublicUserPermissionModel
|