Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow per-user settings and store them in database #639

Merged
merged 68 commits into from Oct 15, 2023

Conversation

Monirzadeh
Copy link
Collaborator

@Monirzadeh Monirzadeh commented Jul 9, 2023

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?

@fmartingr
Copy link
Member

Hey @Monirzadeh, thanks for looking into this! One side note though: Keep in mind that I will need to take over all API/DB modifications over to #497, so the more concise they are the better.

I will try to merge the partial effort ASAP so we can iterate further in that direction, but the fact that the two APIs have to coexist for a little bit will make things difficult. I will gladly listen to some feedback on that end.

@Monirzadeh
Copy link
Collaborator Author

Monirzadeh commented Jul 16, 2023

Hi @fmartingr
I change configure on database as you want (for SQLite for now). Generate shiori-settings from database too (try not to change current settings logic).
Please overview the code and confirm if it hasn't a critical problem in the logic. (it is not removed all old changes yet)
Update: please review to-do list notes. specialy

(can we use json or text for all database? Done all of them the someway in all database if it is possible)

One question remain on my side:

  • Should I write a complete new API for update settings, or I should change the current API for that? Please answer this part, so I can go forward
    for now, we have a new API in last commit (not completed yet and need a better endpoint name)

Side note:

  • first user is horrible in shiori (it is not present in database until you create that after login) can we change this part of code? (it makes code unnecessary complicated). For example, if I try to update user settings for shiori before really create that in database (first login), GetAccount return empty result. (I work on some part of API but not push that it is not complete yet)

Copy link
Member

@fmartingr fmartingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

internal/database/migrations/mysql/0005_config.up.sql Outdated Show resolved Hide resolved
internal/model/model.go Outdated Show resolved Hide resolved
@fmartingr fmartingr added this to the 1.6.1 milestone Jul 19, 2023
@Monirzadeh
Copy link
Collaborator Author

I don't touch shiori-token but it not removes on logout from browser, is it normal?

@fmartingr
Copy link
Member

fmartingr commented Aug 12, 2023

I don't touch shiori-token but it not removes on logout from browser, is it normal?

You need to remove it (empty the shiori-token local storage key or remove the key altogether) on logout.

Copy link
Member

@fmartingr fmartingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work @Monirzadeh ! I have left you some small comments but this seems good to go.

I'm going to hold this on until 1.6.1 first or until I check in which state we can ship 1.6.0 as per the roadmap.

Remember to update the branch from latest master too

internal/view/assets/js/page/setting.js Outdated Show resolved Hide resolved
internal/http/routes/api/v1/auth_test.go Show resolved Hide resolved
internal/http/routes/api/v1/auth.go Outdated Show resolved Hide resolved
@fmartingr fmartingr changed the title Settings per user feat: allow per-user settings and store them in database Aug 12, 2023
Copy link
Member

@fmartingr fmartingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, this is ready to go :)

@fmartingr
Copy link
Member

Hey @Monirzadeh let's fix the conflicts here and merge this directly for 1.6.0.

@fmartingr fmartingr modified the milestones: 1.6.1, 1.6.0 Oct 15, 2023
@Monirzadeh
Copy link
Collaborator Author

@fmartingr it is ready

@fmartingr fmartingr merged commit c05d617 into go-shiori:master Oct 15, 2023
6 checks passed
truecharts-admin added a commit to truecharts/charts that referenced this pull request Mar 17, 2024
…0@628826c by renovate (#19427)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/go-shiori/shiori](https://togithub.com/go-shiori/shiori) |
minor | `v1.5.5` -> `v1.6.0` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>go-shiori/shiori (ghcr.io/go-shiori/shiori)</summary>

###
[`v1.6.0`](https://togithub.com/go-shiori/shiori/releases/tag/v1.6.0)

[Compare
Source](https://togithub.com/go-shiori/shiori/compare/v1.5.5...v1.6.0)

It's finally here! After some work we have started moving towards **a
more usable and open API** for others to consume, with **proper session
handling** (no more random logouts on server shutdowns!), improvements
to **ePubs**, UX and some more!

See details below for more information (important notes are the breaking
changes) and please fill an issue if you see anything weird, better be
safe than sorry!

#### Breaking changes

- The `serve` command is considered deprecated and will be removed in a
future release. Right now just proxies to a new `server` command that is
the one that should be used from now on.
- The **server** command uses a new http backend. This **should be
transparent to users** and all things should keep working as usual, but
that meant refactoring some of the underlying systems too, so
experiences may vary between deployments and operating systems. Please
fill an issue if you see that something is not working as expected.
- We are moving the API to a more stable, documented and with a proper
code structure. Right now there's a mix between old and new endpoints
until migration is completed. Check [the
documentation](https://togithub.com/go-shiori/shiori/blob/master/docs/APIv1.md)
for more information on the new API and [this roadmap
filter](https://togithub.com/orgs/go-shiori/projects/2/views/11) to see
progress on the API migration.
- Authentication to the API now uses JWTs instead of session tokens and
the **endpoint has changed to a new one**, please check the
documentation mentioned above. This means that there's no longer logout
issues when the server is restarted or when you log in in other
computer/browser.
- The `--webroot` flag **no longer modifies the routes internally**, is
up to the user to proxy the routes properly to Shiori without the prefix
used to serve it.
That means that if you want to serve Shiori under `domain.com/shiori`
you need to send the path back to Shiori without the `/shiori` prefix so
routes keep working. This can be done in most reverse proxies that we're
aware of. We provided [a sample configuration for
Nginx](https://togithub.com/go-shiori/shiori/blob/master/docs/Configuration.md#reverse-proxies-and-the-webroot-path).
PRs are welcome for other reverse proxies.
- The `shiori/gopher` initial user is a full fledged user instead of
being hardcoded into Shiori. If you want a new user you need to create a
new owner user and then remove the `shiori` user.

#### Release cadence

Right now the release cadence has been slow because we made too many
changes at once and we had to test and finish everything before doing
this release. Plan moving forward is to iterate and release faster so
we're planning smaller milestones to provide new features and fixes
faster to you.

I will post an update announcement when [the
roadmap](https://togithub.com/orgs/go-shiori/projects/2/views/4) is
reviewed.

#### What's Changed

- APIv1: Start working on new REST API. Refactor logic in domains. by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#497
- Run legacy API and new API at the same time. by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#648
- fix: docker buildx tags by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#650
- Allow JWT authentication into legacy APIs by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#651
- Show version in login page by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#652
- fix: package-name in cleanup tag by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#655
- fix: pr tag prune using other action by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#656
- fix: title is never retrieved when adding bookmark by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#664
- Show Shiori version on server command by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#669
- chore: remove irc badge from README by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#674
- fix: title overwritten if user has defined it by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#684
- Proper SQLite default database and warn SHIORI_DBMS users by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#667
- chore: remove verbose logger by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#685
- Fix CI incorrectly tagging RC releases and disables docker builds on
forks by [@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#686
- preserve fragment in URLs
([#&#8203;315](https://togithub.com/go-shiori/shiori/issues/315)) by
[@&#8203;arakimo](https://togithub.com/arakimo) in
[go-shiori/shiori#687
- Swagger improvements by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#666
- fix: Ensure bookmark files are correctly downloaded before deleting
current ones by [@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#683
- fix(db): handle usage of special characters in searches by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#721
- fix: properly parse mysql connection string, docs update by
[@&#8203;rutkai](https://togithub.com/rutkai) in
[go-shiori/shiori#730
- deps: upgrade to Go 1.21 by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#698
- deps: upgrade github.com/gofrs/uuid to v5 by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#736
- feat: build css from less files locally by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#735
- refactor: Migrate ePub generation to go-epub by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#679
- chore(deps): bump the all group with 6 updates by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[go-shiori/shiori#738
- chore(deps): bump the all group with 1 update by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[go-shiori/shiori#740
- feat: use new JWT auth in all frontend API calls by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#743
- chore(deps): bump the all group with 1 update by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[go-shiori/shiori#746
- fix: styles-check and swag-check monitor just needed directory not
project root by [@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#747
- feat: allow resize the dialogbox for bigger/hidpi screens by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#732
- feat: allow per-user settings and store them in database by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#639
- fix: Remove unneeded variable and unify the way send token in header
by [@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#763
- add create ebook by default in settings by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#761
- fix: Actions in overlays on mobile hard to press by
[@&#8203;cbe](https://togithub.com/cbe) in
[go-shiori/shiori#759
- fix: Use webp as thumbnail by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#758
- Update documentation for add links to shiori in android devices from
share menu by [@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#757
- Fix typos by [@&#8203;shirayu](https://togithub.com/shirayu) in
[go-shiori/shiori#756
- chore(deps): bump the all group with 1 update by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[go-shiori/shiori#767
- refactor: migrate ebook routes by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#742
- Make suggestions tapable/clickable by
[@&#8203;cbe](https://togithub.com/cbe) in
[go-shiori/shiori#765
- chore: frontend formatting by [@&#8203;cbe](https://togithub.com/cbe)
in
[go-shiori/shiori#764
- ci: add codecov reporting by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#776
- deps: update go dependencies by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#777
- fix typo by [@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#778
- docs: example deployment for kubernetes by
[@&#8203;JPFrancoia](https://togithub.com/JPFrancoia) in
[go-shiori/shiori#754
- Add Documentation>CLI>Add bookmark by
[@&#8203;LLKoder](https://togithub.com/LLKoder) in
[go-shiori/shiori#794
- fix: generate coverage profile by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#797
- fix: use noreferer to prevent exposing shiori instance url to archived
websites by [@&#8203;istiak101](https://togithub.com/istiak101) in
[go-shiori/shiori#802
- deps: upgrade by [@&#8203;fmartingr](https://togithub.com/fmartingr)
in
[go-shiori/shiori#804
- refactor: migrate bookmark static pages to new http server by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#775
- Fixed lint errors after refactor by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#806
- docs: updated configuration page by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#808
- fix: force usage of shiori prefix for environment variables in
configuration by [@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#807
- deps: updated docker image versions by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#809
- chore(deps): bump the all group with 3 updates by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[go-shiori/shiori#812
- chore(deps): bump the all group with 3 updates by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[go-shiori/shiori#815
- chore(deps): bump the all group with 3 updates by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[go-shiori/shiori#830
- fix: fixes path issues on windows by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[go-shiori/shiori#829
- fix: regressions and documentation from 1.5.5 upgrade by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#837
- fix: update go-epub to latest version to avoid filename errors on
windows by [@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#840
- fix: point go-epub go correct repository by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[go-shiori/shiori#842
- feat: allow authentication using proxy request header by
[@&#8203;PterX](https://togithub.com/PterX) in
[go-shiori/shiori#836

#### New Contributors

- [@&#8203;arakimo](https://togithub.com/arakimo) made their first
contribution in
[go-shiori/shiori#687
- [@&#8203;rutkai](https://togithub.com/rutkai) made their first
contribution in
[go-shiori/shiori#730
- [@&#8203;cbe](https://togithub.com/cbe) made their first contribution
in
[go-shiori/shiori#759
- [@&#8203;shirayu](https://togithub.com/shirayu) made their first
contribution in
[go-shiori/shiori#756
- [@&#8203;JPFrancoia](https://togithub.com/JPFrancoia) made their first
contribution in
[go-shiori/shiori#754
- [@&#8203;LLKoder](https://togithub.com/LLKoder) made their first
contribution in
[go-shiori/shiori#794
- [@&#8203;istiak101](https://togithub.com/istiak101) made their first
contribution in
[go-shiori/shiori#802
- [@&#8203;PterX](https://togithub.com/PterX) made their first
contribution in
[go-shiori/shiori#836

**Full Changelog**:
go-shiori/shiori@v1.5.5...v1.6.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNTIuMCIsInVwZGF0ZWRJblZlciI6IjM3LjI1Mi4wIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIn0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants