the-djmaze / snappymail

Simple, modern & fast web-based email client
https://snappymail.eu
GNU Affero General Public License v3.0
989 stars 117 forks source link

identities delete icon #1013

Closed avinash-0007 closed 10 months ago

avinash-0007 commented 1 year ago

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 commented 1 year ago

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

the-djmaze commented 1 year ago

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

the-djmaze commented 1 year ago

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
    }
}
avinash-0007 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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