From cac17039571d8446aa8dd7b7680b33fc34e62145 Mon Sep 17 00:00:00 2001 From: youngS Date: Thu, 9 Sep 2021 10:39:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=80=E5=8F=91=E8=80=85?= =?UTF-8?q?=E8=B4=A6=E6=88=B7=E5=90=8C=E6=AD=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/apps/FirAppInfossupersign.vue | 2 +- fir_ser/api/base_views.py | 4 +-- .../api/migrations/0007_auto_20210909_0919.py | 21 ++++++++++++ fir_ser/api/models.py | 3 +- fir_ser/api/utils/app/apputils.py | 2 +- fir_ser/api/utils/app/iossignapi.py | 2 +- fir_ser/api/utils/app/supersignutils.py | 32 ++++++++++++------- fir_ser/api/views/apps.py | 21 ++++++------ 8 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 fir_ser/api/migrations/0007_auto_20210909_0919.py diff --git a/fir_client/src/components/apps/FirAppInfossupersign.vue b/fir_client/src/components/apps/FirAppInfossupersign.vue index 161bb91..6c35f4a 100644 --- a/fir_client/src/components/apps/FirAppInfossupersign.vue +++ b/fir_client/src/components/apps/FirAppInfossupersign.vue @@ -18,7 +18,7 @@ inactive-value="off"> - 清理开发者账户脏数据 超级签名,iOS专用,需要配置好苹果开发者账户,方可开启 diff --git a/fir_ser/api/base_views.py b/fir_ser/api/base_views.py index 8902b47..99e3721 100644 --- a/fir_ser/api/base_views.py +++ b/fir_ser/api/base_views.py @@ -28,7 +28,7 @@ def app_delete(app_obj): count = APPToDeveloper.objects.filter(app_id=app_obj).count() if app_obj.issupersign or count > 0: logger.info(f"app_id:{app_obj.app_id} is supersign ,delete this app need clean IOS developer") - IosUtils.clean_app_by_user_obj(app_obj, user_obj) + IosUtils.clean_app_by_user_obj(app_obj) storage = Storage(user_obj) has_combo = app_obj.has_combo @@ -76,7 +76,7 @@ def app_release_delete(app_obj, release_id, storage): count = APPToDeveloper.objects.filter(app_id=app_obj).count() if app_obj.issupersign or count > 0: logger.info(f"app_id:{app_obj.app_id} is supersign ,delete this app need clean IOS developer") - IosUtils.clean_app_by_user_obj(app_obj, user_obj) + IosUtils.clean_app_by_user_obj(app_obj) storage.delete_file(appreleaseobj.release_id, appreleaseobj.release_type) delete_local_files(appreleaseobj.release_id, appreleaseobj.release_type) diff --git a/fir_ser/api/migrations/0007_auto_20210909_0919.py b/fir_ser/api/migrations/0007_auto_20210909_0919.py new file mode 100644 index 0000000..daab0b8 --- /dev/null +++ b/fir_ser/api/migrations/0007_auto_20210909_0919.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.3 on 2021-09-09 09:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('api', '0006_auto_20210907_2100'), + ] + + operations = [ + migrations.RemoveField( + model_name='udidsyncdeveloper', + name='platform', + ), + migrations.AddField( + model_name='udidsyncdeveloper', + name='status', + field=models.BooleanField(default=False, verbose_name='设备在开发者平台状态'), + ), + ] diff --git a/fir_ser/api/models.py b/fir_ser/api/models.py index 4b8b79b..56d8f1c 100644 --- a/fir_ser/api/models.py +++ b/fir_ser/api/models.py @@ -326,8 +326,7 @@ class UDIDsyncDeveloper(models.Model): serial = models.CharField(max_length=64, verbose_name="序列号", blank=True, null=True, ) version = models.CharField(max_length=64, verbose_name="型号", blank=True, null=True, ) created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间"), - platform_choices = ((0, 'fly分发'), (1, 'app developer'),) - platform = models.SmallIntegerField(choices=platform_choices, default=0, verbose_name="udid所在平台") + status = models.BooleanField(verbose_name="设备在开发者平台状态", default=False) class Meta: verbose_name = 'iOS开发平台同步设备信息' diff --git a/fir_ser/api/utils/app/apputils.py b/fir_ser/api/utils/app/apputils.py index 61ef730..bbb4be1 100644 --- a/fir_ser/api/utils/app/apputils.py +++ b/fir_ser/api/utils/app/apputils.py @@ -152,7 +152,7 @@ def save_app_infos(app_file_name, user_obj, app_info, bundle_id, app_img, short, app_obj.name = app_info["labelname"] app_obj.save() - AppReleaseInfo.objects.filter(app_id=app_obj).update(**{"is_master": False}) + AppReleaseInfo.objects.filter(app_id=app_obj).update(is_master=False) release_data = { "app_id": app_obj, diff --git a/fir_ser/api/utils/app/iossignapi.py b/fir_ser/api/utils/app/iossignapi.py index 1858f27..7b8bef6 100644 --- a/fir_ser/api/utils/app/iossignapi.py +++ b/fir_ser/api/utils/app/iossignapi.py @@ -339,7 +339,7 @@ class AppDeveloperApiV2(object): result = {} try: apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) - devices_obj_list = apple_obj.list_enabled_devices() + devices_obj_list = apple_obj.get_all_devices() if devices_obj_list is not None: return True, devices_obj_list except Exception as e: diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index 5d2a017..d0a3264 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -325,7 +325,7 @@ class IosUtils(object): developer_app_id = developer_app_id_obj.aid if udid_info: sync_device_obj = UDIDsyncDeveloper.objects.filter(udid=udid_info.get('udid'), - developerid=developer_obj).first() + developerid=developer_obj, status=True).first() if sync_device_obj: DeveloperDevicesID.objects.update_or_create(did=sync_device_obj.serial, udid=sync_device_obj, developerid=developer_obj, @@ -540,7 +540,7 @@ class IosUtils(object): defaults=self.udid_info) if not result.get("did_exists", None): app_udid_obj = UDIDsyncDeveloper.objects.filter(developerid=self.developer_obj, - udid=self.udid_info.get('udid')).first() + udid=self.udid_info.get('udid'), status=True).first() if not app_udid_obj: appudid_obj = AppUDID.objects.filter(app_id=self.app_obj, udid=self.udid_info.get('udid')) device = appudid_obj.values("serial", @@ -549,7 +549,10 @@ class IosUtils(object): 'version').first() if result.get("did", None): device['serial'] = result["did"] - app_udid_obj = UDIDsyncDeveloper.objects.create(developerid=self.developer_obj, **device) + device['status'] = True + app_udid_obj, _ = UDIDsyncDeveloper.objects.update_or_create(developerid=self.developer_obj, + udid=device['udid'], + defaults=device) DeveloperDevicesID.objects.create(did=result["did"], udid=app_udid_obj, developerid=self.developer_obj, app_id=self.app_obj) @@ -602,7 +605,7 @@ class IosUtils(object): if udid_lists.count((udid_obj.udid,)) == 1: app_api_obj = get_api_obj(auth) app_api_obj.set_device_status("disable", udid_obj.udid) - UDIDsyncDeveloper.objects.filter(udid=udid_obj.udid, developerid=developer_obj).delete() + UDIDsyncDeveloper.objects.filter(udid=udid_obj.udid, developerid=developer_obj).update(status=False) udid_obj.delete() @@ -620,17 +623,18 @@ class IosUtils(object): SuperSignUsed_obj.delete() @staticmethod - def clean_app_by_user_obj(app_obj, user_obj): + def clean_app_by_user_obj(app_obj): """ 该APP为超级签,删除app的时候,需要清理一下开发者账户里面的profile 和 bundleid :param app_obj: :param user_obj: :return: """ - super_sign_obj_lists = list( - set(APPSuperSignUsedInfo.objects.values_list("developerid").filter(user_id=user_obj, app_id=app_obj))) - for super_sign_obj in super_sign_obj_lists: - developer_obj = AppIOSDeveloperInfo.objects.filter(pk=super_sign_obj[0]).first() + + developer_id_lists = list(set(DeveloperAppID.objects.values_list("developerid").filter(app_id=app_obj))) + + for developer_id in developer_id_lists: + developer_obj = AppIOSDeveloperInfo.objects.filter(pk=developer_id[0]).first() if developer_obj: IosUtils.clean_app_by_developer_obj(app_obj, developer_obj) delete_app_to_dev_and_file(developer_obj, app_obj.id) @@ -774,22 +778,26 @@ class IosUtils(object): will_del_udid_list = list(set(udid_developer_list) - set(udid_result_list)) + udid_enabled_result_list = [device.udid for device in result if device.status == 'ENABLED'] + will_del_disabled_udid_list = list(set(udid_developer_list) - set(udid_enabled_result_list)) + for device_obj in result: device = { "serial": device_obj.id, "product": device_obj.name, "udid": device_obj.udid, "version": device_obj.model, - "platform": 1 + "status": True if device_obj.status == 'ENABLED' else False } obj, create = UDIDsyncDeveloper.objects.update_or_create(developerid=developer_obj, udid=device_obj.udid, defaults=device) if not create: DeveloperDevicesID.objects.filter(udid=obj, developerid=developer_obj).update( **{'did': device_obj.id}) - AppUDID.objects.filter(udid__in=will_del_udid_list, + AppUDID.objects.filter(udid__in=will_del_disabled_udid_list, app_id__developerdevicesid__udid__in=UDIDsyncDeveloper.objects.filter( - udid__in=will_del_udid_list)).delete() + udid__in=will_del_disabled_udid_list)).delete() UDIDsyncDeveloper.objects.filter(udid__in=will_del_udid_list).delete() + DeveloperDevicesID.objects.filter(udid__udid__in=will_del_disabled_udid_list).delete() return status, result diff --git a/fir_ser/api/views/apps.py b/fir_ser/api/views/apps.py index bde8c2a..74809d5 100644 --- a/fir_ser/api/views/apps.py +++ b/fir_ser/api/views/apps.py @@ -138,7 +138,7 @@ class AppInfoView(APIView): if clean: logger.info(f"app_id:{app_id} clean:{clean} ,close super_sign should clean_app_by_user_obj") app_obj = Apps.objects.filter(user_id=request.user, app_id=app_id).first() - IosUtils.clean_app_by_user_obj(app_obj, request.user) + IosUtils.clean_app_by_user_obj(app_obj) return Response(res.dict) has_combo = data.get("has_combo", None) @@ -153,12 +153,12 @@ class AppInfoView(APIView): try: if actions == "UNCOMBO": if apps_obj.filter(has_combo=has_combo.first()).first(): - apps_obj.update(**{"has_combo": None}) - has_combo.update(**{"has_combo": None}) + apps_obj.update(has_combo=None) + has_combo.update(has_combo=None) elif actions == "COMBO": - apps_obj.update(**{"has_combo": has_combo.first()}) - has_combo.update(**{"has_combo": apps_obj.first()}) + apps_obj.update(has_combo=has_combo.first()) + has_combo.update(has_combo=apps_obj.first()) else: pass del_cache_response_by_short(apps_obj.first().app_id) @@ -297,7 +297,7 @@ class AppReleaseInfoView(APIView): count = APPToDeveloper.objects.filter(app_id=app_obj).count() if app_obj.issupersign or count > 0: logger.info(f"app_id:{app_id} is super_sign ,delete this app need clean IOS developer") - IosUtils.clean_app_by_user_obj(app_obj, request.user) + IosUtils.clean_app_by_user_obj(app_obj) storage.delete_file(app_release_obj.release_id, app_release_obj.release_type) delete_local_files(app_release_obj.release_id, app_release_obj.release_type) @@ -329,11 +329,10 @@ class AppReleaseInfoView(APIView): make_master = data.get("make_master", None) try: if make_master and make_master == act: - AppReleaseInfo.objects.filter(app_id=app_obj).update(**{"is_master": False}) - app_release_objs.update(**{"is_master": True}) + AppReleaseInfo.objects.filter(app_id=app_obj).update(is_master=False) + app_release_objs.update(is_master=True) else: - app_release_objs.update( - **{"changelog": data.get("changelog", app_release_objs.first().changelog)}) + app_release_objs.update(changelog=data.get("changelog", app_release_objs.first().changelog)) binary_url = data.get("binary_url", None) if binary_url != '': if binary_url: @@ -342,7 +341,7 @@ class AppReleaseInfoView(APIView): else: binary_url = app_release_objs.first().binary_url - app_release_objs.update(**{"binary_url": binary_url}) + app_release_objs.update(binary_url=binary_url) logger.info(f"update app:{app_obj} release:{app_release_objs} data:{data}") except Exception as e: logger.error(f"update app:{app_obj} release:{app_release_objs} failed Exception:{e}")