From f101937b4c62d65ca8191d096a3734d41f36f703 Mon Sep 17 00:00:00 2001 From: Gerard del Castillo Date: Sun, 23 Sep 2018 20:17:04 +0200 Subject: [PATCH 1/4] fix security bug --- hardware/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hardware/views.py b/hardware/views.py index 13e7363..1227d8d 100644 --- a/hardware/views.py +++ b/hardware/views.py @@ -44,12 +44,14 @@ def get_queryset(self): return Request.objects.all() -class HardwareLendingsView(TabsViewMixin, SingleTableMixin, FilterView): +class HardwareLendingsView(LoginRequiredMixin, TabsViewMixin, SingleTableMixin, + FilterView): template_name = 'hardware_lendings.html' table_class = LendingTable table_pagination = {'per_page': 50} filterset_class = LendingFilter + def get_current_tabs(self): return hardware_tabs(self.request.user) From e6260af6984729ab76913a95c3a114e0ec4552dd Mon Sep 17 00:00:00 2001 From: Gerard del Castillo Date: Sun, 23 Sep 2018 20:21:45 +0200 Subject: [PATCH 2/4] remove filter and extra details from hacker lendings view --- hardware/views.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hardware/views.py b/hardware/views.py index 1227d8d..8596bf5 100644 --- a/hardware/views.py +++ b/hardware/views.py @@ -51,6 +51,14 @@ class HardwareLendingsView(LoginRequiredMixin, TabsViewMixin, SingleTableMixin, table_pagination = {'per_page': 50} filterset_class = LendingFilter + def get_context_data(self, **kwargs): + context = super(HardwareLendingsView, self).get_context_data(**kwargs) + if not self.request.user.is_hardware_admin: + context['filter'] = False + context['table'].exclude = ('id', 'user', 'lending_by', 'return_by') + + return context + def get_current_tabs(self): return hardware_tabs(self.request.user) From d48b1fd5eca27c8d1ba672fb4f3aa0b2d434141f Mon Sep 17 00:00:00 2001 From: Gerard del castillo Date: Sun, 30 Sep 2018 13:32:51 +0200 Subject: [PATCH 3/4] fix style --- hardware/views.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hardware/views.py b/hardware/views.py index 8596bf5..faa154f 100644 --- a/hardware/views.py +++ b/hardware/views.py @@ -44,8 +44,8 @@ def get_queryset(self): return Request.objects.all() -class HardwareLendingsView(LoginRequiredMixin, TabsViewMixin, SingleTableMixin, - FilterView): +class HardwareLendingsView(LoginRequiredMixin, TabsViewMixin, SingleTableMixin, + FilterView): template_name = 'hardware_lendings.html' table_class = LendingTable table_pagination = {'per_page': 50} @@ -59,7 +59,6 @@ def get_context_data(self, **kwargs): return context - def get_current_tabs(self): return hardware_tabs(self.request.user) From 4e16915d032c629a101f0bfc1ad46a2617043121 Mon Sep 17 00:00:00 2001 From: Gerard del castillo Date: Sat, 13 Oct 2018 14:04:07 +0200 Subject: [PATCH 4/4] fix LMK finish state --- hardware/static/js/hw.js | 1 + hardware/static/js/hw_list.js | 73 +++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/hardware/static/js/hw.js b/hardware/static/js/hw.js index 4eccf90..cb9236f 100644 --- a/hardware/static/js/hw.js +++ b/hardware/static/js/hw.js @@ -48,6 +48,7 @@ let hw = (()=>{ let msg = msg_in || "" let title = title_in || "HackathonAssistant" let closeIn = time || 10000 + var icon = icon || window.location.origin + "/static/favicon.png" let notification = new Notification(title, { body: msg, icon: icon diff --git a/hardware/static/js/hw_list.js b/hardware/static/js/hw_list.js index 8494ef6..9f5a33b 100644 --- a/hardware/static/js/hw_list.js +++ b/hardware/static/js/hw_list.js @@ -26,7 +26,7 @@ let hw_list = ((hw)=>{ element.innerHTML=count } function notifyAvailableItem(item){ - hw.notify("A "+item.name+" has become available! Click the notification to request.", + hw.notify("A "+item.name+" has become available! Click the notification to request (May not work in your browser).", "HackathonAssistant", "", ()=>{ hw.ajax_req({ 'req_item':true, @@ -71,8 +71,6 @@ let hw_list = ((hw)=>{ checkItems.push(itemId) if(!timer){ timer = setInterval(()=>{ - if(!checkItems) - timer = false hw.ajax_req({ 'check_availability': true, 'item_ids': checkItems @@ -80,43 +78,60 @@ let hw_list = ((hw)=>{ for(let item of data.available_items){ obj.stopPool(item.id) notifyAvailableItem(item) + var btn =$("[data-item-id="+item.id+"]")[0] + btn.dataset.action = 'request' + btn.innerHTML = "REQUEST" + btn.classList.remove('active') + } + if(!checkItems.length) + { + clearInterval(timer) + timer = false } }) }, POOLING_TIME) } } obj.initListeners = ()=>{ - $("[data-action='lmk']").on("click", (ev)=>{ - if($(ev.target).hasClass('active')){ - $(ev.target).removeClass('active') - obj.stopPool(ev.target.dataset.itemId) - return + $("[data-action]").on("click", (ev)=>{ + if(ev.currentTarget.dataset.action === 'lmk') + { + if($(ev.target).hasClass('active')) + { + $(ev.target).removeClass('active') + obj.stopPool(ev.target.dataset.itemId) + return + } + if(!hw.canNotify) + { + hw.initNotifications((permission)=>{ + if(permission){ + hw.notify("Notifications enabled!") + $(ev.target).addClass('active') + obj.poolAvailability(ev.target.dataset.itemId) + } + }) + } + else + { + $(ev.target).addClass('active') + obj.poolAvailability(ev.target.dataset.itemId) + } } - if(!hw.canNotify){ - hw.initNotifications((permission)=>{ - if(permission){ - hw.notify("Notifications enabled!") - $(ev.target).addClass('active') - obj.poolAvailability(ev.target.dataset.itemId) + else + { + hw.ajax_req({ + 'req_item':true, + 'item_id': ev.currentTarget.dataset.itemId, + }, (data)=>{ + if(data.ok){ + ev.currentTarget.dataset.targetTime = "00:"+data.minutes+":00" + obj.setTimer(ev.currentTarget) } - }) - } else { - $(ev.target).addClass('active') - obj.poolAvailability(ev.target.dataset.itemId) + }) } }) - $("[data-action='request']").on("click", (ev)=>{ - hw.ajax_req({ - 'req_item':true, - 'item_id': ev.currentTarget.dataset.itemId, - }, (data)=>{ - if(data.ok){ - ev.currentTarget.dataset.targetTime = "00:"+data.minutes+":00" - obj.setTimer(ev.currentTarget) - } - }) - }) $(".hw-toggle").on("click", (ev)=>{ $(ev.currentTarget).toggleClass("open") $(ev.currentTarget).siblings(".hw-toggle-actor").toggleClass("open")