Beispiel #1
0
 def test03_user_access(self):
     """ Setting the user pref raises an access error if the user is not \
     in group_no_one """
     user = self.env['res.users'].create({
         'name': 'Test user technical features',
         'login': '******',
         'groups_id': [(6, 0, [])]
     })
     with api.Environment.manage():
         env = api.Environment(self.env.cr, user.id, self.env.context)
         with self.assertRaises(AccessError):
             env['res.users'].browse(user.id).write(
                 {'technical_features': True})
     with self.assertRaises(AccessError):
         user.write({'technical_features': True})
     user.write({'groups_id': [(4, self.env.ref('base.group_no_one').id)]})
     with api.Environment.manage():
         env = api.Environment(self.env.cr, user.id, self.env.context)
         env['res.users'].browse(user.id).write(
             {'technical_features': True})
Beispiel #2
0
 def install_addons(self, addons, is_template_db):
     addons = set(addons)
     addons.add('mail_delete_sent_by_footer')  # debug
     if is_template_db:
         addons.add('auth_oauth')
         addons.add('saas_client')
     else:
         addons.add('saas_client')
     if not addons:
         return
     with self.registry()[0].cursor() as cr:
         env = api.Environment(cr, SUPERUSER_ID, self._context)
         self._install_addons(env, addons)
Beispiel #3
0
    def update(self):
        try:
            registry = self.registry()[0]

            with registry.cursor() as client_cr:
                client_env = api.Environment(client_cr, SUPERUSER_ID,
                                             self._context)
                data = self._get_data(client_env, self.client_id)[0]
                self.write(data)
        except psycopg2.OperationalError:
            if self.state != 'draft':
                self.state = 'deleted'
            return
Beispiel #4
0
    def setUp(self):
        self.registry = RegistryManager.get(get_db_name())
        #: current transaction's cursor
        self.cr = self.cursor()
        self.uid = yuancloud.SUPERUSER_ID
        #: :class:`~yuancloud.api.Environment` for the current test case
        self.env = api.Environment(self.cr, self.uid, {})

        @self.addCleanup
        def reset():
            # rollback and close the cursor, and reset the environments
            self.registry.clear_caches()
            self.env.reset()
            self.cr.rollback()
            self.cr.close()
Beispiel #5
0
 def upgrade_database(self, **kwargs):
     with self.registry()[0].cursor() as cr:
         env = api.Environment(cr, SUPERUSER_ID, self._context)
         return self._upgrade_database(env, **kwargs)[0]
Beispiel #6
0
 def prepare_database(self, **kwargs):
     with self.registry()[0].cursor() as cr:
         env = api.Environment(cr, SUPERUSER_ID, self._context)
         self._prepare_database(env, **kwargs)
Beispiel #7
0
 def setUpClass(cls):
     cls.registry = RegistryManager.get(get_db_name())
     cls.cr = cls.registry.cursor()
     cls.uid = yuancloud.SUPERUSER_ID
     cls.env = api.Environment(cls.cr, cls.uid, {})
Beispiel #8
0
    def new_database(self, **post):
        _logger.info('new_database post: %s', post)

        state = simplejson.loads(post.get('state'))
        owner_user = state.get('owner_user')
        new_db = state.get('d')
        trial = state.get('t')
        expiration_db = state.get('e')
        template_db = state.get('db_template')
        disable_mail_server = state.get('disable_mail_server', False)
        demo = state.get('demo')
        lang = state.get('lang', 'en_US')
        tz = state.get('tz')
        addons = state.get('addons', [])
        is_template_db = state.get('is_template_db')
        action = 'base.open_module_tree'
        access_token = post['access_token']

        client_id = post['client_id']
        saas_oauth_provider = request.registry[
            'ir.model.data'].xmlid_to_object(
                request.cr, SUPERUSER_ID, 'saas_server.saas_oauth_provider')
        saas_portal_user = request.registry['res.users']._auth_oauth_rpc(
            request.cr, SUPERUSER_ID, saas_oauth_provider.validation_endpoint,
            access_token)
        if saas_portal_user.get('user_id') != 1:
            raise Exception('auth error')
        if saas_portal_user.get("error"):
            raise Exception(saas_portal_user['error'])

        client_data = {
            'name': new_db,
            'client_id': client_id,
            'expiration_datetime': expiration_db,
            'trial': trial
        }
        client = request.env['saas_server.client'].sudo().create(client_data)
        client.create_database(template_db, demo, lang)
        client.install_addons(addons=addons, is_template_db=is_template_db)
        if disable_mail_server:
            client.disable_mail_servers()
        client.update_registry()
        client.prepare_database(tz=tz,
                                owner_user=owner_user,
                                is_template_db=is_template_db,
                                access_token=access_token)

        if is_template_db:
            res = [{
                'name': client.name,
                'state': client.state,
                'client_id': client.client_id
            }]
            return simplejson.dumps(res)

        with client.registry()[0].cursor() as cr:
            client_env = api.Environment(cr, SUPERUSER_ID, request.context)
            oauth_provider_id = client_env.ref(
                'saas_server.saas_oauth_provider').id
            action_id = client_env.ref(action).id

        port = self._get_port()
        scheme = request.httprequest.scheme
        url = '{scheme}://{domain}:{port}/saas_client/new_database'.format(
            scheme=scheme, domain=new_db, port=port)
        return simplejson.dumps({
            'url':
            url,
            'state':
            simplejson.dumps({
                'd': new_db,
                'p': oauth_provider_id,
                'a': action_id
            }),
        })