# Path: m2core/utils/data_helper.py
# class DataHelper:
#     @staticmethod
#     def random_char(length: int) -> str:
#         """
#         Generates random char sequence with the given length
#         """
#         return ''.join(random.choice(string.ascii_letters) for x in range(length))
# 
#     @staticmethod
#     def random_hex_str(length: int) -> str:
#         """
#         Generates random alpha-numeric sequence, where all chars are from hex set (a-f)
#         :param length:
#         :return:
#         """
#         return '%x' % random.randrange(16 ** length)
# 
#     @staticmethod
#     def camel_to_underline(camel) -> str:
#         """
#         Converts camelcased-string to underlined string, example:
#                 ConvertMeToUnderline -> convert_me_to_underline
#         :param camel: string to convert
#         :return: converted string
#         """
#         s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel)
#         return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
# 
# Path: m2core/data_schemes/db_system_scheme.py
# class M2Permission(BaseModel):
#     __repr_list__ = ['id', 'system_name']
# 
#     id = Column(BigInteger, primary_key=True)
#     name = Column(String(255))
#     system_name = Column(String(255), unique=True)
#     description = Column(String(500))
#     active = Column(Boolean, default=True, server_default='1')
#     created = Column(DateTime(timezone=True), server_default=text('now()'), nullable=False)
# 
#     @property
#     def enum_member(self):
#         if not hasattr(self, '__enum_member'):
#             all_perms = PermissionsEnum.all_platform_permissions
#             sys_name = self.system_name
#             for p in all_perms:
#                 if p.sys_name == sys_name:
#                     setattr(self, '__enum_member', p)
#                     return p
#             raise M2Error(f'No corresponding enum member found for Permission with sys_name=`{sys_name}`')
#         else:
#             return getattr(self, '__enum_member')
# 
#     @classmethod
#     def from_enum_member(cls, member: Permission):
#         entity = cls.s.query(M2RolePermission).filter(M2Permission.system_name == member.sys_name).first()
#         if not entity:
#             raise M2Error(f'No corresponding permission found for Permission with sys_name=`{member.sys_name}`')
# 
#         return entity
# 
# Path: m2core/common/options.py
# class M2OptionParser(OptionParser):
#     def parse_environment(self, final=True):


from m2core.utils.data_helper import DataHelper
from m2core.data_schemes.db_system_scheme import M2Permission
from m2core.common.options import options
            self._redis_scheme['USER_ROLES']['prefix'] % self._current_user
        )
        group_ids = [int(role_id) for role_id in redis_val]
        all_permissions = set()
        for group_id in group_ids:
            # get permissions per each role by role id
            permissions = self._redis.smembers(
                self._redis_scheme['ROLE_PERMISSIONS']['prefix'] % group_id
            )
            for p_name in permissions:
                p = M2Permission.load_by_params(system_name=p_name)
                if p:
                    all_permissions.add(p)
        return all_permissions

    def _check_inited(self):
        """
        Check if instance was inited with user's data or not
        """
        if not self.__inited:
            raise Exception('Session is not inited')

    def init_user(self, _access_token: str):
        """
        Init current instance with user access token. This is the place were data per user is requested from Redis
        :param _access_token: 
        """
        redis_val = self._redis.get(
            self._redis_scheme['ACCESS_TOKENS_BY_HASH']['prefix'] % _access_token
        )

# Path: m2core/utils/data_helper.py
# class DataHelper:
#     @staticmethod
#     def random_char(length: int) -> str:
#         """
#         Generates random char sequence with the given length
#         """
#         return ''.join(random.choice(string.ascii_letters) for x in range(length))
# 
#     @staticmethod
#     def random_hex_str(length: int) -> str:
#         """
#         Generates random alpha-numeric sequence, where all chars are from hex set (a-f)
#         :param length:
#         :return:
#         """
#         return '%x' % random.randrange(16 ** length)
# 
#     @staticmethod
#     def camel_to_underline(camel) -> str:
#         """
#         Converts camelcased-string to underlined string, example:
#                 ConvertMeToUnderline -> convert_me_to_underline
#         :param camel: string to convert
#         :return: converted string
#         """
#         s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel)
#         return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
# 
# Path: m2core/data_schemes/db_system_scheme.py
# class M2Permission(BaseModel):
#     __repr_list__ = ['id', 'system_name']
# 
#     id = Column(BigInteger, primary_key=True)
#     name = Column(String(255))
#     system_name = Column(String(255), unique=True)
#     description = Column(String(500))
#     active = Column(Boolean, default=True, server_default='1')
#     created = Column(DateTime(timezone=True), server_default=text('now()'), nullable=False)
# 
#     @property
#     def enum_member(self):
#         if not hasattr(self, '__enum_member'):
#             all_perms = PermissionsEnum.all_platform_permissions
#             sys_name = self.system_name
#             for p in all_perms:
#                 if p.sys_name == sys_name:
#                     setattr(self, '__enum_member', p)
#                     return p
#             raise M2Error(f'No corresponding enum member found for Permission with sys_name=`{sys_name}`')
#         else:
#             return getattr(self, '__enum_member')
# 
#     @classmethod
#     def from_enum_member(cls, member: Permission):
#         entity = cls.s.query(M2RolePermission).filter(M2Permission.system_name == member.sys_name).first()
#         if not entity:
#             raise M2Error(f'No corresponding permission found for Permission with sys_name=`{member.sys_name}`')
# 
#         return entity
# 
# Path: m2core/common/options.py
# class M2OptionParser(OptionParser):
#     def parse_environment(self, final=True):


# Path: m2core/utils/session_helper.py
from m2core.utils.data_helper import DataHelper
from m2core.data_schemes.db_system_scheme import M2Permission
from m2core.common.options import options

            self._redis_scheme['USER_ROLES']['prefix'] % self._current_user
        )
        group_ids = [int(role_id) for role_id in redis_val]
        all_permissions = set()
        for group_id in group_ids:
            # get permissions per each role by role id
            permissions = self._redis.smembers(
                self._redis_scheme['ROLE_PERMISSIONS']['prefix'] % group_id
            )
            for p_name in permissions:
                p = M2Permission.load_by_params(system_name=p_name)
                if p:
                    all_permissions.add(p)
        return all_permissions

    def _check_inited(self):
        """
        Check if instance was inited with user's data or not
        """
        if not self.__inited:
            raise Exception('Session is not inited')

    def init_user(self, _access_token: str):
        """
        Init current instance with user access token. This is the place were data per user is requested from Redis
        :param _access_token: 
        """
        redis_val = self._redis.get(
            self._redis_scheme['ACCESS_TOKENS_BY_HASH']['prefix'] % _access_token
        )

        if options.access_token_update_on_check: