Skip to content

Commit f6c68ec

Browse files
committed
Add another option to get chapters submitting permission
1 parent 2ecf4b3 commit f6c68ec

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/utils/permissions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ interface CanSubmitResult {
1212
reason?: string;
1313
}
1414

15+
async function lowDownvotes(userID: HashedUserID): Promise<boolean> {
16+
const result = await db.prepare("get", `SELECT count(*) as "submissionCount", SUM(CASE WHEN "votes" < 0 AND "views" > 5 THEN 1 ELSE 0 END) AS "downvotedSubmissions" FROM "sponsorTimes" WHERE "userID" = ?`
17+
, [userID], { useReplica: true });
18+
19+
return result.submissionCount > 100 && result.downvotedSubmissions / result.submissionCount < 0.15;
20+
}
21+
1522
export async function canSubmit(userID: HashedUserID, category: Category): Promise<CanSubmitResult> {
1623
switch (category) {
1724
case "chapter":
1825
return {
1926
canSubmit: await oneOf([isUserVIP(userID),
27+
lowDownvotes(userID),
2028
(async () => (await getReputation(userID)) > config.minReputationToSubmitChapter)(),
2129
hasFeature(userID, Feature.ChapterSubmitter)
2230
])

0 commit comments

Comments
 (0)