/fulfill', methods=['POST'])
@requires_admin()
def request_fulfill(id):
@@ -182,8 +211,8 @@ def request_fulfill(id):
message='Out of stock!'
)
# give user item
- r.user.items.append(item)
-
+ r.user.items.append(item)
+
# update request status
request_update(id, RequestStatus.FULFILLED)
@@ -203,6 +232,18 @@ def request_deny(id):
success=True,
)
+@app.route('/request/deny', methods=['POST'])
+@requires_admin()
+def deny_requests():
+ """Deny all requests"""
+ submitted_requests = Request.query.filter_by(requires_lottery = False,
+ status = RequestStatus.SUBMITTED).all()
+ for request in submitted_requests:
+ request_update(request.id, RequestStatus.DENIED)
+ return jsonify(
+ success=True,
+ )
+
@socketio.on('connect', namespace='/admin')
def authenticate_admin_conection():
"""Callback when client connects to /admin namespace, returns True
@@ -211,15 +252,15 @@ def authenticate_admin_conection():
if 'jwt' in request.cookies:
quill_id = verify_token(request.cookies['jwt'])
if not quill_id:
- return False
+ return False
user = User.query.filter_by(quill_id=quill_id).first()
if user == None or not user.is_admin:
- return False
+ return False
return True
- else:
- return False
+ else:
+ return False
@socketio.on('connect', namespace='/user')
def authenticate_user_conection():
@@ -229,18 +270,18 @@ def authenticate_user_conection():
if 'jwt' in request.cookies:
quill_id = verify_token(request.cookies['jwt'])
if not quill_id:
- return False
+ return False
user = User.query.filter_by(quill_id=quill_id).first()
if user == None:
- return False
+ return False
socket = Socket(request.sid, user)
db.session.add(socket)
db.session.commit()
return True
else:
- return False
+ return False
@socketio.on('disconnect', namespace='/user')
def user_disconnect():
@@ -259,7 +300,7 @@ def on_request_update(mapper, connection, target):
def request_change_handler(target):
"""Handler that sends updated HTML for rendering requests"""
- user = target.user
+ user = target.user
sockets = Socket.query.filter_by(user=user).all()
requests = Request.query.filter(Request.user == user, Request.status.in_(
@@ -277,14 +318,14 @@ def request_change_handler(target):
}, namespace='/user', room=socket.sid)
# TODO: add check if at least one admin is connected
- approved_requests = render_template('includes/macros/display_requests.html',
+ approved_requests = render_template('includes/macros/display_requests.html',
# display requests that are submitted and non lottery OR already approved
requests = Request.query.filter_by(status = RequestStatus.APPROVED).all(),
RequestStatus = RequestStatus,
admin = True,
time = True)
- submitted_requests = render_template('includes/macros/display_requests.html',
+ submitted_requests = render_template('includes/macros/display_requests.html',
# display requests that are submitted and non lottery OR already approved
requests = Request.query.filter_by(requires_lottery = False,
status = RequestStatus.SUBMITTED).all(),
@@ -295,10 +336,10 @@ def request_change_handler(target):
lottery_items = InventoryEntry.query.filter_by(item_type=ItemType.LOTTERY).all()
lottery_quantities = []
for item in lottery_items:
- lottery_quantities.append(
+ lottery_quantities.append(
{
"id": item.id,
- "available": item.quantity,
+ "available": item.quantity,
"submitted": item.submitted_request_quantity
}
)
@@ -306,7 +347,7 @@ def request_change_handler(target):
socketio.emit('update', {
'approved_requests': approved_requests,
'submitted_requests': submitted_requests,
- 'lottery_quantities': lottery_quantities
+ 'lottery_quantities': lottery_quantities
}, namespace='/admin')
# listeners for change to Request database
diff --git a/hardwarecheckout/static/scripts/admin.js b/hardwarecheckout/static/scripts/admin.js
index fd3e222..8fa8237 100644
--- a/hardwarecheckout/static/scripts/admin.js
+++ b/hardwarecheckout/static/scripts/admin.js
@@ -1,4 +1,4 @@
-var socket = io.connect(location.protocol + '//' + document.domain + ':'
+var socket = io.connect(location.protocol + '//' + document.domain + ':'
+ location.port + '/admin');
socket.on('connect', function() {
console.log('Socket connected!')
@@ -29,7 +29,7 @@ socket.on('update', function(data) {
}
});
-function init_request_actions() {
+function init_request_actions() {
$('.request-action').api({
method: 'POST',
onSuccess: function(response) {
@@ -43,6 +43,34 @@ function init_request_actions() {
$(document).ready(function() {
init_request_actions();
+ $('.approve-all.button').api({
+ method: 'POST',
+ onSuccess: function(response) {
+ },
+ onFailure: function(err) {
+ console.log(err);
+ alert(err.message)
+ },
+ onError: function(err) {
+ console.log("ERROR!");
+ console.log(err);
+ }
+ });
+
+ $('.deny-all.button').api({
+ method: 'POST',
+ onSuccess: function(response) {
+ },
+ onFailure: function(err) {
+ console.log("ERROR!");
+ console.log(err);
+ },
+ onError: function(err) {
+ console.log("ERROR!");
+ console.log(err);
+ }
+ });
+
$('.run-lottery.button').api({
method: 'POST',
onSuccess: function(response) {
@@ -63,4 +91,4 @@ $(document).ready(function() {
onSuccess: function(response) {
},
});
-});
\ No newline at end of file
+});
diff --git a/hardwarecheckout/static/scripts/api.js b/hardwarecheckout/static/scripts/api.js
index 455970b..1713e41 100644
--- a/hardwarecheckout/static/scripts/api.js
+++ b/hardwarecheckout/static/scripts/api.js
@@ -2,7 +2,7 @@ $.fn.api.settings.api = {
'add item' : '/inventory/add',
'import items' : '/inventory/autoadd',
'update item' : '/inventory/update/{id}',
- 'return item' : '/inventory/return/{id}',
+ 'return item' : '/inventory/return/{id}',
'delete item' : '/inventory/delete/{id}',
'add subitem' : '/inventory/subitem/add/{id}',
'update subitem' : '/inventory/subitem/update/{id}',
@@ -14,7 +14,9 @@ $.fn.api.settings.api = {
'approve request' : '/request/{id}/approve',
'fulfill request' : '/request/{id}/fulfill',
'deny request' : '/request/{id}/deny',
- 'update user' : '/user/{id}/update'
+ 'update user' : '/user/{id}/update',
+ 'approve all' : '/request/approve',
+ 'deny all' : '/request/deny'
}
$.fn.api.settings.successTest = function(response) {
diff --git a/hardwarecheckout/templates/pages/admin.html b/hardwarecheckout/templates/pages/admin.html
index 7457371..24b455c 100644
--- a/hardwarecheckout/templates/pages/admin.html
+++ b/hardwarecheckout/templates/pages/admin.html
@@ -10,7 +10,19 @@ Approved Requests
{{ display_requests(approved_requests, RequestStatus, user.is_admin) }}
- Pending Requests
+
+
+
+
+ Pending Requests
+ |
+
+ Approve All
+ Deny All
+ |
+
+
+
{{ display_requests(submitted_requests, RequestStatus, user.is_admin) }}
@@ -32,19 +44,19 @@ Lotteries
{{ item.name }}
- Quantity:
+ Quantity:
{{ item.quantity }}
- ,
- Proposals:
+ ,
+ Proposals:
{{ item.submitted_request_quantity }}
- (view)
+ (view)
|
- Run Lottery
|
@@ -57,4 +69,4 @@ {{ item.name }}
{% block script %}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/setup.sh b/setup.sh
new file mode 100644
index 0000000..b738cdd
--- /dev/null
+++ b/setup.sh
@@ -0,0 +1,9 @@
+# Environment variables
+export DATABASE_URL="postgresql://postgres:password@localhost/cog"
+export QUILL="https://hackcog.herokuapp.com"
+export SECRET="8561d0aebda375a4dc5d5622250b9dc4a2387aa433d144df49d5599e8f74965e"
+
+# Run
+python initialize.py
+gunicorn --worker-class eventlet -w 1 hardwarecheckout:app
+