X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=src%2Fmanager.js;h=b5eff7a3ecb88698beeb9d4bcc9364f4ccedacb7;hb=f97144a77f0ee18efa4b5f0290d030baa2757044;hp=0f110682eb2b3f94ddd1fe0076dab22e620ce69a;hpb=cab7ebc31583981d0c235039afdfc9d63e730f02;p=websub-hub diff --git a/src/manager.js b/src/manager.js index 0f11068..b5eff7a 100644 --- a/src/manager.js +++ b/src/manager.js @@ -25,13 +25,6 @@ class Manager { this.db = db; this.options = options; this.communication = new Communication(logger, db, options); - - // Precalculate the invariant root GET metadata. - this.getRootContent = Template.rootHTML(undefined, options); - const now = new Date(); - this.startTimeString = now.toGMTString(); - this.startTimeMs = now.getTime(); - this.getRootETag = common.generateETag(undefined, undefined, this.getRootContent); } @@ -53,6 +46,7 @@ class Manager { /** * GET request for root. + * @param {http.ClientRequest} req * @param {http.ServerResponse} res * @param {object} ctx */ @@ -60,16 +54,8 @@ class Manager { const _scope = _fileScope('getRoot'); this.logger.debug(_scope, 'called', { ctx }); - res.setHeader(Enum.Header.LastModified, this.startTimeString); - res.setHeader(Enum.Header.ETag, this.getRootETag); - - if (common.isClientCached(req, this.startTimeMs, this.getRootETag)) { - this.logger.debug(_scope, 'client cached response', { ctx }); - res.statusCode = 304; - res.end(); - return; - } - res.end(this.getRootContent); + const content = Template.rootHTML(ctx, this.options); + res.end(content); this.logger.info(_scope, 'finished', { ctx }); } @@ -576,6 +562,15 @@ class Manager { }); this.logger.debug(_scope, 'got topics', { topics: ctx.topics }); + // Profile users can only see related topics. + if (ctx.session && ctx.session.authenticatedProfile) { + const profileUrlObj = new URL(ctx.session.authenticatedProfile); + ctx.topics = ctx.topics.filter((topic) => { + const topicUrlObj = new URL(topic.url); + return (topicUrlObj.hostname === profileUrlObj.hostname); + }); + } + res.end(Template.adminOverviewHTML(ctx, this.options)); this.logger.info(_scope, 'finished', { ...ctx, topics: ctx.topics.length }) } @@ -597,8 +592,18 @@ class Manager { }); this.logger.debug(_scope, 'got topic details', { topic: ctx.topic, subscriptions: ctx.subscriptions }); + // Profile users can only see related topics. + if (ctx.session && ctx.session.authenticatedProfile) { + const profileUrlObj = new URL(ctx.session.authenticatedProfile); + const topicUrlObj = new URL(ctx.topic.url); + if (topicUrlObj.hostname !== profileUrlObj.hostname) { + ctx.topic = null; + ctx.subscriptions = []; + } + } + res.end(Template.adminTopicDetailsHTML(ctx, this.options)); - this.logger.info(_scope, 'finished', { ...ctx, subscriptions: ctx.subscriptions.length, topic: ctx.topic.id }); + this.logger.info(_scope, 'finished', { ...ctx, subscriptions: ctx.subscriptions.length, topic: ctx.topic && ctx.topic.id || ctx.topic }); } @@ -626,6 +631,8 @@ class Manager { await this.db.topicDeleted(txCtx, topicId); res.end(); this.logger.info(_scope, 'topic set deleted', { ctx, topicId }); + // Attempt to remove from db if no active subscriptions. + await this.db.topicPendingDelete(txCtx, topicId); return; } @@ -770,7 +777,7 @@ class Manager { * @param {object} ctx */ async processTasks(res, ctx) { - const _scope = _fileScope('getTopicDetails'); + const _scope = _fileScope('processTasks'); this.logger.debug(_scope, 'called', { ctx }); // N.B. no await on this