From f588a860dfcf53262d13f935e360f815cc0c4688 Mon Sep 17 00:00:00 2001 From: nineven Date: Sun, 10 May 2020 21:31:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=BB=E5=8A=A0=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E5=AD=97=E6=AE=B5=E4=B8=8D=E6=A0=A1=E9=AA=8C=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_client/src/components/FirUserProfileStorage.vue | 7 ++++++- fir_ser/api/models.py | 9 ++++++++- fir_ser/api/utils/serializer.py | 5 +++-- fir_ser/api/views/storage.py | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/fir_client/src/components/FirUserProfileStorage.vue b/fir_client/src/components/FirUserProfileStorage.vue index 3b3d53d..7b77d40 100644 --- a/fir_client/src/components/FirUserProfileStorage.vue +++ b/fir_client/src/components/FirUserProfileStorage.vue @@ -257,7 +257,12 @@ updateorcreate() { let methods = "PUT"; if (this.isaddflag) { - methods = "POST" + if (this.editstorageinfo.access_key && this.editstorageinfo.secret_key && this.editstorageinfo.bucket_name) { + methods = "POST"; + } else { + this.$message.error("参数不正确"); + return + } } getStorageinfo(data => { if (data.code === 1000) { diff --git a/fir_ser/api/models.py b/fir_ser/api/models.py index a9df3b5..6ba0418 100644 --- a/fir_ser/api/models.py +++ b/fir_ser/api/models.py @@ -147,7 +147,6 @@ class AppReleaseInfo(models.Model): class AppStorage(models.Model): user_id = models.ForeignKey(to="UserInfo", verbose_name="用户ID", on_delete=models.CASCADE) name = models.CharField(max_length=64, blank=True, null=True, verbose_name="存储名字") - # is_used = models.BooleanField(verbose_name="是否使用该存储",default=True) storage_choices = ((0, '本地存储'), (1, '七牛云存储'), (2, '阿里云存储'), (3, '默认存储')) storage_type = models.SmallIntegerField(choices=storage_choices, default=3, verbose_name="存储类型") access_key = models.CharField(max_length=128, blank=True, null=True, verbose_name="存储访问key") @@ -166,6 +165,14 @@ class AppStorage(models.Model): verbose_name = '存储配置' verbose_name_plural = "存储配置" + def save(self, *args, **kwargs): + if self.storage_type in (1, 2): + if self.bucket_name and self.secret_key and self.access_key: + return super(AppStorage, self).save(*args, **kwargs) + else: + return + super(AppStorage, self).save(*args, **kwargs) + def __str__(self): return "%s %s" % (self.user_id.get_username(), self.name) diff --git a/fir_ser/api/utils/serializer.py b/fir_ser/api/utils/serializer.py index 65b4f89..062df76 100644 --- a/fir_ser/api/utils/serializer.py +++ b/fir_ser/api/utils/serializer.py @@ -219,8 +219,9 @@ class StorageSerializer(serializers.ModelSerializer): def create(self, validated_data): if self.context.get("user_obj", None) and self.context.get("user_obj") != "undefined": user_obj = self.context.get("user_obj", None) - storage_obj = models.AppStorage.objects.create(**validated_data, user_id=user_obj, ) - return storage_obj + if user_obj: + storage_obj = models.AppStorage.objects.create(**validated_data, user_id=user_obj) + return storage_obj return None diff --git a/fir_ser/api/views/storage.py b/fir_ser/api/views/storage.py index f787e3c..e680de8 100644 --- a/fir_ser/api/views/storage.py +++ b/fir_ser/api/views/storage.py @@ -46,7 +46,7 @@ class StorageView(APIView): admin_storage = UserInfo.objects.filter(is_superuser=True).order_by('pk').first() res.is_admin_storage = False - if admin_storage.uid == request.user.uid: + if admin_storage and admin_storage.uid == request.user.uid: res.is_admin_storage = True return Response(res.dict)