Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server
1 result
Show changes
Commits on Source (2)
......@@ -12,7 +12,7 @@ export class UnclaimedStructureDto {
@ApiProperty({ type: String })
structureName: string;
@ApiProperty({ type: String })
@ApiProperty({ type: Date })
updatedAt: Date;
@ApiProperty({ type: String })
......
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>
{
"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"
}
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`);
};
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) {}
......
......@@ -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);
}
});
}
......
......@@ -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();
});
......
......@@ -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')
......
......@@ -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)
......