Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tibetsprague committed May 12, 2023
2 parents e466051 + 765fac6 commit 061c944
Show file tree
Hide file tree
Showing 18 changed files with 272 additions and 96 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [5.5.0] - 2023-05-12

### Added
- Initial internationalization support, and translations of emails and notifications into Spanish

## [5.4.1] - 2023-04-11

### Added
Expand Down
12 changes: 8 additions & 4 deletions api/controllers/UserController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { en } from '../../lib/i18n/en'
import { es } from '../../lib/i18n/es'
import InvitationService from '../services/InvitationService'
import OIDCAdapter from '../services/oidc/KnexAdapter'
const locales = {es, en}

module.exports = {

Expand All @@ -12,17 +15,18 @@ module.exports = {
if (user) {
// User already exists
if (group) {
const locale = user?.get('settings')?.locale || 'en'
if (!(await GroupMembership.hasActiveMembership(user, group))) {
// If user exists but is not part of the group then invite them
let message = `${req.api_client} is excited to invite you to join our community on Hylo.`
let subject = `Join me in ${group.get('name')} on Hylo!`
let message = locales[locale].apiInviteMessageContent(req.api_client)
let subject = locales[locale].apiInviteMessageSubject(group.get('name'))
if (req.api_client) {
const client = await (new OIDCAdapter("Client")).find(req.api_client.id)
if (!client) {
return res.status(403).json({ error: 'Unauthorized' })
}
subject = client.invite_subject || `You've been invited to join ${group.get('name')} on Hylo`
message = client.invite_message || `Hi ${user.get('name')}, <br><br> We're excited to welcome you into our community. Click below to join ${group.get('name')} on Hylo.`
subject = client.invite_subject || locales[locale].clientInviteSubjectDefault(group.get('name'))
message = client.invite_message || locales[locale].clientInviteMessageDefault({userName: user.get('name'), groupName: group.get('name')})
}
const inviteBy = await group.moderators().fetchOne()

Expand Down
2 changes: 1 addition & 1 deletion api/graphql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export function makeMutations (expressContext, userId, isAdmin, fetchOne) {
createGroup: (root, { data }) => createGroup(userId, data),

createInvitation: (root, {groupId, data}) =>
createInvitation(userId, groupId, data),
createInvitation(userId, groupId, data), // consider sending locale from the frontend here

createJoinRequest: (root, {groupId, questionAnswers}) => createJoinRequest(userId, groupId, questionAnswers),

Expand Down
7 changes: 6 additions & 1 deletion api/graphql/mutations/invitation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const { GraphQLYogaError } = require('@graphql-yoga/node')
import { es } from '../../../lib/i18n/es'
import { en } from '../../../lib/i18n/en'
import InvitationService from '../../services/InvitationService'
const locales = {es, en}

export async function createInvitation (userId, groupId, data) {
const group = await Group.find(groupId)
const user = await User.find(userId)
const locale = user.get('settings')?.locale || 'en'
return GroupMembership.hasModeratorRole(userId, group)
.then(ok => {
if (!ok) throw new GraphQLYogaError("You don't have permission to create an invitation for this group")
Expand All @@ -16,7 +21,7 @@ export async function createInvitation (userId, groupId, data) {
emails: data.emails,
message: data.message,
moderator: data.isModerator || false,
subject: `Join me in ${group.get('name')} on Hylo!`
subject: locales[locale].createInvitationSubject(group.get('name'))
})
})
.then(invitations => ({invitations}))
Expand Down
19 changes: 11 additions & 8 deletions api/models/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import HasSettings from './mixins/HasSettings'
import findOrCreateThread from './post/findOrCreateThread'
import { groupFilter } from '../graphql/filters'
import { inviteGroupToGroup } from '../graphql/mutations/group.js'

import DataType, {
getDataTypeForInstance, getDataTypeForModel, getModelForDataType
} from './group/DataType'
import convertGraphqlData from '../graphql/mutations/convertGraphqlData'
import { findOrCreateLocation } from '../graphql/mutations/location'
import { es } from '../../lib/i18n/es'
import { en } from '../../lib/i18n/en'
const locales = { es, en }

export const GROUP_ATTR_UPDATE_WHITELIST = [
'role',
Expand Down Expand Up @@ -750,15 +752,16 @@ module.exports = bookshelf.Model.extend(merge({
.then(g => {
var creator = g.relations.creator
var recipient = process.env.NEW_GROUP_EMAIL
const locale = creator.get('settings')?.locale || 'en'
return Email.sendRawEmail(recipient, {
subject: "New Hylo Group Created: " + g.get('name'),
body: `Group
Name: ${g.get('name')}
subject: locales[locale].groupCreatedNotifySubject(g.get('name')),
body: `${locales[locale].Group()}
${locales[locale].Name()}: ${g.get('name')}
URL: ${Frontend.Route.group(g)}
Creator Email: ${creator.get('email')}
Creator Name: ${creator.get('name')}
Creator URL: ${Frontend.Route.profile(creator)}
`.replace(/^\s+/gm, '').replace(/\n/g, '<br/>\n')
${locales[locale].CreatorEmail()}: ${creator.get('email')}
${locales[locale].CreatorName()}: ${creator.get('name')}
${locales[locale].CreatorURL()}: ${Frontend.Route.profile(creator)}
`.replace(/^\s+/gm, '').replace(/\n/g, '<br/>\n')
}, {
sender: {
name: 'Hylobot',
Expand Down
1 change: 1 addition & 0 deletions api/models/Invitation.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ module.exports = bookshelf.Model.extend(Object.assign({
message: this.get('message'),
inviter_name: creator.get('name'),
inviter_email: creator.get('email'),
locale: creator.get('settings').locale || 'en',
// TODO: change this data name in the email
group_name: group.get('name'),
invite_link: Frontend.Route.useInvitation(this.get('token'), email),
Expand Down
Loading

0 comments on commit 061c944

Please sign in to comment.