PR: Docs
Busy adding some docs ... π¨βπ» β³
- [x] Add a couple of new tests https://github.com/dwyl/auth/issues/230
- [x] Add sample
peoplefor testinggroupsonlocalhost#242
Codecov Report
Merging #231 (2bbba99) into main (6415642) will not change coverage. The diff coverage is
100.00%.
@@ Coverage Diff @@
## main #231 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 27 14 -13
Lines 586 190 -396
==========================================
- Hits 586 190 -396
| Impacted Files | Coverage Ξ | |
|---|---|---|
| lib/auth/accounts.ex | 100.00% <100.00%> (ΓΈ) |
|
| lib/auth/accounts/person.ex | 100.00% <100.00%> (ΓΈ) |
|
| lib/auth/accounts/person_notifier.ex | 100.00% <100.00%> (ΓΈ) |
|
| lib/auth/accounts/person_token.ex | 100.00% <100.00%> (ΓΈ) |
|
| lib/auth_web/controllers/error_html.ex | 100.00% <100.00%> (ΓΈ) |
|
| lib/auth_web/controllers/error_json.ex | 100.00% <100.00%> (ΓΈ) |
|
| lib/auth_web/controllers/page_controller.ex | 100.00% <100.00%> (ΓΈ) |
|
| ..._web/controllers/person_confirmation_controller.ex | 100.00% <100.00%> (ΓΈ) |
|
| ..._web/controllers/person_registration_controller.ex | 100.00% <100.00%> (ΓΈ) |
|
| ...eb/controllers/person_reset_password_controller.ex | 100.00% <100.00%> (ΓΈ) |
|
| ... and 29 more |
:mega: Weβre building smart automated test selection to slash your CI/CD build times. Learn more
Build failing due to:
** (ErlangError) Erlang error: {:badarg, {'aead.c', 90}, 'Unknown cipher'}
(crypto 5.0.2) :crypto.aead_cipher_nif(:aes_256_gcm, "",
<<164, 15, 193, 21, 34, 216, 157, 59, 173, 102, 0, 45, 69, 112, 115, 87>>,
"[email protected]", "AES256GCM", 16, true)
(fields 2.8.2) lib/aes.ex:36: Fields.AES.encrypt/1
Looks like this is an issue with Fields not shipping the latest version of the AES cypher ...
https://github.com/dwyl/auth/actions/runs/3272492583/jobs/5383565807

BRB!
Oh oh ... looks like the auth Repository secrets were removed ... π€·ββοΈ
https://github.com/dwyl/auth/settings/secrets/actions

Lame! π€¦ββοΈ
Re-adding them now. β³
Ref: https://github.com/dwyl/auth/blob/f6a72102fd72f99ba8c42d00083e22c2fdec917a/.github/workflows/ci.yml#L42-L52
Re-added all the repository secrets ...

Can of worms: https://github.com/dwyl/learn-elixir/issues/182#issuecomment-1282630190 π€¦ββοΈ
Tests still failing on CI ... https://github.com/dwyl/auth/actions/runs/3276606455/jobs/5392858413

The good (? π€·ββοΈ ) news is that they are also failing on my localhost ...
This is less interesting than working on features ...
But given that it's BLOCKED progress, it's my priority for the morning ... β³
@LuchoTurtle I'm picking off each failing test at a time to fix them all. It's probably going to take a while ... β
You're very welcome to join me and pair on this ... π
But if you have something more interesting to work on, Stick to that. π
Still working on this one ... β³
Finally back to looking at this after reviewing/merging everyone else's PRs ... π€
Wish me luck! π
One to look at in the morning:
warning: undefined function live_flash/2 (expected AuthWeb.LayoutView to define such a function or for it to be imported, but none are available)
lib/auth_web/templates/layout/live.html.heex:14
live_flash with LiveView 0.18 is not part of the Phoenix.Component module, see: https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#live_flash/2
We can make sure to import this module in the view, however we'll need to change this soon with Phoenix 1.7

So in auth_web.ex in the view function, add import Phoenix.Component:
def view do
quote do
use Phoenix.View,
root: "lib/auth_web/templates",
namespace: AuthWeb
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
import Phoenix.Component
# Include shared imports and aliases for views
unquote(view_helpers())
end
end
I think this should resolve this issue. However I had a look at the mvp code for the view function and it looks quiet different. Switching to Phoenix 1.7 should reset/remove all the "ancient" genereated Phoenix code
https://github.com/dwyl/auth/blob/gen-erd-%23207/lib/auth_web.ex#L30-L43
Thanks @SimonLab π I've removed it from the layout/template as don't need the "flash" βοΈ
Trying to add Tailwind CSS to the Auth App but getting the following error when rendering the LiveView template:
[error] #PID<0.815.0> running AuthWeb.Endpoint (connection #PID<0.750.0>, stream id 7) terminated
Server: localhost:4000 (http)
Request: GET /groups
** (exit) an exception was raised:
** (KeyError) key :conn not found in: %{__changed__: %{inner_content: true}, flash: %{}, inner_content:
%Phoenix.LiveView.Rendered{static: ["<h1 class=\"bg-gradient-to-r from-green-400 to-blue-500\">\n
Groups LiveView! Hello!\n</h1>"], dynamic: #Function<0.53126927/1 in AuthWeb.GroupsLive.render/1>,
root: true, caller: :not_available}, live_action: nil, endpoint: AuthWeb.Endpoint, view: AuthWeb.GroupsLive,
parent_pid: nil, root_pid: nil, router: AuthWeb.Router, assigns: #Phoenix.LiveView.Socket.AssignsNotInSocket<>, ...>}
(auth 1.6.7) lib/auth_web/templates/layout/live.html.heex:9: anonymous fn/2 in AuthWeb.LayoutView."live.html"/1
(phoenix_live_view 0.18.2) lib/phoenix_live_view/diff.ex:387: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.18.2) lib/phoenix_live_view/diff.ex:138: Phoenix.LiveView.Diff.render/3
(phoenix_live_view 0.18.2) lib/phoenix_live_view/static.ex:244: Phoenix.LiveView.Static.to_rendered_content_tag/4
(phoenix_live_view 0.18.2) lib/phoenix_live_view/static.ex:127: Phoenix.LiveView.Static.render/3
(phoenix_live_view 0.18.2) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
(phoenix 1.6.14) lib/phoenix/router.ex:354: Phoenix.Router.__call__/2
(auth 1.6.7) lib/auth_web/endpoint.ex:1: AuthWeb.Endpoint.plug_builder_call/2
(auth 1.6.7) lib/plug/debugger.ex:136: AuthWeb.Endpoint."call (overridable 3)"/2
(auth 1.6.7) lib/auth_web/endpoint.ex:1: AuthWeb.Endpoint.call/2
(phoenix 1.6.14) lib/phoenix/endpoint/cowboy2_handler.ex:54: Phoenix.Endpoint.Cowboy2Handler.init/4
(cowboy 2.9.0) /Users/n/code/auth/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
(cowboy 2.9.0) /Users/n/code/auth/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
(cowboy 2.9.0) /Users/n/code/auth/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
(stdlib 4.1.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
This is probably obvious. Will look at it after πΆ bed time. β³
"Change mentions of @conn to @socket in live template"
Thanks to: https://smartlogic.io/blog/converting-phoenix-views-to-liveviews
Works: β

Back to documenting. βοΈ
have the following line in LiveView file:
import Phoenix.LiveView, only: [assign_new: 3]
Getting the following error in IDE:
(CompileError) cannot import Phoenix.LiveView.assign_new/3
because it is undefined or private Stacktrace: β (elixir 1.14.1)
src/elixir_import.erl:91: :elixir_import.calculate/6 β (elixir 1.14.1)
src/elixir_import.erl:22: :elixir_import.import/4Elixir
https://elixirforum.com/t/assign-and-assign-new-missing-in-liveview0-18-0-what-are-we-meant-to-use-instead/50451/2 https://github.com/phoenixframework/phoenix_live_view/blob/master/CHANGELOG.md#0180-2022-09-20
Solution: replace:
import Phoenix.LiveView, only: [assign_new: 3]
With:
import Phoenix.Component, only: [assign_new: 3]
Appears to compile. π
On re-re-re-reading my own notes I think they are confusing. π
So going to re-do the group_people schema to simplify it. β³
** (ArgumentError) expected granter_id to be an assoc in put_assoc, got: :id
[error] GenServer #PID<0.711.0> terminating
** (Ecto.ConstraintError) constraint error when attempting to insert struct:
* group_people_person_id_fkey (foreign_key_constraint)
If you would like to stop this constraint violation from raising an
exception and instead add it as an error to your changeset, please
call `foreign_key_constraint/3` on your changeset with the constraint
`:name` as an option.
The changeset has not defined any constraint.
(ecto 3.9.1) lib/ecto/repo/schema.ex:795: anonymous fn/4 in Ecto.Repo.Schema.constraints_to_errors/3
(elixir 1.14.1) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
(ecto 3.9.1) lib/ecto/repo/schema.ex:780: Ecto.Repo.Schema.constraints_to_errors/3
(ecto 3.9.1) lib/ecto/repo/schema.ex:761: Ecto.Repo.Schema.apply/4
(ecto 3.9.1) lib/ecto/repo/schema.ex:369: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
(auth 1.6.7) lib/auth_web/live/groups_live.ex:50: AuthWeb.GroupsLive.create_group/3
(auth 1.6.7) lib/auth_web/live/groups_live.ex:21: AuthWeb.GroupsLive.handle_event/3
(phoenix_live_view 0.18.2) lib/phoenix_live_view/channel.ex:382: anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3
(telemetry 1.1.0) /Users/n/code/auth/deps/telemetry/src/telemetry.erl:320: :telemetry.span/3
(phoenix_live_view 0.18.2) lib/phoenix_live_view/channel.ex:216: Phoenix.LiveView.Channel.handle_info/2
(stdlib 4.1.1) gen_server.erl:1123: :gen_server.try_dispatch/4
(stdlib 4.1.1) gen_server.erl:1200: :gen_server.handle_msg/6
(stdlib 4.1.1) proc_lib.erl:250: :proc_lib.wake_up/3
Last message: %Phoenix.Socket.Message{topic: "lv:phx-FyN1DUAVM0ykSwAE", event: "event", payload: %{"event" => "create", "type" => "form", "value" => "name=test+1217&desc=my+description"}, ref: "9", join_ref: "7"}
State: %{components: {%{}, %{}, 1}, join_ref: "7", serializer: Phoenix.Socket.V2.JSONSerializer, socket: #Phoenix.LiveView.Socket<id: "phx-FyN1DUAVM0ykSwAE", endpoint: AuthWeb.Endpoint, view: AuthWeb.GroupsLive, parent_pid: nil, root_pid: #PID<0.711.0>, router: AuthWeb.Router, assigns: %{__changed__: %{}, flash: %{}, live_action: nil, loggedin: true, person: %{app_id: 1, aud: "Joken", auth_provider: "github", email: "[email protected]", exp: 1698841911, givenName: "Nelson", iat: 1667304911, id: 2, iss: "Joken", jti: "totesmctoken", nbf: 1667304911, picture: "https://avatars.githubusercontent.com/u/194400?v=4", roles: "6,6", sid: 480, status: 1}}, transport_pid: #PID<0.700.0>, ...>, topic: "lv:phx-FyN1DUAVM0ykSwAE", upload_names: %{}, upload_pids: %{}}
Build failing because coverage is 97.4% (below the 100% requirement) ...
I'm adding tests and will be back up to 100% shortly.
No idea why I'm seeing this error:
[error] GenServer #PID<0.997.0> terminating
** (UndefinedFunctionError) function Auth.Person.fetch/2 is undefined
(Auth.Person does not implement the Access behaviour.
If you are using get_in/put_in/update_in, you can specify the field to be accessed using Access.key!/1)
(auth 1.6.7) Auth.Person.fetch(%Auth.Person{__meta__:
#Ecto.Schema.Metadata<:loaded, "people">, id: 2, auth_provider: "github", email: "[email protected]",
email_hash: <<97, 210, 231, 52, 197, 74, 245, 126, 6, 74, 101, 9, 145, 156, 56, 0, 132, >>,
familyName: nil, givenName: "Nelson", locale: "en", password: nil, password_hash: nil,
picture: "https://avatars.githubusercontent.com/u/194400?v=4", username: "nelsonic",
username_hash: nil, status: 1, tag: nil, key_id: nil, app_id: 1, github_id: 194400,
roles: [%Auth.Role{__meta__: #Ecto.Schema.Metadata<:loaded, "roles">, id: 6,
desc: "Subscribes for updates e.g. newsletter or content from a specific person.
Cannot comment until verified.",
name: "subscriber", person_id: 1, app_id: nil, inserted_at: ~N[2022-11-01 12:16:18],
updated_at: ~N[2022-11-01 12:16:18]}, %Auth.Role{__meta__: #Ecto.Schema.Metadata<:loaded, "roles">,
id: 6, desc: "Subscribes for updates e.g. newsletter or content from a specific person.
Cannot comment until verified.", name: "subscriber", person_id: 1, app_id: nil,
inserted_at: ~N[2022-11-01 12:16:18],
updated_at: ~N[2022-11-01 12:16:18]}], groups: [%Auth.Group{__meta__:
#Ecto.Schema.Metadata<:loaded, "groups">, id: 7, desc: "description", kind: 1, name:
"Simon's Group", app_id: 1, app: #Ecto.Association.NotLoaded<association :app is not loaded>,
inserted_at: ~N[2022-11-03 10:24:32], updated_at: ~N[2022-11-03 10:24:32]}], statuses: [],
inserted_at: ~N[2022-11-03 10:20:47], updated_at: ~N[2022-11-03 10:37:19]}, :id)
(elixir 1.14.1) lib/access.ex:288: Access.get/3
(auth 1.6.7) lib/auth_web/live/groups_live.ex:20: AuthWeb.GroupsLive.get_person_id/1
(auth 1.6.7) lib/auth_web/live/groups_live.ex:32: AuthWeb.GroupsLive.create_group/3
(auth 1.6.7) lib/auth_web/live/groups_live.ex:26: AuthWeb.GroupsLive.handle_event/3
(phoenix_live_view 0.18.2) lib/phoenix_live_view/channel.ex:382:
anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3
(telemetry 1.1.0) /Users/n/code/auth/deps/telemetry/src/telemetry.erl:320: :telemetry.span/3
(phoenix_live_view 0.18.2) lib/phoenix_live_view/channel.ex:216: Phoenix.LiveView.Channel.handle_info/2
(stdlib 4.1.1) gen_server.erl:1123: :gen_server.try_dispatch/4
(stdlib 4.1.1) gen_server.erl:1200: :gen_server.handle_msg/6
(stdlib 4.1.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: %Phoenix.Socket.Message{topic: "lv:phx-FyQy3KDqbQjlMgIB", event: "event",
payload: %{"event" => "create", "type" => "form", "value" => "name=amaze&desc=desc"},
ref: "6", join_ref: "4"}
State: %{components: {%{}, %{}, 1}, join_ref: "4", serializer: Phoenix.Socket.V2.JSONSerializer, socket:
inserted_at: ~N[2022-11-03 10:24:32], updated_at: ~N[2022-11-03 10:24:32]}], statuses: [],
inserted_at: ~N[2022-11-03 10:20:47], updated_at: ~N[2022-11-03 10:37:19]}},
transport_pid: #PID<0.988.0>, ...>,
topic: "lv:phx-FyQy3KDqbQjlMgIB", upload_names: %{}, upload_pids: %{}}
π€·ββοΈ
https://hexdocs.pm/elixir/Access.html
<ul class="w-full">
<%= for group <- @person.groups do %>
<li data-id={group.id} class="mt-2 flex w-full border-t border-slate-200 py-2">
<div class="text-center text-2xl"> <%= group.name %> </div>
</li>
<% end %>
</ul>
This is what I was looking for: https://elixirschool.com/blog/til-cleaner-queries-with-ecto-map !!
The ability to specify the keys of the resulting Repo.all query! π
I think somewhere in the code you called a function on person using [], e.g. person[:id] instead of person.id.
In https://hexdocs.pm/elixir/Access.html:

Because Person is a struct the only the dot syntax can be used to access fields.
Yeah, I saw those docs. And scoured the code to find the instance but couldn't.
The debug log from the Person query with the Repo.preload(:groups) was driving me nuts!
It's fetching an ocean of data just to make a tiny query. So I'm not using it. Ecto is suuuuper inefficient. π
1) test Initialize the Auth Database Delete Everything and init again! (test branches) (Auth.InitTest)
test/auth/init/init_test.exs:10
** (Ecto.ConstraintError) constraint error when attempting to delete struct:
* people_roles_granter_id_fkey (foreign_key_constraint)
If you would like to stop this constraint violation from raising an
exception and instead add it as an error to your changeset, please
call `foreign_key_constraint/3` on your changeset with the constraint
`:name` as an option.
The changeset has not defined any constraint.
code: Auth.Person.delete(person)
stacktrace:
(ecto 3.9.1) lib/ecto/repo/schema.ex:795: anonymous fn/4 in Ecto.Repo.Schema.constraints_to_errors/3
(elixir 1.14.1) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
(ecto 3.9.1) lib/ecto/repo/schema.ex:780: Ecto.Repo.Schema.constraints_to_errors/3
(ecto 3.9.1) lib/ecto/repo/schema.ex:761: Ecto.Repo.Schema.apply/4
(ecto 3.9.1) lib/ecto/repo/schema.ex:552: anonymous fn/11 in Ecto.Repo.Schema.do_delete/4
test/auth/init/init_test.exs:16: (test)
Ecto ... π€¦ββοΈ
Upgraded version of Elixir to 1.14.1 (compiled with Erlang/OTP 25)
Now getting:
1) test Initialize the Auth Database Delete Everything and init again! (test branches) (Auth.InitTest)
test/auth/init/init_test.exs:10
** (FunctionClauseError) no function clause matching in System.put_env/2
Side quest: https://github.com/dwyl/envar/issues/31
Continue: https://github.com/dwyl/auth/blob/gen-erd-%23207/BUILDIT.md#erd-before-adding-groups β³
https://github.com/dwyl/auth/actions/runs/3637982373/jobs/6139636711#step:4:748

Run erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24
Installing OTP OTP-24.3.4 - built on ubuntu-18.04
Installing Elixir v1.14.0
/home/runner/work/_temp/.setup-elixir/elixir/bin/mix local.rebar --force
/home/runner/work/_temp/.setup-elixir/otp/erts-12.3.2/bin/beam.smp: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
Error: The process '/home/runner/work/_temp/.setup-elixir/elixir/bin/mix' failed with exit code 12[7](https://github.com/dwyl/auth/actions/runs/3637982373/jobs/6139636711#step:4:8)
Going to re-run the tests and see if it's just a one-off error ... β