@@ -24,7 +24,7 @@ public function __construct(
2424
2525 /**
2626 * Get a listing of attachments visible to the user.
27- * The external property indicates whether the attachment is simple a link.
27+ * The external property indicates whether the attachment is simply a link.
2828 * A false value for the external property would indicate a file upload.
2929 */
3030 public function list ()
@@ -39,7 +39,7 @@ public function list()
3939 * An uploaded_to value must be provided containing an ID of the page
4040 * that this upload will be related to.
4141 *
42- * If you're uploading a file the POST data should be provided via
42+ * If you're uploading a file, the POST data should be provided via
4343 * a multipart/form-data type request instead of JSON.
4444 *
4545 * @throws ValidationException
@@ -71,7 +71,7 @@ public function create(Request $request)
7171 }
7272
7373 /**
74- * Get the details & content of a single attachment of the given ID.
74+ * Get the details and content of a single attachment of the given ID.
7575 * The attachment link or file content is provided via a 'content' property.
7676 * For files the content will be base64 encoded.
7777 *
@@ -120,7 +120,7 @@ public function read(string $id)
120120
121121 /**
122122 * Update the details of a single attachment.
123- * As per the create endpoint, if a file is being provided as the attachment content
123+ * As per the create endpoint, if a file is being provided as the attachment content,
124124 * the request should be formatted as a multipart/form-data request instead of JSON.
125125 *
126126 * @throws ValidationException
@@ -134,9 +134,12 @@ public function update(Request $request, string $id)
134134
135135 $ page = $ attachment ->page ;
136136 if ($ requestData ['uploaded_to ' ] ?? false ) {
137- $ pageId = $ request ->input ('uploaded_to ' );
138- $ page = $ this ->pageQueries ->findVisibleByIdOrFail ($ pageId );
139- $ attachment ->uploaded_to = $ requestData ['uploaded_to ' ];
137+ $ pageId = intval ($ requestData ['uploaded_to ' ]);
138+ if ($ pageId !== $ page ->id ) {
139+ $ this ->checkOwnablePermission (Permission::PageUpdate, $ page );
140+ $ page = $ this ->pageQueries ->findVisibleByIdOrFail ($ pageId );
141+ $ attachment ->uploaded_to = $ pageId ;
142+ }
140143 }
141144
142145 $ this ->checkOwnablePermission (Permission::PageView, $ page );
0 commit comments