@@ -16,7 +16,14 @@ async function sendDiscordEmbed(embed: Embed) {
1616}
1717
1818export async function banUserPlatform ( userId : string , banReason : string , banEnd ?: string ) {
19+ const operator = await getUserFromSession ( )
20+ if ( ! operator ) {
21+ throw new Error ( 'Not allowed' )
22+ }
1923 try {
24+ if ( operator . role !== "admin" ) {
25+ return { success : false , error : 'Unauthorized' }
26+ }
2027 const updateData : any = {
2128 loginAllowed : false ,
2229 banReason : banReason
@@ -63,6 +70,10 @@ export async function banUserPlatform(userId: string, banReason: string, banEnd?
6370}
6471
6572export async function banUserForum ( userId : string , banReason : string , banEnd ?: string ) {
73+ const operator = await getUserFromSession ( )
74+ if ( ! operator || ! ( operator . role !== "admin" ) ) {
75+ return { success : false , error : 'Unauthorized' }
76+ }
6677 try {
6778 const updateData : any = {
6879 forumAllowed : false ,
@@ -99,6 +110,10 @@ export async function banUserForum(userId: string, banReason: string, banEnd?: s
99110 }
100111}
101112export async function unbanUserPlatform ( userId : string ) {
113+ const operator = await getUserFromSession ( )
114+ if ( ! operator || ! ( operator . role !== "admin" ) ) {
115+ return { success : false , error : 'Unauthorized' }
116+ }
102117 try {
103118 await prisma . user . update ( {
104119 where : {
@@ -131,6 +146,10 @@ export async function unbanUserPlatform(userId: string) {
131146 }
132147}
133148export async function unbanUserForum ( userId : string ) {
149+ const operator = await getUserFromSession ( )
150+ if ( ! operator || ! ( operator . role !== "admin" ) ) {
151+ return { success : false , error : 'Unauthorized' }
152+ }
134153 try {
135154 await prisma . user . update ( {
136155 where : {
0 commit comments