Skip to content

[improvement/request] Hide Alias-Domains in list-virtual.php/template as Selectable #841

Open

Description

@Ramalama2

If Alias-Domains point to another Domain, there is no reason to select that domain, since you cant add there Mailboxes or Alias Email-Adresses.

So Displaying Alias-Domains is just "nervy" because sometimes if you visit list-virtual, an Alias Domain could be selected by default...
And it will be anyway always empty.

Im Searching a way to hide them entirely in the Domain Select Dropdowns, if they point to another Domains.

But its really not that easy, public/list-virtual.php is hard to understand.
I thought initially it does some select from a Database Query, which i could modify...
But yeah, its a little bit more complicated as that.

Can anyone give me a hint?

Activity

  1. Ramalama2 commented on Jul 11, 2024

    @Ramalama2
    Author

    I have a half working solution:

    in functions.inc.php:

    function list_domains_for_admin($username)
    {
        $table_domain = table_by_key('domain');
        $table_domain_admins = table_by_key('domain_admins');
    
        $condition = array();
    
        $E_username = escape_string($username);
    
        $query = "SELECT $table_domain.domain FROM $table_domain ";
        $condition[] = "$table_domain.domain != 'ALL'";
        $condition[] = "$table_domain.domain NOT IN (SELECT alias_domain FROM alias_domain WHERE active = 1)";
    
        $pvalues = array();
    
        $result = db_query_one("SELECT username FROM $table_domain_admins WHERE username= :username AND domain='ALL'", array('username' => $username));
        if (empty($result)) { # not a superadmin
            $pvalues['username'] = $username;
            $pvalues['active'] = db_get_boolean(true);
            $pvalues['backupmx'] = db_get_boolean(false);
    
            $query .= " LEFT JOIN $table_domain_admins ON $table_domain.domain=$table_domain_admins.domain ";
            $condition[] = "$table_domain_admins.username = :username  ";
            $condition[] = "$table_domain.active = :active "; # TODO: does it really make sense to exclude inactive...
            $condition[] = "$table_domain.backupmx = :backupmx"; # TODO: ... and backupmx domains for non-superadmins?
        }
    
        $query .= " WHERE " . join(' AND ', $condition);
        $query .= " ORDER BY $table_domain.domain";
    
        $result = db_query_all($query, $pvalues);
    
        return array_column($result, 'domain');
    }
    

    I have added the line:
    $condition[] = "$table_domain.domain NOT IN (SELECT alias_domain FROM alias_domain WHERE active = 1)";

    It works almost as expected, but the issue is, that Alias-Domains dissappear everywhere, not just in list-virtual xD

    So yeah, i need an entire new function, that i can use only in list-virtual i think.
    Not sure how to do it differently, since i just want to hide the Alias-Domains from the Dropdowns in list-virtual and in the dropdown of creating new alias user.
    Mhhh

  2. Ramalama2 commented on Jul 11, 2024

    @Ramalama2
    Author

    Yeah, i simply duplicated the function, leaving one as original and renamed the other to: list_domains_without_aliasdomain

    and using my function only in list-virtual.php:
    $list_domains = list_domains_without_aliasdomain($admin_username);

    That does exactly what i want.
    I just thought there is a more beatifull way. So that code could possibly be used by others or even added an config.local.php setting and merged.

    But in this state, its only usefull for me :-(

    Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions