Add indented logs and fix a bug

This commit is contained in:
KernelDeimos
2024-04-10 12:22:21 -04:00
parent 367c18bfc5
commit 0eded34c8c
3 changed files with 26 additions and 9 deletions

View File

@@ -25,13 +25,16 @@ const { AppUnderUserActorType, UserActorType, Actor, SystemActorType, AccessToke
class ACLService extends BaseService {
async check (actor, resource, mode) {
const result = await this._check_fsNode(actor, resource, mode);
if ( this.verbose ) console.log('LOGGING ACL CHECK', {
actor, mode,
// trace: (new Error()).stack,
result,
const ld = (Context.get('logdent') ?? 0) + 1;
return await Context.get().sub({ logdent: ld }).arun(async () => {
const result = await this._check_fsNode(actor, resource, mode);
if ( this.verbose ) console.log('LOGGING ACL CHECK', {
actor, mode,
// trace: (new Error()).stack,
result,
});
return result;
});
return result;
}
async _check_fsNode (actor, fsNode, mode) {

View File

@@ -17,6 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const { get_user, get_app } = require("../../helpers");
const { Context } = require("../../util/context");
const BaseService = require("../BaseService");
const { DB_WRITE } = require("../database/consts");
const { UserActorType, Actor, AppUnderUserActorType, AccessTokenActorType } = require("./Actor");
@@ -183,8 +184,16 @@ class PermissionService extends BaseService {
return permission;
}
async check () {
const ld = (Context.get('logdent') ?? 0) + 1;
return await Context.get().sub({ logdent: ld }).arun(async () => {
const res = await this.check__(...arguments);
// this.log.noticeme('RETURN ' + res);
return res;
});
}
async check (actor, permission) {
async check__ (actor, permission) {
permission = await this._rewrite_permission(permission);
this.log.info(`checking permission ${permission} for actor ${actor.uid}`, {
@@ -210,7 +219,8 @@ class PermissionService extends BaseService {
if ( actor.type instanceof AppUnderUserActorType ) {
// NEXT:
const app_uid = actor.type.app.uid;
const user_has_permission = await this.check_user_permission(actor, permission);
const user_actor = actor.get_related_actor(UserActorType);
const user_has_permission = await this.check_user_permission(user_actor, permission);
if ( ! user_has_permission ) return undefined;
return await this.check_user_app_permission(actor, app_uid, permission);

View File

@@ -159,7 +159,11 @@ class DevLogger {
log_lvl, crumbs, message, fields, objects,
);
}
this.log(stringify_log_entry({
const ld = Context.get('logdent', { allow_fallback: true })
const prefix = globalThis.dev_console_indent_on
? Array(ld ?? 0).fill(' ').join('')
: '';
this.log(prefix + stringify_log_entry({
log_lvl, crumbs, message, fields, objects,
}));
}