diff --git a/backend/src/jwt/encode.js b/backend/src/jwt/encode.js
index 9126f2577..50e439474 100644
--- a/backend/src/jwt/encode.js
+++ b/backend/src/jwt/encode.js
@@ -5,7 +5,7 @@ import CONFIG from './../config'
export default function encode(user) {
const { id, name, slug } = user
const token = jwt.sign({ id, name, slug }, CONFIG.JWT_SECRET, {
- expiresIn: '1d',
+ expiresIn: '2y',
issuer: CONFIG.GRAPHQL_URI,
audience: CONFIG.CLIENT_URI,
subject: user.id.toString(),
diff --git a/backend/src/middleware/permissionsMiddleware.js b/backend/src/middleware/permissionsMiddleware.js
index 25598a30f..b10389f50 100644
--- a/backend/src/middleware/permissionsMiddleware.js
+++ b/backend/src/middleware/permissionsMiddleware.js
@@ -88,7 +88,7 @@ const noEmailFilter = rule({
return !('email' in args)
})
-const publicRegistration = rule()(() => !!CONFIG.PUBLIC_REGISTRATION)
+const publicRegistration = rule()(() => CONFIG.PUBLIC_REGISTRATION)
const inviteRegistration = rule()(async (_parent, args, { user, driver }) => {
if (!CONFIG.INVITE_REGISTRATION) return false
@@ -132,6 +132,7 @@ export default shield(
VerifyNonce: allow,
queryLocations: isAuthenticated,
availableRoles: isAdmin,
+ getInviteCode: isAuthenticated, // and inviteRegistration
},
Mutation: {
'*': deny,
diff --git a/backend/src/schema/resolvers/inviteCodes.js b/backend/src/schema/resolvers/inviteCodes.js
index 6bb1401cd..442ff17b1 100644
--- a/backend/src/schema/resolvers/inviteCodes.js
+++ b/backend/src/schema/resolvers/inviteCodes.js
@@ -13,6 +13,52 @@ const uniqueInviteCode = async (session, code) => {
export default {
Query: {
+ getInviteCode: async (_parent, args, context, _resolveInfo) => {
+ const {
+ user: { id: userId },
+ } = context
+ const session = context.driver.session()
+ const readTxResultPromise = session.readTransaction(async (txc) => {
+ const result = await txc.run(
+ `MATCH (user:User {id: $userId})-[:GENERATED]->(ic:InviteCode)
+ WHERE ic.expiresAt IS NULL
+ OR datetime(ic.expiresAt) >= datetime()
+ RETURN properties(ic) AS inviteCodes`,
+ {
+ userId,
+ },
+ )
+ return result.records.map((record) => record.get('inviteCodes'))
+ })
+ try {
+ const inviteCode = await readTxResultPromise
+ if (inviteCode && inviteCode.length > 0) return inviteCode[0]
+ let code = generateInviteCode()
+ while (!(await uniqueInviteCode(session, code))) {
+ code = generateInviteCode()
+ }
+ const writeTxResultPromise = session.writeTransaction(async (txc) => {
+ const result = await txc.run(
+ `MATCH (user:User {id: $userId})
+ MERGE (user)-[:GENERATED]->(ic:InviteCode { code: $code })
+ ON CREATE SET
+ ic.createdAt = toString(datetime()),
+ ic.expiresAt = $expiresAt
+ RETURN ic AS inviteCode`,
+ {
+ userId,
+ code,
+ expiresAt: null,
+ },
+ )
+ return result.records.map((record) => record.get('inviteCode').properties)
+ })
+ const txResult = await writeTxResultPromise
+ return txResult[0]
+ } finally {
+ session.close()
+ }
+ },
MyInviteCodes: async (_parent, args, context, _resolveInfo) => {
const {
user: { id: userId },
diff --git a/backend/src/schema/resolvers/users/location.spec.js b/backend/src/schema/resolvers/users/location.spec.js
index 41b784249..1ef427034 100644
--- a/backend/src/schema/resolvers/users/location.spec.js
+++ b/backend/src/schema/resolvers/users/location.spec.js
@@ -114,10 +114,22 @@ describe('Location Service', () => {
const result = await query({ query: queryLocations, variables })
expect(result.data.queryLocations).toEqual([
{ id: 'place.14094307404564380', place_name: 'Berlin, Germany' },
- { id: 'place.15095411613564380', place_name: 'Berlin, Maryland, United States' },
- { id: 'place.5225018734564380', place_name: 'Berlin, Connecticut, United States' },
- { id: 'place.16922023226564380', place_name: 'Berlin, New Jersey, United States' },
- { id: 'place.4035845612564380', place_name: 'Berlin Township, New Jersey, United States' },
+ {
+ id: expect.stringMatching(/^place\.[0-9]+$/),
+ place_name: 'Berlin, Maryland, United States',
+ },
+ {
+ id: expect.stringMatching(/^place\.[0-9]+$/),
+ place_name: 'Berlin, Connecticut, United States',
+ },
+ {
+ id: expect.stringMatching(/^place\.[0-9]+$/),
+ place_name: 'Berlin, New Jersey, United States',
+ },
+ {
+ id: expect.stringMatching(/^place\.[0-9]+$/),
+ place_name: 'Berlin Township, New Jersey, United States',
+ },
])
})
@@ -128,11 +140,23 @@ describe('Location Service', () => {
}
const result = await query({ query: queryLocations, variables })
expect(result.data.queryLocations).toEqual([
- { id: 'place.14094307404564380', place_name: 'Berlin, Deutschland' },
- { id: 'place.15095411613564380', place_name: 'Berlin, Maryland, Vereinigte Staaten' },
- { id: 'place.16922023226564380', place_name: 'Berlin, New Jersey, Vereinigte Staaten' },
- { id: 'place.10735893248465990', place_name: 'Berlin Heights, Ohio, Vereinigte Staaten' },
- { id: 'place.1165756679564380', place_name: 'Berlin, Massachusetts, Vereinigte Staaten' },
+ { id: expect.stringMatching(/^place\.[0-9]+$/), place_name: 'Berlin, Deutschland' },
+ {
+ id: expect.stringMatching(/^place\.[0-9]+$/),
+ place_name: 'Berlin, Maryland, Vereinigte Staaten',
+ },
+ {
+ id: expect.stringMatching(/^place\.[0-9]+$/),
+ place_name: 'Berlin, New Jersey, Vereinigte Staaten',
+ },
+ {
+ id: expect.stringMatching(/^place\.[0-9]+$/),
+ place_name: 'Berlin Heights, Ohio, Vereinigte Staaten',
+ },
+ {
+ id: expect.stringMatching(/^place\.[0-9]+$/),
+ place_name: 'Berlin, Massachusetts, Vereinigte Staaten',
+ },
])
})
diff --git a/backend/src/schema/types/type/InviteCode.gql b/backend/src/schema/types/type/InviteCode.gql
index 8ad7851a2..3293c735b 100644
--- a/backend/src/schema/types/type/InviteCode.gql
+++ b/backend/src/schema/types/type/InviteCode.gql
@@ -14,4 +14,5 @@ type Mutation {
type Query {
MyInviteCodes: [InviteCode]
isValidInviteCode(code: ID!): Boolean
+ getInviteCode: InviteCode
}
diff --git a/webapp/assets/_new/icons/svgs/copy.svg b/webapp/assets/_new/icons/svgs/copy.svg
new file mode 100644
index 000000000..1792f2002
--- /dev/null
+++ b/webapp/assets/_new/icons/svgs/copy.svg
@@ -0,0 +1,5 @@
+
+
diff --git a/webapp/components/Editor/Editor.spec.js b/webapp/components/Editor/Editor.spec.js
index ee762b332..f51c5782f 100644
--- a/webapp/components/Editor/Editor.spec.js
+++ b/webapp/components/Editor/Editor.spec.js
@@ -99,6 +99,37 @@ describe('Editor.vue', () => {
})
})
+ it('suggestion list returns results prefixed by query', () => {
+ const manyUsersList = []
+ for (let i = 0; i < 10; i++) {
+ manyUsersList.push({ id: `user${i}` })
+ manyUsersList.push({ id: `admin${i}` })
+ manyUsersList.push({ id: `moderator${i}` })
+ }
+ propsData.users = manyUsersList
+ wrapper = Wrapper()
+ const suggestionList = wrapper.vm.editor.extensions.options.mention.onFilter(
+ propsData.users,
+ 'moderator',
+ )
+ expect(suggestionList).toHaveLength(10)
+ for (var i = 0; i < suggestionList.length; i++) {
+ expect(suggestionList[i].id).toMatch(/^moderator.*/)
+ }
+ })
+
+ it('exact match appears at the top of suggestion list', () => {
+ const manyUsersList = []
+ for (let i = 0; i < 25; i++) {
+ manyUsersList.push({ id: `user${i}` })
+ }
+ propsData.users = manyUsersList
+ wrapper = Wrapper()
+ expect(
+ wrapper.vm.editor.extensions.options.mention.onFilter(propsData.users, 'user7')[0].id,
+ ).toMatch('user7')
+ })
+
it('sets the Hashtag items to the hashtags', () => {
propsData.hashtags = [
{
diff --git a/webapp/components/Editor/Editor.vue b/webapp/components/Editor/Editor.vue
index 67329a60b..cf0fd710b 100644
--- a/webapp/components/Editor/Editor.vue
+++ b/webapp/components/Editor/Editor.vue
@@ -185,6 +185,9 @@ export default {
if (this.suggestionType === HASHTAG && this.query !== '') {
this.selectItem({ id: this.query })
}
+ if (this.suggestionType === MENTION && item) {
+ this.selectItem(item)
+ }
return true
default:
@@ -199,9 +202,14 @@ export default {
const filteredList = items.filter((item) => {
const itemString = item.slug || item.id
- return itemString.toLowerCase().includes(query.toLowerCase())
+ return itemString.toLowerCase().startsWith(query.toLowerCase())
})
- return filteredList.slice(0, 15)
+ const sortedList = filteredList.sort((itemA, itemB) => {
+ const aString = itemA.slug || itemA.id
+ const bString = itemB.slug || itemB.id
+ return aString.length - bString.length
+ })
+ return sortedList.slice(0, 15)
},
sanitizeQuery(query) {
if (this.suggestionType === HASHTAG) {
diff --git a/webapp/components/InviteButton/InviteButton.vue b/webapp/components/InviteButton/InviteButton.vue
new file mode 100644
index 000000000..9eec37bc2
--- /dev/null
+++ b/webapp/components/InviteButton/InviteButton.vue
@@ -0,0 +1,113 @@
+
+