mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
47152cf05b
* refactor: user creation screen cleanup * feat: deprecation notice for google sso * fix: docs openid typo * invite link bar * invite link page * fix prettier docs * regenerated openapi * hooks for invite page api * update openapi * feat: invite link update * feat: add public signup token soft-delete * public signup frontend feature flag * fix: new user api issues * feat: allow for creating new user from invite link * Feat/invite user public controller (#2106) * added PublicInviteController for public urls * added PublicInviteController for public urls * added PublicInviteController for public urls * added PublicInviteController for public urls * fix test * fix test * update openapi * refactor: password reset props * fix: public invite schema and validation Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com> * user invite frontend Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com> * invite link delete confirmation dialog * refactor: password reset action * fix: new user invite loading state * fix: run ts check with ci * revert openapi changes * fix: invite token api interface * fix: openapi schema index * fix: update test snapshots * update frontend snapshot * fix: prettier ci * fix: updates after review Co-authored-by: andreas-unleash <104830839+andreas-unleash@users.noreply.github.com> Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>
97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import { IPublicSignupTokenStore } from '../../lib/types/stores/public-signup-token-store';
|
|
import { PublicSignupTokenSchema } from '../../lib/openapi/spec/public-signup-token-schema';
|
|
import { IPublicSignupTokenCreate } from '../../lib/types/models/public-signup-token';
|
|
|
|
export default class FakePublicSignupStore implements IPublicSignupTokenStore {
|
|
tokens: PublicSignupTokenSchema[] = [];
|
|
|
|
async addTokenUser(secret: string, userId: number): Promise<void> {
|
|
this.get(secret).then((token) => token.users.push({ id: userId }));
|
|
return Promise.resolve();
|
|
}
|
|
|
|
async get(secret: string): Promise<PublicSignupTokenSchema> {
|
|
const token = this.tokens.find((t) => t.secret === secret);
|
|
return Promise.resolve(token);
|
|
}
|
|
|
|
async isValid(secret: string): Promise<boolean> {
|
|
const token = this.tokens.find((t) => t.secret === secret);
|
|
return Promise.resolve(
|
|
token && new Date(token.expiresAt) > new Date() && token.enabled,
|
|
);
|
|
}
|
|
|
|
async count(): Promise<number> {
|
|
return Promise.resolve(0);
|
|
}
|
|
|
|
// eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
|
|
async delete(secret: string): Promise<void> {
|
|
return Promise.resolve(undefined);
|
|
}
|
|
|
|
async getAllActive(): Promise<PublicSignupTokenSchema[]> {
|
|
return Promise.resolve(this.tokens);
|
|
}
|
|
|
|
async create(
|
|
newToken: IPublicSignupTokenCreate,
|
|
): Promise<PublicSignupTokenSchema> {
|
|
return this.insert(newToken);
|
|
}
|
|
|
|
async insert(
|
|
newToken: IPublicSignupTokenCreate,
|
|
): Promise<PublicSignupTokenSchema> {
|
|
const token = {
|
|
secret: 'some-secret',
|
|
expiresAt: newToken.expiresAt.toISOString(),
|
|
createdAt: new Date().toISOString(),
|
|
users: [],
|
|
url: 'some=url',
|
|
name: newToken.name,
|
|
role: {
|
|
name: 'Viewer',
|
|
type: '',
|
|
id: 1,
|
|
},
|
|
enabled: true,
|
|
createdBy: newToken.createdBy,
|
|
};
|
|
this.tokens.push(token);
|
|
return Promise.resolve(token);
|
|
}
|
|
|
|
async update(
|
|
secret: string,
|
|
{ expiresAt, enabled }: { expiresAt?: Date; enabled?: boolean },
|
|
): Promise<PublicSignupTokenSchema> {
|
|
const token = await this.get(secret);
|
|
if (expiresAt) {
|
|
token.expiresAt = expiresAt.toISOString();
|
|
}
|
|
if (enabled !== undefined) {
|
|
token.enabled = enabled;
|
|
}
|
|
const index = this.tokens.findIndex((t) => t.secret === secret);
|
|
this.tokens[index] = token;
|
|
return Promise.resolve(token);
|
|
}
|
|
|
|
async deleteAll(): Promise<void> {
|
|
return Promise.resolve(undefined);
|
|
}
|
|
|
|
destroy(): void {}
|
|
|
|
async exists(key: string): Promise<boolean> {
|
|
return this.tokens.some((t) => t.secret === key);
|
|
}
|
|
|
|
// eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
|
|
async getAll(query?: Object): Promise<PublicSignupTokenSchema[]> {
|
|
return Promise.resolve(this.tokens);
|
|
}
|
|
}
|