Permalink
Browse files

[balrog-ui] Merge pull request #15 from bhearsum/permission-error

bug 1237264: Fix error showing when updating permissions.
  • Loading branch information...
bhearsum committed Jan 13, 2016
2 parents a923aa7 + d27559f commit 73c457b73a0862b03f7b2c5fbeee382f7f563d3d
@@ -12,7 +12,9 @@ function ($scope, $modalInstance, CSRF, Permissions, user, users) {
permission: '',
options_as_json: ''
};
$scope.errors = {};
$scope.errors = {
permissions: {}
};
$scope.user.permissions = [];
Permissions.getUserPermissions(user.username)
@@ -50,17 +52,28 @@ function ($scope, $modalInstance, CSRF, Permissions, user, users) {
permission: '',
options_as_json: ''
};
$scope.errors = {};
$scope.errors = {
permissions: {}
};
sweetAlert("Saved", "Permission added.", "success");
})
.error(function(response) {
$scope.errors.permission = [response];
sweetAlert(
"Form submission error",
response,
"error"
);
console.error(response);
if (typeof response === 'object') {
$scope.errors = response;
sweetAlert(
"Form submission error",
"See fields highlighted in red.",
"error"
);
} else if (typeof response === 'string') {
// quite possibly an error in the blob validation
sweetAlert(
"Form submission error",
"Unable to submit successfully.\n" +
"(" + response+ ")",
"error"
);
}
})
.finally(function() {
$scope.saving = false;
@@ -116,16 +129,28 @@ function ($scope, $modalInstance, CSRF, Permissions, user, users) {
Permissions.updatePermission($scope.user.username, permission, csrf_token)
.success(function(response) {
permission.data_version = response.new_data_version;
$scope.errors = {
permissions: {}
};
sweetAlert("Saved", "Permission changes saved.", "success");
})
.error(function(response) {
// $scope.errors.permission = [response];
sweetAlert(
"Form submission error",
response,
"error"
);
console.error(response);
if (typeof response === 'object') {
$scope.errors.permissions[permission.permission] = response;
sweetAlert(
"Form submission error",
"See fields highlighted in red.",
"error"
);
} else if (typeof response === 'string') {
// quite possibly an error in the blob validation
sweetAlert(
"Form submission error",
"Unable to submit successfully.\n" +
"(" + response+ ")",
"error"
);
}
})
.finally(function() {
$scope.saving = false;
@@ -38,6 +38,7 @@ <h3 class="panel-title">
</div>
<div class="panel-body">
<textarea ng-model="permission.options_as_json" class="options-as-json"></textarea>
<p class="help-block" ng-show="errors.permissions[permission.permission]">{{ errors.permissions[permission.permission].options.join(', ') }}</p>
</div>
<div class="panel-footer" ng-show="rule_id">
<button class="btn btn-primary" ng-show="!saving" ng-click="updatePermissionChanges(permission)">Update</button>
@@ -45,7 +45,7 @@ describe("controller: UserPermissionsCtrl", function() {
this.$httpBackend.expectGET('/api/users/peterbe/permissions')
.respond(200, JSON.stringify(sample_permissions));
this.$httpBackend.flush();
expect(this.scope.errors).toEqual({});
expect(this.scope.errors).toEqual({permissions:{}});
expect(this.scope.saving).toEqual(false);
expect(this.scope.loading).toEqual(false);
expect(this.scope.user).toEqual({
@@ -83,7 +83,7 @@ describe("controller: UserPermissionsCtrl", function() {
expect(this.scope.saving).toEqual(false);
expect(this.scope.user.permissions.length).toEqual(2);
expect(this.scope.saving).toEqual(false);
expect(this.scope.errors).toEqual({});
expect(this.scope.errors).toEqual({permissions:{}});
});
it("should should be able update a permission", function() {
@@ -105,7 +105,7 @@ describe("controller: UserPermissionsCtrl", function() {
expect(this.scope.saving).toEqual(false);
expect(this.scope.user.permissions.length).toEqual(1);
expect(this.scope.saving).toEqual(false);
expect(this.scope.errors).toEqual({});
expect(this.scope.errors).toEqual({permissions:{}});
});
});

0 comments on commit 73c457b

Please sign in to comment.