diff --git a/relengapi/blueprints/slaveloan/__init__.py b/relengapi/blueprints/slaveloan/__init__.py index ad52ec75..c6b6c19f 100644 --- a/relengapi/blueprints/slaveloan/__init__.py +++ b/relengapi/blueprints/slaveloan/__init__.py @@ -11,12 +11,15 @@ 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 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.lib import api from relengapi.util import tz from werkzeug.exceptions import BadRequest from werkzeug.exceptions import InternalServerError @@ -162,12 +165,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") @@ -288,7 +294,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='slaveloan_root.js'), + machine_types=api.get_data(get_machine_classes), + loan_request_url=url_for("slaveloan.new_loan_request"), + ) @bp.route('/details/') diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.html b/relengapi/blueprints/slaveloan/static/slaveloan_root.html new file mode 100644 index 00000000..a1758f56 --- /dev/null +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.html @@ -0,0 +1,46 @@ + +
+

New Loan

+ +
+
Who You Are +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
Slave Info +
+ +
+ +
+
+ +
+ +Complete + +
+ +
diff --git a/relengapi/blueprints/slaveloan/static/slaveloan_root.js b/relengapi/blueprints/slaveloan/static/slaveloan_root.js new file mode 100644 index 00000000..5514ff2b --- /dev/null +++ b/relengapi/blueprints/slaveloan/static/slaveloan_root.js @@ -0,0 +1,48 @@ +/* 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', + function($scope, restapi, initial_data) { + $scope.machineTypes = initial_data.machine_types; + $scope.user = initial_data.user.authenticated_email; + $scope.loanRequestUrl = initial_data.loan_request_url; + + $scope.newLoan = { + ldap_email: $scope.user, + bugzilla_email: '', + slavetype: '', + }; + + $scope.origNewLoan = angular.copy($scope.newLoan); + + $scope.submitLoanRequest = function() { + var ldap = $scope.newLoan.ldap_email; + var bugzilla = $scope.newLoan.bugzilla_email; + var slavetype = $scope.newLoan.slavetype; + + restapi({ + url: $scope.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; + $scope.newLoan = angular.copy($scope.origNewLoan); + $scope.newLoanForm.$setPristine(); + alertify.success("Loan id " + r.id + " successfully filed") + } else { + alertify.error("Error submitting loan"); + } + }); + }; + +}); 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 %}