From 76b125f042dd4da55c997b10c206712a8072055b Mon Sep 17 00:00:00 2001 From: IAmSamHankins Date: Fri, 4 Aug 2017 13:42:19 -0400 Subject: [PATCH 01/11] adjustments to comment queue counters --- .../src/routes/Moderation/components/CommentCount.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/coral-admin/src/routes/Moderation/components/CommentCount.css b/client/coral-admin/src/routes/Moderation/components/CommentCount.css index 4d24d5702..998133d07 100644 --- a/client/coral-admin/src/routes/Moderation/components/CommentCount.css +++ b/client/coral-admin/src/routes/Moderation/components/CommentCount.css @@ -1,16 +1,16 @@ .count { display: inline-block; - background: #989797; + background: #616161; margin: 2px; vertical-align: middle; - padding: 1px 7px; + padding: 1px 5px; border-radius: 2px; margin-left: 2px; - line-height: 20px; + line-height: 18px; box-sizing: border-box; - height: 21px; + height: 18px; right: 0; - margin-top: -2px; + margin-top: 0px; font-size: 12px; color: white; } From 11b2bc265a0e1469383b0613a0a4b3066bf32820 Mon Sep 17 00:00:00 2001 From: IAmSamHankins Date: Fri, 4 Aug 2017 13:50:14 -0400 Subject: [PATCH 02/11] comment tag/marker updates for size --- client/coral-admin/src/components/CommentType.css | 5 +++-- .../client/components/ModTag.css | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/client/coral-admin/src/components/CommentType.css b/client/coral-admin/src/components/CommentType.css index b5dbc229b..61a65f89a 100644 --- a/client/coral-admin/src/components/CommentType.css +++ b/client/coral-admin/src/components/CommentType.css @@ -3,10 +3,11 @@ color: white; background: grey; box-sizing: border-box; - padding: 2px 8px; + padding: 0px 5px; border-radius: 2px; font-size: 12px; - height: 28px; + height: 24px; + letter-spacing: 0.4px; > i { font-size: 14px; diff --git a/plugins/talk-plugin-featured-comments/client/components/ModTag.css b/plugins/talk-plugin-featured-comments/client/components/ModTag.css index c8ba1b6ba..683c16570 100644 --- a/plugins/talk-plugin-featured-comments/client/components/ModTag.css +++ b/plugins/talk-plugin-featured-comments/client/components/ModTag.css @@ -4,13 +4,14 @@ color: #696969; background-color: white; box-sizing: border-box; - padding: 2px 8px; + padding: 0px 5px; border-radius: 2px; font-size: 12px; - height: 28px; + height: 24px; transition: background-color .2s cubic-bezier(.4,0,.2,1), color .2s cubic-bezier(.4,0,.2,1), border-color .2s cubic-bezier(.4,0,.2,1); margin: 2px 0px; letter-spacing: 0.4px; + } .tag:hover { @@ -39,4 +40,3 @@ font-size: 15px; vertical-align: text-bottom; } - \ No newline at end of file From ddadd6c5d32bd17c1741e95c8e01e4f54a3c9d68 Mon Sep 17 00:00:00 2001 From: IAmSamHankins Date: Mon, 7 Aug 2017 10:26:42 -0500 Subject: [PATCH 03/11] adjustments/fixes to approved rejected widths --- client/coral-admin/src/components/CommentType.css | 3 ++- client/coral-admin/src/components/ModerationList.css | 1 - client/coral-ui/components/Button.css | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/client/coral-admin/src/components/CommentType.css b/client/coral-admin/src/components/CommentType.css index 61a65f89a..e4851275e 100644 --- a/client/coral-admin/src/components/CommentType.css +++ b/client/coral-admin/src/components/CommentType.css @@ -8,7 +8,8 @@ font-size: 12px; height: 24px; letter-spacing: 0.4px; - + margin-bottom: 1px; + > i { font-size: 14px; vertical-align: text-top; diff --git a/client/coral-admin/src/components/ModerationList.css b/client/coral-admin/src/components/ModerationList.css index 89e43e02a..4ac894290 100644 --- a/client/coral-admin/src/components/ModerationList.css +++ b/client/coral-admin/src/components/ModerationList.css @@ -186,7 +186,6 @@ .actionButton { transform: scale(.8); margin: 0; - width: 140px; } .minimal { diff --git a/client/coral-ui/components/Button.css b/client/coral-ui/components/Button.css index 7bd1d4379..1b7efb205 100644 --- a/client/coral-ui/components/Button.css +++ b/client/coral-ui/components/Button.css @@ -27,9 +27,10 @@ } .icon { - margin-right: 13px; + margin-right: 5px; font-size: 18px; vertical-align: middle; + margin-top: -3px; } .type--black { @@ -143,7 +144,7 @@ border-radius: 3px; text-transform: capitalize; box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.03), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.09); - width: 128px; + width: 129px; &:hover { box-shadow: none; @@ -166,7 +167,7 @@ border-radius: 3px; text-transform: capitalize; box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.03), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.09); - width: 128px; + width: 129px; &:hover { color: white; From 27216cbfdbc7c8208516c3cc720a2df8e9cf66da Mon Sep 17 00:00:00 2001 From: IAmSamHankins Date: Mon, 7 Aug 2017 10:32:21 -0500 Subject: [PATCH 04/11] hierarchy for asset search title --- .../coral-admin/src/routes/Moderation/components/styles.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/coral-admin/src/routes/Moderation/components/styles.css b/client/coral-admin/src/routes/Moderation/components/styles.css index ccc762641..b821d9429 100644 --- a/client/coral-admin/src/routes/Moderation/components/styles.css +++ b/client/coral-admin/src/routes/Moderation/components/styles.css @@ -111,7 +111,7 @@ span { color: white; text-transform: capitalize; font-weight: 400; - font-size: 15px; + font-size: 20px; letter-spacing: 1px; transition: background-color 200ms; opacity: 1; @@ -490,7 +490,7 @@ span { .searchTrigger { position: relative; - top: .3em; + top: .2em; } .adminCommentInfoBar { @@ -499,4 +499,4 @@ span { right: 0px; top: 0px; text-align: right; -} \ No newline at end of file +} From 53cac48e3b365bc9e4066b5b8e9163ecd7307e75 Mon Sep 17 00:00:00 2001 From: IAmSamHankins Date: Mon, 7 Aug 2017 11:53:39 -0500 Subject: [PATCH 05/11] resizing of the comment component --- client/coral-admin/src/routes/Moderation/components/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-admin/src/routes/Moderation/components/styles.css b/client/coral-admin/src/routes/Moderation/components/styles.css index b821d9429..cccf85f78 100644 --- a/client/coral-admin/src/routes/Moderation/components/styles.css +++ b/client/coral-admin/src/routes/Moderation/components/styles.css @@ -173,7 +173,7 @@ span { border-bottom: 1px solid #e0e0e0; font-size: 18px; width: 100%; - max-width: 700px; + max-width: 650px; min-width: 400px; margin: 0 auto; position: relative; From c62e7328c5801466315a5c632f90566b5ed8a2fa Mon Sep 17 00:00:00 2001 From: IAmSamHankins Date: Wed, 9 Aug 2017 10:15:52 -0500 Subject: [PATCH 06/11] adjustments to top navigation and logo --- client/coral-admin/src/components/FlagBox.css | 2 +- client/coral-admin/src/components/ui/Logo.css | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client/coral-admin/src/components/FlagBox.css b/client/coral-admin/src/components/FlagBox.css index 402a88045..232803203 100644 --- a/client/coral-admin/src/components/FlagBox.css +++ b/client/coral-admin/src/components/FlagBox.css @@ -1,6 +1,6 @@ .flagBox { border-top: 1px solid rgba(66, 66, 66, 0.12); - + margin-top: 10px; .container { padding: 0 14px; } diff --git a/client/coral-admin/src/components/ui/Logo.css b/client/coral-admin/src/components/ui/Logo.css index af2758bcb..62a223683 100644 --- a/client/coral-admin/src/components/ui/Logo.css +++ b/client/coral-admin/src/components/ui/Logo.css @@ -10,16 +10,18 @@ .logo span { display: inline-block; margin-left: 10px; - font-size: 18px; + font-size: 26px; vertical-align: middle; font-weight: 500; + color: white; } .logo { - background: #E5E5E5; + background: #696969; height: 100%; width: 128px; z-index: 10; + border-right: 1px #757575 solid; } .base { From ca422f0109ec25508efb4d9b64975dfef25dd1b7 Mon Sep 17 00:00:00 2001 From: IAmSamHankins Date: Wed, 9 Aug 2017 10:23:03 -0500 Subject: [PATCH 07/11] mod queue nav styling adjust --- .../coral-admin/src/routes/Moderation/components/styles.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/routes/Moderation/components/styles.css b/client/coral-admin/src/routes/Moderation/components/styles.css index cccf85f78..d1d1ae697 100644 --- a/client/coral-admin/src/routes/Moderation/components/styles.css +++ b/client/coral-admin/src/routes/Moderation/components/styles.css @@ -18,7 +18,7 @@ .tab { flex: 1; - color: #C0C0C0; + color: #BDBDBD; text-transform: capitalize; font-weight: 100; font-size: 14px; @@ -29,7 +29,7 @@ margin-right: 20px; &:hover { color: white; - border-bottom: solid 2px #F36451; + /*border-bottom: solid 2px #F36451;*/ box-sizing: border-box; } } From b9243938bdfab47376caf9061fc8508188a70ef0 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 10 Aug 2017 10:33:45 +1000 Subject: [PATCH 08/11] Added support for changing the singing cookie name --- config.js | 19 +++++++++++++++++++ docs/_docs/02-01-configuration.md | 12 ++++++++++-- services/passport.js | 13 +++++++------ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/config.js b/config.js index 4472af26e..4a3609dc8 100644 --- a/config.js +++ b/config.js @@ -7,6 +7,8 @@ // entrypoint for the entire applications configuration. require('env-rewrite').rewrite(); +const uniq = require('lodash/uniq'); + //============================================================================== // CONFIG INITIALIZATION //============================================================================== @@ -31,6 +33,13 @@ const CONFIG = { // token. JWT_COOKIE_NAME: process.env.TALK_JWT_COOKIE_NAME || 'authorization', + // JWT_SIGNING_COOKIE_NAME will be the cookie set when cookies are issued. + // This defaults to the TALK_JWT_COOKIE_NAME value. + JWT_SIGNING_COOKIE_NAME: process.env.TALK_JWT_SIGNING_COOKIE_NAME || process.env.TALK_JWT_COOKIE_NAME || 'authorization', + + // JWT_COOKIE_NAMES declares the many cookie names used for verification. + JWT_COOKIE_NAMES: process.env.TALK_JWT_COOKIE_NAMES || null, + // JWT_CLEAR_COOKIE_LOGOUT specifies whether the named cookie should be // cleared when the user is logged out. JWT_CLEAR_COOKIE_LOGOUT: process.env.TALK_JWT_CLEAR_COOKIE_LOGOUT ? process.env.TALK_JWT_CLEAR_COOKIE_LOGOUT !== 'FALSE' : true, @@ -165,6 +174,16 @@ if (CONFIG.JWT_DISABLE_ISSUER) { CONFIG.JWT_ISSUER = undefined; } +// Parse and handle cookie names. +if (CONFIG.JWT_COOKIE_NAMES) { + CONFIG.JWT_COOKIE_NAMES = CONFIG.JWT_COOKIE_NAMES.split(','); +} else { + CONFIG.JWT_COOKIE_NAMES = []; +} + +// Add in the default cookie names and strip duplicates. +CONFIG.JWT_COOKIE_NAMES = uniq(CONFIG.JWT_COOKIE_NAMES.concat([CONFIG.JWT_COOKIE_NAME, CONFIG.JWT_SIGNING_COOKIE_NAME])); + //------------------------------------------------------------------------------ // External database url's //------------------------------------------------------------------------------ diff --git a/docs/_docs/02-01-configuration.md b/docs/_docs/02-01-configuration.md index 74bd8972e..b02376c24 100644 --- a/docs/_docs/02-01-configuration.md +++ b/docs/_docs/02-01-configuration.md @@ -87,8 +87,16 @@ on the contents of those variables.** These are advanced settings for fine tuning the auth integration, and is not needed in most situations. -- `TALK_JWT_COOKIE_NAME` (_optional_) - the name of the cookie to extract the - JWT from (Default `authorization`) +- `TALK_JWT_COOKIE_NAME` (_optional_) - the default cookie name to check for a + valid JWT token to use for verifying a user. (Default `authorization`) +- `TALK_JWT_SIGNING_COOKIE_NAME` (_optional_) - the default cookie name that is + use to set a cookie containing a JWT that was issued by Talk. + (Default `process.env.TALK_JWT_COOKIE_NAME`) +- `TALK_JWT_COOKIE_NAMES` (_optional_) - the different cookie names to check for + a JWT token in, seperated by `,`. By default, we always use the + `process.env.TALK_JWT_COOKIE_NAME` and `process.env.TALK_JWT_SIGNING_COOKIE_NAME` + for this value. Any additional cookie names specified here will be appended to + the list of cookie names to inspect. - `TALK_JWT_CLEAR_COOKIE_LOGOUT` (_optional_) - when `FALSE`, Talk will not clear the cookie with name `TALK_JWT_COOKIE_NAME` when logging out (Default `TRUE`) diff --git a/services/passport.js b/services/passport.js index 409bb2279..31a8ecba1 100644 --- a/services/passport.js +++ b/services/passport.js @@ -23,7 +23,8 @@ const { JWT_ALG, RECAPTCHA_SECRET, RECAPTCHA_ENABLED, - JWT_COOKIE_NAME, + JWT_SIGNING_COOKIE_NAME, + JWT_COOKIE_NAMES, JWT_CLEAR_COOKIE_LOGOUT, JWT_USER_ID_CLAIM, } = require('../config'); @@ -53,7 +54,7 @@ const GenerateToken = (user) => { const SetTokenForSafari = (req, res, token) => { const browser = bowser._detect(req.headers['user-agent']); if (browser.ios || browser.safari) { - res.cookie(JWT_COOKIE_NAME, token, { + res.cookie(JWT_SIGNING_COOKIE_NAME, token, { httpOnly: true, secure: process.env.NODE_ENV === 'production', expires: new Date(Date.now() + ms(JWT_EXPIRY)) @@ -169,7 +170,7 @@ const HandleLogout = (req, res, next) => { // Only clear the cookie on logout if enabled. if (JWT_CLEAR_COOKIE_LOGOUT) { - res.clearCookie(JWT_COOKIE_NAME); + res.clearCookie(JWT_SIGNING_COOKIE_NAME); } res.status(204).end(); @@ -209,11 +210,11 @@ const CheckBlacklisted = async (jwt) => { const JwtStrategy = require('passport-jwt').Strategy; const ExtractJwt = require('passport-jwt').ExtractJwt; -let cookieExtractor = function(req) { +let cookieExtractor = (cookieName) => (req) => { let token = null; if (req && req.cookies) { - token = req.cookies[JWT_COOKIE_NAME]; + token = req.cookies[cookieName]; } return token; @@ -237,7 +238,7 @@ passport.use(new JwtStrategy({ // Prepare the extractor from the header. jwtFromRequest: ExtractJwt.fromExtractors([ - cookieExtractor, + ...JWT_COOKIE_NAMES.map(cookieExtractor), ExtractJwt.fromUrlQueryParameter('access_token'), ExtractJwt.fromAuthHeaderWithScheme('Bearer') ]), From 6d70a7b20e048166578b5313530cf0ed91719208 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 10 Aug 2017 10:46:11 +1000 Subject: [PATCH 09/11] improved code around cookie handling, added to docs --- docs/_docs/02-01-configuration.md | 8 ++++++++ services/passport.js | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/_docs/02-01-configuration.md b/docs/_docs/02-01-configuration.md index b02376c24..18a483723 100644 --- a/docs/_docs/02-01-configuration.md +++ b/docs/_docs/02-01-configuration.md @@ -123,6 +123,14 @@ will be used: } ``` +When our passport middleware checks for JWT tokens, it searches in the following +order: + +1. Custom cookies named from the list in `TALK_JWT_COOKIE_NAMES`. +2. Default cookies named `TALK_JWT_COOKIE_NAME` then `TALK_JWT_SIGNING_COOKIE_NAME`. +3. Query parameter `?access_token={TOKEN}`. +4. Header: `Authorization: Bearer {TOKEN}`. + ### Email - `TALK_SMTP_EMAIL` (*required for email*) - the address to send emails from diff --git a/services/passport.js b/services/passport.js index 31a8ecba1..14a2134ce 100644 --- a/services/passport.js +++ b/services/passport.js @@ -210,14 +210,20 @@ const CheckBlacklisted = async (jwt) => { const JwtStrategy = require('passport-jwt').Strategy; const ExtractJwt = require('passport-jwt').ExtractJwt; -let cookieExtractor = (cookieName) => (req) => { - let token = null; - +let cookieExtractor = (req) => { if (req && req.cookies) { - token = req.cookies[cookieName]; + + // Walk over all the cookie names in JWT_COOKIE_NAMES. + for (const cookieName of JWT_COOKIE_NAMES) { + + // Check to see if that cookie is set. + if (cookieName in req.cookies && req.cookies[cookieName] !== null && req.cookies[cookieName].length > 0) { + return req.cookies[cookieName]; + } + } } - return token; + return null; }; // Override the JwtVerifier method on the JwtStrategy so we can pack the @@ -238,7 +244,7 @@ passport.use(new JwtStrategy({ // Prepare the extractor from the header. jwtFromRequest: ExtractJwt.fromExtractors([ - ...JWT_COOKIE_NAMES.map(cookieExtractor), + cookieExtractor, ExtractJwt.fromUrlQueryParameter('access_token'), ExtractJwt.fromAuthHeaderWithScheme('Bearer') ]), From 0013c366860981a076a4ee3f08405456fc8f317a Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Thu, 10 Aug 2017 11:20:45 +0100 Subject: [PATCH 10/11] Update version number to 3.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 476e7eda5..087044a4c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "talk", - "version": "3.0.0", + "version": "3.1.0", "description": "A better commenting experience from Mozilla, The New York Times, and the Washington Post. https://coralproject.net", "main": "app.js", "scripts": { From 6956b4cd3102112ee3eff9b1d8400d8c260754c7 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 10 Aug 2017 18:39:02 +0700 Subject: [PATCH 11/11] Remove Tag should keep remaining tags --- services/tags.js | 4 ++-- test/server/services/tags.js | 42 ++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/services/tags.js b/services/tags.js index fbe6b58ec..b0d0c4b96 100644 --- a/services/tags.js +++ b/services/tags.js @@ -205,8 +205,8 @@ class TagsService { return updateModel(item_type, query, { $pull: { tags: { - name: link.tag.name - } + 'tag.name': link.tag.name, + }, } }); } diff --git a/test/server/services/tags.js b/test/server/services/tags.js index 7cdad829e..1080563f0 100644 --- a/test/server/services/tags.js +++ b/test/server/services/tags.js @@ -27,7 +27,7 @@ describe('services.TagsService', () => { const id = comment.id; const name = 'BEST'; const assigned_by = user.id; - + await TagsService.add(id, 'COMMENTS', { tag: { name @@ -45,7 +45,7 @@ describe('services.TagsService', () => { const id = comment.id; const name = 'BEST'; const assigned_by = user.id; - + await TagsService.add(id, 'COMMENTS', { tag: { name @@ -103,5 +103,43 @@ describe('services.TagsService', () => { expect(tags.length).to.equal(0); } }); + it('removes a tag out of 2', async () => { + const id = comment.id; + const name = 'BEST'; + const assigned_by = user.id; + + await TagsService.add(id, 'COMMENTS', { + tag: { + name: 'ANOTHER' + }, + assigned_by + }); + + await TagsService.add(id, 'COMMENTS', { + tag: { + name + }, + assigned_by + }); + + { + const {tags} = await CommentsService.findById(id); + expect(tags.length).to.equal(2); + } + + // ok now to remove it + await TagsService.remove(id, 'COMMENTS', { + tag: { + name + }, + assigned_by + }); + + { + const {tags} = await CommentsService.findById(id); + expect(tags.length).to.equal(1); + expect(tags[0].tag.name).to.equal('ANOTHER'); + } + }); }); });