{"action":"closed","issue":{"url":"https://api.github.com/repos/KronicDeth/intellij-elixir/issues/1142","repository_url":"https://api.github.com/repos/KronicDeth/intellij-elixir","labels_url":"https://api.github.com/repos/KronicDeth/intellij-elixir/issues/1142/labels{/name}","comments_url":"https://api.github.com/repos/KronicDeth/intellij-elixir/issues/1142/comments","events_url":"https://api.github.com/repos/KronicDeth/intellij-elixir/issues/1142/events","html_url":"https://github.com/KronicDeth/intellij-elixir/issues/1142","id":333567073,"node_id":"MDU6SXNzdWUzMzM1NjcwNzM=","number":1142,"title":"functions appear twice in structure view","user":{"login":"StefanHoutzager","id":6817215,"node_id":"MDQ6VXNlcjY4MTcyMTU=","avatar_url":"https://avatars2.githubusercontent.com/u/6817215?v=4","gravatar_id":"","url":"https://api.github.com/users/StefanHoutzager","html_url":"https://github.com/StefanHoutzager","followers_url":"https://api.github.com/users/StefanHoutzager/followers","following_url":"https://api.github.com/users/StefanHoutzager/following{/other_user}","gists_url":"https://api.github.com/users/StefanHoutzager/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanHoutzager/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanHoutzager/subscriptions","organizations_url":"https://api.github.com/users/StefanHoutzager/orgs","repos_url":"https://api.github.com/users/StefanHoutzager/repos","events_url":"https://api.github.com/users/StefanHoutzager/events{/privacy}","received_events_url":"https://api.github.com/users/StefanHoutzager/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-19T08:23:20Z","updated_at":"2018-06-23T04:22:33Z","closed_at":"2018-06-23T04:22:33Z","author_association":"NONE","body":"![image](https://user-images.githubusercontent.com/6817215/41585520-a0dd96a6-73aa-11e8-8c0e-9f9a8fd7a038.png)\r\n\r\nHere is a copy of the file to reproduce the issue:\r\n\r\n<details>\r\n\r\n```elixir\r\ndefmodule Dal.User do\r\n  use Ecto.Schema\r\n  import Ecto.Changeset\r\n  import Ecto.Query, only: [from: 2]\r\n  import Plug.Conn\r\n  import Comeonin.Bcrypt, only: [checkpw: 2, dummy_checkpw: 0, hashpwsalt: 1]\r\n  alias Dal.{Repo, Role, UserRole}\r\n\r\n  schema \"users\" do\r\n    field :name, :string\r\n    field :email, :string\r\n    field :password, :string, virtual: true\r\n    field :password_repeat, :string, virtual: true\r\n    field :password_hash, :string\r\n    field :new_password_hash, :string, virtual: true\r\n    field :password_confirmation, :string, virtual: true\r\n    field :password_old, :string, virtual: true\r\n    belongs_to :usergroup, Usergroup\r\n    many_to_many :roles, Role, join_through: UserRole, on_replace: :delete\r\n\r\n    timestamps()\r\n  end\r\n\r\n  def update_emailaddress(user, params),\r\n    do: changeset_email(user, params)\r\n        |> Repo.update()\r\n\r\n  def update_password(user, params),\r\n    do: changeset_password(user, params)\r\n        |> Repo.update()\r\n\r\n  def changeset_password(model, params \\\\ %{}) do\r\n    required_fields = ~w(password password_confirmation password_old)a\r\n    fields          = ~w(password password_confirmation password_old)a\r\n\r\n    case params do\r\n      %{\"user\" => user} ->\r\n        model\r\n        |> cast(params[\"password\"], fields) # params contains the form, \"password\" the fields/values\r\n        |> validate_password(model, :password_old)\r\n        |> validate_required(required_fields)\r\n        |> validate_length(:password, min: 8)\r\n        |> validate_passwords_equality()\r\n        |> put_pass_hash()\r\n      _ ->\r\n        model\r\n        |> cast(params, fields)\r\n    end\r\n  end\r\n\r\n  def validate_passwords_equality(changeset) do\r\n    case changeset.valid? do\r\n      true -> case get_change(changeset, :password) === get_change(changeset, :password_confirmation) do\r\n                true  -> changeset\r\n                false -> add_error(changeset, :password, \"Wachtwoord en wachtwoord bevestiging moeten gelijk zijn\")\r\n              end\r\n       _   -> changeset\r\n    end\r\n  end\r\n\r\n  def changeset_email(model, params \\\\ %{}) do\r\n    required_fields = ~w(password email)a\r\n    fields          = ~w(password email)a\r\n\r\n    case params do\r\n      %{\"user\" => _user} ->\r\n        model\r\n        |> cast(params[\"user\"], fields) # params contains the form, \"update_mailaddress\" the fields/values\r\n        |> validate_required(required_fields)\r\n        |> validate_password(model, :password)\r\n        |> validate_format(:email, ~r/@/)\r\n      _ ->\r\n        model\r\n        |> cast(params, fields)\r\n    end\r\n  end\r\n\r\n  def validate_password(changeset, model, pwd_field) do\r\n    case get_change(changeset, pwd_field) |> check_password(model.password_hash) do\r\n      true  -> changeset\r\n      false -> add_error(changeset, pwd_field, \"Geef het correcte wachtwoord in\")\r\n    end\r\n  end\r\n\r\n  def changeset(model, params \\\\ :invalid) do\r\n    model\r\n    |> cast(params, ~w(name email password usergroup_id))\r\n  end\r\n\r\n  def changeset_create(model, params \\\\ :invalid) do\r\n    model =\r\n      case model do\r\n        nil -> %Dal.User{}\r\n        _   -> model\r\n      end\r\n  IO.puts \"model hoeft niet als param binnen te komen\"\r\n  IO.inspect model\r\n  IO.inspect params\r\n  IO.inspect Process.info(self(), :current_stacktrace)\r\n\r\n    model\r\n    |> cast(params, ~w(name email password usergroup_id))\r\n    |> validate_required([:name, :password, :email])\r\n    |> validate_length(:name, max: 20)\r\n    |> unique_constraint(:name)\r\n    |> unique_constraint(:email)\r\n    |> validate_length(:password, min: 8)\r\n    |> validate_format(:email, ~r/@/)\r\n    |> put_pass_hash()\r\n    |> add_roles(params)\r\n\r\n    # tijdelijk voor user invoer taak {:ok, user} = Repo.insert(changeset)\r\n  end\r\n\r\n  def changeset_update(model, params \\\\ :invalid) do\r\n    model\r\n    |> cast(params, ~w(name email))\r\n    |> validate_required([:name, :email])\r\n    |> validate_format(:email, ~r/@/)\r\n    |> validate_length(:name, max: 20)\r\n    |> unique_constraint(:name)\r\n    |> unique_constraint(:email)\r\n    |> add_roles(params)\r\n  end\r\n\r\n  def login(conn, user) do\r\n    conn\r\n    |> put_current_user(user)\r\n    |> put_session(:user_id, user.id)\r\n    |> configure_session(renew: true)\r\n  end\r\n\r\n  def put_current_user(conn, user) do\r\n    token = Phoenix.Token.sign(conn, \"user socket\", user.id)\r\n    conn\r\n    |> assign(:current_user, user)\r\n    |> assign(:user_token, token)\r\n  end\r\n\r\n  def logout(conn) do\r\n    configure_session(conn, drop: true)\r\n  end\r\n\r\n  def authenticate_user(conn, _opts) do\r\n    if Map.has_key?(conn.assigns, :current_user) && conn.assigns.current_user do\r\n      conn\r\n    else\r\n      conn\r\n      |> Phoenix.Controller.put_flash(:error, \"Toegang alleen mogelijk na inloggen\")\r\n      |> Phoenix.Controller.redirect(external: Application.get_env(:dal, :home_url) <> \"/sessions/new\")\r\n      |> halt()\r\n    end\r\n  end\r\n\r\n  def login_by_username_and_pass(conn, name, given_pass) do\r\n    user = Repo.get_by(Dal.User, name: name)\r\n\r\n    cond do\r\n      user && check_password(given_pass, user.password_hash) ->\r\n        {:ok, login(conn, user)}\r\n      user ->\r\n        {:error, :unauthorized, conn}\r\n     true ->\r\n        dummy_checkpw()\r\n        {:error, :not_found, conn}\r\n    end\r\n  end\r\n\r\n  def check_password(given_pass, hash),\r\n    do: checkpw(given_pass, hash)\r\n\r\n  def add_roles(changeset, params) do\r\n  # see https://github.com/smpallen99/ex_admin, code had to be customized\r\n  IO.puts \"add_roles in dal/lib/user.ex model params\"\r\n  IO.inspect params\r\n\r\n    if Map.get(params, :role_ids, []) !== [\"\"] do\r\n      ids = params.role_ids |> Map.keys() |> Enum.map(fn atom -> atom |> Atom.to_string() |> String.to_integer() end)\r\n      roles = Repo.all(from r in Role, where: r.id in ^ids)\r\n      put_assoc(changeset, :roles, roles)\r\n    else\r\n      put_assoc(changeset, :roles, [])\r\n    end\r\n  end\r\n\r\n  def put_pass_hash(changeset) do\r\n    case changeset do\r\n      %Ecto.Changeset{valid?: true, changes: %{password: pass}} ->\r\n        put_change(changeset, :password_hash, hashpwsalt(pass))\r\n      _ ->\r\n        changeset\r\n    end\r\n  end\r\n\r\n  def get_user(user_id),\r\n    do: Repo.get(Dal.User, user_id)\r\n\r\n  @spec get_name(User.id) :: list\r\n  def get_name(user_id),\r\n    do: (from u in \"users\", where: u.id == ^user_id, select: u.name)\r\n        |> Repo.all()\r\nend\r\n```\r\n\r\n</details>"}}
{"actor":{"display_login":"KronicDeth"}}