Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support uploading files with administrator privileges #845

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

jelly
Copy link
Member

@jelly jelly commented Nov 28, 2024

Files could not yet support uploading to non-logged in user directories as these files would always be uploaded as root:root and this might not be wanted in directories not owned by root.


Allow uploading files as administrator

Cockpit-files now allows you to upload files into directories not owned by the logged in user, when you are administrator. It will by default upload the file with the same user/group as the current directory. You can change the ownership after uploading.

image

@jelly jelly added the no-test label Nov 28, 2024
src/upload-button.tsx Fixed Show fixed Hide fixed
@garrett
Copy link
Member

garrett commented Dec 5, 2024

We should do what's mocked up at #453 (comment)

I can transplant that into an alert for a mockup for the time being though.

@garrett
Copy link
Member

garrett commented Dec 5, 2024

Same success state concept, transferred to a standard standalone alert, so we can immediately use it:

upload success alert

@jelly jelly force-pushed the upload-file-permissions branch from 0e40e15 to b9050b4 Compare December 10, 2024 10:27
src/upload-button.tsx Fixed Show fixed Hide fixed
@jelly jelly removed the no-test label Dec 10, 2024
@jelly jelly force-pushed the upload-file-permissions branch 3 times, most recently from edba4f8 to 57046a2 Compare December 11, 2024 10:29
@jelly jelly marked this pull request as ready for review December 11, 2024 11:11
@jelly jelly requested a review from martinpitt December 11, 2024 11:23
src/upload-button.tsx Outdated Show resolved Hide resolved
Comment on lines 276 to 295
} catch (exc) {
await cockpit.spawn(["rm", "-f", destination], { superuser: "require" });
console.warn("Cannot set initial file permissions", exc);
addAlert(_("Cancelled"), AlertVariant.warning, "upload",
cockpit.format(_("Cancelled upload of $0"), file.name));
cancelledUploads.push(file);
return;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure how to test this, I'll give it some more thought.

test/check-application Outdated Show resolved Hide resolved
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay, thanks! Nice progress!

Comment on lines +60 to +61
addAlert: (title: string, variant: AlertVariant, key: string, detail?: string | React.ReactNode,
actionLinks?: React.ReactNode) => void,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically repeats interface Alert. Couldn't this be changed to pass an alert: Alert object instead? that would make the typing more useful and stronger. It would also simplify the addAlert() implementation below (to the point of being trivial and it could be dropped)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that works does it? Doesn't seem too, because then there is one argument instead of multiple and an interface cannot be an argument. In general open to making this easier. But feels out of scope now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, what? addAlert: (alert: Alert) => void and calling it as alert({ title: "foo", variant: ... }) doesn't work? Then I'm rather disappointed by types. This duplication is annoying and error prone, and most of all does not express what we actually want.

If it's too hard, then ok to ignore of course.

src/app.tsx Outdated Show resolved Hide resolved
src/upload-button.tsx Outdated Show resolved Hide resolved
src/upload-button.tsx Outdated Show resolved Hide resolved
src/upload-button.tsx Outdated Show resolved Hide resolved
src/upload-button.tsx Outdated Show resolved Hide resolved
test/check-application Outdated Show resolved Hide resolved
test/check-application Outdated Show resolved Hide resolved
test/check-application Show resolved Hide resolved
test/check-application Outdated Show resolved Hide resolved
@jelly jelly force-pushed the upload-file-permissions branch 2 times, most recently from f26f8fe to f4c5c2e Compare December 12, 2024 18:18
@jelly jelly requested a review from martinpitt December 13, 2024 09:54
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The "create file" yak has been properly shaven now.

Just three tiny cleanups, pixel update, and then go!

src/upload-button.tsx Outdated Show resolved Hide resolved
test/check-application Outdated Show resolved Hide resolved
test/check-application Outdated Show resolved Hide resolved
Files could not yet support uploading to non-logged in user directories
as these files would always be uploaded as `root:root` and this might
not be wanted in directories not owned by `root`. Therefore they are now
uploaded by default as the owner of the directory with the ability to
change ownership after upload in the shown alert.
@jelly jelly force-pushed the upload-file-permissions branch from f4c5c2e to 2a1b189 Compare December 13, 2024 12:24
cwdInfo: FileInfo | null,
}

export const FilesContext = React.createContext({
addAlert: () => console.warn("FilesContext not initialized"),
removeAlert: () => console.warn("FilesContext not initialized"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

Comment on lines +284 to +285
} catch (exc) {
console.warn(`Unable to cleanup file: ${destination}, err: ${exc}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 added lines are not executed by any test.

Comment on lines +318 to +325
} catch (exc) {
console.warn("Unable to move file to final destination", exc);
addAlert(_("Upload error"), AlertVariant.danger, "upload-error",
_("Unable to move uploaded file to final destination"));
try {
await cockpit.file(destination, { superuser: "require" }).replace(null);
} catch (exc) {
console.warn(`Unable to cleanup file: ${destination}, err: ${exc}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 8 added lines are not executed by any test.

Comment on lines +336 to +337
} catch (exc) {
console.warn(`Unable to cleanup file: ${destination}, err: ${exc}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 added lines are not executed by any test.

@jelly jelly requested a review from martinpitt December 13, 2024 13:05
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick, before it gets stale! Can you please update the screenshot in the description for the release notes still? Otherwise our current friendly pilot will yell at you next Wednesday 😀

@martinpitt martinpitt merged commit 6ffd203 into cockpit-project:main Dec 13, 2024
19 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants