<commit_before>import Ember from 'ember';

export default Ember.Route.extend({

    model(params) {
        return this.store.findRecord('node', params.node_id);
    },

    setupController(controller, model) {
        controller.set('editedTitle', model.get('title'));
        this._super(...arguments);
    },

    actions: {
        editExisting(value) {
            // TODO: Should test PUT or PATCH
            console.log('Will edit title from', this.modelFor(this.routeName).get('title'), ' to ', value);
            var node = this.modelFor(this.routeName);
            if (node.get('currentUserPermissions').indexOf('write') !== -1) {
                node.set('title', value);
                node.save();
            } else {
                console.log('You do not have permissions to edit this node');
            }
        },
        addContributor(contribId, permission, bibliographic) {
            var node = this.modelFor(this.routeName);
            if (contribId) {
                if (node.get('currentUserPermissions').indexOf('admin') !== -1) {
                    var contributor = this.store.createRecord('contributor', {
                        id: contribId,
                        permission: permission,
                        bibliographic: bibliographic,
                        nodeId: node.id
                    });
                    contributor.save();
                    console.log('Contributor added.');
                } else {
                    console.log('You do not have permissions to add contributors');
                }
            } else {
                console.log('User ID must be specified.');
            }
        },
        deleteContributor(contrib) {
            var node = this.modelFor(this.routeName);
            contrib.setProperties({ nodeId: node.id });
            let user = this.modelFor('application');

            var contribMap = node.get('contributors').content.currentState.reduce(function(newMap, contrib) {
                newMap[contrib.id] = { permission: contrib._data.permission, bibliographic: contrib._data.bibliographic };
                return newMap;
            }, {});
<commit_msg>Add updateContributors action.<commit_after>import Ember from 'ember';

export default Ember.Route.extend({

    model(params) {
        return this.store.findRecord('node', params.node_id);
    },

    setupController(controller, model) {
        controller.set('editedTitle', model.get('title'));
        this._super(...arguments);
    },

    actions: {
        editExisting(value) {
            // TODO: Should test PUT or PATCH
            console.log('Will edit title from', this.modelFor(this.routeName).get('title'), ' to ', value);
            var node = this.modelFor(this.routeName);
            if (node.get('currentUserPermissions').indexOf('write') !== -1) {
                node.set('title', value);
                node.save();
            } else {
                console.log('You do not have permissions to edit this node');
            }
        },
        addContributor(contribId, permission, bibliographic) {
            var node = this.modelFor(this.routeName);
            if (contribId) {
                if (node.get('currentUserPermissions').indexOf('admin') !== -1) {
                    var contributor = this.store.createRecord('contributor', {
                        id: contribId,
                        permission: permission,
                        bibliographic: bibliographic,
                        nodeId: node.id
                    });
                    contributor.save();
                    console.log('Contributor added.');
                } else {
                    console.log('You do not have permissions to add contributors');
                }
            } else {
                console.log('User ID must be specified.');
            }
        },
        updateContributors(editedPermissions, editedBibliographic) {
            var node = this.modelFor(this.routeName);
            var contribMap = this.generateContributorMap(node.get('contributors'));
            let user = this.modelFor('application');

            for (var contrib in editedPermissions) {
                contribMap[contrib].permission = editedPermissions[contrib];
            }

            for (var c in editedBibliographic) {
                contribMap[c].bibliographic = editedBibliographic[c];
            }

            if (node.get('currentUserPermissions').indexOf('admin') !== -1) {
                this.attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic);
            } else {
                // Non-admins can only attempt to remove themselves as contributors
                if (contrib.id === user.id) {
                    this.attemptContributorsUpdate(contribMap, node);
                } else {
                    console.log('Non-admins cannot update other contributors.');
                }
            }

        },
        deleteContributor(contrib) {
            var node = this.modelFor(this.routeName);
            contrib.setProperties({ nodeId: node.id });
            let user = this.modelFor('application');

            var contribMap = this.generateContributorMap(node.get('contributors'));

{'fraction_non_alphanumeric': 0.11535537818320031, 'fraction_numerical': 0.0009502090459901178, 'mean_word_length': 1.6906952965235174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6256489', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1246, 'n_words': 270}