diff --git a/.gitignore b/.gitignore
index b3bf067..7d9a8ee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,5 @@
node_modules
server/data
-server/db
data
background
.vscode
diff --git a/frontend/src/helpers/constants.js b/frontend/src/helpers/constants.js
index ff3dff8..38a48a2 100644
--- a/frontend/src/helpers/constants.js
+++ b/frontend/src/helpers/constants.js
@@ -1,5 +1,5 @@
export const APP_NAME = "NeonLink";
-export const VERSION = "1.4.4";
+export const VERSION = "1.4.5";
export const DEF_MAX_ITEMS = 20;
export const DEF_COLUMNS = 3;
export const CARD_HEADER_STYLE = [
diff --git a/frontend/src/pages/settings/tabs/mainTab/UsersList.jsx b/frontend/src/pages/settings/tabs/mainTab/UsersList.jsx
index 1ddd35e..09afa4b 100644
--- a/frontend/src/pages/settings/tabs/mainTab/UsersList.jsx
+++ b/frontend/src/pages/settings/tabs/mainTab/UsersList.jsx
@@ -2,11 +2,15 @@ import React, { useEffect, useRef, useState } from "react";
import { notify } from "../../../../components/Notification";
import { deleteJSON, getJSON, putJSON } from "../../../../helpers/fetch";
import UserItem from "./UserItem";
+import { appSettingsKeys, useAppSettingsStore } from "../../../../stores/appSettingsStore";
export default function UsersList() {
const [users, setUsers] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(undefined);
+ const [authenticationEnabled] = useAppSettingsStore(
+ appSettingsKeys.AuthenticationEnabled
+ );
const abortController = useRef(null);
@@ -74,11 +78,19 @@ export default function UsersList() {
}, []);
useEffect(() => {
- if (isError) notify("Error", isError?.message || "", "error");
- }, [isError]);
+ if (isError && authenticationEnabled) {
+ notify(
+ "Error",
+ "Can't get list of users. " + isError?.message || "",
+ "error"
+ );
+ }
+ }, [isError, authenticationEnabled]);
if (isLoading) return
Loading...
;
+ if (users.length === 0) return No users
;
+
return (
{users.map((user) => (
diff --git a/server/db/sqlite/stores/backgrounds.js b/server/db/sqlite/stores/backgrounds.js
index 0cb28e5..d12c76c 100644
--- a/server/db/sqlite/stores/backgrounds.js
+++ b/server/db/sqlite/stores/backgrounds.js
@@ -9,22 +9,43 @@ export default class BackgroundsStore {
}
deleteItem(id, userId) {
- const deleteQuery = `DELETE FROM backgrounds WHERE id=:id AND (userId=:userId OR userId IS NULL)`;
- return this.db.prepare(deleteQuery).run({ id, userId }).changes;
+ const deleteQuery = `DELETE FROM backgrounds WHERE id=:id`;
+ let deleteParams = {id};
+ if (userId) {
+ deleteQuery += " AND (userId IN (:userId, 0) OR userId IS NULL)";
+ deleteParams += { userId };
+ }
+ return this.db.prepare(deleteQuery).run(deleteParams).changes;
}
getAll(userId) {
- const selectQuery = `SELECT * FROM backgrounds WHERE userId=:userId OR userId IS NULL`;
- return this.db.prepare(selectQuery).all({ userId });
+ let selectQuery = `SELECT * FROM backgrounds`;
+ let selectParams = {};
+ if (userId) {
+ selectQuery += " WHERE userId IN (:userId, 0) OR userId IS NULL";
+ selectParams += { userId };
+ }
+
+ return this.db.prepare(selectQuery).all(selectParams);
}
getItemById(id, userId) {
- const selectQuery = `SELECT * FROM backgrounds WHERE id=:id AND (userId=:userId OR userId IS NULL)`;
- return this.db.prepare(selectQuery).all({ id, userId });
+ let selectQuery = `SELECT * FROM backgrounds WHERE id=:id`;
+ let selectParams = {id};
+ if (userId) {
+ selectQuery += " AND (userId IN (:userId, 0) OR userId IS NULL)";
+ selectParams += { userId };
+ }
+ return this.db.prepare(selectQuery).all(selectParams);
}
getItemByUrl(url, userId) {
- const selectQuery = `SELECT * FROM backgrounds WHERE url=:url AND (userId=:userId OR userId IS NULL)`;
- return this.db.prepare(selectQuery).all({ url, userId });
+ let selectQuery = `SELECT * FROM backgrounds WHERE url=:url`;
+ let selectParams = {url};
+ if (userId) {
+ selectQuery += " AND (userId IN (:userId, 0) OR userId IS NULL)";
+ selectParams += { userId };
+ }
+ return this.db.prepare(selectQuery).all(selectParams);
}
}
diff --git a/server/db/sqlite/stores/bookmarks.js b/server/db/sqlite/stores/bookmarks.js
index 0bdaa45..b20f678 100644
--- a/server/db/sqlite/stores/bookmarks.js
+++ b/server/db/sqlite/stores/bookmarks.js
@@ -59,16 +59,15 @@ export default class BookmarksStore {
category !== undefined
? "LEFT JOIN category ON category.id = bookmarks.categoryId"
: ""
- }
- WHERE userId = :userId`;
+ }`;
const selectParams = {
userId,
};
- if (search || tag || category) {
- const conditions = [];
+ const conditions = [];
+ if (search || tag || category) {
if (search) {
conditions.push("bookmarks.search LIKE :search");
selectParams.search = `%${search}%`;
@@ -81,10 +80,15 @@ export default class BookmarksStore {
conditions.push("category.name = :category");
selectParams.category = category;
}
+ }
- selectQuery += ` WHERE ${conditions.join(" AND ")}`;
+ if (userId) {
+ conditions.push("(userId IN (:userId, 0) OR userId IS NULL)");
+ selectParams.userId = userId;
}
+ selectQuery += ` WHERE ${conditions.join(" AND ")}`;
+
selectQuery += ` GROUP BY bookmarks.id
ORDER BY bookmarks.created DESC`;
@@ -146,7 +150,11 @@ export default class BookmarksStore {
const conditions = [];
- conditions.push("bookmarks.userId = :userId");
+ if (userId) {
+ conditions.push("(bookmarks.userId IN (:userId, 0) OR bookmarks.userId IS NULL)");
+ countParams.userId = userId;
+ selectParams.userId = userId;
+ }
if (search || tag || category) {
if (search) {
@@ -166,8 +174,10 @@ export default class BookmarksStore {
}
}
- countQuery += ` WHERE ${conditions.join(" AND ")}`;
- selectQuery += ` WHERE ${conditions.join(" AND ")}`;
+ if (conditions.length > 0) {
+ countQuery += ` WHERE ${conditions.join(" AND ")}`;
+ selectQuery += ` WHERE ${conditions.join(" AND ")}`;
+ }
selectQuery += ` GROUP BY bookmarks.id
ORDER BY bookmarks.created DESC
@@ -192,22 +202,27 @@ export default class BookmarksStore {
id, url, title, desc, bookmarks.categoryId, created, bookmarkPosition.position
FROM bookmarks
LEFT JOIN bookmarkPosition ON bookmarks.id = bookmarkPosition.bookmarkId
- WHERE
- bookmarks.categoryId = :categoryId
- AND
- bookmarks.userId = :userId
- ORDER BY bookmarkPosition.position`;
+ `;
+ let selectParams = { categoryId, userId }
+
+ let conditions = []
+ conditions.push("bookmarks.categoryId = :categoryId")
+ if(userId){
+ conditions.push("(bookmarks.userId IN (:userId, 0) OR bookmarks.userId IS NULL)")
+ }
+ selectQuery += `WHERE ${conditions.join(" AND ")} `
+ selectQuery += "ORDER BY bookmarkPosition.position"
return this.db
.prepare(selectQuery)
- .all({ categoryId, userId })
+ .all(selectParams)
.map((bookmark) => {
return { ...bookmark, tags: bookmark.tags?.split(",") };
});
}
getItemById(userId, id) {
- const selectQuery = `SELECT
+ let selectQuery = `SELECT
bookmarks.id,
url,
title,
@@ -218,16 +233,27 @@ export default class BookmarksStore {
FROM bookmarks
LEFT JOIN bookmarksTags ON bookmarksTags.bookmarkId = bookmarks.id
LEFT JOIN tags ON bookmarksTags.tagId = tags.id
- WHERE bookmarks.id = :id
- AND bookmarks.userId = :userId
- GROUP BY bookmarks.id`;
-
- return this.db.prepare(selectQuery).get({ id, userId });
+ `;
+ let selectParams = {id}
+ let conditions = ["bookmarks.id = :id"]
+ conditions.push()
+ if(userId){
+ conditions.push("(bookmarks.userId IN (:userId, 0) OR bookmarks.userId IS NULL)")
+ selectParams.userId = userId
+ }
+ selectQuery += `WHERE ${conditions.join(" AND ")} `
+ selectQuery += `GROUP BY bookmarks.id`
+ return this.db.prepare(selectQuery).get(selectParams);
}
getItemByUrl(userId, url) {
- const selectQuery = `SELECT * FROM bookmarks WHERE url = :url AND userId = :userId`;
- return this.db.prepare(selectQuery).get({ url, userId });
+ const selectQuery = `SELECT * FROM bookmarks WHERE url = :url`;
+ let selectParams = {url}
+ if(userId){
+ selectQuery += " AND (userId IN (:userId, 0) OR userId IS NULL)"
+ selectParams.userId = userId
+ }
+ return this.db.prepare(selectQuery).get(selectParams);
}
getIconByBookmarkId(id) {
diff --git a/server/db/sqlite/stores/categories.js b/server/db/sqlite/stores/categories.js
index d06525a..c35a0eb 100644
--- a/server/db/sqlite/stores/categories.js
+++ b/server/db/sqlite/stores/categories.js
@@ -22,13 +22,17 @@ export default class CategoriesStore {
}
getAll(userId) {
- const selectQuery = `SELECT
+ let selectQuery = `SELECT
id, name, color, position FROM category
- INNER JOIN categoryPosition ON categoryPosition.categoryId = category.id
- WHERE userId = :userId
- ORDER BY position ASC`;
+ INNER JOIN categoryPosition ON categoryPosition.categoryId = category.id`
+ let selectParams = {}
+ if(userId){
+ selectQuery += ` WHERE (userId IN (:userId, 0) OR userId IS NULL) `
+ selectParams.userId = userId
+ }
+ selectQuery += ` ORDER BY position ASC`;
- return this.db.prepare(selectQuery).all({ userId });
+ return this.db.prepare(selectQuery).all(selectParams);
}
getItemById(id) {
@@ -42,15 +46,21 @@ export default class CategoriesStore {
}
getItemByName(name, userId) {
- const selectQuery = `SELECT
+ let selectQuery = `SELECT
id, name, color, position FROM category
INNER JOIN categoryPosition ON categoryPosition.categoryId = category.id
- WHERE
- name = :name
- AND userId = :userId
- ORDER BY position ASC`;
-
- return this.db.prepare(selectQuery).get({ name, userId });
+
+ `;
+ let selectParams = {name}
+ let conditions = []
+ conditions.push("name = :name")
+ if(userId){
+ conditions.push("(userId IN (:userId, 0) OR userId IS NULL)")
+ selectParams.userId = userId
+ }
+ selectQuery += ` WHERE ${conditions.join(" AND ")} `
+ selectQuery += `ORDER BY position ASC`
+ return this.db.prepare(selectQuery).get(selectParams);
}
deleteItem(id) {
diff --git a/server/db/sqlite/stores/tags.js b/server/db/sqlite/stores/tags.js
index c941491..a1b60cb 100644
--- a/server/db/sqlite/stores/tags.js
+++ b/server/db/sqlite/stores/tags.js
@@ -16,8 +16,14 @@ export default class TagsStore {
}
existsItemByName(name, userId) {
- const selectQuery = `SELECT COUNT(*) AS count FROM tags WHERE name = :name AND userId = :userId`;
- const result = this.db.prepare(selectQuery).get({ name, userId });
+ let selectQuery = `SELECT COUNT(*) AS count FROM tags WHERE name = :name`;
+ let selectParams = { name };
+ if (userId) {
+ selectQuery += ` AND (userId IN (:userId, 0) OR userId IS NULL) `;
+ selectParams.userId = userId;
+ }
+
+ const result = this.db.prepare(selectQuery).get(selectParams);
return result && result.count > 0;
}
@@ -26,22 +32,25 @@ export default class TagsStore {
id, name
FROM tags`;
- const selectParams = { userId };
- const conditions = [];
- conditions.push("tags.userId = :userId");
+ let selectParams = {};
+ let conditions = [];
+ if (userId) {
+ conditions.push("(tags.userId IN (:userId, 0) OR tags.userId IS NULL)");
+ selectParams.userId = userId;
+ }
if (name) {
conditions.push("tags.name LIKE :name");
selectParams.name = `%${name}%`;
}
- selectQuery += ` WHERE ${conditions.join(" AND ")}`;
+ if (conditions.length > 0) {
+ selectQuery += ` WHERE ${conditions.join(" AND ")}`;
+ }
selectQuery += ` GROUP BY tags.id
ORDER BY tags.name`;
- console.log(selectQuery, selectParams);
-
return this.db.prepare(selectQuery).all(selectParams);
}