[PR #639] [MERGED] feat: allow per-user settings and store them in database #708

Closed
opened 2026-02-25 23:35:12 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-shiori/shiori/pull/639
Author: @Monirzadeh
Created: 7/9/2023
Status: Merged
Merged: 10/15/2023
Merged by: @fmartingr

Base: masterHead: settings-per-user


📝 Commits (10+)

  • 3d5778f create needed field in sqlite database
  • c574a7e update account model
  • 53314e5 update Account struct for save Account options
  • ab0b922 update sqlite database return account settings
  • c6fdddc save configure in sqlite as text and return that
  • 8d68fb5 read configure from user account and defualt configure for shiori
  • f32dfd8 add api/ui for update settings in database user can save settings in database (in sqlite database)
  • c106749 check configures be in json format before save in database
  • 440a125 support MariaDB
  • b872736 fix wrong comment

📊 Changes

29 files changed (+906 additions, -117 deletions)

View changed files

📝 docs/swagger/docs.go (+72 -0)
📝 docs/swagger/swagger.json (+72 -0)
📝 docs/swagger/swagger.yaml (+46 -0)
📝 internal/database/database.go (+3 -0)
📝 internal/database/migrations/mysql/0001_initial.up.sql (+4 -4)
internal/database/migrations/mysql/0005_config.down.sql (+1 -0)
internal/database/migrations/mysql/0005_config.up.sql (+2 -0)
📝 internal/database/migrations/postgres/0001_initial.up.sql (+1 -1)
internal/database/migrations/postgres/0002_config.down.sql (+1 -0)
internal/database/migrations/postgres/0002_config.up.sql (+2 -0)
internal/database/migrations/sqlite/0003_config.down.sql (+1 -0)
internal/database/migrations/sqlite/0003_config.up.sql (+3 -0)
📝 internal/database/mysql.go (+15 -4)
📝 internal/database/mysql_test.go (+117 -0)
📝 internal/database/pg.go (+16 -4)
📝 internal/database/pg_test.go (+116 -0)
📝 internal/database/sqlite.go (+21 -5)
📝 internal/database/sqlite_test.go (+102 -0)
📝 internal/http/routes/api/v1/auth.go (+36 -0)
📝 internal/http/routes/api/v1/auth_test.go (+110 -0)

...and 9 more files

📄 Description

First step for real separate user in Shiori.
The goal is to move each user settings to the database and call each setting separately for each user.
I'm done some part of code but not push yet (it is not clean). It will be completed step by step until be ready for merge.

Why we need this?

TODO:

  • add needed field to the database
  • update model
  • update database.go to get database account information
  • update function for call data from database (sqlite)
  • settings of each user based on data called from database for that user
  • change logic to save configure just as on text field in SQLite
  • API for update setting record in database (better name for endpoint)
  • save settings from UI (do i need loading indicator while save in database?)
  • reflect updated value to the session
  • mechanism for check if configures is a valid json before add to database.
  • update function for call data from database (mysql)
  • update function for call data from database (pg)
  • add function saveSettings for other database.
    • MySQL
    • PostgreSQL
  • SaveAccount to SaveAccountSettings and configures to config
  • mechanism to migrate from old database to newer version and not break current instant of Shiori with data.
  • use json instead of text for config in database
  • Visitor account can't save settings because some settings not available for them. and validsetion check owner status fix that
  • can we use json or text for all database? Done all of them the same way in all database is better solution if it is possible
  • move update config in account variable to a function for more readable code
  • Done remaining TODO in code
  • down migrate script
  • fix some typo and update createEbook
  • Remove unneeded part because of driver.valuer
  • remove default config value for new user.
  • merge with master and solve conflicts
  • move to new API
  • solve validationsession
  • remove jsonify
  • unit test for database
  • unit test for API

Repeat for other database

What I need to know?

  • Specific security concern or test that should be pass?
  • Any specific settings should be active for new user by default?
  • Should I change current API for update settings or create new one?

Things make work unnecessary harder

  • current first user logic
  • first user (shiori with gopher) have problem before save that in database if user save new settings. Kinda bug in current logic be sure it solved. after version 1.6 it not a problem anymore.

Should be checked before merge:

  • does it work on SQLite?
  • does it work on MySQL?
  • does it work on PostgreSQL?
  • can migrate database without any problem?
  • any specific security concern?

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-shiori/shiori/pull/639 **Author:** [@Monirzadeh](https://github.com/Monirzadeh) **Created:** 7/9/2023 **Status:** ✅ Merged **Merged:** 10/15/2023 **Merged by:** [@fmartingr](https://github.com/fmartingr) **Base:** `master` ← **Head:** `settings-per-user` --- ### 📝 Commits (10+) - [`3d5778f`](https://github.com/go-shiori/shiori/commit/3d5778fd299f308adb7c825abbe1f4d5021006ee) create needed field in sqlite database - [`c574a7e`](https://github.com/go-shiori/shiori/commit/c574a7e54030bc1b16b531bb638b46c76ce35a0a) update account model - [`53314e5`](https://github.com/go-shiori/shiori/commit/53314e5fd9b5814dccacb0931040d37c7761b9e1) update Account struct for save Account options - [`ab0b922`](https://github.com/go-shiori/shiori/commit/ab0b922f4020e6cd30e0fba458329e84a97ee9b7) update sqlite database return account settings - [`c6fdddc`](https://github.com/go-shiori/shiori/commit/c6fdddcbedd0ceca698288a9bcb7a3204aa72131) save configure in sqlite as text and return that - [`8d68fb5`](https://github.com/go-shiori/shiori/commit/8d68fb5ef83dc5ee0423b7286ef8dab9d7428bd2) read configure from user account and defualt configure for shiori - [`f32dfd8`](https://github.com/go-shiori/shiori/commit/f32dfd8828f37f2ac3aa93ae1cf904255eb4027a) add api/ui for update settings in database user can save settings in database (in sqlite database) - [`c106749`](https://github.com/go-shiori/shiori/commit/c1067498acd7b01f05874567beb66267cd4c005b) check configures be in json format before save in database - [`440a125`](https://github.com/go-shiori/shiori/commit/440a125eb961998b54b18c217b35e18af4ca6984) support MariaDB - [`b872736`](https://github.com/go-shiori/shiori/commit/b87273651d8c8e527781e911179f4dc4faa18923) fix wrong comment ### 📊 Changes **29 files changed** (+906 additions, -117 deletions) <details> <summary>View changed files</summary> 📝 `docs/swagger/docs.go` (+72 -0) 📝 `docs/swagger/swagger.json` (+72 -0) 📝 `docs/swagger/swagger.yaml` (+46 -0) 📝 `internal/database/database.go` (+3 -0) 📝 `internal/database/migrations/mysql/0001_initial.up.sql` (+4 -4) ➕ `internal/database/migrations/mysql/0005_config.down.sql` (+1 -0) ➕ `internal/database/migrations/mysql/0005_config.up.sql` (+2 -0) 📝 `internal/database/migrations/postgres/0001_initial.up.sql` (+1 -1) ➕ `internal/database/migrations/postgres/0002_config.down.sql` (+1 -0) ➕ `internal/database/migrations/postgres/0002_config.up.sql` (+2 -0) ➕ `internal/database/migrations/sqlite/0003_config.down.sql` (+1 -0) ➕ `internal/database/migrations/sqlite/0003_config.up.sql` (+3 -0) 📝 `internal/database/mysql.go` (+15 -4) 📝 `internal/database/mysql_test.go` (+117 -0) 📝 `internal/database/pg.go` (+16 -4) 📝 `internal/database/pg_test.go` (+116 -0) 📝 `internal/database/sqlite.go` (+21 -5) 📝 `internal/database/sqlite_test.go` (+102 -0) 📝 `internal/http/routes/api/v1/auth.go` (+36 -0) 📝 `internal/http/routes/api/v1/auth_test.go` (+110 -0) _...and 9 more files_ </details> ### 📄 Description First step for real separate user in Shiori. The goal is to move each user settings to the database and call each setting separately for each user. I'm done some part of code but not push yet (it is not clean). It will be completed step by step until be ready for merge. # Why we need this? - I explain some part of reason in this comment https://github.com/go-shiori/shiori/discussions/338#discussioncomment-6376681. - Maybe we can use this feature for cleaner code for #338 and make it per user - in the long term, maybe we can separate bookmark databases for each user. (we should keep public bookmark feature) # TODO: - [x] add needed field to the database - [x] update model - [x] update database.go to get database account information - [x] update function for call data from database (sqlite) - [x] settings of each user based on data called from database for that user - [x] change logic to save configure just as on text field in SQLite - [x] API for update setting record in database (better name for endpoint) - [x] save settings from UI (do i need loading indicator while save in database?) - [x] reflect updated value to the session - [x] mechanism for check if configures is a valid json before add to database. - [x] update function for call data from database (mysql) - [x] update function for call data from database (pg) - [x] add function saveSettings for other database. - [x] MySQL - [x] PostgreSQL - [x] `SaveAccount` to `SaveAccountSettings` and `configures` to `config` - [x] mechanism to migrate from old database to newer version and not break current instant of Shiori with data. - [x] use json instead of text for config in database - [x] Visitor account can't save settings because some settings not available for them. and validsetion check owner status fix that - [x] can we use json or text for all database? Done all of them the same way in all database is better solution if it is possible - [x] move update config in account variable to a function for more readable code - [x] Done remaining TODO in code - [x] down migrate script - [x] fix some typo and update createEbook - [x] Remove unneeded part because of `driver.valuer` - [x] remove default config value for new user. - [x] merge with master and solve conflicts - [x] move to new API - [x] solve validationsession - [x] remove jsonify - [x] unit test for database - [x] unit test for API ## Repeat for other database # What I need to know? - Specific security concern or test that should be pass? - Any specific settings should be active for new user by default? - ~~Should I change current API for update settings or create new one?~~ # Things make work unnecessary harder - ~~current first user logic~~ - ~~first user (shiori with gopher) have problem before save that in database if user save new settings. _Kinda bug in current logic_ be sure it solved.~~ after version 1.6 it not a problem anymore. # Should be checked before merge: - [x] does it work on SQLite? - [x] does it work on MySQL? - [x] does it work on PostgreSQL? - [x] can migrate database without any problem? - [x] any specific security concern? --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-25 23:35:12 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shiori#708
No description provided.