diff --git a/backend/src/middleware/handleHtmlContent/handleContentData.spec.js b/backend/src/middleware/handleHtmlContent/handleContentData.spec.js index e9439fe21..aa281e6d7 100644 --- a/backend/src/middleware/handleHtmlContent/handleContentData.spec.js +++ b/backend/src/middleware/handleHtmlContent/handleContentData.spec.js @@ -177,6 +177,7 @@ describe('Hashtags', () => { query($id: ID) { Post(id: $id) { tags { + id name } } @@ -216,12 +217,14 @@ describe('Hashtags', () => { }) }) - it('both Hashtags are created', async () => { + it('both Hashtags are created with the "id" set to thier "name"', async () => { const expected = [ { + id: 'Democracy', name: 'Democracy', }, { + id: 'Liberty', name: 'Liberty', }, ] @@ -259,9 +262,11 @@ describe('Hashtags', () => { const expected = [ { + id: 'Elections', name: 'Elections', }, { + id: 'Liberty', name: 'Liberty', }, ] diff --git a/backend/src/middleware/handleHtmlContent/hashtags/extractHashtags.js b/backend/src/middleware/handleHtmlContent/hashtags/extractHashtags.js index 5e77e6e3a..fd6613065 100644 --- a/backend/src/middleware/handleHtmlContent/hashtags/extractHashtags.js +++ b/backend/src/middleware/handleHtmlContent/hashtags/extractHashtags.js @@ -1,5 +1,11 @@ import cheerio from 'cheerio' -const ID_REGEX = /\/search\/hashtag\/([\w\-.!~*'"(),]+)/g +// formats of a Hashtag: +// https://en.wikipedia.org/w/index.php?title=Hashtag&oldid=905141980#Style +// here: +// 0. Search for whole string. +// 1. Hashtag has only 'a-z', 'A-Z', and '0-9'. +// 2. If it starts with a digit '0-9' than 'a-z', or 'A-Z' has to follow. +const ID_REGEX = /^\/search\/hashtag\/(([a-zA-Z]+[a-zA-Z0-9]*)|([0-9]+[a-zA-Z]+[a-zA-Z0-9]*))$/g export default function(content) { if (!content) return [] diff --git a/backend/src/middleware/handleHtmlContent/hashtags/extractHashtags.spec.js b/backend/src/middleware/handleHtmlContent/hashtags/extractHashtags.spec.js index 1b37aaa34..eb581d8f5 100644 --- a/backend/src/middleware/handleHtmlContent/hashtags/extractHashtags.spec.js +++ b/backend/src/middleware/handleHtmlContent/hashtags/extractHashtags.spec.js @@ -21,16 +21,16 @@ describe('extractHashtags', () => { }) describe('handles links', () => { - it('with domains', () => { + it('ignores links with domains', () => { const content = - '

#Elections#Democracy

' - expect(extractHashtags(content)).toEqual(['Elections', 'Democracy']) + '

#Elections#Democracy

' + expect(extractHashtags(content)).toEqual(['Democracy']) }) - it('special characters', () => { + it('ignores Hashtag links with not allowed character combinations', () => { const content = - '

Something inspirational about #u!*(),2 and #u.~-3.

' - expect(extractHashtags(content)).toEqual(['u!*(),2', 'u.~-3']) + '

Something inspirational about #AbcDefXyz0123456789!*(),2, #0123456789, #0123456789a and #AbcDefXyz0123456789.

' + expect(extractHashtags(content)).toEqual(['0123456789a', 'AbcDefXyz0123456789']) }) }) @@ -41,6 +41,12 @@ describe('extractHashtags', () => { expect(extractHashtags(content)).toEqual([]) }) + it('`href` contains Hashtag as page anchor', () => { + const content = + '

Something inspirational about #anchor.

' + expect(extractHashtags(content)).toEqual([]) + }) + it('`href` is empty or invalid', () => { const content = '

Something inspirational about @bob-der-baumeister and @jenny-rostock.

' diff --git a/backend/src/seed/seed-db.js b/backend/src/seed/seed-db.js index e31d09a68..18eefb76f 100644 --- a/backend/src/seed/seed-db.js +++ b/backend/src/seed/seed-db.js @@ -69,47 +69,144 @@ import Factory from './factories' role: 'user', email: 'user@example.org', }), - f.create('User', { id: 'u4', name: 'Tick', role: 'user', email: 'tick@example.org' }), - f.create('User', { id: 'u5', name: 'Trick', role: 'user', email: 'trick@example.org' }), - f.create('User', { id: 'u6', name: 'Track', role: 'user', email: 'track@example.org' }), - f.create('User', { id: 'u7', name: 'Dagobert', role: 'user', email: 'dagobert@example.org' }), + f.create('User', { + id: 'u4', + name: 'Tick', + role: 'user', + email: 'tick@example.org', + }), + f.create('User', { + id: 'u5', + name: 'Trick', + role: 'user', + email: 'trick@example.org', + }), + f.create('User', { + id: 'u6', + name: 'Track', + role: 'user', + email: 'track@example.org', + }), + f.create('User', { + id: 'u7', + name: 'Dagobert', + role: 'user', + email: 'dagobert@example.org', + }), ]) const [asAdmin, asModerator, asUser, asTick, asTrick, asTrack] = await Promise.all([ - Factory().authenticateAs({ email: 'admin@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'moderator@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'user@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'tick@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'trick@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'track@example.org', password: '1234' }), + Factory().authenticateAs({ + email: 'admin@example.org', + password: '1234', + }), + Factory().authenticateAs({ + email: 'moderator@example.org', + password: '1234', + }), + Factory().authenticateAs({ + email: 'user@example.org', + password: '1234', + }), + Factory().authenticateAs({ + email: 'tick@example.org', + password: '1234', + }), + Factory().authenticateAs({ + email: 'trick@example.org', + password: '1234', + }), + Factory().authenticateAs({ + email: 'track@example.org', + password: '1234', + }), ]) await Promise.all([ - f.relate('User', 'Badges', { from: 'b6', to: 'u1' }), - f.relate('User', 'Badges', { from: 'b5', to: 'u2' }), - f.relate('User', 'Badges', { from: 'b4', to: 'u3' }), - f.relate('User', 'Badges', { from: 'b3', to: 'u4' }), - f.relate('User', 'Badges', { from: 'b2', to: 'u5' }), - f.relate('User', 'Badges', { from: 'b1', to: 'u6' }), - f.relate('User', 'Friends', { from: 'u1', to: 'u2' }), - f.relate('User', 'Friends', { from: 'u1', to: 'u3' }), - f.relate('User', 'Friends', { from: 'u2', to: 'u3' }), - f.relate('User', 'Blacklisted', { from: 'u7', to: 'u4' }), - f.relate('User', 'Blacklisted', { from: 'u7', to: 'u5' }), - f.relate('User', 'Blacklisted', { from: 'u7', to: 'u6' }), + f.relate('User', 'Badges', { + from: 'b6', + to: 'u1', + }), + f.relate('User', 'Badges', { + from: 'b5', + to: 'u2', + }), + f.relate('User', 'Badges', { + from: 'b4', + to: 'u3', + }), + f.relate('User', 'Badges', { + from: 'b3', + to: 'u4', + }), + f.relate('User', 'Badges', { + from: 'b2', + to: 'u5', + }), + f.relate('User', 'Badges', { + from: 'b1', + to: 'u6', + }), + f.relate('User', 'Friends', { + from: 'u1', + to: 'u2', + }), + f.relate('User', 'Friends', { + from: 'u1', + to: 'u3', + }), + f.relate('User', 'Friends', { + from: 'u2', + to: 'u3', + }), + f.relate('User', 'Blacklisted', { + from: 'u7', + to: 'u4', + }), + f.relate('User', 'Blacklisted', { + from: 'u7', + to: 'u5', + }), + f.relate('User', 'Blacklisted', { + from: 'u7', + to: 'u6', + }), ]) await Promise.all([ - asAdmin.follow({ id: 'u3', type: 'User' }), - asModerator.follow({ id: 'u4', type: 'User' }), - asUser.follow({ id: 'u4', type: 'User' }), - asTick.follow({ id: 'u6', type: 'User' }), - asTrick.follow({ id: 'u4', type: 'User' }), - asTrack.follow({ id: 'u3', type: 'User' }), + asAdmin.follow({ + id: 'u3', + type: 'User', + }), + asModerator.follow({ + id: 'u4', + type: 'User', + }), + asUser.follow({ + id: 'u4', + type: 'User', + }), + asTick.follow({ + id: 'u6', + type: 'User', + }), + asTrick.follow({ + id: 'u4', + type: 'User', + }), + asTrack.follow({ + id: 'u3', + type: 'User', + }), ]) await Promise.all([ - f.create('Category', { id: 'cat1', name: 'Just For Fun', slug: 'justforfun', icon: 'smile' }), + f.create('Category', { + id: 'cat1', + name: 'Just For Fun', + slug: 'justforfun', + icon: 'smile', + }), f.create('Category', { id: 'cat2', name: 'Happyness & Values', @@ -203,10 +300,22 @@ import Factory from './factories' ]) await Promise.all([ - f.create('Tag', { id: 't1', name: 'Umwelt' }), - f.create('Tag', { id: 't2', name: 'Naturschutz' }), - f.create('Tag', { id: 't3', name: 'Demokratie' }), - f.create('Tag', { id: 't4', name: 'Freiheit' }), + f.create('Tag', { + id: 'Umwelt', + name: 'Umwelt', + }), + f.create('Tag', { + id: 'Naturschutz', + name: 'Naturschutz', + }), + f.create('Tag', { + id: 'Demokratie', + name: 'Demokratie', + }), + f.create('Tag', { + id: 'Freiheit', + name: 'Freiheit', + }), ]) const mention1 = 'Hey @jenny-rostock, what\'s up?' @@ -214,108 +323,347 @@ import Factory from './factories' 'Hey @jenny-rostock, here is another notification for you!' await Promise.all([ - asAdmin.create('Post', { id: 'p0', image: faker.image.unsplash.food() }), - asModerator.create('Post', { id: 'p1', image: faker.image.unsplash.technology() }), - asUser.create('Post', { id: 'p2' }), - asTick.create('Post', { id: 'p3' }), - asTrick.create('Post', { id: 'p4' }), - asTrack.create('Post', { id: 'p5' }), - asAdmin.create('Post', { id: 'p6', image: faker.image.unsplash.buildings() }), - asModerator.create('Post', { id: 'p7', content: `${mention1} ${faker.lorem.paragraph()}` }), - asUser.create('Post', { id: 'p8', image: faker.image.unsplash.nature() }), - asTick.create('Post', { id: 'p9' }), - asTrick.create('Post', { id: 'p10' }), - asTrack.create('Post', { id: 'p11', image: faker.image.unsplash.people() }), - asAdmin.create('Post', { id: 'p12', content: `${mention2} ${faker.lorem.paragraph()}` }), - asModerator.create('Post', { id: 'p13' }), - asUser.create('Post', { id: 'p14', image: faker.image.unsplash.objects() }), - asTick.create('Post', { id: 'p15' }), + asAdmin.create('Post', { + id: 'p0', + image: faker.image.unsplash.food(), + }), + asModerator.create('Post', { + id: 'p1', + image: faker.image.unsplash.technology(), + }), + asUser.create('Post', { + id: 'p2', + }), + asTick.create('Post', { + id: 'p3', + }), + asTrick.create('Post', { + id: 'p4', + }), + asTrack.create('Post', { + id: 'p5', + }), + asAdmin.create('Post', { + id: 'p6', + image: faker.image.unsplash.buildings(), + }), + asModerator.create('Post', { + id: 'p7', + content: `${mention1} ${faker.lorem.paragraph()}`, + }), + asUser.create('Post', { + id: 'p8', + image: faker.image.unsplash.nature(), + }), + asTick.create('Post', { + id: 'p9', + }), + asTrick.create('Post', { + id: 'p10', + }), + asTrack.create('Post', { + id: 'p11', + image: faker.image.unsplash.people(), + }), + asAdmin.create('Post', { + id: 'p12', + content: `${mention2} ${faker.lorem.paragraph()}`, + }), + asModerator.create('Post', { + id: 'p13', + }), + asUser.create('Post', { + id: 'p14', + image: faker.image.unsplash.objects(), + }), + asTick.create('Post', { + id: 'p15', + }), ]) await Promise.all([ - f.relate('Post', 'Categories', { from: 'p0', to: 'cat16' }), - f.relate('Post', 'Categories', { from: 'p1', to: 'cat1' }), - f.relate('Post', 'Categories', { from: 'p2', to: 'cat2' }), - f.relate('Post', 'Categories', { from: 'p3', to: 'cat3' }), - f.relate('Post', 'Categories', { from: 'p4', to: 'cat4' }), - f.relate('Post', 'Categories', { from: 'p5', to: 'cat5' }), - f.relate('Post', 'Categories', { from: 'p6', to: 'cat6' }), - f.relate('Post', 'Categories', { from: 'p7', to: 'cat7' }), - f.relate('Post', 'Categories', { from: 'p8', to: 'cat8' }), - f.relate('Post', 'Categories', { from: 'p9', to: 'cat9' }), - f.relate('Post', 'Categories', { from: 'p10', to: 'cat10' }), - f.relate('Post', 'Categories', { from: 'p11', to: 'cat11' }), - f.relate('Post', 'Categories', { from: 'p12', to: 'cat12' }), - f.relate('Post', 'Categories', { from: 'p13', to: 'cat13' }), - f.relate('Post', 'Categories', { from: 'p14', to: 'cat14' }), - f.relate('Post', 'Categories', { from: 'p15', to: 'cat15' }), + f.relate('Post', 'Categories', { + from: 'p0', + to: 'cat16', + }), + f.relate('Post', 'Categories', { + from: 'p1', + to: 'cat1', + }), + f.relate('Post', 'Categories', { + from: 'p2', + to: 'cat2', + }), + f.relate('Post', 'Categories', { + from: 'p3', + to: 'cat3', + }), + f.relate('Post', 'Categories', { + from: 'p4', + to: 'cat4', + }), + f.relate('Post', 'Categories', { + from: 'p5', + to: 'cat5', + }), + f.relate('Post', 'Categories', { + from: 'p6', + to: 'cat6', + }), + f.relate('Post', 'Categories', { + from: 'p7', + to: 'cat7', + }), + f.relate('Post', 'Categories', { + from: 'p8', + to: 'cat8', + }), + f.relate('Post', 'Categories', { + from: 'p9', + to: 'cat9', + }), + f.relate('Post', 'Categories', { + from: 'p10', + to: 'cat10', + }), + f.relate('Post', 'Categories', { + from: 'p11', + to: 'cat11', + }), + f.relate('Post', 'Categories', { + from: 'p12', + to: 'cat12', + }), + f.relate('Post', 'Categories', { + from: 'p13', + to: 'cat13', + }), + f.relate('Post', 'Categories', { + from: 'p14', + to: 'cat14', + }), + f.relate('Post', 'Categories', { + from: 'p15', + to: 'cat15', + }), - f.relate('Post', 'Tags', { from: 'p0', to: 't4' }), - f.relate('Post', 'Tags', { from: 'p1', to: 't1' }), - f.relate('Post', 'Tags', { from: 'p2', to: 't2' }), - f.relate('Post', 'Tags', { from: 'p3', to: 't3' }), - f.relate('Post', 'Tags', { from: 'p4', to: 't4' }), - f.relate('Post', 'Tags', { from: 'p5', to: 't1' }), - f.relate('Post', 'Tags', { from: 'p6', to: 't2' }), - f.relate('Post', 'Tags', { from: 'p7', to: 't3' }), - f.relate('Post', 'Tags', { from: 'p8', to: 't4' }), - f.relate('Post', 'Tags', { from: 'p9', to: 't1' }), - f.relate('Post', 'Tags', { from: 'p10', to: 't2' }), - f.relate('Post', 'Tags', { from: 'p11', to: 't3' }), - f.relate('Post', 'Tags', { from: 'p12', to: 't4' }), - f.relate('Post', 'Tags', { from: 'p13', to: 't1' }), - f.relate('Post', 'Tags', { from: 'p14', to: 't2' }), - f.relate('Post', 'Tags', { from: 'p15', to: 't3' }), + f.relate('Post', 'Tags', { + from: 'p0', + to: 'Freiheit', + }), + f.relate('Post', 'Tags', { + from: 'p1', + to: 'Umwelt', + }), + f.relate('Post', 'Tags', { + from: 'p2', + to: 'Naturschutz', + }), + f.relate('Post', 'Tags', { + from: 'p3', + to: 'Demokratie', + }), + f.relate('Post', 'Tags', { + from: 'p4', + to: 'Freiheit', + }), + f.relate('Post', 'Tags', { + from: 'p5', + to: 'Umwelt', + }), + f.relate('Post', 'Tags', { + from: 'p6', + to: 'Naturschutz', + }), + f.relate('Post', 'Tags', { + from: 'p7', + to: 'Demokratie', + }), + f.relate('Post', 'Tags', { + from: 'p8', + to: 'Freiheit', + }), + f.relate('Post', 'Tags', { + from: 'p9', + to: 'Umwelt', + }), + f.relate('Post', 'Tags', { + from: 'p10', + to: 'Naturschutz', + }), + f.relate('Post', 'Tags', { + from: 'p11', + to: 'Demokratie', + }), + f.relate('Post', 'Tags', { + from: 'p12', + to: 'Freiheit', + }), + f.relate('Post', 'Tags', { + from: 'p13', + to: 'Umwelt', + }), + f.relate('Post', 'Tags', { + from: 'p14', + to: 'Naturschutz', + }), + f.relate('Post', 'Tags', { + from: 'p15', + to: 'Demokratie', + }), ]) await Promise.all([ - asAdmin.shout({ id: 'p2', type: 'Post' }), - asAdmin.shout({ id: 'p6', type: 'Post' }), - asModerator.shout({ id: 'p0', type: 'Post' }), - asModerator.shout({ id: 'p6', type: 'Post' }), - asUser.shout({ id: 'p6', type: 'Post' }), - asUser.shout({ id: 'p7', type: 'Post' }), - asTick.shout({ id: 'p8', type: 'Post' }), - asTick.shout({ id: 'p9', type: 'Post' }), - asTrack.shout({ id: 'p10', type: 'Post' }), + asAdmin.shout({ + id: 'p2', + type: 'Post', + }), + asAdmin.shout({ + id: 'p6', + type: 'Post', + }), + asModerator.shout({ + id: 'p0', + type: 'Post', + }), + asModerator.shout({ + id: 'p6', + type: 'Post', + }), + asUser.shout({ + id: 'p6', + type: 'Post', + }), + asUser.shout({ + id: 'p7', + type: 'Post', + }), + asTick.shout({ + id: 'p8', + type: 'Post', + }), + asTick.shout({ + id: 'p9', + type: 'Post', + }), + asTrack.shout({ + id: 'p10', + type: 'Post', + }), ]) await Promise.all([ - asAdmin.shout({ id: 'p2', type: 'Post' }), - asAdmin.shout({ id: 'p6', type: 'Post' }), - asModerator.shout({ id: 'p0', type: 'Post' }), - asModerator.shout({ id: 'p6', type: 'Post' }), - asUser.shout({ id: 'p6', type: 'Post' }), - asUser.shout({ id: 'p7', type: 'Post' }), - asTick.shout({ id: 'p8', type: 'Post' }), - asTick.shout({ id: 'p9', type: 'Post' }), - asTrack.shout({ id: 'p10', type: 'Post' }), + asAdmin.shout({ + id: 'p2', + type: 'Post', + }), + asAdmin.shout({ + id: 'p6', + type: 'Post', + }), + asModerator.shout({ + id: 'p0', + type: 'Post', + }), + asModerator.shout({ + id: 'p6', + type: 'Post', + }), + asUser.shout({ + id: 'p6', + type: 'Post', + }), + asUser.shout({ + id: 'p7', + type: 'Post', + }), + asTick.shout({ + id: 'p8', + type: 'Post', + }), + asTick.shout({ + id: 'p9', + type: 'Post', + }), + asTrack.shout({ + id: 'p10', + type: 'Post', + }), ]) await Promise.all([ - asUser.create('Comment', { id: 'c1', postId: 'p1' }), - asTick.create('Comment', { id: 'c2', postId: 'p1' }), - asTrack.create('Comment', { id: 'c3', postId: 'p3' }), - asTrick.create('Comment', { id: 'c4', postId: 'p2' }), - asModerator.create('Comment', { id: 'c5', postId: 'p3' }), - asAdmin.create('Comment', { id: 'c6', postId: 'p4' }), - asUser.create('Comment', { id: 'c7', postId: 'p2' }), - asTick.create('Comment', { id: 'c8', postId: 'p15' }), - asTrick.create('Comment', { id: 'c9', postId: 'p15' }), - asTrack.create('Comment', { id: 'c10', postId: 'p15' }), - asUser.create('Comment', { id: 'c11', postId: 'p15' }), - asUser.create('Comment', { id: 'c12', postId: 'p15' }), + asUser.create('Comment', { + id: 'c1', + postId: 'p1', + }), + asTick.create('Comment', { + id: 'c2', + postId: 'p1', + }), + asTrack.create('Comment', { + id: 'c3', + postId: 'p3', + }), + asTrick.create('Comment', { + id: 'c4', + postId: 'p2', + }), + asModerator.create('Comment', { + id: 'c5', + postId: 'p3', + }), + asAdmin.create('Comment', { + id: 'c6', + postId: 'p4', + }), + asUser.create('Comment', { + id: 'c7', + postId: 'p2', + }), + asTick.create('Comment', { + id: 'c8', + postId: 'p15', + }), + asTrick.create('Comment', { + id: 'c9', + postId: 'p15', + }), + asTrack.create('Comment', { + id: 'c10', + postId: 'p15', + }), + asUser.create('Comment', { + id: 'c11', + postId: 'p15', + }), + asUser.create('Comment', { + id: 'c12', + postId: 'p15', + }), ]) const disableMutation = 'mutation($id: ID!) { disable(id: $id) }' await Promise.all([ - asModerator.mutate(disableMutation, { id: 'p11' }), - asModerator.mutate(disableMutation, { id: 'c5' }), + asModerator.mutate(disableMutation, { + id: 'p11', + }), + asModerator.mutate(disableMutation, { + id: 'c5', + }), ]) await Promise.all([ - asTick.create('Report', { description: "I don't like this comment", id: 'c1' }), - asTrick.create('Report', { description: "I don't like this post", id: 'p1' }), - asTrack.create('Report', { description: "I don't like this user", id: 'u1' }), + asTick.create('Report', { + description: "I don't like this comment", + id: 'c1', + }), + asTrick.create('Report', { + description: "I don't like this post", + id: 'p1', + }), + asTrack.create('Report', { + description: "I don't like this user", + id: 'u1', + }), ]) await Promise.all([ @@ -342,10 +690,22 @@ import Factory from './factories' ]) await Promise.all([ - f.relate('Organization', 'CreatedBy', { from: 'u1', to: 'o1' }), - f.relate('Organization', 'CreatedBy', { from: 'u1', to: 'o2' }), - f.relate('Organization', 'OwnedBy', { from: 'u2', to: 'o2' }), - f.relate('Organization', 'OwnedBy', { from: 'u2', to: 'o3' }), + f.relate('Organization', 'CreatedBy', { + from: 'u1', + to: 'o1', + }), + f.relate('Organization', 'CreatedBy', { + from: 'u1', + to: 'o2', + }), + f.relate('Organization', 'OwnedBy', { + from: 'u2', + to: 'o2', + }), + f.relate('Organization', 'OwnedBy', { + from: 'u2', + to: 'o3', + }), ]) /* eslint-disable-next-line no-console */ console.log('Seeded Data...') diff --git a/webapp/components/Editor/Editor.vue b/webapp/components/Editor/Editor.vue index 98a5bc3df..4413bfa0d 100644 --- a/webapp/components/Editor/Editor.vue +++ b/webapp/components/Editor/Editor.vue @@ -1,6 +1,8 @@