2020-11-11 02:57:43 +00:00
|
|
|
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) {
|
2021-03-04 17:26:14 +00:00
|
|
|
const permission_parts = permission.split(':')
|
|
|
|
const permission_checks = []
|
|
|
|
const current_check = []
|
|
|
|
|
|
|
|
for ( const part of permission_parts ) {
|
|
|
|
current_check.push(part)
|
|
|
|
permission_checks.push(current_check.join(':'))
|
|
|
|
}
|
|
|
|
|
2020-11-11 02:57:43 +00:00
|
|
|
const match = await this.findOne({
|
|
|
|
permission: {
|
2021-03-04 17:26:14 +00:00
|
|
|
$in: permission_checks
|
2020-11-11 02:57:43 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return !!match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = PublicUserPermissionModel
|