• 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

16.67
/api/controllers/v1/caver/set-groups.js
1
const esClient = require('../../../../config/elasticsearch').elasticsearchCli;
1✔
2
const ControllerService = require('../../../services/ControllerService');
1✔
3
const ErrorService = require('../../../services/ErrorService');
1✔
4
const RightService = require('../../../services/RightService');
1✔
5

6
module.exports = async (req, res) => {
1✔
7
  // Check right
8
  const hasRight = RightService.hasGroup(
×
9
    req.token.groups,
10
    RightService.G.ADMINISTRATOR
11
  );
12
  if (!hasRight) {
×
13
    return res.forbidden('You are not authorized to set caver groups.');
×
14
  }
15

16
  // Check params
17
  if (
×
18
    !(await sails.helpers.checkIfExists.with({
19
      attributeName: 'id',
20
      attributeValue: req.param('caverId'),
21
      sailsModel: TCaver,
22
    }))
23
  ) {
24
    return res.badRequest(
×
25
      `Could not find caver with id ${req.param('caverId')}.`
26
    );
27
  }
28

29
  const newGroups = req.param('groups');
×
30
  const notFoundGroup = newGroups.find(
×
31
    async (g) =>
32
      !(await sails.helpers.checkIfExists.with({
×
33
        attributeName: 'id',
34
        attributeValue: g.id,
35
        sailsModel: TGroup,
36
      }))
37
  );
38
  if (notFoundGroup.length > 0) {
×
39
    return res.badRequest(
×
40
      `Could not find group with id ${notFoundGroup[0].id}.`
41
    );
42
  }
43

44
  // Update caver
45
  try {
×
46
    await TCaver.replaceCollection(
×
47
      req.param('caverId'),
48
      'groups',
49
      newGroups.map((g) => g.id)
×
50
    );
51
    esClient.update({
×
52
      index: 'cavers-index',
53
      id: req.param('caverId'),
54
      body: {
55
        doc: {
56
          groups: newGroups.map((g) => g.id).join(','),
×
57
        },
58
      },
59
    });
60

61
    const params = {};
×
62
    params.controllerMethod = 'CaverController.setGroups';
×
63
    return ControllerService.treat(req, null, {}, params, res);
×
64
  } catch (e) {
65
    return ErrorService.getDefaultErrorHandler(res)(e);
×
66
  }
67
};
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