Check Server Feature PermittedCreateCollectionByToken before showing token sharing buttons and reload ServerFeatures on refresh
This commit is contained in:
@@ -21,9 +21,9 @@
|
||||
import { CreateEditCollectionScene } from "./CreateEditCollectionScene.js";
|
||||
import { DeleteCollectionScene } from "./DeleteCollectionScene.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { CreateShareCollectionScene } from "./ShareCollectionScene.js";
|
||||
import { CreateShareCollectionScene, maybe_enable_sharing_options } from "./ShareCollectionScene.js";
|
||||
import { UploadCollectionScene } from "./UploadCollectionScene.js";
|
||||
import { get_collections } from "./api.js";
|
||||
import { discover_server_features, get_collections } from "./api.js";
|
||||
import { SERVER } from "./constants.js";
|
||||
import { Collection, CollectionType } from "./models.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
@@ -189,6 +189,7 @@ export class CollectionsScene {
|
||||
upload_btn.onclick = onupload;
|
||||
if (collections === null) {
|
||||
update();
|
||||
discover_server_features(user, password, maybe_enable_sharing_options);
|
||||
} else {
|
||||
// from update loading scene
|
||||
show_collections(collections);
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Scene, push_scene, pop_scene, scene_stack } from "./scene_manager.js";
|
||||
import { Collection, CollectionType } from "./models.js";
|
||||
import { random_uuid, random_hex, cleanHREFinput, isValidHREF } from "./utils.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { COLOR_RE } from "./constants.js";
|
||||
import { create_collection, edit_collection } from "./api.js";
|
||||
import { COLOR_RE } from "./constants.js";
|
||||
import { Collection, CollectionType } from "./models.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
import { cleanHREFinput, isValidHREF, random_hex, random_uuid } from "./utils.js";
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -34,7 +34,8 @@ import { create_collection, edit_collection } from "./api.js";
|
||||
* collection will be created inside of it.
|
||||
* Otherwise the collection will be edited.
|
||||
*/
|
||||
export function CreateEditCollectionScene(user, password, collection) {
|
||||
export class CreateEditCollectionScene {
|
||||
constructor(user, password, collection) {
|
||||
let edit = collection.type !== CollectionType.PRINCIPAL;
|
||||
let html_scene = document.getElementById(edit ? "editcollectionscene" : "createcollectionscene");
|
||||
/** @type {HTMLElement} */ let title_form = edit ? html_scene.querySelector("[data-name=title]") : null;
|
||||
@@ -187,7 +188,7 @@ export function CreateEditCollectionScene(user, password, collection) {
|
||||
scene_index = scene_stack.length - 1;
|
||||
// Clone type_form because it's impossible to hide options without removing them
|
||||
saved_type_form = type_form;
|
||||
type_form = type_form.cloneNode(true);
|
||||
type_form = /** @type {HTMLSelectElement} */ (type_form.cloneNode(true));
|
||||
saved_type_form.parentNode.replaceChild(type_form, saved_type_form);
|
||||
remove_invalid_types();
|
||||
html_scene.classList.remove("hidden");
|
||||
@@ -222,3 +223,4 @@ export function CreateEditCollectionScene(user, password, collection) {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,17 +18,17 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Scene, push_scene, pop_scene, scene_stack } from "./scene_manager.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { get_principal, discover_server_features } from "./api.js";
|
||||
import { get_principal } from "./api.js";
|
||||
import { CollectionsScene } from "./CollectionsScene.js";
|
||||
import { maybe_enable_sharing_options } from "./ShareCollectionScene.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Scene}
|
||||
*/
|
||||
export function LoginScene() {
|
||||
export class LoginScene {
|
||||
constructor() {
|
||||
/** @type {HTMLElement} */ let html_scene = document.getElementById("loginscene");
|
||||
/** @type {HTMLElement} */ let form = html_scene.querySelector("[data-name=form]");
|
||||
/** @type {HTMLInputElement} */ let user_form = html_scene.querySelector("[data-name=user]");
|
||||
@@ -90,7 +90,6 @@ export function LoginScene() {
|
||||
error = error1;
|
||||
user = saved_user;
|
||||
});
|
||||
discover_server_features(saved_user, password, maybe_enable_sharing_options);
|
||||
push_scene(collections_scene, true);
|
||||
}
|
||||
});
|
||||
@@ -154,3 +153,4 @@ export function LoginScene() {
|
||||
remove_logout();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -83,12 +83,14 @@ export class CreateShareCollectionScene {
|
||||
scene_index = scene_stack.length - 1;
|
||||
html_scene.classList.remove("hidden");
|
||||
cancel_btn.onclick = oncancel;
|
||||
if (server_features["sharing"]["FeatureEnabledCollectionByToken"]) {
|
||||
if (server_features["sharing"]["PermittedCreateCollectionByToken"]) {
|
||||
share_by_token_btn_ro.classList.remove("hidden");
|
||||
share_by_token_btn_rw.classList.remove("hidden");
|
||||
share_by_token_btn_ro.onclick = onsharebytoken_ro;
|
||||
share_by_token_btn_rw.onclick = onsharebytoken_rw;
|
||||
} else {
|
||||
share_by_token_btn_ro.parentElement.removeChild(share_by_token_btn_ro);
|
||||
share_by_token_btn_rw.parentElement.removeChild(share_by_token_btn_rw);
|
||||
share_by_token_btn_ro.classList.add("hidden");
|
||||
share_by_token_btn_rw.classList.add("hidden");
|
||||
}
|
||||
title.textContent = collection.displayname || collection.href;
|
||||
update_share_list(user, password, collection);
|
||||
|
||||
@@ -28,7 +28,7 @@ export let server_features = {};
|
||||
* Find the principal collection.
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
* @param {function(?Collection, ?string)} callback Returns result or error
|
||||
* @param {function(?Collection, ?string):void} callback Returns result or error
|
||||
* @return {XMLHttpRequest}
|
||||
*/
|
||||
export function get_principal(user, password, callback) {
|
||||
@@ -48,6 +48,7 @@ export function get_principal(user, password, callback) {
|
||||
CollectionType.PRINCIPAL,
|
||||
displayname_element ? displayname_element.textContent : "",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
""), null);
|
||||
} else {
|
||||
@@ -72,7 +73,7 @@ export function get_principal(user, password, callback) {
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
* @param {Collection} collection
|
||||
* @param {function(?Array<Collection>, ?string)} callback Returns result or error
|
||||
* @param {function(?Array<Collection>, ?string):void} callback Returns result or error
|
||||
* @return {XMLHttpRequest}
|
||||
*/
|
||||
export function get_collections(user, password, collection, callback) {
|
||||
@@ -195,7 +196,7 @@ export function get_collections(user, password, collection, callback) {
|
||||
* @param {string} password
|
||||
* @param {string} collection_href Must always start and end with /.
|
||||
* @param {File} file
|
||||
* @param {function(?string)} callback Returns error or null
|
||||
* @param {function(?string):void} callback Returns error or null
|
||||
* @return {XMLHttpRequest}
|
||||
*/
|
||||
export function upload_collection(user, password, collection_href, file, callback) {
|
||||
@@ -220,7 +221,7 @@ export function upload_collection(user, password, collection_href, file, callbac
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
* @param {Collection} collection
|
||||
* @param {function(?string)} callback Returns error or null
|
||||
* @param {function(?string):void} callback Returns error or null
|
||||
* @return {XMLHttpRequest}
|
||||
*/
|
||||
export function delete_collection(user, password, collection, callback) {
|
||||
@@ -245,7 +246,7 @@ export function delete_collection(user, password, collection, callback) {
|
||||
* @param {string} password
|
||||
* @param {Collection} collection
|
||||
* @param {boolean} create
|
||||
* @param {function(?string)} callback Returns error or null
|
||||
* @param {function(?string):void} callback Returns error or null
|
||||
* @return {XMLHttpRequest}
|
||||
*/
|
||||
function create_edit_collection(user, password, collection, create, callback) {
|
||||
@@ -325,7 +326,7 @@ function create_edit_collection(user, password, collection, create, callback) {
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
* @param {Collection} collection
|
||||
* @param {function(?string)} callback Returns error or null
|
||||
* @param {function(?string):void} callback Returns error or null
|
||||
* @return {XMLHttpRequest}
|
||||
*/
|
||||
export function create_collection(user, password, collection, callback) {
|
||||
@@ -336,7 +337,7 @@ export function create_collection(user, password, collection, callback) {
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
* @param {Collection} collection
|
||||
* @param {function(?string)} callback Returns error or null
|
||||
* @param {function(?string):void} callback Returns error or null
|
||||
* @return {XMLHttpRequest}
|
||||
*/
|
||||
export function edit_collection(user, password, collection, callback) {
|
||||
|
||||
Reference in New Issue
Block a user