Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit 4b3e54a

Browse files
release: v0.15.0 (#45)
* feat: Unshare file (#44) --------- Co-authored-by: Miguel Mateo Mendoza Rojas <115849391+MiguelMRojas@users.noreply.github.com>
1 parent 981ac24 commit 4b3e54a

File tree

5 files changed

+127
-15
lines changed

5 files changed

+127
-15
lines changed

CHANGELOG.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# [0.15.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.14.0...v0.15.0) (2023-10-25)
2+
3+
4+
### Features
5+
6+
* Unshare file ([#44](https://github.com/PedroChaparro/alternative-frontend-react/issues/44)) ([8bb105c](https://github.com/PedroChaparro/alternative-frontend-react/commit/8bb105c20762c59c522ec5c3b6587597920c1f49))
7+
8+
9+
110
# [0.14.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.13.0...v0.14.0) (2023-10-25)
211

312

@@ -34,12 +43,3 @@
3443

3544

3645

37-
# [0.11.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.10.0...v0.11.0) (2023-10-24)
38-
39-
40-
### Features
41-
42-
* List shared files ([#33](https://github.com/PedroChaparro/alternative-frontend-react/issues/33)) ([b19c51f](https://github.com/PedroChaparro/alternative-frontend-react/commit/b19c51f733526ecefe01806ea6112aadeb275532))
43-
44-
45-

e2e/files/share-files.spec.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,48 @@ test.describe.serial("Users can share files", () => {
146146
// Assert the shared file is shown
147147
await expect(page.getByText("yellow.jpg")).toBeVisible();
148148
});
149+
150+
test("Users can un-share a file", async ({ page }) => {
151+
// Login with the owner user
152+
await page.goto("/login");
153+
await page.getByLabel("Username").fill(username);
154+
await page.getByLabel("Password", { exact: true }).fill(password);
155+
await page.getByRole("button", { name: "Submit", exact: true }).click();
156+
await page.waitForURL(/\/files$/);
157+
158+
// Open the folder dropdown
159+
const folderCard = page.getByRole("button", {
160+
name: `${sharedFolder} card`
161+
});
162+
await expect(folderCard).toBeVisible();
163+
await folderCard.getByLabel(`More options for ${sharedFolder}`).click();
164+
165+
// Select the "Manage access" option
166+
const shareButton = page.getByRole("menuitem", {
167+
name: "Manage access",
168+
exact: true
169+
});
170+
await expect(shareButton).toBeVisible();
171+
await shareButton.click();
172+
173+
// Assert modal is open
174+
await expect(page.getByRole("dialog")).toBeVisible();
175+
await expect(page.getByText("Manage access")).toBeVisible();
176+
177+
// Assert the other user is shown
178+
const userRow = page.getByText(new RegExp(usernameShare, "i"));
179+
await expect(userRow).toBeVisible();
180+
181+
// Unshare the file
182+
const unShareButton = page.getByRole("button", {
183+
name: `Un-share with ${usernameShare}`
184+
});
185+
await unShareButton.click();
186+
187+
// Assert an alert is shown
188+
await expect(page.getByText("File unshared successfully")).toBeVisible();
189+
190+
// Assert the other user does not appears
191+
await expect(userRow).not.toBeVisible();
192+
});
149193
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "unofficial-frontend-react",
33
"private": true,
4-
"version": "0.14.0",
4+
"version": "0.15.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src/screens/files/dialogs/access-management/users-with-access/UserWithAccessRow.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { Button } from "@/components/ui/button";
2+
import { AuthContext, FilesDialogsContext } from "@/context";
3+
import { unshareFileService } from "@/services/files/unshare-file.service";
4+
import { useContext } from "react";
5+
import { toast } from "sonner";
26

37
interface UserWithAccessRowProps {
48
user: string;
@@ -9,11 +13,24 @@ export const UserWithAccessRow = ({
913
user,
1014
unshareCallback
1115
}: UserWithAccessRowProps) => {
12-
const handleUnshare = () => {
13-
// TODO: Make the request to unshare the file
16+
const { session } = useContext(AuthContext);
17+
const { selectedFile } = useContext(FilesDialogsContext);
1418

15-
// Remove the user from the UI
16-
unshareCallback(user);
19+
const handleUnshare = async (userName: string) => {
20+
const unShareRequest = {
21+
token: session?.token as string,
22+
fileUUID: selectedFile?.uuid as string,
23+
otherUsername: userName
24+
};
25+
26+
const { success, msg } = await unshareFileService(unShareRequest);
27+
if (!success) {
28+
toast.error(msg);
29+
return;
30+
}
31+
32+
toast.success(msg);
33+
unshareCallback(userName);
1734
};
1835

1936
return (
@@ -25,7 +42,7 @@ export const UserWithAccessRow = ({
2542
<Button
2643
variant={"destructive"}
2744
aria-label={`Un-share with ${user}`}
28-
onClick={handleUnshare}
45+
onClick={() => handleUnshare(user)}
2946
>
3047
Un-share
3148
</Button>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { ENVIRONMENT } from "@/config/environment";
2+
import axios, { AxiosError } from "axios";
3+
4+
type UnshareFileRequest = {
5+
token: string;
6+
fileUUID: string;
7+
otherUsername: string;
8+
};
9+
10+
type UnshareFileResponse = {
11+
success: boolean;
12+
msg: string;
13+
};
14+
15+
export const unshareFileService = async (
16+
req: UnshareFileRequest
17+
): Promise<UnshareFileResponse> => {
18+
const URL = `${ENVIRONMENT.PROXY_BASE_URL}/file/unshare`;
19+
20+
try {
21+
const unshareFileResponse = await axios.post(
22+
URL,
23+
{
24+
fileUUID: req.fileUUID,
25+
otherUsername: req.otherUsername
26+
},
27+
{
28+
headers: {
29+
Authorization: `Bearer ${req.token}`
30+
}
31+
}
32+
);
33+
const { data } = unshareFileResponse;
34+
35+
return {
36+
success: true,
37+
msg: data.msg
38+
};
39+
} catch (error) {
40+
let errorMsg = "There was an error while trying to un-share the file";
41+
42+
if (error instanceof AxiosError) {
43+
errorMsg = error.response?.data.msg || errorMsg;
44+
}
45+
46+
return {
47+
success: false,
48+
msg: errorMsg
49+
};
50+
}
51+
};

0 commit comments

Comments
 (0)