Commit 8baffd58 authored by Peter van der meulen's avatar Peter van der meulen

Update user name only when needed

parent 6eda5588
......@@ -104,7 +104,7 @@ defmodule SnugglesApp.Accounts do
user = Repo.get(User, user_id)
{:ok, eve_user} = EveUser.fetch_full(user.character_id)
{:ok, updated_user } = update_user(user, eve_user)
Discord.manage_alliance_permissions(updated_user.discord_id, user.access, updated_user.access)
Discord.manage_alliance_permissions(updated_user, user.access, updated_user.access)
manage_corp_discord_permissions(updated_user, user.corp_id, updated_user.corp_id)
{:ok, updated_user}
end
......
......@@ -37,14 +37,14 @@ defmodule SnugglesApp.Discord do
"""
def manage_alliance_permissions(_, unchanged, unchanged), do: {:ok}
def manage_alliance_permissions(discord_id, _, true) do
add_default_role_to_user(discord_id)
Discord.update_user_name(updated_user)
def manage_alliance_permissions(user, _, true) do
add_default_role_to_user(user.discord_id)
update_user_name(user)
end
def manage_alliance_permissions(discord_id, _, false) do
remove_default_role_from_user(String.to_integer(discord_id))
Discord.update_user_name(updated_user)
def manage_alliance_permissions(user, _, false) do
remove_default_role_from_user(String.to_integer(user.discord_id))
update_user_name(user)
end
defp add_default_role_to_user(discord_id) do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment