def connect_domain_ou(ou_id, dom_id, c_aff): ee_dom = Email.EntityEmailDomain(db) ee_dom.clear() try: ee_dom.find(ou_id, c_aff) except Errors.NotFoundError: ee_dom.populate_email_domain(dom_id, c_aff) ee_dom.write_db()
def get_primary_maildomain(self): """Return correct `domain_id' for account's primary address.""" dom = Email.EmailDomain(self._db) dom.find_by_domain(Email.get_primary_default_email_domain()) entdom = Email.EntityEmailDomain(self._db) # Find OU and affiliation for this user's best-priority # account_type entry. for row in self.get_account_types(): ou, aff = row['ou_id'], row['affiliation'] # If a maildomain is associated with this (ou, aff) # combination, then that is the user's default maildomain. entdom.clear() try: entdom.find(ou, affiliation=aff) # # This if-test assumes that the cereconf.EMAIL_DEFAULT_DOMAIN # cannot be considered as a primary domain if another # valid domain is found for an account. The behaviour is wrong # for ØFK as quite av few of the accounts should have primary # addresses in default domain while they have other domains # Jazz # # If the default domain is specified, ignore this # affiliation. # if entdom.entity_email_domain_id == dom.entity_id: # continue return entdom.entity_email_domain_id except Errors.NotFoundError: pass # Otherwise, try falling back to tha maildomain associated # with (ou, None). entdom.clear() try: entdom.find(ou) if entdom.entity_email_domain_id == dom.entity_id: continue return entdom.entity_email_domain_id except Errors.NotFoundError: pass # Still no proper maildomain association has been found; fall # back to default maildomain. return dom.entity_id
def get_report(exclude_empty): """Returns a list of OUs with no email domain""" db = Factory.get("Database")() co = Factory.get("Constants")(db) ou = Factory.get("OU")(db) ac = Factory.get("Account")(db) email = Email.EmailDomain(db) eed = Email.EntityEmailDomain(db) # Count the number of accounts in each OU ou_to_num_accounts = {} for acc in ac.list_accounts_by_type(): ou_id = acc['ou_id'] if ou_to_num_accounts.has_key(ou_id): ou_to_num_accounts[ou_id] += 1 else: ou_to_num_accounts[ou_id] = 1 # Map OU ids to email domain ou_to_domain = {} for dom in email.list_email_domains(): for affs in eed.list_affiliations(domain_id=dom['domain_id']): ou_to_domain[affs[0]] = dom['domain_id'] # Iterate through OUs report = [] for sko in ou.get_stedkoder(): ou_id = sko['ou_id'] if exclude_empty and not ou_to_num_accounts.has_key(ou_id): continue if not ou_to_domain.has_key(ou_id): ou.clear() ou.find(ou_id) ou_quarantine = ou.get_entity_quarantine() # Skip if OU is in quarantine if len(ou_quarantine) is 0: if not ou_to_num_accounts.has_key(ou_id): ou_num_accounts = 0 else: ou_num_accounts = ou_to_num_accounts[ou_id] ou_name = ou.get_name_with_language( name_variant=co.ou_name, name_language=co.language_nb, default="") report.append({ 'stedkode': '%02d%02d%02d' % (sko['fakultet'], sko['institutt'], sko['avdeling']), 'ou_id': ou_id, 'ou_num_accounts': ou_num_accounts, 'ou_name': ou_name }) return sorted(report, key=lambda k: k['stedkode'])