field(:no_rich_text, :boolean, default: false)
field(:ap_enabled, :boolean, default: false)
field(:is_moderator, :boolean, default: false)
+ field(:is_admin, :boolean, default: false)
field(:keys, :string, default: nil)
field(:settings, :map, default: nil)
field(:magic_key, :string, default: nil)
|> cast(params, [:source_data])
|> validate_required([:source_data])
end
+
+ def admin_api_update(info, params) do
+ info
+ |> cast(params, [
+ :is_moderator,
+ :is_admin
+ ])
+ end
end
user = User.get_by_nickname(nickname)
info =
- user.info
+ %{}
|> Map.put("is_" <> permission_group, true)
- cng = User.info_changeset(user, %{info: info})
+ info_cng = User.Info.admin_api_update(user.info, info)
+
+ cng =
+ Ecto.Changeset.change(user)
+ |> Ecto.Changeset.put_embed(:info, info_cng)
+
{:ok, user} = User.update_and_set_cache(cng)
conn
- |> json(user.info)
+ |> json(info)
end
def right_get(conn, %{"nickname" => nickname}) do
user = User.get_by_nickname(nickname)
conn
- |> json(user.info)
+ |> json(%{
+ is_moderator: user.info.is_moderator,
+ is_admin: user.info.is_admin
+ })
end
def right_add(conn, _) do
user = User.get_by_nickname(nickname)
info =
- user.info
+ %{}
|> Map.put("is_" <> permission_group, false)
- cng = User.info_changeset(user, %{info: info})
+ info_cng = User.Info.admin_api_update(user.info, info)
+
+ cng =
+ Ecto.Changeset.change(user)
+ |> Ecto.Changeset.put_embed(:info, info_cng)
+
{:ok, user} = User.update_and_set_cache(cng)
conn
- |> json(user.info)
+ |> json(info)
end
end
describe "/api/pleroma/admin/user" do
test "Delete" do
- admin = insert(:user, info: %{"is_admin" => true})
+ admin = insert(:user, info: %{is_admin: true})
user = insert(:user)
conn =
end
test "Create" do
- admin = insert(:user, info: %{"is_admin" => true})
+ admin = insert(:user, info: %{is_admin: true})
conn =
build_conn()
describe "/api/pleroma/admin/permission_group" do
test "GET is giving user_info" do
- admin = insert(:user, info: %{"is_admin" => true})
+ admin = insert(:user, info: %{is_admin: true})
conn =
build_conn()
|> put_req_header("accept", "application/json")
|> get("/api/pleroma/admin/permission_group/#{admin.nickname}")
- assert json_response(conn, 200) == admin.info
+ assert json_response(conn, 200) == %{
+ "is_admin" => true,
+ "is_moderator" => false
+ }
end
test "/:right POST, can add to a permission group" do
- admin = insert(:user, info: %{"is_admin" => true})
+ admin = insert(:user, info: %{is_admin: true})
user = insert(:user)
- user_info =
- user.info
- |> Map.put("is_admin", true)
-
conn =
build_conn()
|> assign(:user, admin)
|> put_req_header("accept", "application/json")
|> post("/api/pleroma/admin/permission_group/#{user.nickname}/admin")
- assert json_response(conn, 200) == user_info
+ assert json_response(conn, 200) == %{
+ "is_admin" => true
+ }
end
test "/:right DELETE, can remove from a permission group" do
- admin = insert(:user, info: %{"is_admin" => true})
- user = insert(:user, info: %{"is_admin" => true})
-
- user_info =
- user.info
- |> Map.put("is_admin", false)
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user, info: %{is_admin: true})
conn =
build_conn()
|> put_req_header("accept", "application/json")
|> delete("/api/pleroma/admin/permission_group/#{user.nickname}/admin")
- assert json_response(conn, 200) == user_info
+ assert json_response(conn, 200) == %{
+ "is_admin" => false
+ }
end
end
test "/api/pleroma/admin/invite_token" do
- admin = insert(:user, info: %{"is_admin" => true})
+ admin = insert(:user, info: %{is_admin: true})
conn =
build_conn()
end
test "/api/pleroma/admin/password_reset" do
- admin = insert(:user, info: %{"is_admin" => true})
- user = insert(:user, info: %{"is_admin" => true})
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
conn =
build_conn()