Skip to content

Commit 0f415a5

Browse files
committed
0.9.1
Ability to show admin scores and bug fixes
1 parent 99c9c20 commit 0f415a5

File tree

3 files changed

+60
-28
lines changed

3 files changed

+60
-28
lines changed

api/api.js

+2-18
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,21 @@ MongoDB.MongoClient.connect('mongodb://localhost:27017', {
141141
}
142142
}
143143

144-
app.get('/v1/account/disableCreate', async (req, res) => {
144+
app.get('/v1/account/disableStates', async (req, res) => {
145145
try {
146146
if (req.headers.authorization == undefined) throw new Error('MissingToken');
147147
const username = signer.unsign(req.headers.authorization);
148148
if (await checkPermissions(username) < 2) throw new Error('Permissions');
149149
res.send({
150150
success: true,
151-
state: cache.registerDisable
151+
states: {registerDisable: cache.registerDisable, adminShowDisable: cache.adminShowDisable}
152152
});
153153
}
154154
catch (err) {
155155
errors(err, res);
156156
}
157157
});
158158

159-
160159
app.post('/v1/account/disableCreate', async (req, res) => {
161160
try {
162161
if (req.headers.authorization == undefined) throw new Error('MissingToken');
@@ -178,21 +177,6 @@ MongoDB.MongoClient.connect('mongodb://localhost:27017', {
178177
}
179178
});
180179

181-
app.get('/v1/account/adminShowDisable', async (req, res) => {
182-
try {
183-
if (req.headers.authorization == undefined) throw new Error('MissingToken');
184-
const username = signer.unsign(req.headers.authorization);
185-
if (await checkPermissions(username) < 2) throw new Error('Permissions');
186-
res.send({
187-
success: true,
188-
state: cache.adminShowDisable
189-
});
190-
}
191-
catch (err) {
192-
errors(err, res);
193-
}
194-
});
195-
196180

197181
app.post('/v1/account/adminShowDisable', async (req, res) => {
198182
try {

client/src/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const Login = lazy(() => import("./login.js"));
3434
const Admin = lazy(() => import("./admin.js"));
3535
const Oops = lazy(() => import("./oops.js"));
3636

37-
var ctfxVersion = "0.9"
37+
var ctfxVersion = "0.9.1"
3838

3939

4040
class App extends React.Component {

client/src/adminUsers.js

+57-9
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,29 @@ class AdminUsers extends React.Component {
105105
modalLoading: false,
106106
disableRegisterState: false,
107107
disableLoading: false,
108+
disableLoading2: false,
109+
disableAdminShow: false,
108110
selectedTableKeys: [],
109111
disableEditButtons: true
110112
}
111113
}
112114

113115
componentDidMount() {
114116
this.fillTableData()
115-
this.getDisableRegister()
117+
this.getDisableStates()
116118
}
117119

118-
getDisableRegister = async () => {
120+
getDisableStates = async () => {
119121
this.setState({ disableLoading: true })
120-
await fetch(window.ipAddress + "/v1/account/disableCreate", {
122+
await fetch(window.ipAddress + "/v1/account/disableStates", {
121123
method: 'get',
122124
headers: { 'Content-Type': 'application/json', "Authorization": localStorage.getItem("IRSCTF-token") },
123125
}).then((results) => {
124126
return results.json(); //return data in JSON (since its JSON data)
125127
}).then((data) => {
126128
if (data.success === true) {
127129
//console.log(data)
128-
this.setState({ disableRegisterState: data.state })
130+
this.setState({ disableRegisterState: data.states.registerDisable, disableAdminShow: data.states.adminShowDisable })
129131
}
130132
else {
131133
message.error({ content: "Oops. Unknown error" })
@@ -193,7 +195,7 @@ class AdminUsers extends React.Component {
193195

194196

195197
deleteAccounts = async (close, users) => {
196-
this.setState({disableEditButtons: true})
198+
this.setState({ disableEditButtons: true })
197199
await fetch(window.ipAddress + "/v1/account/delete", {
198200
method: 'post',
199201
headers: { 'Content-Type': 'application/json', "Authorization": localStorage.getItem("IRSCTF-token") },
@@ -215,16 +217,16 @@ class AdminUsers extends React.Component {
215217
else {
216218
message.error({ content: "Oops. Unknown error" })
217219
}
218-
220+
219221

220222

221223
}).catch((error) => {
222224
console.log(error)
223225
message.error({ content: "Oops. There was an issue connecting with the server" });
224-
226+
225227
})
226228
close()
227-
this.setState({selectedTableKeys: []})
229+
this.setState({ selectedTableKeys: [] })
228230

229231
}
230232

@@ -301,6 +303,38 @@ class AdminUsers extends React.Component {
301303
this.setState({ disableLoading: false })
302304
}
303305

306+
disableAdminShow = async (value) => {
307+
this.setState({ disableLoading2: true })
308+
await fetch(window.ipAddress + "/v1/account/adminShowDisable", {
309+
method: 'post',
310+
headers: { 'Content-Type': 'application/json', "Authorization": localStorage.getItem("IRSCTF-token") },
311+
body: JSON.stringify({
312+
disable: value
313+
})
314+
}).then((results) => {
315+
return results.json(); //return data in JSON (since its JSON data)
316+
}).then((data) => {
317+
if (data.success === true) {
318+
if (value) {
319+
message.success("Admin scores disabled")
320+
}
321+
else {
322+
message.success("Admin scores enabled")
323+
}
324+
this.setState({ disableAdminShow: value })
325+
326+
}
327+
else {
328+
message.error({ content: "Oops. Unknown error" })
329+
}
330+
331+
332+
}).catch((error) => {
333+
message.error({ content: "Oops. There was an issue connecting with the server" });
334+
})
335+
this.setState({ disableLoading2: false })
336+
}
337+
304338

305339
handleTableSelect = (selectedRowKeys) => {
306340
this.setState({ selectedTableKeys: selectedRowKeys })
@@ -413,7 +447,21 @@ class AdminUsers extends React.Component {
413447
/>
414448
</Table>
415449
<Divider />
416-
<h3>Disable User Registration: <Switch disabled={this.state.disableLoading} onClick={this.disableRegister} checked={this.state.disableRegisterState} /></h3>
450+
451+
<div style={{ display: "flex", justifyContent: "space-between" }}>
452+
453+
<div>
454+
<h3>Disable User Registration: <Switch disabled={this.state.disableLoading} onClick={this.disableRegister} checked={this.state.disableRegisterState} /></h3>
455+
<p>Disables user registration for unregistered users. Admins can still create users from this page.</p>
456+
</div>
457+
458+
<Divider type="vertical" style={{ height: "inherit" }} />
459+
460+
<div>
461+
<h3>Disable Admin Scores: <Switch disabled={this.state.disableLoading2} onClick={this.disableAdminShow} checked={this.state.disableAdminShow} /></h3>
462+
<p>Prevents admin scores from showing up on scoreboards and profile pages. Admin solves will still appear under the solve list in challenges.</p>
463+
</div>
464+
</div>
417465

418466
</Layout>
419467
);

0 commit comments

Comments
 (0)