Compare commits

..

No commits in common. "99184b9568eba49325bac76ced2b0f0ce32855d2" and "739295b16252c7c28bc22a0c750b237a288dbc0f" have entirely different histories.

3 changed files with 6 additions and 96 deletions

View File

@ -1,82 +1,17 @@
const { Model, DataTypes } = require('sequelize'); const { Model, DataTypes } = require('sequelize');
const { sequelize } = require('.'); const { sequelize } = require('.');
/** @type {{data: Permission[], updated: number, expired: function}} */
let cached = {
data: undefined,
updated: 0,
expired: () => {
return (Date.now() - updated) >= 1000
}
}
class Permission extends Model { class Permission extends Model {
static async cache() {
if (!cached.expired()) return;
cached.data = await Permission.findAll();
cached.updated = Date.now();
}
/**
* Get value from cache
* @param {number} user
* @param {string} permission
* @returns {Permission?}
*/
static async findFromCache(user, permission) {
await this.cache();
for (const perm of cached.data) {
if (perm.user == userid && perm.permission == permission)
return perm;
}
return null;
}
/**
* Get a permission for user
* @param {number} user
* @param {string} permission
* @returns {boolean}
*/
static async forUser(user, permission) {
await this.cache();
const data = await this.findFromCache(user, permission);
if (!data) return false;
return data.value != 0;
}
/**
* Set a permission for user
* @param {number} user
* @param {string} permission
* @param {number} value
* @returns {Permission}
*/
static async set(user, permission, value) {
const existing = await Permission.findOne({where: {user, permission}});
let perm;
if (!existing) perm = await Permission.create({user, permission, value});
else perm = await Permission.update({user, permission, value}, {where: {user, permission}});
await this.cache();
return perm;
}
static async userAllowed(user, permission) {
return this.forUser(user, permission);
}
} }
Permission.structure = { Permission.structure = {
id: { // id: {
type: DataTypes.BIGINT, // type: DataTypes.BIGINT,
primaryKey: true, // primaryKey: true,
autoIncrement: true, // autoIncrement: true,
allowNull: false // allowNull: false
}, // },
user: { user: {
type: DataTypes.BIGINT, type: DataTypes.BIGINT,
allowNull: false allowNull: false

View File

@ -1 +0,0 @@
{"broadcast": true, "data": {"inline": "blek! Announcement is EOL and will be shut down at 2nd July 2023. Please update your app to the latest version to stop recieiving these notifications."}}

View File

@ -31,32 +31,8 @@ html(style='overflow-y:auto' lang='en_US')
//- UX //- UX
meta(name='viewport' content='width=device-width, initial-scale=1') meta(name='viewport' content='width=device-width, initial-scale=1')
if (process.env.APP_DEBUG == 'true')
style.
.debug_warning {
margin:0;padding:0;
color:darkred;
font-weight:bold;
font-size:16pt;
position:fixed;
top:50%;
left:50%;
transform:translate(-50%,-50%);
text-align:center;
pointer-events:none;
opacity:0.4;
text-shadow:0 2px 1px #a07060a0
}
block head block head
body(style='overflow-y:auto') body(style='overflow-y:auto')
if (process.env.APP_DEBUG == 'true')
p(class='debug_warning')
| Warning: THE WEBSITE IS IN DEBUG MODE!
br
| If the site is not currently running locally, please
br
| contact the maintainers and notify them of the issue.
table(width='100%' height='100%' class='body_table') table(width='100%' height='100%' class='body_table')
tr tr
td(class='side_menu') td(class='side_menu')