From 174dbb5e740cb7367223967b9488d996bfb80a30 Mon Sep 17 00:00:00 2001 From: Geometrically Date: Mon, 18 Jan 2021 10:10:45 -0700 Subject: [PATCH] Fix auth params, Add params to indexing, Order version game versions, Remove version moderation, Return donation platforms in get routes --- .../20210118161307_remove-version-access.sql | 3 + sqlx-data.json | 1081 ++++++++--------- src/database/models/mod_item.rs | 7 +- src/database/models/version_item.rs | 18 +- src/routes/auth.rs | 2 +- src/routes/mod.rs | 6 +- src/routes/mod_creation.rs | 2 + src/routes/moderation.rs | 50 +- src/routes/mods.rs | 11 +- src/routes/version_creation.rs | 9 +- src/routes/versions.rs | 80 +- src/search/indexing/local_import.rs | 75 +- src/search/indexing/mod.rs | 9 +- src/search/mod.rs | 6 + 14 files changed, 614 insertions(+), 745 deletions(-) create mode 100644 migrations/20210118161307_remove-version-access.sql diff --git a/migrations/20210118161307_remove-version-access.sql b/migrations/20210118161307_remove-version-access.sql new file mode 100644 index 000000000..869ead47b --- /dev/null +++ b/migrations/20210118161307_remove-version-access.sql @@ -0,0 +1,3 @@ +-- Add migration script here +ALTER TABLE versions +DROP COLUMN accepted; \ No newline at end of file diff --git a/sqlx-data.json b/sqlx-data.json index bc07ff129..85457cdf8 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -75,19 +75,6 @@ "nullable": [] } }, - "037b285b751880c643b0dc711ba23bc598959f0ff4a1eb4f7201da68a3b5d377": { - "query": "\n UPDATE versions\n SET accepted = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Bool", - "Int8" - ] - }, - "nullable": [] - } - }, "04345d9c23430267f755b1420520df91bd403524fd60ba1a94e3a239ea70cae7": { "query": "\n UPDATE mods\n SET source_url = $1\n WHERE (id = $2)\n ", "describe": { @@ -216,6 +203,26 @@ ] } }, + "0e0057078bce50b61e7fef071389cb6b462472da76abee1d4e1ab952aa8dc4b9": { + "query": "\n SELECT gv.version FROM game_versions_versions gvv\n INNER JOIN game_versions gv ON gvv.game_version_id=gv.id\n WHERE gvv.joining_version_id = $1\n ORDER BY gv.created\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "version", + "type_info": "Varchar" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false + ] + } + }, "1220d15a56dbf823eaa452fbafa17442ab0568bc81a31fa38e16e3df3278e5f9": { "query": "SELECT EXISTS(SELECT 1 FROM users WHERE id = $1)", "describe": { @@ -236,6 +243,102 @@ ] } }, + "1305fabd44e54fb9f4a78e698507f19cbcd9cf52bb193f3188679918979f28a8": { + "query": "\n SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status, m.slug, m.license, m.client_side, m.server_side FROM mods m\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "title", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "description", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "downloads", + "type_info": "Int4" + }, + { + "ordinal": 4, + "name": "icon_url", + "type_info": "Varchar" + }, + { + "ordinal": 5, + "name": "body_url", + "type_info": "Varchar" + }, + { + "ordinal": 6, + "name": "published", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "updated", + "type_info": "Timestamptz" + }, + { + "ordinal": 8, + "name": "team_id", + "type_info": "Int8" + }, + { + "ordinal": 9, + "name": "status", + "type_info": "Int4" + }, + { + "ordinal": 10, + "name": "slug", + "type_info": "Varchar" + }, + { + "ordinal": 11, + "name": "license", + "type_info": "Int4" + }, + { + "ordinal": 12, + "name": "client_side", + "type_info": "Int4" + }, + { + "ordinal": 13, + "name": "server_side", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + false, + false, + true, + true, + false, + false, + false, + false, + true, + false, + false, + false + ] + } + }, "1524c0462be70077736ac70fcd037fbf75651456b692e2ce40fa2e3fc8123984": { "query": "\n SELECT hashes.algorithm, hashes.hash FROM hashes\n WHERE hashes.file_id = $1\n ", "describe": { @@ -651,92 +754,6 @@ "nullable": [] } }, - "35a05ad89abf739b345f9544b57fe439cd364a9969bb02953e5d9faec697ae97": { - "query": "\n SELECT v.id, v.mod_id, v.author_id, v.name, v.version_number,\n v.changelog, v.changelog_url, v.date_published, v.downloads,\n v.release_channel, v.accepted, v.featured\n FROM versions v\n WHERE v.id IN (SELECT * FROM UNNEST($1::bigint[]))\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "mod_id", - "type_info": "Int8" - }, - { - "ordinal": 2, - "name": "author_id", - "type_info": "Int8" - }, - { - "ordinal": 3, - "name": "name", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "version_number", - "type_info": "Varchar" - }, - { - "ordinal": 5, - "name": "changelog", - "type_info": "Varchar" - }, - { - "ordinal": 6, - "name": "changelog_url", - "type_info": "Varchar" - }, - { - "ordinal": 7, - "name": "date_published", - "type_info": "Timestamptz" - }, - { - "ordinal": 8, - "name": "downloads", - "type_info": "Int4" - }, - { - "ordinal": 9, - "name": "release_channel", - "type_info": "Int4" - }, - { - "ordinal": 10, - "name": "accepted", - "type_info": "Bool" - }, - { - "ordinal": 11, - "name": "featured", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [ - "Int8Array" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - false, - true, - false, - false, - false, - false, - false - ] - } - }, "3831c1b321e47690f1f54597506a0d43362eda9540c56acb19c06532bba50b01": { "query": "\n SELECT id, user_id, role, permissions, accepted\n FROM team_members\n WHERE team_id = $1\n ", "describe": { @@ -939,92 +956,6 @@ "nullable": [] } }, - "486c13abb9648b16a4c354f25754408d649b13980fe7486cdcfdcacfa2725c2b": { - "query": "\n SELECT * FROM versions\n WHERE accepted = FALSE\n ORDER BY date_published ASC\n LIMIT $1;\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "mod_id", - "type_info": "Int8" - }, - { - "ordinal": 2, - "name": "name", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "version_number", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "changelog_url", - "type_info": "Varchar" - }, - { - "ordinal": 5, - "name": "date_published", - "type_info": "Timestamptz" - }, - { - "ordinal": 6, - "name": "downloads", - "type_info": "Int4" - }, - { - "ordinal": 7, - "name": "release_channel", - "type_info": "Int4" - }, - { - "ordinal": 8, - "name": "author_id", - "type_info": "Int8" - }, - { - "ordinal": 9, - "name": "accepted", - "type_info": "Bool" - }, - { - "ordinal": 10, - "name": "featured", - "type_info": "Bool" - }, - { - "ordinal": 11, - "name": "changelog", - "type_info": "Varchar" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - true, - false, - false, - false, - false, - false, - false, - false - ] - } - }, "49e36828e3a0214b48234435e34311735ae32e08d8be1270f8f0db4b27e708ba": { "query": "\n INSERT INTO loaders (loader)\n VALUES ($1)\n ON CONFLICT (loader) DO NOTHING\n RETURNING id\n ", "describe": { @@ -1202,28 +1133,6 @@ "nullable": [] } }, - "50a15c443b01cefc478a3b5ca03bb9b279782d74bcf42ee4e7c06581457c130d": { - "query": "\n INSERT INTO versions (\n id, mod_id, author_id, name, version_number,\n changelog_url, date_published,\n downloads, release_channel, accepted, featured\n )\n VALUES (\n $1, $2, $3, $4, $5,\n $6, $7,\n $8, $9,\n $10, $11\n )\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Int8", - "Int8", - "Varchar", - "Varchar", - "Varchar", - "Timestamptz", - "Int4", - "Int4", - "Bool", - "Bool" - ] - }, - "nullable": [] - } - }, "5322e7791400b47640f897f3e32d9a0f2915da7d71a34c4e6bf6bd648cfaaa6e": { "query": "\n DELETE FROM files\n WHERE files.id = $1\n ", "describe": { @@ -1413,27 +1322,6 @@ ] } }, - "618472f46632ddf15b01bb0df27c9d5e6f5b56a9413a6f7393d6d7c29b852459": { - "query": "SELECT EXISTS(SELECT 1 FROM team_members tm INNER JOIN mods m ON m.team_id = tm.team_id AND m.id = $1 WHERE tm.user_id = $2)", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "exists", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [ - "Int8", - "Int8" - ] - }, - "nullable": [ - null - ] - } - }, "637fd5f9564a79b625e00a705b3c9fe70ba3cba9050c0993557ca46f50d89623": { "query": "\n SELECT * FROM mods\n WHERE status = (\n SELECT id FROM statuses WHERE status = $1\n )\n ORDER BY updated ASC\n LIMIT $2;\n ", "describe": { @@ -2028,6 +1916,44 @@ "nullable": [] } }, + "8eff482abade78aff21f443abf7dedd57e1c91e46bebf1b553db5be505f4bd20": { + "query": "\n SELECT d.joining_platform_id, d.url, dp.short, dp.name FROM mods_donations d\n INNER JOIN donation_platforms dp ON d.joining_platform_id=dp.id\n WHERE joining_mod_id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "joining_platform_id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "url", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "short", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "name", + "type_info": "Varchar" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false + ] + } + }, "8f706d78ac4235ea04c59e2c220a4791e1d08fdf287b783b4aaef36fd2445467": { "query": "\n DELETE FROM loaders\n WHERE loader = $1\n ", "describe": { @@ -2207,6 +2133,98 @@ ] } }, + "975616f51d8d179a34e92b445c8ed3ac62de17dbbc44a7d42ca5476615b4f04d": { + "query": "\n SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.slug, m.license, m.client_side, m.server_side\n FROM mods m\n WHERE id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "title", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "description", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "downloads", + "type_info": "Int4" + }, + { + "ordinal": 4, + "name": "icon_url", + "type_info": "Varchar" + }, + { + "ordinal": 5, + "name": "body_url", + "type_info": "Varchar" + }, + { + "ordinal": 6, + "name": "published", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "updated", + "type_info": "Timestamptz" + }, + { + "ordinal": 8, + "name": "team_id", + "type_info": "Int8" + }, + { + "ordinal": 9, + "name": "slug", + "type_info": "Varchar" + }, + { + "ordinal": 10, + "name": "license", + "type_info": "Int4" + }, + { + "ordinal": 11, + "name": "client_side", + "type_info": "Int4" + }, + { + "ordinal": 12, + "name": "server_side", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + true, + true, + false, + false, + false, + true, + false, + false, + false + ] + } + }, "99a1eac69d7f5a5139703df431e6a5c3012a90143a8c635f93632f04d0bc41d4": { "query": "\n UPDATE mods\n SET wiki_url = $1\n WHERE (id = $2)\n ", "describe": { @@ -2247,86 +2265,6 @@ ] } }, - "a08d75ec11e3cec9826d6968c0e953fe5d6627660384d066e4628dd9c79ceeeb": { - "query": "\n SELECT v.mod_id, v.author_id, v.name, v.version_number,\n v.changelog, v.changelog_url, v.date_published, v.downloads,\n v.release_channel, v.accepted, v.featured\n FROM versions v\n WHERE v.id = $1\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "mod_id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "author_id", - "type_info": "Int8" - }, - { - "ordinal": 2, - "name": "name", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "version_number", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "changelog", - "type_info": "Varchar" - }, - { - "ordinal": 5, - "name": "changelog_url", - "type_info": "Varchar" - }, - { - "ordinal": 6, - "name": "date_published", - "type_info": "Timestamptz" - }, - { - "ordinal": 7, - "name": "downloads", - "type_info": "Int4" - }, - { - "ordinal": 8, - "name": "release_channel", - "type_info": "Int4" - }, - { - "ordinal": 9, - "name": "accepted", - "type_info": "Bool" - }, - { - "ordinal": 10, - "name": "featured", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - true, - false, - false, - false, - false, - false - ] - } - }, "a2369858ff21b3fa491685168624e9eb22aca34ef0fefc774675b38066c8beba": { "query": "\n SELECT title, description, downloads,\n icon_url, body, body_url, published,\n updated, status,\n issues_url, source_url, wiki_url, discord_url, license_url,\n team_id, client_side, server_side, license, slug\n FROM mods\n WHERE id = $1\n ", "describe": { @@ -2568,6 +2506,86 @@ ] } }, + "a8f8acda6246fe82cc16c8804589102bfb176980fbcb93ca131f524ac395d86a": { + "query": "\n SELECT v.id, v.mod_id, v.author_id, v.name, v.version_number,\n v.changelog, v.changelog_url, v.date_published, v.downloads,\n v.release_channel, v.featured\n FROM versions v\n WHERE v.id IN (SELECT * FROM UNNEST($1::bigint[]))\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "mod_id", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "author_id", + "type_info": "Int8" + }, + { + "ordinal": 3, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "version_number", + "type_info": "Varchar" + }, + { + "ordinal": 5, + "name": "changelog", + "type_info": "Varchar" + }, + { + "ordinal": 6, + "name": "changelog_url", + "type_info": "Varchar" + }, + { + "ordinal": 7, + "name": "date_published", + "type_info": "Timestamptz" + }, + { + "ordinal": 8, + "name": "downloads", + "type_info": "Int4" + }, + { + "ordinal": 9, + "name": "release_channel", + "type_info": "Int4" + }, + { + "ordinal": 10, + "name": "featured", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int8Array" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + true, + false, + false, + false, + false + ] + } + }, "a90bb6904e1b790c0e29e060dac5ba4c2a6087e07c1197dc1f59f0aff31944c9": { "query": "\n DELETE FROM states\n WHERE expires < CURRENT_DATE\n ", "describe": { @@ -2728,84 +2746,6 @@ "nullable": [] } }, - "b2a9bf9cb82a5e5597c2d2c8b5678cb2ee63dedde43f27c759c3300072312a1f": { - "query": "\n SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status, m.slug FROM mods m\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "title", - "type_info": "Varchar" - }, - { - "ordinal": 2, - "name": "description", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "downloads", - "type_info": "Int4" - }, - { - "ordinal": 4, - "name": "icon_url", - "type_info": "Varchar" - }, - { - "ordinal": 5, - "name": "body_url", - "type_info": "Varchar" - }, - { - "ordinal": 6, - "name": "published", - "type_info": "Timestamptz" - }, - { - "ordinal": 7, - "name": "updated", - "type_info": "Timestamptz" - }, - { - "ordinal": 8, - "name": "team_id", - "type_info": "Int8" - }, - { - "ordinal": 9, - "name": "status", - "type_info": "Int4" - }, - { - "ordinal": 10, - "name": "slug", - "type_info": "Varchar" - } - ], - "parameters": { - "Left": [] - }, - "nullable": [ - false, - false, - false, - false, - true, - true, - false, - false, - false, - false, - true - ] - } - }, "b34577335d30ffe30327cdd5b3c029a187a1cae27bea99ff0bcf062f87468fe7": { "query": "\n SELECT loaders.loader FROM versions\n INNER JOIN loaders_versions lv ON lv.version_id = versions.id\n INNER JOIN loaders ON loaders.id = lv.loader_id\n WHERE versions.mod_id = $1\n ", "describe": { @@ -2851,6 +2791,80 @@ "nullable": [] } }, + "b8485af7c70d7e585a681bb9733ed7864c49b8e280a0097f32e1edfeae83d08b": { + "query": "\n SELECT v.mod_id, v.author_id, v.name, v.version_number,\n v.changelog, v.changelog_url, v.date_published, v.downloads,\n release_channels.channel, v.featured\n FROM versions v\n INNER JOIN release_channels ON v.release_channel = release_channels.id\n WHERE v.id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "mod_id", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "author_id", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "version_number", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "changelog", + "type_info": "Varchar" + }, + { + "ordinal": 5, + "name": "changelog_url", + "type_info": "Varchar" + }, + { + "ordinal": 6, + "name": "date_published", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "downloads", + "type_info": "Int4" + }, + { + "ordinal": 8, + "name": "channel", + "type_info": "Varchar" + }, + { + "ordinal": 9, + "name": "featured", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + true, + false, + false, + false, + false + ] + } + }, "b903ac4e686ef85ba28d698c668da07860e7f276b261d8f2cebb74e73b094970": { "query": "\n DELETE FROM hashes\n WHERE EXISTS(\n SELECT 1 FROM files WHERE\n (files.version_id = $1) AND\n (hashes.file_id = files.id)\n )\n ", "describe": { @@ -3305,32 +3319,6 @@ "nullable": [] } }, - "cdf37a51c68eaa7401da19c5b1e34097592027ceb777bfa535116e3a52b28958": { - "query": "\n SELECT joining_platform_id, url FROM mods_donations\n WHERE joining_mod_id = $1\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "joining_platform_id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "url", - "type_info": "Varchar" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - false, - false - ] - } - }, "cf031f19c7882833a8a30348ee90175a5d8b1fb7d9645c5deb2dc68c6eb33683": { "query": "\n SELECT id FROM release_channels\n WHERE channel = $1\n ", "describe": { @@ -3593,86 +3581,6 @@ "nullable": [] } }, - "e7558867b28d7760ca10063374dbfdb9c5b625a4ba039cab38582a6ab6767a24": { - "query": "\n SELECT v.mod_id, v.author_id, v.name, v.version_number,\n v.changelog, v.changelog_url, v.date_published, v.downloads,\n release_channels.channel, v.accepted, v.featured\n FROM versions v\n INNER JOIN release_channels ON v.release_channel = release_channels.id\n WHERE v.id = $1\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "mod_id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "author_id", - "type_info": "Int8" - }, - { - "ordinal": 2, - "name": "name", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "version_number", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "changelog", - "type_info": "Varchar" - }, - { - "ordinal": 5, - "name": "changelog_url", - "type_info": "Varchar" - }, - { - "ordinal": 6, - "name": "date_published", - "type_info": "Timestamptz" - }, - { - "ordinal": 7, - "name": "downloads", - "type_info": "Int4" - }, - { - "ordinal": 8, - "name": "channel", - "type_info": "Varchar" - }, - { - "ordinal": 9, - "name": "accepted", - "type_info": "Bool" - }, - { - "ordinal": 10, - "name": "featured", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - true, - false, - false, - false, - false, - false - ] - } - }, "e7d0a64a08df6783c942f2fcadd94dd45f8d96ad3d3736e52ce90f68d396cdab": { "query": "SELECT EXISTS(SELECT 1 FROM team_members WHERE id=$1)", "describe": { @@ -3886,6 +3794,27 @@ ] } }, + "f195d865a7e79248ed6cbab5fc600c5739b540caafe98975469bf7bbc101ffa6": { + "query": "\n INSERT INTO versions (\n id, mod_id, author_id, name, version_number,\n changelog_url, date_published,\n downloads, release_channel, featured\n )\n VALUES (\n $1, $2, $3, $4, $5,\n $6, $7,\n $8, $9,\n $10\n )\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Int8", + "Int8", + "Varchar", + "Varchar", + "Varchar", + "Timestamptz", + "Int4", + "Int4", + "Bool" + ] + }, + "nullable": [] + } + }, "f22e9aee090f9952cf795a3540c03b0a5036dab0b740847d05e03d4565756283": { "query": "\n DELETE FROM team_members\n WHERE user_id = $1\n ", "describe": { @@ -3940,80 +3869,6 @@ "nullable": [] } }, - "f741273df7b987cbe2be4db3c3a11cf18027dfedb61dff41b9226aaa793b90cb": { - "query": "\n SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.slug\n FROM mods m\n WHERE id = $1\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "title", - "type_info": "Varchar" - }, - { - "ordinal": 2, - "name": "description", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "downloads", - "type_info": "Int4" - }, - { - "ordinal": 4, - "name": "icon_url", - "type_info": "Varchar" - }, - { - "ordinal": 5, - "name": "body_url", - "type_info": "Varchar" - }, - { - "ordinal": 6, - "name": "published", - "type_info": "Timestamptz" - }, - { - "ordinal": 7, - "name": "updated", - "type_info": "Timestamptz" - }, - { - "ordinal": 8, - "name": "team_id", - "type_info": "Int8" - }, - { - "ordinal": 9, - "name": "slug", - "type_info": "Varchar" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - true, - true, - false, - false, - false, - true - ] - } - }, "f7bea04e8e279e27a24de1bdf3c413daa8677994df5131494b28691ed6611efc": { "query": "\n SELECT url,expires FROM states\n WHERE id = $1\n ", "describe": { @@ -4040,26 +3895,6 @@ ] } }, - "f80ca292323952d10dbd26d3453ced5c12bdd1b71dcd3cb3ade4c7d4dc3590f6": { - "query": "\n SELECT gv.version FROM game_versions_versions gvv\n INNER JOIN game_versions gv ON gvv.game_version_id=gv.id\n WHERE gvv.joining_version_id = $1\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "version", - "type_info": "Varchar" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - false - ] - } - }, "f8c00875a7450c74423f9913cc3500898e9fcb6aa7eb8fc2f6fd16dc560773de": { "query": "\n SELECT short, name FROM donation_platforms\n WHERE id = $1\n ", "describe": { @@ -4118,6 +3953,80 @@ ] } }, + "fc12e683844642245dae7ffad7aff29f2b65c7441be7f22e319da468e7f3d323": { + "query": "\n SELECT v.mod_id, v.author_id, v.name, v.version_number,\n v.changelog, v.changelog_url, v.date_published, v.downloads,\n v.release_channel, v.featured\n FROM versions v\n WHERE v.id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "mod_id", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "author_id", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "version_number", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "changelog", + "type_info": "Varchar" + }, + { + "ordinal": 5, + "name": "changelog_url", + "type_info": "Varchar" + }, + { + "ordinal": 6, + "name": "date_published", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "downloads", + "type_info": "Int4" + }, + { + "ordinal": 8, + "name": "release_channel", + "type_info": "Int4" + }, + { + "ordinal": 9, + "name": "featured", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + true, + false, + false, + false, + false + ] + } + }, "fcb0ceeacfa2fa0f8f1f1987e744dabb73c26ac0fb8178ad9b3b9ebb3bd0acac": { "query": "SELECT EXISTS(SELECT 1 FROM versions WHERE (version_number=$1) AND (mod_id=$2))", "describe": { diff --git a/src/database/models/mod_item.rs b/src/database/models/mod_item.rs index 03928ad13..c97222e1e 100644 --- a/src/database/models/mod_item.rs +++ b/src/database/models/mod_item.rs @@ -3,6 +3,8 @@ use super::ids::*; pub struct DonationUrl { pub mod_id: ModId, pub platform_id: DonationPlatformId, + pub platform_short: String, + pub platform_name: String, pub url: String, } @@ -429,7 +431,8 @@ impl Mod { let donations: Vec = sqlx::query!( " - SELECT joining_platform_id, url FROM mods_donations + SELECT d.joining_platform_id, d.url, dp.short, dp.name FROM mods_donations d + INNER JOIN donation_platforms dp ON d.joining_platform_id=dp.id WHERE joining_mod_id = $1 ", id as ModId, @@ -439,6 +442,8 @@ impl Mod { Ok(e.right().map(|c| DonationUrl { mod_id: id, platform_id: DonationPlatformId(c.joining_platform_id), + platform_short: c.short, + platform_name: c.name, url: c.url, })) }) diff --git a/src/database/models/version_item.rs b/src/database/models/version_item.rs index 46cfc7850..66ac1e989 100644 --- a/src/database/models/version_item.rs +++ b/src/database/models/version_item.rs @@ -83,7 +83,6 @@ impl VersionBuilder { date_published: chrono::Utc::now(), downloads: 0, release_channel: self.release_channel, - accepted: false, featured: self.featured, }; @@ -158,7 +157,6 @@ pub struct Version { pub date_published: chrono::DateTime, pub downloads: i32, pub release_channel: ChannelId, - pub accepted: bool, pub featured: bool, } @@ -172,13 +170,13 @@ impl Version { INSERT INTO versions ( id, mod_id, author_id, name, version_number, changelog_url, date_published, - downloads, release_channel, accepted, featured + downloads, release_channel, featured ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, - $10, $11 + $10 ) ", self.id as VersionId, @@ -190,7 +188,6 @@ impl Version { self.date_published, self.downloads, self.release_channel as ChannelId, - self.accepted, self.featured ) .execute(&mut *transaction) @@ -385,7 +382,7 @@ impl Version { " SELECT v.mod_id, v.author_id, v.name, v.version_number, v.changelog, v.changelog_url, v.date_published, v.downloads, - v.release_channel, v.accepted, v.featured + v.release_channel, v.featured FROM versions v WHERE v.id = $1 ", @@ -406,7 +403,6 @@ impl Version { date_published: row.date_published, downloads: row.downloads, release_channel: ChannelId(row.release_channel), - accepted: row.accepted, featured: row.featured, })) } else { @@ -428,7 +424,7 @@ impl Version { " SELECT v.id, v.mod_id, v.author_id, v.name, v.version_number, v.changelog, v.changelog_url, v.date_published, v.downloads, - v.release_channel, v.accepted, v.featured + v.release_channel, v.featured FROM versions v WHERE v.id IN (SELECT * FROM UNNEST($1::bigint[])) ", @@ -447,7 +443,6 @@ impl Version { date_published: v.date_published, downloads: v.downloads, release_channel: ChannelId(v.release_channel), - accepted: v.accepted, featured: v.featured, })) }) @@ -468,7 +463,7 @@ impl Version { " SELECT v.mod_id, v.author_id, v.name, v.version_number, v.changelog, v.changelog_url, v.date_published, v.downloads, - release_channels.channel, v.accepted, v.featured + release_channels.channel, v.featured FROM versions v INNER JOIN release_channels ON v.release_channel = release_channels.id WHERE v.id = $1 @@ -486,6 +481,7 @@ impl Version { SELECT gv.version FROM game_versions_versions gvv INNER JOIN game_versions gv ON gvv.game_version_id=gv.id WHERE gvv.joining_version_id = $1 + ORDER BY gv.created ", id as VersionId, ) @@ -558,7 +554,6 @@ impl Version { files, loaders, game_versions, - accepted: row.accepted, featured: row.featured, })) } else { @@ -613,7 +608,6 @@ pub struct QueryVersion { pub files: Vec, pub game_versions: Vec, pub loaders: Vec, - pub accepted: bool, pub featured: bool, } diff --git a/src/routes/auth.rs b/src/routes/auth.rs index 83c4442e2..4114c218f 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -113,7 +113,7 @@ pub async fn init( "https://github.com/login/oauth/authorize?client_id={}&state={}&scope={}", client_id, to_base62(state.0 as u64), - "read%3Auser%20user%3Aemail" + "read%3Auser" ); Ok(HttpResponse::TemporaryRedirect() diff --git a/src/routes/mod.rs b/src/routes/mod.rs index c6022a295..77e463fcc 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -81,11 +81,7 @@ pub fn teams_config(cfg: &mut web::ServiceConfig) { } pub fn moderation_config(cfg: &mut web::ServiceConfig) { - cfg.service( - web::scope("moderation") - .service(moderation::mods) - .service(moderation::versions), - ); + cfg.service(web::scope("moderation").service(moderation::mods)); } #[derive(thiserror::Error, Debug)] diff --git a/src/routes/mod_creation.rs b/src/routes/mod_creation.rs index 6f1e21797..731c5df00 100644 --- a/src/routes/mod_creation.rs +++ b/src/routes/mod_creation.rs @@ -493,6 +493,8 @@ async fn mod_create_inner( donation_urls.push(models::mod_item::DonationUrl { mod_id: mod_id.into(), platform_id, + platform_short: "".to_string(), + platform_name: "".to_string(), url: url.url.clone(), }) } diff --git a/src/routes/moderation.rs b/src/routes/moderation.rs index 9c256176d..075e1d741 100644 --- a/src/routes/moderation.rs +++ b/src/routes/moderation.rs @@ -1,8 +1,7 @@ use super::ApiError; use crate::auth::check_is_moderator_from_headers; use crate::database; -use crate::models; -use crate::models::mods::{ModId, ModStatus, VersionType}; +use crate::models::mods::{ModId, ModStatus}; use crate::models::teams::TeamId; use actix_web::{get, web, HttpRequest, HttpResponse}; use serde::{Deserialize, Serialize}; @@ -103,50 +102,3 @@ pub async fn mods( Ok(HttpResponse::Ok().json(mods)) } - -/// Returns a list of versions that need to be approved -#[get("versions")] -pub async fn versions( - req: HttpRequest, - pool: web::Data, - count: web::Query, -) -> Result { - check_is_moderator_from_headers(req.headers(), &**pool).await?; - - use futures::stream::TryStreamExt; - - let versions = sqlx::query!( - " - SELECT * FROM versions - WHERE accepted = FALSE - ORDER BY date_published ASC - LIMIT $1; - ", - count.count as i64 - ) - .fetch_many(&**pool) - .try_filter_map(|e| async { - Ok(e.right().map(|m| models::mods::Version { - id: database::models::ids::VersionId(m.id).into(), - mod_id: database::models::ids::ModId(m.mod_id).into(), - author_id: database::models::ids::UserId(m.author_id).into(), - featured: m.featured, - name: m.name, - version_number: m.version_number, - changelog: m.changelog, - changelog_url: m.changelog_url, - date_published: m.date_published, - downloads: m.downloads as u32, - version_type: VersionType::Release, - files: vec![], - dependencies: vec![], - game_versions: vec![], - loaders: vec![], - })) - }) - .try_collect::>() - .await - .map_err(|e| ApiError::DatabaseError(e.into()))?; - - Ok(HttpResponse::Ok().json(versions)) -} diff --git a/src/routes/mods.rs b/src/routes/mods.rs index 3f95c93c5..f57015008 100644 --- a/src/routes/mods.rs +++ b/src/routes/mods.rs @@ -223,7 +223,16 @@ fn convert_mod(data: database::models::mod_item::QueryMod) -> models::mods::Mod source_url: m.source_url, wiki_url: m.wiki_url, discord_url: m.discord_url, - donation_urls: None, + donation_urls: Some( + data.donation_urls + .into_iter() + .map(|d| DonationLink { + id: d.platform_short, + platform: d.platform_name, + url: d.url, + }) + .collect(), + ), } } diff --git a/src/routes/version_creation.rs b/src/routes/version_creation.rs index 712fb3920..974a67c40 100644 --- a/src/routes/version_creation.rs +++ b/src/routes/version_creation.rs @@ -49,8 +49,7 @@ pub fn check_version(version: &InitialVersionData) -> Result<(), CreateError> { version .file_parts .iter() - .map(|f| check_length(1..=256, "file part name", f)) - .collect::>()?; + .try_for_each(|f| check_length(1..=256, "file part name", f))?; check_length(1..=64, "version number", &version.version_number)?; check_length(3..=256, "version title", &version.version_title)?; @@ -61,13 +60,11 @@ pub fn check_version(version: &InitialVersionData) -> Result<(), CreateError> { version .game_versions .iter() - .map(|v| check_length(1..=256, "game version", &v.0)) - .collect::>()?; + .try_for_each(|v| check_length(1..=256, "game version", &v.0))?; version .loaders .iter() - .map(|l| check_length(1..=256, "loader name", &l.0)) - .collect::>()?; + .try_for_each(|l| check_length(1..=256, "loader name", &l.0))?; Ok(()) } diff --git a/src/routes/versions.rs b/src/routes/versions.rs index c5194d59a..c499c33d7 100644 --- a/src/routes/versions.rs +++ b/src/routes/versions.rs @@ -54,7 +54,6 @@ pub struct VersionIds { #[get("versions")] pub async fn versions_get( - req: HttpRequest, web::Query(ids): web::Query, pool: web::Data, ) -> Result { @@ -66,39 +65,11 @@ pub async fn versions_get( .await .map_err(|e| ApiError::DatabaseError(e.into()))?; - let user_option = get_user_from_headers(req.headers(), &**pool).await.ok(); - let mut versions = Vec::new(); for version_data in versions_data { if let Some(version) = version_data { - let mut authorized = version.accepted; - - if let Some(user) = &user_option { - if !authorized { - if user.role.is_mod() { - authorized = true; - } else { - let user_id: database::models::ids::UserId = user.id.into(); - - let member_exists = sqlx::query!( - "SELECT EXISTS(SELECT 1 FROM team_members tm INNER JOIN mods m ON m.team_id = tm.team_id AND m.id = $1 WHERE tm.user_id = $2)", - version.mod_id as database::models::ModId, - user_id as database::models::ids::UserId, - ) - .fetch_one(&**pool) - .await - .map_err(|e| ApiError::DatabaseError(e.into()))? - .exists; - - authorized = member_exists.unwrap_or(false); - } - } - } - - if authorized { - versions.push(convert_version(version)); - } + versions.push(convert_version(version)); } } @@ -107,7 +78,6 @@ pub async fn versions_get( #[get("{version_id}")] pub async fn version_get( - req: HttpRequest, info: web::Path<(models::ids::VersionId,)>, pool: web::Data, ) -> Result { @@ -115,33 +85,8 @@ pub async fn version_get( let version_data = database::models::Version::get_full(id.into(), &**pool) .await .map_err(|e| ApiError::DatabaseError(e.into()))?; - let user_option = get_user_from_headers(req.headers(), &**pool).await.ok(); if let Some(data) = version_data { - if !data.accepted { - if let Some(user) = user_option { - if !user.role.is_mod() { - let user_id: database::models::ids::UserId = user.id.into(); - - let member_exists = sqlx::query!( - "SELECT EXISTS(SELECT 1 FROM team_members tm INNER JOIN mods m ON m.team_id = tm.team_id AND m.id = $1 WHERE tm.user_id = $2)", - data.mod_id as database::models::ModId, - user_id as database::models::ids::UserId, - ) - .fetch_one(&**pool) - .await - .map_err(|e| ApiError::DatabaseError(e.into()))? - .exists; - - if !member_exists.unwrap_or(false) { - return Ok(HttpResponse::NotFound().body("")); - } - } - } else { - return Ok(HttpResponse::NotFound().body("")); - } - } - Ok(HttpResponse::Ok().json(convert_version(data))) } else { Ok(HttpResponse::NotFound().body("")) @@ -212,7 +157,6 @@ pub struct EditVersion { pub dependencies: Option>, pub game_versions: Option>, pub loaders: Option>, - pub accepted: Option, pub featured: Option, pub primary_file: Option<(String, String)>, } @@ -262,28 +206,6 @@ pub async fn version_edit( .await .map_err(|e| ApiError::DatabaseError(e.into()))?; - if let Some(accepted) = &new_version.accepted { - if !user.role.is_mod() { - return Err(ApiError::CustomAuthenticationError( - "You do not have the permissions to edit the approval of this version!" - .to_string(), - )); - } - - sqlx::query!( - " - UPDATE versions - SET accepted = $1 - WHERE (id = $2) - ", - accepted, - id as database::models::ids::VersionId, - ) - .execute(&mut *transaction) - .await - .map_err(|e| ApiError::DatabaseError(e.into()))?; - } - if let Some(name) = &new_version.name { sqlx::query!( " diff --git a/src/search/indexing/local_import.rs b/src/search/indexing/local_import.rs index 5833f7e1c..9f6cdac26 100644 --- a/src/search/indexing/local_import.rs +++ b/src/search/indexing/local_import.rs @@ -2,6 +2,7 @@ use futures::{StreamExt, TryStreamExt}; use log::info; use super::IndexingError; +use crate::models::mods::SideType; use crate::search::UploadSearchMod; use sqlx::postgres::PgPool; use std::borrow::Cow; @@ -14,7 +15,7 @@ pub async fn index_local(pool: PgPool) -> Result, IndexingE let mut mods = sqlx::query!( " - SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status, m.slug FROM mods m + SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status, m.slug, m.license, m.client_side, m.server_side FROM mods m " ).fetch(&pool); @@ -112,6 +113,38 @@ pub async fn index_local(pool: PgPool) -> Result, IndexingE .map(Cow::Owned) .unwrap_or_else(|| Cow::Borrowed("")); + let client_side = SideType::from_str( + &sqlx::query!( + " + SELECT name FROM side_types + WHERE id = $1 + ", + mod_data.client_side, + ) + .fetch_one(&pool) + .await? + .name, + ); + + let server_side = SideType::from_str( + &sqlx::query!( + " + SELECT name FROM side_types + WHERE id = $1 + ", + mod_data.server_side, + ) + .fetch_one(&pool) + .await? + .name, + ); + + let license = crate::database::models::categories::License::get( + crate::database::models::LicenseId(mod_data.license), + &pool, + ) + .await?; + docs_to_add.push(UploadSearchMod { mod_id: format!("local-{}", mod_id), title: mod_data.title, @@ -128,6 +161,9 @@ pub async fn index_local(pool: PgPool) -> Result, IndexingE date_modified: mod_data.updated, modified_timestamp: mod_data.updated.timestamp(), latest_version, + license: license.short, + client_side: client_side.to_string(), + server_side: server_side.to_string(), host: Cow::Borrowed("modrinth"), slug: mod_data.slug, }); @@ -143,7 +179,7 @@ pub async fn query_one( ) -> Result { let mod_data = sqlx::query!( " - SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.slug + SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.slug, m.license, m.client_side, m.server_side FROM mods m WHERE id = $1 ", @@ -225,6 +261,38 @@ pub async fn query_one( .map(Cow::Owned) .unwrap_or_else(|| Cow::Borrowed("")); + let client_side = SideType::from_str( + &sqlx::query!( + " + SELECT name FROM side_types + WHERE id = $1 + ", + mod_data.client_side, + ) + .fetch_one(&mut *exec) + .await? + .name, + ); + + let server_side = SideType::from_str( + &sqlx::query!( + " + SELECT name FROM side_types + WHERE id = $1 + ", + mod_data.server_side, + ) + .fetch_one(&mut *exec) + .await? + .name, + ); + + let license = crate::database::models::categories::License::get( + crate::database::models::LicenseId(mod_data.license), + &mut *exec, + ) + .await?; + Ok(UploadSearchMod { mod_id: format!("local-{}", mod_id), title: mod_data.title, @@ -241,6 +309,9 @@ pub async fn query_one( date_modified: mod_data.updated, modified_timestamp: mod_data.updated.timestamp(), latest_version, + license: license.short, + client_side: client_side.to_string(), + server_side: server_side.to_string(), host: Cow::Borrowed("modrinth"), slug: mod_data.slug, }) diff --git a/src/search/indexing/mod.rs b/src/search/indexing/mod.rs index b215bc3f3..9e66cc5c9 100644 --- a/src/search/indexing/mod.rs +++ b/src/search/indexing/mod.rs @@ -15,14 +15,14 @@ use thiserror::Error; pub enum IndexingError { #[error("Error while connecting to the MeiliSearch database")] IndexDBError(#[from] meilisearch_sdk::errors::Error), - #[error("Error while importing mods from CurseForge")] - CurseforgeImportError(#[from] reqwest::Error), #[error("Error while serializing or deserializing JSON: {0}")] SerDeError(#[from] serde_json::Error), #[error("Error while parsing a timestamp: {0}")] ParseDateError(#[from] chrono::format::ParseError), #[error("Database Error: {0}")] - DatabaseError(#[from] sqlx::error::Error), + SqlxError(#[from] sqlx::error::Error), + #[error("Database Error: {0}")] + DatabaseError(#[from] crate::database::models::DatabaseError), #[error("Environment Error")] EnvError(#[from] dotenv::Error), } @@ -268,6 +268,9 @@ fn default_settings() -> Settings { String::from("categories"), String::from("host"), String::from("versions"), + String::from("license"), + String::from("client_side"), + String::from("server_side"), ]) } diff --git a/src/search/mod.rs b/src/search/mod.rs index 43371f751..87bef0060 100644 --- a/src/search/mod.rs +++ b/src/search/mod.rs @@ -73,6 +73,9 @@ pub struct UploadSearchMod { pub icon_url: String, pub author_url: String, pub latest_version: Cow<'static, str>, + pub license: String, + pub client_side: String, + pub server_side: String, /// RFC 3339 formatted creation date of the mod pub date_created: DateTime, @@ -113,6 +116,9 @@ pub struct ResultSearchMod { /// RFC 3339 formatted modification date of the mod pub date_modified: String, pub latest_version: String, + pub license: String, + pub client_side: String, + pub server_side: String, /// The host of the mod: Either `modrinth` or `curseforge` pub host: String,