Feature/simplify admin user sign up (#675)
* Simplify admin user sign up * Update changelog
This commit is contained in:
parent
48b524de5a
commit
65bfe52db4
@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Improved the export functionality for activities (respect filtering)
|
- Improved the export functionality for activities (respect filtering)
|
||||||
|
- Removed the _Admin_ user from the database seeding
|
||||||
|
- Assigned the role `ADMIN` on sign up (only if there is no admin yet)
|
||||||
|
|
||||||
|
### Todo
|
||||||
|
|
||||||
|
- Apply data migration (`yarn database:migrate`)
|
||||||
|
|
||||||
## 1.111.0 - 03.02.2022
|
## 1.111.0 - 03.02.2022
|
||||||
|
|
||||||
|
12
README.md
12
README.md
@ -124,16 +124,10 @@ docker-compose -f docker/docker-compose.build.yml exec ghostfolio yarn database:
|
|||||||
|
|
||||||
Open http://localhost:3333 in your browser and accomplish these steps:
|
Open http://localhost:3333 in your browser and accomplish these steps:
|
||||||
|
|
||||||
1. Login as _Admin_ with the following _Security Token_: `ae76872ae8f3419c6d6f64bf51888ecbcc703927a342d815fafe486acdb938da07d0cf44fca211a0be74a423238f535362d390a41e81e633a9ce668a6e31cdf9`
|
1. Create a new user via _Get Started_ (this first user will get the role `ADMIN`)
|
||||||
1. Go to the _Admin Control Panel_ and click _Gather All Data_ to fetch historical data
|
1. Go to the _Admin Control Panel_ and click _Gather All Data_ to fetch historical data
|
||||||
1. Click _Sign out_ and check out the _Live Demo_
|
1. Click _Sign out_ and check out the _Live Demo_
|
||||||
|
|
||||||
### Finalization
|
|
||||||
|
|
||||||
1. Create a new user via _Get Started_
|
|
||||||
1. Assign the role `ADMIN` to this user (directly in the database)
|
|
||||||
1. Delete the original _Admin_ (directly in the database)
|
|
||||||
|
|
||||||
### Migrate Database
|
### Migrate Database
|
||||||
|
|
||||||
With the following command you can keep your database schema in sync after a Ghostfolio version update:
|
With the following command you can keep your database schema in sync after a Ghostfolio version update:
|
||||||
@ -155,8 +149,8 @@ docker-compose -f docker/docker-compose-build-local.yml exec ghostfolio yarn dat
|
|||||||
1. Run `yarn install`
|
1. Run `yarn install`
|
||||||
1. Run `docker-compose -f docker/docker-compose.dev.yml up -d` to start [PostgreSQL](https://www.postgresql.org) and [Redis](https://redis.io)
|
1. Run `docker-compose -f docker/docker-compose.dev.yml up -d` to start [PostgreSQL](https://www.postgresql.org) and [Redis](https://redis.io)
|
||||||
1. Run `yarn database:setup` to initialize the database schema and populate your database with (example) data
|
1. Run `yarn database:setup` to initialize the database schema and populate your database with (example) data
|
||||||
1. Start server and client (see [_Development_](#Development))
|
1. Start the server and the client (see [_Development_](#Development))
|
||||||
1. Login as _Admin_ with the following _Security Token_: `ae76872ae8f3419c6d6f64bf51888ecbcc703927a342d815fafe486acdb938da07d0cf44fca211a0be74a423238f535362d390a41e81e633a9ce668a6e31cdf9`
|
1. Create a new user via _Get Started_ (this first user will get the role `ADMIN`)
|
||||||
1. Go to the _Admin Control Panel_ and click _Gather All Data_ to fetch historical data
|
1. Go to the _Admin Control Panel_ and click _Gather All Data_ to fetch historical data
|
||||||
1. Click _Sign out_ and check out the _Live Demo_
|
1. Click _Sign out_ and check out the _Live Demo_
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
import { REQUEST } from '@nestjs/core';
|
import { REQUEST } from '@nestjs/core';
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
import { Provider } from '@prisma/client';
|
import { Provider, Role } from '@prisma/client';
|
||||||
import { User as UserModel } from '@prisma/client';
|
import { User as UserModel } from '@prisma/client';
|
||||||
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
|
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
|
||||||
|
|
||||||
@ -83,8 +83,10 @@ export class UserController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasAdmin = await this.userService.hasAdmin();
|
||||||
|
|
||||||
const { accessToken, id } = await this.userService.createUser({
|
const { accessToken, id } = await this.userService.createUser({
|
||||||
provider: Provider.ANONYMOUS
|
role: hasAdmin ? 'USER' : 'ADMIN'
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -70,6 +70,18 @@ export class UserService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async hasAdmin() {
|
||||||
|
const usersWithAdminRole = await this.users({
|
||||||
|
where: {
|
||||||
|
role: {
|
||||||
|
equals: 'ADMIN'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return usersWithAdminRole.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public isRestrictedView(aUser: UserWithSettings) {
|
public isRestrictedView(aUser: UserWithSettings) {
|
||||||
return (aUser.Settings.settings as UserSettings)?.isRestrictedView ?? false;
|
return (aUser.Settings.settings as UserSettings)?.isRestrictedView ?? false;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
-- Set default value
|
||||||
|
UPDATE "User" SET "provider" = 'ANONYMOUS' WHERE "provider" IS NULL;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "User" ALTER COLUMN "provider" SET NOT NULL,
|
||||||
|
ALTER COLUMN "provider" SET DEFAULT E'ANONYMOUS';
|
@ -156,7 +156,7 @@ model User {
|
|||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
Order Order[]
|
Order Order[]
|
||||||
provider Provider?
|
provider Provider @default(ANONYMOUS)
|
||||||
role Role @default(USER)
|
role Role @default(USER)
|
||||||
Settings Settings?
|
Settings Settings?
|
||||||
Subscription Subscription[]
|
Subscription Subscription[]
|
||||||
|
@ -78,30 +78,6 @@ async function main() {
|
|||||||
where: { id: '1377d9df-0d25-42c2-9d9b-e4c63156291f' }
|
where: { id: '1377d9df-0d25-42c2-9d9b-e4c63156291f' }
|
||||||
});
|
});
|
||||||
|
|
||||||
const userAdmin = await prisma.user.upsert({
|
|
||||||
create: {
|
|
||||||
accessToken:
|
|
||||||
'c689bcc894e4a420cb609ee34271f3e07f200594f7d199c50d75add7102889eb60061a04cd2792ebc853c54e37308271271e7bf588657c9e0c37faacbc28c3c6',
|
|
||||||
Account: {
|
|
||||||
create: [
|
|
||||||
{
|
|
||||||
accountType: AccountType.SECURITIES,
|
|
||||||
balance: 0,
|
|
||||||
currency: 'USD',
|
|
||||||
id: 'f4425b66-9ba9-4ac4-93d7-fdf9a145e8cb',
|
|
||||||
isDefault: true,
|
|
||||||
name: 'Default Account'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
alias: 'Admin',
|
|
||||||
id: '4e1af723-95f6-44f8-92a7-464df17f6ec3',
|
|
||||||
role: Role.ADMIN
|
|
||||||
},
|
|
||||||
update: {},
|
|
||||||
where: { id: '4e1af723-95f6-44f8-92a7-464df17f6ec3' }
|
|
||||||
});
|
|
||||||
|
|
||||||
const userDemo = await prisma.user.upsert({
|
const userDemo = await prisma.user.upsert({
|
||||||
create: {
|
create: {
|
||||||
accessToken:
|
accessToken:
|
||||||
@ -345,7 +321,6 @@ async function main() {
|
|||||||
platformInteractiveBrokers,
|
platformInteractiveBrokers,
|
||||||
platformPostFinance,
|
platformPostFinance,
|
||||||
platformSwissquote,
|
platformSwissquote,
|
||||||
userAdmin,
|
|
||||||
userDemo
|
userDemo
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user