use Ecto.Schema
import Ecto.{Changeset, Query}
+ alias Ecto.Multi
alias Pleroma.{Repo, User, Object, Web, Activity, Notification}
alias Comeonin.Pbkdf2
alias Pleroma.Formatter
|> List.flatten()
|> Enum.map(&String.downcase(&1))
- Repo.transaction(fn ->
- for user <- users do
+ multi =
+ Enum.reduce(users, Multi.new(), fn user, multi ->
new_tags = mutate_tags(user, tags, action)
+ Multi.update(multi, {:user, user.id}, change(user, %{tags: new_tags}))
+ end)
- {:ok, updated_user} =
- user
- |> change(%{tags: new_tags})
- |> Repo.update()
-
- updated_user
- end
- end)
+ Repo.transaction(multi)
end
defp mutate_tags(user, tags, :tag), do: Enum.uniq(user.tags ++ tags)
delete("/user", AdminAPIController, :user_delete)
post("/user", AdminAPIController, :user_create)
put("/users/tag", AdminAPIController, :tag_users)
- put("/users/untag", AdminAPIController, :untag_users)
+ delete("/users/tag", AdminAPIController, :untag_users)
get("/permission_group/:nickname", AdminAPIController, :right_get)
get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
end
end
- describe "/api/pleroma/admin//users/tag" do
+ describe "PUT /api/pleroma/admin/users/tag" do
setup do
admin = insert(:user, info: %{is_admin: true})
user1 = insert(:user, %{tags: ["x"]})
end
end
- describe "/api/pleroma/admin//users/untag" do
+ describe "DELETE /api/pleroma/admin/users/tag" do
setup do
admin = insert(:user, info: %{is_admin: true})
user1 = insert(:user, %{tags: ["x"]})
build_conn()
|> assign(:user, admin)
|> put_req_header("accept", "application/json")
- |> put(
- "/api/pleroma/admin/users/untag?nicknames[]=#{user1.nickname}&nicknames[]=#{
+ |> delete(
+ "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=#{
user2.nickname
}&tags[]=x&tags[]=z"
)