Spaces:
Running
Running
Upload 9 files
Browse files- src/services/auth.js +6 -2
- src/views/InstructorView.js +27 -8
src/services/auth.js
CHANGED
|
@@ -87,8 +87,11 @@ export async function checkInstructorPermission(user) {
|
|
| 87 |
let snap;
|
| 88 |
|
| 89 |
try {
|
|
|
|
| 90 |
snap = await getDoc(instructorRef);
|
|
|
|
| 91 |
} catch (error) {
|
|
|
|
| 92 |
console.warn("Instructor Permission Check Failed (likely not whitelisted):", error.code);
|
| 93 |
// If permission denied, it means they are not allowed to read the doc => likely not in whitelist
|
| 94 |
return null;
|
|
@@ -147,9 +150,10 @@ export async function getInstructors() {
|
|
| 147 |
* Add new instructor (Admin Only)
|
| 148 |
*/
|
| 149 |
export async function addInstructor(email, name, permissions) {
|
| 150 |
-
const
|
|
|
|
| 151 |
await setDoc(instructorRef, {
|
| 152 |
-
email,
|
| 153 |
name,
|
| 154 |
role: 'instructor',
|
| 155 |
permissions,
|
|
|
|
| 87 |
let snap;
|
| 88 |
|
| 89 |
try {
|
| 90 |
+
console.log(`[Permission Check] Checking whitelist for email: '${email}'`);
|
| 91 |
snap = await getDoc(instructorRef);
|
| 92 |
+
console.log(`[Permission Check] Result for '${email}': exists=${snap.exists()}`);
|
| 93 |
} catch (error) {
|
| 94 |
+
console.warn(`[Permission Check] Failed for '${email}'. Error:`, error);
|
| 95 |
console.warn("Instructor Permission Check Failed (likely not whitelisted):", error.code);
|
| 96 |
// If permission denied, it means they are not allowed to read the doc => likely not in whitelist
|
| 97 |
return null;
|
|
|
|
| 150 |
* Add new instructor (Admin Only)
|
| 151 |
*/
|
| 152 |
export async function addInstructor(email, name, permissions) {
|
| 153 |
+
const safeEmail = email.trim(); // Ensure no leading/trailing spaces
|
| 154 |
+
const instructorRef = doc(db, INSTRUCTORS_COLLECTION, safeEmail);
|
| 155 |
await setDoc(instructorRef, {
|
| 156 |
+
email: safeEmail,
|
| 157 |
name,
|
| 158 |
role: 'instructor',
|
| 159 |
permissions,
|
src/views/InstructorView.js
CHANGED
|
@@ -336,23 +336,42 @@ export async function renderInstructorView() {
|
|
| 336 |
}
|
| 337 |
|
| 338 |
export function setupInstructorEvents() {
|
|
|
|
| 339 |
// Utility for cleaning prompt indentation
|
| 340 |
function stripIndent(str) {
|
| 341 |
if (!str) return '';
|
| 342 |
-
//
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
|
| 345 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
const minIndent = lines.reduce((min, line) => {
|
| 347 |
-
if (!line.trim()) return min;
|
| 348 |
-
const
|
|
|
|
| 349 |
return Math.min(min, indent);
|
| 350 |
}, Infinity);
|
| 351 |
|
| 352 |
-
if (minIndent === Infinity) return str.trim();
|
| 353 |
|
| 354 |
-
// Strip indent
|
| 355 |
-
return lines.map(line =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
}
|
| 357 |
|
| 358 |
let roomUnsubscribe = null;
|
|
|
|
| 336 |
}
|
| 337 |
|
| 338 |
export function setupInstructorEvents() {
|
| 339 |
+
// Utility for cleaning prompt indentation
|
| 340 |
// Utility for cleaning prompt indentation
|
| 341 |
function stripIndent(str) {
|
| 342 |
if (!str) return '';
|
| 343 |
+
// 1. Split into lines
|
| 344 |
+
let lines = str.split('\n');
|
| 345 |
+
|
| 346 |
+
// 2. Remove leading empty lines (often result of template literals)
|
| 347 |
+
while (lines.length > 0 && lines[0].trim() === '') {
|
| 348 |
+
lines.shift();
|
| 349 |
+
}
|
| 350 |
|
| 351 |
+
// 3. Remove trailing empty lines
|
| 352 |
+
while (lines.length > 0 && lines[lines.length - 1].trim() === '') {
|
| 353 |
+
lines.pop();
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
if (lines.length === 0) return '';
|
| 357 |
+
|
| 358 |
+
// 4. Find min indent
|
| 359 |
const minIndent = lines.reduce((min, line) => {
|
| 360 |
+
if (!line.trim()) return min; // Ignore empty lines
|
| 361 |
+
const match = line.match(/^ */);
|
| 362 |
+
const indent = match ? match[0].length : 0;
|
| 363 |
return Math.min(min, indent);
|
| 364 |
}, Infinity);
|
| 365 |
|
| 366 |
+
if (minIndent === Infinity) return str.trim();
|
| 367 |
|
| 368 |
+
// 5. Strip indent
|
| 369 |
+
return lines.map(line => {
|
| 370 |
+
if (line.length >= minIndent) {
|
| 371 |
+
return line.slice(minIndent);
|
| 372 |
+
}
|
| 373 |
+
return line;
|
| 374 |
+
}).join('\n');
|
| 375 |
}
|
| 376 |
|
| 377 |
let roomUnsubscribe = null;
|