Skip to content

Commit

Permalink
feat: Account linking (#158)
Browse files Browse the repository at this point in the history
* up to speed iwth in mem db

* bug fix

* adds link account function

* removes unneeded index

* Account linking function changes (#136)

* fixes bugs

* more tests

* Link accounts (#137)

* fixes bugs

* more tests

* updates to function (#138)

* Account linking unlink accounts (#139)

* updates to function

* adds unlink account function

* fixes and adds test (#140)

* changes for password reset flow (#141)

* Account linking update email (#142)

* changes for password reset flow

* removes unneeded function

* removes unneeded function

* adds recipe user id in session (#143)

* fixes query (#144)

* fix: user pagination (#145)

* fix: query update

* fix: primary_or_recipe_user_time_joined added to all_auth_users table

* fix: primary_or_recipe_user_time_joined added to all_auth_users table

* fix: user pagination queries

* fix: user pagination queries

* fix: plugin interface fix (#146)

* fix: plugin interface fix

* fix: pr comments

* fix: pr comments

* fix: External userid (#147)

* fix: plugin interface fix

* fix: pr comments

* fix: pr comments

* fix: external userid

* fix: remove UserInfo class (#148)

* fix: multitenant user association with account linking (#149)

* fix: tenant association query fixes

* fix: multitenancy related changes

* fix: pr comments

* fix: pr comments

* fix: pr comments

* fix: remove con reuse (#150)

* fix: remove con reuse

* fix: pr comments

* fix: pr comments

* fix: pr comments

* fix: pr comments

* fix: index updates (#152)

* fix: updated indexes

* fix: pr comments

* fix: pr comments

* fix: fkey constraint for primary_or_recipe_user_id (#153)

* fix: account linking stats (#154)

* fix: account linking stats

* fix: query

* fix: pr comment

* fix: fixing tenant association

* fix: allow user disassociation from all tenant (#156)

* fix: allow user disassociation from all tenant

* fix: query

* fix: useridmapping functions (#157)

* fix: version and changelog

* fix: version and changelog

* fix: time joined fix

---------

Co-authored-by: rishabhpoddar <[email protected]>
Co-authored-by: Mihály Lengyel <[email protected]>
  • Loading branch information
3 people authored Sep 20, 2023
1 parent 7f961ab commit 449dc14
Show file tree
Hide file tree
Showing 20 changed files with 2,753 additions and 834 deletions.
91 changes: 91 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,97 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [5.0.0] - 2023-09-19

### Changes

- Support for Account Linking
- Adds columns `primary_or_recipe_user_id`, `is_linked_or_is_a_primary_user` and `primary_or_recipe_user_time_joined` to `all_auth_recipe_users` table
- Adds columns `primary_or_recipe_user_id` and `is_linked_or_is_a_primary_user` to `app_id_to_user_id` table
- Removes index `all_auth_recipe_users_pagination_index` and addes `all_auth_recipe_users_pagination_index1`,
`all_auth_recipe_users_pagination_index2`, `all_auth_recipe_users_pagination_index3` and
`all_auth_recipe_users_pagination_index4` indexes instead on `all_auth_recipe_users` table
- Adds `all_auth_recipe_users_recipe_id_index` on `all_auth_recipe_users` table
- Adds `all_auth_recipe_users_primary_user_id_index` on `all_auth_recipe_users` table
- Adds `email` column to `emailpassword_pswd_reset_tokens` table
- Changes `user_id` foreign key constraint on `emailpassword_pswd_reset_tokens` to `app_id_to_user_id` table

### Migration

1. Ensure that the core is already upgraded to the version 6.0.13 (CDI version 3.0)
2. Stop the core instance(s)
3. Run the migration script
```sql
ALTER TABLE all_auth_recipe_users
ADD COLUMN primary_or_recipe_user_id CHAR(36) NOT NULL DEFAULT ('0');

ALTER TABLE all_auth_recipe_users
ADD COLUMN is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE;

ALTER TABLE all_auth_recipe_users
ADD COLUMN primary_or_recipe_user_time_joined BIGINT NOT NULL DEFAULT 0;

UPDATE all_auth_recipe_users
SET primary_or_recipe_user_id = user_id
WHERE primary_or_recipe_user_id = '0';

UPDATE all_auth_recipe_users
SET primary_or_recipe_user_time_joined = time_joined
WHERE primary_or_recipe_user_time_joined = 0;

ALTER TABLE all_auth_recipe_users
ADD CONSTRAINT all_auth_recipe_users_primary_or_recipe_user_id_fkey
FOREIGN KEY (app_id, primary_or_recipe_user_id)
REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;

ALTER TABLE all_auth_recipe_users
ALTER primary_or_recipe_user_id DROP DEFAULT;

ALTER TABLE app_id_to_user_id
ADD COLUMN primary_or_recipe_user_id CHAR(36) NOT NULL DEFAULT ('0');

ALTER TABLE app_id_to_user_id
ADD COLUMN is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE;

UPDATE app_id_to_user_id
SET primary_or_recipe_user_id = user_id
WHERE primary_or_recipe_user_id = '0';

ALTER TABLE app_id_to_user_id
ADD CONSTRAINT app_id_to_user_id_primary_or_recipe_user_id_fkey
FOREIGN KEY (app_id, primary_or_recipe_user_id)
REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;

ALTER TABLE app_id_to_user_id
ALTER primary_or_recipe_user_id DROP DEFAULT;

DROP INDEX all_auth_recipe_users_pagination_index;

CREATE INDEX all_auth_recipe_users_pagination_index1 ON all_auth_recipe_users (
app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);

CREATE INDEX all_auth_recipe_users_pagination_index2 ON all_auth_recipe_users (
app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);

CREATE INDEX all_auth_recipe_users_pagination_index3 ON all_auth_recipe_users (
recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);

CREATE INDEX all_auth_recipe_users_pagination_index4 ON all_auth_recipe_users (
recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);

CREATE INDEX all_auth_recipe_users_primary_user_id_index ON all_auth_recipe_users (primary_or_recipe_user_id, app_id);

CREATE INDEX all_auth_recipe_users_recipe_id_index ON all_auth_recipe_users (app_id, recipe_id, tenant_id);

ALTER TABLE emailpassword_pswd_reset_tokens DROP CONSTRAINT IF EXISTS emailpassword_pswd_reset_tokens_user_id_fkey;

ALTER TABLE emailpassword_pswd_reset_tokens ADD CONSTRAINT emailpassword_pswd_reset_tokens_user_id_fkey FOREIGN KEY (app_id, user_id) REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;

ALTER TABLE emailpassword_pswd_reset_tokens ADD COLUMN email VARCHAR(256);
```
4. Run the new instance(s) of the core (version 7.0.0)


## [4.0.2]

- Fixes null pointer issue when user belongs to no tenant.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

version = "4.0.2"
version = "5.0.0"

repositories {
mavenCentral()
Expand Down
Binary file removed jar/postgresql-plugin-4.0.2.jar
Binary file not shown.
Binary file added jar/postgresql-plugin-5.0.0.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pluginInterfaceSupported.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_comment": "contains a list of plugin interfaces branch names that this core supports",
"versions": [
"3.0"
"4.0"
]
}
Loading

0 comments on commit 449dc14

Please sign in to comment.