diff --git a/src/admin/dto/unclaimed-structure-dto.ts b/src/admin/dto/unclaimed-structure-dto.ts index 53fdc2b785765869966cdbda5e097135457998d7..2a82db660976cda4e721808421426bfa96c0e72f 100644 --- a/src/admin/dto/unclaimed-structure-dto.ts +++ b/src/admin/dto/unclaimed-structure-dto.ts @@ -12,7 +12,7 @@ export class UnclaimedStructureDto { @ApiProperty({ type: String }) structureName: string; - @ApiProperty({ type: String }) + @ApiProperty({ type: Date }) updatedAt: Date; @ApiProperty({ type: String }) diff --git a/src/mailer/mail-templates/structureJoinRequest.ejs b/src/mailer/mail-templates/structureJoinRequest.ejs index cdfbb3c341198a71bc97947a5d59aaef20e0cdf9..ce6bce858f1893b640153135ec3e65b6b393c9c3 100644 --- a/src/mailer/mail-templates/structureJoinRequest.ejs +++ b/src/mailer/mail-templates/structureJoinRequest.ejs @@ -1,14 +1,14 @@ Bonjour,<br /> <br /> -Vous recevez ce message car <strong><%= surname %></strong> <strong><%= name %></strong> demande à rejoindre votre -stucture <strong><%= structureName %></strong> sur RES'in, le réseau des acteurs de l'inclusion numérique de la -Métropole de Lyon. Vous pouvez dès maintenant valider la demande en -<a - href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/join?id=<%= id %>&userId=<%= userId %>&status=true" - >cliquant ici</a -> -ou refuser la demande -<a - href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/join?id=<%= id %>&userId=<%= userId %>&status=false" - >cliquant ici</a ->. +<%= name %> <%= surname %> indique travailler au sein de votre structure <%= structureName %>.<br /> +S'il s'agit d'une erreur, merci de nous le signaler en cliquant sur le lien ci-dessous. +<br /> +<br /> +<br /> + +<div style="text-align: center"> + <a + href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/exclude?id=<%= id %>&userId=<%= userId %>" + >Signaler une erreur d'appartenance à cette structure</a + > +</div> diff --git a/src/mailer/mail-templates/structureJoinRequest.json b/src/mailer/mail-templates/structureJoinRequest.json index 8b756e80dda646b74494d044a1c027c48294ac34..23e2f607f8f7b00f73f9c39e19021af222fb33d0 100644 --- a/src/mailer/mail-templates/structureJoinRequest.json +++ b/src/mailer/mail-templates/structureJoinRequest.json @@ -1,3 +1,3 @@ { - "subject": "Un acteur demande a rejoindre votre structure, Réseau des Acteurs de la Médiation Numérique de la Métropole de Lyon" + "subject": "Un acteur a rejoint votre structure, Réseau des Acteurs de la Médiation Numérique de la Métropole de Lyon" } diff --git a/src/migrations/scripts/1653297328930-empty-pendingStructuresLink.ts b/src/migrations/scripts/1653297328930-empty-pendingStructuresLink.ts new file mode 100644 index 0000000000000000000000000000000000000000..555809d17fe47c19d6392230fac73339e3ba5361 --- /dev/null +++ b/src/migrations/scripts/1653297328930-empty-pendingStructuresLink.ts @@ -0,0 +1,17 @@ +import { Db } from 'mongodb'; +import { getDb } from '../migrations-utils/db'; + +export const up = async () => { + const db: Db = await getDb(); + const cursor = db.collection('users').find({}); + let document; + while ((document = await cursor.next())) { + await db.collection('users').updateOne({ _id: document._id }, [{ $set: { pendingStructuresLink: [] } }]); + } + console.log(`Update done : 'pendingStructuresLink' emptied in 'users' collection`); +}; + +export const down = async () => { + // Nothing can be done since 'pendingStructuresLink' cannot be filled again with previously deleted values + console.log(`Downgrade done`); +}; diff --git a/src/parameters/parameters.controller.ts b/src/parameters/parameters.controller.ts index c21cd3c97bda9547d432ef07ae6aa80696363128..fcd6e4883f3f06248445add283831a67b49b572f 100644 --- a/src/parameters/parameters.controller.ts +++ b/src/parameters/parameters.controller.ts @@ -1,10 +1,12 @@ import { Body, Controller, Post, Get, UseGuards } from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; import { Roles } from '../users/decorators/roles.decorator'; import { RolesGuard } from '../users/guards/roles.guard'; import { ParametersService } from './parameters.service'; import { Parameters } from './schemas/parameters.schema'; +@ApiTags('parameters') @Controller('parameters') export class ParametersController { constructor(private parametersService: ParametersService) {} diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index 4f3215e420579b71419f4e695c5918733a084aad..562d19ce9ebd0ffae543a17a7a8a88e83d3bccc8 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -710,7 +710,9 @@ export class StructuresService { }); const owners = await this.getOwners(structure._id); owners.forEach((owner) => { - this.mailerService.send(owner.email, jsonConfig.subject, html); + if (!owner._id.equals(user._id)) { + this.mailerService.send(owner.email, jsonConfig.subject, html); + } }); } diff --git a/src/structures/structures.controller.spec.ts b/src/structures/structures.controller.spec.ts index 033c50a86de22aa293b1464f95841bcfaf758d00..91af044377b8818545e7630527812a8c0e2e2c9e 100644 --- a/src/structures/structures.controller.spec.ts +++ b/src/structures/structures.controller.spec.ts @@ -230,17 +230,8 @@ describe('AuthController', () => { expect(res).toBeTruthy(); }); - it('should join in struct', async () => { - let res = controller.joinValidation('6093ba0e2ab5775cfc01ed3e', 'true', 'tsfsf6296'); - expect(res).toBeTruthy(); - res = controller.joinValidation('6093ba0e2ab5775cfc01ed3e', 'true', ''); - expect(res).toBeTruthy(); - res = controller.joinValidation('', 'true', ''); - expect(res).toBeTruthy(); - }); - it('should remove user from struct', async () => { - const res = controller.joinValidation('6093ba0e2ab5775cfc01ed3e', 'false', 'tsfsf6296'); + const res = controller.removeOwner('6093ba0e2ab5775cfc01ed3e', 'tsfsf6296'); expect(res).toBeTruthy(); }); diff --git a/src/structures/structures.controller.ts b/src/structures/structures.controller.ts index aaf9475cc8a250a3db24532b8b02e0334ee336a0..855826b013775147b08376c2af2d1675d4fc96e8 100644 --- a/src/structures/structures.controller.ts +++ b/src/structures/structures.controller.ts @@ -189,54 +189,14 @@ export class StructuresController { if (!structure) { throw new HttpException('Invalid Structure', HttpStatus.NOT_FOUND); } - // Get user and add pending structure + // Get user and add structure to user const userFromDb = await this.userService.findOne(user.email); if (!userFromDb) { throw new HttpException('Invalid User', HttpStatus.NOT_FOUND); } - // If user has not already request it, send owner's validation email - if (!userFromDb.pendingStructuresLink.includes(Types.ObjectId(id))) { - userFromDb.pendingStructuresLink.push(Types.ObjectId(id)); - userFromDb.save(); - // Send structure owner's an email - this.structureService.sendStructureJoinRequest(userFromDb, structure); - } - } - - @Post(':id/join/:userId/:status') - @UseGuards(JwtAuthGuard, IsStructureOwnerGuard) - @ApiParam({ name: 'id', type: String, required: true }) - @ApiParam({ name: 'userId', type: String, required: true }) - @ApiParam({ name: 'status', type: String, required: true }) - public async joinValidation( - @Param('id') id: string, - @Param('status') status: string, - @Param('userId') userId: string - ): Promise<any> { - // Get structure name - const structure = await this.structureService.findOne(id); - if (!structure) { - throw new HttpException('Invalid Structure', HttpStatus.NOT_FOUND); - } - - // Get user and add pending structure - const userFromDb = await this.userService.findById(userId); - if (!userFromDb) { - throw new HttpException('Invalid User', HttpStatus.NOT_FOUND); - } - - if (!userFromDb.pendingStructuresLink.includes(Types.ObjectId(id))) { - throw new HttpException('User not linked to structure', HttpStatus.NOT_FOUND); - } - - if (status === 'true') { - // Accept - await this.userService.updateStructureLinked(userFromDb.email, id); - await this.userService.removeFromPendingStructureLinked(userFromDb.email, id); - } else { - // Refuse - this.userService.removeFromPendingStructureLinked(userFromDb.email, id); - } + await this.userService.updateStructureLinked(userFromDb.email, id); + // Send structure owners an email + this.structureService.sendStructureJoinRequest(userFromDb, structure); } @Delete(':id/owner/:userId') diff --git a/src/users/controllers/users.controller.ts b/src/users/controllers/users.controller.ts index b896cf400da1d36e0f410fc3c85a39e40ed025b6..2e6eabdadfa83a1dee853243c6b0be1aa95dd923 100644 --- a/src/users/controllers/users.controller.ts +++ b/src/users/controllers/users.controller.ts @@ -193,6 +193,13 @@ export class UsersController { return this.structureService.getAllDataConsentPendingStructures(req.user); } + @UseGuards(JwtAuthGuard) + @Get(':id') + @ApiParam({ name: 'id', type: String, required: true }) + public async getUser(@Param() params): Promise<IUser> { + return this.usersService.findById(params.id); + } + @ApiResponse({ status: HttpStatus.CREATED, description: 'Description updated' }) @ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: 'Unauthorized' }) @UseGuards(JwtAuthGuard)