-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(AUTH-CPC-755): Add More Roles Front End #573
Changes from all commits
2ea4b47
c09e6ae
07ab18a
218801f
865c54e
fd74a3e
889f5cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
angular.module('userModule') | ||
.component('updateUserRoleComponent', { | ||
templateUrl: 'scripts/auth/update-role-form/role-update.template.html', | ||
controller: 'UpdateUserRoleController', | ||
bindings: { | ||
userId: '<' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this doing ? |
||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
angular.module('userModule', ['ui.router']) | ||
.config(['$stateProvider', function($stateProvider) { | ||
$stateProvider | ||
.state('updateUserRole', { | ||
parent: 'app', | ||
url: '/users/:userId/updateRole', | ||
component: 'updateUserRoleComponent', | ||
resolve: { | ||
userId: ['$stateParams', function($stateParams) { | ||
return $stateParams.userId; | ||
}] | ||
} | ||
}); | ||
}]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
angular.module('userModule') | ||
.controller('UpdateUserRoleController', ['$scope', '$http', 'UserService', '$state', function($scope, $http, UserService, $state) { | ||
var ctrl = this; // Capture the controller instance | ||
|
||
$scope.roles = UserService.getAvailableRoles(); | ||
$scope.selectedRole = {}; | ||
|
||
// Use $onInit lifecycle hook to set $scope.userId | ||
ctrl.$onInit = function() { | ||
$scope.userId = ctrl.userId; | ||
}; | ||
|
||
$scope.selectedRoles = {}; | ||
|
||
$scope.updateRole = function() { | ||
var rolesList = []; | ||
for (var role in $scope.selectedRoles) { | ||
if ($scope.selectedRoles[role]) { | ||
rolesList.push(role); | ||
} | ||
} | ||
|
||
if (rolesList.length === 0) { | ||
alert('Please select at least one role.'); | ||
return; | ||
} | ||
|
||
if (rolesList.length > 1) { | ||
alert('Please select only one role.'); | ||
return; | ||
} | ||
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use radio buttons instead of this bloated logic ? |
||
|
||
var rolesChangeRequest = { | ||
roles: rolesList | ||
}; | ||
|
||
// Send the PATCH request | ||
$http({ | ||
method: 'PATCH', | ||
url: 'api/gateway/users/' + $scope.userId, | ||
data: rolesChangeRequest, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
// Add token headers if needed | ||
} | ||
}) | ||
.then(function successCallback(response) { | ||
alert('Roles updated successfully!'); | ||
$state.go('AdminPanel'); | ||
}, function errorCallback(response) { | ||
alert('Failed to update roles. ' + response.data.message); | ||
}); | ||
}; | ||
}]); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dylan recently added his inventory manger story so I would recommend adding Inventory Manager as a role if you have the time. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
angular.module('userModule').service('UserService', [function() { | ||
this.getAvailableRoles = function() { | ||
return ['ADMIN', 'VET', 'OWNER']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these values not fetched from the database, what happens if a new role is added ? For example I added the inventory manager ?
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this normally work with the default preexisting roles? New ones would prove to be an issue no? |
||
}; | ||
|
||
}]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<h2>Update User Role</h2> | ||
<form style="background-color: #f5f5f5; padding: 20px; border-radius: 10px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);"> | ||
<div class="form-group"> | ||
<label>Select Role:</label> | ||
<div ng-repeat="role in roles" class="form-check"> | ||
<input type="checkbox" class="form-check-input" id="{{role}}" ng-model="selectedRoles[role]" ng-true-value="'{{role}}'" ng-false-value="undefined"> | ||
<label class="form-check-label" for="{{role}}">{{role}}</label> | ||
</div> | ||
</div> | ||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using checkboxes ? Radio buttons would fit better since we would want to choose only one role. |
||
<button type="button" class="btn btn-warning" ng-click="updateRole()">Update Roles</button> | ||
<a ui-sref="AdminPanel" class="btn btn-secondary">Cancel</a> | ||
</form> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this doing ? Is it reading from the fetched user ?