Skip to content

Commit 7cf2ead

Browse files
committed
create groups schema for #220
1 parent 997cc36 commit 7cf2ead

File tree

7 files changed

+98
-19
lines changed

7 files changed

+98
-19
lines changed

BUILDIT.md

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,27 @@ to invite others
3737
to ***collaborate***.
3838

3939
Our reasoning to include **`groups`**
40-
in the **`auth`** App is that
41-
we _already_ store all **`people`** related
40+
in the **`auth`** App
41+
is that it _already_ stores all **`people`** related
4242
(_personally identifiable_) data
43-
in **`auth`** therefore _grouping_
43+
in therefore _grouping_
4444
those **`people`** together makes logical sense.
45-
Therefore this is a **_generalised_ implementation**
45+
This is a **_generalised_ implementation**
4646
that can be used by **_any_ application**
4747
that requires collaboration/teamwork.
4848

4949
## 10.1 Create Schema
5050

51+
First we need to create a new schema for storing the data.
52+
5153
Run the folloiwng
5254
[**`mix phx.gen.schema`**](https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Schema.html)
5355
command to create the `groups` schema
5456
as outlined in
5557
[**`#220`**](https://github.com/dwyl/auth/issues/220)
5658

5759
```sh
58-
mix phx.gen.schema Group groups name:binary desc:binary kind:string
60+
mix phx.gen.schema Group groups name:binary desc:binary kind:integer
5961
```
6062

6163
Both `group.name` and `group.desc` (description)
@@ -64,7 +66,46 @@ hence using the `binary` type in the `gen.schema` command.
6466
The data for these fields will be encrypted at rest using
6567
[`Fields.Encrypted`](https://github.com/dwyl/fields).
6668

67-
## 10.2 Create `LiveView` for `groups`
69+
The `group.kind` will be the way people _categorise_
70+
their various groups. It will be an `Enum`
71+
and therefore the `integer` will be stored in the DB.
72+
73+
74+
## 10.2 _Test_ Groups Schema
75+
76+
Having created the Groups Schema + Migration in the previous step,
77+
it created a new file:
78+
`lib/auth/group.ex`
79+
80+
If we run the coverage report with the command: `mix c`
81+
82+
We see that there are no tests for the code in the `group.ex` file:
83+
84+
```sh
85+
86+
Randomized with seed 366521
87+
----------------
88+
COV FILE LINES RELEVANT MISSED
89+
100.0% lib/auth.ex 9 0 0
90+
100.0% lib/auth/apikey.ex 105 15 0
91+
100.0% lib/auth/app.ex 158 17 0
92+
100.0% lib/auth/email.ex 41 7 0
93+
0.0% lib/auth/group.ex 19 2 2 <-- This!
94+
100.0% lib/auth/init/init.ex 124 26 0
95+
...
96+
100.0% lib/auth_web/views/layout_view.ex 3 0 0
97+
100.0% lib/auth_web/views/people_view.ex 35 7 0
98+
100.0% lib/auth_web/views/permission_view.ex 3 0 0
99+
100.0% lib/auth_web/views/role_view.ex 10 3 0
100+
[TOTAL] 99.3%
101+
----------------
102+
```
103+
104+
That's what we are fixing now.
105+
106+
107+
108+
## 10.3 Create `LiveView` for `groups`
68109

69110
Create the `lib/auth_web/live` directory
70111
and the controller at `lib/auth_web/live/groups_live.ex`:
@@ -113,7 +154,7 @@ update the contents of the `<body>` to:
113154
</body>
114155
```
115156

116-
## 1.5 Update `router.ex`
157+
## 10.4 Update `router.ex`
117158

118159
Now that you've created the necessary files,
119160
open the router
@@ -140,7 +181,7 @@ you should see the following:
140181

141182
![liveveiw-page-with-tailwind-style](https://user-images.githubusercontent.com/194400/176137805-34467c88-add2-487f-9593-931d0314df62.png)
142183

143-
## 1.6 Update Tests
184+
## 10.5 Update Tests
144185

145186
At this point we have made a few changes
146187
that mean our automated test suite will no longer pass ...
@@ -204,3 +245,10 @@ Finished in 0.1 seconds (0.08s async, 0.1s sync)
204245

205246
Randomized with seed 796477
206247
```
248+
249+
250+
251+
252+
## 10.6 Group _Members_
253+
254+
Now that we have groups

lib/auth/group.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule Auth.Group do
2+
use Ecto.Schema
3+
import Ecto.Changeset
4+
5+
schema "groups" do
6+
field :desc, :binary
7+
field :kind, :integer
8+
field :name, :binary
9+
10+
timestamps()
11+
end
12+
13+
@doc false
14+
def changeset(group, attrs) do
15+
group
16+
|> cast(attrs, [:name, :desc, :kind])
17+
|> validate_required([:name, :desc, :kind])
18+
end
19+
end
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
<body>
2-
<header>
3-
<section class="container">
4-
<h1>Your App Name Here</h1>
5-
</section>
6-
</header>
72
<%= @inner_content %>
83
</body>

lib/auth_web/templates/layout/nav.html.eex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<li class="pl5 pl6-m di-l tl pb2-m">
2828
<a href="/roles" class="white link">Roles</a>
2929
</li>
30+
31+
<li class="pl5 pl6-m di-l tl pb2-m">
32+
<a href="/groups" class="white link">Groups</a>
33+
</li>
3034
<% end %>
3135

3236
<%= if Map.has_key?(@conn.assigns, :person) do %>

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ defmodule Auth.Mixfile do
116116
# See the documentation for `Mix` for more info on aliases.
117117
defp aliases do
118118
[
119+
"assets.deploy": ["esbuild default --minify", "phx.digest"],
119120
c: ["coveralls.html"],
120121
"ecto.setup": ["ecto.create --quiet", "ecto.migrate --quiet", "seeds"],
121122
"ecto.reset": ["ecto.drop", "ecto.setup"],
122123
seeds: ["run priv/repo/seeds.exs"],
124+
s: ["phx.server"],
123125
test: ["ecto.reset", "test"],
124-
"assets.deploy": ["esbuild default --minify", "phx.digest"],
125-
s: ["phx.server"]
126126
]
127127
end
128128

mix.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@
4242
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
4343
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
4444
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
45-
"mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
45+
"mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"},
4646
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
4747
"mochiweb": {:hex, :mochiweb, "2.22.0", "f104d6747c01a330c38613561977e565b788b9170055c5241ac9dd6e4617cba5", [:rebar3], [], "hexpm", "cbbd1fd315d283c576d1c8a13e0738f6dafb63dc840611249608697502a07655"},
4848
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
4949
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
50-
"phoenix": {:hex, :phoenix, "1.6.11", "29f3c0fd12fa1fc4d4b05e341578e55bc78d96ea83a022587a7e276884d397e4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1664e34f80c25ea4918fbadd957f491225ef601c0e00b4e644b1a772864bfbc2"},
50+
"phoenix": {:hex, :phoenix, "1.6.14", "57678366dc1d5bad49832a0fc7f12c2830c10d3eacfad681bfe9602cd4445f04", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d48c0da00b3d4cd1aad6055387917491af9f6e1f1e96cedf6c6b7998df9dba26"},
5151
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"},
5252
"phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"},
5353
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"},
54-
"phoenix_live_view": {:hex, :phoenix_live_view, "0.17.11", "205f6aa5405648c76f2abcd57716f42fc07d8f21dd8ea7b262dd12b324b50c95", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7177791944b7f90ed18f5935a6a5f07f760b36f7b3bdfb9d28c57440a3c43f99"},
54+
"phoenix_live_view": {:hex, :phoenix_live_view, "0.18.2", "635cf07de947235deb030cd6b776c71a3b790ab04cebf526aa8c879fe17c7784", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6 or ~> 1.7", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "da287a77327e996cc166e4c440c3ad5ab33ccdb151b91c793209b39ebbce5b75"},
5555
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"},
5656
"phoenix_view": {:hex, :phoenix_view, "1.1.2", "1b82764a065fb41051637872c7bd07ed2fdb6f5c3bd89684d4dca6e10115c95a", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "7ae90ad27b09091266f6adbb61e1d2516a7c3d7062c6789d46a7554ec40f3a56"},
5757
"ping": {:hex, :ping, "1.1.0", "088a2e3356dc2a0f4b4b6b1dd50b08e108f31b0ea8058f20e621e0de27281415", [:mix], [{:plug, "~> 1.12.1", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "e05403a9fc8878e17e4b206fdaa77465c6b7fc4b9cc4dc3179dd3a93f39644b3"},
5858
"plug": {:hex, :plug, "1.12.1", "645678c800601d8d9f27ad1aebba1fdb9ce5b2623ddb961a074da0b96c35187d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d57e799a777bc20494b784966dc5fbda91eb4a09f571f76545b72a634ce0d30b"},
5959
"plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"},
60-
"plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
60+
"plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"},
6161
"postgrex": {:hex, :postgrex, "0.16.2", "0f83198d0e73a36e8d716b90f45f3bde75b5eebf4ade4f43fa1f88c90a812f74", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "a9ea589754d9d4d076121090662b7afe155b374897a6550eb288f11d755acfa0"},
6262
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
6363
"rbac": {:hex, :rbac, "0.7.2", "3849d8428774e6d082fcb77b5c96c41257a21b03cf658ded582013fa967e44a2", [:mix], [{:auth_plug, "~> 1.4", [hex: :auth_plug, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.8.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.3.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "526bf9e2c8391453d5e93c9a97f47e29715920b7851979663ecf6f138e9b3a74"},
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule Auth.Repo.Migrations.CreateGroups do
2+
use Ecto.Migration
3+
4+
def change do
5+
create table(:groups) do
6+
add :name, :binary
7+
add :desc, :binary
8+
add :kind, :integer
9+
10+
timestamps()
11+
end
12+
end
13+
end

0 commit comments

Comments
 (0)