Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5e1088e

Browse files
Gcolon021Luke Sikina
authored and
Luke Sikina
committedOct 7, 2024
[ALS-5612] Updated stored procedure (#155)
* Add connectionSubPrefix to user creation stored procedure * Refactor connection prefix manipulation in SQL procedure * Update user creation stored procedure The changes made address the process of user creation in the stored procedure. A new variable, @baseUUID, has been introduced for storing UUIDs during processing. Additionally, the preparation of @connectionSubPrefix has been adjusted to concatenate LONG_TERM_TOKEN with existing values instead of overriding them. * Add PIC-SURE User role assignment in CreateUserWithRole procedure Improved the CreateUserWithRole stored procedure in the auth-db. All new users are now automatically assigned the 'PIC-SURE User' role in addition to specific roles designated during account creation. This ensures all users have access to the base level of functionalities.
1 parent 9c5234b commit 5e1088e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed
 

‎pic-sure-auth-db/db/sql/V4__ADD_CREATE_USER_STORED_PROCEDURE.sql

+21-10
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,42 @@ USE `auth`;
22

33
DROP PROCEDURE IF EXISTS CreateUserWithRole;
44
DELIMITER //
5-
CREATE PROCEDURE CreateUserWithRole (
5+
CREATE PROCEDURE CreateUserWithRole(
66
IN user_email VARCHAR(255),
77
IN connection_id VARCHAR(255),
88
IN role_name VARCHAR(255),
99
IN user_general_metadata varchar(255)
1010
)
1111
BEGIN
1212
-- Attempt to retrieve the UUIDs for the user and role based on the provided information
13-
SELECT @userUUID := uuid FROM auth.user WHERE email = user_email AND connectionId = connection_id;
14-
SELECT @roleUUID := uuid FROM auth.role WHERE name = role_name;
13+
SELECT @userUUID := uuid FROM auth.user WHERE email = user_email AND connectionId = connection_id;
14+
SELECT @roleUUID := uuid FROM auth.role WHERE name = role_name;
15+
SELECT @picsureUserRoleId := uuid FROM auth.role WHERE name = 'PIC-SURE User';
1516

1617
-- If the user does not exist, create a new user entry
17-
IF @userUUID IS NULL THEN
18+
IF @userUUID IS NULL THEN
19+
set @baseUUID = UUID();
1820
-- Generate a new UUID for the user
19-
SET @userUUID = UNHEX(REPLACE(UUID(), '-', ''));
21+
SET @userUUID = UNHEX(REPLACE(@baseUUID, '-', ''));
2022
-- Retrieve the UUID for the connection
21-
SELECT @connectionUUID := uuid FROM auth.connection WHERE id = connection_id;
23+
SELECT @connectionUUID := uuid FROM auth.connection WHERE id = connection_id;
24+
SELECT @connectionSubPrefix := subPrefix FROM auth.connection WHERE id = connection_id;
2225
-- Insert the new user record into the user table
23-
INSERT INTO auth.user (uuid, general_metadata, acceptedTOS, connectionId, email, matched, subject, is_active, long_term_token)
24-
VALUES (@userUUID, user_general_metadata, CURRENT_TIMESTAMP, @connectionUUID, user_email, 0, NULL, 1, NULL);
25-
END IF;
26+
INSERT INTO auth.user (uuid, general_metadata, acceptedTOS, connectionId, email, matched, subject, is_active,
27+
long_term_token)
28+
VALUES (@userUUID, user_general_metadata, CURRENT_TIMESTAMP, @connectionUUID, user_email, 0,
29+
concat(@connectionSubPrefix, REPLACE(@baseUUID, '-', '')), 1, NULL);
30+
END IF;
2631

2732
-- If the role exists, associate the user with the role
2833
IF @roleUUID IS NOT NULL THEN
2934
INSERT INTO auth.user_role (user_id, role_id) VALUES (@userUUID, @roleUUID);
30-
END IF;
35+
END IF;
36+
37+
-- If the role is not PIC-SURE User, associate the user with the PIC-SURE User role as well
38+
-- All users must have the PIC-SURE User role
39+
IF @roleUUID IS NOT NULL AND @roleUUID != @picsureUserRoleId THEN
40+
INSERT INTO auth.user_role (user_id, role_id) VALUES (@userUUID, @picsureUserRoleId);
41+
END IF;
3142
END//
3243
DELIMITER ;

0 commit comments

Comments
 (0)
Please sign in to comment.