Skip to content

Commit

Permalink
Disable chat and message deletion for "chat-admin"
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Mar 10, 2024
1 parent dbbf737 commit 3862e31
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 5 additions & 0 deletions controllers/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func (c *ApiController) AddChat() {
}

func (c *ApiController) DeleteChat() {
ok := c.RequireAdmin()
if !ok {
return
}

var chat object.Chat
err := json.Unmarshal(c.Ctx.Input.RequestBody, &chat)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions controllers/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ func (c *ApiController) AddMessage() {
}

func (c *ApiController) DeleteMessage() {
ok := c.RequireAdmin()
if !ok {
return
}

var message object.Message
err := json.Unmarshal(c.Ctx.Input.RequestBody, &message)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions web/src/ChatListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class ChatListPage extends React.Component {
okText={i18next.t("general:OK")}
cancelText={i18next.t("general:Cancel")}
>
<Button style={{marginBottom: "10px"}} type="primary" danger>{i18next.t("general:Delete")}</Button>
<Button disabled={!Setting.isLocalAdminUser(this.props.account)} style={{marginBottom: "10px"}} type="primary" danger>{i18next.t("general:Delete")}</Button>
</Popconfirm>
</div>
);
Expand Down Expand Up @@ -442,7 +442,7 @@ class ChatListPage extends React.Component {
title={() => (
<div>
{i18next.t("chat:Chats")}&nbsp;&nbsp;&nbsp;&nbsp;
<Button type="primary" size="small" onClick={this.addChat.bind(this)}>{i18next.t("general:Add")}</Button>
<Button disabled={!Setting.isLocalAdminUser(this.props.account)} type="primary" size="small" onClick={this.addChat.bind(this)}>{i18next.t("general:Add")}</Button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{/* {i18next.t("chat:Filter single chat")}*/}
{/* &nbsp;&nbsp;&nbsp;&nbsp;*/}
Expand Down
13 changes: 3 additions & 10 deletions web/src/MessageListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class MessageListPage extends React.Component {
okText={i18next.t("general:OK")}
cancelText={i18next.t("general:Cancel")}
>
<Button style={{marginBottom: "10px"}} type="primary" danger>
<Button disabled={!Setting.isLocalAdminUser(this.props.account)} style={{marginBottom: "10px"}} type="primary" danger>
{i18next.t("general:Delete")}
</Button>
</Popconfirm>
Expand All @@ -308,18 +308,11 @@ class MessageListPage extends React.Component {

return (
<div>
<Table
scroll={{x: "max-content"}}
columns={columns}
dataSource={messages}
rowKey="name"
size="middle"
bordered
pagination={{pageSize: 100}}
<Table scroll={{x: "max-content"}} columns={columns} dataSource={messages} rowKey="name" size="middle" bordered pagination={{pageSize: 100}}
title={() => (
<div>
{i18next.t("message:Messages")}&nbsp;&nbsp;&nbsp;&nbsp;
<Button type="primary" size="small" onClick={this.addMessage.bind(this)}>
<Button disabled={!Setting.isLocalAdminUser(this.props.account)} type="primary" size="small" onClick={this.addMessage.bind(this)}>
{i18next.t("general:Add")}
</Button>
</div>
Expand Down

0 comments on commit 3862e31

Please sign in to comment.