Initial support for configuring incoming shares
This commit is contained in:
@@ -234,7 +234,7 @@ def test_edit_share_by_map(page: Page, radicale_server: str) -> None:
|
||||
|
||||
# Change permissions and enabled status
|
||||
page.click('label[for="newshare_attr_permissions_rw"]')
|
||||
page.uncheck('input[data-name="enabled"]')
|
||||
page.uncheck('#newshare input[data-name="enabled"]')
|
||||
page.click('#newshare button[data-name="submit"]')
|
||||
|
||||
# Verify changes
|
||||
@@ -244,7 +244,7 @@ def test_edit_share_by_map(page: Page, radicale_server: str) -> None:
|
||||
# If disabled, it might not show up or show differently, but our current UI doesn't visually distinguish enabled/disabled in the list yet
|
||||
# Let's verify by re-opening edit scene
|
||||
page.click('tr:not(.hidden) button[data-name="edit"]')
|
||||
expect(page.locator('input[data-name="enabled"]')).not_to_be_checked()
|
||||
expect(page.locator('#newshare input[data-name="enabled"]')).not_to_be_checked()
|
||||
page.click('#newshare button[data-name="cancel"]')
|
||||
|
||||
|
||||
@@ -279,3 +279,55 @@ def test_share_by_map_validation(page: Page, radicale_server: str) -> None:
|
||||
expect(
|
||||
page.locator("tr[data-name='sharemaprowtemplate']:not(.hidden)")
|
||||
).to_have_count(1)
|
||||
|
||||
|
||||
def test_incoming_shares(page: Page, radicale_server: str) -> None:
|
||||
# 1. Admin logs in and creates a map share for 'max'
|
||||
login(page, radicale_server)
|
||||
create_collection(page, radicale_server)
|
||||
|
||||
page.hover("article:not(.hidden)")
|
||||
page.click('article:not(.hidden) a[data-name="share"]', force=True, strict=True)
|
||||
page.click('button[data-name="sharebymap"]')
|
||||
page.locator('input[data-name="shareuser"]').fill("max")
|
||||
page.locator('input[data-name="sharehref"]').fill("mapped")
|
||||
page.click('#newshare button[data-name="submit"]')
|
||||
expect(
|
||||
page.locator("tr[data-name='sharemaprowtemplate']:not(.hidden)")
|
||||
).to_have_count(1)
|
||||
page.click('#sharecollectionscene button[data-name="cancel"]')
|
||||
|
||||
# 2. Admin logs out
|
||||
page.click('a[data-name="logout"]')
|
||||
|
||||
# 3. Max logs in
|
||||
page.fill('#loginscene input[data-name="user"]', "max")
|
||||
page.fill('#loginscene input[data-name="password"]', "maxpassword")
|
||||
page.click('button:has-text("Next")')
|
||||
|
||||
# 4. Max sees the incoming share
|
||||
page.click('a[data-name="incomingshares"]')
|
||||
expect(page.locator('#incomingsharingscene')).to_be_visible()
|
||||
expect(
|
||||
page.locator("tr[data-name='incomingsharerowtemplate']:not(.hidden)")
|
||||
).to_have_count(1)
|
||||
|
||||
expect(
|
||||
page.locator("tr[data-name='incomingsharerowtemplate']:not(.hidden) td[data-name='pathortoken']")
|
||||
).to_have_text("mapped")
|
||||
|
||||
# 5. Max makes changes to the hidden flag
|
||||
expect(
|
||||
page.locator("tr[data-name='incomingsharerowtemplate']:not(.hidden) input[data-name='hidden']")
|
||||
).to_be_checked()
|
||||
page.uncheck("tr[data-name='incomingsharerowtemplate']:not(.hidden) input[data-name='hidden']")
|
||||
|
||||
expect(
|
||||
page.locator("tr[data-name='incomingsharerowtemplate']:not(.hidden) input[data-name='hidden']")
|
||||
).not_to_be_checked()
|
||||
|
||||
# 6. Assert no error was shown
|
||||
expect(page.locator('#incomingsharingscene span[data-name="error"]')).to_be_hidden()
|
||||
|
||||
page.click('#incomingsharingscene button[data-name="cancel"]')
|
||||
expect(page.locator('#incomingsharingscene')).to_be_hidden()
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
<a href="" class="blue" data-name="upload" title="Upload an addressbook or calendar">
|
||||
<img src="css/icons/upload.svg" class="icon" alt="⬆️">
|
||||
</a>
|
||||
<a href="" class="blue" data-name="incomingshares" title="Incoming Shares">
|
||||
<img src="css/icons/share.svg" class="icon" alt="🔗">
|
||||
</a>
|
||||
</div>
|
||||
<article data-name="collectiontemplate" class="hidden">
|
||||
<div class="colorbar" data-name="color"></div>
|
||||
@@ -207,6 +210,35 @@
|
||||
<span class="error hidden" data-name="error"></span>
|
||||
</section>
|
||||
|
||||
<section id="incomingsharingscene" class="container hidden">
|
||||
<h1>Incoming Shares</h1>
|
||||
<p>Manage shares that others have shared with you.</p>
|
||||
<table>
|
||||
<!-- <thead>
|
||||
<tr>
|
||||
<th>Path</th>
|
||||
<th>Owner</th>
|
||||
<th>Permissions</th>
|
||||
<th>Enabled</th>
|
||||
<th>Hidden</th>
|
||||
</tr>
|
||||
</thead> -->
|
||||
<tbody data-name="incomingsharesbody">
|
||||
<tr data-name="incomingsharerowtemplate" class="hidden">
|
||||
<td data-name="pathortoken"></td>
|
||||
<td data-name="owner"></td>
|
||||
<td data-name="permissions"></td>
|
||||
<td><input type="checkbox" data-name="enabled"></td>
|
||||
<td><input type="checkbox" data-name="hidden"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<form>
|
||||
<button type="button" class="green" data-name="cancel">Close</button>
|
||||
</form>
|
||||
<span class="error hidden" data-name="error"></span>
|
||||
</section>
|
||||
|
||||
<section id="newshare" class="container hidden">
|
||||
<h1>New Share</h1>
|
||||
<form>
|
||||
|
||||
@@ -146,11 +146,12 @@ export class Share {
|
||||
* @param {function(Array<Share>, ?string):void} callback
|
||||
*/
|
||||
export function reload_sharing_list(user, password, collection, callback) {
|
||||
let body = collection ? { PathMapped: collection.href } : {};
|
||||
call_sharing_api(
|
||||
user,
|
||||
password,
|
||||
"all/list",
|
||||
{ PathMapped: collection.href },
|
||||
body,
|
||||
function (response) {
|
||||
let parsed = JSON.parse(response);
|
||||
let shares = (parsed["Content"] || []).map(data => new Share(data));
|
||||
@@ -411,3 +412,41 @@ export function update_share_by_map(
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a shared map entry as the recipient user.
|
||||
* Only sends fields the non-owner user is allowed to change: PathOrToken, EnabledByUser, HiddenByUser.
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
* @param {Share} share
|
||||
* @param {function(?string):void} callback
|
||||
*/
|
||||
export function update_incoming_share(
|
||||
user,
|
||||
password,
|
||||
share,
|
||||
callback,
|
||||
) {
|
||||
call_sharing_api(
|
||||
user,
|
||||
password,
|
||||
"map/update",
|
||||
{
|
||||
PathOrToken: share.PathOrToken,
|
||||
Enabled: share.EnabledByUser,
|
||||
Hidden: share.HiddenByUser,
|
||||
},
|
||||
function (response) {
|
||||
let json_response = JSON.parse(response);
|
||||
if (json_response["Status"] !== "success") {
|
||||
callback(json_response["Status"] || "Unknown error");
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
null,
|
||||
function (error) {
|
||||
callback(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import { Collection, CollectionType } from "../models/collection.js";
|
||||
import { bytesToHumanReadable } from "../utils/misc.js";
|
||||
import { CreateEditCollectionScene } from "./CreateEditCollectionScene.js";
|
||||
import { DeleteCollectionScene } from "./DeleteCollectionScene.js";
|
||||
import { IncomingSharingScene } from "./IncomingSharingScene.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
import { ShareCollectionScene, maybe_enable_sharing_options } from "./ShareCollectionScene.js";
|
||||
@@ -48,6 +49,7 @@ export class CollectionsScene {
|
||||
/** @type {HTMLElement} */ let template = html_scene.querySelector("[data-name=collectiontemplate]");
|
||||
/** @type {HTMLElement} */ let new_btn = html_scene.querySelector("[data-name=new]");
|
||||
/** @type {HTMLElement} */ let upload_btn = html_scene.querySelector("[data-name=upload]");
|
||||
/** @type {HTMLElement} */ let incomingshares_btn = html_scene.querySelector("[data-name=incomingshares]");
|
||||
|
||||
/** @type {?number} */ let scene_index = null;
|
||||
/** @type {?XMLHttpRequest} */ let collections_req = null;
|
||||
@@ -74,6 +76,16 @@ export class CollectionsScene {
|
||||
return false;
|
||||
}
|
||||
|
||||
function onincomingshares() {
|
||||
try {
|
||||
let incoming_sharing_scene = new IncomingSharingScene(user, password);
|
||||
push_scene(incoming_sharing_scene, false);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function onedit(collection) {
|
||||
try {
|
||||
let edit_collection_scene = new CreateEditCollectionScene(user, password, collection);
|
||||
@@ -191,6 +203,7 @@ export class CollectionsScene {
|
||||
html_scene.classList.remove("hidden");
|
||||
new_btn.onclick = onnew;
|
||||
upload_btn.onclick = onupload;
|
||||
incomingshares_btn.onclick = onincomingshares;
|
||||
if (collections === null) {
|
||||
update();
|
||||
discover_server_features(user, password, maybe_enable_sharing_options);
|
||||
@@ -204,6 +217,7 @@ export class CollectionsScene {
|
||||
scene_index = scene_stack.length - 1;
|
||||
new_btn.onclick = null;
|
||||
upload_btn.onclick = null;
|
||||
incomingshares_btn.onclick = null;
|
||||
collections = null;
|
||||
// remove collection
|
||||
nodes.forEach(function (node) {
|
||||
|
||||
175
radicale/web/internal_data/js/scenes/IncomingSharingScene.js
Normal file
175
radicale/web/internal_data/js/scenes/IncomingSharingScene.js
Normal file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* This file is part of Radicale Server - Calendar Server
|
||||
* Copyright © 2017-2024 Unrud <unrud@outlook.com>
|
||||
* Copyright © 2023-2024 Matthew Hana <matthew.hana@gmail.com>
|
||||
* Copyright © 2024-2025 Peter Bieringer <pb@bieringer.de>
|
||||
* Copyright © 2026-2026 Max Berger <max@berger.name>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Share, reload_sharing_list, update_incoming_share } from "../api/sharing.js";
|
||||
import { ErrorHandler } from "../utils/error.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
|
||||
/**
|
||||
* @implements {Scene}
|
||||
*/
|
||||
export class IncomingSharingScene {
|
||||
/**
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
*/
|
||||
constructor(user, password) {
|
||||
/** @type {HTMLElement} */ let html_scene = document.getElementById("incomingsharingscene");
|
||||
/** @type {HTMLElement} */ let cancel_btn = html_scene.querySelector("[data-name=cancel]");
|
||||
/** @type {HTMLElement} */ let error_element = html_scene.querySelector("[data-name=error]");
|
||||
/** @type {HTMLElement} */ let tbody = html_scene.querySelector("tbody[data-name=incomingsharesbody]");
|
||||
/** @type {HTMLElement} */ let template = tbody.querySelector("[data-name=incomingsharerowtemplate]");
|
||||
|
||||
let error_handler = new ErrorHandler(error_element);
|
||||
|
||||
/** @type {?number} */ let scene_index = null;
|
||||
/** @type {Array<HTMLElement>} */ let nodes = [];
|
||||
/** @type {?Array<Object>} */ let shares_cache = null;
|
||||
|
||||
function on_cancel() {
|
||||
pop_scene(scene_index - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Share} share
|
||||
* @param {HTMLElement} node
|
||||
*/
|
||||
function toggle_share(share, node) {
|
||||
let enabled_cb = /** @type {HTMLInputElement} */ (node.querySelector("[data-name=enabled]"));
|
||||
let hidden_cb = /** @type {HTMLInputElement} */ (node.querySelector("[data-name=hidden]"));
|
||||
|
||||
// disable checkboxes while updating
|
||||
enabled_cb.disabled = true;
|
||||
hidden_cb.disabled = true;
|
||||
|
||||
let old_enabled = share.EnabledByUser;
|
||||
let old_hidden = share.HiddenByUser;
|
||||
|
||||
share.EnabledByUser = enabled_cb.checked;
|
||||
share.HiddenByUser = hidden_cb.checked;
|
||||
error_handler.clearError();
|
||||
|
||||
update_incoming_share(user, password, share, function (error) {
|
||||
enabled_cb.disabled = false;
|
||||
hidden_cb.disabled = false;
|
||||
|
||||
if (error) {
|
||||
error_handler.setError(error);
|
||||
enabled_cb.checked = old_enabled;
|
||||
hidden_cb.checked = old_hidden;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Share[]} shares
|
||||
*/
|
||||
function render_shares(shares) {
|
||||
// clear old nodes
|
||||
nodes.forEach(function (node) {
|
||||
node.parentNode.removeChild(node);
|
||||
});
|
||||
nodes = [];
|
||||
|
||||
let prefix = "/" + user + "/";
|
||||
let filtered_shares = shares.filter(share => share.ShareType === "map" && share.PathOrToken.startsWith(prefix));
|
||||
|
||||
filtered_shares.forEach(function (share) {
|
||||
let node = /** @type {HTMLElement} */(template.cloneNode(true));
|
||||
node.classList.remove("hidden");
|
||||
|
||||
let pathortoken_td = node.querySelector("[data-name=pathortoken]");
|
||||
let owner_td = node.querySelector("[data-name=owner]");
|
||||
let permissions_td = node.querySelector("[data-name=permissions]");
|
||||
let enabled_cb = /** @type {HTMLInputElement} */ (node.querySelector("[data-name=enabled]"));
|
||||
let hidden_cb = /** @type {HTMLInputElement} */ (node.querySelector("[data-name=hidden]"));
|
||||
|
||||
let displayPath = share.PathOrToken.substring(prefix.length);
|
||||
if (displayPath.endsWith("/")) {
|
||||
displayPath = displayPath.substring(0, displayPath.length - 1);
|
||||
}
|
||||
|
||||
pathortoken_td.textContent = displayPath;
|
||||
owner_td.textContent = share.Owner;
|
||||
permissions_td.textContent = share.Permissions;
|
||||
|
||||
enabled_cb.checked = share.EnabledByUser;
|
||||
hidden_cb.checked = share.HiddenByUser;
|
||||
|
||||
enabled_cb.onchange = function () { toggle_share(share, node); };
|
||||
hidden_cb.onchange = function () { toggle_share(share, node); };
|
||||
|
||||
nodes.push(node);
|
||||
tbody.appendChild(node);
|
||||
});
|
||||
}
|
||||
|
||||
function update() {
|
||||
let loading_scene = new LoadingScene();
|
||||
push_scene(loading_scene, false);
|
||||
|
||||
error_handler.clearError();
|
||||
|
||||
reload_sharing_list(user, password, null, function (shares, error) {
|
||||
if (scene_index === null) {
|
||||
return;
|
||||
}
|
||||
if (error) {
|
||||
error_handler.setError(error);
|
||||
pop_scene(scene_index - 1);
|
||||
} else {
|
||||
shares_cache = shares;
|
||||
pop_scene(scene_index);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.show = function () {
|
||||
scene_index = scene_stack.length - 1;
|
||||
html_scene.classList.remove("hidden");
|
||||
cancel_btn.onclick = on_cancel;
|
||||
if (shares_cache === null) {
|
||||
update();
|
||||
} else {
|
||||
render_shares(shares_cache);
|
||||
}
|
||||
};
|
||||
|
||||
this.hide = function () {
|
||||
html_scene.classList.add("hidden");
|
||||
cancel_btn.onclick = null;
|
||||
error_handler.clearError();
|
||||
|
||||
nodes.forEach(function (node) {
|
||||
node.parentNode.removeChild(node);
|
||||
});
|
||||
nodes = [];
|
||||
shares_cache = null;
|
||||
};
|
||||
|
||||
this.release = function () {
|
||||
scene_index = null;
|
||||
error_handler.clearError();
|
||||
shares_cache = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user