예제 #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})
예제 #2
0
 def update(self):
     try:
         registry = self.registry()[0]
     except psycopg2.OperationalError:
         if self.state != 'draft':
             self.state = 'deleted'
         return
     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)
예제 #3
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)
예제 #4
0
    def setUp(self):
        self.registry = RegistryManager.get(get_db_name())
        #: current transaction's cursor
        self.cr = self.cursor()
        self.uid = ecore.SUPERUSER_ID
        #: :class:`~ecore.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()
예제 #5
0
파일: hooks.py 프로젝트: ecoreos/hz
def set_default_map_settings(cr, registry):
    """Method called as post-install script
    The default method on the field can't be used, because it would be executed
    before loading map_website_data.xml, so it would not be able to set a
    value"""
    with api.Environment.manage():
        env = api.Environment(cr, SUPERUSER_ID, {})
        user_model = env['res.users']
        users = user_model.search([('context_map_website_id', '=', False)])
        logger.info('Updating user settings for maps...')
        users.write({
            'context_map_website_id':
            user_model._default_map_website().id,
            'context_route_map_website_id':
            (user_model._default_route_map_website().id),
        })
    # Update the starting partner this way that is faster
    cr.execute("""
        UPDATE res_users
        SET context_route_start_partner_id = partner_id
        WHERE context_route_start_partner_id IS NULL;
        """)
예제 #6
0
 def setUpClass(cls):
     cls.registry = RegistryManager.get(get_db_name())
     cls.cr = cls.registry.cursor()
     cls.uid = ecore.SUPERUSER_ID
     cls.env = api.Environment(cls.cr, cls.uid, {})
예제 #7
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
            }),
        })
예제 #8
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)
예제 #9
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]