Welcome to mirror list, hosted at ThFree Co, Russian Federation.

manage-user-access.controller.js « manage-user-access « angularjs « UsersManager « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 55d2f34b64a7934d33776d69b726b70c4c05de23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*!
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
(function () {
    angular.module('piwikApp').controller('ManageUserAccessController', ManageUserAccessController);

    ManageUserAccessController.$inject = ['piwik', 'piwikApi', '$timeout'];

    function ManageUserAccessController(piwik, piwikApi, $timeout) {

        var self = this;
        this.isLoading = false;

        function launchAjaxRequest(login, access, successCallback) {

            self.isLoading = true;

            $timeout(function () {
                piwik.helper.lazyScrollTo('.loadingManageUserAccess', 50);
            });

            var parameters = {userLogin: login, access: access, idSites: self.site.id};

            return piwikApi.post({
                module: 'API',
                format: 'json',
                method: 'UsersManager.setUserAccess'
            }, parameters).then(function (response) {
                self.isLoading = false;
                return response;
            }, function () {
                self.isLoading = false;
            });
        }

        this.siteChanged = function () {
            if (this.site && this.site.id != piwik.idSite) {
                piwik.broadcast.propagateNewPage('segment=&idSite=' + this.site.id, false);
            }
        };

        this.setAccess = function (login, access) {
          login=piwik.helper.escape(piwik.helper.htmlEntities(login));
            if ( $('[data-login="' + login + '"]').find("#"+access).has('.accessGranted').length ){
                return;
            }
            // callback called when the ajax request Update the user permissions is successful
            function successCallback(response) {
                var mainDiv = $('[data-login="' + login + '"]');
                var grantedDiv = mainDiv.find('.accessGranted');
                var currentSite = $(".sites_autocomplete").attr("sitename");
                currentSite = piwik.helper.escape(piwik.helper.htmlEntities(currentSite));

                grantedDiv.attr("src", "plugins/UsersManager/images/no-access.png")
                    .attr("class", "updateAccess")
                    .attr("title", function(){
                      var access = grantedDiv.parents('[id]').attr('id');
                      if (access =="noaccess"){
                        return _pk_translate('UsersManager_RemoveUserAccess', [login,currentSite])
                      }
                      else if (access =="view") {
                        return _pk_translate('UsersManager_GiveUserAccess', [login,_pk_translate('UsersManager_PrivView'),currentSite]);
                      }
                      else if (access =="admin") {
                        return _pk_translate('UsersManager_GiveUserAccess', [login,_pk_translate('UsersManager_PrivAdmin'),currentSite]);
                      }
                    })
                    .off('click')
                    .click(function () {
                        var access = $(this).parent().attr('id')
                        self.setAccess(login, access);
                    })
                ;
                mainDiv.find('#' + access + ' img')
                    .attr('src', "plugins/UsersManager/images/ok.png")
                    .attr('class', "accessGranted")
                    .attr("title",function(){
                      if(access=="noaccess"){
                        return _pk_translate('UsersManager_UserHasNoPermission', [login,_pk_translate('UsersManager_PrivNone'),currentSite]);
                      }else {
                        return _pk_translate('UsersManager_UserHasPermission', [login,access,currentSite]);
                      }}
                  )
                  ;

                var UI = require('piwik/UI');
                var notification = new UI.Notification();
                notification.show(_pk_translate('General_Done'), {
                    placeat: '#accessUpdated',
                    context: 'success',
                    noclear: true,
                    type: 'toast',
                    style: {display: 'inline-block', marginTop: '10px'},
                    id: 'usersManagerAccessUpdated'
                });

                // reload if user anonymous was updated, since we display a Notice message when anon has view access
                if (login == 'anonymous') {
                    window.location.reload();
                }
            }

            if (this.site.id == 'all') {

                //ask confirmation
                $('#confirm').find('.login').text(login);

                function onValidate() {
                    launchAjaxRequest(login, access).then(successCallback);
                }

                piwikHelper.modalConfirm('#confirm', {yes: onValidate})
            }
            else {
                launchAjaxRequest(login, access).then(successCallback);
            }
        }
    }
})();