From 47db0e82be6b7ca877ea4216f3cdcbacaa3ac925 Mon Sep 17 00:00:00 2001 From: Zac Sturgess Date: Sun, 1 May 2016 23:04:09 +0100 Subject: [PATCH] Fix #144 Signed-off-by: Zac Sturgess --- src/ResultBundle/Tests/E2E/ViewTestTest.php | 9 +++++++++ web/assets/lib/app.min.js | 2 +- web/assets/lib/src/helpers.js | 7 ++++++- web/partials/dashboard.html | 4 ++-- web/partials/viewTest.html | 6 +++--- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/ResultBundle/Tests/E2E/ViewTestTest.php b/src/ResultBundle/Tests/E2E/ViewTestTest.php index b3fce3c..edbce02 100644 --- a/src/ResultBundle/Tests/E2E/ViewTestTest.php +++ b/src/ResultBundle/Tests/E2E/ViewTestTest.php @@ -82,6 +82,15 @@ public function testEditDeleteAndRunInsufficentPermissions() $this->assertFalse($this->getActionItem(2)->isDisplayed()); $this->assertFalse($this->getActionItem(3)->isDisplayed()); } + + public function testEditDeleteAndRunAsAdmin() { + $this->logInAsUser('user-3'); + $this->clickThroughToTest(1); + + $this->assertFalse($this->getActionItem(1)->isDisplayed()); + $this->assertFalse($this->getActionItem(2)->isDisplayed()); + $this->assertFalse($this->getActionItem(3)->isDisplayed()); + } private function clickThroughToTest($number) { diff --git a/web/assets/lib/app.min.js b/web/assets/lib/app.min.js index 677329d..2e1bf3c 100644 --- a/web/assets/lib/app.min.js +++ b/web/assets/lib/app.min.js @@ -1 +1 @@ -var overwatchApp=angular.module("overwatch",["ngRoute","angularModalService","ngIdle"]);overwatchApp.run(["$rootScope","$location","$routeParams",function(e,t,r){e.$on("$routeChangeSuccess",function(r,o,n){e.currentPage=t.path()})}]),overwatchApp.config(["$routeProvider","$httpProvider","IdleProvider",function(e,t,r){e.when("/",{title:"Dashboard",templateUrl:"partials/dashboard.html",controller:"DashboardController"}).when("/group/:id",{title:"Edit Group",templateUrl:"partials/editGroup.html",controller:"EditGroupController"}).when("/group/:id/add-test",{title:"Add test",templateUrl:"partials/testForm.html",controller:"AddTestController"}).when("/test/:id",{title:"View test",templateUrl:"partials/viewTest.html",controller:"ViewTestController"}).when("/test/:id/edit",{title:"Edit test",templateUrl:"partials/testForm.html",controller:"EditTestController"}).when("/users",{title:"Manage Users",templateUrl:"partials/manageUsers.html",controller:"ManageUsersController"}).when("/alerts",{title:"Change Alert Settings",templateUrl:"partials/changeAlertSettings.html",controller:"ManageAlertSettingsController"}).when("/my-account",{title:"My Account",templateUrl:"/profile/change-password",controller:"MyAccountController"}).when("/error",{title:"Error",templateUrl:"partials/error.html",controller:function(e,t){t.status={code:"500",text:"Internal Server Error"},e(!1)}}).otherwise({title:"Not Found",templateUrl:"partials/error.html",controller:function(e,t){t.status={code:"404",text:"Not Found"},e(!1)}}),t.interceptors.push("overwatchApiErrorHandler"),r.idle(300),r.timeout(5)}]),overwatchApp.factory("$gravatar",function(){return{fn:function(e,t){var r=function(e){function t(e,t){return e<>>32-t}function r(e,t){var r,o,n,a,s;return n=2147483648&e,a=2147483648&t,r=1073741824&e,o=1073741824&t,s=(1073741823&e)+(1073741823&t),r&o?2147483648^s^n^a:r|o?1073741824&s?3221225472^s^n^a:1073741824^s^n^a:s^n^a}function o(e,t,r){return e&t|~e&r}function n(e,t,r){return e&r|t&~r}function a(e,t,r){return e^t^r}function s(e,t,r){return t^(e|~r)}function u(e,n,a,s,u,i,c){return e=r(e,r(r(o(n,a,s),u),c)),r(t(e,i),n)}function i(e,o,a,s,u,i,c){return e=r(e,r(r(n(o,a,s),u),c)),r(t(e,i),o)}function c(e,o,n,s,u,i,c){return e=r(e,r(r(a(o,n,s),u),c)),r(t(e,i),o)}function l(e,o,n,a,u,i,c){return e=r(e,r(r(s(o,n,a),u),c)),r(t(e,i),o)}function p(e){for(var t,r=e.length,o=r+8,n=(o-o%64)/64,a=16*(n+1),s=Array(a-1),u=0,i=0;r>i;)t=(i-i%4)/4,u=i%4*8,s[t]=s[t]|e.charCodeAt(i)<>>29,s}function d(e){var t,r,o="",n="";for(r=0;3>=r;r++)t=e>>>8*r&255,n="0"+t.toString(16),o+=n.substr(n.length-2,2);return o}function f(e){e=e.replace(/rn/g,"n");for(var t="",r=0;ro?t+=String.fromCharCode(o):o>127&&2048>o?(t+=String.fromCharCode(o>>6|192),t+=String.fromCharCode(63&o|128)):(t+=String.fromCharCode(o>>12|224),t+=String.fromCharCode(o>>6&63|128),t+=String.fromCharCode(63&o|128))}return t}var h,g,m,v,w,_,A,$,y,R=Array(),U=7,S=12,C=17,E=22,T=5,b=9,M=14,N=20,P=4,x=11,L=16,D=23,I=6,G=10,O=15,F=21;for(e=f(e),R=p(e),_=1732584193,A=4023233417,$=2562383102,y=271733878,h=0;h21600)},r.removeTest=function(t){n.confirm("Are you sure you want to remove this test? All historical data for this test will also be deleted.")&&(e(!0),o["delete"](Routing.generate("overwatch_test_testapi_deletetest",{id:t})).success(function(){u()}))},r.removeGroup=function(t){n.confirm("Are you sure you want to remove this group?")&&(e(!0),o["delete"](Routing.generate("overwatch_test_testgroupapi_deletegroup",{id:t})).success(function(){u()}))},r.createGroup=function(){var t=n.prompt("Please enter a name for the new group","Untitled Group");null!==t&&(e(!0),o.post(Routing.generate("overwatch_test_testgroupapi_creategroup"),{name:t}).success(function(){u()}))},r.runTest=function(t){e(!0),o.post(Routing.generate("overwatch_test_testapi_runtest",{id:t}),null).success(function(){a.path("/test/"+t)})},u()}]),overwatchApp.controller("EditGroupController",["showLoading","$scope","overwatchApi","$routeParams","$location","$window","$gravatar",function(e,t,r,o,n,a,s){t.group={};var u=function(){r.get(Routing.generate("overwatch_test_testgroupapi_getgroup",{id:o.id})).success(function(r){t.group=r,e(!1)})};t.userAvatar=function(e,t){return s.fn(e,t)},t.removeUser=function(o){a.confirm("Are you sure you want to remove this user from group '"+t.group.name+"'?")&&(e(!0),r["delete"](Routing.generate("overwatch_test_testgroupapi_removeuserfromgroup",{groupId:t.group.id,userId:o})).success(function(){u()}))},t.addUser=function(){var o=a.prompt("Please enter the e-mail address of the user you wish to add to group '"+t.group.name+"'",currentUser.email);null!==o&&(e(!0),r.get(Routing.generate("overwatch_user_api_finduser",{email:o})).success(function(e){r.post(Routing.generate("overwatch_test_testgroupapi_addusertogroup",{groupId:t.group.id,userId:e.id}),{}).success(function(){u()})}).error(function(){e(!1),a.alert("Could not find user by e-mail address '"+o+"'. Please ensure that they are already registered.")}))},t.renameGroup=function(){var o=a.prompt("Please type a new name for this group",t.group.name);null!==o&&o!==t.group.name&&(e(!0),r.put(Routing.generate("overwatch_test_testgroupapi_updategroup",{id:t.group.id}),{name:o}).success(function(r){t.group=r,currentUser.groups.push(r.name),e(!1)}))},u()}]),overwatchApp.controller("AddTestController",["showLoading","$scope","overwatchApi","$routeParams","$location",function(e,t,r,o,n){t.title="Add test",t.test={},t.expectations=[],r.get(Routing.generate("overwatch_expectation_api_getall")).success(function(r){t.expectations=r,e(!1)}),t.save=function(){e(!0),r.post(Routing.generate("overwatch_test_testapi_createtest",{id:o.id}),t.test).success(function(){n.path("/")})}}]),overwatchApp.controller("ViewTestController",["showLoading","isGranted","$scope","overwatchApi","$routeParams","$interval","$location","$window","$q",function(e,t,r,o,n,a,s,u,i){r.test={},r.test.results={},r.lastRequestedResultSize=0,r.loadResults=function(t){var a=o.get(Routing.generate("overwatch_test_testapi_gettest",{id:n.id})).success(function(e){var t=r.test.results;r.test=e,r.test.results=t}),s=o.get(Routing.generate("overwatch_result_api_getresultsfortest",{id:n.id})+"?pageSize="+t).success(function(e){r.test.results=e,r.lastRequestedResultSize=t});i.all([a,s]).then(function(){e(!1)})},r.loadOlderResults=function(){e(!0),r.loadResults(r.lastRequestedResultSize+10)},r.removeTest=function(t){u.confirm("Are you sure you want to remove this test? All historical data for this test will also be deleted.")&&(e(!0),o["delete"](Routing.generate("overwatch_test_testapi_deletetest",{id:t})).success(function(){s.path("/")}))},r.isGranted=function(e,r){return"undefined"==typeof r?t(e):t(e,r.name)},r.runTest=function(t){e(!0),o.post(Routing.generate("overwatch_test_testapi_runtest",{id:t}),null).success(function(){r.loadResults(r.lastRequestedResultSize)})},r.loadResults(10);var c=a(function(){r.loadResults(r.lastRequestedResultSize)},6e4);r.$on("$destroy",function(){a.cancel(c)})}]),overwatchApp.controller("EditTestController",["showLoading","$scope","overwatchApi","$routeParams","$location","$q",function(e,t,r,o,n,a){t.title="Edit test",t.test={},t.expectations=[];var s=r.get(Routing.generate("overwatch_expectation_api_getall")).success(function(e){t.expectations=e}),u=r.get(Routing.generate("overwatch_test_testapi_gettest",{id:o.id})).success(function(e){t.test=e});a.all([s,u]).then(function(){e(!1)}),t.save=function(){e(!0),r.put(Routing.generate("overwatch_test_testapi_updatetest",{id:o.id}),t.test).success(function(){n.path("/test/"+o.id)})}}]),overwatchApp.controller("ManageUsersController",["showLoading","$scope","overwatchApi","$window","ModalService","$gravatar",function(e,t,r,o,n,a){t.users=[],t.updatedRoles=[],t.currentUserId=currentUser.id;var s=function(){r.get(Routing.generate("overwatch_user_api_getallusers")).success(function(r){t.users=r,e(!1)})};t.createUser=function(){var t=o.prompt("Please type the new user's email address.","");null!==t&&(e(!0),r.post(Routing.generate("overwatch_user_api_createuser",{email:t}),{}).success(function(e){s()}))},t.userAvatar=function(e,t){return a.fn(e,t)},t.updateRole=function(t){n.showModal({templateUrl:"/partials/roleDialog.html",controller:"RoleDialogController"}).then(function(o){o.close.then(function(o){"CANCEL"!==o&&(e(!0),r.put(Routing.generate("overwatch_user_api_setuserrole",{id:t,role:o}),{}).success(function(){s()}))})})},t.lockUser=function(t){e(!0),r.put(Routing.generate("overwatch_user_api_togglelockuser",{id:t}),{}).success(function(){s()})},t.removeUser=function(t){o.confirm("Are you sure you want to permanently remove this user?")&&(e(!0),r["delete"](Routing.generate("overwatch_user_api_deleteuser",{id:t})).success(function(){s()}))},s()}]),overwatchApp.controller("ManageAlertSettingsController",["showLoading","$scope","overwatchApi",function(e,t,r){t.settings=[];var o=function(){r.get(Routing.generate("overwatch_user_api_getalertsettings")).success(function(r){t.settings=r,e(!1)})};t.isUsersSetting=function(e){return currentUser.alertSetting===e},t.saveSetting=function(t){e(!0),r.put(Routing.generate("overwatch_user_api_updateuser"),{alertSetting:t}).success(function(){currentUser.alertSetting=t,e(!1)})},o()}]),overwatchApp.controller("RoleDialogController",["$scope","close",function(e,t){e.close=function(e){t(e)}}]),overwatchApp.controller("MyAccountController",["showLoading","$scope","overwatchApi",function(e,t,r){t.telephoneNumber=currentUser.telephoneNumber,t.apiKeyFieldType="password",t.saveProfile=function(){e(!0),r.put(Routing.generate("overwatch_user_api_updateuser"),{telephoneNumber:t.telephoneNumber}).then(function(t){currentUser.telephoneNumber=t.data.telephoneNumber,e(!1)})["catch"](function(){e(!1),alert("Sorry, there was an error saving your telephone number.")})},t.toggleAPIKeyVisibility=function(){var e="password";"password"===t.apiKeyFieldType&&(e="text"),t.apiKeyFieldType=e},e(!1)}]),overwatchApp.run(["showLoading","$rootScope","$window","Idle",function(e,t,r,o){t.$on("$routeChangeStart",function(){e(!0)}),t.$on("$routeChangeSuccess",function(e,t){t.title?r.document.title=t.title+" - Overwatch":r.document.title="Overwatch"}),t.$on("IdleTimeout",function(){r.location.href="/logout"}),o.watch()}]),overwatchApp.factory("showLoading",["$rootScope",function(e){return function(t){e.isLoading=t}}]),overwatchApp.factory("isGranted",[function(){var e=function(t){return"ROLE_SUPER_ADMIN"!==t&&e("ROLE_SUPER_ADMIN")?!0:-1!==currentUser.roles.indexOf(t)},t=function(t){return e("ROLE_SUPER_ADMIN")?!0:-1!==currentUser.groups.indexOf(t)};return function(r,o){switch(r){case"SUPER_ADMIN":return e("ROLE_SUPER_ADMIN");case"ADMIN":return e("ROLE_ADMIN")&&t(o);case"USER":return t(o);default:return!1}}}]),overwatchApp.factory("overwatchApiAuth",[function(){return{getHttpHeaders:function(){return{"X-Api-User":this.getUser(),"X-Api-Timestamp":this.getTimestamp(),"X-Api-Token":this.getToken()}},getToken:function(){return CryptoJS.HmacSHA256("timestamp="+this.getTimestamp(),currentUser.apiKey)},getUser:function(){return currentUser.id},getTimestamp:function(){return(new Date).getTime().toString().substr(0,10)}}}]),overwatchApp.service("overwatchApi",["overwatchApiAuth","$http",function(e,t){return{call:function(r){return r.hasOwnProperty("headers")?r.headers=angular.merge(r.headers,e.getHttpHeaders()):r.headers=e.getHttpHeaders(),t(r)},transformUrl:function(e){return 0!==e.indexOf("/api/")&&(e=Routing.generate(e)),e},get:function(e){return this.call({method:"GET",url:this.transformUrl(e)})},post:function(e,t){return this.call({method:"POST",data:t,url:this.transformUrl(e)})},put:function(e,t){return this.call({method:"PUT",data:t,url:this.transformUrl(e)})},"delete":function(e){return this.call({method:"DELETE",url:this.transformUrl(e)})}}}]),overwatchApp.factory("overwatchApiErrorHandler",["$location","$window",function(e,t){return{responseError:function(r){401===r.status||403===r.status?t.location.reload():e.url("/error")}}}]),overwatchApp.filter("ucfirst",[function(){return function(e,t){return e.replace(/(?:^|\s)\S/g,function(e){return e.toUpperCase()})}}]),overwatchApp.filter("strLimit",["$filter",function(e){return function(t,r){return t.length<=r?t:e("limitTo")(t,r)+"..."}}]),overwatchApp.filter("timeago",[function(){return function(e,t){var e=1e3*e;if(isNaN(e))return"never";var r,o=function(e,t,r){var o="function"==typeof e?e(t,i):e,n=r.numbers&&r.numbers[t]||t;return o.replace(/%d/i,n)},n=(new Date).getTime(),a=new Date(e).getTime(),s=t||!1,u={prefixAgo:null,prefixFromNow:null,suffixAgo:"ago",suffixFromNow:"from now",seconds:"less than a minute",minute:"about a minute",minutes:"%d minutes",hour:"about an hour",hours:"about %d hours",day:"a day",days:"%d days",month:"about a month",months:"%d months",year:"about a year",years:"%d years"},i=n-a,c=Math.abs(i)/1e3,l=c/60,p=l/60,d=p/24,f=d/365,h=void 0===u.wordSeparator?" ":u.wordSeparator,g=u.prefixAgo,m=u.suffixAgo;return s&&0>i&&(g=u.prefixFromNow,m=u.suffixFromNow),r=45>c&&o(u.seconds,Math.round(c),u)||90>c&&o(u.minute,1,u)||45>l&&o(u.minutes,Math.round(l),u)||90>l&&o(u.hour,1,u)||24>p&&o(u.hours,Math.round(p),u)||42>p&&o(u.day,1,u)||30>d&&o(u.days,Math.round(d),u)||45>d&&o(u.month,1,u)||365>d&&o(u.months,Math.round(d/30),u)||1.5>f&&o(u.year,1,u)||o(u.years,Math.round(f),u),[g,r,m].join(h).trim()}}]),!function(){"use strict";var e=angular.module("angularModalService",[]);e.factory("ModalService",["$document","$compile","$controller","$http","$rootScope","$q","$timeout","$templateCache",function(e,t,r,o,n,a,s,u){function i(){var e=this,i=function(e,t){var r=a.defer();if(e)r.resolve(e);else if(t){var n=u.get(t);void 0!==n?r.resolve(n):o({method:"GET",url:t,cache:!0}).then(function(e){u.put(t,e.data),r.resolve(e.data)})["catch"](function(e){r.reject(e)})}else r.reject("No template or templateUrl has been specified.");return r.promise};e.showModal=function(e){var o=a.defer(),u=e.controller;return u?(i(e.template,e.templateUrl).then(function(i){var l=n.$new(),p=a.defer(),d={$scope:l,close:function(e,t){(void 0===t||null===t)&&(t=0),s(function(){p.resolve(e)},t)}};if(e.inputs)for(var f in e.inputs)d[f]=e.inputs[f];var h=angular.element(i),g=t(h),m=g(l);d.$element=m;var v=r(u,d);e.appendElement?e.appendElement.append(m):c.append(m);var w={controller:v,scope:l,element:m,close:p.promise};w.close.then(function(){l.$destroy(),m.remove()}),o.resolve(w)})["catch"](function(e){o.reject(e)}),o.promise):(o.reject("No controller has been specified."),o.promise)}}var c=e.find("body");return new i}])}(); \ No newline at end of file +var overwatchApp=angular.module("overwatch",["ngRoute","angularModalService","ngIdle"]);overwatchApp.run(["$rootScope","$location","$routeParams",function(e,t,r){e.$on("$routeChangeSuccess",function(r,o,n){e.currentPage=t.path()})}]),overwatchApp.config(["$routeProvider","$httpProvider","IdleProvider",function(e,t,r){e.when("/",{title:"Dashboard",templateUrl:"partials/dashboard.html",controller:"DashboardController"}).when("/group/:id",{title:"Edit Group",templateUrl:"partials/editGroup.html",controller:"EditGroupController"}).when("/group/:id/add-test",{title:"Add test",templateUrl:"partials/testForm.html",controller:"AddTestController"}).when("/test/:id",{title:"View test",templateUrl:"partials/viewTest.html",controller:"ViewTestController"}).when("/test/:id/edit",{title:"Edit test",templateUrl:"partials/testForm.html",controller:"EditTestController"}).when("/users",{title:"Manage Users",templateUrl:"partials/manageUsers.html",controller:"ManageUsersController"}).when("/alerts",{title:"Change Alert Settings",templateUrl:"partials/changeAlertSettings.html",controller:"ManageAlertSettingsController"}).when("/my-account",{title:"My Account",templateUrl:"/profile/change-password",controller:"MyAccountController"}).when("/error",{title:"Error",templateUrl:"partials/error.html",controller:function(e,t){t.status={code:"500",text:"Internal Server Error"},e(!1)}}).otherwise({title:"Not Found",templateUrl:"partials/error.html",controller:function(e,t){t.status={code:"404",text:"Not Found"},e(!1)}}),t.interceptors.push("overwatchApiErrorHandler"),r.idle(300),r.timeout(5)}]),overwatchApp.factory("$gravatar",function(){return{fn:function(e,t){var r=function(e){function t(e,t){return e<>>32-t}function r(e,t){var r,o,n,a,s;return n=2147483648&e,a=2147483648&t,r=1073741824&e,o=1073741824&t,s=(1073741823&e)+(1073741823&t),r&o?2147483648^s^n^a:r|o?1073741824&s?3221225472^s^n^a:1073741824^s^n^a:s^n^a}function o(e,t,r){return e&t|~e&r}function n(e,t,r){return e&r|t&~r}function a(e,t,r){return e^t^r}function s(e,t,r){return t^(e|~r)}function u(e,n,a,s,u,i,c){return e=r(e,r(r(o(n,a,s),u),c)),r(t(e,i),n)}function i(e,o,a,s,u,i,c){return e=r(e,r(r(n(o,a,s),u),c)),r(t(e,i),o)}function c(e,o,n,s,u,i,c){return e=r(e,r(r(a(o,n,s),u),c)),r(t(e,i),o)}function l(e,o,n,a,u,i,c){return e=r(e,r(r(s(o,n,a),u),c)),r(t(e,i),o)}function p(e){for(var t,r=e.length,o=r+8,n=(o-o%64)/64,a=16*(n+1),s=Array(a-1),u=0,i=0;r>i;)t=(i-i%4)/4,u=i%4*8,s[t]=s[t]|e.charCodeAt(i)<>>29,s}function d(e){var t,r,o="",n="";for(r=0;3>=r;r++)t=e>>>8*r&255,n="0"+t.toString(16),o+=n.substr(n.length-2,2);return o}function f(e){e=e.replace(/rn/g,"n");for(var t="",r=0;ro?t+=String.fromCharCode(o):o>127&&2048>o?(t+=String.fromCharCode(o>>6|192),t+=String.fromCharCode(63&o|128)):(t+=String.fromCharCode(o>>12|224),t+=String.fromCharCode(o>>6&63|128),t+=String.fromCharCode(63&o|128))}return t}var h,g,m,v,w,_,A,$,y,R=Array(),U=7,S=12,C=17,E=22,T=5,M=9,b=14,N=20,P=4,L=11,x=16,D=23,I=6,G=10,O=15,F=21;for(e=f(e),R=p(e),_=1732584193,A=4023233417,$=2562383102,y=271733878,h=0;h21600)},r.removeTest=function(t){n.confirm("Are you sure you want to remove this test? All historical data for this test will also be deleted.")&&(e(!0),o["delete"](Routing.generate("overwatch_test_testapi_deletetest",{id:t})).success(function(){u()}))},r.removeGroup=function(t){n.confirm("Are you sure you want to remove this group?")&&(e(!0),o["delete"](Routing.generate("overwatch_test_testgroupapi_deletegroup",{id:t})).success(function(){u()}))},r.createGroup=function(){var t=n.prompt("Please enter a name for the new group","Untitled Group");null!==t&&(e(!0),o.post(Routing.generate("overwatch_test_testgroupapi_creategroup"),{name:t}).success(function(){u()}))},r.runTest=function(t){e(!0),o.post(Routing.generate("overwatch_test_testapi_runtest",{id:t}),null).success(function(){a.path("/test/"+t)})},u()}]),overwatchApp.controller("EditGroupController",["showLoading","$scope","overwatchApi","$routeParams","$location","$window","$gravatar",function(e,t,r,o,n,a,s){t.group={};var u=function(){r.get(Routing.generate("overwatch_test_testgroupapi_getgroup",{id:o.id})).success(function(r){t.group=r,e(!1)})};t.userAvatar=function(e,t){return s.fn(e,t)},t.removeUser=function(o){a.confirm("Are you sure you want to remove this user from group '"+t.group.name+"'?")&&(e(!0),r["delete"](Routing.generate("overwatch_test_testgroupapi_removeuserfromgroup",{groupId:t.group.id,userId:o})).success(function(){u()}))},t.addUser=function(){var o=a.prompt("Please enter the e-mail address of the user you wish to add to group '"+t.group.name+"'",currentUser.email);null!==o&&(e(!0),r.get(Routing.generate("overwatch_user_api_finduser",{email:o})).success(function(e){r.post(Routing.generate("overwatch_test_testgroupapi_addusertogroup",{groupId:t.group.id,userId:e.id}),{}).success(function(){u()})}).error(function(){e(!1),a.alert("Could not find user by e-mail address '"+o+"'. Please ensure that they are already registered.")}))},t.renameGroup=function(){var o=a.prompt("Please type a new name for this group",t.group.name);null!==o&&o!==t.group.name&&(e(!0),r.put(Routing.generate("overwatch_test_testgroupapi_updategroup",{id:t.group.id}),{name:o}).success(function(r){t.group=r,currentUser.groups.push(r.name),e(!1)}))},u()}]),overwatchApp.controller("AddTestController",["showLoading","$scope","overwatchApi","$routeParams","$location",function(e,t,r,o,n){t.title="Add test",t.test={},t.expectations=[],r.get(Routing.generate("overwatch_expectation_api_getall")).success(function(r){t.expectations=r,e(!1)}),t.save=function(){e(!0),r.post(Routing.generate("overwatch_test_testapi_createtest",{id:o.id}),t.test).success(function(){n.path("/")})}}]),overwatchApp.controller("ViewTestController",["showLoading","isGranted","$scope","overwatchApi","$routeParams","$interval","$location","$window","$q",function(e,t,r,o,n,a,s,u,i){r.test={},r.test.results={},r.lastRequestedResultSize=0,r.loadResults=function(t){var a=o.get(Routing.generate("overwatch_test_testapi_gettest",{id:n.id})).success(function(e){var t=r.test.results;r.test=e,r.test.results=t}),s=o.get(Routing.generate("overwatch_result_api_getresultsfortest",{id:n.id})+"?pageSize="+t).success(function(e){r.test.results=e,r.lastRequestedResultSize=t});i.all([a,s]).then(function(){e(!1)})},r.loadOlderResults=function(){e(!0),r.loadResults(r.lastRequestedResultSize+10)},r.removeTest=function(t){u.confirm("Are you sure you want to remove this test? All historical data for this test will also be deleted.")&&(e(!0),o["delete"](Routing.generate("overwatch_test_testapi_deletetest",{id:t})).success(function(){s.path("/")}))},r.isGranted=function(e,r){return"undefined"==typeof r?t(e):t(e,r.name)},r.runTest=function(t){e(!0),o.post(Routing.generate("overwatch_test_testapi_runtest",{id:t}),null).success(function(){r.loadResults(r.lastRequestedResultSize)})},r.loadResults(10);var c=a(function(){r.loadResults(r.lastRequestedResultSize)},6e4);r.$on("$destroy",function(){a.cancel(c)})}]),overwatchApp.controller("EditTestController",["showLoading","$scope","overwatchApi","$routeParams","$location","$q",function(e,t,r,o,n,a){t.title="Edit test",t.test={},t.expectations=[];var s=r.get(Routing.generate("overwatch_expectation_api_getall")).success(function(e){t.expectations=e}),u=r.get(Routing.generate("overwatch_test_testapi_gettest",{id:o.id})).success(function(e){t.test=e});a.all([s,u]).then(function(){e(!1)}),t.save=function(){e(!0),r.put(Routing.generate("overwatch_test_testapi_updatetest",{id:o.id}),t.test).success(function(){n.path("/test/"+o.id)})}}]),overwatchApp.controller("ManageUsersController",["showLoading","$scope","overwatchApi","$window","ModalService","$gravatar",function(e,t,r,o,n,a){t.users=[],t.updatedRoles=[],t.currentUserId=currentUser.id;var s=function(){r.get(Routing.generate("overwatch_user_api_getallusers")).success(function(r){t.users=r,e(!1)})};t.createUser=function(){var t=o.prompt("Please type the new user's email address.","");null!==t&&(e(!0),r.post(Routing.generate("overwatch_user_api_createuser",{email:t}),{}).success(function(e){s()}))},t.userAvatar=function(e,t){return a.fn(e,t)},t.updateRole=function(t){n.showModal({templateUrl:"/partials/roleDialog.html",controller:"RoleDialogController"}).then(function(o){o.close.then(function(o){"CANCEL"!==o&&(e(!0),r.put(Routing.generate("overwatch_user_api_setuserrole",{id:t,role:o}),{}).success(function(){s()}))})})},t.lockUser=function(t){e(!0),r.put(Routing.generate("overwatch_user_api_togglelockuser",{id:t}),{}).success(function(){s()})},t.removeUser=function(t){o.confirm("Are you sure you want to permanently remove this user?")&&(e(!0),r["delete"](Routing.generate("overwatch_user_api_deleteuser",{id:t})).success(function(){s()}))},s()}]),overwatchApp.controller("ManageAlertSettingsController",["showLoading","$scope","overwatchApi",function(e,t,r){t.settings=[];var o=function(){r.get(Routing.generate("overwatch_user_api_getalertsettings")).success(function(r){t.settings=r,e(!1)})};t.isUsersSetting=function(e){return currentUser.alertSetting===e},t.saveSetting=function(t){e(!0),r.put(Routing.generate("overwatch_user_api_updateuser"),{alertSetting:t}).success(function(){currentUser.alertSetting=t,e(!1)})},o()}]),overwatchApp.controller("RoleDialogController",["$scope","close",function(e,t){e.close=function(e){t(e)}}]),overwatchApp.controller("MyAccountController",["showLoading","$scope","overwatchApi",function(e,t,r){t.telephoneNumber=currentUser.telephoneNumber,t.apiKeyFieldType="password",t.saveProfile=function(){e(!0),r.put(Routing.generate("overwatch_user_api_updateuser"),{telephoneNumber:t.telephoneNumber}).then(function(t){currentUser.telephoneNumber=t.data.telephoneNumber,e(!1)})["catch"](function(){e(!1),alert("Sorry, there was an error saving your telephone number.")})},t.toggleAPIKeyVisibility=function(){var e="password";"password"===t.apiKeyFieldType&&(e="text"),t.apiKeyFieldType=e},e(!1)}]),overwatchApp.run(["showLoading","$rootScope","$window","Idle",function(e,t,r,o){t.$on("$routeChangeStart",function(){e(!0)}),t.$on("$routeChangeSuccess",function(e,t){t.title?r.document.title=t.title+" - Overwatch":r.document.title="Overwatch"}),t.$on("IdleTimeout",function(){r.location.href="/logout"}),o.watch()}]),overwatchApp.factory("showLoading",["$rootScope",function(e){return function(t){e.isLoading=t}}]),overwatchApp.factory("isGranted",[function(){var e=function(t){return"ROLE_SUPER_ADMIN"!==t&&e("ROLE_SUPER_ADMIN")?!0:-1!==currentUser.roles.indexOf(t)},t=function(t){return e("ROLE_SUPER_ADMIN")?!0:-1!==currentUser.groups.indexOf(t)};return function(r,o){switch(r){case"SUPER_ADMIN":return e("ROLE_SUPER_ADMIN");case"ADMIN":return"undefined"==typeof o?e("ROLE_ADMIN"):e("ROLE_ADMIN")&&t(o);case"USER":return t(o);default:return!1}}}]),overwatchApp.factory("overwatchApiAuth",[function(){return{getHttpHeaders:function(){return{"X-Api-User":this.getUser(),"X-Api-Timestamp":this.getTimestamp(),"X-Api-Token":this.getToken()}},getToken:function(){return CryptoJS.HmacSHA256("timestamp="+this.getTimestamp(),currentUser.apiKey)},getUser:function(){return currentUser.id},getTimestamp:function(){return(new Date).getTime().toString().substr(0,10)}}}]),overwatchApp.service("overwatchApi",["overwatchApiAuth","$http",function(e,t){return{call:function(r){return r.hasOwnProperty("headers")?r.headers=angular.merge(r.headers,e.getHttpHeaders()):r.headers=e.getHttpHeaders(),t(r)},transformUrl:function(e){return 0!==e.indexOf("/api/")&&(e=Routing.generate(e)),e},get:function(e){return this.call({method:"GET",url:this.transformUrl(e)})},post:function(e,t){return this.call({method:"POST",data:t,url:this.transformUrl(e)})},put:function(e,t){return this.call({method:"PUT",data:t,url:this.transformUrl(e)})},"delete":function(e){return this.call({method:"DELETE",url:this.transformUrl(e)})}}}]),overwatchApp.factory("overwatchApiErrorHandler",["$location","$window",function(e,t){return{responseError:function(r){401===r.status||403===r.status?t.location.reload():e.url("/error")}}}]),overwatchApp.filter("ucfirst",[function(){return function(e,t){return e.replace(/(?:^|\s)\S/g,function(e){return e.toUpperCase()})}}]),overwatchApp.filter("strLimit",["$filter",function(e){return function(t,r){return t.length<=r?t:e("limitTo")(t,r)+"..."}}]),overwatchApp.filter("timeago",[function(){return function(e,t){var e=1e3*e;if(isNaN(e))return"never";var r,o=function(e,t,r){var o="function"==typeof e?e(t,i):e,n=r.numbers&&r.numbers[t]||t;return o.replace(/%d/i,n)},n=(new Date).getTime(),a=new Date(e).getTime(),s=t||!1,u={prefixAgo:null,prefixFromNow:null,suffixAgo:"ago",suffixFromNow:"from now",seconds:"less than a minute",minute:"about a minute",minutes:"%d minutes",hour:"about an hour",hours:"about %d hours",day:"a day",days:"%d days",month:"about a month",months:"%d months",year:"about a year",years:"%d years"},i=n-a,c=Math.abs(i)/1e3,l=c/60,p=l/60,d=p/24,f=d/365,h=void 0===u.wordSeparator?" ":u.wordSeparator,g=u.prefixAgo,m=u.suffixAgo;return s&&0>i&&(g=u.prefixFromNow,m=u.suffixFromNow),r=45>c&&o(u.seconds,Math.round(c),u)||90>c&&o(u.minute,1,u)||45>l&&o(u.minutes,Math.round(l),u)||90>l&&o(u.hour,1,u)||24>p&&o(u.hours,Math.round(p),u)||42>p&&o(u.day,1,u)||30>d&&o(u.days,Math.round(d),u)||45>d&&o(u.month,1,u)||365>d&&o(u.months,Math.round(d/30),u)||1.5>f&&o(u.year,1,u)||o(u.years,Math.round(f),u),[g,r,m].join(h).trim()}}]),!function(){"use strict";var e=angular.module("angularModalService",[]);e.factory("ModalService",["$document","$compile","$controller","$http","$rootScope","$q","$timeout","$templateCache",function(e,t,r,o,n,a,s,u){function i(){var e=this,i=function(e,t){var r=a.defer();if(e)r.resolve(e);else if(t){var n=u.get(t);void 0!==n?r.resolve(n):o({method:"GET",url:t,cache:!0}).then(function(e){u.put(t,e.data),r.resolve(e.data)})["catch"](function(e){r.reject(e)})}else r.reject("No template or templateUrl has been specified.");return r.promise};e.showModal=function(e){var o=a.defer(),u=e.controller;return u?(i(e.template,e.templateUrl).then(function(i){var l=n.$new(),p=a.defer(),d={$scope:l,close:function(e,t){(void 0===t||null===t)&&(t=0),s(function(){p.resolve(e)},t)}};if(e.inputs)for(var f in e.inputs)d[f]=e.inputs[f];var h=angular.element(i),g=t(h),m=g(l);d.$element=m;var v=r(u,d);e.appendElement?e.appendElement.append(m):c.append(m);var w={controller:v,scope:l,element:m,close:p.promise};w.close.then(function(){l.$destroy(),m.remove()}),o.resolve(w)})["catch"](function(e){o.reject(e)}),o.promise):(o.reject("No controller has been specified."),o.promise)}}var c=e.find("body");return new i}])}(); \ No newline at end of file diff --git a/web/assets/lib/src/helpers.js b/web/assets/lib/src/helpers.js index d3ffbb6..1c14e08 100644 --- a/web/assets/lib/src/helpers.js +++ b/web/assets/lib/src/helpers.js @@ -55,7 +55,12 @@ overwatchApp.factory('isGranted', [ return userHasRole('ROLE_SUPER_ADMIN'); break; case 'ADMIN': - return userHasRole('ROLE_ADMIN') && userInGroup(group); + if (typeof group === 'undefined') { + return userHasRole('ROLE_ADMIN'); + } else { + return userHasRole('ROLE_ADMIN') && userInGroup(group); + } + break; case 'USER': return userInGroup(group); diff --git a/web/partials/dashboard.html b/web/partials/dashboard.html index 55cf34b..4cdb5c3 100644 --- a/web/partials/dashboard.html +++ b/web/partials/dashboard.html @@ -23,9 +23,9 @@

Dashboard

  • -
    +
    -

    {{ test.name }} (Last Tested {{ test.result.createdAt|timeago }})

    +

    {{ test.name }} (Last Tested {{ test.result.createdAt|timeago }})

    Expect {{ test.actual }} {{ test.expectation }} {{ test.expected }}

    diff --git a/web/partials/viewTest.html b/web/partials/viewTest.html index b905c54..8b60b7c 100644 --- a/web/partials/viewTest.html +++ b/web/partials/viewTest.html @@ -18,9 +18,9 @@

    View Test '{{ test.name }}'