Skip to content

Commit d9af9bd

Browse files
fix SQL syntax erros and target 419 (#10273)
1 parent b93589b commit d9af9bd

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`;
19+
20+
CREATE PROCEDURE `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION` (
21+
IN role VARCHAR(255),
22+
IN rule VARCHAR(255),
23+
IN permission VARCHAR(255)
24+
)
25+
BEGIN
26+
DECLARE role_id BIGINT(20) UNSIGNED
27+
; DECLARE max_sort_order BIGINT(20) UNSIGNED
28+
29+
; SELECT `r`.`id` INTO role_id
30+
FROM `cloud`.`roles` `r`
31+
WHERE `r`.`name` = role
32+
AND `r`.`is_default` = 1
33+
34+
; SELECT MAX(`rp`.`sort_order`) INTO max_sort_order
35+
FROM `cloud`.`role_permissions` `rp`
36+
WHERE `rp`.`role_id` = role_id
37+
38+
; IF NOT EXISTS (
39+
SELECT * FROM `cloud`.`role_permissions` `rp`
40+
WHERE `rp`.`role_id` = role_id
41+
AND `rp`.`rule` = rule
42+
) THEN
43+
UPDATE `cloud`.`role_permissions` `rp`
44+
SET `rp`.`sort_order` = max_sort_order + 1
45+
WHERE `rp`.`sort_order` = max_sort_order
46+
AND `rp`.`role_id` = role_id
47+
48+
; INSERT INTO `cloud`.`role_permissions`
49+
(uuid, role_id, rule, permission, sort_order)
50+
VALUES (uuid(), role_id, rule, permission, max_sort_order)
51+
; END IF
52+
;END;

engine/schema/src/main/resources/META-INF/db/schema-41910to41920.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@
2121

2222
-- Add last_id to the volumes table
2323
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes', 'last_id', 'bigint(20) unsigned DEFAULT NULL');
24+
25+
-- Grant access to 2FA APIs for the "Read-Only User - Default" role
26+
27+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Read-Only User - Default', 'setupUserTwoFactorAuthentication', 'ALLOW');
28+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Read-Only User - Default', 'validateUserTwoFactorAuthenticationCode', 'ALLOW');
29+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Read-Only User - Default', 'listUserTwoFactorAuthenticatorProviders', 'ALLOW');
30+
31+
-- Grant access to 2FA APIs for the "Support User - Default" role
32+
33+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Support User - Default', 'setupUserTwoFactorAuthentication', 'ALLOW');
34+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Support User - Default', 'validateUserTwoFactorAuthenticationCode', 'ALLOW');
35+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Support User - Default', 'listUserTwoFactorAuthenticatorProviders', 'ALLOW');
36+
37+
-- Grant access to 2FA APIs for the "Read-Only Admin - Default" role
38+
39+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Read-Only Admin - Default', 'setupUserTwoFactorAuthentication', 'ALLOW');
40+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Read-Only Admin - Default', 'validateUserTwoFactorAuthenticationCode', 'ALLOW');
41+
42+
-- Grant access to 2FA APIs for the "Support Admin - Default" role
43+
44+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Support Admin - Default', 'setupUserTwoFactorAuthentication', 'ALLOW');
45+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Support Admin - Default', 'validateUserTwoFactorAuthenticationCode', 'ALLOW');

0 commit comments

Comments
 (0)