This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository mum. See http://git.chorem.org/mum.git commit 2379592f52a6df2aae3bc68aeb53ec7a953f7039 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 26 11:47:32 2015 +0100 profile: modal pour visualiser les abonnements de l'utilisateur --- app/app.py | 7 ++-- app/modules/storage_modules/shelve_db.py | 40 +++++++++++++++++- static/js/controllers/profileCtrl.js | 61 ++++++++++++++++++++++++++- views/profile.html | 71 +++++++++++++++++++++++++++++++- 4 files changed, 170 insertions(+), 9 deletions(-) diff --git a/app/app.py b/app/app.py index 92c5d26..7ec70c8 100755 --- a/app/app.py +++ b/app/app.py @@ -184,10 +184,9 @@ if __name__ == '__main__': ml.load_all_detection_modules() ml.load_all_notification_modules() wsc = WebSocketContainer(ml.get_db()) - dict_notif = ml.db.add_check('127.0.0.1', "ping", False) - print dict_notif - ml.run_notification_modules(dict_notif) - #process_monitoring.init(ml, wsc) + #dict_notif = ml.db.add_check('127.0.0.1', "ping", False) + #ml.run_notification_modules(dict_notif) + process_monitoring.init(ml, wsc) port = int(os.environ.get('PORT', 1337)) run(host='0.0.0.0', port=port, debug=True, server=GeventWebSocketServer) # after ending diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index a935b88..083e7c4 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -1035,6 +1035,44 @@ class shelve_db: finally: self.close_db() + def get_user_subscriptions(self, username): + """ + Get every subscriptions of a given user (host or group), by notifications modules, including the number of + itterations necessary to get the notification. + :param username: the user name + :return: a dictionary containing : + { + 'hosts':{ + addr_host:{ + 'major':{ + notif_mod:{ + 'priority': int, + 'activated': bool + }, ... + } + 'minor':{...} + }, ... + }, + 'groups':{ ... } + } + """ + res = {} + res['hosts'] = {} + res['groups'] = {} + self.open_db() + try: + for addr_host in self.db['hosts']: + if username in self.db['hosts'][addr_host]['conf']['subscribers']: + res['hosts'][addr_host] = self.db['hosts'][addr_host]['conf']['subscribers'][username] + for group in self.db['groups']: + if username in self.db['groups'][group]['subscribers']: + res['groups'][group] = self.db['groups'][group]['subscribers'][username] + except Exception: + print traceback.format_exc() + finally: + self.close_db() + return res + def remove_user(self, args): """ Removes a user from the database. If the user is registered to a host or a group, @@ -1049,7 +1087,7 @@ class shelve_db: del self.db['users'][username] # unregistering user from hosts for host in self.db['hosts']: - if username in self.db['hosts'][host]['subscribers']: + if username in self.db['hosts'][host]['conf']['subscribers']: del self.db['hosts'][host]['conf']['subscribers'][username] # unregistering user form groups for group in self.db['groups']: diff --git a/static/js/controllers/profileCtrl.js b/static/js/controllers/profileCtrl.js index fa3bbb9..2ca21a6 100644 --- a/static/js/controllers/profileCtrl.js +++ b/static/js/controllers/profileCtrl.js @@ -1,4 +1,4 @@ -mumApp.controller('profileCtrl', function($scope, $rootScope, $route){ +mumApp.controller('profileCtrl', function($scope, $rootScope, $route, $modal){ $scope.users = {}; @@ -9,7 +9,7 @@ mumApp.controller('profileCtrl', function($scope, $rootScope, $route){ $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_users', 'args': null}})); - // receiving the user list + // after calling db functions $scope.$on("resCall", function (event, args) { if(args.func == 'get_users'){ $scope.$apply(function(){ @@ -45,4 +45,61 @@ mumApp.controller('profileCtrl', function($scope, $rootScope, $route){ $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_user_settings', 'args': args}})); } + + // creation of modals + $scope.open_modal_subscriptions = function () { + var modalInstance = $modal.open({ + templateUrl: 'modal_subscriptions_label.html', + controller: 'ModalSubscriptionsInstanceCtrl', + resolve: { + subs_args: function(){ + return {'username': $scope.selected_user}; + } + } + }); + }; +}); + +mumApp.controller('ModalSubscriptionsInstanceCtrl', function ($scope, $rootScope, $modalInstance, subs_args) { + $scope.subs_args = subs_args; // { 'username': stringĀ } + + $scope.user_subscriptions = {}; /* + { + 'hosts':{ + addr_host:{ + 'major':{ + notif_mod:{ + 'priority': int, + 'activated': bool + }, ... + } + 'minor':{...} + }, ... + }, + 'groups':{ ... } + } + */ + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_user_subscriptions', + 'args': $scope.subs_args['username']}})); + + $scope.$on("resCall", function (event, args) { + if(args.func == 'get_user_subscriptions'){ + $scope.$apply(function(){ + $scope.user_subscriptions = args.res; + }); + } + }); + + $scope.get_class = function(sub_part, sub_type, target_name, notif_mod){ + res = ""; + if($scope.user_subscriptions[sub_part][target_name][sub_type][notif_mod]['activated']){ + res = "success"; + } + return res; + } + + $scope.close = function () { + $modalInstance.close(); + }; }); \ No newline at end of file diff --git a/views/profile.html b/views/profile.html index 074c630..1ed35ae 100644 --- a/views/profile.html +++ b/views/profile.html @@ -6,10 +6,13 @@ ng-options="user as user for user in users" ng-change="get_user_settings()"> </select> + <button type="button" class="btn btn-primary" + ng-click="open_modal_subscriptions()" + ng-disabled="selected_user==''">See your subscriptions</button> + <!--<h2 class="sub-header">They will be applied on each new host you will add.</h2>--> - <form> + <form ng-show="selected_user!=''"> <div class="row"> - <h3>Personal informations</h3> <div class="col-xs-3"> <label for="username">Username</label> <input type="text" class="form-control" id="username" @@ -75,6 +78,70 @@ --> </form> + + <script type="text/ng-template" id="modal_subscriptions_label.html"> + <div class="modal-header"> + <h3 class="modal-title">Summary of your subscriptions</h3> + </div> + <div class="modal-body"> + <p>Number of notifications between your last login</p> + <table class="table table-hover"> + <thead> + <tr> + <th>Host</th> + <th>Notification service</th> + <th>Minor</th> + <th>Major</th> + </tr> + </thead> + <tbody> + <tr ng-repeat-start="(addr_host, host) in user_subscriptions.hosts"> + <td>{{addr_host}}</td> + </tr> + <tr ng-repeat-end + ng-repeat="(notif_mod_name, notif_mod) in host.minor"> + <td></td> + <td>{{notif_mod_name}}</td> + <td class="{{get_class('hosts', 'minor', addr_host, notif_mod_name)}}"> + {{notif_mod.priority}} + </td> + <td class="{{get_class('hosts', 'major', addr_host, notif_mod_name)}}"> + {{user_subscriptions.hosts[addr_host].major[notif_mod_name].priority}} + </td> + </tr> + </tbody> + </table> + <table class="table table-hover"> + <thead> + <tr> + <th>Group</th> + <th>Notification service</th> + <th>Minor</th> + <th>Major</th> + </tr> + </thead> + <tbody> + <tr ng-repeat-start="(grp_name, grp) in user_subscriptions.groups"> + <td>{{grp_name}}</td> + </tr> + <tr ng-repeat-end + ng-repeat="(notif_mod_name, notif_mod) in grp.minor"> + <td></td> + <td>{{notif_mod_name}}</td> + <td class="{{get_class('groups', 'minor', grp_name, notif_mod_name)}}"> + {{notif_mod.priority}} + </td> + <td class="{{get_class('groups', 'major', grp_name, notif_mod_name)}}"> + {{user_subscriptions.groups[grp_name].major[notif_mod_name].priority}} + </td> + </tr> + </tbody> + </table> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="close()">Close</button> + </div> + </script> <!--<h3>Summary of notification subscriptions</h3> <p>Number of notifications between your last login</p> <table class="table table-hover"> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.