From 7be25c00562a82cad54b27fc85cdece9e33a4afc Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 14 May 2015 15:34:07 -0400 Subject: [PATCH 01/10] Initial angular.template switch for root --- relengapi/blueprints/slaveloan/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/relengapi/blueprints/slaveloan/__init__.py b/relengapi/blueprints/slaveloan/__init__.py index 75ced835..5f59ea05 100644 --- a/relengapi/blueprints/slaveloan/__init__.py +++ b/relengapi/blueprints/slaveloan/__init__.py @@ -17,6 +17,7 @@ from relengapi.blueprints.slaveloan import task_groups from relengapi.blueprints.slaveloan.slave_mappings import slave_patterns from relengapi.blueprints.slaveloan.slave_mappings import slave_to_slavetype +from relengapi.lib import angular from relengapi.util import tz from werkzeug.exceptions import BadRequest from werkzeug.exceptions import InternalServerError @@ -267,7 +268,12 @@ def update_loan_action(action_id, body): @bp.route('/') @flask_login.login_required def root(): - return render_template('slaveloan_root.html') + return angular.template( + 'slaveloan_root.html', + ) +# url_for('.static', filename='clobberer.js'), +# url_for('.static', filename='clobberer.css'), + # return render_template('slaveloan_root.html') @bp.route('/details/') From 7a287367a91bc6aff73bfe39d4fcf9f884097e82 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Fri, 5 Jun 2015 02:48:46 -0400 Subject: [PATCH 02/10] Checkpoint add basic UI for slaveloan's root using angular --- relengapi/blueprints/slaveloan/__init__.py | 4 ++ .../slaveloan/static/slaveloan_root.html | 47 +++++++++++++++++++ .../slaveloan/static/slaveloan_root.js | 8 ++++ .../slaveloan/templates/slaveloan_root.html | 23 --------- 4 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 relengapi/blueprints/slaveloan/static/slaveloan_root.html create mode 100644 relengapi/blueprints/slaveloan/static/slaveloan_root.js delete mode 100644 relengapi/blueprints/slaveloan/templates/slaveloan_root.html diff --git a/relengapi/blueprints/slaveloan/__init__.py b/relengapi/blueprints/slaveloan/__init__.py index 5f59ea05..51d3f7e3 100644 --- a/relengapi/blueprints/slaveloan/__init__.py +++ b/relengapi/blueprints/slaveloan/__init__.py @@ -11,6 +11,7 @@ from flask import Blueprint from flask import g from flask import render_template +from flask import url_for from flask.ext.login import current_user from relengapi import apimethod from relengapi import p @@ -18,6 +19,7 @@ from relengapi.blueprints.slaveloan.slave_mappings import slave_patterns from relengapi.blueprints.slaveloan.slave_mappings import slave_to_slavetype from relengapi.lib import angular +from relengapi.lib import api from relengapi.util import tz from werkzeug.exceptions import BadRequest from werkzeug.exceptions import InternalServerError @@ -270,6 +272,8 @@ def update_loan_action(action_id, body): def root(): return angular.template( 'slaveloan_root.html', + url_for('.static', filename='slaveloan_root.js'), + machine_types=api.get_data(get_machine_classes), ) # url_for('.static', filename='clobberer.js'), # url_for('.static', filename='clobberer.css'), diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.html b/relengapi/blueprints/slaveloan/static/slaveloan_root.html new file mode 100644 index 00000000..46ba2136 --- /dev/null +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.html @@ -0,0 +1,47 @@ + +
+

New Loan

+ +
+
Who You Are +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
Slave Info +
+ +
+ +
+
+ +
+ +Complete +Submitting Request... + +
+ +
diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.js b/relengapi/blueprints/slaveloan/static/slaveloan_root.js new file mode 100644 index 00000000..b5688c20 --- /dev/null +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.js @@ -0,0 +1,8 @@ +angular.module('slaveloan', ['relengapi', 'initial_data']); + +angular.module('slaveloan').controller('slaveloanController', + function($scope, restapi, initial_data) { + $scope.user = initial_data.user.authenticated_email; + + $scope.machineTypes = initial_data.machine_types; +}); diff --git a/relengapi/blueprints/slaveloan/templates/slaveloan_root.html b/relengapi/blueprints/slaveloan/templates/slaveloan_root.html deleted file mode 100644 index 77790c15..00000000 --- a/relengapi/blueprints/slaveloan/templates/slaveloan_root.html +++ /dev/null @@ -1,23 +0,0 @@ -{# This Source Code Form is subject to the terms of the Mozilla Public - # License, v. 2.0. If a copy of the MPL was not distributed with this - # file, You can obtain one at http://mozilla.org/MPL/2.0/. #} -{% extends "layout.html" %} -{% block content %} - -

New Loan

-
Who You Are
- -
-
Slave Info -What Slave do you need?
-
  • -
  • Other (Specify):
  • -
  • I don't know what I need, I'll ping in #releng
  • -
-
-Complete -Submitting Request... - -
-
-{% endblock %} From 9d1e41a0b7ccf5ac908a9c3f0999f09f8ce5e96e Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 11 Jun 2015 13:28:45 -0400 Subject: [PATCH 03/10] Force relengapi < 3.0 to be installed so that this legacy repo's tests still pass --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c93fa213..3cbe2a76 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ install_requires=[ "Flask", "furl", - "relengapi>=0.3", + "relengapi>=0.3,<3.0", "redo", # Temporary freeze until https://github.com/bhearsum/bzrest/pull/3 is fixed "bzrest==0.9", From 7ecd11c78eda59ddf7f5c658e937a72b1bd2478a Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Fri, 12 Jun 2015 01:41:18 -0400 Subject: [PATCH 04/10] Flesh out rest of user loan --- relengapi/blueprints/slaveloan/__init__.py | 6 +++- .../slaveloan/static/slaveloan_root.html | 12 +++---- .../slaveloan/static/slaveloan_root.js | 34 ++++++++++++++++++- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/relengapi/blueprints/slaveloan/__init__.py b/relengapi/blueprints/slaveloan/__init__.py index 51d3f7e3..9847e0f3 100644 --- a/relengapi/blueprints/slaveloan/__init__.py +++ b/relengapi/blueprints/slaveloan/__init__.py @@ -144,12 +144,15 @@ def new_loan_from_admin(body): @bp.route('/loans/request', methods=['POST']) -@p.slaveloan.admin.require() @apimethod(rest.Loan, body=rest.LoanRequest) def new_loan_request(body): "User Loan Requesting, returns the id of the loan" if not body.ldap_email: raise BadRequest("Missing LDAP E-Mail") + if not p.slaveloan.admin.can(): + if not body.ldap_email == current_user.authenticated_email: + raise BadRequest("You can't request loans on behalf of others.") + if not body.requested_slavetype: raise BadRequest("Missing slavetype") @@ -274,6 +277,7 @@ def root(): 'slaveloan_root.html', url_for('.static', filename='slaveloan_root.js'), machine_types=api.get_data(get_machine_classes), + loanRequestUrl=url_for(new_loan_request), ) # url_for('.static', filename='clobberer.js'), # url_for('.static', filename='clobberer.css'), diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.html b/relengapi/blueprints/slaveloan/static/slaveloan_root.html index 46ba2136..627c2dbd 100644 --- a/relengapi/blueprints/slaveloan/static/slaveloan_root.html +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.html @@ -7,15 +7,15 @@

New Loan

Who You Are
- +
- +
- +
- +
@@ -24,7 +24,7 @@

New Loan

- @@ -41,7 +41,7 @@

New Loan

Complete Submitting Request... - +
diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.js b/relengapi/blueprints/slaveloan/static/slaveloan_root.js index b5688c20..1cf46ac9 100644 --- a/relengapi/blueprints/slaveloan/static/slaveloan_root.js +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.js @@ -2,7 +2,39 @@ angular.module('slaveloan', ['relengapi', 'initial_data']); angular.module('slaveloan').controller('slaveloanController', function($scope, restapi, initial_data) { + $scope.machineTypes = initial_data.machine_types; $scope.user = initial_data.user.authenticated_email; + $scope.loanRequestUrl = initial_data.loanRequestUrl; + + $scope.newLoanModel = { + ldap_email: $scope.user, + bugzilla_email: '', + slavetype: '', + }; + + $scope.submitLoanRequest = function(str) { + var ldap = $scope.newLoanModel.ldap_email; + var bugzilla = $scope.newLoanModel.bugzilla_email; + var slavetype = $scope.newLoanModel.slavetype; + + restapi({ + url: loanRequestUrl, + method: 'POST', + headers: {'Content-Type': 'application/json; charset=utf-8'}, + data: JSON.stringify({ + ldap_email: ldap, + bugzilla_email: bugzilla, + requested_slavetype: slavetype, + }), + while: 'Submitting Loan Request', + }).then(function(response) { + if (response.data.result) { + var r = response.data.result; + alertify("Loan id " + r.id + " successfully filed") + } else { + alertify.error("Error submitting loan"); + } + }); + }; - $scope.machineTypes = initial_data.machine_types; }); From 24c3e863bdb195e1c71c90c1c2e7831d67136198 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Fri, 12 Jun 2015 01:52:37 -0400 Subject: [PATCH 05/10] Minor fixups --- relengapi/blueprints/slaveloan/__init__.py | 3 --- relengapi/blueprints/slaveloan/static/slaveloan_root.html | 3 +-- relengapi/blueprints/slaveloan/static/slaveloan_root.js | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/relengapi/blueprints/slaveloan/__init__.py b/relengapi/blueprints/slaveloan/__init__.py index 9847e0f3..f6ce0d72 100644 --- a/relengapi/blueprints/slaveloan/__init__.py +++ b/relengapi/blueprints/slaveloan/__init__.py @@ -279,9 +279,6 @@ def root(): machine_types=api.get_data(get_machine_classes), loanRequestUrl=url_for(new_loan_request), ) -# url_for('.static', filename='clobberer.js'), -# url_for('.static', filename='clobberer.css'), - # return render_template('slaveloan_root.html') @bp.route('/details/') diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.html b/relengapi/blueprints/slaveloan/static/slaveloan_root.html index 627c2dbd..6c10c696 100644 --- a/relengapi/blueprints/slaveloan/static/slaveloan_root.html +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.html @@ -40,8 +40,7 @@

New Loan

Complete -Submitting Request... - +
diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.js b/relengapi/blueprints/slaveloan/static/slaveloan_root.js index 1cf46ac9..0d934e4e 100644 --- a/relengapi/blueprints/slaveloan/static/slaveloan_root.js +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.js @@ -12,13 +12,13 @@ angular.module('slaveloan').controller('slaveloanController', slavetype: '', }; - $scope.submitLoanRequest = function(str) { + $scope.submitLoanRequest = function() { var ldap = $scope.newLoanModel.ldap_email; var bugzilla = $scope.newLoanModel.bugzilla_email; var slavetype = $scope.newLoanModel.slavetype; restapi({ - url: loanRequestUrl, + url: $scope.loanRequestUrl, method: 'POST', headers: {'Content-Type': 'application/json; charset=utf-8'}, data: JSON.stringify({ From c70aa26b7c6915ec55d2d26cf4d9827105c3125a Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Fri, 12 Jun 2015 01:54:49 -0400 Subject: [PATCH 06/10] Trailing whitespace --- relengapi/blueprints/slaveloan/static/slaveloan_root.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.js b/relengapi/blueprints/slaveloan/static/slaveloan_root.js index 0d934e4e..c3fb43fc 100644 --- a/relengapi/blueprints/slaveloan/static/slaveloan_root.js +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.js @@ -34,7 +34,7 @@ angular.module('slaveloan').controller('slaveloanController', } else { alertify.error("Error submitting loan"); } - }); + }); }; }); From 13421e4301c4548806ed43eda497394d5b54d7d5 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Fri, 12 Jun 2015 01:58:23 -0400 Subject: [PATCH 07/10] Fixup url_for --- relengapi/blueprints/slaveloan/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relengapi/blueprints/slaveloan/__init__.py b/relengapi/blueprints/slaveloan/__init__.py index f6ce0d72..1bfaf467 100644 --- a/relengapi/blueprints/slaveloan/__init__.py +++ b/relengapi/blueprints/slaveloan/__init__.py @@ -277,7 +277,7 @@ def root(): 'slaveloan_root.html', url_for('.static', filename='slaveloan_root.js'), machine_types=api.get_data(get_machine_classes), - loanRequestUrl=url_for(new_loan_request), + loanRequestUrl=url_for("slaveloan.new_loan_request"), ) From 84437946e4f0c092d216a48a6506bcd918255642 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Mon, 15 Jun 2015 12:11:24 -0400 Subject: [PATCH 08/10] Address review comments and some fixes based on my local testing --- .../slaveloan/static/slaveloan_root.html | 8 ++++---- .../blueprints/slaveloan/static/slaveloan_root.js | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.html b/relengapi/blueprints/slaveloan/static/slaveloan_root.html index 6c10c696..a1758f56 100644 --- a/relengapi/blueprints/slaveloan/static/slaveloan_root.html +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.html @@ -4,18 +4,18 @@

New Loan

-
+
Who You Are
- +
- +
@@ -24,7 +24,7 @@

New Loan

- diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.js b/relengapi/blueprints/slaveloan/static/slaveloan_root.js index c3fb43fc..1627c5e4 100644 --- a/relengapi/blueprints/slaveloan/static/slaveloan_root.js +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.js @@ -6,16 +6,18 @@ angular.module('slaveloan').controller('slaveloanController', $scope.user = initial_data.user.authenticated_email; $scope.loanRequestUrl = initial_data.loanRequestUrl; - $scope.newLoanModel = { + $scope.newLoan = { ldap_email: $scope.user, bugzilla_email: '', slavetype: '', }; + $scope.origNewLoan = angular.copy($scope.newLoan); + $scope.submitLoanRequest = function() { - var ldap = $scope.newLoanModel.ldap_email; - var bugzilla = $scope.newLoanModel.bugzilla_email; - var slavetype = $scope.newLoanModel.slavetype; + var ldap = $scope.newLoan.ldap_email; + var bugzilla = $scope.newLoan.bugzilla_email; + var slavetype = $scope.newLoan.slavetype; restapi({ url: $scope.loanRequestUrl, @@ -30,7 +32,9 @@ angular.module('slaveloan').controller('slaveloanController', }).then(function(response) { if (response.data.result) { var r = response.data.result; - alertify("Loan id " + r.id + " successfully filed") + $scope.newLoan = angular.copy($scope.origNewLoan); + $scope.newLoanForm.$setPristine(); + alertify.success("Loan id " + r.id + " successfully filed") } else { alertify.error("Error submitting loan"); } From 3263ae8efed700ec4c4d786428a45b5ffcbd3c13 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Mon, 15 Jun 2015 12:15:18 -0400 Subject: [PATCH 09/10] MPL --- relengapi/blueprints/slaveloan/static/slaveloan_root.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.js b/relengapi/blueprints/slaveloan/static/slaveloan_root.js index 1627c5e4..dd0d7535 100644 --- a/relengapi/blueprints/slaveloan/static/slaveloan_root.js +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.js @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + angular.module('slaveloan', ['relengapi', 'initial_data']); angular.module('slaveloan').controller('slaveloanController', From 643a1f55e82725786c10d80b17276ef3822c9890 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Mon, 15 Jun 2015 12:36:48 -0400 Subject: [PATCH 10/10] Missed camelCase transition --- relengapi/blueprints/slaveloan/__init__.py | 2 +- relengapi/blueprints/slaveloan/static/slaveloan_root.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/relengapi/blueprints/slaveloan/__init__.py b/relengapi/blueprints/slaveloan/__init__.py index ea2acf3e..c6b6c19f 100644 --- a/relengapi/blueprints/slaveloan/__init__.py +++ b/relengapi/blueprints/slaveloan/__init__.py @@ -298,7 +298,7 @@ def root(): 'slaveloan_root.html', url_for('.static', filename='slaveloan_root.js'), machine_types=api.get_data(get_machine_classes), - loanRequestUrl=url_for("slaveloan.new_loan_request"), + loan_request_url=url_for("slaveloan.new_loan_request"), ) diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.js b/relengapi/blueprints/slaveloan/static/slaveloan_root.js index dd0d7535..5514ff2b 100644 --- a/relengapi/blueprints/slaveloan/static/slaveloan_root.js +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.js @@ -8,7 +8,7 @@ angular.module('slaveloan').controller('slaveloanController', function($scope, restapi, initial_data) { $scope.machineTypes = initial_data.machine_types; $scope.user = initial_data.user.authenticated_email; - $scope.loanRequestUrl = initial_data.loanRequestUrl; + $scope.loanRequestUrl = initial_data.loan_request_url; $scope.newLoan = { ldap_email: $scope.user,