-
Notifications
You must be signed in to change notification settings - Fork 13
feat(account): add menu for managing API credentials #191
Changes from all commits
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,33 @@ | ||
"use strict"; | ||
angular.module("UserAccount.controllers") | ||
.controller("UserAccount.controllers.credentials.delete", class UserAccountCredentialsDeleteController { | ||
|
||
constructor ($scope, UseraccountCredentialsService, Alerter) { | ||
this.$scope = $scope; | ||
this.UseraccountCredentialsService = UseraccountCredentialsService; | ||
this.Alerter = Alerter; | ||
this.credential = $scope.currentActionData; | ||
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. You can move this to |
||
this.loader = false; | ||
} | ||
|
||
$onInit () { | ||
this.$scope.deleteCredential = this.deleteCredential.bind(this); | ||
} | ||
|
||
deleteCredential () { | ||
this.loader = true; | ||
|
||
this.UseraccountCredentialsService.deleteCredential(this.credential.credentialId) | ||
.then(() => { | ||
this.Alerter.success(this.$scope.tr("user_credentials_delete_success_message"), "userCredentials"); | ||
}) | ||
.catch((err) => { | ||
this.Alerter.error(`${this.$scope.tr("user_credentials_delete_error_message")} ${_.get(err, "message") || err}`, "userCredentials"); | ||
}) | ||
.finally(() => { | ||
this.loader = false; | ||
this.$scope.resetAction(); | ||
}); | ||
} | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div data-ng-controller="UserAccount.controllers.credentials.delete as $ctrl"> | ||
|
||
<div data-wizard | ||
data-wizard-on-cancel="resetAction" | ||
data-wizard-on-finish="deleteCredential" | ||
data-wizard-title="i18n.user_credentials_delete_modal_title"> | ||
|
||
<div data-wizard-step> | ||
|
||
<p data-ng-bind-html="tr('user_credentials_delete_modal_step1_question', [$ctrl.credential.name])"></p> | ||
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. tr? Should be $translate now :) 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. Yes I need to rebase on |
||
|
||
</div> | ||
|
||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
angular.module("UserAccount.controllers") | ||
.controller("UserAccount.controllers.credentials.read", class UserAccountCredentialsReadController { | ||
constructor ($scope) { | ||
this.$scope = $scope; | ||
this.credential = $scope.currentActionData; | ||
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. You can move this to |
||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<div data-ng-controller="UserAccount.controllers.credentials.read as $ctrl"> | ||
|
||
<div data-wizard | ||
data-wizard-on-cancel="resetAction" | ||
data-wizard-on-finish="resetAction" | ||
data-wizard-title="i18n.user_credentials_read_modal_title"> | ||
|
||
<div data-wizard-step> | ||
|
||
<p data-ng-bind="$ctrl.credential.name"></p> | ||
<table class="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th scope="col" | ||
data-i18n-static="user_credentials_permissions_method"> | ||
</th> | ||
<th scope="col" | ||
data-i18n-static="user_credentials_permissions_path"> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr data-ng-repeat="rule in $ctrl.credential.rules track by $index"> | ||
<td> | ||
<span class="label" | ||
data-ng-class="{ | ||
'label-danger': rule.method === 'DELETE', | ||
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 is |
||
'label-success': rule.method === 'POST', | ||
'label-info': rule.method === 'GET', | ||
'label-warning': rule.method === 'PUT' | ||
}" | ||
data-ng-bind="rule.method"> | ||
</span> | ||
</td> | ||
<th scope="row" | ||
data-ng-bind="rule.path"> | ||
</th> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
angular.module("UserAccount.controllers") | ||
.controller("UserAccount.controllers.credentials", class UserAccountCredentialsController { | ||
|
||
constructor ($q, $scope, Alerter, UseraccountCredentialsService) { | ||
this.$q = $q; | ||
this.$scope = $scope; | ||
this.Alerter = Alerter; | ||
this.UseraccountCredentialsService = UseraccountCredentialsService; | ||
|
||
this.$scope.$on("useraccount.credentials.refresh", () => { | ||
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. Move to |
||
this.$onInit(); | ||
}); | ||
} | ||
|
||
$onInit () { | ||
this.credentialsIds = []; | ||
|
||
return this.getCredentials(); | ||
} | ||
|
||
/** | ||
* Get the list of your Api Credentials IDs. | ||
* @return {Promise} | ||
*/ | ||
getCredentials () { | ||
return this.UseraccountCredentialsService.getCredentials() | ||
.then((credentialsIds) => { | ||
this.credentialsIds = credentialsIds; | ||
return credentialsIds; | ||
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. Is this needed ? You already have |
||
}) | ||
.catch((err) => { | ||
this.Alerter.error(`${this.$scope.tr("user_credentials_error")} ${_.get(err, "message", "")}`, "userCredentials"); | ||
}); | ||
} | ||
|
||
loadDatagridCredentials ({ offset, pageSize }) { | ||
return this.getCredentials() | ||
.then(() => { | ||
const part = this.credentialsIds.slice(offset - 1, offset - 1 + pageSize); | ||
return { | ||
data: part.map((id) => ({ id })), | ||
meta: { | ||
totalCount: this.credentialsIds.length | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
transformItem (credential) { | ||
return this.UseraccountCredentialsService | ||
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. return this.UseraccountCredentialsService
.getCredential(credential.id)
.then((credentialInfo) => this.UseraccountCredentialsService
.getApplication(credentialInfo.credentialId)
.then((applicationInfo) => _.assign(credentialInfo, applicationInfo))); to return this.UseraccountCredentialsService
.getCredential(credential.id)
.then((credentialInfo) => this.UseraccountCredentialsService.getApplication(credentialInfo.credentialId))
.then((applicationInfo) => _.assign(credentialInfo, applicationInfo)); |
||
.getCredential(credential.id) | ||
.then((credentialInfo) => this.UseraccountCredentialsService | ||
.getApplication(credentialInfo.credentialId) | ||
.then((applicationInfo) => _.assign(credentialInfo, applicationInfo))); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<div class="module-useraccount-sections-credentials-container"> | ||
|
||
<div class="page-header"> | ||
<h1 data-i18n-static="user_credentials_title"></h1> | ||
</div> | ||
|
||
<div class="tab-content"> | ||
|
||
<div data-ovh-alert="userCredentials"></div> | ||
|
||
<!-- CREDENTIALS EXPLAIN --> | ||
<oui-message class="d-block mb-4" | ||
data-type="info"> | ||
<span data-i18n-static="user_credentials_info"></span> | ||
</oui-message> | ||
|
||
<!-- CREDENTIALS LIST --> | ||
<oui-datagrid data-rows-loader="$ctrl.loadDatagridCredentials($config)" | ||
data-row-loader="$ctrl.transformItem($row)"> | ||
<oui-column data-title=":: i18n.user_credentials_name" | ||
data-property="name"> | ||
</oui-column> | ||
<oui-column data-title=":: i18n.user_credentials_desc"> | ||
<span data-ng-if="$row.description.length > 20" | ||
data-ng-bind="($row.description | limitTo:'15') + '…'" | ||
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. 👍 |
||
data-uib-tooltip="{{ $row.description }}"> | ||
</span> | ||
<span data-ng-if="$row.description.length <= 20" | ||
data-ng-bind="$row.description"> | ||
</span> | ||
</oui-column> | ||
<oui-column data-title=":: i18n.user_credentials_creation_date"> | ||
<span data-ng-bind="$row.creation | date"></span> | ||
</oui-column> | ||
<oui-column data-title=":: i18n.user_credentials_expiration_date"> | ||
<span data-ng-bind="($row.expiration | date) || '-'"></span> | ||
</oui-column> | ||
<oui-action-menu data-align="end" | ||
data-compact> | ||
<oui-action-menu-item data-text="{{:: i18n.user_credentials_read }}" | ||
data-ng-click="setAction('credentials/read/user-credentials-read', $row)"> | ||
</oui-action-menu-item> | ||
<oui-action-menu-item data-text="{{:: i18n.user_credentials_delete }}" | ||
data-ng-click="setAction('credentials/delete/user-credentials-delete', $row)"> | ||
</oui-action-menu-item> | ||
</oui-action-menu> | ||
</oui-datagrid> | ||
</div> | ||
|
||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
angular | ||
.module("UserAccount") | ||
.config(["$stateProvider", function ($stateProvider) { | ||
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. No need to inject $stateProvider before the function, grunt ng-annotate task do it for you :) |
||
$stateProvider.state("app.account.useraccount.credentials", { | ||
url: "/credentials", | ||
templateUrl: "account/user/credentials/user-credentials.html", | ||
controller: "UserAccount.controllers.credentials", | ||
controllerAs: "$ctrl" | ||
}); | ||
}]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
angular.module("UserAccount.services") | ||
.service("UseraccountCredentialsService", class UseraccountCredentialsService { | ||
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. It should be in ovh-api-services :) 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. You're right! I'll have to merge and release this pull request first. |
||
constructor (OvhHttp) { | ||
this.OvhHttp = OvhHttp; | ||
} | ||
|
||
getCredentials () { | ||
return this.OvhHttp.get("/me/api/credential", { | ||
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. you should use a variable for the pattern: "/me/api/credential" and use it across your methods :) 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.
|
||
rootPath: "apiv6" | ||
}); | ||
} | ||
|
||
getCredential (credentialId) { | ||
return this.OvhHttp.get("/me/api/credential/{credentialId}", { | ||
rootPath: "apiv6", | ||
urlParams: { | ||
credentialId | ||
} | ||
}); | ||
} | ||
|
||
getApplication (credentialId) { | ||
return this.OvhHttp.get("/me/api/credential/{credentialId}/application", { | ||
rootPath: "apiv6", | ||
urlParams: { | ||
credentialId | ||
} | ||
}); | ||
} | ||
|
||
deleteCredential (credentialId) { | ||
return this.OvhHttp.delete("/me/api/credential/{credentialId}", { | ||
rootPath: "apiv6", | ||
urlParams: { | ||
credentialId | ||
}, | ||
broadcast: "useraccount.credentials.refresh" | ||
}); | ||
} | ||
}); |
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.
No need for this if you use a
class