Skip to content

Commit

Permalink
refactor transform_role_list_to_string/1 to use Enum.map_join suggest…
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Aug 21, 2020
1 parent a4d4d87 commit b165ef6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ should learn about RBAC.

### Installation

The package can be installed
by adding `rbac` to your list of dependencies in `mix.exs`:
Install by adding `rbac` to your list of dependencies in `mix.exs`:

```elixir
def deps do
Expand Down
5 changes: 1 addition & 4 deletions lib/rbac.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ defmodule RBAC do
"""
def transform_role_list_to_string(role_list) do
for i <- role_list do
i.id |> Integer.to_string
end
|> Enum.join(",")
Enum.map_join(role_list, ",", &(&1.id))

This comment has been minimized.

Copy link
@th0mas

th0mas Aug 21, 2020

Collaborator

Is there a reason of using a map list instead of a keyword list?

This comment has been minimized.

Copy link
@nelsonic

nelsonic Aug 21, 2020

Author Member

@th0mas good question.
I was just trying to proactively minimise the data sent over the wire.
Happy for any suggestions for improvement.
Note: the way roles are represented in the conn.assigns.person and JWT will not matter once we have RBAC.has_role/2. Any app using RBAC will need to grab the list of roles during App boot #3 in order to ensure that we have the correct list for the given app. 💭

This comment has been minimized.

Copy link
@nelsonic

nelsonic Aug 21, 2020

Author Member

Sample:

conn.assigns.person: %{
  aud: "Joken",
  auth_provider: "google",
  email: "[email protected]",
  exp: 1629582005,
  givenName: "Nelson",
  iat: 1598045005,
  id: 1,
  iss: "Joken",
  jti: "2ommatp3m7qoguuoik000002",
  nbf: 1598045005,
  picture: "https://lh3.googleusercontent.com/a-/AOh14GhaNpCI3Px_VuIC8GkRuCY",
  roles: "1,8,42",
  status: 1
}
end
end

0 comments on commit b165ef6

Please sign in to comment.