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

Added user:group to the file footer. #872

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/files-footer-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Text } from "@patternfly/react-core/dist/esm/components/Text";
import { Tooltip } from "@patternfly/react-core/dist/esm/components/Tooltip";

import cockpit from "cockpit";
import type { FileInfo } from "cockpit/fsinfo.ts";
import * as timeformat from "timeformat";

import { useFilesContext } from './app.tsx';
Expand Down Expand Up @@ -70,7 +71,11 @@ export const FilesFooterDetail = ({
const selectedFile = (selected.length === 1) ? selected[0] : cwdInfo;

let permsPopover = null;
let userGroup = null;

if (selectedFile.mode !== undefined) {
userGroup = <UserGroupPopover file={selectedFile} />;

const mode = selectedFile.mode;
const popoverBody = [_("Owner"), _("Group"), _("Others")].map((permGroup, i) => {
return (
Expand Down Expand Up @@ -102,6 +107,7 @@ export const FilesFooterDetail = ({
variant="link"
isInline
component="pre"
id="files-footer-permissions"
>
{permissionShortStr(selectedFile.mode)}
</Button>
Expand All @@ -118,7 +124,47 @@ export const FilesFooterDetail = ({
{timeformat.distanceToNow(selectedFile.mtime * 1000)}
</Text>
</Tooltip>}
{userGroup}
{permsPopover}
</div>
);
};

const UserGroupPopover = ({ file }: { file: FileInfo }) => (
<Popover
id="files-footer-usergroup-popover"
hasAutoWidth
bodyContent={
<DescriptionList
isHorizontal
isCompact
>
<DescriptionListGroup key="user">
<DescriptionListTerm>
{_("User")}
</DescriptionListTerm>
<DescriptionListDescription>
{file.user}
</DescriptionListDescription>
</DescriptionListGroup>
<DescriptionListGroup key="group">
<DescriptionListTerm>
{_("Group")}
</DescriptionListTerm>
<DescriptionListDescription>
{file.group}
</DescriptionListDescription>
</DescriptionListGroup>
</DescriptionList>
}
>
<Button
id="files-footer-owner"
variant="link"
isInline
component="pre"
>
{(file.user === file.group) ? file.user : `${file.user}:${file.group}`}
</Button>
</Popover>
);
26 changes: 22 additions & 4 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -330,18 +330,35 @@ class TestFiles(testlib.MachineCase):
# Change permissions of cwd and see that files-footer-info is updated
b.go("/files#/?path=/home/admin/newdir")
self.assert_last_breadcrumb("newdir")
b.wait_in_text(".files-footer-info .pf-m-link", "rwx r-x r-x")
b.wait_in_text("#files-footer-permissions", "rwx r-x r-x")
m.execute("chmod 700 /home/admin/newdir")
b.wait_in_text(".files-footer-info .pf-m-link", "rwx --- ---")
b.wait_in_text("#files-footer-permissions", "rwx --- ---")
b.wait_text("#files-footer-owner", "root")

# Also check popover
b.click(".files-footer-info .pf-m-link")
b.click("#files-footer-permissions")
b.wait_in_text(".pf-v5-c-popover dl div:nth-child(1) > dd", "read, write, and execute")
b.wait_in_text(".pf-v5-c-popover dl div:nth-child(2) > dd", "none")
b.wait_in_text(".pf-v5-c-popover dl div:nth-child(3) > dd", "none")
b.click(".pf-v5-c-popover__close > button")
b.wait_not_present(".pf-v5-c-popover")

b.click("#files-footer-owner")
b.wait_in_text(".pf-v5-c-popover dl div:nth-child(1) > dd", "root")
b.wait_in_text(".pf-v5-c-popover dl div:nth-child(2) > dd", "root")
b.click(".pf-v5-c-popover__close > button")
b.wait_not_present(".pf-v5-c-popover")

# Change group is shown in popover
m.execute("chown root:admin /home/admin/newdir")
b.wait_text("#files-footer-owner", "root:admin")

b.click("#files-footer-owner")
b.wait_in_text(".pf-v5-c-popover dl div:nth-child(1) > dd", "root")
b.wait_in_text(".pf-v5-c-popover dl div:nth-child(2) > dd", "admin")
b.click(".pf-v5-c-popover__close > button")
b.wait_not_present(".pf-v5-c-popover")

# Change last edit time on cwd
m.execute("touch -d '2 hours ago' /home/admin/newdir")
b.wait_in_text(".files-footer-mtime", "2 hours ago")
Expand Down Expand Up @@ -379,7 +396,8 @@ class TestFiles(testlib.MachineCase):
# Selecting one file shows its info in the footer
b.click("[data-item='newdir']")
b.wait_in_text(".files-footer-info", "newdir")
b.wait_in_text(".files-footer-info .pf-m-link", "rwx --- ---")
b.wait_in_text("#files-footer-permissions", "rwx --- ---")
b.wait_in_text("#files-footer-owner", "root")

# Select multiple files
m.execute("touch /home/admin/newfile.txt")
Expand Down