Add functionality to add a new share by map
This commit is contained in:
@@ -45,6 +45,8 @@ permit_create_map = true
|
|||||||
with open(user_path, "w") as f:
|
with open(user_path, "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
"""admin:adminpassword
|
"""admin:adminpassword
|
||||||
|
max:maxpassword
|
||||||
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -49,3 +49,46 @@ def test_create_and_delete_share_by_key(page: Page, radicale_server: str) -> Non
|
|||||||
expect(
|
expect(
|
||||||
page.locator("tr[data-name='sharetokenrowtemplate']:not(.hidden)")
|
page.locator("tr[data-name='sharetokenrowtemplate']:not(.hidden)")
|
||||||
).to_have_count(0)
|
).to_have_count(0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_and_delete_share_by_map(page: Page, radicale_server: str) -> None:
|
||||||
|
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)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
page.locator("tr[data-name='sharemaprowtemplate']:not(.hidden)")
|
||||||
|
).to_have_count(0)
|
||||||
|
|
||||||
|
page.click('button[data-name="sharebymap"]')
|
||||||
|
page.locator('input[data-name="shareuser"]').fill("max")
|
||||||
|
page.locator('input[data-name="sharehref"]').fill("1234")
|
||||||
|
page.click('#newshare button[data-name="submit"]')
|
||||||
|
expect(
|
||||||
|
page.locator("tr[data-name='sharemaprowtemplate']:not(.hidden)")
|
||||||
|
).to_have_count(1)
|
||||||
|
expect(
|
||||||
|
page.locator("tr[data-name='sharemaprowtemplate']:not(.hidden) img[alt='RO']")
|
||||||
|
).to_be_visible()
|
||||||
|
page.once("dialog", lambda dialog: dialog.accept())
|
||||||
|
page.click('tr:not(.hidden) button[data-name="delete"]', strict=True)
|
||||||
|
expect(
|
||||||
|
page.locator("tr[data-name='sharemaprowtemplate']:not(.hidden)")
|
||||||
|
).to_have_count(0)
|
||||||
|
page.click('button[data-name="sharebymap"]')
|
||||||
|
page.click('label[for="newshare_attr_permissions_rw"]')
|
||||||
|
page.locator('input[data-name="shareuser"]').fill("max")
|
||||||
|
page.locator('input[data-name="sharehref"]').fill("1234")
|
||||||
|
page.click('#newshare button[data-name="submit"]')
|
||||||
|
expect(
|
||||||
|
page.locator("tr[data-name='sharemaprowtemplate']:not(.hidden)")
|
||||||
|
).to_have_count(1)
|
||||||
|
expect(
|
||||||
|
page.locator("tr[data-name='sharemaprowtemplate']:not(.hidden) img[alt='RW']")
|
||||||
|
).to_be_visible()
|
||||||
|
page.once("dialog", lambda dialog: dialog.accept())
|
||||||
|
page.click('tr:not(.hidden) button[data-name="delete"]', strict=True)
|
||||||
|
expect(
|
||||||
|
page.locator("tr[data-name='sharemaprowtemplate']:not(.hidden)")
|
||||||
|
).to_have_count(0)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { add_share_by_token } from "./api.js";
|
import { add_share_by_map, add_share_by_token } from "./api.js";
|
||||||
import { Scene, pop_scene, scene_stack } from "./scene_manager.js";
|
import { Scene, pop_scene, scene_stack } from "./scene_manager.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,11 +29,15 @@ export class NewShareScene {
|
|||||||
* @param {string} user
|
* @param {string} user
|
||||||
* @param {string} password
|
* @param {string} password
|
||||||
* @param {string} pathMapped
|
* @param {string} pathMapped
|
||||||
|
* @param {string} shareType
|
||||||
* @param {function():void} onclose
|
* @param {function():void} onclose
|
||||||
*/
|
*/
|
||||||
constructor(user, password, pathMapped, onclose) {
|
constructor(user, password, pathMapped, shareType, onclose) {
|
||||||
/** @type {HTMLElement} */ let html_scene = document.getElementById("newshare");
|
/** @type {HTMLElement} */ let html_scene = document.getElementById("newshare");
|
||||||
/** @type {HTMLFormElement} */ let form = html_scene.querySelector("form");
|
/** @type {HTMLFormElement} */ let form = html_scene.querySelector("form");
|
||||||
|
/** @type {HTMLElement} */ let sharemapfields = html_scene.querySelector("[data-name=sharemapfields]");
|
||||||
|
/** @type {HTMLInputElement} */ let shareuser_input = html_scene.querySelector("[data-name=shareuser]");
|
||||||
|
/** @type {HTMLInputElement} */ let sharehref_input = html_scene.querySelector("[data-name=sharehref]");
|
||||||
/** @type {HTMLInputElement} */ let enabled_checkbox = html_scene.querySelector("[data-name=enabled]");
|
/** @type {HTMLInputElement} */ let enabled_checkbox = html_scene.querySelector("[data-name=enabled]");
|
||||||
/** @type {HTMLInputElement} */ let hidden_checkbox = html_scene.querySelector("[data-name=hidden]");
|
/** @type {HTMLInputElement} */ let hidden_checkbox = html_scene.querySelector("[data-name=hidden]");
|
||||||
let permissions_ro_radio = /** @type {HTMLInputElement} */ (document.getElementById("newshare_attr_permissions_ro"));
|
let permissions_ro_radio = /** @type {HTMLInputElement} */ (document.getElementById("newshare_attr_permissions_ro"));
|
||||||
@@ -62,12 +66,20 @@ export class NewShareScene {
|
|||||||
let permissions = permissions_rw_radio.checked ? "rw" : "r";
|
let permissions = permissions_rw_radio.checked ? "rw" : "r";
|
||||||
let properties = properties_input.value;
|
let properties = properties_input.value;
|
||||||
|
|
||||||
add_share_by_token(user, password, pathMapped, permissions, enabled, hidden, properties, function () {
|
let callback = function () {
|
||||||
if (scene_index !== null) {
|
if (scene_index !== null) {
|
||||||
pop_scene(scene_index - 1);
|
pop_scene(scene_index - 1);
|
||||||
}
|
}
|
||||||
if (onclose) onclose();
|
if (onclose) onclose();
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (shareType === "map") {
|
||||||
|
let share_user = shareuser_input.value;
|
||||||
|
let href = sharehref_input.value;
|
||||||
|
add_share_by_map(user, password, pathMapped, permissions, enabled, hidden, properties, share_user, href, callback);
|
||||||
|
} else {
|
||||||
|
add_share_by_token(user, password, pathMapped, permissions, enabled, hidden, properties, callback);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
@@ -81,6 +93,14 @@ export class NewShareScene {
|
|||||||
cancel_btn.onclick = oncancel;
|
cancel_btn.onclick = oncancel;
|
||||||
form.onsubmit = onsubmit;
|
form.onsubmit = onsubmit;
|
||||||
|
|
||||||
|
if (shareType === "map") {
|
||||||
|
sharemapfields.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
sharemapfields.classList.add("hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
shareuser_input.value = "";
|
||||||
|
sharehref_input.value = "";
|
||||||
enabled_checkbox.checked = true;
|
enabled_checkbox.checked = true;
|
||||||
hidden_checkbox.checked = false;
|
hidden_checkbox.checked = false;
|
||||||
permissions_ro_radio.checked = true;
|
permissions_ro_radio.checked = true;
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ export class ShareCollectionScene {
|
|||||||
/** @type {HTMLElement} */ let cancel_btn = html_scene.querySelector("[data-name=cancel]");
|
/** @type {HTMLElement} */ let cancel_btn = html_scene.querySelector("[data-name=cancel]");
|
||||||
/** @type {HTMLElement} */ let share_by_token_btn = html_scene.querySelector(
|
/** @type {HTMLElement} */ let share_by_token_btn = html_scene.querySelector(
|
||||||
"button[data-name=sharebytoken]"
|
"button[data-name=sharebytoken]"
|
||||||
|
);
|
||||||
|
/** @type {HTMLElement} */ let share_by_map_btn = html_scene.querySelector(
|
||||||
|
"button[data-name=sharebymap]"
|
||||||
);
|
);
|
||||||
/** @type {HTMLElement} */ let share_by_token_div = html_scene.querySelector(
|
/** @type {HTMLElement} */ let share_by_token_div = html_scene.querySelector(
|
||||||
"div[data-name=sharebytoken]"
|
"div[data-name=sharebytoken]"
|
||||||
@@ -65,7 +68,14 @@ export class ShareCollectionScene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onsharebytoken() {
|
function onsharebytoken() {
|
||||||
let new_share_scene = new NewShareScene(user, password, collection.href, function () {
|
let new_share_scene = new NewShareScene(user, password, collection.href, "token", function () {
|
||||||
|
update_share_list(user, password, collection);
|
||||||
|
});
|
||||||
|
push_scene(new_share_scene, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onsharebymap() {
|
||||||
|
let new_share_scene = new NewShareScene(user, password, collection.href, "map", function () {
|
||||||
update_share_list(user, password, collection);
|
update_share_list(user, password, collection);
|
||||||
});
|
});
|
||||||
push_scene(new_share_scene, false);
|
push_scene(new_share_scene, false);
|
||||||
@@ -91,6 +101,15 @@ export class ShareCollectionScene {
|
|||||||
if (share_by_token_div) share_by_token_div.classList.add("hidden");
|
if (share_by_token_div) share_by_token_div.classList.add("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (server_features.sharing && server_features.sharing.PermittedCreateCollectionByMap) {
|
||||||
|
if (share_by_map_btn) {
|
||||||
|
share_by_map_btn.classList.remove("hidden");
|
||||||
|
share_by_map_btn.onclick = onsharebymap;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (share_by_map_btn) share_by_map_btn.classList.add("hidden");
|
||||||
|
}
|
||||||
|
|
||||||
if (server_features.sharing && server_features.sharing.FeatureEnabledCollectionByMap) {
|
if (server_features.sharing && server_features.sharing.FeatureEnabledCollectionByMap) {
|
||||||
if (share_by_map_div) share_by_map_div.classList.remove("hidden");
|
if (share_by_map_div) share_by_map_div.classList.remove("hidden");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -519,6 +519,54 @@ export function add_share_by_token(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} user
|
||||||
|
* @param {string} password
|
||||||
|
* @param {string} pathMapped
|
||||||
|
* @param {string} permissions
|
||||||
|
* @param {boolean} enabled
|
||||||
|
* @param {boolean} hidden
|
||||||
|
* @param {string} properties
|
||||||
|
* @param {string} share_user
|
||||||
|
* @param {string} href
|
||||||
|
* @param {function():void} callback
|
||||||
|
*/
|
||||||
|
export function add_share_by_map(
|
||||||
|
user,
|
||||||
|
password,
|
||||||
|
pathMapped,
|
||||||
|
permissions,
|
||||||
|
enabled,
|
||||||
|
hidden,
|
||||||
|
properties,
|
||||||
|
share_user,
|
||||||
|
href,
|
||||||
|
callback,
|
||||||
|
) {
|
||||||
|
call_sharing_api(
|
||||||
|
user,
|
||||||
|
password,
|
||||||
|
"map/create",
|
||||||
|
{
|
||||||
|
PathMapped: pathMapped,
|
||||||
|
Permissions: permissions,
|
||||||
|
Enabled: enabled,
|
||||||
|
Hidden: hidden,
|
||||||
|
Properties: properties,
|
||||||
|
User: share_user,
|
||||||
|
PathOrToken: "/" + share_user + "/" + href,
|
||||||
|
},
|
||||||
|
function (response) {
|
||||||
|
let json_response = JSON.parse(response);
|
||||||
|
if (json_response["Status"] !== "success") {
|
||||||
|
console.error("Failed to create share map: " + (json_response["Status"] || "Unknown error"));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} user
|
* @param {string} user
|
||||||
* @param {string} password
|
* @param {string} password
|
||||||
|
|||||||
@@ -263,6 +263,11 @@ main {
|
|||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#newshare input[type=text] {
|
||||||
|
margin-bottom: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.deleteconfirmationtxt {
|
.deleteconfirmationtxt {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
|
|||||||
@@ -185,16 +185,15 @@
|
|||||||
<td><input type="text" data-name="pathortoken" value="" readonly=""
|
<td><input type="text" data-name="pathortoken" value="" readonly=""
|
||||||
onfocus="this.setSelectionRange(0, 99999);" class="inline"></td>
|
onfocus="this.setSelectionRange(0, 99999);" class="inline"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<!--
|
<tr>
|
||||||
<tr>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td>
|
||||||
<td></td>
|
<button type="button" class="blue inline" data-name="sharebymap">
|
||||||
<td><button type="button" class="blue inline" data-name="sharebymap"><img src="css/icons/new.svg"
|
<img src="css/icons/new.svg" class="small_icon" alt="New Share by Map">
|
||||||
class="small_icon" alt="New Share by Map"></button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
-->
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@@ -206,6 +205,13 @@
|
|||||||
<section id="newshare" class="container hidden">
|
<section id="newshare" class="container hidden">
|
||||||
<h1>New Share</h1>
|
<h1>New Share</h1>
|
||||||
<form>
|
<form>
|
||||||
|
<fieldset data-name="sharemapfields" class="hidden">
|
||||||
|
<legend>Map Target</legend>
|
||||||
|
<label for="newshare_attr_shareuser">Share User</label>
|
||||||
|
<input type="text" data-name="shareuser" id="newshare_attr_shareuser" />
|
||||||
|
<label for="newshare_attr_sharehref">Share Href</label>
|
||||||
|
<input type="text" data-name="sharehref" id="newshare_attr_sharehref" />
|
||||||
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Attributes</legend>
|
<legend>Attributes</legend>
|
||||||
<input type="checkbox" data-name="enabled" checked="true" id="newshare_attr_enabled" /><label
|
<input type="checkbox" data-name="enabled" checked="true" id="newshare_attr_enabled" /><label
|
||||||
|
|||||||
Reference in New Issue
Block a user