<commit_before>/*
 * Copyright (c) $year, <NAME>istforening (DNT)
 *
 * https://github.com/Turistforeningen/turadmin
 */

sentry = require('../lib/sentry');

module.exports = function (app, express, options) {
    "use strict";

    var api = options.api;

    return function (req, res, next) {

        var userGroups = [];

        if (req.session && req.session.user && (!!req.session.user.sherpa_id)) {

            api.getAssociationsFor({bruker_sherpa_id: req.session.user.sherpa_id}, function (err, statusCode, associations) {
                if (err) { throw err; }
                if (statusCode === 200) {

                    for (var i = 0; i < associations.length; i++) {
                        if (associations[i].object_id) {
                            userGroups.push(associations[i]);
                        } else {
                            sentry.captureMessage('Group "' + associations[i].navn + '" without Turbase ID!', {
                                level: 'warning',
                                extra: {
                                    user: req.session.user,
                                    group: associations[i]
                                }
                            });
                        }
                    }

                    req.userGroups = userGroups;
                    next();

                } else {
                    sentry.captureMessage('Request to DNT API failed!', {
                        extra: {
                            statusCode: statusCode,
                            errors: associations.errors
                        }
                    });
                    next();
                }
            });

        } else {
            // User is authenticated by other method than DNT Connect
            console.log('Not implemented.');
            next();
        }

    };
<commit_msg>Disable logging of groups without Turbase ID<commit_after>/*
 * Copyright (c) $year, Den Norske Turistforening (DNT)
 *
 * https://github.com/Turistforeningen/turadmin
 */

sentry = require('../lib/sentry');

module.exports = function (app, express, options) {
    "use strict";

    var api = options.api;

    return function (req, res, next) {

        var userGroups = [];

        if (req.session && req.session.user && (!!req.session.user.sherpa_id)) {

            api.getAssociationsFor({bruker_sherpa_id: req.session.user.sherpa_id}, function (err, statusCode, associations) {
                if (err) { throw err; }
                if (statusCode === 200) {

                    for (var i = 0; i < associations.length; i++) {
                        if (associations[i].object_id) {
                            userGroups.push(associations[i]);
                        } else {
                            //sentry.captureMessage('Group "' + associations[i].navn + '" without Turbase ID!', {
                            //    level: 'warning',
                            //    extra: {
                            //        user: req.session.user,
                            //        group: associations[i]
                            //    }
                            //});
                        }
                    }

                    req.userGroups = userGroups;
                    next();

                } else {
                    sentry.captureMessage('Request to DNT API failed!', {
                        extra: {
                            statusCode: statusCode,
                            errors: associations.errors
                        }
                    });
                    next();
                }
            });

        } else {
            // User is authenticated by other method than DNT Connect
            console.log('Not implemented.');
            next();
        }

    };

{'fraction_non_alphanumeric': 0.11073387307390964, 'fraction_numerical': 0.0020893183598850876, 'mean_word_length': 1.0211081794195251, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4411322', 'n_tokens_mistral': 965, 'n_tokens_neox': 900, 'n_words': 196}