Skip to content

Commit

Permalink
Auto-confirm Demo Accounts (#2398)
Browse files Browse the repository at this point in the history
* Autoconfirm demo users

* Fix alias order

* Update CHANGELOG.md
  • Loading branch information
elias-ba authored Aug 17, 2024
1 parent 0be4f3e commit d1f8c45
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ and this project adheres to

### Changed

- Ensure that all the demo accounts are confirmed by default
[#2395](https://github.com/OpenFn/lightning/issues/2395)

### Fixed

## [v2.7.17] - 2024-08-14
Expand Down
22 changes: 21 additions & 1 deletion lib/lightning/setup_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Lightning.SetupUtils do
import Ecto.Changeset

alias Lightning.Accounts
alias Lightning.Accounts.User
alias Lightning.Credentials
alias Lightning.Jobs
alias Lightning.Projects
Expand Down Expand Up @@ -49,7 +50,7 @@ defmodule Lightning.SetupUtils do
"""
def setup_demo(opts \\ [create_super: false]) do
%{super_user: super_user, admin: admin, editor: editor, viewer: viewer} =
create_users(opts)
create_users(opts) |> confirm_users()

%{
project: openhie_project,
Expand Down Expand Up @@ -164,6 +165,25 @@ defmodule Lightning.SetupUtils do
%{super_user: super_user, admin: admin, editor: editor, viewer: viewer}
end

def confirm_users(users) do
confirm_user = fn user ->
case user do
nil ->
:ok

_ ->
User.confirm_changeset(user)
|> Repo.update!()
end
end

users
|> Map.values()
|> Enum.each(confirm_user)

users
end

def create_starter_project(name, project_users) do
{:ok, project} =
Projects.create_project(
Expand Down

0 comments on commit d1f8c45

Please sign in to comment.