Skip to content

Commit a245acd

Browse files
Add user authentication for faculty commands
1 parent ee908e8 commit a245acd

19 files changed

+93
-0
lines changed

src/discordBot/commands/faculty/add_instructors.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const { editEphemeral, editErrorEphemeral, sendEphemeral } = require("../../serv
77
const { courseAdminRole, facultyRole } = require("../../../../config.json");
88

99
const execute = async (interaction, client, models) => {
10+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) { // Olisiko parempi tarkistaa tietokannasta eikä discordista?
11+
await sendEphemeral(interaction, "You do not have permission to use this command.");
12+
return
13+
}
14+
1015
await sendEphemeral(interaction, "Adding instructors...");
1116

1217
const courseModel = models.Course;

src/discordBot/commands/faculty/create_channel.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const { sendEphemeral, editEphemeral, editErrorEphemeral } = require("../../serv
66
const { facultyRole } = require("../../../../config.json");
77

88
const execute = async (interaction, client, models) => {
9+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) {
10+
await sendEphemeral(interaction, "You do not have permission to use this command.");
11+
return
12+
}
13+
914
await sendEphemeral(interaction, "Creating text channel...");
1015

1116
const courseModel = models.Course;

src/discordBot/commands/faculty/create_course.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const { sendErrorEphemeral, sendEphemeral, editEphemeral } = require("../../serv
88
const { facultyRole } = require("../../../../config.json");
99

1010
const execute = async (interaction, client, models) => {
11+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) {
12+
await sendEphemeral(interaction, "You do not have permission to use this command.");
13+
return
14+
}
15+
1116
const courseCode = interaction.options.getString("coursecode").replace(/\s/g, "");
1217
const courseFullName = interaction.options.getString("full_name").trim();
1318
if (await findCourseFromDbWithFullName(courseFullName, models.Course)) return await sendErrorEphemeral(interaction, "Course fullname must be unique.");

src/discordBot/commands/faculty/create_poll.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const { facultyRole } = require("../../../../config.json");
77
const numbers = [ "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟" ];
88

99
const execute = async (interaction, client) => {
10+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) {
11+
await sendEphemeral(interaction, "You do not have permission to use this command.");
12+
return
13+
}
1014

1115
const guild = client.guild;
1216
const channel = guild.channels.cache.get(interaction.channelId);

src/discordBot/commands/faculty/delete_bridge.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const { sendMessageToTelegram } = require("../../../telegramBot/bridge/service")
77

88

99
const execute = async (interaction, client, models) => {
10+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) {
11+
await sendEphemeral(interaction, "You do not have permission to use this command.");
12+
return
13+
}
1014

1115
await sendEphemeral(interaction, "Deleting bridge...");
1216
const Course = models.Course;

src/discordBot/commands/faculty/delete_channel.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const { confirmChoice } = require("../../services/confirm");
77
const { facultyRole } = require("../../../../config.json");
88

99
const execute = async (interaction, client, models) => {
10+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) {
11+
await sendEphemeral(interaction, "You do not have permission to use this command.");
12+
return
13+
}
14+
1015
await sendEphemeral(interaction, "Deleting text channel...");
1116
const channelModel = models.Channel;
1217
const courseModel = models.Course;

src/discordBot/commands/faculty/disable_bridge.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const { confirmChoice } = require("../../services/confirm");
77
const { facultyRole } = require("../../../../config.json");
88

99
const execute = async (interaction, client, models) => {
10+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) {
11+
await sendEphemeral(interaction, "You do not have permission to use this command.");
12+
return
13+
}
14+
1015
await sendEphemeral(interaction, "Disabling the bridge to Telegram...");
1116

1217
const channel = client.guild.channels.cache.get(interaction.channelId);

src/discordBot/commands/faculty/edit_course.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const changeCourseNick = async (interaction, client, models, courseName, newValu
6666
};
6767

6868
const execute = async (interaction, client, models) => {
69+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) {
70+
await sendEphemeral(interaction, "You do not have permission to use this command.");
71+
return
72+
}
73+
6974
await sendEphemeral(interaction, "Editing...");
7075
const guild = client.guild;
7176
const interactionChannel = guild.channels.cache.get(interaction.channelId);

src/discordBot/commands/faculty/edit_topic.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const { facultyRole } = require("../../../../config.json");
1111
const { saveChannelTopicToDb } = require("../../../db/services/channelService");
1212

1313
const execute = async (interaction, client, models) => {
14+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) {
15+
await sendEphemeral(interaction, "You do not have permission to use this command.");
16+
return
17+
}
18+
1419
await sendEphemeral(interaction, "Editing topic...");
1520
const newTopic = interaction.options.getString("topic").trim();
1621

src/discordBot/commands/faculty/enable_bridge.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const { confirmChoice } = require("../../services/confirm");
77
const { facultyRole } = require("../../../../config.json");
88

99
const execute = async (interaction, client, models) => {
10+
if (!interaction.member.permissions.has("ADMINISTRATOR") && !interaction.member.roles.cache.some(r => r.name === facultyRole)) {
11+
await sendEphemeral(interaction, "You do not have permission to use this command.");
12+
return
13+
}
14+
1015
await sendEphemeral(interaction, "Enabling the bridge to Telegram...");
1116

1217
const channel = client.guild.channels.cache.get(interaction.channelId);

0 commit comments

Comments
 (0)