gpt4 book ai didi

erlang - 如何在面向文档的系统中处理经过身份验证的用户对资源的访问?

转载 作者:行者123 更新时间:2023-12-02 05:14:23 24 4
gpt4 key购买 nike

我正在开发一个面向文档的应用程序,需要管理用户对文档的访问。我有一个处理用户身份验证的模块,另一个处理数据存储上的文档 CRUD 操作的模块。一旦用户通过身份验证,我需要根据用户的权限强制执行用户可以和不能对文档执行的操作。我能想到的将这两个部分集成在一起的最佳选择是创建另一个模块来复制数据 API,但也将经过身份验证的用户作为参数。该模块会将授权检查委托(delegate)给 auth 模块,并将文档操作委托(delegate)给数据访问模块。像这样的东西:

 -module(auth_data_access).

% User is authenticated (logged into the system)
% save_doc validates if user is allowed to save the given document and if so
% saves it returning ok, else returns {error, permission_denied}
save_doc(Doc, User) ->
case auth:save_allowed(Doc, User) of
ok ->
data_access:save_doc(Doc);
denied ->
{error, permission_denied}
end
end.

我有更好的方法来处理这个问题吗?

最佳答案

根据我的answer to "How do I elegantly check many conditions in Erlang"我更喜欢类似的东西

save_doc(Doc, User) ->
ok = auth:save_allowed(Doc, User),
data_access:save_doc(Doc).

关于erlang - 如何在面向文档的系统中处理经过身份验证的用户对资源的访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2046557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com