Example #1
0
    def populate(self, email, account_name, human_first_name, human_last_name, expire_date=None):
        """Populate data for a new VirtAccount.

        The caller is responsible for populating VirtAccount owner's human
        name elsewhere, if the name at all exists.
        
        @type email: basestring
        @param email:
          E-mail address associated with this VirtAccount. This is the only
          communication channel with whoever/whatever really owns a
          VirtAccount.

        @type account_name: basestring
        @param account_name:
          Account name for this VirtAccount structured as <name>@<realm>. The
          <realm> is fixed -- cereconf.VIRTACCOUNT_REALM. <name> cannot
          contain '@' and it cannot be empty. Account names are obviously
          unique (within the virthome realm). This can be used as an id. 

        @type expire_date: mx.DateTime.DateTime
        @param expire_date:
          Expiration date for the account (an expired account is no longer
          considered available for any external services). If nothing is
          specified a default of now (creation date) + 1 year is used.
        """

        # IVR 2009-04-11 FIXME: We need to check that at the very least the
        # email is in a valid format.
        assert email and email.strip(), "VirtHome e-mail addresses cannot be empty"

        # Double check that the username is available
        assert self.uname_is_available(account_name), "Username already taken"

        Account.populate(
            self,
            account_name,
            # VA is owned by the system
            self.const.entity_group,
            self.initial_group,
            self.account_type,
            # VA is created by the system
            self.initial_account,
            expire_date,
        )
        self.extend_expire_date(expire_date)

        self.populate_contact_info(self.const.system_virthome)
        self.populate_contact_info(self.const.system_virthome, self.const.virthome_contact_email, email)
        # Push the names in. NB! Don't store the full name -- we'll derive it
        # later as needed.
        self.populate_contact_info(self.const.system_virthome, self.const.human_first_name, human_first_name)
        self.populate_contact_info(self.const.system_virthome, self.const.human_last_name, human_last_name)
Example #2
0
def create_user(uname, db):
    """Helper function to create some system users we need in VH.

    uname will be owned by the system group andit will have been created by
    the system account.
    """

    account = Account(db)
    constants = Factory.get("Constants")()
    try:
        account.find_by_name(uname)
        logger.debug("Found account with name=%s, id=%s", account.account_name,
                     account.entity_id)
        return
    except Errors.NotFoundError:
        sys_group = get_system_group(db)
        sys_account = get_system_account(db)
        account.populate(
            uname,
            constants.entity_group,  # owned by 
            sys_group.entity_id,  # ... system group
            constants.account_program,
            sys_account.entity_id,  # created by system account
            None)  # no expire (duh!)
        account.write_db()
        logger.debug("Created account uname=%s, id=%s", account.account_name,
                     account.entity_id)
        logger.debug("Don't forget to set a password on uname=%s",
                     account.account_name)
Example #3
0
def get_entity(ident, entity_type, db):
    """Find a group, given its identity.

    This is much like what _get_group()/_get_account() in bofhd does... except simpler
    """

    const = Factory.get("Constants")()
    if entity_type in ('group', const.entity_group):
        obj = Factory.get("Group")(db)
    elif entity_type in ('account', const.entity_account):
        obj = Account(db)

    finder = None
    if isinstance(ident, str):
        if ident.isdigit():
            finder = obj.find
        else:
            finder = obj.find_by_name
    elif isinstance(ident, int):
        finder = obj.find
    else:
        assert False

    finder(ident)
    return obj
Example #4
0
def create_user(uname, db):
    """Helper function to create some system users we need in VH.

    uname will be owned by the system group andit will have been created by
    the system account.
    """

    account = Account(db)
    constants = Factory.get("Constants")()
    try:
        account.find_by_name(uname)
        logger.debug("Found account with name=%s, id=%s",
                     account.account_name, account.entity_id)
        return
    except Errors.NotFoundError:
        sys_group = get_system_group(db)
        sys_account = get_system_account(db)
        account.populate(uname,
                         constants.entity_group,       # owned by 
                         sys_group.entity_id,          # ... system group
                         constants.account_program, 
                         sys_account.entity_id, # created by system account
                         None)                  # no expire (duh!)
        account.write_db()
        logger.debug("Created account uname=%s, id=%s",
                     account.account_name, account.entity_id)
        logger.debug("Don't forget to set a password on uname=%s",
                     account.account_name)
def prepare_empty(db, args):
    """This function constructs a destination group
    if it doesn't exist."""
    co = Factory.get('Constants')(db)
    gr = Factory.get('Group')(db)
    try:
        gr.find_by_name(args.destination_group)
    except Errors.NotFoundError:
        bootstrap_ac = Account(db)
        bootstrap_ac.find_by_name(cereconf.INITIAL_ACCOUNTNAME)
        gr.populate(
            creator_id=bootstrap_ac.entity_id,
            visibility=co.group_visibility_all,
            name=args.destination_group,
            description=('Flattened variant of %s' % args.target_group),
            group_type=co.group_type_derived,
        )
    gr.write_db()
Example #6
0
    def setUpClass(cls):
        """ Set up this TestCase module.

        This setup code sets up shared objects between each tests. This is done
        *once* before running any of the tests within this class.
        """

        # TODO: We might want this basic class setup in other TestCases. Maybe
        #       set up a generic TestCase class to inherit common stuff from?
        cls._db = Factory.get('Database')()
        cls._db.cl_init(change_program='nosetests')
        cls._db.commit = cls._db.rollback  # Let's try not to screw up the db

        cls._ac = Factory.get('Account')(cls._db)
        cls._ac = Account(cls._db)
        cls._co = Factory.get('Constants')(cls._db)

        # Data sources
        cls.account_ds = BasicAccountSource()
        cls.person_ds = BasicPersonSource()

        # Tools for creating and destroying temporary db items
        cls.db_tools = DatabaseTools(cls._db)
        cls.db_tools._ac = cls._ac
Example #7
0
    def populate(self,
                 email,
                 account_name,
                 human_first_name,
                 human_last_name,
                 expire_date=None):
        """Populate data for a new VirtAccount.

        The caller is responsible for populating VirtAccount owner's human
        name elsewhere, if the name at all exists.
        
        @type email: basestring
        @param email:
          E-mail address associated with this VirtAccount. This is the only
          communication channel with whoever/whatever really owns a
          VirtAccount.

        @type account_name: basestring
        @param account_name:
          Account name for this VirtAccount structured as <name>@<realm>. The
          <realm> is fixed -- cereconf.VIRTACCOUNT_REALM. <name> cannot
          contain '@' and it cannot be empty. Account names are obviously
          unique (within the virthome realm). This can be used as an id. 

        @type expire_date: mx.DateTime.DateTime
        @param expire_date:
          Expiration date for the account (an expired account is no longer
          considered available for any external services). If nothing is
          specified a default of now (creation date) + 1 year is used.
        """

        # IVR 2009-04-11 FIXME: We need to check that at the very least the
        # email is in a valid format.
        assert email and email.strip(
        ), "VirtHome e-mail addresses cannot be empty"

        # Double check that the username is available
        assert self.uname_is_available(account_name), "Username already taken"

        Account.populate(
            self,
            account_name,
            # VA is owned by the system
            self.const.entity_group,
            self.initial_group,
            self.account_type,
            # VA is created by the system
            self.initial_account,
            expire_date)
        self.extend_expire_date(expire_date)

        self.populate_contact_info(self.const.system_virthome)
        self.populate_contact_info(self.const.system_virthome,
                                   self.const.virthome_contact_email, email)
        # Push the names in. NB! Don't store the full name -- we'll derive it
        # later as needed.
        self.populate_contact_info(self.const.system_virthome,
                                   self.const.human_first_name,
                                   human_first_name)
        self.populate_contact_info(self.const.system_virthome,
                                   self.const.human_last_name, human_last_name)