| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-12-15 11:21:19 +0100 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-12-15 11:21:19 +0100 | 
| commit | 5247072964e0d827868a3cab5baad23938f15f41 (patch) | |
| tree | 3a5680b03bec2e4685acba18d4321883b12e6056 /src/ataxia_lock.erl | |
| parent | 503bb83db31fa64b066c88c65ac17c0cec7a445f (diff) | |
...
Diffstat (limited to 'src/ataxia_lock.erl')
| -rw-r--r-- | src/ataxia_lock.erl | 62 | 
1 files changed, 62 insertions, 0 deletions
| diff --git a/src/ataxia_lock.erl b/src/ataxia_lock.erl new file mode 100644 index 0000000..b6ce2c6 --- /dev/null +++ b/src/ataxia_lock.erl @@ -0,0 +1,62 @@ +-module(ataxia_lock). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-type status() :: none | locked. + +-record +( +   lock, +   { +      status :: status(), +      permission :: ataxia_security:permission(), +      time :: ataxia_time:type() +   } +). + +-type type() :: #lock{}. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export_type([type/0]). + +-export([locked/2, unlocked/0, allows/2]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec locked (ataxia_security:user(), ataxia_time:type()) -> type(). +locked (User, Time) -> +   #lock +   { +      status = locked, +      permission = ataxia_security:allow_only(User), +      time = ataxia_time:add(ataxia_time:now(), Time) +   }. + +-spec unlocked () -> type(). +unlocked () -> +   #lock +   { +      status = none, +      permission = ataxia_security:allow_only(ataxia_security:any()), +      time = ataxia_time:now() +   }. + +-spec allows (ataxia_security:user(), type()) -> boolean(). +allows (User, Lock) -> +   case Lock#lock.status of +      none -> true; +      locked -> +         ( +            ataxia_security:can_access(Lock#lock.permission, User) +            or ataxia_time:is_past(Lock#lock.time) +         ) +   end. + | 


