Make email and nickname case insensitive.
authorRoger Braun <roger@rogerbraun.net>
Mon, 22 May 2017 16:10:50 +0000 (18:10 +0200)
committerRoger Braun <roger@rogerbraun.net>
Mon, 22 May 2017 16:10:50 +0000 (18:10 +0200)
priv/repo/migrations/20170522160642_case_insensivtivity.exs [new file with mode: 0644]
test/user_test.exs

diff --git a/priv/repo/migrations/20170522160642_case_insensivtivity.exs b/priv/repo/migrations/20170522160642_case_insensivtivity.exs
new file mode 100644 (file)
index 0000000..c756594
--- /dev/null
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.CaseInsensivtivity do
+  use Ecto.Migration
+
+  def up do
+    execute ("create extension if not exists citext")
+    alter table(:users) do
+      modify :email, :citext
+      modify :nickname, :citext
+    end
+  end
+
+  def down do
+    alter table(:users) do
+      modify :email, :string
+      modify :nickname, :string
+    end
+    execute ("drop extension if exists citext")
+  end
+end
index b87d3186266c94d19e636c05de67e8dd94e32f21..6a7ecca27bc3c009c3c9764b9522b8be97e6bd81 100644 (file)
@@ -114,6 +114,13 @@ defmodule Pleroma.UserTest do
       assert user == fetched_user
     end
 
+    test "gets an existing user, case insensitive" do
+      user = insert(:user, nickname: "nick")
+      fetched_user = User.get_or_fetch_by_nickname("NICK")
+
+      assert user == fetched_user
+    end
+
     test "fetches an external user via ostatus if no user exists" do
       fetched_user = User.get_or_fetch_by_nickname("shp@social.heldscal.la")
       assert fetched_user.nickname == "shp@social.heldscal.la"