Skip to content
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

identities delete icon #1013

Closed
avinash-0007 opened this issue Mar 13, 2023 · 6 comments
Closed

identities delete icon #1013

avinash-0007 opened this issue Mar 13, 2023 · 6 comments
Labels
documentation Improvements or additions to documentation

Comments

@avinash-0007
Copy link

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?

@avinash-0007
Copy link
Author

specific identity of particular domain i dont want to allow to delete it?

@the-djmaze
Copy link
Owner

Currently this is not possible.
Instead, you could write a plugin that add it back on delete

@the-djmaze
Copy link
Owner

the-djmaze commented Apr 11, 2023

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
	}
}

@the-djmaze the-djmaze added the documentation Improvements or additions to documentation label Apr 11, 2023
@the-djmaze the-djmaze reopened this Apr 11, 2023
@avinash-0007
Copy link
Author

I dont want to a delete button in some of the domains identities but above code only allow to stop it while deleting

the-djmaze pushed a commit that referenced this issue May 8, 2023
@the-djmaze
Copy link
Owner

the-djmaze commented May 8, 2023

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)}');
}

@avinash-0007
Copy link
Author

avinash-0007 commented May 9, 2023

@the-djmaze the above code does not work.
e.detail.viewModelTemplateID not returning SettingsAccounts

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants