修复添加存储字段不校验问题

super_signature
nineven 5 years ago
parent 7821d10929
commit f588a860df
  1. 7
      fir_client/src/components/FirUserProfileStorage.vue
  2. 9
      fir_ser/api/models.py
  3. 5
      fir_ser/api/utils/serializer.py
  4. 2
      fir_ser/api/views/storage.py

@ -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) {

@ -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)

@ -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

@ -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)

Loading…
Cancel
Save