Files
threshold-ui/ui/admin/app/components/form/auth-method/ldap/index.js
T
Lisbet Alvarez 3ba93927fe Update copyright headers (#3146)
* empty commit

* Add missing copyright headers

* chore: 🤖 update copywrite config file with correct year

* Add missing copyright headers

* empty commit (gh action merge checks are stuck)
2026-01-28 17:09:06 -08:00

102 lines
2.1 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
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];
dereferenceAliasesList = options.ldap.dereference_aliases;
/**
* @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);
}
}
}