aboutsummaryrefslogtreecommitdiff
path: root/lib/permissions.nom
blob: a65fb6798eaf9cf60f95db747fa7786e24a94702 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require "lib/metaprogramming.nom"
require "lib/control_flow.nom"
require "lib/operators.nom"
require "lib/collections.nom"

# Permission functions
rule (standardize rules %rules) =:
    if (lua expr "type(vars.rules) == 'string'"): %rules = [%rules]
    (nomsu "get_stub" [%]) for all %rules
rule (restrict %rules to within %elite-rules) =:
    %rules =: standardize rules %rules
    %elite-rules =: standardize rules %elite-rules
    say "Restricting \(%rules) to within \(%elite-rules)"
    for all (flatten [%elite-rules, %rules]):
        assert ((nomsu's "defs") has key %) "Undefined function: \(%)"
    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
    say "Allowing \(%elite-rules) to use \(%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
    say "Forbidding \(%pleb-rules) to use \(%rules)"
    for all (flatten [%pleb-rules, %used]):
        assert ((nomsu's "defs") has key %) "Undefined function: \(%)"
    for all %rules:
        assert (nomsu "check_permission" [%]) ".."
            |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)