Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad words filter #395

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acmucsd/membership-portal",
"version": "3.2.0",
"version": "3.2.1",
"description": "REST API for ACM UCSD's membership portal.",
"main": "index.d.ts",
"files": [
Expand Down Expand Up @@ -55,6 +55,7 @@
"moment-timezone": "^0.5.34",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"obscenity": "^0.2.0",
"pg": "^8.6.0",
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.9.0",
Expand Down
14 changes: 14 additions & 0 deletions services/UserAccountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { EntityManager } from 'typeorm';
import * as moment from 'moment';
import * as faker from 'faker';
import { UserAccessUpdates } from 'api/validators/AdminControllerRequests';
import {
RegExpMatcher,
englishDataset,
englishRecommendedTransformers,
} from 'obscenity';
import Repositories, { TransactionsManager } from '../repositories';
import {
Uuid,
Expand All @@ -23,8 +28,14 @@ import { UserModel } from '../models/UserModel';
export default class UserAccountService {
private transactions: TransactionsManager;

private matcher: RegExpMatcher;

constructor(@InjectManager() entityManager: EntityManager) {
this.transactions = new TransactionsManager(entityManager);
this.matcher = new RegExpMatcher({
...englishDataset.build(),
...englishRecommendedTransformers,
});
}

public async findByUuid(uuid: Uuid): Promise<UserModel> {
Expand Down Expand Up @@ -104,6 +115,9 @@ export default class UserAccountService {
}
changes.hash = await UserRepository.generateHash(newPassword);
}
if (this.matcher.hasMatch(userPatches.handle)) {
throw new ForbiddenError('Please remove profanity from handle.');
}
return this.transactions.readWrite(async (txn) => {
if (userPatches.handle) {
const userRepository = Repositories.user(txn);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4342,6 +4342,11 @@ object.values@^1.1.5:
define-properties "^1.1.3"
es-abstract "^1.19.1"

obscenity@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/obscenity/-/obscenity-0.2.0.tgz#5a234c7af0aaebcd58fc762b29d2852104350fa2"
integrity sha512-eYe8r9hqJk5dEMZkLtWlGlwGxKYO6xA/yEOzd8MGSG3vzn8hAgo6MUZ9dirA3kPAfy/1d1jEOkCUpIU1nGI1EQ==

on-finished@^2.3.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.4.1.tgz#58c8c44116e54845ad57f14ab10b03533184ac3f"
Expand Down
Loading