优化开发者账户同步逻辑

dependabot/npm_and_yarn/fir_admin/tmpl-1.0.5
youngS 3 years ago
parent dfcf878416
commit cac1703957
  1. 2
      fir_client/src/components/apps/FirAppInfossupersign.vue
  2. 4
      fir_ser/api/base_views.py
  3. 21
      fir_ser/api/migrations/0007_auto_20210909_0919.py
  4. 3
      fir_ser/api/models.py
  5. 2
      fir_ser/api/utils/app/apputils.py
  6. 2
      fir_ser/api/utils/app/iossignapi.py
  7. 32
      fir_ser/api/utils/app/supersignutils.py
  8. 21
      fir_ser/api/views/apps.py

@ -18,7 +18,7 @@
inactive-value="off"> inactive-value="off">
</el-switch> </el-switch>
</el-tooltip> </el-tooltip>
<el-button @click="clean_app" v-if="currentapp.issupersign === 0 && currentapp.count !== 0" <el-button @click="clean_app" v-if="!currentapp.issupersign && currentapp.count !== 0"
style="margin-left: 20px" size="small" type="info" plain>清理开发者账户脏数据 style="margin-left: 20px" size="small" type="info" plain>清理开发者账户脏数据
</el-button> </el-button>
<el-link v-else :underline="false" style="margin-left: 20px">超级签名iOS专用需要配置好苹果开发者账户方可开启</el-link> <el-link v-else :underline="false" style="margin-left: 20px">超级签名iOS专用需要配置好苹果开发者账户方可开启</el-link>

@ -28,7 +28,7 @@ def app_delete(app_obj):
count = APPToDeveloper.objects.filter(app_id=app_obj).count() count = APPToDeveloper.objects.filter(app_id=app_obj).count()
if app_obj.issupersign or count > 0: 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") 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) storage = Storage(user_obj)
has_combo = app_obj.has_combo 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() count = APPToDeveloper.objects.filter(app_id=app_obj).count()
if app_obj.issupersign or count > 0: 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") 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) storage.delete_file(appreleaseobj.release_id, appreleaseobj.release_type)
delete_local_files(appreleaseobj.release_id, appreleaseobj.release_type) delete_local_files(appreleaseobj.release_id, appreleaseobj.release_type)

@ -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='设备在开发者平台状态'),
),
]

@ -326,8 +326,7 @@ class UDIDsyncDeveloper(models.Model):
serial = models.CharField(max_length=64, verbose_name="序列号", blank=True, null=True, ) serial = models.CharField(max_length=64, verbose_name="序列号", blank=True, null=True, )
version = 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="创建时间"), created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
platform_choices = ((0, 'fly分发'), (1, 'app developer'),) status = models.BooleanField(verbose_name="设备在开发者平台状态", default=False)
platform = models.SmallIntegerField(choices=platform_choices, default=0, verbose_name="udid所在平台")
class Meta: class Meta:
verbose_name = 'iOS开发平台同步设备信息' verbose_name = 'iOS开发平台同步设备信息'

@ -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.name = app_info["labelname"]
app_obj.save() 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 = { release_data = {
"app_id": app_obj, "app_id": app_obj,

@ -339,7 +339,7 @@ class AppDeveloperApiV2(object):
result = {} result = {}
try: try:
apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) 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: if devices_obj_list is not None:
return True, devices_obj_list return True, devices_obj_list
except Exception as e: except Exception as e:

@ -325,7 +325,7 @@ class IosUtils(object):
developer_app_id = developer_app_id_obj.aid developer_app_id = developer_app_id_obj.aid
if udid_info: if udid_info:
sync_device_obj = UDIDsyncDeveloper.objects.filter(udid=udid_info.get('udid'), 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: if sync_device_obj:
DeveloperDevicesID.objects.update_or_create(did=sync_device_obj.serial, udid=sync_device_obj, DeveloperDevicesID.objects.update_or_create(did=sync_device_obj.serial, udid=sync_device_obj,
developerid=developer_obj, developerid=developer_obj,
@ -540,7 +540,7 @@ class IosUtils(object):
defaults=self.udid_info) defaults=self.udid_info)
if not result.get("did_exists", None): if not result.get("did_exists", None):
app_udid_obj = UDIDsyncDeveloper.objects.filter(developerid=self.developer_obj, 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: if not app_udid_obj:
appudid_obj = AppUDID.objects.filter(app_id=self.app_obj, udid=self.udid_info.get('udid')) appudid_obj = AppUDID.objects.filter(app_id=self.app_obj, udid=self.udid_info.get('udid'))
device = appudid_obj.values("serial", device = appudid_obj.values("serial",
@ -549,7 +549,10 @@ class IosUtils(object):
'version').first() 'version').first()
if result.get("did", None): if result.get("did", None):
device['serial'] = result["did"] 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, DeveloperDevicesID.objects.create(did=result["did"], udid=app_udid_obj,
developerid=self.developer_obj, developerid=self.developer_obj,
app_id=self.app_obj) app_id=self.app_obj)
@ -602,7 +605,7 @@ class IosUtils(object):
if udid_lists.count((udid_obj.udid,)) == 1: if udid_lists.count((udid_obj.udid,)) == 1:
app_api_obj = get_api_obj(auth) app_api_obj = get_api_obj(auth)
app_api_obj.set_device_status("disable", udid_obj.udid) 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() udid_obj.delete()
@ -620,17 +623,18 @@ class IosUtils(object):
SuperSignUsed_obj.delete() SuperSignUsed_obj.delete()
@staticmethod @staticmethod
def clean_app_by_user_obj(app_obj, user_obj): def clean_app_by_user_obj(app_obj):
""" """
该APP为超级签删除app的时候需要清理一下开发者账户里面的profile bundleid 该APP为超级签删除app的时候需要清理一下开发者账户里面的profile bundleid
:param app_obj: :param app_obj:
:param user_obj: :param user_obj:
:return: :return:
""" """
super_sign_obj_lists = list(
set(APPSuperSignUsedInfo.objects.values_list("developerid").filter(user_id=user_obj, app_id=app_obj))) developer_id_lists = list(set(DeveloperAppID.objects.values_list("developerid").filter(app_id=app_obj)))
for super_sign_obj in super_sign_obj_lists:
developer_obj = AppIOSDeveloperInfo.objects.filter(pk=super_sign_obj[0]).first() for developer_id in developer_id_lists:
developer_obj = AppIOSDeveloperInfo.objects.filter(pk=developer_id[0]).first()
if developer_obj: if developer_obj:
IosUtils.clean_app_by_developer_obj(app_obj, developer_obj) IosUtils.clean_app_by_developer_obj(app_obj, developer_obj)
delete_app_to_dev_and_file(developer_obj, app_obj.id) 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)) 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: for device_obj in result:
device = { device = {
"serial": device_obj.id, "serial": device_obj.id,
"product": device_obj.name, "product": device_obj.name,
"udid": device_obj.udid, "udid": device_obj.udid,
"version": device_obj.model, "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, obj, create = UDIDsyncDeveloper.objects.update_or_create(developerid=developer_obj,
udid=device_obj.udid, defaults=device) udid=device_obj.udid, defaults=device)
if not create: if not create:
DeveloperDevicesID.objects.filter(udid=obj, developerid=developer_obj).update( DeveloperDevicesID.objects.filter(udid=obj, developerid=developer_obj).update(
**{'did': device_obj.id}) **{'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( 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() 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 return status, result

@ -138,7 +138,7 @@ class AppInfoView(APIView):
if clean: if clean:
logger.info(f"app_id:{app_id} clean:{clean} ,close super_sign should clean_app_by_user_obj") 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() 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) return Response(res.dict)
has_combo = data.get("has_combo", None) has_combo = data.get("has_combo", None)
@ -153,12 +153,12 @@ class AppInfoView(APIView):
try: try:
if actions == "UNCOMBO": if actions == "UNCOMBO":
if apps_obj.filter(has_combo=has_combo.first()).first(): if apps_obj.filter(has_combo=has_combo.first()).first():
apps_obj.update(**{"has_combo": None}) apps_obj.update(has_combo=None)
has_combo.update(**{"has_combo": None}) has_combo.update(has_combo=None)
elif actions == "COMBO": elif actions == "COMBO":
apps_obj.update(**{"has_combo": has_combo.first()}) apps_obj.update(has_combo=has_combo.first())
has_combo.update(**{"has_combo": apps_obj.first()}) has_combo.update(has_combo=apps_obj.first())
else: else:
pass pass
del_cache_response_by_short(apps_obj.first().app_id) 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() count = APPToDeveloper.objects.filter(app_id=app_obj).count()
if app_obj.issupersign or count > 0: if app_obj.issupersign or count > 0:
logger.info(f"app_id:{app_id} is super_sign ,delete this app need clean IOS developer") 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) 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) 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) make_master = data.get("make_master", None)
try: try:
if make_master and make_master == act: if make_master and make_master == act:
AppReleaseInfo.objects.filter(app_id=app_obj).update(**{"is_master": False}) AppReleaseInfo.objects.filter(app_id=app_obj).update(is_master=False)
app_release_objs.update(**{"is_master": True}) app_release_objs.update(is_master=True)
else: else:
app_release_objs.update( app_release_objs.update(changelog=data.get("changelog", app_release_objs.first().changelog))
**{"changelog": data.get("changelog", app_release_objs.first().changelog)})
binary_url = data.get("binary_url", None) binary_url = data.get("binary_url", None)
if binary_url != '': if binary_url != '':
if binary_url: if binary_url:
@ -342,7 +341,7 @@ class AppReleaseInfoView(APIView):
else: else:
binary_url = app_release_objs.first().binary_url 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}") logger.info(f"update app:{app_obj} release:{app_release_objs} data:{data}")
except Exception as e: except Exception as e:
logger.error(f"update app:{app_obj} release:{app_release_objs} failed Exception:{e}") logger.error(f"update app:{app_obj} release:{app_release_objs} failed Exception:{e}")

Loading…
Cancel
Save