mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch '1319-email-optin' of https://github.com/gradido/gradido into 1319-email-optin
This commit is contained in:
commit
ce0cc2c1b7
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@ -509,16 +509,13 @@ jobs:
|
||||
##########################################################################
|
||||
# UNIT TESTS BACKEND #####################################################
|
||||
##########################################################################
|
||||
- name: backend | docker-compose
|
||||
- name: backend | docker-compose mariadb
|
||||
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb
|
||||
- name: Sleep for 30 seconds
|
||||
run: sleep 30s
|
||||
shell: bash
|
||||
- name: backend | docker-compose database
|
||||
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps database
|
||||
- name: Sleep for 30 seconds
|
||||
run: sleep 30s
|
||||
shell: bash
|
||||
- name: backend Unit tests | test
|
||||
run: cd database && yarn && yarn build && cd ../backend && yarn && yarn test
|
||||
# run: docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T backend yarn test
|
||||
|
||||
@ -60,12 +60,12 @@
|
||||
"typescript": "^4.3.4"
|
||||
},
|
||||
"_moduleAliases": {
|
||||
"@": "./src",
|
||||
"@arg": "./src/graphql/arg",
|
||||
"@": "./build/src",
|
||||
"@arg": "./build/src/graphql/arg",
|
||||
"@dbTools": "../database/build/src",
|
||||
"@entity": "../database/build/entity",
|
||||
"@enum": "./src/graphql/enum",
|
||||
"@model": "./src/graphql/model",
|
||||
"@repository": "./src/typeorm/repository"
|
||||
"@enum": "./build/src/graphql/enum",
|
||||
"@model": "./build/src/graphql/model",
|
||||
"@repository": "./build/src/typeorm/repository"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { testEnvironment, resetEntities, createUser } from '@test/helpers'
|
||||
import { testEnvironment, createUser, headerPushMock, cleanDB } from '@test/helpers'
|
||||
import { createUserMutation, setPasswordMutation } from '@test/graphql'
|
||||
import gql from 'graphql-tag'
|
||||
import { GraphQLError } from 'graphql'
|
||||
import { resetDB } from '@dbTools/helpers'
|
||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||
import { User } from '@entity/User'
|
||||
import CONFIG from '@/config'
|
||||
@ -30,29 +29,18 @@ jest.mock('@/apis/KlicktippController', () => {
|
||||
})
|
||||
*/
|
||||
|
||||
let token: string
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const headerPushMock = jest.fn((t) => (token = t.value))
|
||||
|
||||
const context = {
|
||||
setHeaders: {
|
||||
push: headerPushMock,
|
||||
forEach: jest.fn(),
|
||||
},
|
||||
}
|
||||
|
||||
let mutate: any, query: any, con: any
|
||||
|
||||
beforeAll(async () => {
|
||||
const testEnv = await testEnvironment(context)
|
||||
const testEnv = await testEnvironment()
|
||||
mutate = testEnv.mutate
|
||||
query = testEnv.query
|
||||
con = testEnv.con
|
||||
await cleanDB()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await resetDB(true)
|
||||
await cleanDB()
|
||||
await con.close()
|
||||
})
|
||||
|
||||
@ -75,7 +63,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await resetEntities([User, LoginEmailOptIn])
|
||||
await cleanDB()
|
||||
})
|
||||
|
||||
it('returns success', () => {
|
||||
@ -213,7 +201,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await resetEntities([User, LoginEmailOptIn])
|
||||
await cleanDB()
|
||||
})
|
||||
|
||||
it('sets email checked to true', () => {
|
||||
@ -256,7 +244,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await resetEntities([User, LoginEmailOptIn])
|
||||
await cleanDB()
|
||||
})
|
||||
|
||||
it('throws an error', () => {
|
||||
@ -282,7 +270,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await resetEntities([User, LoginEmailOptIn])
|
||||
await cleanDB()
|
||||
})
|
||||
|
||||
it('throws an error', () => {
|
||||
@ -323,7 +311,7 @@ describe('UserResolver', () => {
|
||||
let result: User
|
||||
|
||||
afterAll(async () => {
|
||||
await resetEntities([User, LoginEmailOptIn])
|
||||
await cleanDB()
|
||||
})
|
||||
|
||||
describe('no users in database', () => {
|
||||
@ -353,7 +341,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await resetEntities([User, LoginEmailOptIn])
|
||||
await cleanDB()
|
||||
})
|
||||
|
||||
it('returns the user object', () => {
|
||||
|
||||
@ -191,11 +191,9 @@ const getOptInCode = async (loginUserId: number): Promise<LoginEmailOptIn> => {
|
||||
// Check for 10 minute delay
|
||||
if (optInCode) {
|
||||
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
|
||||
if (timeElapsed <= parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
|
||||
if (timeElapsed < parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
|
||||
throw new Error(
|
||||
'email already sent less than ' +
|
||||
parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) +
|
||||
' minutes ago',
|
||||
`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`
|
||||
)
|
||||
} else {
|
||||
optInCode.updatedAt = new Date()
|
||||
|
||||
@ -7,8 +7,28 @@ import { resetDB, initialize } from '@dbTools/helpers'
|
||||
import { createUserMutation, setPasswordMutation } from './graphql'
|
||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||
import { User } from '@entity/User'
|
||||
import { entities } from '@entity/index'
|
||||
|
||||
export const testEnvironment = async (context: any) => {
|
||||
let token = ''
|
||||
|
||||
export const headerPushMock = jest.fn((t) => (token = t.value))
|
||||
|
||||
const context = {
|
||||
token,
|
||||
setHeaders: {
|
||||
push: headerPushMock,
|
||||
forEach: jest.fn(),
|
||||
},
|
||||
}
|
||||
|
||||
export const cleanDB = async () => {
|
||||
// this only works as lond we do not have foreign key constraints
|
||||
for (let i = 0; i < entities.length; i++) {
|
||||
await resetEntity(entities[i])
|
||||
}
|
||||
}
|
||||
|
||||
export const testEnvironment = async () => {
|
||||
const server = await createServer(context)
|
||||
const con = server.con
|
||||
const testClient = createTestClient(server.apollo)
|
||||
@ -27,12 +47,6 @@ export const resetEntity = async (entity: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const resetEntities = async (entities: any[]) => {
|
||||
for (let i = 0; i < entities.length; i++) {
|
||||
await resetEntity(entities[i])
|
||||
}
|
||||
}
|
||||
|
||||
export const createUser = async (mutate: any, user: any) => {
|
||||
await mutate({ mutation: createUserMutation, variables: user })
|
||||
const dbUser = await User.findOne({ where: { email: user.email } })
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
$GRADIDO_LOG_PATH/* {
|
||||
$GRADIDO_LOG_PATH/*.log {
|
||||
weekly
|
||||
rotate 26
|
||||
size 10M
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
Gradido is currently updating...<br>
|
||||
please stand by and try again in some minutes<br>
|
||||
<br>
|
||||
<pre>
|
||||
Gradido is currently updating...
|
||||
please stand by and try again in some minutes
|
||||
|
||||
|
||||
@ -42,30 +42,38 @@ if [ -f $LOCK_FILE ] ; then
|
||||
fi
|
||||
touch $LOCK_FILE
|
||||
|
||||
# find today string
|
||||
TODAY=$(date +"%Y-%m-%d")
|
||||
|
||||
# Create a new updating.html from the template
|
||||
\cp $SCRIPT_DIR/nginx/update-page/updating.html.template $UPDATE_HTML
|
||||
|
||||
# redirect all output of the script to the UPDATE_HTML and also have things on console
|
||||
# TODO: this might pose a security risk
|
||||
exec > >(tee -a $UPDATE_HTML) 2>&1
|
||||
|
||||
# configure nginx for the update-page
|
||||
echo 'Configuring nginx to serve the update-page<br>' >> $UPDATE_HTML
|
||||
echo 'Configuring nginx to serve the update-page' >> $UPDATE_HTML
|
||||
rm /etc/nginx/sites-enabled/gradido.conf
|
||||
ln -s /etc/nginx/sites-available/update-page.conf /etc/nginx/sites-enabled/
|
||||
sudo /etc/init.d/nginx restart
|
||||
|
||||
# stop all services
|
||||
echo 'Stopping all Gradido services<br>' >> $UPDATE_HTML
|
||||
echo 'Stopping all Gradido services' >> $UPDATE_HTML
|
||||
pm2 stop all
|
||||
|
||||
# git
|
||||
BRANCH=${1:-master}
|
||||
echo "Starting with git pull - branch:$BRANCH<br>" >> $UPDATE_HTML
|
||||
echo "Starting with git pull - branch:$BRANCH" >> $UPDATE_HTML
|
||||
cd $PROJECT_ROOT
|
||||
git fetch origin $BRANCH
|
||||
# TODO: this overfetches alot, but ensures we can use start.sh with tags
|
||||
git fetch origin --all
|
||||
git checkout $BRANCH
|
||||
git pull
|
||||
export BUILD_COMMIT="$(git rev-parse HEAD)"
|
||||
|
||||
# Generate gradido.conf from template
|
||||
echo 'Generate new gradido nginx config<br>' >> $UPDATE_HTML
|
||||
echo 'Generate new gradido nginx config' >> $UPDATE_HTML
|
||||
case "$NGINX_SSL" in
|
||||
true) TEMPLATE_FILE="gradido.conf.ssl.template" ;;
|
||||
*) TEMPLATE_FILE="gradido.conf.template" ;;
|
||||
@ -73,7 +81,7 @@ esac
|
||||
envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $NGINX_CONFIG_DIR/$TEMPLATE_FILE > $NGINX_CONFIG_DIR/gradido.conf
|
||||
|
||||
# Generate update-page.conf from template
|
||||
echo 'Generate new update-page nginx config<br>' >> $UPDATE_HTML
|
||||
echo 'Generate new update-page nginx config' >> $UPDATE_HTML
|
||||
case "$NGINX_SSL" in
|
||||
true) TEMPLATE_FILE="update-page.conf.ssl.template" ;;
|
||||
*) TEMPLATE_FILE="update-page.conf.template" ;;
|
||||
@ -91,7 +99,7 @@ envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/frontend/.env
|
||||
envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/admin/.env.template > $PROJECT_ROOT/admin/.env
|
||||
|
||||
# Install & build database
|
||||
echo 'Updating database<br>' >> $UPDATE_HTML
|
||||
echo 'Updating database' >> $UPDATE_HTML
|
||||
cd $PROJECT_ROOT/database
|
||||
yarn install
|
||||
yarn build
|
||||
@ -104,7 +112,7 @@ else
|
||||
fi
|
||||
|
||||
# Install & build backend
|
||||
echo 'Updating backend<br>' >> $UPDATE_HTML
|
||||
echo 'Updating backend' >> $UPDATE_HTML
|
||||
cd $PROJECT_ROOT/backend
|
||||
# TODO maybe handle this differently?
|
||||
unset NODE_ENV
|
||||
@ -113,11 +121,11 @@ yarn build
|
||||
# TODO maybe handle this differently?
|
||||
export NODE_ENV=production
|
||||
pm2 delete gradido-backend
|
||||
pm2 start --name gradido-backend "yarn --cwd $PROJECT_ROOT/backend start" -l $GRADIDO_LOG_PATH/pm2.backend.log --log-date-format 'DD-MM HH:mm:ss.SSS'
|
||||
pm2 start --name gradido-backend "yarn --cwd $PROJECT_ROOT/backend start" -l $GRADIDO_LOG_PATH/pm2.backend.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS'
|
||||
pm2 save
|
||||
|
||||
# Install & build frontend
|
||||
echo 'Updating frontend<br>' >> $UPDATE_HTML
|
||||
echo 'Updating frontend' >> $UPDATE_HTML
|
||||
cd $PROJECT_ROOT/frontend
|
||||
# TODO maybe handle this differently?
|
||||
unset NODE_ENV
|
||||
@ -126,11 +134,11 @@ yarn build
|
||||
# TODO maybe handle this differently?
|
||||
export NODE_ENV=production
|
||||
pm2 delete gradido-frontend
|
||||
pm2 start --name gradido-frontend "yarn --cwd $PROJECT_ROOT/frontend start" -l $GRADIDO_LOG_PATH/pm2.frontend.log --log-date-format 'DD-MM HH:mm:ss.SSS'
|
||||
pm2 start --name gradido-frontend "yarn --cwd $PROJECT_ROOT/frontend start" -l $GRADIDO_LOG_PATH/pm2.frontend.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS'
|
||||
pm2 save
|
||||
|
||||
# Install & build admin
|
||||
echo 'Updating admin<br>' >> $UPDATE_HTML
|
||||
echo 'Updating admin' >> $UPDATE_HTML
|
||||
cd $PROJECT_ROOT/admin
|
||||
# TODO maybe handle this differently?
|
||||
unset NODE_ENV
|
||||
@ -139,14 +147,17 @@ yarn build
|
||||
# TODO maybe handle this differently?
|
||||
export NODE_ENV=production
|
||||
pm2 delete gradido-admin
|
||||
pm2 start --name gradido-admin "yarn --cwd $PROJECT_ROOT/admin start" -l $GRADIDO_LOG_PATH/pm2.admin.log --log-date-format 'DD-MM HH:mm:ss.SSS'
|
||||
pm2 start --name gradido-admin "yarn --cwd $PROJECT_ROOT/admin start" -l $GRADIDO_LOG_PATH/pm2.admin.$TODAY.log --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS'
|
||||
pm2 save
|
||||
|
||||
# let nginx showing gradido
|
||||
echo 'Configuring nginx to serve gradido again<br>' >> $UPDATE_HTML
|
||||
echo 'Configuring nginx to serve gradido again' >> $UPDATE_HTML
|
||||
ln -s /etc/nginx/sites-available/gradido.conf /etc/nginx/sites-enabled/
|
||||
rm /etc/nginx/sites-enabled/update-page.conf
|
||||
sudo /etc/init.d/nginx restart
|
||||
|
||||
# keep the update log
|
||||
cat $UPDATE_HTML >> $GRADIDO_LOG_PATH/update.$TODAY.log
|
||||
|
||||
# release lock
|
||||
rm $LOCK_FILE
|
||||
@ -201,7 +201,7 @@
|
||||
"uppercase": "Großbuchstabe erforderlich."
|
||||
},
|
||||
"thx": {
|
||||
"activateEmail": "Dein Konto wurde noch nicht aktiviert. Bitte überprüfe deine E-Mail und klicke den Aktivierungslink! Oder fordere einen neuen Aktivierungslink über die password reset seite.",
|
||||
"activateEmail": "Dein Konto wurde noch nicht aktiviert. Bitte überprüfe deine E-Mail und klicke den Aktivierungslink oder fordere einen neuen Aktivierungslink über die Password Reset Seite.",
|
||||
"checkEmail": "Deine E-Mail wurde erfolgreich verifiziert. Du kannst dich jetzt anmelden.",
|
||||
"email": "Wir haben dir eine E-Mail gesendet.",
|
||||
"emailActivated": "Danke dass Du deine E-Mail bestätigt hast.",
|
||||
|
||||
@ -201,7 +201,7 @@
|
||||
"uppercase": "One uppercase letter required."
|
||||
},
|
||||
"thx": {
|
||||
"activateEmail": "Your account has not been activated yet, please check your emails and click the activation link! Or order a new activation link over the password reset page.",
|
||||
"activateEmail": "Your account has not been activated yet, please check your emails and click the activation link or order a new activation link over the password reset page.",
|
||||
"checkEmail": "Your email has been successfully verified. You can sign in now.",
|
||||
"email": "We have sent you an email.",
|
||||
"emailActivated": "Thank you your email has been activated.",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user