コード例 #1
0
    def save(self, **kwargs):
        """
        做了一些数据转换
        """
        meta = self.validated_data.get('meta', {})

        org_id = self.validated_data.get('org_id')
        if org_id is not None and org_id == Organization.DEFAULT_ID:
            self.validated_data['org_id'] = ''

        # 时间的转换,好烦😭,可能有更好的办法吧
        date_start = meta.get('date_start')
        if date_start:
            meta['date_start'] = dt_formater(date_start)

        date_expired = meta.get('date_expired')
        if date_expired:
            meta['date_expired'] = dt_formater(date_expired)

        # UUID 的转换
        confirmed_system_users = meta.get('confirmed_system_users')
        if confirmed_system_users:
            meta['confirmed_system_users'] = [
                str(system_user) for system_user in confirmed_system_users
            ]

        confirmed_assets = meta.get('confirmed_assets')
        if confirmed_assets:
            meta['confirmed_assets'] = [
                str(asset) for asset in confirmed_assets
            ]

        with tmp_to_root_org():
            return super().save(**kwargs)
コード例 #2
0
ファイル: tasks.py プロジェクト: zunxhinwepac/jumpserver
def check_asset_permission_expired():
    """
    这里的任务要足够短,不要影响周期任务
    """
    from settings.models import Setting

    setting_name = 'last_asset_perm_expired_check'

    end = now()
    default_start = end - timedelta(days=36000)  # Long long ago in china

    defaults = {'value': dt_formater(default_start)}
    setting, created = Setting.objects.get_or_create(
        name=setting_name, defaults=defaults
    )
    if created:
        start = default_start
    else:
        start = dt_parser(setting.value)
    setting.value = dt_formater(end)
    setting.save()

    asset_perm_ids = AssetPermission.objects.filter(
        date_expired__gte=start, date_expired__lte=end
    ).distinct().values_list('id', flat=True)
    asset_perm_ids = list(asset_perm_ids)
    logger.info(f'>>> checking {start} to {end} have {asset_perm_ids} expired')
    UserGrantedTreeRefreshController.add_need_refresh_by_asset_perm_ids_cross_orgs(asset_perm_ids)
コード例 #3
0
def check_asset_permission_expired():
    """
    这里的任务要足够短,不要影响周期任务
    """
    from settings.models import Setting

    setting_name = 'last_asset_perm_expired_check'

    end = now()
    default_start = end - timedelta(days=36000)  # Long long ago in china

    defaults = {'value': dt_formater(default_start)}
    setting, created = Setting.objects.get_or_create(name=setting_name,
                                                     defaults=defaults)
    if created:
        start = default_start
    else:
        start = dt_parser(setting.value)
    setting.value = dt_formater(end)
    setting.save()

    ids = AssetPermission.objects.filter(
        date_expired__gte=start,
        date_expired__lte=end).distinct().values_list('id', flat=True)
    logger.info(f'>>> checking {start} to {end} have {ids} expired')
    dispatch_process_expired_asset_permission.delay(list(ids))
コード例 #4
0
def _generate_value(stage=lock.DOING):
    cur_thread = threading.current_thread()

    return VALUE_TEMPLATE.format(stage=stage,
                                 thread_name=cur_thread.name,
                                 thread_id=cur_thread.ident,
                                 now=dt_formater(now()),
                                 rand_str=uuid4())
コード例 #5
0
ファイル: lock.py プロジェクト: WaylonWang2020/JumpServer
def _generate_value(request: Request, stage=DOING):
    # 不支持匿名用户
    user = request.user
    if user.is_anonymous:
        raise NotAuthenticated

    return VALUE_TEMPLATE.format(
        stage=stage, username=user.username, user_id=user.id,
        now=dt_formater(now()), rand_str=uuid4()
    )