Can we restrict the deletion of a user from database based on his email address in Repo.delete!(changeset) condition in elixir and phoenix web development
This is right now the code which I am using. I want to restrict the deletion of two users from database during deletion:-
def delete(conn, _params, current_admin) do
changeset = AdminUser.common_changeset(conn.assigns.admin_user, %{}, whodoneit(current_admin))
Repo.delete!(changeset)
msg = gettext("%{name} deleted successfully", name: gettext("Administrator"))
conn
|> put_flash(:success, msg)
|> redirect(to: Routes.admin_admin_user_path(conn, :index))
end
I want to restrict the deletion of users with email ids say 'test1@gmail.com' and 'test2@gmail.com'. But I am not sure how to use this in changeset.
Thanks for respondingā¦
Here is my query condition
query = Repo.all(from u in AdminUser, where: u.email == ātest1@gmail.comā or u.email == ātest2@gmail.comā).
The deletion wonāt happen if the changeset isnāt valid, so make sure either of those emails renders it invalid (Ecto.Changeset ā Ecto v3.11.1). Or is there something more to it Iām missing?