Pārlūkot izejas kodu

Fix Dashboard issues

Markus-Rost 4 gadi atpakaļ
vecāks
revīzija
749bd73c5e
5 mainītis faili ar 28 papildinājumiem un 9 dzēšanām
  1. 3 1
      dashboard/guilds.js
  2. 14 2
      dashboard/index.js
  3. 1 1
      dashboard/oauth.js
  4. 5 5
      dashboard/settings.js
  5. 5 0
      i18n/en.json

+ 3 - 1
dashboard/guilds.js

@@ -42,6 +42,7 @@ function dashboard_guilds(res, state, reqURL) {
 		}).prependTo('#text');
 	}
 	if ( reqURL.searchParams.get('save') === 'success' ) {
+		$('<script>').text(`history.replaceState(null, null, '${reqURL.pathname}')`).insertBefore('script#indexjs');
 		createNotice($, {
 			type: 'success',
 			title: 'Settings saved!',
@@ -49,6 +50,7 @@ function dashboard_guilds(res, state, reqURL) {
 		}).prependTo('#text');
 	}
 	if ( reqURL.searchParams.get('save') === 'failed' ) {
+		$('<script>').text(`history.replaceState(null, null, '${reqURL.pathname}')`).insertBefore('script#indexjs');
 		let reason = '';
 		if ( reqURL.searchParams.has('reason') ) {
 			reason += '\nReason: ' + reqURL.searchParams.get('reason');
@@ -122,7 +124,7 @@ function dashboard_guilds(res, state, reqURL) {
 		else if ( settings.guilds.notMember.has(id) ) {
 			let guild = settings.guilds.notMember.get(id);
 			$('head title').text(`${guild.name} – ` + $('head title').text());
-			res.setHeader('Set-Cookie', [`guild="${guild.id}"; HttpOnly; Path=/`]);
+			res.setHeader('Set-Cookie', [`guild="${guild.id}/settings"; HttpOnly; Path=/`]);
 			let url = oauth.generateAuthUrl( {
 				scope: ['identify', 'guilds', 'bot'],
 				permissions: defaultPermissions,

+ 14 - 2
dashboard/index.js

@@ -113,8 +113,8 @@ const server = http.createServer((req, res) => {
 	res.setHeader('Content-Language', ['en']);
 
 	var lastGuild = req.headers?.cookie?.split('; ')?.filter( cookie => {
-		return cookie.split('=')[0] === 'guild';
-	} )?.map( cookie => cookie.replace( /^guild="(\w*)"$/, '$1' ) )?.join();
+		return cookie.split('=')[0] === 'guild' && /^\d+\/(?:settings|verification|rcscript)(?:\/(?:\d+|new))?$/.test(( cookie.split('=')[1] || '' ));
+	} )?.map( cookie => cookie.replace( /^guild="(\d+\/(?:settings|verification|rcscript)(?:\/(?:\d+|new))?)"$/, '$1' ) )?.join();
 	if ( lastGuild ) res.setHeader('Set-Cookie', ['guild=""; HttpOnly; Path=/; Max-Age=0']);
 
 	var state = req.headers.cookie?.split('; ')?.filter( cookie => {
@@ -135,6 +135,12 @@ const server = http.createServer((req, res) => {
 	}
 
 	if ( !state ) {
+		if ( reqURL.pathname.startsWith( '/guild/' ) ) {
+			let pathGuild = reqURL.pathname.split('/').slice(2, 5).join('/');
+			if ( /^\d+\/(?:settings|verification|rcscript)(?:\/(?:\d+|new))?$/.test(pathGuild) ) {
+				res.setHeader('Set-Cookie', [`guild="${pathGuild}"; HttpOnly; Path=/`]);
+			}
+		}
 		return pages.login(res, state, ( reqURL.pathname === '/' ? '' : 'unauthorized' ));
 	}
 
@@ -143,6 +149,12 @@ const server = http.createServer((req, res) => {
 	}
 
 	if ( !settingsData.has(state) ) {
+		if ( reqURL.pathname.startsWith( '/guild/' ) ) {
+			let pathGuild = reqURL.pathname.split('/').slice(2, 5).join('/');
+			if ( /^\d+\/(?:settings|verification|rcscript)(?:\/(?:\d+|new))?$/.test(pathGuild) ) {
+				res.setHeader('Set-Cookie', [`guild="${pathGuild}"; HttpOnly; Path=/`]);
+			}
+		}
 		return pages.login(res, state, ( reqURL.pathname === '/' ? '' : 'unauthorized' ));
 	}
 

+ 1 - 1
dashboard/oauth.js

@@ -156,7 +156,7 @@ function dashboard_oauth(res, state, searchParams, lastGuild) {
 				} );
 				settingsData.set(settings.state, settings);
 				res.writeHead(302, {
-					Location: ( lastGuild ? `/guild/${lastGuild}/settings` : '/' ),
+					Location: ( lastGuild && /^\d+\/(?:settings|verification|rcscript)(?:\/(?:\d+|new))?$/.test(lastGuild) ? `/guild/${lastGuild}` : '/' ),
 					'Set-Cookie': [`wikibot="${settings.state}"; HttpOnly; Path=/`]
 				});
 				return res.end();

+ 5 - 5
dashboard/settings.js

@@ -237,7 +237,7 @@ function update_settings(res, userSettings, guild, type, settings) {
 					}
 					if ( !row ) return;
 					var lang = new Lang(row.lang);
-					var text = `<@${userSettings.user.id}> removed the settings for <#${type}>.`;
+					var text = lang.get('settings.dashboard.removed', `<@${userSettings.user.id}>`, `<#${type}>`);
 					text += '\n' + new URL(`/guild/${guild}/settings`, process.env.dashboard).href;
 					sendMsg( {
 						type: 'notifyGuild', guild, text
@@ -333,7 +333,7 @@ function update_settings(res, userSettings, guild, type, settings) {
 					}
 					console.log( '- Dashboard: Settings successfully saved: ' + guild );
 					res(`/guild/${guild}/settings?save=success`);
-					var text = `<@${userSettings.user.id}> updated the server settings.`;
+					var text = lang.get('settings.dashboard.updated', `<@${userSettings.user.id}>`);
 					text += '\n' + lang.get('settings.currentwiki') + ` <${wiki.href}>`;
 					text += '\n' + lang.get('settings.currentlang') + ` \`${allLangs.names[settings.lang]}\``;
 					if ( response.patreon ) {
@@ -368,7 +368,7 @@ function update_settings(res, userSettings, guild, type, settings) {
 					}
 					console.log( '- Dashboard: Settings successfully saved: ' + guild );
 					res(`/guild/${guild}/settings?save=success`);
-					var text = `<@${userSettings.user.id}> updated the server settings.`;
+					var text = lang.get('settings.dashboard.updated', `<@${userSettings.user.id}>`);
 					text += '\n' + diff.join('\n');
 					text += '\n' + new URL(`/guild/${guild}/settings`, process.env.dashboard).href;
 					sendMsg( {
@@ -396,7 +396,7 @@ function update_settings(res, userSettings, guild, type, settings) {
 					}
 					console.log( `- Dashboard: Settings successfully removed: ${guild}#${type}` );
 					res(`/guild/${guild}/settings?save=success`);
-					var text = `<@${userSettings.user.id}> removed the settings for <#${type}>.`;
+					var text = lang.get('settings.dashboard.removed', `<@${userSettings.user.id}>`, `<#${type}>`);
 					text += '\n' + new URL(`/guild/${guild}/settings`, process.env.dashboard).href;
 					sendMsg( {
 						type: 'notifyGuild', guild, text
@@ -436,7 +436,7 @@ function update_settings(res, userSettings, guild, type, settings) {
 						}
 						console.log( `- Dashboard: Settings successfully saved: ${guild}#${settings.channel}` );
 						res(`/guild/${guild}/settings/${settings.channel}?save=success`);
-						var text = `<@${userSettings.user.id}> updated the settings for <#${settings.channel}>.`;
+						var text = lang.get('settings.dashboard.channel', `<@${userSettings.user.id}>`, `<#${settings.channel}>`);
 						text += '\n' + diff.join('\n');
 						text += '\n' + new URL(`/guild/${guild}/settings/${settings.channel}`, process.env.dashboard).href;
 						sendMsg( {

+ 5 - 0
i18n/en.json

@@ -522,6 +522,11 @@
         "currentlang": "Language:",
         "currentprefix": "Prefix:",
         "currentwiki": "Default wiki:",
+        "dashboard": {
+            "channel": "$1 updated the settings for $2.",
+            "removed": "$1 removed the settings for $2.",
+            "updated": "$1 updated the server settings."
+        },
         "foundwikis": "Do you mean any of these wikis?",
         "inline disabled": {
             "channel inline": "inline commands are currently disabled for this channel.",