Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • how to add access rights and group_id in object models in OpenERP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 388
    Comment on it

    In OpenERP to add access rights and group_id in object models first we have to create users and users have many type of access rights and those access rights were provided by admin. object models reference in fields_relations intersects with access rights of current user to avoid granting too much rights.

    Use this function given below

    def access_group(self, cr, uid, group_id, mode, fields_relations, context=None):
          
            model_access_obj = self.pool.get('ir.model.access')
            user_obj = self.pool.get('res.users')
            target_model_ids = [x[1].id for x in fields_relations]
            perms_to_add = (mode == 'readonly') and READ_ONLY_ACCESS or READ_WRITE_ACCESS
            current_user = user_obj.browse(cr, uid, uid, context=context)
    
            current_user_access_map = self._get_access_map_for_groups_and_models(cr, uid,
                [x.id for x in current_user.groups_id], target_model_ids, context=context)
            group_access_map = self._get_access_map_for_groups_and_models(cr, uid,
                [group_id], target_model_ids, context=context)
            self._logger.debug("Current user access matrix: %r", current_user_access_map)
            self._logger.debug("New group current access matrix: %r", group_access_map)
    
            # Create required rights if allowed by current user rights and not
            # already granted
            for dummy, model in fields_relations:
                values = {
                    'name': _('Copied access for sharing'),
                    'group_id': group_id,
                    'model_id': model.id,
                }
                current_user_access_line = current_user_access_map.get(model.model,set())
                existing_group_access_line = group_access_map.get(model.model,set())
                need_creation = False
                for perm in perms_to_add:
                    if perm in current_user_access_line \
                       and perm not in existing_group_access_line:
                        values.update({perm:True})
                        group_access_map.setdefault(model.model, set()).add(perm)
                        need_creation = True
                if need_creation:
                    model_access_obj.create(cr, UID_ROOT, values)
                    self._logger.debug("Creating access right for model %s with values: %r", model.model, values)

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: