예제 #1
0
    def get(self):
        """Return salesperson of an account
        """
        context = pecan.request.context

        user_id = self.user_id
        conn = pecan.request.db_conn
        account = conn.get_account(context, user_id)
        sales_id = account.sales_id
        if not sales_id:
            # Only allow sales admin to know that an account
            # belongs to no salesperson.
            check_policy(context, 'uos_sales_admin')
            return models.SalesPerson()

        # Only allow salesperson to get account that
        # belongs to himself/herself.
        if not acl.limit_to_sales(context, sales_id):
            raise exception.NotAuthorized()

        try:
            sales_user = keystone.get_uos_user(sales_id)
            return models.SalesPerson(
                user_id=sales_id,
                user_name=sales_user['name'],
                user_email=sales_user.get('email', ''),
                real_name=sales_user.get('real_name', ''),
                mobile_number=sales_user.get('mobile_number', ''),
                company=sales_user.get('company', ''))
        except (exception.NotFound):
            msg = _('Could not find salesperson %s of account %s'
                    ' from keystone' % (sales_id, user_id))
            LOG.error(msg)
            raise exception.NotFound(msg)
예제 #2
0
 def mocked_get_uos_user(self, user_id):
     account = self.get_account_from_list(user_id, self.sales_customers)
     if account:
         user = self.build_uos_user_info_from_keystone(
             user_id=account.user_id, name=account.name,
             email=account.email)
         return user
     else:
         raise exception.NotFound()
예제 #3
0
def get_uos_user_by_name(user_name):

    auth_url = get_auth_url()
    internal_api = lambda api: auth_url + '/US-INTERNAL'+ '/' + api

    query = {'query': {'name': user_name}}
    r = requests.post(internal_api('get_user'),
                      data=json.dumps(query),
                      headers={'Content-Type': 'application/json'})
    if r.status_code == 404:
        LOG.warn("can't not find user %s from keystone" % user_name)
        raise exception.NotFound()
    return r.json()['user']
예제 #4
0
    def delete(self):
        """Delete the account including the projects that belong to it."""
        # only admin can delete account
        check_policy(request.context, "account:delete")

        try:
            self.conn = pecan.request.db_conn
            self.conn.delete_account(request.context, self._id)
        except (exception.NotFound):
            msg = _('Could not find account whose user_id is %s' % self._id)
            raise exception.NotFound(msg)
        except Exception as e:
            msg = _("failed to delete account whose user_id is %s." % self._id)
            LOG.warn(msg)
            raise exception.DBError(reason=e)
예제 #5
0
def get_uos_user(user_id):
    # NOTE(chengkun): Now The user's detail info is stored in kunkka,
    # so we should use kunkka api to get user info.
    ks_cfg = cfg.CONF.keystone_authtoken
    auth_url = '%s://%s' % (ks_cfg.auth_protocol, ks_cfg.auth_host)
    url = auth_url + '/api/v1/user/%s' % user_id
    r = requests.get(url,
                     headers={
                         'Content-Type': 'application/json',
                         'X-Auth-Token': keystone.get_token()
                     })
    if r.status_code == 404:
        LOG.warn("can't not find user %s from kunkka" % user_id)
        raise exception.NotFound()
    return r.json()