Closed avinash-0007 closed 10 months ago
specific identity of particular domain i dont want to allow to delete it?
Currently this is not possible. Instead, you could write a plugin that add it back on delete
Here's an example
class MyIdentitiesPlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init() : void
{
$this->addHook("json.before-IdentityDelete", 'beforeIdentityDelete')
$this->addHook("json.after-AccountsAndIdentities", 'afterAccountsAndIdentities')
}
public function beforeIdentityDelete()
{
$sId = \trim($this->Manager()->Actions()->GetActionParam('idToDelete', ''));
if ('NotAllowed' = $sId) {
// Throw exception
}
}
public function afterAccountsAndIdentities(array &$aResponse)
{
// find identity in $aResponse['Identities']
// if not found, add the RainLoop\Model\Identity
}
}
I dont want to a delete button in some of the domains identities but above code only allow to stop it while deleting
I've added a change so you can solve this with CSS.
[data-identity-id="0123456"] .delete {
display: none;
}
Where 0123456
is the id of the identity.
If you need a more complex solution, this is possible with JavaScript. Here's some pseudo code
addEventListener('rl-view-model.create', event => {
if ('SettingsAccounts' === e.detail.viewModelTemplateID) {
// https://github.com/the-djmaze/snappymail/blob/master/dev/Settings/User/Accounts.js
let view = e.detail;
// https://knockoutjs.com/documentation/observableArrays.html
// view.identities.subscribe(fn, thisArg, "arrayChange");
view.canDelete = ko.computed(identity =>
!identity.askDelete() && identity.id() && !identity.email().includes('@domain')
);
}
});
let template = document.getElementById('SettingsAccounts');
const deleteBtn = template.content.querySelector('.identities-list .delete');
if (deleteBtn) {
deleteBtn.dataset.bind.replace('!askDelete() && id()', 'function(){$root.canDelete($data)}');
}
@the-djmaze the above code does not work. e.detail.viewModelTemplateID not returning SettingsAccounts
In settings->accounts,
i have multiple identities but i wanted to stop user from deleting the specific identity . Is there any way to do so?