From e8832cb0cb2c76677b95bdd8e8ae32be83147cf8 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 13 Dec 2012 17:13:51 +0100 Subject: [PATCH 1/3] [FIX] hr_attendance: do not show slider widget if user is not an employee bzr revid: chs@openerp.com-20121213161351-27jx0l3utfzavaeo --- .../hr_attendance/static/src/js/attendance.js | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/addons/hr_attendance/static/src/js/attendance.js b/addons/hr_attendance/static/src/js/attendance.js index 84516353b9d..281822361ef 100644 --- a/addons/hr_attendance/static/src/js/attendance.js +++ b/addons/hr_attendance/static/src/js/attendance.js @@ -60,7 +60,7 @@ openerp.hr_attendance = function (instance) { return employee.read_slice(['id', 'name', 'state', 'last_sign', 'attendance_access']).then(function (res) { if (_.isEmpty(res) ) return; - if (res[0].attendance_access == false){ + if (res[0].attendance_access === false){ return; } self.$el.show(); @@ -72,16 +72,36 @@ openerp.hr_attendance = function (instance) { }); instance.web.UserMenu.include({ + + is_employee: function() { + var self = this; + if (_.isUndefined(self._is_employee)) { + var Users = new instance.web.Model('res.users'); + return Users.query(['employee']).filter([['id', '=', self.session.uid]]).all().then(function(records) { + if (_.isEmpty(records)) { + self._is_employee = false; + } else { + self._is_employee = records[0].employee; + } + return self._is_employee; + }); + } else { + return $.Deferred().resolve(self._is_employee).promise(); + } + }, + do_update: function () { this._super(); var self = this; - this.update_promise = this.update_promise.done(function () { - if (self.attendanceslider) - return; - self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self); - - self.attendanceslider.prependTo(instance.webclient.$('.oe_systray')); + this.update_promise.done(function () { + $.when(self.is_employee()).done(function(is_employee) { + if (!is_employee || self.attendanceslider) { + return; + } + self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self); + self.attendanceslider.prependTo(instance.webclient.$('.oe_systray')); + }); }); }, }); -} +}; From 539af8a8f04375e100eb55d7c61b25b39c5c31f2 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 14 Dec 2012 16:24:53 +0100 Subject: [PATCH 2/3] [FIX] hr_attendance: check the user is an employee by checking if (s)he belongs to the "Employee" group bzr revid: chs@openerp.com-20121214152453-tvtjuvvmefw9qcrp --- .../hr_attendance/static/src/js/attendance.js | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/addons/hr_attendance/static/src/js/attendance.js b/addons/hr_attendance/static/src/js/attendance.js index 281822361ef..f030562da9b 100644 --- a/addons/hr_attendance/static/src/js/attendance.js +++ b/addons/hr_attendance/static/src/js/attendance.js @@ -72,34 +72,22 @@ openerp.hr_attendance = function (instance) { }); instance.web.UserMenu.include({ - - is_employee: function() { - var self = this; - if (_.isUndefined(self._is_employee)) { - var Users = new instance.web.Model('res.users'); - return Users.query(['employee']).filter([['id', '=', self.session.uid]]).all().then(function(records) { - if (_.isEmpty(records)) { - self._is_employee = false; - } else { - self._is_employee = records[0].employee; - } - return self._is_employee; - }); - } else { - return $.Deferred().resolve(self._is_employee).promise(); - } - }, - do_update: function () { this._super(); var self = this; this.update_promise.done(function () { - $.when(self.is_employee()).done(function(is_employee) { - if (!is_employee || self.attendanceslider) { - return; + if (_.isUndefined(self.attendanceslider)) { + return; + } + // check current user is an employee + var Users = new instance.web.Model('res.users'); + Users.call('has_group', ['base.group_user']).done(function(is_employee) { + if (is_employee) { + self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self); + self.attendanceslider.prependTo(instance.webclient.$('.oe_systray')); + } else { + self.attendanceslider = null; } - self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self); - self.attendanceslider.prependTo(instance.webclient.$('.oe_systray')); }); }); }, From 2c8f4f75729c20ff9c43dff100e3eb97e86ffd5e Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 14 Dec 2012 16:52:25 +0100 Subject: [PATCH 3/3] [FIX] hr_attendance: invert condition bzr revid: chs@openerp.com-20121214155225-olze66svgx4hwqvg --- addons/hr_attendance/static/src/js/attendance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_attendance/static/src/js/attendance.js b/addons/hr_attendance/static/src/js/attendance.js index f030562da9b..c2750a920a4 100644 --- a/addons/hr_attendance/static/src/js/attendance.js +++ b/addons/hr_attendance/static/src/js/attendance.js @@ -76,7 +76,7 @@ openerp.hr_attendance = function (instance) { this._super(); var self = this; this.update_promise.done(function () { - if (_.isUndefined(self.attendanceslider)) { + if (!_.isUndefined(self.attendanceslider)) { return; } // check current user is an employee