@@ -274,7 +274,7 @@ def validate(self, data):
274
274
class FileBrowserFileSerializer (serializers .HyperlinkedModelSerializer ):
275
275
new_file_path = serializers .CharField (max_length = 1024 , write_only = True ,
276
276
required = False )
277
- fname = serializers .FileField (use_url = False )
277
+ fname = serializers .FileField (use_url = False , required = False )
278
278
fsize = serializers .ReadOnlyField (source = 'fname.size' )
279
279
owner_username = serializers .ReadOnlyField (source = 'owner.username' )
280
280
file_resource = ItemLinkField ('get_file_link' )
@@ -522,6 +522,7 @@ def validate(self, data):
522
522
class FileBrowserLinkFileSerializer (serializers .HyperlinkedModelSerializer ):
523
523
new_link_file_path = serializers .CharField (max_length = 1024 , write_only = True ,
524
524
required = False )
525
+ path = serializers .CharField (max_length = 1024 , required = False )
525
526
fname = serializers .FileField (use_url = False , required = False )
526
527
fsize = serializers .ReadOnlyField (source = 'fname.size' )
527
528
owner_username = serializers .ReadOnlyField (source = 'owner.username' )
@@ -573,7 +574,8 @@ def update(self, instance, validated_data):
573
574
instance .parent_folder = parent_folder
574
575
instance .fname .name = new_link_file_path
575
576
576
- instance .save ()
577
+ link_name = os .path .basename (instance .fname .name ).rsplit ('.chrislink' , 1 )[0 ]
578
+ instance .save (name = link_name )
577
579
return instance
578
580
579
581
def get_file_link (self , obj ):
@@ -689,6 +691,9 @@ def validate(self, data):
689
691
raise serializers .ValidationError (
690
692
{'non_field_errors' :
691
693
[f"Moving link file '{ fname } ' is not allowed." ]})
694
+ else : # on create
695
+ if 'path' not in data :
696
+ raise serializers .ValidationError ({'path' : ['This field is required.' ]})
692
697
return data
693
698
694
699
@@ -703,7 +708,7 @@ class FileBrowserLinkFileGroupPermissionSerializer(serializers.HyperlinkedModelS
703
708
group = serializers .HyperlinkedRelatedField (view_name = 'group-detail' , read_only = True )
704
709
705
710
class Meta :
706
- model = FileGroupPermission
711
+ model = LinkFileGroupPermission
707
712
fields = ('url' , 'id' , 'permission' , 'link_file_id' , 'link_file_fname' ,
708
713
'group_id' , 'group_name' , 'link_file' , 'group' , 'grp_name' )
709
714
@@ -768,7 +773,7 @@ class FileBrowserLinkFileUserPermissionSerializer(serializers.HyperlinkedModelSe
768
773
user = serializers .HyperlinkedRelatedField (view_name = 'user-detail' , read_only = True )
769
774
770
775
class Meta :
771
- model = FileUserPermission
776
+ model = LinkFileUserPermission
772
777
fields = ('url' , 'id' , 'permission' , 'link_file_id' , 'link_file_fname' , 'user_id' ,
773
778
'user_username' , 'link_file' , 'user' , 'username' )
774
779
@@ -788,7 +793,7 @@ def create(self, validated_data):
788
793
raise serializers .ValidationError (
789
794
{'non_field_errors' :
790
795
[f"User '{ user .username } ' already has a permission to access "
791
- f"file with id { lf .id } " ]})
796
+ f"link file with id { lf .id } " ]})
792
797
793
798
shared_lf = lf .create_shared_link ()
794
799
shared_lf .grant_user_permission (user , 'r' )
0 commit comments