Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen LangNing committed Sep 15, 2023
1 parent 65b3fab commit afb202f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
52 changes: 50 additions & 2 deletions Server/Source/Process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ export class Process {
await this.XMOJDatabase.Delete("bbs_post", { post_id: Post["post_id"] });
continue;
}

let LockData = {
Locked: false,
LockPerson: "",
LockTime: 0
};
let Locked = ThrowErrorIfFailed(await this.XMOJDatabase.Select("bbs_lock", [], {
post_id: Data["PostID"]
}));
if (Locked.toString() != "") {
LockData.Locked = true;
LockData.LockPerson = Locked[0]["lock_person"];
LockData.LockTime = Locked[0]["lock_time"];
}

ResponseData.Posts.push({
PostID: Post["post_id"],
UserID: Post["user_id"],
Expand All @@ -168,7 +183,8 @@ export class Process {
PostTime: Post["post_time"],
ReplyCount: ReplyCount,
LastReplyUserID: LastReply[0]["user_id"],
LastReplyTime: LastReply[0]["reply_time"]
LastReplyTime: LastReply[0]["reply_time"],
Lock: LockData
});
}
return new Result(true, "获得讨论列表成功", ResponseData);
Expand All @@ -184,7 +200,12 @@ export class Process {
Title: "",
PostTime: 0,
Reply: new Array<Object>(),
PageCount: 0
PageCount: 0,
Lock: {
Locked: false,
LockPerson: "",
LockTime: 0
}
};
let Post = ThrowErrorIfFailed(await this.XMOJDatabase.Select("bbs_post", [], {
post_id: Data["PostID"]
Expand All @@ -203,6 +224,16 @@ export class Process {
ResponseData.ProblemID = Post[0]["problem_id"];
ResponseData.Title = Post[0]["title"];
ResponseData.PostTime = Post[0]["post_time"];

let Locked = ThrowErrorIfFailed(await this.XMOJDatabase.Select("bbs_lock", [], {
post_id: Data["PostID"]
}));
if (Locked.toString() != "") {
ResponseData.Lock.Locked = true;
ResponseData.Lock.LockPerson = Locked[0]["lock_person"];
ResponseData.Lock.LockTime = Locked[0]["lock_time"];
}

let Reply = ThrowErrorIfFailed(await this.XMOJDatabase.Select("bbs_reply", [], { post_id: Data["PostID"] }, {
Order: "reply_time",
OrderIncreasing: true,
Expand Down Expand Up @@ -239,6 +270,13 @@ export class Process {
}))["TableSize"] === 0) {
return new Result(false, "未找到讨论");
}

if (!this.SecurityChecker.IsAdmin() && ThrowErrorIfFailed(await this.XMOJDatabase.GetTableSize("bbs_lock", {
post_id: Reply[0]["post_id"]
}))["TableSize"] === 1) {
return new Result(false, "讨论已被锁定");
}

Data["Content"] = Data["Content"].trim();
if (Data["Content"] === "") {
return new Result(false, "内容不能为空");
Expand Down Expand Up @@ -278,6 +316,11 @@ export class Process {
if (Post.toString() == "") {
return new Result(false, "未找到讨论");
}
if (!this.SecurityChecker.IsAdmin() && ThrowErrorIfFailed(await this.XMOJDatabase.GetTableSize("bbs_lock", {
post_id: Data["PostID"]
}))["TableSize"] === 1) {
return new Result(false, "讨论已被锁定");
}
if (!this.SecurityChecker.IsAdmin() && CheckUserID && Post[0]["user_id"] != this.SecurityChecker.GetUsername()) {
return new Result(false, "没有权限删除此讨论");
}
Expand All @@ -300,6 +343,11 @@ export class Process {
if (Reply.toString() == "") {
return new Result(false, "未找到回复");
}
if (!this.SecurityChecker.IsAdmin() && ThrowErrorIfFailed(await this.XMOJDatabase.GetTableSize("bbs_lock", {
post_id: Reply[0]["post_id"]
}))["TableSize"] === 1) {
return new Result(false, "讨论已被锁定");
}
if (!this.SecurityChecker.IsAdmin() && Reply[0]["user_id"] != this.SecurityChecker.GetUsername()) {
return new Result(false, "没有权限删除此回复");
}
Expand Down
11 changes: 11 additions & 0 deletions XMOJ.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3545,6 +3545,11 @@ else {
InnerHTMLData += `<td>${Posts[i].PostID}</td>`;
InnerHTMLData += `<td>`;
InnerHTMLData += `<a href="http://www.xmoj.tech/discuss3/thread.php?tid=${Posts[i].PostID}">`;
if (Posts[i].Lock.Locked) {
InnerHTMLData += `<span class="text-muted">🔒 ${Posts[i].Title}</span>`;
} else {
InnerHTMLData += `<span>${Posts[i].Title}</span>`;
}
InnerHTMLData += `</a>`;
InnerHTMLData += `</td>`;
InnerHTMLData += `<td>`;
Expand Down Expand Up @@ -3825,6 +3830,7 @@ else {
DeleteButton.className = "btn btn-sm btn-danger ms-1";
DeleteButton.innerText = "删除";
DeleteButton.style.display = (AdminUserList.indexOf(profile.innerText) !== -1 || Replies[i].UserID == profile.innerText ? "" : "none");
DeleteButton.disabled = AdminUserList.indexOf(profile.innerText) === -1 && ResponseData.Lock.Locked;
DeleteButton.addEventListener("click", () => {
DeleteButton.disabled = true;
DeleteButton.lastChild.style.display = "";
Expand Down Expand Up @@ -3895,6 +3901,7 @@ else {
EditButton.className = "btn btn-sm btn-warning ms-1";
EditButton.innerText = "编辑";
EditButton.style.display = (AdminUserList.indexOf(profile.innerText) !== -1 || Replies[i].UserID == profile.innerText ? "" : "none");
EditButton.disabled = AdminUserList.indexOf(profile.innerText) === -1 && ResponseData.Lock.Locked;
EditButton.addEventListener("click", () => {
CardBodyElement.children[2].style.display = "none";
CardBodyElement.children[3].style.display = "";
Expand Down Expand Up @@ -3952,6 +3959,10 @@ else {
}).setSize("100%", "auto");
CodeElements[i].remove();
}
if (AdminUserList.indexOf(profile.innerText) === -1 && ResponseData.Lock.Locked) {
ContentElement.disabled = true;
ContentElement.innerHTML = "帖子已于 " + (new Date(ResponseData.Lock.Locked).toLocaleString()) + " 被 " + (await GetUsernameHTML(ResponseData.Lock.LockPerson)) + " 锁定";
}

Style.innerHTML += "img {";
Style.innerHTML += " width: 50%;";
Expand Down

0 comments on commit afb202f

Please sign in to comment.