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)