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

feat: Add support for privileged user flag #324

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion app/components/board/post/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class PostComponent extends Component<Signature> {
if (typeof this.args.post.message === 'string') {
const content = this.contentParser.parsePostContent(
this.args.post.message,
{ groupId: this.args.post.author.groupId },
{ privileged: this.args.post.author.privileged },
);
return htmlSafe(content);
} else {
Expand Down
4 changes: 0 additions & 4 deletions app/config/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ export const appConfig = {
* The threshold for HTTP timeout warning in milliseconds.
*/
httpTimeoutWarningThreshold: 5000,
/**
* The default user group id. Other group ids define mods, admins and the like.
*/
standardUserGroupId: '3',
/**
* The refresh interval for the newsfeed in milliseconds.
*/
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class User extends Model {
declare age?: string;

@attr()
declare groupId?: string;
declare privileged?: boolean;

@attr()
declare locked?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion app/services/api/types/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export interface Read {
activity?: string;
status?: string;
age?: string;
groupId?: string;
locked?: boolean;
privileged: boolean;
}
10 changes: 5 additions & 5 deletions app/services/content-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ export default class ContentParserService extends Service {
/**
* Parses post content to HTML and returns the result.
* @param input The post content containing BBCode and other things.
* @param options.groupId (optional) The author's group id. Will be used to decide whether specific tags should be parsed at all (e.g. `[mod]`).
* Defaults to '3', the value for normal users.
* @param options.privileged (optional) Whether the author is considered privileged.
* Will be used to decide whether specific tags should be parsed at all (e.g. `[mod]`).
* @returns The HTML output.
*/
parsePostContent(input: string, options?: { groupId?: string }) {
const { groupId } = { groupId: appConfig.standardUserGroupId, ...options };
parsePostContent(input: string, options?: { privileged?: boolean }) {
const { privileged } = { ...options };
let output = input;
output = sanitize(output);
output = parseCode(output);
output = parseSimpleTags(output);
output = parseTex(output);
output = parsePrivilegedTags(output, groupId);
output = parsePrivilegedTags(output, privileged);
output = parseImg(output);
output = parseVideo(output, window.location);
output = parseUrl(output, {
Expand Down
11 changes: 4 additions & 7 deletions app/services/content-parser/privileged-tags.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { appConfig } from 'potber-client/config/app.config';

/**
* Parses all privileged tags. Privileged will only be parsed if the given `groupId` does not equal 3,
* which is the value for normal users.
* Parses all privileged tags.
* @param input The input string.
* @param groupId The group id.
* @param privileged Whether the user is privileged.
* @returns The output string.
*/
export function parsePrivilegedTags(input: string, groupId: string) {
if (groupId === appConfig.standardUserGroupId) {
export function parsePrivilegedTags(input: string, privileged?: boolean) {
if (!privileged) {
return input;
}
let output = input;
Expand Down
Loading