Coverage report for Casbin.Effect.
Generated at 18/02/2019 12:10:19 by DelphiCodeCoverage - an open source tool for Delphi Code Coverage.
Statistics for Casbin.Effect.pas
| Number of lines covered | 31 |
| Number of lines with code gen | 31 |
| Line coverage | 100% |
| 1 | // Copyright 2018 by John Kouraklis and Contributors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | unit Casbin.Effect; |
| 15 | |
| 16 | interface |
| 17 | |
| 18 | uses |
| 19 | Casbin.Effect.Types; |
| 20 | |
| 21 | function mergeEffects(const aEffectCondition: TEffectCondition; |
| 22 | const aEffects: TEffectArray): Boolean; |
| 23 | |
| 24 | implementation |
| 25 | |
| 26 | uses |
| 27 | System.SysUtils, Casbin.Exception.Types; |
| 28 | |
| 29 | function mergeEffects(const aEffectCondition: TEffectCondition; |
| 30 | const aEffects: TEffectArray): Boolean; |
| 31 | var |
| 32 | effect: TEffectResult; |
| 33 | begin |
| 34 | Result:=True; |
| 35 | case aEffectCondition of |
| 36 | ecSomeAllow: begin |
| 37 | Result:=False; |
| 38 | for effect in aEffects do |
| 39 | begin |
| 40 | if effect = erAllow then |
| 41 | begin |
| 42 | Result:=True; |
| 43 | Exit; |
| 44 | end; |
| 45 | end; |
| 46 | end; |
| 47 | |
| 48 | ecNotSomeDeny: begin |
| 49 | Result:=True; |
| 50 | for effect in aEffects do |
| 51 | begin |
| 52 | if effect = erDeny then |
| 53 | begin |
| 54 | Result:=false; |
| 55 | Exit; |
| 56 | end; |
| 57 | end; |
| 58 | end; |
| 59 | |
| 60 | ecSomeAllowANDNotDeny: begin |
| 61 | Result:=False; |
| 62 | for effect in aEffects do |
| 63 | begin |
| 64 | if effect = erAllow then |
| 65 | Result:=True |
| 66 | else |
| 67 | if effect = erDeny then |
| 68 | begin |
| 69 | Result:=false; |
| 70 | Exit; |
| 71 | end; |
| 72 | end; |
| 73 | end; |
| 74 | |
| 75 | ecPriorityORDeny: begin |
| 76 | Result:=False; |
| 77 | for effect in aEffects do |
| 78 | begin |
| 79 | if effect <> erIndeterminate then |
| 80 | begin |
| 81 | Result:= effect = erAllow; |
| 82 | Exit; |
| 83 | end; |
| 84 | end; |
| 85 | end; |
| 86 | |
| 87 | ecUnknown: raise ECasbinException.Create('Unknown effector'); |
| 88 | end; |
| 89 | end; |
| 90 | |
| 91 | end. |