Skip to content

Commit 809e97f

Browse files
committed
Use maybe syntax for super stream management permissions
1 parent 043ddcb commit 809e97f

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

deps/rabbitmq_stream/src/rabbit_stream_utils.erl

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
-module(rabbit_stream_utils).
1818

19+
-feature(maybe_expr, enable).
20+
1921
%% API
2022
-export([enforce_correct_name/1,
2123
write_messages/5,
@@ -202,32 +204,20 @@ check_read_permitted(Resource, User, Context) ->
202204

203205
check_super_stream_management_permitted(VirtualHost, SuperStream, Partitions, User) ->
204206
Exchange = e(VirtualHost, SuperStream),
205-
%% exchange creation
206-
case check_configure_permitted(Exchange, User) of
207-
ok ->
208-
%% stream creations
209-
case check_streams_permissions(fun check_configure_permitted/2,
210-
VirtualHost, Partitions,
211-
User) of
212-
ok ->
213-
%% binding from exchange
214-
case check_read_permitted(Exchange, User, #{}) of
215-
ok ->
216-
%% binding to streams
217-
case check_streams_permissions(fun check_write_permitted/2,
218-
VirtualHost, Partitions,
219-
User) of
220-
ok ->
221-
ok;
222-
_ ->
223-
error
224-
end;
225-
_ ->
226-
error
227-
end;
228-
_ ->
229-
error
230-
end;
207+
maybe
208+
%% exchange creation
209+
ok ?= check_configure_permitted(Exchange, User),
210+
%% stream creations
211+
ok ?= check_streams_permissions(fun check_configure_permitted/2,
212+
VirtualHost, Partitions,
213+
User),
214+
%% binding from exchange
215+
ok ?= check_read_permitted(Exchange, User, #{}),
216+
%% binding to streams
217+
ok ?= check_streams_permissions(fun check_write_permitted/2,
218+
VirtualHost, Partitions,
219+
User)
220+
else
231221
_ ->
232222
error
233223
end.
@@ -347,10 +337,7 @@ filtering_supported() ->
347337
rabbit_feature_flags:is_enabled(stream_filtering).
348338

349339
q(VirtualHost, Name) ->
350-
r(VirtualHost, Name, queue).
340+
rabbit_misc:r(VirtualHost, queue, Name).
351341

352342
e(VirtualHost, Name) ->
353-
r(VirtualHost, Name, exchange).
354-
355-
r(VirtualHost, Name, Kind) when Kind =:= exchange orelse Kind =:= queue ->
356-
#resource{virtual_host = VirtualHost, name = Name, kind = Kind}.
343+
rabbit_misc:r(VirtualHost, exchange, Name).

0 commit comments

Comments
 (0)