Files
threshold-ui/ui/admin/app/components/form/auth-method/ldap/index.js
T
Lisbet AlvarezandDharini Jeeva 3b284fac66 refactor: 💡 update to allow state change & update edit action (#1797)
* refactor: 💡 update to allow state change & update edit action

✅ Closes: ICU-10078

* test: 💍 add more update and delete test cases

* refactor: 💡 auth-method serializer

* refactor: 💡 add secret input fields

* refactor: 💡 remove changes to ldap auth method serializer

---------

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
2023-07-27 14:25:40 -07:00

100 lines
2.0 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { options } from 'api/models/auth-method';
import { set } from '@ember/object';
export default class FormAuthMethodLdapComponent extends Component {
// =attributes
/**
* @type {object}
*/
toAttributes = options.ldap.account_attribute_maps.to;
/**
* @type {string}
*/
newToAttribute = options.ldap.account_attribute_maps.to[0];
/**
* @type {string}
*/
@tracked newFromAttribute = '';
/**
* @type {string}
*/
@tracked newCertificate = '';
/**
* @type {string}
*/
@tracked urlsArrayString = this.parseUrlsArray();
//actions
/**
* @param {object} event
*/
@action
toggleField(event) {
const { name: field } = event.target;
this.args.model[field] = !this.args.model[field];
}
@action
addCertificate() {
if (this.newCertificate) {
this.args.addStringItem('certificates', this.newCertificate);
}
this.newCertificate = '';
}
@action
addAttributeMap() {
if (this.newFromAttribute) {
this.args.addAccountMapItem(
'account_attribute_maps',
this.newFromAttribute,
this.newToAttribute
);
}
this.newFromAttribute = '';
}
/**
* @param {object} event
*/
@action
setUrls(event) {
const { value } = event.target;
this.urlsArrayString = value;
const array = value.split(',').map((item) => ({ value: item }));
this.args.model.set('urls', array);
}
/**
* @returns {string}
*/
parseUrlsArray() {
return (this.args.model.urls || []).map((item) => item.value).toString();
}
/**
* @param {string} currentAttr
*/
@action
rollbackSecretAttrs(currentAttr) {
const changedAttrs = this.args.model.changedAttributes();
if (currentAttr in changedAttrs) {
const [oldVal] = changedAttrs[currentAttr];
set(this.args.model, currentAttr, oldVal);
}
}
}