Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Greenlight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arbeitsgruppe Hardwarenahe IT-Systeme
Greenlight
Commits
bebe607d
Unverified
Commit
bebe607d
authored
Feb 2, 2023
by
Khemissi Amir
Committed by
GitHub
Feb 2, 2023
Browse files
Options
Downloads
Patches
Plain Diff
V3 Migrations: Optimized `Migrations::ExternalController::create_role` API. (#4720)
parent
f72af5e9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/controllers/api/v1/migrations/external_controller.rb
+13
-8
13 additions, 8 deletions
app/controllers/api/v1/migrations/external_controller.rb
with
13 additions
and
8 deletions
app/controllers/api/v1/migrations/external_controller.rb
+
13
−
8
View file @
bebe607d
...
@@ -39,13 +39,16 @@ module Api
...
@@ -39,13 +39,16 @@ module Api
return
render_data
status: :created
unless
role_hash
[
:role_permissions
].
any?
return
render_data
status: :created
unless
role_hash
[
:role_permissions
].
any?
# Finds all the RolePermissions that need to be updated
# Finds all the RolePermissions that need to be updated
role_permissions_
temp
=
RolePermission
.
includes
(
:permission
)
role_permissions_
joined
=
RolePermission
.
includes
(
:permission
)
.
where
(
role_id:
role
.
id
,
'permissions.name'
:
role_hash
[
:role_permissions
].
keys
)
.
where
(
role_id:
role
.
id
,
'permissions.name'
:
role_hash
[
:role_permissions
].
keys
)
.
pluck
(
:id
,
:'permissions.name'
)
.
to_h
okay
=
true
# Re-structure the data so it is in the format: { <role_permission_id>: { value: <role_permission_new_value> } }
role_permissions_joined
.
each
do
|
role_permission
|
role_permissions
=
role_permissions_temp
.
transform_values
{
|
v
|
{
value:
role_hash
[
:role_permissions
][
v
.
to_sym
]
}
}
permission_name
=
role_permission
.
permission
.
name
RolePermission
.
update!
(
role_permissions
.
keys
,
role_permissions
.
values
)
okay
=
false
unless
role_permission
.
update
(
value:
role_hash
[
:role_permissions
][
permission_name
])
end
return
render_error
status: :bad_request
,
errors:
'Something went wrong when migrating the role permissions.'
unless
okay
render_data
status: :created
render_data
status: :created
end
end
...
@@ -159,7 +162,9 @@ module Api
...
@@ -159,7 +162,9 @@ module Api
private
private
def
role_params
def
role_params
decrypted_params
.
require
(
:role
).
permit
(
:name
,
role_permissions:
{})
decrypted_params
.
require
(
:role
).
permit
(
:name
,
role_permissions:
%w[CreateRoom CanRecord ManageUsers ManageRoles ManageRooms ManageRecordings
ManageSiteSettings]
)
end
end
def
user_params
def
user_params
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment