Change index interval, add slug to search documents (#110)

* Change index interval, add slug to search documents

* Allow the removal of '@' for slug get

* Fix

* Remove name and rename side type

* Run prepare
This commit is contained in:
Geometrically
2020-12-13 18:10:58 -07:00
committed by GitHub
parent df5684a9f8
commit f0b73fd696
14 changed files with 486 additions and 533 deletions

2
.env
View File

@@ -26,6 +26,8 @@ S3_BUCKET_NAME=none
# 1 hour
LOCAL_INDEX_INTERVAL=3600
# 30 minutes
VERSION_INDEX_INTERVAL=1800
GITHUB_CLIENT_ID=3acffb2e808d16d4b226
GITHUB_CLIENT_SECRET=none

View File

@@ -0,0 +1,5 @@
-- Add migration script here
ALTER TABLE team_members
DROP COLUMN member_name;
UPDATE side_types SET name = 'optional' WHERE name = 'no-functionality';

View File

@@ -1,5 +1,49 @@
{
"db": "PostgreSQL",
"017c9fd0c8103c590489453a25b3317e6790a21f388bcf7ec8c93cd26255f368": {
"query": "\n SELECT id, team_id, role, permissions, accepted\n FROM team_members\n WHERE (user_id = $1 AND accepted = TRUE)\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "team_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 4,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false
]
}
},
"0267d1ea5387d4acfc132aeb4776004a1ebb048e7789e686bfaba3357d392f62": {
"query": "\n DELETE FROM mods_donations\n WHERE joining_mod_id = $1\n ",
"describe": {
@@ -426,124 +470,6 @@
"nullable": []
}
},
"21d268dbad5ffd34d476998aea4475cdb071e8cfbb245c4853ee5f4c44b0c8ae": {
"query": "\n SELECT id, user_id, member_name, role, permissions, accepted\n FROM team_members\n WHERE (team_id = $1 AND accepted = TRUE)\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "user_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "member_name",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 4,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false,
false
]
}
},
"225597042db9c2d95296ea6bbeda4e99ffc9ddfab3991c8637ac3f4749ece6f3": {
"query": "\n SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id\n FROM mods m\n WHERE id = $1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "title",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "description",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "downloads",
"type_info": "Int4"
},
{
"ordinal": 4,
"name": "icon_url",
"type_info": "Varchar"
},
{
"ordinal": 5,
"name": "body_url",
"type_info": "Varchar"
},
{
"ordinal": 6,
"name": "published",
"type_info": "Timestamptz"
},
{
"ordinal": 7,
"name": "updated",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"name": "team_id",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
true,
false,
false,
false,
false
]
}
},
"2439ae8db5ae81aad03351e9a2e19259ef033110ed1c2d71bc0a643104ca32d0": {
"query": "\n UPDATE versions\n SET downloads = downloads + 1\n WHERE id = $1\n ",
"describe": {
@@ -640,6 +566,23 @@
"nullable": []
}
},
"2d2e5b06be5125226ed9e4d7b7b5f99043db73537f2199f2146bdcd56091ae75": {
"query": "\n INSERT INTO team_members (id, team_id, user_id, role, permissions, accepted)\n VALUES ($1, $2, $3, $4, $5, $6)\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Int8",
"Int8",
"Varchar",
"Int8",
"Bool"
]
},
"nullable": []
}
},
"2f5ce51392035ccfd846b16824ad6ee607de87bb55e7152a51f21035f83021c7": {
"query": "\n SELECT v.id, v.mod_id, v.author_id, v.name, v.version_number,\n v.changelog_url, v.date_published, v.downloads,\n v.release_channel, v.accepted, v.featured\n FROM versions v\n WHERE v.id IN (SELECT * FROM UNNEST($1::bigint[]))\n ",
"describe": {
@@ -1156,6 +1099,51 @@
"nullable": []
}
},
"4b305fba5341b183cc07048aef48dc593c7a2fdf7abb82f7440e5a63786ebe7b": {
"query": "\n SELECT id, user_id, role, permissions, accepted\n FROM team_members\n WHERE (team_id = $1 AND user_id = $2 AND accepted = TRUE)\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "user_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 4,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8",
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false
]
}
},
"4c99c0840159d18e88cd6094a41117258f2337346c145d926b5b610c76b5125f": {
"query": "\n SELECT c.category\n FROM mods_categories mc\n INNER JOIN categories c ON mc.joining_category_id=c.id\n WHERE mc.joining_mod_id = $1\n ",
"describe": {
@@ -1289,6 +1277,22 @@
]
}
},
"596bf1e0a31e35ab768b1239673a69ac6598b0cb94700a84c15682aae55de9bd": {
"query": "\n INSERT INTO team_members (\n id, user_id, role, permissions, accepted\n )\n VALUES (\n $1, $2, $3, $4, $5\n )\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Int8",
"Varchar",
"Int8",
"Bool"
]
},
"nullable": []
}
},
"5c4262689205aafdd97a74bee0003f39eef0a34c97f97a939c14fb8fe349f7eb": {
"query": "\n UPDATE files\n SET is_primary = TRUE\n WHERE (id = $1)\n ",
"describe": {
@@ -1571,57 +1575,6 @@
"nullable": []
}
},
"6d8f1863579977d367784a5b457e21c841886834afe69a964de039d6f92795d4": {
"query": "\n SELECT id, user_id, member_name, role, permissions, accepted\n FROM team_members\n WHERE (team_id = $1 AND user_id = $2)\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "user_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "member_name",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 4,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8",
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false,
false
]
}
},
"6f1fb4c3269b2a8190f328df025be76241eae757d9c4f3e5eb1cc01b191837df": {
"query": "\n DELETE FROM mods_categories\n WHERE joining_mod_id = $1\n ",
"describe": {
@@ -1876,56 +1829,6 @@
]
}
},
"733a9569fef2aa48d1d3b1b02d7fa893174d523adc57fb22995b1ea8897f3abf": {
"query": "\n SELECT id, team_id, member_name, role, permissions, accepted\n FROM team_members\n WHERE (user_id = $1 AND accepted = TRUE)\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "team_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "member_name",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 4,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false,
false
]
}
},
"73bdd6c9e7cd8c1ed582261aebdee0f8fd2734e712ef288a2608564c918009cb": {
"query": "\n DELETE FROM versions WHERE id = $1\n ",
"describe": {
@@ -2054,57 +1957,6 @@
]
}
},
"7bbbeecf3246a8e07ad073a07f7d057e0990a810d69ae18cec41de60b704b174": {
"query": "\n SELECT id, user_id, member_name, role, permissions, accepted\n FROM team_members\n WHERE (team_id = $1 AND user_id = $2 AND accepted = TRUE)\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "user_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "member_name",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 4,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8",
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false,
false
]
}
},
"82515e4e7e88f1193c956f032caabc70f535f925e212de30f974afd3ec126092": {
"query": "\n INSERT INTO licenses (short, name)\n VALUES ($1, $2)\n ON CONFLICT (short) DO NOTHING\n RETURNING id\n ",
"describe": {
@@ -2126,6 +1978,50 @@
]
}
},
"89310b2bc5f020744a9a42dae6f15dfebc1544cdd754939f0d09714353f2aa7c": {
"query": "\n SELECT id, team_id, role, permissions, accepted\n FROM team_members\n WHERE user_id = $1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "team_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 4,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false
]
}
},
"8ba2b2c38958f1c542e514fc62ab4682f58b0b442ac1842d20625420698e34ec": {
"query": "\n DELETE FROM team_members\n WHERE (team_id = $1 AND user_id = $2 AND NOT role = $3)\n ",
"describe": {
@@ -2225,22 +2121,48 @@
]
}
},
"9ef0577ee4845091a0d29bad6d1130223767e6d6140cafb9013fdb428d5159dd": {
"query": "\n INSERT INTO team_members (id, team_id, user_id, member_name, role, permissions, accepted)\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n ",
"9f93c94dd5d4fe4fad9c3021099a84b8e0c8cd2f0c9458063453f2416010657c": {
"query": "\n SELECT id, user_id, role, permissions, accepted\n FROM team_members\n WHERE (team_id = $1 AND accepted = TRUE)\n ",
"describe": {
"columns": [],
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "user_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 4,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8",
"Int8",
"Int8",
"Varchar",
"Varchar",
"Int8",
"Bool"
"Int8"
]
},
"nullable": []
"nullable": [
false,
false,
false,
false,
false
]
}
},
"a28188c4840d0f3449379b3bba6b3c4af9483e01f50fd56785317398a59881ca": {
@@ -2644,6 +2566,84 @@
"nullable": []
}
},
"b2a9bf9cb82a5e5597c2d2c8b5678cb2ee63dedde43f27c759c3300072312a1f": {
"query": "\n SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status, m.slug FROM mods m\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "title",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "description",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "downloads",
"type_info": "Int4"
},
{
"ordinal": 4,
"name": "icon_url",
"type_info": "Varchar"
},
{
"ordinal": 5,
"name": "body_url",
"type_info": "Varchar"
},
{
"ordinal": 6,
"name": "published",
"type_info": "Timestamptz"
},
{
"ordinal": 7,
"name": "updated",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"name": "team_id",
"type_info": "Int8"
},
{
"ordinal": 9,
"name": "status",
"type_info": "Int4"
},
{
"ordinal": 10,
"name": "slug",
"type_info": "Varchar"
}
],
"parameters": {
"Left": []
},
"nullable": [
false,
false,
false,
false,
true,
false,
false,
false,
false,
false,
true
]
}
},
"b34577335d30ffe30327cdd5b3c029a187a1cae27bea99ff0bcf062f87468fe7": {
"query": "\n SELECT loaders.loader FROM versions\n INNER JOIN loaders_versions lv ON lv.version_id = versions.id\n INNER JOIN loaders ON loaders.id = lv.loader_id\n WHERE versions.mod_id = $1\n ",
"describe": {
@@ -2721,78 +2721,6 @@
]
}
},
"bbefd1a6eb97ff17b185cfd704dda537334e23b254a1ce9e565216a967f204a3": {
"query": "\n SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status FROM mods m\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "title",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "description",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "downloads",
"type_info": "Int4"
},
{
"ordinal": 4,
"name": "icon_url",
"type_info": "Varchar"
},
{
"ordinal": 5,
"name": "body_url",
"type_info": "Varchar"
},
{
"ordinal": 6,
"name": "published",
"type_info": "Timestamptz"
},
{
"ordinal": 7,
"name": "updated",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"name": "team_id",
"type_info": "Int8"
},
{
"ordinal": 9,
"name": "status",
"type_info": "Int4"
}
],
"parameters": {
"Left": []
},
"nullable": [
false,
false,
false,
false,
true,
false,
false,
false,
false,
false
]
}
},
"bc91841f9672608a28bd45a862919f2bd34fac0b3479e3b4b67a9f6bea2a562a": {
"query": "\n UPDATE mods\n SET issues_url = $1\n WHERE (id = $2)\n ",
"describe": {
@@ -2818,6 +2746,51 @@
"nullable": []
}
},
"bdaab7da16d07169c29d96330fcc17ef2fb87fdfbadca23b7289c64420ac3a04": {
"query": "\n SELECT id, user_id, role, permissions, accepted\n FROM team_members\n WHERE (team_id = $1 AND user_id = $2)\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "user_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 4,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8",
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false
]
}
},
"bec1612d4929d143bc5d6860a57cc036c5ab23e69d750ca5791c620297953c50": {
"query": "\n SELECT team_id FROM mods WHERE id = $1\n ",
"describe": {
@@ -3315,73 +3288,6 @@
]
}
},
"d99c8f5a2d8f73f6c91ac7e72e352e03e608522142aab1b569ef5eced5ec18f8": {
"query": "\n INSERT INTO team_members (\n id, user_id, member_name, role, permissions, accepted\n )\n VALUES (\n $1, $2, $3, $4, $5,\n $6\n )\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Int8",
"Varchar",
"Varchar",
"Int8",
"Bool"
]
},
"nullable": []
}
},
"dd16be7b85d2a4bd77eccc780d27031b964d4d346d8899b4dd0e2f47ba86d5fd": {
"query": "\n SELECT id, team_id, member_name, role, permissions, accepted\n FROM team_members\n WHERE user_id = $1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "team_id",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "member_name",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "role",
"type_info": "Varchar"
},
{
"ordinal": 4,
"name": "permissions",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "accepted",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false,
false
]
}
},
"deb81673526789bca38d39e64303f61d2a63febfdfb68136e58517af9f7792bc": {
"query": "\n SELECT category FROM mods_categories\n INNER JOIN categories ON joining_category_id = id\n WHERE joining_mod_id = $1\n ",
"describe": {
@@ -3461,21 +3367,6 @@
"nullable": []
}
},
"e53013562a3a9659df5c56185b92cf9cc30ce7e409f4762be98662161af593b9": {
"query": "\n UPDATE team_members\n SET member_name = $1\n WHERE (team_id = $2 AND user_id = $3 AND NOT role = $4)\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Varchar",
"Int8",
"Int8",
"Text"
]
},
"nullable": []
}
},
"e673006d1355fa91ba5739d7cf569eec5e1ec501f7b1dc2b431f0b1c25ac07d5": {
"query": "\n DELETE FROM game_versions\n WHERE version = $1\n ",
"describe": {
@@ -3788,6 +3679,80 @@
"nullable": []
}
},
"f741273df7b987cbe2be4db3c3a11cf18027dfedb61dff41b9226aaa793b90cb": {
"query": "\n SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.slug\n FROM mods m\n WHERE id = $1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "title",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "description",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "downloads",
"type_info": "Int4"
},
{
"ordinal": 4,
"name": "icon_url",
"type_info": "Varchar"
},
{
"ordinal": 5,
"name": "body_url",
"type_info": "Varchar"
},
{
"ordinal": 6,
"name": "published",
"type_info": "Timestamptz"
},
{
"ordinal": 7,
"name": "updated",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"name": "team_id",
"type_info": "Int8"
},
{
"ordinal": 9,
"name": "slug",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
true,
false,
false,
false,
false,
true
]
}
},
"f7bea04e8e279e27a24de1bdf3c413daa8677994df5131494b28691ed6611efc": {
"query": "\n SELECT url,expires FROM states\n WHERE id = $1\n ",
"describe": {

View File

@@ -6,7 +6,6 @@ pub struct TeamBuilder {
}
pub struct TeamMemberBuilder {
pub user_id: UserId,
pub name: String,
pub role: String,
pub permissions: Permissions,
pub accepted: bool,
@@ -37,7 +36,6 @@ impl TeamBuilder {
id: team_member_id,
team_id,
user_id: member.user_id,
name: member.name,
role: member.role,
permissions: member.permissions,
accepted: member.accepted,
@@ -45,13 +43,12 @@ impl TeamBuilder {
sqlx::query!(
"
INSERT INTO team_members (id, team_id, user_id, member_name, role, permissions, accepted)
VALUES ($1, $2, $3, $4, $5, $6, $7)
INSERT INTO team_members (id, team_id, user_id, role, permissions, accepted)
VALUES ($1, $2, $3, $4, $5, $6)
",
team_member.id as TeamMemberId,
team_member.team_id as TeamId,
team_member.user_id as UserId,
team_member.name,
team_member.role,
team_member.permissions.bits() as i64,
team_member.accepted,
@@ -76,8 +73,6 @@ pub struct TeamMember {
pub team_id: TeamId,
/// The ID of the user associated with the member
pub user_id: UserId,
/// The name of the user
pub name: String,
pub role: String,
pub permissions: Permissions,
pub accepted: bool,
@@ -96,7 +91,7 @@ impl TeamMember {
let team_members = sqlx::query!(
"
SELECT id, user_id, member_name, role, permissions, accepted
SELECT id, user_id, role, permissions, accepted
FROM team_members
WHERE (team_id = $1 AND accepted = TRUE)
",
@@ -111,7 +106,6 @@ impl TeamMember {
id: TeamMemberId(m.id),
team_id: id,
user_id: UserId(m.user_id),
name: m.member_name,
role: m.role,
permissions: perms,
accepted: m.accepted,
@@ -145,7 +139,7 @@ impl TeamMember {
let team_members = sqlx::query!(
"
SELECT id, team_id, member_name, role, permissions, accepted
SELECT id, team_id, role, permissions, accepted
FROM team_members
WHERE (user_id = $1 AND accepted = TRUE)
",
@@ -160,7 +154,6 @@ impl TeamMember {
id: TeamMemberId(m.id),
team_id: TeamId(m.team_id),
user_id: id,
name: m.member_name,
role: m.role,
permissions: perms,
accepted: m.accepted,
@@ -194,7 +187,7 @@ impl TeamMember {
let team_members = sqlx::query!(
"
SELECT id, team_id, member_name, role, permissions, accepted
SELECT id, team_id, role, permissions, accepted
FROM team_members
WHERE user_id = $1
",
@@ -209,7 +202,6 @@ impl TeamMember {
id: TeamMemberId(m.id),
team_id: TeamId(m.team_id),
user_id: id,
name: m.member_name,
role: m.role,
permissions: perms,
accepted: m.accepted,
@@ -242,7 +234,7 @@ impl TeamMember {
{
let result = sqlx::query!(
"
SELECT id, user_id, member_name, role, permissions, accepted
SELECT id, user_id, role, permissions, accepted
FROM team_members
WHERE (team_id = $1 AND user_id = $2 AND accepted = TRUE)
",
@@ -257,7 +249,6 @@ impl TeamMember {
id: TeamMemberId(m.id),
team_id: id,
user_id,
name: m.member_name,
role: m.role,
permissions: Permissions::from_bits(m.permissions as u64)
.ok_or(super::DatabaseError::BitflagError)?,
@@ -279,7 +270,7 @@ impl TeamMember {
{
let result = sqlx::query!(
"
SELECT id, user_id, member_name, role, permissions, accepted
SELECT id, user_id, role, permissions, accepted
FROM team_members
WHERE (team_id = $1 AND user_id = $2)
",
@@ -294,7 +285,6 @@ impl TeamMember {
id: TeamMemberId(m.id),
team_id: id,
user_id,
name: m.member_name,
role: m.role,
permissions: Permissions::from_bits(m.permissions as u64)
.ok_or(super::DatabaseError::BitflagError)?,
@@ -312,16 +302,14 @@ impl TeamMember {
sqlx::query!(
"
INSERT INTO team_members (
id, user_id, member_name, role, permissions, accepted
id, user_id, role, permissions, accepted
)
VALUES (
$1, $2, $3, $4, $5,
$6
$1, $2, $3, $4, $5
)
",
self.id as TeamMemberId,
self.user_id as UserId,
self.name,
self.role,
self.permissions.bits() as i64,
self.accepted,
@@ -369,7 +357,6 @@ impl TeamMember {
new_permissions: Option<Permissions>,
new_role: Option<String>,
new_accepted: Option<bool>,
new_name: Option<String>,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<(), super::DatabaseError> {
if let Some(permissions) = new_permissions {
@@ -421,22 +408,6 @@ impl TeamMember {
}
}
if let Some(name) = new_name {
sqlx::query!(
"
UPDATE team_members
SET member_name = $1
WHERE (team_id = $2 AND user_id = $3 AND NOT role = $4)
",
name,
id as TeamId,
user_id as UserId,
crate::models::teams::OWNER_ROLE,
)
.execute(&mut *transaction)
.await?;
}
Ok(())
}
}

View File

@@ -343,6 +343,8 @@ fn check_env_vars() -> bool {
failed |= check_var::<usize>("LOCAL_INDEX_INTERVAL");
failed |= check_var::<usize>("VERSION_INDEX_INTERVAL");
failed |= check_var::<String>("GITHUB_CLIENT_ID");
failed |= check_var::<String>("GITHUB_CLIENT_SECRET");

View File

@@ -69,7 +69,7 @@ pub struct Mod {
#[serde(rename_all = "kebab-case")]
pub enum SideType {
Required,
NoFunctionality,
Optional,
Unsupported,
Unknown,
}
@@ -85,7 +85,7 @@ impl SideType {
pub fn as_str(&self) -> &'static str {
match self {
SideType::Required => "required",
SideType::NoFunctionality => "no-functionality",
SideType::Optional => "optional",
SideType::Unsupported => "unsupported",
SideType::Unknown => "unknown",
}
@@ -94,7 +94,7 @@ impl SideType {
pub fn from_str(string: &str) -> SideType {
match string {
"required" => SideType::Required,
"no-functionality" => SideType::NoFunctionality,
"optional" => SideType::Optional,
"unsupported" => SideType::Unsupported,
_ => SideType::Unknown,
}

View File

@@ -47,8 +47,6 @@ impl Default for Permissions {
pub struct TeamMember {
/// The ID of the user associated with the member
pub user_id: UserId,
/// The name of the user
pub name: String,
/// The role of the user in the team
pub role: String,
/// A bitset containing the user's permissions in this team

View File

@@ -165,7 +165,7 @@ pub async fn mod_create(
&mut transaction,
&***file_host,
&mut uploaded_files,
&***indexing_queue
&***indexing_queue,
)
.await;
@@ -457,7 +457,6 @@ async fn mod_create_inner(
let team = models::team_item::TeamBuilder {
members: vec![models::team_item::TeamMemberBuilder {
user_id: current_user.id.into(),
name: current_user.username.clone(),
role: crate::models::teams::OWNER_ROLE.to_owned(),
permissions: crate::models::teams::Permissions::ALL,
accepted: true,

View File

@@ -3,16 +3,16 @@ use crate::auth::get_user_from_headers;
use crate::database;
use crate::file_hosting::FileHost;
use crate::models;
use crate::models::mods::{DonationLink, License, ModStatus, SearchRequest, SideType};
use crate::models::mods::{DonationLink, License, ModId, ModStatus, SearchRequest, SideType};
use crate::models::teams::Permissions;
use crate::search::indexing::queue::CreationQueue;
use crate::search::{search_for_mod, SearchConfig, SearchError};
use actix_web::web::Data;
use actix_web::{delete, get, patch, web, HttpRequest, HttpResponse};
use futures::StreamExt;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use std::sync::Arc;
use crate::search::indexing::queue::CreationQueue;
use actix_web::web::Data;
#[get("mod")]
pub async fn mod_search(
@@ -133,13 +133,30 @@ pub async fn mod_slug_get(
#[get("{id}")]
pub async fn mod_get(
req: HttpRequest,
info: web::Path<(models::ids::ModId,)>,
info: web::Path<(String,)>,
pool: web::Data<PgPool>,
) -> Result<HttpResponse, ApiError> {
let id = info.into_inner().0;
let mod_data = database::models::Mod::get_full(id.into(), &**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
let string = info.into_inner().0;
let id_option: Option<ModId> = serde_json::from_str(&*format!("\"{}\"", string)).ok();
let mut mod_data;
if let Some(id) = id_option {
mod_data = database::models::Mod::get_full(id.into(), &**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
if mod_data.is_none() {
mod_data = database::models::Mod::get_full_from_slug(string, &**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
}
} else {
mod_data = database::models::Mod::get_full_from_slug(string, &**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
}
let user_option = get_user_from_headers(req.headers(), &**pool).await.ok();
if let Some(data) = mod_data {
@@ -384,9 +401,11 @@ pub async fn mod_edit(
if mod_item.status.is_searchable() && !status.is_searchable() {
delete_from_index(id.into(), config).await?;
} else if !mod_item.status.is_searchable() && status.is_searchable() {
let index_mod =
crate::search::indexing::local_import::query_one(mod_id.into(), &mut *transaction)
.await?;
let index_mod = crate::search::indexing::local_import::query_one(
mod_id.into(),
&mut *transaction,
)
.await?;
indexing_queue.add(index_mod);
}

View File

@@ -28,7 +28,6 @@ pub async fn team_members_get(
.into_iter()
.map(|data| crate::models::teams::TeamMember {
user_id: data.user_id.into(),
name: data.name,
role: data.role,
permissions: Some(data.permissions),
})
@@ -42,7 +41,6 @@ pub async fn team_members_get(
.into_iter()
.map(|data| crate::models::teams::TeamMember {
user_id: data.user_id.into(),
name: data.name,
role: data.role,
permissions: None,
})
@@ -81,7 +79,6 @@ pub async fn join_team(
None,
None,
Some(true),
None,
&mut transaction,
)
.await?;
@@ -174,7 +171,7 @@ pub async fn add_team_member(
}
}
let new_user = crate::database::models::User::get(member.user_id, &**pool)
crate::database::models::User::get(member.user_id, &**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?
.ok_or_else(|| ApiError::InvalidInputError("An invalid User ID specified".to_string()))?;
@@ -184,7 +181,6 @@ pub async fn add_team_member(
id: new_id,
team_id,
user_id: new_member.user_id.into(),
name: new_user.username,
role: new_member.role.clone(),
permissions: new_member.permissions,
accepted: false,
@@ -205,7 +201,6 @@ pub async fn add_team_member(
pub struct EditTeamMember {
pub permissions: Option<Permissions>,
pub role: Option<String>,
pub name: Option<String>,
}
#[patch("{id}/members/{user_id}")]
@@ -236,31 +231,6 @@ pub async fn edit_team_member(
}
};
// If the only thing being modified is the name, a user can
// modify their own member without extra permissions.
if user_id == current_user.id.into()
&& edit_member.permissions.is_none()
&& edit_member.role.is_none()
{
TeamMember::edit_team_member(
id,
user_id,
None,
None,
None,
edit_member.name.clone(),
&mut transaction,
)
.await?;
transaction
.commit()
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
return Ok(HttpResponse::Ok().body(""));
}
if !member.permissions.contains(Permissions::EDIT_MEMBER) {
return Err(ApiError::CustomAuthenticationError(
"You don't have permission to edit members of this team".to_string(),
@@ -287,7 +257,6 @@ pub async fn edit_team_member(
edit_member.permissions,
edit_member.role.clone(),
None,
edit_member.name.clone(),
&mut transaction,
)
.await?;

View File

@@ -70,13 +70,29 @@ pub async fn user_username_get(
#[get("{id}")]
pub async fn user_get(
info: web::Path<(UserId,)>,
info: web::Path<(String,)>,
pool: web::Data<PgPool>,
) -> Result<HttpResponse, ApiError> {
let id = info.into_inner().0;
let user_data = User::get(id.into(), &**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
let string = info.into_inner().0;
let id_option: Option<UserId> = serde_json::from_str(&*format!("\"{}\"", string)).ok();
let mut user_data;
if let Some(id) = id_option {
user_data = User::get(id.into(), &**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
if user_data.is_none() {
user_data = User::get_from_username(string, &**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
}
} else {
user_data = User::get_from_username(string, &**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
}
if let Some(data) = user_data {
let response = convert_user(data);
@@ -160,7 +176,6 @@ pub async fn teams(
.into_iter()
.map(|data| crate::models::teams::TeamMember {
user_id: data.user_id.into(),
name: data.name,
role: data.role,
permissions: if same_user {
Some(data.permissions)

View File

@@ -36,8 +36,12 @@ pub fn schedule_versions(
pool: sqlx::Pool<sqlx::Postgres>,
skip_initial: bool,
) {
// Check mojang's versions every 6 hours
let version_index_interval = std::time::Duration::from_secs(60 * 60 * 6);
let version_index_interval = std::time::Duration::from_secs(
dotenv::var("VERSION_INDEX_INTERVAL")
.ok()
.map(|i| i.parse().unwrap())
.unwrap_or(1800),
);
let mut skip = skip_initial;
scheduler.run(version_index_interval, move || {

View File

@@ -14,7 +14,7 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchMod>, IndexingE
let mut mods = sqlx::query!(
"
SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status FROM mods m
SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status, m.slug FROM mods m
"
).fetch(&pool);
@@ -129,6 +129,7 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchMod>, IndexingE
modified_timestamp: mod_data.updated.timestamp(),
latest_version,
host: Cow::Borrowed("modrinth"),
slug: mod_data.slug,
});
}
}
@@ -142,7 +143,7 @@ pub async fn query_one(
) -> Result<UploadSearchMod, IndexingError> {
let mod_data = sqlx::query!(
"
SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id
SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.slug
FROM mods m
WHERE id = $1
",
@@ -241,5 +242,6 @@ pub async fn query_one(
modified_timestamp: mod_data.updated.timestamp(),
latest_version,
host: Cow::Borrowed("modrinth"),
slug: mod_data.slug,
})
}

View File

@@ -62,6 +62,7 @@ pub struct SearchConfig {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UploadSearchMod {
pub mod_id: String,
pub slug: Option<String>,
pub author: String,
pub title: String,
pub description: String,
@@ -96,6 +97,7 @@ pub struct SearchResults {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ResultSearchMod {
pub mod_id: String,
pub slug: Option<String>,
pub author: String,
pub title: String,
pub description: String,