Skip to content

Commit

Permalink
Feat/email login flow (#480)
Browse files Browse the repository at this point in the history
* build(deps): bump file-type from 16.5.3 to 16.5.4 (#475)

Bumps [file-type](https://github.com/sindresorhus/file-type) from 16.5.3 to 16.5.4.
- [Release notes](https://github.com/sindresorhus/file-type/releases)
- [Commits](sindresorhus/file-type@v16.5.3...v16.5.4)

---
updated-dependencies:
- dependency-name: file-type
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: package.json & package-lock.json to reduce vulnerabilities (#476)

The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/SNYK-JS-SEQUELIZE-2959225

* build(deps): bump vm2 from 3.9.5 to 3.9.7 (#350)

Bumps [vm2](https://github.com/patriksimek/vm2) from 3.9.5 to 3.9.7.
- [Release notes](https://github.com/patriksimek/vm2/releases)
- [Changelog](https://github.com/patriksimek/vm2/blob/master/CHANGELOG.md)
- [Commits](patriksimek/vm2@3.9.5...3.9.7)

---
updated-dependencies:
- dependency-name: vm2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Chore: remove site links from description (#482)

* Fix: update resource room (#481)

* 0.10.0

* fix: remove unnecessary update step (#487)

* 0.10.1

* Chore: update commit message to include user id

* Feat: add login and verify endpoints

* Fix: model relations and alias

* Feat: add findSitesByUserId

* Feat: add site retrieval for email and admin users

* Fix: hasAccessToSite

* Fix: update email/mobile by isomer id

* Chore: update error message

* Fix: await check for whitelist

* Chore: add mockSessionData for email login

* Fix: SiteService behaviour for email users with no whitelisted sites

* Test: update sitesservice tests

* Test: add new authservice tests and fix existing tests

* Fix: update user model to allow null in github field

* Fix: update test fixture

* Fix: update user test suite

* Chore: remove unused endpoint

* Fix: rebase errors

* Chore: remove unnecessary message in test

* Chore: remove unnecessary userId field

* Nit: rename variable

* Refactor: shift site retrieval for email users into helper method

* Chore: spacing and remove unused var

* Fix: tests

* Tests: add new authorizationMiddlewareService test

* fix: remove resources_name and add support for url (#490)

* fix: remove resources_name and add support for url

* fix: display url parameter as domain but store with https scheme

* fix: resolve failing tests

* Chore: flip conditional

* Refactor: shift order of getSites to make it easier to understand

* Test: add new auth router tests

* Feat: add integration tests for getSites

* Fix: failing requests for getLastUpdated and getStagingUrl

* Nit: add comment

* Nit: test name and var name

* chore(mocks/axios): remove extra stuff

* test(sites.spec): refactor specs for clarity

* Fix: update settings

* Nit: update comment

* Fix: tests

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Snyk bot <[email protected]>
Co-authored-by: Hsu Zhong Jun <[email protected]>
Co-authored-by: seaerchin <[email protected]>
  • Loading branch information
5 people authored Sep 9, 2022
1 parent 55ed491 commit 656dc7d
Show file tree
Hide file tree
Showing 34 changed files with 984 additions and 199 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v0.10.1](https://github.com/isomerpages/isomercms-backend/compare/v0.10.0...v0.10.1)

- fix: remove unnecessary update step [`#487`](https://github.com/isomerpages/isomercms-backend/pull/487)
- 0.10.0 [`#484`](https://github.com/isomerpages/isomercms-backend/pull/484)

#### [v0.10.0](https://github.com/isomerpages/isomercms-backend/compare/v0.9.0...v0.10.0)

> 11 August 2022
- Fix: update resource room [`#481`](https://github.com/isomerpages/isomercms-backend/pull/481)
- Chore: remove site links from description [`#482`](https://github.com/isomerpages/isomercms-backend/pull/482)
- build(deps): bump vm2 from 3.9.5 to 3.9.7 [`#350`](https://github.com/isomerpages/isomercms-backend/pull/350)
- fix: package.json & package-lock.json to reduce vulnerabilities [`#476`](https://github.com/isomerpages/isomercms-backend/pull/476)
- build(deps): bump file-type from 16.5.3 to 16.5.4 [`#475`](https://github.com/isomerpages/isomercms-backend/pull/475)
- 0.9.0 [`#473`](https://github.com/isomerpages/isomercms-backend/pull/473)

#### [v0.9.0](https://github.com/isomerpages/isomercms-backend/compare/v0.8.0...v0.9.0)

> 14 July 2022
- Misc Backend Cleanup 1 [`#470`](https://github.com/isomerpages/isomercms-backend/pull/470)
- 0.8.0 [`#468`](https://github.com/isomerpages/isomercms-backend/pull/468)

Expand Down
70 changes: 43 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "isomercms",
"version": "0.9.0",
"version": "0.10.1",
"private": true,
"scripts": {
"build": "tsc -p tsconfig.build.json",
Expand Down Expand Up @@ -41,7 +41,7 @@
"dotenv": "^16.0.1",
"exponential-backoff": "^3.1.0",
"express": "~4.16.1",
"file-type": "^16.5.3",
"file-type": "^16.5.4",
"helmet": "^4.6.0",
"http-errors": "~1.8.0",
"is-svg": "^4.3.1",
Expand All @@ -60,7 +60,7 @@
"pg-connection-string": "^2.5.0",
"query-string": "^6.14.1",
"reflect-metadata": "^0.1.13",
"sequelize": "^6.17.0",
"sequelize": "^6.21.2",
"sequelize-typescript": "^2.1.3",
"serialize-error": "^7.0.1",
"slugify": "^1.6.0",
Expand Down
3 changes: 0 additions & 3 deletions src/__mocks__/axios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import mockAxios from "jest-mock-axios"

mockAxios.interceptors.request.use(jest.fn())
mockAxios.interceptors.response.use(jest.fn())

export default mockAxios
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.changeColumn("users", "github_id", {
allowNull: true,
unique: true,
type: Sequelize.TEXT,
validate: {
notEmpty: true,
},
})
},

async down(queryInterface, Sequelize) {
await queryInterface.changeColumn("users", "github_id", {
allowNull: false,
unique: true,
type: Sequelize.TEXT,
validate: {
notEmpty: true,
},
})
},
}
5 changes: 4 additions & 1 deletion src/database/models/Site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class Site extends Model {
onUpdate: "CASCADE",
onDelete: "CASCADE",
through: () => SiteMember,
as: "site_members",
})
users!: User[]

Expand All @@ -80,6 +81,8 @@ export class Site extends Model {
@ForeignKey(() => User)
creatorId!: number

@BelongsTo(() => User)
@BelongsTo(() => User, {
as: "site_creator",
})
creator!: User
}
9 changes: 6 additions & 3 deletions src/database/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class User extends Model {
email?: string | null

@Column({
allowNull: false,
allowNull: true,
unique: true,
type: DataType.TEXT,
validate: {
Expand Down Expand Up @@ -61,13 +61,16 @@ export class User extends Model {
@DeletedAt
deletedAt?: Date

@BelongsToMany(() => User, {
@BelongsToMany(() => Site, {
onUpdate: "CASCADE",
onDelete: "CASCADE",
through: () => SiteMember,
as: "site_members",
})
sites!: Site[]

@HasMany(() => Site)
@HasMany(() => Site, {
as: "sites_created",
})
sitesCreated?: Site[]
}
3 changes: 1 addition & 2 deletions src/fixtures/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const configContent = {
const configSha = "configsha"

const configResponse = {
url: configContent.url,
url: configContent.url.replace("https://", ""),
title: configContent.title,
description: configContent.description,
favicon: configContent.favicon,
Expand All @@ -127,7 +127,6 @@ const configResponse = {
facebook_pixel: configContent["facebook-pixel"],
google_analytics: configContent.google_analytics,
linkedin_insights: configContent["linkedin-insights"],
resources_name: configContent.resources_name,
colors: configContent.colors,
}

Expand Down
11 changes: 10 additions & 1 deletion src/fixtures/sessionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import UserWithSiteSessionData from "@root/classes/UserWithSiteSessionData"

export const mockAccessToken = "mockAccessToken"
export const mockGithubId = "mockGithubId"
export const mockIsomerUserId = "mockIsomerUserId"
export const mockIsomerUserId = "1"
export const mockEmail = "mockEmail"
export const mockTreeSha = "mockTreeSha"
export const mockCurrentCommitSha = "mockCurrentCommitSha"
Expand Down Expand Up @@ -34,3 +34,12 @@ export const mockGithubSessionData = new GithubSessionData({
treeSha: mockTreeSha,
currentCommitSha: mockCurrentCommitSha,
})
export const mockSessionDataEmailUser = new UserSessionData({
isomerUserId: mockIsomerUserId,
email: mockEmail,
})
export const mockSessionDataEmailUserWithSite = new UserWithSiteSessionData({
isomerUserId: mockIsomerUserId,
email: mockEmail,
siteName: mockSiteName,
})
Loading

0 comments on commit 656dc7d

Please sign in to comment.