• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GrottoCenter / grottocenter-api / 5631056675

pending completion
5631056675

push

github

vmarseguerra
refactor(right): replaces rights with a static groups system

751 of 1944 branches covered (38.63%)

Branch coverage included in aggregate %.

59 of 59 new or added lines in 35 files covered. (100.0%)

2702 of 5007 relevant lines covered (53.96%)

14.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.75
/api/controllers/v1/document/validate.js
1
const ControllerService = require('../../../services/ControllerService');
1✔
2
const DocumentService = require('../../../services/DocumentService');
1✔
3
const NotificationService = require('../../../services/NotificationService');
1✔
4
const RightService = require('../../../services/RightService');
1✔
5
const {
6
  NOTIFICATION_TYPES,
7
  NOTIFICATION_ENTITIES,
8
} = require('../../../services/NotificationService');
1✔
9

10
// eslint-disable-next-line consistent-return
11
module.exports = (req, res) => {
1✔
12
  const hasRight = RightService.hasGroup(
×
13
    req.token.groups,
14
    RightService.G.MODERATOR
15
  );
16
  if (!hasRight) {
×
17
    return res.forbidden('You are not authorized to validate a document.');
×
18
  }
19

20
  const isValidated = req.param('isValidated')
×
21
    ? !(req.param('isValidated').toLowerCase() === 'false')
22
    : true;
23
  const validationComment = req.param('validationComment', null);
×
24
  const id = req.param('id');
×
25

26
  if (isValidated === false && !validationComment) {
×
27
    return res.badRequest(
×
28
      `If the document with id ${req.param(
29
        'id'
30
      )} is refused, a comment must be provided.`
31
    );
32
  }
33

34
  TDocument.updateOne({ id })
×
35
    .set({
36
      dateValidation: new Date(),
37
      isValidated,
38
      validationComment,
39
      validator: req.token.id,
40
    })
41
    .then(async (updatedDocument) => {
42
      if (isValidated) {
×
43
        const populatedDoc = await TDocument.findOne(updatedDocument.id)
×
44
          .populate('author')
45
          .populate('authors')
46
          .populate('cave')
47
          .populate('descriptions')
48
          .populate('authorizationDocument')
49
          .populate('editor')
50
          .populate('entrance')
51
          .populate('identifierType')
52
          .populate('languages')
53
          .populate('library')
54
          .populate('license')
55
          .populate('massif')
56
          .populate('parent')
57
          .populate('regions')
58
          .populate('reviewer')
59
          .populate('subjects')
60
          .populate('type');
61
        await DocumentService.setNamesOfPopulatedDocument(populatedDoc);
×
62
        await DocumentService.addDocumentToElasticSearchIndexes(
×
63
          updatedDocument
64
        );
65
        await NotificationService.notifySubscribers(
×
66
          req,
67
          updatedDocument,
68
          req.token.id,
69
          NOTIFICATION_TYPES.VALIDATE,
70
          NOTIFICATION_ENTITIES.DOCUMENT
71
        );
72
      }
73

74
      const params = {
×
75
        controllerMethod: 'DocumentController.validate',
76
        notFoundMessage: `Document of id ${id} not found`,
77
        searchedItem: `Document of id ${id}`,
78
      };
79
      return ControllerService.treat(req, null, updatedDocument, params, res);
×
80
    });
81
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc