You've already forked AstralRinth
forked from didirus/AstralRinth
Links (#763)
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE mods\n SET source_url = $1\n WHERE (id = $2)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "04345d9c23430267f755b1420520df91bd403524fd60ba1a94e3a239ea70cae7"
|
|
||||||
}
|
|
||||||
16
.sqlx/query-268af672e8e475885c18da9edd81bac19f3a78a8a462bf9bb2dbe0a72c2f1ff7.json
generated
Normal file
16
.sqlx/query-268af672e8e475885c18da9edd81bac19f3a78a8a462bf9bb2dbe0a72c2f1ff7.json
generated
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n INSERT INTO mods_links (\n joining_mod_id, joining_platform_id, url\n )\n SELECT * FROM UNNEST($1::bigint[], $2::int[], $3::varchar[])\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8Array",
|
||||||
|
"Int4Array",
|
||||||
|
"VarcharArray"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "268af672e8e475885c18da9edd81bac19f3a78a8a462bf9bb2dbe0a72c2f1ff7"
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE mods\n SET discord_url = $1\n WHERE (id = $2)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "2b8dafe9c3df9fd25235a13868e8e7607decfbe96a413cc576919a1fb510f269"
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n DELETE FROM mods_donations\n WHERE joining_mod_id = $1\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "4567790f0dc98ff20b596a33161d1f6ac8af73da67fe8c54192724626c6bf670"
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n INSERT INTO mods_donations (\n joining_mod_id, joining_platform_id, url\n )\n SELECT * FROM UNNEST($1::bigint[], $2::int[], $3::varchar[])\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8Array",
|
|
||||||
"Int4Array",
|
|
||||||
"VarcharArray"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "473db826b691ae1131990ef0927cfe5b63d48829dd41edb7def22248d5668ac7"
|
|
||||||
}
|
|
||||||
15
.sqlx/query-4d0e2d4345aeab5ee7eed847c03c913073eeb43caaf299cddcac6e41351661fd.json
generated
Normal file
15
.sqlx/query-4d0e2d4345aeab5ee7eed847c03c913073eeb43caaf299cddcac6e41351661fd.json
generated
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n DELETE FROM mods_links\n WHERE joining_mod_id = $1 AND joining_platform_id IN (\n SELECT id FROM link_platforms WHERE name = ANY($2)\n )\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"TextArray"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "4d0e2d4345aeab5ee7eed847c03c913073eeb43caaf299cddcac6e41351661fd"
|
||||||
|
}
|
||||||
16
.sqlx/query-5db4b2678406a9977c1e37409920804e0225181befe8b784dea48e37e30fedcc.json
generated
Normal file
16
.sqlx/query-5db4b2678406a9977c1e37409920804e0225181befe8b784dea48e37e30fedcc.json
generated
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)\n VALUES ($1, $2, $3)\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"Int4",
|
||||||
|
"Varchar"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "5db4b2678406a9977c1e37409920804e0225181befe8b784dea48e37e30fedcc"
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n INSERT INTO mods_donations (joining_mod_id, joining_platform_id, url)\n VALUES ($1, $2, $3)\n ",
|
"query": "\n INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)\n VALUES ($1, $2, $3)\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
@@ -12,5 +12,5 @@
|
|||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "07ebc9dc82cd012cd4f5880b1eb3d82602c195a3e3ddd557103ee037aa6dad1c"
|
"hash": "5e7146bc9dc9145cf3d01875ee599ada89e28c63fd10b3f23680d6660d0e57a2"
|
||||||
}
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE mods\n SET source_url = $1\n WHERE (id = $2)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "83d428e1c07d16e356ef26bdf1d707940b1683b5f631ded1f6674a081453d67b"
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n INSERT INTO mods (\n id, team_id, title, description, body,\n published, downloads, icon_url, issues_url,\n source_url, wiki_url, status, requested_status, discord_url,\n license_url, license,\n slug, color, monetization_status\n )\n VALUES (\n $1, $2, $3, $4, $5,\n $6, $7, $8, $9,\n $10, $11, $12, $13, $14,\n $15, $16, \n LOWER($17), $18, $19\n )\n ",
|
"query": "\n INSERT INTO mods (\n id, team_id, title, description, body,\n published, downloads, icon_url, status, requested_status,\n license_url, license,\n slug, color, monetization_status\n )\n VALUES (\n $1, $2, $3, $4, $5, $6, \n $7, $8, $9, $10, \n $11, $12, \n LOWER($13), $14, $15\n )\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
"Varchar",
|
"Varchar",
|
||||||
"Varchar",
|
"Varchar",
|
||||||
"Varchar",
|
"Varchar",
|
||||||
"Varchar",
|
|
||||||
"Varchar",
|
|
||||||
"Varchar",
|
|
||||||
"Varchar",
|
|
||||||
"Text",
|
"Text",
|
||||||
"Int4",
|
"Int4",
|
||||||
"Varchar"
|
"Varchar"
|
||||||
@@ -28,5 +24,5 @@
|
|||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "fefb4f07a0f0c0cf74e554d120f8707d698fc8b4dbb66d2830f4ec0229bc1019"
|
"hash": "83dc16cc7a0f4507e308a06f4924065e4ea25de0210be222ceae8eb645f888e3"
|
||||||
}
|
}
|
||||||
14
.sqlx/query-872374755deb5d68092dff9fcbc355da7c5c9cea4b471e79b17c4a9cfd6f9954.json
generated
Normal file
14
.sqlx/query-872374755deb5d68092dff9fcbc355da7c5c9cea4b471e79b17c4a9cfd6f9954.json
generated
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n DELETE FROM mods_links\n WHERE joining_mod_id = $1\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "872374755deb5d68092dff9fcbc355da7c5c9cea4b471e79b17c4a9cfd6f9954"
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
15
.sqlx/query-88a085c2f2b1aa11eacdeedb68b490a695ebf2a9efb24bd5715b8d903f57e2c5.json
generated
Normal file
15
.sqlx/query-88a085c2f2b1aa11eacdeedb68b490a695ebf2a9efb24bd5715b8d903f57e2c5.json
generated
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n DELETE FROM mods_links\n WHERE joining_mod_id = $1 AND joining_platform_id IN (\n SELECT id FROM link_platforms WHERE name = ANY($2)\n )\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"TextArray"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "88a085c2f2b1aa11eacdeedb68b490a695ebf2a9efb24bd5715b8d903f57e2c5"
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE mods\n SET wiki_url = $1\n WHERE (id = $2)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "8abb317c85f48c7dd9ccf4a7b8fbc0b58ac73f7ae87ff2dfe67009a51089f784"
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE mods\n SET wiki_url = $1\n WHERE (id = $2)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "99a1eac69d7f5a5139703df431e6a5c3012a90143a8c635f93632f04d0bc41d4"
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n INSERT INTO mods_donations (joining_mod_id, joining_platform_id, url)\n VALUES ($1, $2, $3)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Int4",
|
|
||||||
"Varchar"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "9aab2350d576fd934b0541d1f71f320ac939b44a179fee3d1638113cdb3ddfe7"
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n DELETE FROM mods_donations\n WHERE joining_mod_id = $1\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "acbafe265c4b7a1c95b0494a0a03c8bd2cd778ae561ef5a662fa931ca26cf603"
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n SELECT id FROM donation_platforms\n WHERE short = $1\n ",
|
"query": "\n SELECT id FROM link_platforms\n WHERE name = $1\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -18,5 +18,5 @@
|
|||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "d8020ed838c032c2c287dc0f08989b3ab7156f2571bc75505e6f57b0caeef9c7"
|
"hash": "b1bfb62f4a28ca0fae778738e8a8f325185a83c5d5a240c088a2397b35c55f2a"
|
||||||
}
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE mods\n SET discord_url = $1\n WHERE (id = $2)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "bad7cae347771e801976c26f2afaf33bda371051923b8f74a2f32a0ef5c65e57"
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE mods\n SET issues_url = $1\n WHERE (id = $2)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "bc91841f9672608a28bd45a862919f2bd34fac0b3479e3b4b67a9f6bea2a562a"
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n UPDATE mods\n SET issues_url = $1\n WHERE (id = $2)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "e3fb74a94a6a78b1007dd99ad11bdcfaa0957ed7d1683997aef7301e0f15baba"
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n SELECT id, short, name FROM donation_platforms\n ",
|
"query": "\n SELECT id, name, donation FROM link_platforms\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -10,13 +10,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ordinal": 1,
|
"ordinal": 1,
|
||||||
"name": "short",
|
"name": "name",
|
||||||
"type_info": "Varchar"
|
"type_info": "Varchar"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ordinal": 2,
|
"ordinal": 2,
|
||||||
"name": "name",
|
"name": "donation",
|
||||||
"type_info": "Varchar"
|
"type_info": "Bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
@@ -28,5 +28,5 @@
|
|||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "76db1c204139e18002e5751c3dcefff79791a1dd852b62d34fcf008151e8945a"
|
"hash": "fef7802edefa1a6957fa43ccf64b987c3547294f0c8581028ac6b83de42b3a00"
|
||||||
}
|
}
|
||||||
69
migrations/20231117073600_links_overhaul.sql
Normal file
69
migrations/20231117073600_links_overhaul.sql
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
CREATE TABLE link_platforms (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR(16) UNIQUE NOT NULL,
|
||||||
|
|
||||||
|
-- Used for v2 conversion
|
||||||
|
donation BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
-- Will be removed at the end of the migration
|
||||||
|
donation_platform_id INTEGER REFERENCES donation_platforms (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO link_platforms (donation_platform_id, name, donation)
|
||||||
|
SELECT id, short, true FROM donation_platforms;
|
||||||
|
|
||||||
|
INSERT INTO link_platforms (name, donation) VALUES ('issues', false);
|
||||||
|
INSERT INTO link_platforms (name, donation) VALUES ('wiki', false);
|
||||||
|
INSERT INTO link_platforms (name, donation) VALUES ('discord', false);
|
||||||
|
INSERT INTO link_platforms (name, donation) VALUES ('source', false);
|
||||||
|
INSERT INTO link_platforms (name, donation) VALUES ('site', false);
|
||||||
|
|
||||||
|
CREATE TABLE mods_links (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
joining_mod_id BIGINT NOT NULL REFERENCES mods (id),
|
||||||
|
joining_platform_id INTEGER NOT NULL REFERENCES link_platforms (id),
|
||||||
|
url VARCHAR(255) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
|
||||||
|
SELECT DISTINCT m.id, lp.id, md.url
|
||||||
|
FROM mods m
|
||||||
|
INNER JOIN mods_donations md ON m.id = md.joining_mod_id
|
||||||
|
INNER JOIN donation_platforms dp ON dp.id = md.joining_platform_id
|
||||||
|
INNER JOIN link_platforms lp ON lp.donation_platform_id = dp.id;
|
||||||
|
|
||||||
|
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
|
||||||
|
SELECT DISTINCT m.id, lp.id, issues_url
|
||||||
|
FROM mods m
|
||||||
|
CROSS JOIN link_platforms lp
|
||||||
|
WHERE issues_url IS NOT NULL
|
||||||
|
AND lp.name = 'issues';
|
||||||
|
|
||||||
|
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
|
||||||
|
SELECT DISTINCT m.id, lp.id, wiki_url
|
||||||
|
FROM mods m
|
||||||
|
CROSS JOIN link_platforms lp
|
||||||
|
WHERE wiki_url IS NOT NULL
|
||||||
|
AND lp.name = 'wiki';
|
||||||
|
|
||||||
|
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
|
||||||
|
SELECT DISTINCT m.id, lp.id, discord_url
|
||||||
|
FROM mods m
|
||||||
|
CROSS JOIN link_platforms lp
|
||||||
|
WHERE discord_url IS NOT NULL
|
||||||
|
AND lp.name = 'discord';
|
||||||
|
|
||||||
|
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
|
||||||
|
SELECT DISTINCT m.id, lp.id, source_url
|
||||||
|
FROM mods m
|
||||||
|
CROSS JOIN link_platforms lp
|
||||||
|
WHERE source_url IS NOT NULL
|
||||||
|
AND lp.name = 'source';
|
||||||
|
|
||||||
|
ALTER TABLE mods DROP COLUMN issues_url;
|
||||||
|
ALTER TABLE mods DROP COLUMN wiki_url;
|
||||||
|
ALTER TABLE mods DROP COLUMN discord_url;
|
||||||
|
ALTER TABLE mods DROP COLUMN source_url;
|
||||||
|
|
||||||
|
ALTER TABLE link_platforms DROP COLUMN donation_platform_id;
|
||||||
|
DROP TABLE mods_donations;
|
||||||
|
DROP TABLE donation_platforms;
|
||||||
@@ -29,10 +29,10 @@ pub struct ReportType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct DonationPlatform {
|
pub struct LinkPlatform {
|
||||||
pub id: DonationPlatformId,
|
pub id: LinkPlatformId,
|
||||||
pub short: String,
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub donation: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Category {
|
impl Category {
|
||||||
@@ -129,38 +129,32 @@ impl Category {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DonationPlatform {
|
impl LinkPlatform {
|
||||||
pub async fn get_id<'a, E>(
|
pub async fn get_id<'a, E>(id: &str, exec: E) -> Result<Option<LinkPlatformId>, DatabaseError>
|
||||||
id: &str,
|
|
||||||
exec: E,
|
|
||||||
) -> Result<Option<DonationPlatformId>, DatabaseError>
|
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT id FROM donation_platforms
|
SELECT id FROM link_platforms
|
||||||
WHERE short = $1
|
WHERE name = $1
|
||||||
",
|
",
|
||||||
id
|
id
|
||||||
)
|
)
|
||||||
.fetch_optional(exec)
|
.fetch_optional(exec)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(result.map(|r| DonationPlatformId(r.id)))
|
Ok(result.map(|r| LinkPlatformId(r.id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list<'a, E>(
|
pub async fn list<'a, E>(exec: E, redis: &RedisPool) -> Result<Vec<LinkPlatform>, DatabaseError>
|
||||||
exec: E,
|
|
||||||
redis: &RedisPool,
|
|
||||||
) -> Result<Vec<DonationPlatform>, DatabaseError>
|
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
|
|
||||||
let res: Option<Vec<DonationPlatform>> = redis
|
let res: Option<Vec<LinkPlatform>> = redis
|
||||||
.get_deserialized_from_json(TAGS_NAMESPACE, "donation_platform")
|
.get_deserialized_from_json(TAGS_NAMESPACE, "link_platform")
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(res) = res {
|
if let Some(res) = res {
|
||||||
@@ -169,22 +163,22 @@ impl DonationPlatform {
|
|||||||
|
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT id, short, name FROM donation_platforms
|
SELECT id, name, donation FROM link_platforms
|
||||||
"
|
"
|
||||||
)
|
)
|
||||||
.fetch_many(exec)
|
.fetch_many(exec)
|
||||||
.try_filter_map(|e| async {
|
.try_filter_map(|e| async {
|
||||||
Ok(e.right().map(|c| DonationPlatform {
|
Ok(e.right().map(|c| LinkPlatform {
|
||||||
id: DonationPlatformId(c.id),
|
id: LinkPlatformId(c.id),
|
||||||
short: c.short,
|
|
||||||
name: c.name,
|
name: c.name,
|
||||||
|
donation: c.donation,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
.try_collect::<Vec<DonationPlatform>>()
|
.try_collect::<Vec<LinkPlatform>>()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
redis
|
redis
|
||||||
.set_serialized_to_json(TAGS_NAMESPACE, "donation_platform", &result, None)
|
.set_serialized_to_json(TAGS_NAMESPACE, "link_platform", &result, None)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
|||||||
@@ -223,9 +223,9 @@ pub struct SideTypeId(pub i32);
|
|||||||
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize)]
|
||||||
#[sqlx(transparent)]
|
#[sqlx(transparent)]
|
||||||
pub struct GameId(pub i32);
|
pub struct GameId(pub i32);
|
||||||
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||||
#[sqlx(transparent)]
|
#[sqlx(transparent)]
|
||||||
pub struct DonationPlatformId(pub i32);
|
pub struct LinkPlatformId(pub i32);
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Copy, Clone, Debug, Type, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord,
|
Copy, Clone, Debug, Type, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord,
|
||||||
|
|||||||
@@ -15,26 +15,26 @@ pub const PROJECTS_SLUGS_NAMESPACE: &str = "projects_slugs";
|
|||||||
const PROJECTS_DEPENDENCIES_NAMESPACE: &str = "projects_dependencies";
|
const PROJECTS_DEPENDENCIES_NAMESPACE: &str = "projects_dependencies";
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct DonationUrl {
|
pub struct LinkUrl {
|
||||||
pub platform_id: DonationPlatformId,
|
pub platform_id: LinkPlatformId,
|
||||||
pub platform_short: String,
|
|
||||||
pub platform_name: String,
|
pub platform_name: String,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
pub donation: bool, // Is this a donation link
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DonationUrl {
|
impl LinkUrl {
|
||||||
pub async fn insert_many_projects(
|
pub async fn insert_many_projects(
|
||||||
donation_urls: Vec<Self>,
|
links: Vec<Self>,
|
||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||||
) -> Result<(), sqlx::error::Error> {
|
) -> Result<(), sqlx::error::Error> {
|
||||||
let (project_ids, platform_ids, urls): (Vec<_>, Vec<_>, Vec<_>) = donation_urls
|
let (project_ids, platform_ids, urls): (Vec<_>, Vec<_>, Vec<_>) = links
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|url| (project_id.0, url.platform_id.0, url.url))
|
.map(|url| (project_id.0, url.platform_id.0, url.url))
|
||||||
.multiunzip();
|
.multiunzip();
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
INSERT INTO mods_donations (
|
INSERT INTO mods_links (
|
||||||
joining_mod_id, joining_platform_id, url
|
joining_mod_id, joining_platform_id, url
|
||||||
)
|
)
|
||||||
SELECT * FROM UNNEST($1::bigint[], $2::int[], $3::varchar[])
|
SELECT * FROM UNNEST($1::bigint[], $2::int[], $3::varchar[])
|
||||||
@@ -148,11 +148,7 @@ pub struct ProjectBuilder {
|
|||||||
pub description: String,
|
pub description: String,
|
||||||
pub body: String,
|
pub body: String,
|
||||||
pub icon_url: Option<String>,
|
pub icon_url: Option<String>,
|
||||||
pub issues_url: Option<String>,
|
|
||||||
pub source_url: Option<String>,
|
|
||||||
pub wiki_url: Option<String>,
|
|
||||||
pub license_url: Option<String>,
|
pub license_url: Option<String>,
|
||||||
pub discord_url: Option<String>,
|
|
||||||
pub categories: Vec<CategoryId>,
|
pub categories: Vec<CategoryId>,
|
||||||
pub additional_categories: Vec<CategoryId>,
|
pub additional_categories: Vec<CategoryId>,
|
||||||
pub initial_versions: Vec<super::version_item::VersionBuilder>,
|
pub initial_versions: Vec<super::version_item::VersionBuilder>,
|
||||||
@@ -160,7 +156,7 @@ pub struct ProjectBuilder {
|
|||||||
pub requested_status: Option<ProjectStatus>,
|
pub requested_status: Option<ProjectStatus>,
|
||||||
pub license: String,
|
pub license: String,
|
||||||
pub slug: Option<String>,
|
pub slug: Option<String>,
|
||||||
pub donation_urls: Vec<DonationUrl>,
|
pub link_urls: Vec<LinkUrl>,
|
||||||
pub gallery_items: Vec<GalleryItem>,
|
pub gallery_items: Vec<GalleryItem>,
|
||||||
pub color: Option<u32>,
|
pub color: Option<u32>,
|
||||||
pub monetization_status: MonetizationStatus,
|
pub monetization_status: MonetizationStatus,
|
||||||
@@ -192,11 +188,7 @@ impl ProjectBuilder {
|
|||||||
downloads: 0,
|
downloads: 0,
|
||||||
follows: 0,
|
follows: 0,
|
||||||
icon_url: self.icon_url,
|
icon_url: self.icon_url,
|
||||||
issues_url: self.issues_url,
|
|
||||||
source_url: self.source_url,
|
|
||||||
wiki_url: self.wiki_url,
|
|
||||||
license_url: self.license_url,
|
license_url: self.license_url,
|
||||||
discord_url: self.discord_url,
|
|
||||||
license: self.license,
|
license: self.license,
|
||||||
slug: self.slug,
|
slug: self.slug,
|
||||||
moderation_message: None,
|
moderation_message: None,
|
||||||
@@ -209,7 +201,7 @@ impl ProjectBuilder {
|
|||||||
project_struct.insert(&mut *transaction).await?;
|
project_struct.insert(&mut *transaction).await?;
|
||||||
|
|
||||||
let ProjectBuilder {
|
let ProjectBuilder {
|
||||||
donation_urls,
|
link_urls,
|
||||||
gallery_items,
|
gallery_items,
|
||||||
categories,
|
categories,
|
||||||
additional_categories,
|
additional_categories,
|
||||||
@@ -221,8 +213,7 @@ impl ProjectBuilder {
|
|||||||
version.insert(&mut *transaction).await?;
|
version.insert(&mut *transaction).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
DonationUrl::insert_many_projects(donation_urls, self.project_id, &mut *transaction)
|
LinkUrl::insert_many_projects(link_urls, self.project_id, &mut *transaction).await?;
|
||||||
.await?;
|
|
||||||
|
|
||||||
GalleryItem::insert_many(gallery_items, self.project_id, &mut *transaction).await?;
|
GalleryItem::insert_many(gallery_items, self.project_id, &mut *transaction).await?;
|
||||||
|
|
||||||
@@ -259,11 +250,7 @@ pub struct Project {
|
|||||||
pub downloads: i32,
|
pub downloads: i32,
|
||||||
pub follows: i32,
|
pub follows: i32,
|
||||||
pub icon_url: Option<String>,
|
pub icon_url: Option<String>,
|
||||||
pub issues_url: Option<String>,
|
|
||||||
pub source_url: Option<String>,
|
|
||||||
pub wiki_url: Option<String>,
|
|
||||||
pub license_url: Option<String>,
|
pub license_url: Option<String>,
|
||||||
pub discord_url: Option<String>,
|
|
||||||
pub license: String,
|
pub license: String,
|
||||||
pub slug: Option<String>,
|
pub slug: Option<String>,
|
||||||
pub moderation_message: Option<String>,
|
pub moderation_message: Option<String>,
|
||||||
@@ -283,17 +270,15 @@ impl Project {
|
|||||||
"
|
"
|
||||||
INSERT INTO mods (
|
INSERT INTO mods (
|
||||||
id, team_id, title, description, body,
|
id, team_id, title, description, body,
|
||||||
published, downloads, icon_url, issues_url,
|
published, downloads, icon_url, status, requested_status,
|
||||||
source_url, wiki_url, status, requested_status, discord_url,
|
|
||||||
license_url, license,
|
license_url, license,
|
||||||
slug, color, monetization_status
|
slug, color, monetization_status
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
$1, $2, $3, $4, $5,
|
$1, $2, $3, $4, $5, $6,
|
||||||
$6, $7, $8, $9,
|
$7, $8, $9, $10,
|
||||||
$10, $11, $12, $13, $14,
|
$11, $12,
|
||||||
$15, $16,
|
LOWER($13), $14, $15
|
||||||
LOWER($17), $18, $19
|
|
||||||
)
|
)
|
||||||
",
|
",
|
||||||
self.id as ProjectId,
|
self.id as ProjectId,
|
||||||
@@ -304,12 +289,8 @@ impl Project {
|
|||||||
self.published,
|
self.published,
|
||||||
self.downloads,
|
self.downloads,
|
||||||
self.icon_url.as_ref(),
|
self.icon_url.as_ref(),
|
||||||
self.issues_url.as_ref(),
|
|
||||||
self.source_url.as_ref(),
|
|
||||||
self.wiki_url.as_ref(),
|
|
||||||
self.status.as_str(),
|
self.status.as_str(),
|
||||||
self.requested_status.map(|x| x.as_str()),
|
self.requested_status.map(|x| x.as_str()),
|
||||||
self.discord_url.as_ref(),
|
|
||||||
self.license_url.as_ref(),
|
self.license_url.as_ref(),
|
||||||
&self.license,
|
&self.license,
|
||||||
self.slug.as_ref(),
|
self.slug.as_ref(),
|
||||||
@@ -384,7 +365,7 @@ impl Project {
|
|||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
DELETE FROM mods_donations
|
DELETE FROM mods_links
|
||||||
WHERE joining_mod_id = $1
|
WHERE joining_mod_id = $1
|
||||||
",
|
",
|
||||||
id as ProjectId,
|
id as ProjectId,
|
||||||
@@ -650,23 +631,23 @@ impl Project {
|
|||||||
WHERE m.id = ANY($1) OR m.slug = ANY($2)
|
WHERE m.id = ANY($1) OR m.slug = ANY($2)
|
||||||
GROUP BY mod_id
|
GROUP BY mod_id
|
||||||
),
|
),
|
||||||
donations_json AS (
|
links_json AS (
|
||||||
SELECT DISTINCT joining_mod_id as mod_id,
|
SELECT DISTINCT joining_mod_id as mod_id,
|
||||||
JSONB_AGG(
|
JSONB_AGG(
|
||||||
DISTINCT jsonb_build_object(
|
DISTINCT jsonb_build_object(
|
||||||
'platform_id', md.joining_platform_id, 'platform_short', dp.short, 'platform_name', dp.name,'url', md.url
|
'platform_id', ml.joining_platform_id, 'platform_name', lp.name,'url', ml.url, 'donation', lp.donation
|
||||||
)
|
)
|
||||||
) filter (where md.joining_platform_id is not null) donations_json
|
) filter (where ml.joining_platform_id is not null) links_json
|
||||||
FROM mods_donations md
|
FROM mods_links ml
|
||||||
INNER JOIN mods m ON md.joining_mod_id = m.id AND m.id = ANY($1) OR m.slug = ANY($2)
|
INNER JOIN mods m ON ml.joining_mod_id = m.id AND m.id = ANY($1) OR m.slug = ANY($2)
|
||||||
INNER JOIN donation_platforms dp ON md.joining_platform_id = dp.id
|
INNER JOIN link_platforms lp ON ml.joining_platform_id = lp.id
|
||||||
GROUP BY mod_id
|
GROUP BY mod_id
|
||||||
)
|
)
|
||||||
|
|
||||||
SELECT m.id id, m.title title, m.description description, m.downloads downloads, m.follows follows,
|
SELECT m.id id, m.title title, m.description description, m.downloads downloads, m.follows follows,
|
||||||
m.icon_url icon_url, m.body body, m.published published,
|
m.icon_url icon_url, m.body body, m.published published,
|
||||||
m.updated updated, m.approved approved, m.queued, m.status status, m.requested_status requested_status,
|
m.updated updated, m.approved approved, m.queued, m.status status, m.requested_status requested_status,
|
||||||
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
|
m.license_url license_url,
|
||||||
m.team_id team_id, m.organization_id organization_id, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,
|
m.team_id team_id, m.organization_id organization_id, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,
|
||||||
m.webhook_sent, m.color,
|
m.webhook_sent, m.color,
|
||||||
t.id thread_id, m.monetization_status monetization_status,
|
t.id thread_id, m.monetization_status monetization_status,
|
||||||
@@ -677,14 +658,14 @@ impl Project {
|
|||||||
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,
|
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,
|
||||||
v.versions_json versions,
|
v.versions_json versions,
|
||||||
mg.mods_gallery_json gallery,
|
mg.mods_gallery_json gallery,
|
||||||
md.donations_json donations,
|
ml.links_json links,
|
||||||
vf.version_fields_json version_fields,
|
vf.version_fields_json version_fields,
|
||||||
lf.loader_fields_json loader_fields,
|
lf.loader_fields_json loader_fields,
|
||||||
lfev.loader_field_enum_values_json loader_field_enum_values
|
lfev.loader_field_enum_values_json loader_field_enum_values
|
||||||
FROM mods m
|
FROM mods m
|
||||||
INNER JOIN threads t ON t.mod_id = m.id
|
INNER JOIN threads t ON t.mod_id = m.id
|
||||||
LEFT JOIN mods_gallery_json mg ON mg.mod_id = m.id
|
LEFT JOIN mods_gallery_json mg ON mg.mod_id = m.id
|
||||||
LEFT JOIN donations_json md ON md.mod_id = m.id
|
LEFT JOIN links_json ml ON ml.mod_id = m.id
|
||||||
LEFT JOIN mods_categories mc ON mc.joining_mod_id = m.id
|
LEFT JOIN mods_categories mc ON mc.joining_mod_id = m.id
|
||||||
LEFT JOIN categories c ON mc.joining_category_id = c.id
|
LEFT JOIN categories c ON mc.joining_category_id = c.id
|
||||||
LEFT JOIN versions_json v ON v.mod_id = m.id
|
LEFT JOIN versions_json v ON v.mod_id = m.id
|
||||||
@@ -697,7 +678,7 @@ impl Project {
|
|||||||
LEFT OUTER JOIN loader_fields_json lf ON m.id = lf.mod_id
|
LEFT OUTER JOIN loader_fields_json lf ON m.id = lf.mod_id
|
||||||
LEFT OUTER JOIN loader_field_enum_values_json lfev ON m.id = lfev.mod_id
|
LEFT OUTER JOIN loader_field_enum_values_json lfev ON m.id = lfev.mod_id
|
||||||
WHERE m.id = ANY($1) OR m.slug = ANY($2)
|
WHERE m.id = ANY($1) OR m.slug = ANY($2)
|
||||||
GROUP BY t.id, m.id, version_fields_json, loader_fields_json, loader_field_enum_values_json, versions_json, mods_gallery_json, donations_json;
|
GROUP BY t.id, m.id, version_fields_json, loader_fields_json, loader_field_enum_values_json, versions_json, mods_gallery_json, links_json;
|
||||||
",
|
",
|
||||||
&project_ids_parsed,
|
&project_ids_parsed,
|
||||||
&remaining_strings.into_iter().map(|x| x.to_string().to_lowercase()).collect::<Vec<_>>(),
|
&remaining_strings.into_iter().map(|x| x.to_string().to_lowercase()).collect::<Vec<_>>(),
|
||||||
@@ -719,11 +700,7 @@ impl Project {
|
|||||||
icon_url: m.icon_url.clone(),
|
icon_url: m.icon_url.clone(),
|
||||||
published: m.published,
|
published: m.published,
|
||||||
updated: m.updated,
|
updated: m.updated,
|
||||||
issues_url: m.issues_url.clone(),
|
|
||||||
source_url: m.source_url.clone(),
|
|
||||||
wiki_url: m.wiki_url.clone(),
|
|
||||||
license_url: m.license_url.clone(),
|
license_url: m.license_url.clone(),
|
||||||
discord_url: m.discord_url.clone(),
|
|
||||||
status: ProjectStatus::from_string(
|
status: ProjectStatus::from_string(
|
||||||
&m.status,
|
&m.status,
|
||||||
),
|
),
|
||||||
@@ -774,9 +751,9 @@ impl Project {
|
|||||||
|
|
||||||
gallery
|
gallery
|
||||||
},
|
},
|
||||||
donation_urls: serde_json::from_value(
|
urls: serde_json::from_value(
|
||||||
m.donations.unwrap_or_default(),
|
m.links.unwrap_or_default(),
|
||||||
).ok().unwrap_or_default(),
|
).unwrap_or_default(),
|
||||||
aggregate_version_fields: VersionField::from_query_json(m.loader_fields, m.version_fields, m.loader_field_enum_values, true),
|
aggregate_version_fields: VersionField::from_query_json(m.loader_fields, m.version_fields, m.loader_field_enum_values, true),
|
||||||
thread_id: ThreadId(m.thread_id),
|
thread_id: ThreadId(m.thread_id),
|
||||||
}}))
|
}}))
|
||||||
@@ -894,7 +871,7 @@ pub struct QueryProject {
|
|||||||
pub versions: Vec<VersionId>,
|
pub versions: Vec<VersionId>,
|
||||||
pub project_types: Vec<String>,
|
pub project_types: Vec<String>,
|
||||||
pub games: Vec<String>,
|
pub games: Vec<String>,
|
||||||
pub donation_urls: Vec<DonationUrl>,
|
pub urls: Vec<LinkUrl>,
|
||||||
pub gallery_items: Vec<GalleryItem>,
|
pub gallery_items: Vec<GalleryItem>,
|
||||||
pub thread_id: ThreadId,
|
pub thread_id: ThreadId,
|
||||||
pub aggregate_version_fields: Vec<VersionField>,
|
pub aggregate_version_fields: Vec<VersionField>,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::super::ids::OrganizationId;
|
use super::super::ids::OrganizationId;
|
||||||
@@ -8,13 +10,14 @@ use crate::database::models::{version_item, DatabaseError};
|
|||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::ids::{ProjectId, VersionId};
|
use crate::models::ids::{ProjectId, VersionId};
|
||||||
use crate::models::projects::{
|
use crate::models::projects::{
|
||||||
Dependency, DonationLink, GalleryItem, License, Loader, ModeratorMessage, MonetizationStatus,
|
Dependency, GalleryItem, License, Link, Loader, ModeratorMessage, MonetizationStatus, Project,
|
||||||
Project, ProjectStatus, Version, VersionFile, VersionStatus, VersionType,
|
ProjectStatus, Version, VersionFile, VersionStatus, VersionType,
|
||||||
};
|
};
|
||||||
use crate::models::threads::ThreadId;
|
use crate::models::threads::ThreadId;
|
||||||
use crate::routes::v2_reroute;
|
use crate::routes::v2_reroute;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
/// A project returned from the API
|
/// A project returned from the API
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
@@ -132,6 +135,18 @@ impl LegacyProject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let issues_url = data.link_urls.get("issues").map(|l| l.url.clone());
|
||||||
|
let source_url = data.link_urls.get("source").map(|l| l.url.clone());
|
||||||
|
let wiki_url = data.link_urls.get("wiki").map(|l| l.url.clone());
|
||||||
|
let discord_url = data.link_urls.get("discord").map(|l| l.url.clone());
|
||||||
|
|
||||||
|
let donation_urls = data
|
||||||
|
.link_urls
|
||||||
|
.iter()
|
||||||
|
.filter(|(_, l)| l.donation)
|
||||||
|
.map(|(_, l)| DonationLink::try_from(l.clone()).ok())
|
||||||
|
.collect::<Option<Vec<_>>>();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
slug: data.slug,
|
slug: data.slug,
|
||||||
@@ -157,11 +172,11 @@ impl LegacyProject {
|
|||||||
loaders,
|
loaders,
|
||||||
versions: data.versions,
|
versions: data.versions,
|
||||||
icon_url: data.icon_url,
|
icon_url: data.icon_url,
|
||||||
issues_url: data.issues_url,
|
issues_url,
|
||||||
source_url: data.source_url,
|
source_url,
|
||||||
wiki_url: data.wiki_url,
|
wiki_url,
|
||||||
discord_url: data.discord_url,
|
discord_url,
|
||||||
donation_urls: data.donation_urls,
|
donation_urls,
|
||||||
gallery: data.gallery,
|
gallery: data.gallery,
|
||||||
color: data.color,
|
color: data.color,
|
||||||
thread_id: data.thread_id,
|
thread_id: data.thread_id,
|
||||||
@@ -316,3 +331,36 @@ impl From<Version> for LegacyVersion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Validate, Clone, Eq, PartialEq)]
|
||||||
|
pub struct DonationLink {
|
||||||
|
pub id: String,
|
||||||
|
pub platform: String,
|
||||||
|
#[validate(
|
||||||
|
custom(function = "crate::util::validate::validate_url"),
|
||||||
|
length(max = 2048)
|
||||||
|
)]
|
||||||
|
pub url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<Link> for DonationLink {
|
||||||
|
type Error = String;
|
||||||
|
fn try_from(link: Link) -> Result<Self, String> {
|
||||||
|
if !link.donation {
|
||||||
|
return Err("Not a donation".to_string());
|
||||||
|
}
|
||||||
|
Ok(Self {
|
||||||
|
platform: capitalize_first(&link.platform),
|
||||||
|
url: link.url,
|
||||||
|
id: link.platform,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn capitalize_first(input: &str) -> String {
|
||||||
|
let mut result = input.to_owned();
|
||||||
|
if let Some(first_char) = result.get_mut(0..1) {
|
||||||
|
first_char.make_ascii_uppercase();
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet};
|
|||||||
use super::ids::{Base62Id, OrganizationId};
|
use super::ids::{Base62Id, OrganizationId};
|
||||||
use super::teams::TeamId;
|
use super::teams::TeamId;
|
||||||
use super::users::UserId;
|
use super::users::UserId;
|
||||||
use crate::database::models::project_item::QueryProject;
|
use crate::database::models::project_item::{LinkUrl, QueryProject};
|
||||||
use crate::database::models::version_item::QueryVersion;
|
use crate::database::models::version_item::QueryVersion;
|
||||||
use crate::models::threads::ThreadId;
|
use crate::models::threads::ThreadId;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
@@ -87,16 +87,9 @@ pub struct Project {
|
|||||||
pub versions: Vec<VersionId>,
|
pub versions: Vec<VersionId>,
|
||||||
/// The URL of the icon of the project
|
/// The URL of the icon of the project
|
||||||
pub icon_url: Option<String>,
|
pub icon_url: Option<String>,
|
||||||
/// An optional link to where to submit bugs or issues with the project.
|
|
||||||
pub issues_url: Option<String>,
|
/// A collection of links to the project's various pages.
|
||||||
/// An optional link to the source code for the project.
|
pub link_urls: HashMap<String, Link>,
|
||||||
pub source_url: Option<String>,
|
|
||||||
/// An optional link to the project's wiki page or other relevant information.
|
|
||||||
pub wiki_url: Option<String>,
|
|
||||||
/// An optional link to the project's discord
|
|
||||||
pub discord_url: Option<String>,
|
|
||||||
/// An optional list of all donation links the project has
|
|
||||||
pub donation_urls: Option<Vec<DonationLink>>,
|
|
||||||
|
|
||||||
/// A string of URLs to visual content featuring the project
|
/// A string of URLs to visual content featuring the project
|
||||||
pub gallery: Vec<GalleryItem>,
|
pub gallery: Vec<GalleryItem>,
|
||||||
@@ -206,20 +199,11 @@ impl From<QueryProject> for Project {
|
|||||||
loaders: m.loaders,
|
loaders: m.loaders,
|
||||||
versions: data.versions.into_iter().map(|v| v.into()).collect(),
|
versions: data.versions.into_iter().map(|v| v.into()).collect(),
|
||||||
icon_url: m.icon_url,
|
icon_url: m.icon_url,
|
||||||
issues_url: m.issues_url,
|
link_urls: data
|
||||||
source_url: m.source_url,
|
.urls
|
||||||
wiki_url: m.wiki_url,
|
.into_iter()
|
||||||
discord_url: m.discord_url,
|
.map(|d| (d.platform_name.clone(), Link::from(d)))
|
||||||
donation_urls: Some(
|
.collect(),
|
||||||
data.donation_urls
|
|
||||||
.into_iter()
|
|
||||||
.map(|d| DonationLink {
|
|
||||||
id: d.platform_short,
|
|
||||||
platform: d.platform_name,
|
|
||||||
url: d.url,
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
gallery: data
|
gallery: data
|
||||||
.gallery_items
|
.gallery_items
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -266,15 +250,24 @@ pub struct License {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Validate, Clone, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Validate, Clone, Eq, PartialEq)]
|
||||||
pub struct DonationLink {
|
pub struct Link {
|
||||||
pub id: String,
|
|
||||||
pub platform: String,
|
pub platform: String,
|
||||||
|
pub donation: bool,
|
||||||
#[validate(
|
#[validate(
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
custom(function = "crate::util::validate::validate_url"),
|
||||||
length(max = 2048)
|
length(max = 2048)
|
||||||
)]
|
)]
|
||||||
pub url: String,
|
pub url: String,
|
||||||
}
|
}
|
||||||
|
impl From<LinkUrl> for Link {
|
||||||
|
fn from(data: LinkUrl) -> Self {
|
||||||
|
Self {
|
||||||
|
platform: data.platform_name,
|
||||||
|
donation: data.donation,
|
||||||
|
url: data.url,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A status decides the visibility of a project in search, URLs, and the whole site itself.
|
/// A status decides the visibility of a project in search, URLs, and the whole site itself.
|
||||||
/// Approved - Project is displayed on search, and accessible by URL
|
/// Approved - Project is displayed on search, and accessible by URL
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use crate::database::redis::RedisPool;
|
|||||||
use crate::file_hosting::FileHost;
|
use crate::file_hosting::FileHost;
|
||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::models::ids::ImageId;
|
use crate::models::ids::ImageId;
|
||||||
use crate::models::projects::{DonationLink, Loader, Project, ProjectStatus};
|
use crate::models::projects::{Loader, Project, ProjectStatus};
|
||||||
use crate::models::v2::projects::{LegacyProject, LegacySideType};
|
use crate::models::v2::projects::{DonationLink, LegacyProject, LegacySideType};
|
||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
use crate::routes::v3::project_creation::default_project_type;
|
use crate::routes::v3::project_creation::default_project_type;
|
||||||
use crate::routes::v3::project_creation::{CreateError, NewGalleryItem};
|
use crate::routes::v3::project_creation::{CreateError, NewGalleryItem};
|
||||||
@@ -193,6 +193,25 @@ pub async fn project_create(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let mut link_urls = HashMap::new();
|
||||||
|
if let Some(issue_url) = legacy_create.issues_url {
|
||||||
|
link_urls.insert("issues".to_string(), issue_url);
|
||||||
|
}
|
||||||
|
if let Some(source_url) = legacy_create.source_url {
|
||||||
|
link_urls.insert("source".to_string(), source_url);
|
||||||
|
}
|
||||||
|
if let Some(wiki_url) = legacy_create.wiki_url {
|
||||||
|
link_urls.insert("wiki".to_string(), wiki_url);
|
||||||
|
}
|
||||||
|
if let Some(discord_url) = legacy_create.discord_url {
|
||||||
|
link_urls.insert("discord".to_string(), discord_url);
|
||||||
|
}
|
||||||
|
if let Some(donation_urls) = legacy_create.donation_urls {
|
||||||
|
for donation_url in donation_urls {
|
||||||
|
link_urls.insert(donation_url.platform, donation_url.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(v3::project_creation::ProjectCreateData {
|
Ok(v3::project_creation::ProjectCreateData {
|
||||||
title: legacy_create.title,
|
title: legacy_create.title,
|
||||||
slug: legacy_create.slug,
|
slug: legacy_create.slug,
|
||||||
@@ -201,12 +220,8 @@ pub async fn project_create(
|
|||||||
initial_versions,
|
initial_versions,
|
||||||
categories: legacy_create.categories,
|
categories: legacy_create.categories,
|
||||||
additional_categories: legacy_create.additional_categories,
|
additional_categories: legacy_create.additional_categories,
|
||||||
issues_url: legacy_create.issues_url,
|
|
||||||
source_url: legacy_create.source_url,
|
|
||||||
wiki_url: legacy_create.wiki_url,
|
|
||||||
license_url: legacy_create.license_url,
|
license_url: legacy_create.license_url,
|
||||||
discord_url: legacy_create.discord_url,
|
link_urls,
|
||||||
donation_urls: legacy_create.donation_urls,
|
|
||||||
is_draft: legacy_create.is_draft,
|
is_draft: legacy_create.is_draft,
|
||||||
license_id: legacy_create.license_id,
|
license_id: legacy_create.license_id,
|
||||||
gallery_items: legacy_create.gallery_items,
|
gallery_items: legacy_create.gallery_items,
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
|
use crate::database::models::categories::LinkPlatform;
|
||||||
use crate::database::models::{project_item, version_item};
|
use crate::database::models::{project_item, version_item};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::FileHost;
|
use crate::file_hosting::FileHost;
|
||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::models::projects::{
|
use crate::models::projects::{
|
||||||
DonationLink, MonetizationStatus, Project, ProjectStatus, SearchRequest, Version,
|
Link, MonetizationStatus, Project, ProjectStatus, SearchRequest, Version,
|
||||||
};
|
};
|
||||||
use crate::models::v2::projects::{LegacyProject, LegacySideType};
|
use crate::models::v2::projects::{DonationLink, LegacyProject, LegacySideType};
|
||||||
use crate::models::v2::search::LegacySearchResults;
|
use crate::models::v2::search::LegacySearchResults;
|
||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
use crate::routes::v3::projects::ProjectIds;
|
use crate::routes::v3::projects::ProjectIds;
|
||||||
use crate::routes::{v2_reroute, v3, ApiError};
|
use crate::routes::{v2_reroute, v3, ApiError};
|
||||||
use crate::search::{search_for_project, SearchConfig, SearchError};
|
use crate::search::{search_for_project, SearchConfig, SearchError};
|
||||||
use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse};
|
use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse};
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
@@ -360,18 +361,78 @@ pub async fn project_edit(
|
|||||||
// - change the loaders to mrpack only
|
// - change the loaders to mrpack only
|
||||||
// - add categories to the project for the corresponding loaders
|
// - add categories to the project for the corresponding loaders
|
||||||
|
|
||||||
|
let mut new_links = HashMap::new();
|
||||||
|
if let Some(issues_url) = v2_new_project.issues_url {
|
||||||
|
if let Some(issues_url) = issues_url {
|
||||||
|
new_links.insert("issues".to_string(), Some(issues_url));
|
||||||
|
} else {
|
||||||
|
new_links.insert("issues".to_string(), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(source_url) = v2_new_project.source_url {
|
||||||
|
if let Some(source_url) = source_url {
|
||||||
|
new_links.insert("source".to_string(), Some(source_url));
|
||||||
|
} else {
|
||||||
|
new_links.insert("source".to_string(), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(wiki_url) = v2_new_project.wiki_url {
|
||||||
|
if let Some(wiki_url) = wiki_url {
|
||||||
|
new_links.insert("wiki".to_string(), Some(wiki_url));
|
||||||
|
} else {
|
||||||
|
new_links.insert("wiki".to_string(), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(discord_url) = v2_new_project.discord_url {
|
||||||
|
if let Some(discord_url) = discord_url {
|
||||||
|
new_links.insert("discord".to_string(), Some(discord_url));
|
||||||
|
} else {
|
||||||
|
new_links.insert("discord".to_string(), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// In v2, setting donation links resets all other donation links
|
||||||
|
// (resetting to the new ones)
|
||||||
|
if let Some(donation_urls) = v2_new_project.donation_urls {
|
||||||
|
// Fetch current donation links from project so we know what to delete
|
||||||
|
let fetched_example_project = project_item::Project::get(&info.0, &**pool, &redis).await?;
|
||||||
|
let donation_links = fetched_example_project
|
||||||
|
.map(|x| {
|
||||||
|
x.urls
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|l| {
|
||||||
|
if l.donation {
|
||||||
|
Some(Link::from(l)) // TODO: tests
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
// Set existing donation links to None
|
||||||
|
for old_link in donation_links {
|
||||||
|
new_links.insert(old_link.platform, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new donation links
|
||||||
|
for donation_url in donation_urls {
|
||||||
|
new_links.insert(donation_url.id, Some(donation_url.url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let new_project = v3::projects::EditProject {
|
let new_project = v3::projects::EditProject {
|
||||||
title: v2_new_project.title,
|
title: v2_new_project.title,
|
||||||
description: v2_new_project.description,
|
description: v2_new_project.description,
|
||||||
body: v2_new_project.body,
|
body: v2_new_project.body,
|
||||||
categories: v2_new_project.categories,
|
categories: v2_new_project.categories,
|
||||||
additional_categories: v2_new_project.additional_categories,
|
additional_categories: v2_new_project.additional_categories,
|
||||||
issues_url: v2_new_project.issues_url,
|
|
||||||
source_url: v2_new_project.source_url,
|
|
||||||
wiki_url: v2_new_project.wiki_url,
|
|
||||||
license_url: v2_new_project.license_url,
|
license_url: v2_new_project.license_url,
|
||||||
discord_url: v2_new_project.discord_url,
|
link_urls: Some(new_links),
|
||||||
donation_urls: v2_new_project.donation_urls,
|
|
||||||
license_id: v2_new_project.license_id,
|
license_id: v2_new_project.license_id,
|
||||||
slug: v2_new_project.slug,
|
slug: v2_new_project.slug,
|
||||||
status: v2_new_project.status,
|
status: v2_new_project.status,
|
||||||
@@ -500,6 +561,70 @@ pub async fn projects_edit(
|
|||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let bulk_edit_project = bulk_edit_project.into_inner();
|
let bulk_edit_project = bulk_edit_project.into_inner();
|
||||||
|
|
||||||
|
let mut link_urls = HashMap::new();
|
||||||
|
|
||||||
|
// If we are *setting* donation links, we will set every possible donation link to None, as
|
||||||
|
// setting will delete all of them then 're-add' the ones we want to keep
|
||||||
|
if let Some(donation_url) = bulk_edit_project.donation_urls {
|
||||||
|
let link_platforms = LinkPlatform::list(&**pool, &redis).await?;
|
||||||
|
for link in link_platforms {
|
||||||
|
if link.donation {
|
||||||
|
link_urls.insert(link.name, None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// add
|
||||||
|
for donation_url in donation_url {
|
||||||
|
link_urls.insert(donation_url.id, Some(donation_url.url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For every delete, we will set the link to None
|
||||||
|
if let Some(donation_url) = bulk_edit_project.remove_donation_urls {
|
||||||
|
for donation_url in donation_url {
|
||||||
|
link_urls.insert(donation_url.id, None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For every add, we will set the link to the new url
|
||||||
|
if let Some(donation_url) = bulk_edit_project.add_donation_urls {
|
||||||
|
for donation_url in donation_url {
|
||||||
|
link_urls.insert(donation_url.id, Some(donation_url.url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(issue_url) = bulk_edit_project.issues_url {
|
||||||
|
if let Some(issue_url) = issue_url {
|
||||||
|
link_urls.insert("issues".to_string(), Some(issue_url));
|
||||||
|
} else {
|
||||||
|
link_urls.insert("issues".to_string(), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(source_url) = bulk_edit_project.source_url {
|
||||||
|
if let Some(source_url) = source_url {
|
||||||
|
link_urls.insert("source".to_string(), Some(source_url));
|
||||||
|
} else {
|
||||||
|
link_urls.insert("source".to_string(), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(wiki_url) = bulk_edit_project.wiki_url {
|
||||||
|
if let Some(wiki_url) = wiki_url {
|
||||||
|
link_urls.insert("wiki".to_string(), Some(wiki_url));
|
||||||
|
} else {
|
||||||
|
link_urls.insert("wiki".to_string(), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(discord_url) = bulk_edit_project.discord_url {
|
||||||
|
if let Some(discord_url) = discord_url {
|
||||||
|
link_urls.insert("discord".to_string(), Some(discord_url));
|
||||||
|
} else {
|
||||||
|
link_urls.insert("discord".to_string(), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
v3::projects::projects_edit(
|
v3::projects::projects_edit(
|
||||||
req,
|
req,
|
||||||
web::Query(ids),
|
web::Query(ids),
|
||||||
@@ -511,13 +636,7 @@ pub async fn projects_edit(
|
|||||||
additional_categories: bulk_edit_project.additional_categories,
|
additional_categories: bulk_edit_project.additional_categories,
|
||||||
add_additional_categories: bulk_edit_project.add_additional_categories,
|
add_additional_categories: bulk_edit_project.add_additional_categories,
|
||||||
remove_additional_categories: bulk_edit_project.remove_additional_categories,
|
remove_additional_categories: bulk_edit_project.remove_additional_categories,
|
||||||
donation_urls: bulk_edit_project.donation_urls,
|
link_urls: Some(link_urls),
|
||||||
add_donation_urls: bulk_edit_project.add_donation_urls,
|
|
||||||
remove_donation_urls: bulk_edit_project.remove_donation_urls,
|
|
||||||
issues_url: bulk_edit_project.issues_url,
|
|
||||||
source_url: bulk_edit_project.source_url,
|
|
||||||
wiki_url: bulk_edit_project.wiki_url,
|
|
||||||
discord_url: bulk_edit_project.discord_url,
|
|
||||||
}),
|
}),
|
||||||
redis,
|
redis,
|
||||||
session_queue,
|
session_queue,
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ use super::ApiError;
|
|||||||
use crate::database::models::loader_fields::LoaderFieldEnumValue;
|
use crate::database::models::loader_fields::LoaderFieldEnumValue;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::v2::projects::LegacySideType;
|
use crate::models::v2::projects::LegacySideType;
|
||||||
use crate::routes::v3::tags::{LoaderData as LoaderDataV3, LoaderFieldsEnumQuery};
|
use crate::routes::v3::tags::{
|
||||||
|
LinkPlatformQueryData, LoaderData as LoaderDataV3, LoaderFieldsEnumQuery,
|
||||||
|
};
|
||||||
use crate::routes::{v2_reroute, v3};
|
use crate::routes::{v2_reroute, v3};
|
||||||
use actix_web::{get, web, HttpResponse};
|
use actix_web::{get, web, HttpResponse};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
@@ -164,8 +166,10 @@ pub async fn license_text(params: web::Path<(String,)>) -> Result<HttpResponse,
|
|||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
pub struct DonationPlatformQueryData {
|
pub struct DonationPlatformQueryData {
|
||||||
short: String,
|
// The difference between name and short is removed in v3.
|
||||||
name: String,
|
// Now, the 'id' becomes the name, and the 'name' is removed (the frontend uses the id as the name)
|
||||||
|
// pub short: String,
|
||||||
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("donation_platform")]
|
#[get("donation_platform")]
|
||||||
@@ -173,7 +177,21 @@ pub async fn donation_platform_list(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
v3::tags::donation_platform_list(pool, redis).await
|
let response = v3::tags::link_platform_list(pool, redis).await?;
|
||||||
|
|
||||||
|
// Convert to V2 format
|
||||||
|
Ok(
|
||||||
|
match v2_reroute::extract_ok_json::<Vec<LinkPlatformQueryData>>(response).await {
|
||||||
|
Ok(platforms) => {
|
||||||
|
let platforms = platforms
|
||||||
|
.into_iter()
|
||||||
|
.map(|p| DonationPlatformQueryData { name: p.name })
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
HttpResponse::Ok().json(platforms)
|
||||||
|
}
|
||||||
|
Err(response) => response,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("report_type")]
|
#[get("report_type")]
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use crate::models::ids::{ImageId, OrganizationId};
|
|||||||
use crate::models::images::{Image, ImageContext};
|
use crate::models::images::{Image, ImageContext};
|
||||||
use crate::models::pats::Scopes;
|
use crate::models::pats::Scopes;
|
||||||
use crate::models::projects::{
|
use crate::models::projects::{
|
||||||
DonationLink, License, MonetizationStatus, ProjectId, ProjectStatus, VersionId, VersionStatus,
|
License, Link, MonetizationStatus, ProjectId, ProjectStatus, VersionId, VersionStatus,
|
||||||
};
|
};
|
||||||
use crate::models::teams::ProjectPermissions;
|
use crate::models::teams::ProjectPermissions;
|
||||||
use crate::models::threads::ThreadType;
|
use crate::models::threads::ThreadType;
|
||||||
@@ -187,39 +187,12 @@ pub struct ProjectCreateData {
|
|||||||
/// A list of the categories that the project is in.
|
/// A list of the categories that the project is in.
|
||||||
pub additional_categories: Vec<String>,
|
pub additional_categories: Vec<String>,
|
||||||
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
/// An optional link to where to submit bugs or issues with the project.
|
|
||||||
pub issues_url: Option<String>,
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
/// An optional link to the source code for the project.
|
|
||||||
pub source_url: Option<String>,
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
/// An optional link to the project's wiki page or other relevant information.
|
|
||||||
pub wiki_url: Option<String>,
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
/// An optional link to the project's license page
|
/// An optional link to the project's license page
|
||||||
pub license_url: Option<String>,
|
pub license_url: Option<String>,
|
||||||
#[validate(
|
/// An optional list of all donation links the project has
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
#[validate(custom(function = "crate::util::validate::validate_url_hashmap_values"))]
|
||||||
length(max = 2048)
|
#[serde(default)]
|
||||||
)]
|
pub link_urls: HashMap<String, String>,
|
||||||
/// An optional link to the project's discord.
|
|
||||||
pub discord_url: Option<String>,
|
|
||||||
/// An optional list of all donation links the project has\
|
|
||||||
#[validate]
|
|
||||||
pub donation_urls: Option<Vec<DonationLink>>,
|
|
||||||
|
|
||||||
/// An optional boolean. If true, the project will be created as a draft.
|
/// An optional boolean. If true, the project will be created as a draft.
|
||||||
pub is_draft: Option<bool>,
|
pub is_draft: Option<bool>,
|
||||||
@@ -671,27 +644,35 @@ async fn project_create_inner(
|
|||||||
CreateError::InvalidInput(format!("Invalid SPDX license identifier: {err}"))
|
CreateError::InvalidInput(format!("Invalid SPDX license identifier: {err}"))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut donation_urls = vec![];
|
let mut link_urls = vec![];
|
||||||
|
|
||||||
if let Some(urls) = &project_create_data.donation_urls {
|
let link_platforms =
|
||||||
for url in urls {
|
models::categories::LinkPlatform::list(&mut **transaction, redis).await?;
|
||||||
let platform_id =
|
for (platform, url) in &project_create_data.link_urls {
|
||||||
models::categories::DonationPlatform::get_id(&url.id, &mut **transaction)
|
let platform_id =
|
||||||
.await?
|
models::categories::LinkPlatform::get_id(platform, &mut **transaction)
|
||||||
.ok_or_else(|| {
|
.await?
|
||||||
CreateError::InvalidInput(format!(
|
.ok_or_else(|| {
|
||||||
"Donation platform {} does not exist.",
|
CreateError::InvalidInput(format!(
|
||||||
url.id.clone()
|
"Link platform {} does not exist.",
|
||||||
))
|
platform.clone()
|
||||||
})?;
|
))
|
||||||
|
})?;
|
||||||
donation_urls.push(models::project_item::DonationUrl {
|
let link_platform = link_platforms
|
||||||
platform_id,
|
.iter()
|
||||||
platform_short: "".to_string(),
|
.find(|x| x.id == platform_id)
|
||||||
platform_name: "".to_string(),
|
.ok_or_else(|| {
|
||||||
url: url.url.clone(),
|
CreateError::InvalidInput(format!(
|
||||||
})
|
"Link platform {} does not exist.",
|
||||||
}
|
platform.clone()
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
link_urls.push(models::project_item::LinkUrl {
|
||||||
|
platform_id,
|
||||||
|
platform_name: link_platform.name.clone(),
|
||||||
|
url: url.clone(),
|
||||||
|
donation: link_platform.donation,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let project_builder_actual = models::project_item::ProjectBuilder {
|
let project_builder_actual = models::project_item::ProjectBuilder {
|
||||||
@@ -702,12 +683,8 @@ async fn project_create_inner(
|
|||||||
description: project_create_data.description,
|
description: project_create_data.description,
|
||||||
body: project_create_data.body,
|
body: project_create_data.body,
|
||||||
icon_url: icon_data.clone().map(|x| x.0),
|
icon_url: icon_data.clone().map(|x| x.0),
|
||||||
issues_url: project_create_data.issues_url,
|
|
||||||
source_url: project_create_data.source_url,
|
|
||||||
wiki_url: project_create_data.wiki_url,
|
|
||||||
|
|
||||||
license_url: project_create_data.license_url,
|
license_url: project_create_data.license_url,
|
||||||
discord_url: project_create_data.discord_url,
|
|
||||||
categories,
|
categories,
|
||||||
additional_categories,
|
additional_categories,
|
||||||
initial_versions: versions,
|
initial_versions: versions,
|
||||||
@@ -715,7 +692,7 @@ async fn project_create_inner(
|
|||||||
requested_status: Some(project_create_data.requested_status),
|
requested_status: Some(project_create_data.requested_status),
|
||||||
license: license_id.to_string(),
|
license: license_id.to_string(),
|
||||||
slug: Some(project_create_data.slug),
|
slug: Some(project_create_data.slug),
|
||||||
donation_urls,
|
link_urls,
|
||||||
gallery_items: gallery_urls
|
gallery_items: gallery_urls
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| models::project_item::GalleryItem {
|
.map(|x| models::project_item::GalleryItem {
|
||||||
@@ -835,11 +812,12 @@ async fn project_create_inner(
|
|||||||
.map(|v| v.version_id.into())
|
.map(|v| v.version_id.into())
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
icon_url: project_builder.icon_url.clone(),
|
icon_url: project_builder.icon_url.clone(),
|
||||||
issues_url: project_builder.issues_url.clone(),
|
link_urls: project_builder
|
||||||
source_url: project_builder.source_url.clone(),
|
.link_urls
|
||||||
wiki_url: project_builder.wiki_url.clone(),
|
.clone()
|
||||||
discord_url: project_builder.discord_url.clone(),
|
.into_iter()
|
||||||
donation_urls: project_create_data.donation_urls.clone(),
|
.map(|x| (x.platform_name.clone(), Link::from(x)))
|
||||||
|
.collect(),
|
||||||
gallery: gallery_urls,
|
gallery: gallery_urls,
|
||||||
color: project_builder.color,
|
color: project_builder.color,
|
||||||
thread_id: thread_id.into(),
|
thread_id: thread_id.into(),
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::auth::{filter_authorized_projects, get_user_from_headers, is_authorized};
|
use crate::auth::{filter_authorized_projects, get_user_from_headers, is_authorized};
|
||||||
@@ -14,7 +15,7 @@ use crate::models::images::ImageContext;
|
|||||||
use crate::models::notifications::NotificationBody;
|
use crate::models::notifications::NotificationBody;
|
||||||
use crate::models::pats::Scopes;
|
use crate::models::pats::Scopes;
|
||||||
use crate::models::projects::{
|
use crate::models::projects::{
|
||||||
DonationLink, MonetizationStatus, Project, ProjectId, ProjectStatus, SearchRequest,
|
MonetizationStatus, Project, ProjectId, ProjectStatus, SearchRequest,
|
||||||
};
|
};
|
||||||
use crate::models::teams::ProjectPermissions;
|
use crate::models::teams::ProjectPermissions;
|
||||||
use crate::models::threads::MessageBody;
|
use crate::models::threads::MessageBody;
|
||||||
@@ -192,49 +193,10 @@ pub struct EditProject {
|
|||||||
custom(function = "crate::util::validate::validate_url"),
|
custom(function = "crate::util::validate::validate_url"),
|
||||||
length(max = 2048)
|
length(max = 2048)
|
||||||
)]
|
)]
|
||||||
pub issues_url: Option<Option<String>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "::serde_with::rust::double_option"
|
|
||||||
)]
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
pub source_url: Option<Option<String>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "::serde_with::rust::double_option"
|
|
||||||
)]
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
pub wiki_url: Option<Option<String>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "::serde_with::rust::double_option"
|
|
||||||
)]
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
pub license_url: Option<Option<String>>,
|
pub license_url: Option<Option<String>>,
|
||||||
#[serde(
|
#[validate(custom(function = "crate::util::validate::validate_url_hashmap_optional_values"))]
|
||||||
default,
|
// <name, url> (leave url empty to delete)
|
||||||
skip_serializing_if = "Option::is_none",
|
pub link_urls: Option<HashMap<String, Option<String>>>,
|
||||||
with = "::serde_with::rust::double_option"
|
|
||||||
)]
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
pub discord_url: Option<Option<String>>,
|
|
||||||
#[validate]
|
|
||||||
pub donation_urls: Option<Vec<DonationLink>>,
|
|
||||||
pub license_id: Option<String>,
|
pub license_id: Option<String>,
|
||||||
#[validate(
|
#[validate(
|
||||||
length(min = 3, max = 64),
|
length(min = 3, max = 64),
|
||||||
@@ -592,69 +554,6 @@ pub async fn project_edit(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(issues_url) = &new_project.issues_url {
|
|
||||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
|
||||||
return Err(ApiError::CustomAuthentication(
|
|
||||||
"You do not have the permissions to edit the issues URL of this project!"
|
|
||||||
.to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
UPDATE mods
|
|
||||||
SET issues_url = $1
|
|
||||||
WHERE (id = $2)
|
|
||||||
",
|
|
||||||
issues_url.as_deref(),
|
|
||||||
id as db_ids::ProjectId,
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(source_url) = &new_project.source_url {
|
|
||||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
|
||||||
return Err(ApiError::CustomAuthentication(
|
|
||||||
"You do not have the permissions to edit the source URL of this project!"
|
|
||||||
.to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
UPDATE mods
|
|
||||||
SET source_url = $1
|
|
||||||
WHERE (id = $2)
|
|
||||||
",
|
|
||||||
source_url.as_deref(),
|
|
||||||
id as db_ids::ProjectId,
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(wiki_url) = &new_project.wiki_url {
|
|
||||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
|
||||||
return Err(ApiError::CustomAuthentication(
|
|
||||||
"You do not have the permissions to edit the wiki URL of this project!"
|
|
||||||
.to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
UPDATE mods
|
|
||||||
SET wiki_url = $1
|
|
||||||
WHERE (id = $2)
|
|
||||||
",
|
|
||||||
wiki_url.as_deref(),
|
|
||||||
id as db_ids::ProjectId,
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(license_url) = &new_project.license_url {
|
if let Some(license_url) = &new_project.license_url {
|
||||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||||
return Err(ApiError::CustomAuthentication(
|
return Err(ApiError::CustomAuthentication(
|
||||||
@@ -676,27 +575,6 @@ pub async fn project_edit(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(discord_url) = &new_project.discord_url {
|
|
||||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
|
||||||
return Err(ApiError::CustomAuthentication(
|
|
||||||
"You do not have the permissions to edit the discord URL of this project!"
|
|
||||||
.to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
UPDATE mods
|
|
||||||
SET discord_url = $1
|
|
||||||
WHERE (id = $2)
|
|
||||||
",
|
|
||||||
discord_url.as_deref(),
|
|
||||||
id as db_ids::ProjectId,
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(slug) = &new_project.slug {
|
if let Some(slug) = &new_project.slug {
|
||||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||||
return Err(ApiError::CustomAuthentication(
|
return Err(ApiError::CustomAuthentication(
|
||||||
@@ -785,51 +663,59 @@ pub async fn project_edit(
|
|||||||
.execute(&mut *transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
if let Some(donations) = &new_project.donation_urls {
|
if let Some(links) = &new_project.link_urls {
|
||||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||||
return Err(ApiError::CustomAuthentication(
|
return Err(ApiError::CustomAuthentication(
|
||||||
"You do not have the permissions to edit the donation links of this project!"
|
"You do not have the permissions to edit the links of this project!"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ids_to_delete = links
|
||||||
|
.iter()
|
||||||
|
.map(|(name, _)| name.clone())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
// Deletes all links from hashmap- either will be deleted or be replaced
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
DELETE FROM mods_donations
|
DELETE FROM mods_links
|
||||||
WHERE joining_mod_id = $1
|
WHERE joining_mod_id = $1 AND joining_platform_id IN (
|
||||||
|
SELECT id FROM link_platforms WHERE name = ANY($2)
|
||||||
|
)
|
||||||
",
|
",
|
||||||
id as db_ids::ProjectId,
|
id as db_ids::ProjectId,
|
||||||
|
&ids_to_delete
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for donation in donations {
|
for (platform, url) in links {
|
||||||
let platform_id = db_models::categories::DonationPlatform::get_id(
|
if let Some(url) = url {
|
||||||
&donation.id,
|
let platform_id = db_models::categories::LinkPlatform::get_id(
|
||||||
&mut *transaction,
|
platform,
|
||||||
)
|
&mut *transaction,
|
||||||
.await?
|
)
|
||||||
.ok_or_else(|| {
|
.await?
|
||||||
ApiError::InvalidInput(format!(
|
.ok_or_else(|| {
|
||||||
"Platform {} does not exist.",
|
ApiError::InvalidInput(format!(
|
||||||
donation.id.clone()
|
"Platform {} does not exist.",
|
||||||
))
|
platform.clone()
|
||||||
})?;
|
))
|
||||||
|
})?;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
INSERT INTO mods_donations (joining_mod_id, joining_platform_id, url)
|
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
",
|
",
|
||||||
id as db_ids::ProjectId,
|
id as db_ids::ProjectId,
|
||||||
platform_id as db_ids::DonationPlatformId,
|
platform_id as db_ids::LinkPlatformId,
|
||||||
donation.url
|
url
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(moderation_message) = &new_project.moderation_message {
|
if let Some(moderation_message) = &new_project.moderation_message {
|
||||||
if !user.role.is_mod()
|
if !user.role.is_mod()
|
||||||
&& (!project_item.inner.status.is_approved() || moderation_message.is_some())
|
&& (!project_item.inner.status.is_approved() || moderation_message.is_some())
|
||||||
@@ -1139,53 +1025,8 @@ pub struct BulkEditProject {
|
|||||||
pub add_additional_categories: Option<Vec<String>>,
|
pub add_additional_categories: Option<Vec<String>>,
|
||||||
pub remove_additional_categories: Option<Vec<String>>,
|
pub remove_additional_categories: Option<Vec<String>>,
|
||||||
|
|
||||||
#[validate]
|
#[validate(custom(function = " crate::util::validate::validate_url_hashmap_optional_values"))]
|
||||||
pub donation_urls: Option<Vec<DonationLink>>,
|
pub link_urls: Option<HashMap<String, Option<String>>>,
|
||||||
#[validate]
|
|
||||||
pub add_donation_urls: Option<Vec<DonationLink>>,
|
|
||||||
#[validate]
|
|
||||||
pub remove_donation_urls: Option<Vec<DonationLink>>,
|
|
||||||
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "::serde_with::rust::double_option"
|
|
||||||
)]
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
pub issues_url: Option<Option<String>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "::serde_with::rust::double_option"
|
|
||||||
)]
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
pub source_url: Option<Option<String>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "::serde_with::rust::double_option"
|
|
||||||
)]
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
pub wiki_url: Option<Option<String>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "::serde_with::rust::double_option"
|
|
||||||
)]
|
|
||||||
#[validate(
|
|
||||||
custom(function = "crate::util::validate::validate_url"),
|
|
||||||
length(max = 2048)
|
|
||||||
)]
|
|
||||||
pub discord_url: Option<Option<String>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn projects_edit(
|
pub async fn projects_edit(
|
||||||
@@ -1250,7 +1091,7 @@ pub async fn projects_edit(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let categories = db_models::categories::Category::list(&**pool, &redis).await?;
|
let categories = db_models::categories::Category::list(&**pool, &redis).await?;
|
||||||
let donation_platforms = db_models::categories::DonationPlatform::list(&**pool, &redis).await?;
|
let link_platforms = db_models::categories::LinkPlatform::list(&**pool, &redis).await?;
|
||||||
|
|
||||||
let mut transaction = pool.begin().await?;
|
let mut transaction = pool.begin().await?;
|
||||||
|
|
||||||
@@ -1330,130 +1171,52 @@ pub async fn projects_edit(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let project_donations: Vec<DonationLink> = project
|
if let Some(links) = &bulk_edit_project.link_urls {
|
||||||
.donation_urls
|
let ids_to_delete = links
|
||||||
.into_iter()
|
.iter()
|
||||||
.map(|d| DonationLink {
|
.map(|(name, _)| name.clone())
|
||||||
id: d.platform_short,
|
.collect::<Vec<String>>();
|
||||||
platform: d.platform_name,
|
// Deletes all links from hashmap- either will be deleted or be replaced
|
||||||
url: d.url,
|
sqlx::query!(
|
||||||
})
|
"
|
||||||
.collect();
|
DELETE FROM mods_links
|
||||||
let mut set_donation_links =
|
WHERE joining_mod_id = $1 AND joining_platform_id IN (
|
||||||
if let Some(donation_links) = bulk_edit_project.donation_urls.clone() {
|
SELECT id FROM link_platforms WHERE name = ANY($2)
|
||||||
donation_links
|
)
|
||||||
} else {
|
",
|
||||||
project_donations.clone()
|
project.inner.id as db_ids::ProjectId,
|
||||||
};
|
&ids_to_delete
|
||||||
|
)
|
||||||
|
.execute(&mut *transaction)
|
||||||
|
.await?;
|
||||||
|
|
||||||
if let Some(delete_donations) = &bulk_edit_project.remove_donation_urls {
|
for (platform, url) in links {
|
||||||
for donation in delete_donations {
|
if let Some(url) = url {
|
||||||
if let Some(pos) = set_donation_links
|
let platform_id = link_platforms
|
||||||
.iter()
|
.iter()
|
||||||
.position(|x| donation.url == x.url && donation.id == x.id)
|
.find(|x| &x.name == platform)
|
||||||
{
|
.ok_or_else(|| {
|
||||||
set_donation_links.remove(pos);
|
ApiError::InvalidInput(format!(
|
||||||
|
"Platform {} does not exist.",
|
||||||
|
platform.clone()
|
||||||
|
))
|
||||||
|
})?
|
||||||
|
.id;
|
||||||
|
sqlx::query!(
|
||||||
|
"
|
||||||
|
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
|
||||||
|
VALUES ($1, $2, $3)
|
||||||
|
",
|
||||||
|
project.inner.id as db_ids::ProjectId,
|
||||||
|
platform_id as db_ids::LinkPlatformId,
|
||||||
|
url
|
||||||
|
)
|
||||||
|
.execute(&mut *transaction)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(add_donations) = &bulk_edit_project.add_donation_urls {
|
|
||||||
set_donation_links.append(&mut add_donations.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
if set_donation_links != project_donations {
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
DELETE FROM mods_donations
|
|
||||||
WHERE joining_mod_id = $1
|
|
||||||
",
|
|
||||||
project.inner.id as db_ids::ProjectId,
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
for donation in set_donation_links {
|
|
||||||
let platform_id = donation_platforms
|
|
||||||
.iter()
|
|
||||||
.find(|x| x.short == donation.id)
|
|
||||||
.ok_or_else(|| {
|
|
||||||
ApiError::InvalidInput(format!(
|
|
||||||
"Platform {} does not exist.",
|
|
||||||
donation.id.clone()
|
|
||||||
))
|
|
||||||
})?
|
|
||||||
.id;
|
|
||||||
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
INSERT INTO mods_donations (joining_mod_id, joining_platform_id, url)
|
|
||||||
VALUES ($1, $2, $3)
|
|
||||||
",
|
|
||||||
project.inner.id as db_ids::ProjectId,
|
|
||||||
platform_id as db_ids::DonationPlatformId,
|
|
||||||
donation.url
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(issues_url) = &bulk_edit_project.issues_url {
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
UPDATE mods
|
|
||||||
SET issues_url = $1
|
|
||||||
WHERE (id = $2)
|
|
||||||
",
|
|
||||||
issues_url.as_deref(),
|
|
||||||
project.inner.id as db_ids::ProjectId,
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(source_url) = &bulk_edit_project.source_url {
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
UPDATE mods
|
|
||||||
SET source_url = $1
|
|
||||||
WHERE (id = $2)
|
|
||||||
",
|
|
||||||
source_url.as_deref(),
|
|
||||||
project.inner.id as db_ids::ProjectId,
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(wiki_url) = &bulk_edit_project.wiki_url {
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
UPDATE mods
|
|
||||||
SET wiki_url = $1
|
|
||||||
WHERE (id = $2)
|
|
||||||
",
|
|
||||||
wiki_url.as_deref(),
|
|
||||||
project.inner.id as db_ids::ProjectId,
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(discord_url) = &bulk_edit_project.discord_url {
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
UPDATE mods
|
|
||||||
SET discord_url = $1
|
|
||||||
WHERE (id = $2)
|
|
||||||
",
|
|
||||||
discord_url.as_deref(),
|
|
||||||
project.inner.id as db_ids::ProjectId,
|
|
||||||
)
|
|
||||||
.execute(&mut *transaction)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
db_models::Project::clear_cache(project.inner.id, project.inner.slug, None, &redis).await?;
|
db_models::Project::clear_cache(project.inner.id, project.inner.slug, None, &redis).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
use crate::database::models::categories::{Category, DonationPlatform, ProjectType, ReportType};
|
use crate::database::models::categories::{Category, LinkPlatform, ProjectType, ReportType};
|
||||||
use crate::database::models::loader_fields::{
|
use crate::database::models::loader_fields::{
|
||||||
Game, Loader, LoaderField, LoaderFieldEnumValue, LoaderFieldType,
|
Game, Loader, LoaderField, LoaderFieldEnumValue, LoaderFieldType,
|
||||||
};
|
};
|
||||||
@@ -22,7 +22,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
|||||||
.route("loader_field", web::get().to(loader_fields_list))
|
.route("loader_field", web::get().to(loader_fields_list))
|
||||||
.route("license", web::get().to(license_list))
|
.route("license", web::get().to(license_list))
|
||||||
.route("license/{id}", web::get().to(license_text))
|
.route("license/{id}", web::get().to(license_text))
|
||||||
.route("donation_platform", web::get().to(donation_platform_list))
|
.route("link_platform", web::get().to(link_platform_list))
|
||||||
.route("report_type", web::get().to(report_type_list))
|
.route("report_type", web::get().to(report_type_list))
|
||||||
.route("project_type", web::get().to(project_type_list));
|
.route("project_type", web::get().to(project_type_list));
|
||||||
}
|
}
|
||||||
@@ -214,23 +214,19 @@ pub async fn license_text(params: web::Path<(String,)>) -> Result<HttpResponse,
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
pub struct DonationPlatformQueryData {
|
pub struct LinkPlatformQueryData {
|
||||||
short: String,
|
pub name: String,
|
||||||
name: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn donation_platform_list(
|
pub async fn link_platform_list(
|
||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let results: Vec<DonationPlatformQueryData> = DonationPlatform::list(&**pool, &redis)
|
let results: Vec<LinkPlatformQueryData> = LinkPlatform::list(&**pool, &redis)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| DonationPlatformQueryData {
|
.map(|x| LinkPlatformQueryData { name: x.name })
|
||||||
short: x.short,
|
|
||||||
name: x.name,
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
Ok(HttpResponse::Ok().json(results))
|
Ok(HttpResponse::Ok().json(results))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,26 @@ pub fn validate_url(value: &str) -> Result<(), validator::ValidationError> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn validate_url_hashmap_optional_values(
|
||||||
|
values: &std::collections::HashMap<String, Option<String>>,
|
||||||
|
) -> Result<(), validator::ValidationError> {
|
||||||
|
for value in values.values().flatten() {
|
||||||
|
validate_url(value)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn validate_url_hashmap_values(
|
||||||
|
values: &std::collections::HashMap<String, String>,
|
||||||
|
) -> Result<(), validator::ValidationError> {
|
||||||
|
for value in values.values() {
|
||||||
|
validate_url(value)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn validate_no_restricted_scopes(value: &Scopes) -> Result<(), validator::ValidationError> {
|
pub fn validate_no_restricted_scopes(value: &Scopes) -> Result<(), validator::ValidationError> {
|
||||||
if value.is_restricted() {
|
if value.is_restricted() {
|
||||||
return Err(validator::ValidationError::new(
|
return Err(validator::ValidationError::new(
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use labrinth::models::{
|
|||||||
notifications::{NotificationAction, NotificationBody, NotificationId},
|
notifications::{NotificationAction, NotificationBody, NotificationId},
|
||||||
organizations::OrganizationId,
|
organizations::OrganizationId,
|
||||||
projects::{
|
projects::{
|
||||||
Dependency, DonationLink, GalleryItem, License, ModeratorMessage, MonetizationStatus,
|
Dependency, GalleryItem, License, ModeratorMessage, MonetizationStatus, ProjectId,
|
||||||
ProjectId, ProjectStatus, VersionFile, VersionId, VersionStatus, VersionType,
|
ProjectStatus, VersionFile, VersionId, VersionStatus, VersionType,
|
||||||
},
|
},
|
||||||
teams::{OrganizationPermissions, ProjectPermissions, TeamId},
|
teams::{OrganizationPermissions, ProjectPermissions, TeamId},
|
||||||
threads::ThreadId,
|
threads::ThreadId,
|
||||||
@@ -52,11 +52,6 @@ pub struct CommonProject {
|
|||||||
pub loaders: Vec<String>,
|
pub loaders: Vec<String>,
|
||||||
pub versions: Vec<VersionId>,
|
pub versions: Vec<VersionId>,
|
||||||
pub icon_url: Option<String>,
|
pub icon_url: Option<String>,
|
||||||
pub issues_url: Option<String>,
|
|
||||||
pub source_url: Option<String>,
|
|
||||||
pub wiki_url: Option<String>,
|
|
||||||
pub discord_url: Option<String>,
|
|
||||||
pub donation_urls: Option<Vec<DonationLink>>,
|
|
||||||
pub gallery: Vec<GalleryItem>,
|
pub gallery: Vec<GalleryItem>,
|
||||||
pub color: Option<u32>,
|
pub color: Option<u32>,
|
||||||
pub thread_id: ThreadId,
|
pub thread_id: ThreadId,
|
||||||
|
|||||||
118
tests/project.rs
118
tests/project.rs
@@ -271,7 +271,7 @@ async fn test_add_remove_project() {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
pub async fn test_patch_project() {
|
pub async fn test_patch_project() {
|
||||||
with_test_environment_all(None, |test_env| async move {
|
with_test_environment(None, |test_env: TestEnvironment<ApiV3>| async move {
|
||||||
let api = &test_env.api;
|
let api = &test_env.api;
|
||||||
|
|
||||||
let alpha_project_slug = &test_env.dummy.as_ref().unwrap().project_alpha.project_slug;
|
let alpha_project_slug = &test_env.dummy.as_ref().unwrap().project_alpha.project_slug;
|
||||||
@@ -291,12 +291,14 @@ pub async fn test_patch_project() {
|
|||||||
assert_eq!(resp.status(), 401);
|
assert_eq!(resp.status(), 401);
|
||||||
|
|
||||||
// Failure because we are setting URL fields to invalid urls.
|
// Failure because we are setting URL fields to invalid urls.
|
||||||
for url_type in ["issues_url", "source_url", "wiki_url", "discord_url"] {
|
for url_type in ["issues", "source", "wiki", "discord"] {
|
||||||
let resp = api
|
let resp = api
|
||||||
.edit_project(
|
.edit_project(
|
||||||
alpha_project_slug,
|
alpha_project_slug,
|
||||||
json!({
|
json!({
|
||||||
url_type: "w.fake.url",
|
"link_urls": {
|
||||||
|
url_type: "not a url",
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
USER_USER_PAT,
|
USER_USER_PAT,
|
||||||
)
|
)
|
||||||
@@ -391,18 +393,18 @@ pub async fn test_patch_project() {
|
|||||||
"body": "New successful body",
|
"body": "New successful body",
|
||||||
"categories": [DUMMY_CATEGORIES[0]],
|
"categories": [DUMMY_CATEGORIES[0]],
|
||||||
"license_id": "MIT",
|
"license_id": "MIT",
|
||||||
"issues_url": "https://github.com",
|
"link_urls":
|
||||||
"discord_url": "https://discord.gg",
|
{
|
||||||
"wiki_url": "https://wiki.com",
|
"patreon": "https://patreon.com",
|
||||||
"donation_urls": [{
|
"issues": "https://github.com",
|
||||||
"id": "patreon",
|
"discord": "https://discord.gg",
|
||||||
"platform": "Patreon",
|
"wiki": "https://wiki.com"
|
||||||
"url": "https://patreon.com"
|
}
|
||||||
}]
|
|
||||||
}),
|
}),
|
||||||
USER_USER_PAT,
|
USER_USER_PAT,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
println!("{:?}", resp.response().body());
|
||||||
assert_eq!(resp.status(), 204);
|
assert_eq!(resp.status(), 204);
|
||||||
|
|
||||||
// Old slug no longer works
|
// Old slug no longer works
|
||||||
@@ -410,9 +412,7 @@ pub async fn test_patch_project() {
|
|||||||
assert_eq!(resp.status(), 404);
|
assert_eq!(resp.status(), 404);
|
||||||
|
|
||||||
// New slug does work
|
// New slug does work
|
||||||
let project = api
|
let project = api.get_project_deserialized("newslug", USER_USER_PAT).await;
|
||||||
.get_project_deserialized_common("newslug", USER_USER_PAT)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
assert_eq!(project.slug.unwrap(), "newslug");
|
assert_eq!(project.slug.unwrap(), "newslug");
|
||||||
assert_eq!(project.title, "New successful title");
|
assert_eq!(project.title, "New successful title");
|
||||||
@@ -420,13 +420,40 @@ pub async fn test_patch_project() {
|
|||||||
assert_eq!(project.body, "New successful body");
|
assert_eq!(project.body, "New successful body");
|
||||||
assert_eq!(project.categories, vec![DUMMY_CATEGORIES[0]]);
|
assert_eq!(project.categories, vec![DUMMY_CATEGORIES[0]]);
|
||||||
assert_eq!(project.license.id, "MIT");
|
assert_eq!(project.license.id, "MIT");
|
||||||
assert_eq!(project.issues_url, Some("https://github.com".to_string()));
|
|
||||||
assert_eq!(project.discord_url, Some("https://discord.gg".to_string()));
|
|
||||||
assert_eq!(project.wiki_url, Some("https://wiki.com".to_string()));
|
|
||||||
assert_eq!(project.donation_urls.unwrap()[0].url, "https://patreon.com");
|
|
||||||
|
|
||||||
// TODO:
|
let link_urls = project.link_urls;
|
||||||
// for loader fields?
|
assert_eq!(link_urls.len(), 4);
|
||||||
|
assert_eq!(link_urls["patreon"].platform, "patreon");
|
||||||
|
assert_eq!(link_urls["patreon"].url, "https://patreon.com");
|
||||||
|
assert!(link_urls["patreon"].donation);
|
||||||
|
assert_eq!(link_urls["issues"].platform, "issues");
|
||||||
|
assert_eq!(link_urls["issues"].url, "https://github.com");
|
||||||
|
assert!(!link_urls["issues"].donation);
|
||||||
|
assert_eq!(link_urls["discord"].platform, "discord");
|
||||||
|
assert_eq!(link_urls["discord"].url, "https://discord.gg");
|
||||||
|
assert!(!link_urls["discord"].donation);
|
||||||
|
assert_eq!(link_urls["wiki"].platform, "wiki");
|
||||||
|
assert_eq!(link_urls["wiki"].url, "https://wiki.com");
|
||||||
|
assert!(!link_urls["wiki"].donation);
|
||||||
|
|
||||||
|
// Unset the set link_urls
|
||||||
|
let resp = api
|
||||||
|
.edit_project(
|
||||||
|
"newslug",
|
||||||
|
json!({
|
||||||
|
"link_urls":
|
||||||
|
{
|
||||||
|
"issues": null,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
USER_USER_PAT,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
println!("{:?}", resp.response().body());
|
||||||
|
assert_eq!(resp.status(), 204);
|
||||||
|
let project = api.get_project_deserialized("newslug", USER_USER_PAT).await;
|
||||||
|
assert_eq!(project.link_urls.len(), 3);
|
||||||
|
assert!(!project.link_urls.contains_key("issues"));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
@@ -472,6 +499,57 @@ pub async fn test_bulk_edit_categories() {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
pub async fn test_bulk_edit_links() {
|
||||||
|
with_test_environment(None, |test_env: TestEnvironment<ApiV3>| async move {
|
||||||
|
let api = &test_env.api;
|
||||||
|
let alpha_project_id: &str = &test_env.dummy.as_ref().unwrap().project_alpha.project_id;
|
||||||
|
let beta_project_id: &str = &test_env.dummy.as_ref().unwrap().project_beta.project_id;
|
||||||
|
|
||||||
|
// Sets links for issue, source, wiki, and patreon for all projects
|
||||||
|
// The first loop, sets issue, the second, clears it for all projects.
|
||||||
|
for issues in [Some("https://www.issues.com"), None] {
|
||||||
|
let resp = api
|
||||||
|
.edit_project_bulk(
|
||||||
|
&[alpha_project_id, beta_project_id],
|
||||||
|
json!({
|
||||||
|
"link_urls": {
|
||||||
|
"issues": issues,
|
||||||
|
"wiki": "https://wiki.com",
|
||||||
|
"patreon": "https://patreon.com",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
ADMIN_USER_PAT,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(resp.status(), StatusCode::NO_CONTENT);
|
||||||
|
|
||||||
|
let alpha_body = api
|
||||||
|
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
|
||||||
|
.await;
|
||||||
|
if let Some(issues) = issues {
|
||||||
|
assert_eq!(alpha_body.link_urls.len(), 3);
|
||||||
|
assert_eq!(alpha_body.link_urls["issues"].url, issues);
|
||||||
|
} else {
|
||||||
|
assert_eq!(alpha_body.link_urls.len(), 2);
|
||||||
|
assert!(!alpha_body.link_urls.contains_key("issues"));
|
||||||
|
}
|
||||||
|
assert_eq!(alpha_body.link_urls["wiki"].url, "https://wiki.com");
|
||||||
|
assert_eq!(alpha_body.link_urls["patreon"].url, "https://patreon.com");
|
||||||
|
|
||||||
|
let beta_body = api
|
||||||
|
.get_project_deserialized(beta_project_id, ADMIN_USER_PAT)
|
||||||
|
.await;
|
||||||
|
assert_eq!(beta_body.categories, alpha_body.categories);
|
||||||
|
assert_eq!(
|
||||||
|
beta_body.additional_categories,
|
||||||
|
alpha_body.additional_categories,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn permissions_patch_project() {
|
async fn permissions_patch_project() {
|
||||||
with_test_environment_all(Some(8), |test_env| async move {
|
with_test_environment_all(Some(8), |test_env| async move {
|
||||||
|
|||||||
@@ -4,11 +4,15 @@ use crate::common::{
|
|||||||
request_data::{get_public_project_creation_data_json, get_public_version_creation_data},
|
request_data::{get_public_project_creation_data_json, get_public_version_creation_data},
|
||||||
ApiV2,
|
ApiV2,
|
||||||
},
|
},
|
||||||
database::{ENEMY_USER_PAT, FRIEND_USER_ID, FRIEND_USER_PAT, MOD_USER_PAT, USER_USER_PAT},
|
database::{
|
||||||
|
ADMIN_USER_PAT, ENEMY_USER_PAT, FRIEND_USER_ID, FRIEND_USER_PAT, MOD_USER_PAT,
|
||||||
|
USER_USER_PAT,
|
||||||
|
},
|
||||||
dummy_data::{TestFile, DUMMY_CATEGORIES},
|
dummy_data::{TestFile, DUMMY_CATEGORIES},
|
||||||
environment::{with_test_environment, TestEnvironment},
|
environment::{with_test_environment, TestEnvironment},
|
||||||
permissions::{PermissionsTest, PermissionsTestContext},
|
permissions::{PermissionsTest, PermissionsTestContext},
|
||||||
};
|
};
|
||||||
|
use actix_http::StatusCode;
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use labrinth::{
|
use labrinth::{
|
||||||
@@ -475,7 +479,6 @@ pub async fn test_patch_project() {
|
|||||||
|
|
||||||
// New slug does work
|
// New slug does work
|
||||||
let project = api.get_project_deserialized("newslug", USER_USER_PAT).await;
|
let project = api.get_project_deserialized("newslug", USER_USER_PAT).await;
|
||||||
|
|
||||||
assert_eq!(project.slug.unwrap(), "newslug");
|
assert_eq!(project.slug.unwrap(), "newslug");
|
||||||
assert_eq!(project.title, "New successful title");
|
assert_eq!(project.title, "New successful title");
|
||||||
assert_eq!(project.description, "New successful description");
|
assert_eq!(project.description, "New successful description");
|
||||||
@@ -495,3 +498,169 @@ pub async fn test_patch_project() {
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
pub async fn test_bulk_edit_links() {
|
||||||
|
with_test_environment(None, |test_env: TestEnvironment<ApiV2>| async move {
|
||||||
|
let api = &test_env.api;
|
||||||
|
let alpha_project_id: &str = &test_env.dummy.as_ref().unwrap().project_alpha.project_id;
|
||||||
|
let beta_project_id: &str = &test_env.dummy.as_ref().unwrap().project_beta.project_id;
|
||||||
|
|
||||||
|
let resp = api
|
||||||
|
.edit_project_bulk(
|
||||||
|
&[alpha_project_id, beta_project_id],
|
||||||
|
json!({
|
||||||
|
"issues_url": "https://github.com",
|
||||||
|
"donation_urls": [
|
||||||
|
{
|
||||||
|
"id": "patreon",
|
||||||
|
"platform": "Patreon",
|
||||||
|
"url": "https://www.patreon.com/my_user"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
ADMIN_USER_PAT,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(resp.status(), StatusCode::NO_CONTENT);
|
||||||
|
|
||||||
|
let alpha_body = api
|
||||||
|
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
|
||||||
|
.await;
|
||||||
|
let donation_urls = alpha_body.donation_urls.unwrap();
|
||||||
|
assert_eq!(donation_urls.len(), 1);
|
||||||
|
assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user");
|
||||||
|
assert_eq!(
|
||||||
|
alpha_body.issues_url,
|
||||||
|
Some("https://github.com".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(alpha_body.discord_url, None);
|
||||||
|
|
||||||
|
let beta_body = api
|
||||||
|
.get_project_deserialized(beta_project_id, ADMIN_USER_PAT)
|
||||||
|
.await;
|
||||||
|
let donation_urls = beta_body.donation_urls.unwrap();
|
||||||
|
assert_eq!(donation_urls.len(), 1);
|
||||||
|
assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user");
|
||||||
|
assert_eq!(beta_body.issues_url, Some("https://github.com".to_string()));
|
||||||
|
assert_eq!(beta_body.discord_url, None);
|
||||||
|
|
||||||
|
let resp = api
|
||||||
|
.edit_project_bulk(
|
||||||
|
&[alpha_project_id, beta_project_id],
|
||||||
|
json!({
|
||||||
|
"discord_url": "https://discord.gg",
|
||||||
|
"issues_url": null,
|
||||||
|
"add_donation_urls": [
|
||||||
|
{
|
||||||
|
"id": "bmac",
|
||||||
|
"platform": "Buy Me a Coffee",
|
||||||
|
"url": "https://www.buymeacoffee.com/my_user"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
ADMIN_USER_PAT,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(resp.status(), StatusCode::NO_CONTENT);
|
||||||
|
|
||||||
|
let alpha_body = api
|
||||||
|
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
|
||||||
|
.await;
|
||||||
|
let donation_urls = alpha_body
|
||||||
|
.donation_urls
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.sorted_by_key(|x| x.id.clone())
|
||||||
|
.collect_vec();
|
||||||
|
assert_eq!(donation_urls.len(), 2);
|
||||||
|
assert_eq!(donation_urls[0].url, "https://www.buymeacoffee.com/my_user");
|
||||||
|
assert_eq!(donation_urls[1].url, "https://www.patreon.com/my_user");
|
||||||
|
assert_eq!(alpha_body.issues_url, None);
|
||||||
|
assert_eq!(
|
||||||
|
alpha_body.discord_url,
|
||||||
|
Some("https://discord.gg".to_string())
|
||||||
|
);
|
||||||
|
|
||||||
|
let beta_body = api
|
||||||
|
.get_project_deserialized(beta_project_id, ADMIN_USER_PAT)
|
||||||
|
.await;
|
||||||
|
let donation_urls = beta_body
|
||||||
|
.donation_urls
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.sorted_by_key(|x| x.id.clone())
|
||||||
|
.collect_vec();
|
||||||
|
assert_eq!(donation_urls.len(), 2);
|
||||||
|
assert_eq!(donation_urls[0].url, "https://www.buymeacoffee.com/my_user");
|
||||||
|
assert_eq!(donation_urls[1].url, "https://www.patreon.com/my_user");
|
||||||
|
assert_eq!(alpha_body.issues_url, None);
|
||||||
|
assert_eq!(
|
||||||
|
alpha_body.discord_url,
|
||||||
|
Some("https://discord.gg".to_string())
|
||||||
|
);
|
||||||
|
|
||||||
|
let resp = api
|
||||||
|
.edit_project_bulk(
|
||||||
|
&[alpha_project_id, beta_project_id],
|
||||||
|
json!({
|
||||||
|
"donation_urls": [
|
||||||
|
{
|
||||||
|
"id": "patreon",
|
||||||
|
"platform": "Patreon",
|
||||||
|
"url": "https://www.patreon.com/my_user"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "ko-fi",
|
||||||
|
"platform": "Ko-fi",
|
||||||
|
"url": "https://www.ko-fi.com/my_user"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"add_donation_urls": [
|
||||||
|
{
|
||||||
|
"id": "paypal",
|
||||||
|
"platform": "PayPal",
|
||||||
|
"url": "https://www.paypal.com/my_user"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"remove_donation_urls": [
|
||||||
|
{
|
||||||
|
"id": "ko-fi",
|
||||||
|
"platform": "Ko-fi",
|
||||||
|
"url": "https://www.ko-fi.com/my_user"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
ADMIN_USER_PAT,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(resp.status(), StatusCode::NO_CONTENT);
|
||||||
|
|
||||||
|
let alpha_body = api
|
||||||
|
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
|
||||||
|
.await;
|
||||||
|
let donation_urls = alpha_body
|
||||||
|
.donation_urls
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.sorted_by_key(|x| x.id.clone())
|
||||||
|
.collect_vec();
|
||||||
|
assert_eq!(donation_urls.len(), 2);
|
||||||
|
assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user");
|
||||||
|
assert_eq!(donation_urls[1].url, "https://www.paypal.com/my_user");
|
||||||
|
|
||||||
|
let beta_body = api
|
||||||
|
.get_project_deserialized(beta_project_id, ADMIN_USER_PAT)
|
||||||
|
.await;
|
||||||
|
let donation_urls = beta_body
|
||||||
|
.donation_urls
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.sorted_by_key(|x| x.id.clone())
|
||||||
|
.collect_vec();
|
||||||
|
assert_eq!(donation_urls.len(), 2);
|
||||||
|
assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user");
|
||||||
|
assert_eq!(donation_urls[1].url, "https://www.paypal.com/my_user");
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user