aboutsummaryrefslogtreecommitdiffstats
path: root/DEVNOTES.md
blob: bcdd37f5e0243038894842accc261661fdd30860 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
# Authorization Logic in Policies

## Base Rules

### ApplicationPolicy

Policies inheriting from the `ApplicationPolicy` authorize _Undestructive_ _Permissions_ whiche are `index?` and
`show?`. And forbid _Destructive_ _Permissions_ which are `create?`, `destroy?` & `update`.

These _CRUD_ permissions are tied to to _Action_ permissions, `delete?``destroy?`, `edit?``update? and `new?`→ `create?`.

These three _Action_ permissions are not supposed to be overriden in `ApplicationPolicy` subclasses.


### Common Policy Types

There are two common policy types.

#### Read Only Type Policy

This corresponds to inheriting from  `ApplicationPolicy` without overriding one of the five aforementioned _CRUD_ permissions.

The following Policies are of this type.

  - `Company`
  - `GroupOfLine`
  - `Line` + custom
  - `Network`
  - `StopArea`

#### Standard Type Policy

The standard type policy inherits from `ApplicationPolicy` does not override any _Undesructive_ _Pemission_ but overrides the _Destructive_ ones.

They are overriden as follows

```ruby
      def <destructive>?
        !referential_read_only? && organisation_match? && user.has_permission('<resource in plural form>.<action>')
      end
```

**An exception** is `Referntial` which **cannot** check for `organisation_match?` for creation as there is no referential.

The following Policies are of this type.

  - `AccessLink`
  - `AccessPoint`
  - `Calendar`
  - `ConnectionLink`
  - `JourneyPattern`
  - `Referential` + custom
  - `Route` (used by `StopPoint` too)
  - `RoutingConstraintZone`
  - `TimeTable` + custom