Move user to person
This commit is contained in:
parent
462716633e
commit
c9dd17ae14
|
|
@ -0,0 +1,5 @@
|
|||
-- Remove person level tables
|
||||
ALTER TABLE if exists users
|
||||
drop column if exists person_id;
|
||||
|
||||
drop table if exists people;
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
-- Add login table
|
||||
create table if not exists people (
|
||||
id uuid NOT NULL DEFAULT gen_random_uuid (),
|
||||
created_at timestamp without time zone NOT NULL DEFAULT now(),
|
||||
created_by uuid NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL DEFAULT now(),
|
||||
updated_by uuid NOT NULL,
|
||||
email text NOT NULL,
|
||||
name text NOT NULL,
|
||||
family_name text NOT NULL,
|
||||
given_name text NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE
|
||||
people
|
||||
ADD
|
||||
CONSTRAINT people_pkey PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE if exists users
|
||||
ADD COLUMN person_id uuid REFERENCES people (id) ON DELETE SET NULL;
|
||||
|
||||
-- Copy data
|
||||
insert into people (created_by, updated_by, email, name, family_name, given_name)
|
||||
select created_by, updated_by, email, name, family_name, given_name from users;
|
||||
|
||||
update users u set person_id = p.id from people p where p.email = u.email;
|
||||
|
|
@ -28,6 +28,7 @@ struct UserProfileTemplate {
|
|||
user: UserData,
|
||||
user_roles: Vec<crate::user::UserRolesDisplay>,
|
||||
profile: UserData,
|
||||
profile_accounts: Vec<UserData>,
|
||||
profile_roles: Vec<crate::user::UserRolesDisplay>,
|
||||
non_profile_roles: Vec<crate::user::UserRolesDisplay>,
|
||||
}
|
||||
|
|
@ -181,6 +182,23 @@ pub async fn user_profile(
|
|||
// Get logged in user roles
|
||||
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
||||
|
||||
// Get user accounts
|
||||
let profile_accounts = sqlx::query_as( r#"SELECT
|
||||
id,
|
||||
created_at,
|
||||
created_by,
|
||||
updated_at,
|
||||
updated_by,
|
||||
email,
|
||||
name,
|
||||
family_name,
|
||||
given_name
|
||||
FROM users WHERE person_id = $1"#)
|
||||
.bind(user_id)
|
||||
.fetch_all(&db_pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Get user roles
|
||||
let profile_roles = get_user_roles_display(user_id, &db_pool.clone()).await;
|
||||
|
||||
|
|
@ -193,6 +211,7 @@ pub async fn user_profile(
|
|||
user,
|
||||
user_roles,
|
||||
profile,
|
||||
profile_accounts,
|
||||
profile_roles,
|
||||
non_profile_roles,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,6 +7,24 @@ Given name: {{ profile.given_name }}<br/>
|
|||
Family name: {{ profile.family_name }}<br/>
|
||||
Your email address: {{ profile.email }}<br/>
|
||||
<br/>
|
||||
<h2>Accounts</h2>
|
||||
<button type="button" class="btn btn-primary">Merge</button>
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for account in profile_accounts %}
|
||||
<tr>
|
||||
<td><a href="/accounts/{{ account.id }}">{{ account.name }}</a></td>
|
||||
<td><a href="/accounts/{{ account.id }}/delete">Delete</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>User Roles</h2>
|
||||
<button type="button" class="btn btn-primary">Edit</button>
|
||||
<button type="button" class="btn btn-primary">Add</button>
|
||||
|
|
|
|||
Loading…
Reference in New Issue