mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-29 18:16:17 +01:00 
			
		
		
		
	fix: use slug instead of groupname in acp for groups
#13286, acp page was inaccessible
This commit is contained in:
		| @@ -136,8 +136,8 @@ paths: | ||||
|     $ref: 'read/admin/manage/admins-mods.yaml' | ||||
|   /api/admin/manage/groups: | ||||
|     $ref: 'read/admin/manage/groups.yaml' | ||||
|   "/api/admin/manage/groups/{name}": | ||||
|     $ref: 'read/admin/manage/groups/name.yaml' | ||||
|   "/api/admin/manage/groups/{slug}": | ||||
|     $ref: 'read/admin/manage/groups/slug.yaml' | ||||
|   /api/admin/manage/uploads: | ||||
|     $ref: 'read/admin/manage/uploads.yaml' | ||||
|   /api/admin/manage/digest: | ||||
|   | ||||
| @@ -3,7 +3,7 @@ get: | ||||
|     - admin | ||||
|   summary: Get user group details | ||||
|   parameters: | ||||
|     - name: name | ||||
|     - name: slug | ||||
|       in: path | ||||
|       required: true | ||||
|       schema: | ||||
| @@ -29,6 +29,8 @@ get: | ||||
|                           type: string | ||||
|                         displayName: | ||||
|                           type: string | ||||
|                         slug: | ||||
|                           type: string | ||||
|                         selected: | ||||
|                           type: boolean | ||||
|                   allowPrivateGroups: | ||||
| @@ -27,10 +27,6 @@ define('admin/manage/group', [ | ||||
|  | ||||
| 		const groupName = ajaxify.data.group.name; | ||||
|  | ||||
| 		$('#group-selector').on('change', function () { | ||||
| 			ajaxify.go('admin/manage/groups/' + $(this).val() + window.location.hash); | ||||
| 		}); | ||||
|  | ||||
| 		memberList.init('admin/manage/group'); | ||||
|  | ||||
| 		changeGroupUserTitle.on('keyup', function () { | ||||
|   | ||||
| @@ -9,7 +9,6 @@ const groups = require('../../groups'); | ||||
| const meta = require('../../meta'); | ||||
| const pagination = require('../../pagination'); | ||||
| const events = require('../../events'); | ||||
| const slugify = require('../../slugify'); | ||||
|  | ||||
| const groupsController = module.exports; | ||||
|  | ||||
| @@ -23,7 +22,7 @@ groupsController.list = async function (req, res) { | ||||
| 	const stop = start + groupsPerPage - 1; | ||||
| 	groupNames = groupNames.slice(start, stop + 1); | ||||
|  | ||||
| 	const groupData = await groups.getGroupsData(groupNames); | ||||
| 	const groupData = await groups.getGroupsData(groupNames.map(g => g.name)); | ||||
| 	res.render('admin/manage/groups', { | ||||
| 		groups: groupData, | ||||
| 		pagination: pagination.create(page, pageCount), | ||||
| @@ -32,8 +31,16 @@ groupsController.list = async function (req, res) { | ||||
| }; | ||||
|  | ||||
| groupsController.get = async function (req, res, next) { | ||||
| 	const slug = slugify(req.params.name); | ||||
| 	const groupName = await groups.getGroupNameByGroupSlug(slug); | ||||
| 	const lowercaseSlug = req.params.slug.toLowerCase(); | ||||
| 	if (req.params.slug !== lowercaseSlug) { | ||||
| 		if (res.locals.isAPI) { | ||||
| 			req.params.slug = lowercaseSlug; | ||||
| 		} else { | ||||
| 			return res.redirect(`${nconf.get('relative_path')}/admin/manage/groups/${lowercaseSlug}`); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	const groupName = await groups.getGroupNameByGroupSlug(req.params.slug); | ||||
| 	if (!groupName) { | ||||
| 		return next(); | ||||
| 	} | ||||
| @@ -46,10 +53,11 @@ groupsController.get = async function (req, res, next) { | ||||
| 		return next(); | ||||
| 	} | ||||
|  | ||||
| 	const groupNameData = groupNames.map(name => ({ | ||||
| 		encodedName: encodeURIComponent(name), | ||||
| 		displayName: validator.escape(String(name)), | ||||
| 		selected: name === groupName, | ||||
| 	const groupNameData = groupNames.map(g => ({ | ||||
| 		encodedName: encodeURIComponent(g.name), | ||||
| 		displayName: validator.escape(String(g.name)), | ||||
| 		slug: g.slug, | ||||
| 		selected: g.name === groupName, | ||||
| 	})); | ||||
|  | ||||
| 	res.render('admin/manage/group', { | ||||
| @@ -62,13 +70,14 @@ groupsController.get = async function (req, res, next) { | ||||
| }; | ||||
|  | ||||
| async function getGroupNames() { | ||||
| 	const groupNames = Object.values(await db.getObject('groupslug:groupname')); | ||||
| 	return groupNames.filter(name => ( | ||||
| 		name !== 'registered-users' && | ||||
| 		name !== 'verified-users' && | ||||
| 		name !== 'unverified-users' && | ||||
| 		name !== groups.BANNED_USERS | ||||
| 	)).sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())); | ||||
| 	let groupEntries = Object.entries(await db.getObject('groupslug:groupname')); | ||||
| 	groupEntries = groupEntries.map(g => ({ slug: g[0], name: g[1] })); | ||||
| 	return groupEntries.filter(g => ( | ||||
| 		g.name !== 'registered-users' && | ||||
| 		g.name !== 'verified-users' && | ||||
| 		g.name !== 'unverified-users' && | ||||
| 		g.name !== groups.BANNED_USERS | ||||
| 	)).sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase())); | ||||
| } | ||||
|  | ||||
| groupsController.getCSV = async function (req, res) { | ||||
|   | ||||
| @@ -28,7 +28,7 @@ module.exports = function (app, name, middleware, controllers) { | ||||
| 	helpers.setupAdminPageRoute(app, `/${name}/manage/admins-mods`, middlewares, controllers.admin.adminsMods.get); | ||||
|  | ||||
| 	helpers.setupAdminPageRoute(app, `/${name}/manage/groups`, middlewares, controllers.admin.groups.list); | ||||
| 	helpers.setupAdminPageRoute(app, `/${name}/manage/groups/:name`, middlewares, controllers.admin.groups.get); | ||||
| 	helpers.setupAdminPageRoute(app, `/${name}/manage/groups/:slug`, middlewares, controllers.admin.groups.get); | ||||
|  | ||||
| 	helpers.setupAdminPageRoute(app, `/${name}/manage/uploads`, middlewares, controllers.admin.uploads.get); | ||||
| 	helpers.setupAdminPageRoute(app, `/${name}/manage/digest`, middlewares, controllers.admin.digest.get); | ||||
|   | ||||
| @@ -16,7 +16,7 @@ | ||||
| 					</button> | ||||
| 					<ul class="dropdown-menu {{{ if config.isRTL }}}dropdown-menu-end{{{ end }}} p-1" role="menu"> | ||||
| 						{{{ each templates }}} | ||||
| 						<li><a class="dropdown-item rounded-1 d-flex justify-content-between align-items-center gap-3" href="#" data-template="{./template}" data-toggle="pill" role="menuitem">{./template} <span class="badge text-bg-light border" style="min-width: 2.15em;">{./widgetCount}</span></a></li> | ||||
| 						<li><a class="dropdown-item rounded-1 d-flex justify-content-between align-items-center gap-3" href="#" data-template="{./template}" role="menuitem">{./template} <span class="badge text-bg-light border" style="min-width: 2.15em;">{./widgetCount}</span></a></li> | ||||
| 						{{{ end }}} | ||||
| 					</ul> | ||||
| 				</div> | ||||
|   | ||||
| @@ -20,8 +20,8 @@ | ||||
| 							<a class="dropdown-item rounded-1" role="menuitem">[[search:no-matches]]</a> | ||||
| 						</li> | ||||
| 						{{{ each groupNames }}} | ||||
| 						<li role="presentation" class="group" data-name="{groupNames.displayName}"> | ||||
| 							<a class="dropdown-item rounded-1" href="{config.relative_path}/admin/manage/groups/{groupNames.encodedName}" role="menuitem">{groupNames.displayName}</a> | ||||
| 						<li role="presentation" class="group" data-name="{./displayName}"> | ||||
| 							<a class="dropdown-item rounded-1" href="{config.relative_path}/admin/manage/groups/{./slug}" role="menuitem">{./displayName}</a> | ||||
| 						</li> | ||||
| 						{{{ end }}} | ||||
| 					</ul> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user