nomsu/lib/permissions.nom

55 lines
2.3 KiB
Plaintext
Raw Normal View History

require "lib/metaprogramming.nom"
require "lib/control_flow.nom"
require "lib/operators.nom"
require "lib/collections.nom"
# Permission functions
rule [standardize rules %rules] =:
2017-10-19 18:56:42 -07:00
if ((type of %rules) == "string"): %rules = [%rules]
%stubs = (nomsu "get_stubs" [%rules])
2017-10-19 18:56:42 -07:00
%result = []
for %stub in %stubs:
2017-10-19 18:56:42 -07:00
%def = ((nomsu's "defs")->%stub)
if %def:
%aliases = (%def's "aliases")
for all %aliases: add % to %result
..else: add %def to %result
2017-10-19 18:56:42 -07:00
unique %result
rule [restrict %rules to within %elite_rules] =:
%rules = (standardize rules %rules)
%elite_rules = (standardize rules %elite_rules)
for all (flatten [%elite_rules, %rules]):
assert ((nomsu's "defs") has key %) "Undefined function: \(%)"
2017-09-29 22:04:03 -07:00
for %rule in %rules:
assert (nomsu "check_permission" [%]) ".."
|You do not have permission to restrict permissions for function: \(%)
((nomsu) ->* ["defs",%rule,"whiteset"]) = (..)
dict ([%, yes] for all %elite_rules)
rule [allow %elite_rules to use %rules] =:
%rules = (standardize rules %rules)
%elite_rules = (standardize rules %elite_rules)
for all (flatten [%elite_rules, %rules]):
assert ((nomsu's "defs") has key %) "Undefined function: \(%)"
for %rule in %rules:
assert (nomsu "check_permission" [%rule]) ".."
|You do not have permission to grant permissions for function: \(%rule)
%whiteset = ((nomsu) ->* ["defs",%rule,"whiteset"])
if (not %whiteset): go to next %rule
for all %elite_rules: %whiteset -> % = (yes)
rule [forbid %pleb_rules to use %rules] =:
%rules = (standardize rules %rules)
%pleb_rules = (standardize rules %pleb_rules)
for all (flatten [%pleb_rules, %used]):
assert ((nomsu's "defs") has key %) "Undefined function: \(%)"
for all %rules:
assert (nomsu "check_permission" [%]) ".."
2017-09-29 22:04:03 -07:00
|You do not have permission to grant permissions for function: \(%)
%whiteset = ((nomsu) ->* ["defs",%,"whiteset"])
assert %whiteset ".."
|Cannot individually restrict permissions for \(%) because it is currently
|available to everyone. Perhaps you meant to use "restrict % to within %" instead?
for all %pleb_rules: %whiteset's % = (nil)