77
88namespace OCP \Files ;
99
10+ use OC \Files \Mount \MoveableMount ;
1011use OCP \Constants ;
1112use OCP \Files \Mount \IMovableMount ;
1213
@@ -33,7 +34,7 @@ public static function getDavFileId(int $id): string {
3334 *
3435 * @since 25.0.0
3536 */
36- public static function getDavPermissions (FileInfo $ info ): string {
37+ public static function getDavPermissions (FileInfo $ info, ? FileInfo $ parent = null ): string {
3738 $ permissions = $ info ->getPermissions ();
3839 $ p = '' ;
3940 if ($ info ->isShared ()) {
@@ -51,8 +52,17 @@ public static function getDavPermissions(FileInfo $info): string {
5152 if ($ permissions & Constants::PERMISSION_DELETE ) {
5253 $ p .= 'D ' ;
5354 }
54- if ($ permissions & Constants::PERMISSION_UPDATE ) {
55- $ p .= 'NV ' ; // Renameable, Movable
55+ if ($ parent ) {
56+ if (self ::canRename ($ info , $ parent )) {
57+ $ p .= 'N ' ; // Renamable
58+ }
59+ if ($ permissions & Constants::PERMISSION_UPDATE ) {
60+ $ p .= 'V ' ; // Movable
61+ }
62+ } else {
63+ if ($ permissions & Constants::PERMISSION_UPDATE ) {
64+ $ p .= 'NV ' ; // Renamable, Movable
65+ }
5666 }
5767
5868 // since we always add update permissions for the root of movable mounts
@@ -76,4 +86,35 @@ public static function getDavPermissions(FileInfo $info): string {
7686 }
7787 return $ p ;
7888 }
89+
90+ /**
91+ * Check if a node has rename permissions.
92+ *
93+ * We allow renaming the file if either the file has update permissions
94+ * or the file can be deleted and the parent has create permissions
95+ *
96+ * @param FileInfo $info
97+ * @param FileInfo $parent
98+ * @return bool
99+ * @since 33.0.4
100+ */
101+ public static function canRename (FileInfo $ info , FileInfo $ parent ): bool {
102+ // the root of a movable mountpoint can be renamed regardless of the file permissions
103+ if ($ info ->getMountPoint () instanceof MoveableMount && $ info ->getInternalPath () === '' ) {
104+ return true ;
105+ }
106+
107+ // we allow renaming the file if either the file has update permissions
108+ if ($ info ->isUpdateable ()) {
109+ return true ;
110+ }
111+
112+ // or the file can be deleted and the parent has create permissions
113+ if ($ info ->getStorage () instanceof IHomeStorage && $ info ->getInternalPath () === 'files ' ) {
114+ // can't rename the users home
115+ return false ;
116+ }
117+
118+ return $ info ->isDeletable () && $ parent ->isCreatable ();
119+ }
79120}
0 commit comments