mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-30 18:46:01 +01:00 
			
		
		
		
	fix: #7567, allow invite and approval at the same time
This commit is contained in:
		| @@ -27,6 +27,7 @@ | |||||||
|     "maximumTagLength": 15, |     "maximumTagLength": 15, | ||||||
|     "allowTopicsThumbnail": 0, |     "allowTopicsThumbnail": 0, | ||||||
|     "registrationType": "normal", |     "registrationType": "normal", | ||||||
|  |     "registrationApprovalType": "normal", | ||||||
|     "allowAccountDelete": 1, |     "allowAccountDelete": 1, | ||||||
|     "allowFileUploads": 0, |     "allowFileUploads": 0, | ||||||
|     "allowedFileExtensions": "png,jpg,bmp", |     "allowedFileExtensions": "png,jpg,bmp", | ||||||
|   | |||||||
| @@ -34,13 +34,15 @@ | |||||||
| 	"online-cutoff-help": "If user performs no actions for this duration, they are considered inactive and they do not receive realtime updates.", | 	"online-cutoff-help": "If user performs no actions for this duration, they are considered inactive and they do not receive realtime updates.", | ||||||
| 	"registration": "User Registration", | 	"registration": "User Registration", | ||||||
| 	"registration-type": "Registration Type", | 	"registration-type": "Registration Type", | ||||||
|  | 	"registration-approval-type": "Registration Approval Type", | ||||||
| 	"registration-type.normal": "Normal", | 	"registration-type.normal": "Normal", | ||||||
| 	"registration-type.admin-approval": "Admin Approval", | 	"registration-type.admin-approval": "Admin Approval", | ||||||
| 	"registration-type.admin-approval-ip": "Admin Approval for IPs", | 	"registration-type.admin-approval-ip": "Admin Approval for IPs", | ||||||
| 	"registration-type.invite-only": "Invite Only", | 	"registration-type.invite-only": "Invite Only", | ||||||
| 	"registration-type.admin-invite-only": "Admin Invite Only", | 	"registration-type.admin-invite-only": "Admin Invite Only", | ||||||
| 	"registration-type.disabled": "No registration", | 	"registration-type.disabled": "No registration", | ||||||
| 	"registration-type.help": "Normal - Users can register from the /register page.<br/>\nAdmin Approval - User registrations are placed in an <a href=\"%1/admin/manage/registration\">approval queue</a> for administrators.<br/>\nAdmin Approval for IPs - Normal for new users, Admin Approval for IP addresses that already have an account.<br/>\nInvite Only - Users can invite others from the <a href=\"%1/users\" target=\"_blank\">users</a> page.<br/>\nAdmin Invite Only - Only administrators can invite others from <a href=\"%1/users\" target=\"_blank\">users</a> and <a href=\"%1/admin/manage/users\">admin/manage/users</a> pages.<br/>\nNo registration - No user registration.<br/>", | 	"registration-type.help": "Normal - Users can register from the /register page.<br/>\nInvite Only - Users can invite others from the <a href=\"%1/users\" target=\"_blank\">users</a> page.<br/>\nAdmin Invite Only - Only administrators can invite others from <a href=\"%1/users\" target=\"_blank\">users</a> and <a href=\"%1/admin/manage/users\">admin/manage/users</a> pages.<br/>\nNo registration - No user registration.<br/>", | ||||||
|  | 	"registration-approval-type.help": "Normal - Users are registered immediately.<br/>\nAdmin Approval - User registrations are placed in an <a href=\"%1/admin/manage/registration\">approval queue</a> for administrators.<br/>\nAdmin Approval for IPs - Normal for new users, Admin Approval for IP addresses that already have an account.<br/>", | ||||||
| 	"registration.max-invites": "Maximum Invitations per User", | 	"registration.max-invites": "Maximum Invitations per User", | ||||||
| 	"max-invites": "Maximum Invitations per User", | 	"max-invites": "Maximum Invitations per User", | ||||||
| 	"max-invites-help": "0 for no restriction. Admins get infinite invitations<br>Only applicable for \"Invite Only\"", | 	"max-invites-help": "0 for no restriction. Admins get infinite invitations<br>Only applicable for \"Invite Only\"", | ||||||
|   | |||||||
| @@ -100,7 +100,6 @@ Controllers.login = function (req, res, next) { | |||||||
| 	var data = {}; | 	var data = {}; | ||||||
| 	var loginStrategies = require('../routes/authentication').getLoginStrategies(); | 	var loginStrategies = require('../routes/authentication').getLoginStrategies(); | ||||||
| 	var registrationType = meta.config.registrationType || 'normal'; | 	var registrationType = meta.config.registrationType || 'normal'; | ||||||
|  |  | ||||||
| 	var allowLoginWith = (meta.config.allowLoginWith || 'username-email'); | 	var allowLoginWith = (meta.config.allowLoginWith || 'username-email'); | ||||||
| 	var returnTo = (req.headers['x-return-to'] || '').replace(nconf.get('base_url') + nconf.get('relative_path'), ''); | 	var returnTo = (req.headers['x-return-to'] || '').replace(nconf.get('base_url') + nconf.get('relative_path'), ''); | ||||||
|  |  | ||||||
| @@ -117,7 +116,7 @@ Controllers.login = function (req, res, next) { | |||||||
|  |  | ||||||
| 	data.alternate_logins = loginStrategies.length > 0; | 	data.alternate_logins = loginStrategies.length > 0; | ||||||
| 	data.authentication = loginStrategies; | 	data.authentication = loginStrategies; | ||||||
| 	data.allowRegistration = registrationType === 'normal' || registrationType === 'admin-approval' || registrationType === 'admin-approval-ip'; | 	data.allowRegistration = registrationType === 'normal'; | ||||||
| 	data.allowLoginWith = '[[login:' + allowLoginWith + ']]'; | 	data.allowLoginWith = '[[login:' + allowLoginWith + ']]'; | ||||||
| 	data.breadcrumbs = helpers.buildBreadcrumbs([{ | 	data.breadcrumbs = helpers.buildBreadcrumbs([{ | ||||||
| 		text: '[[global:login]]', | 		text: '[[global:login]]', | ||||||
| @@ -159,7 +158,7 @@ Controllers.register = function (req, res, next) { | |||||||
| 	var registrationType = meta.config.registrationType || 'normal'; | 	var registrationType = meta.config.registrationType || 'normal'; | ||||||
|  |  | ||||||
| 	if (registrationType === 'disabled') { | 	if (registrationType === 'disabled') { | ||||||
| 		return next(); | 		return setImmediate(next); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var errorText; | 	var errorText; | ||||||
|   | |||||||
| @@ -63,7 +63,7 @@ module.exports = function (middleware) { | |||||||
| 			'brand:logo:url': meta.config['brand:logo:url'] || '', | 			'brand:logo:url': meta.config['brand:logo:url'] || '', | ||||||
| 			'brand:logo:alt': meta.config['brand:logo:alt'] || '', | 			'brand:logo:alt': meta.config['brand:logo:alt'] || '', | ||||||
| 			'brand:logo:display': meta.config['brand:logo'] ? '' : 'hide', | 			'brand:logo:display': meta.config['brand:logo'] ? '' : 'hide', | ||||||
| 			allowRegistration: registrationType === 'normal' || registrationType === 'admin-approval' || registrationType === 'admin-approval-ip', | 			allowRegistration: registrationType === 'normal', | ||||||
| 			searchEnabled: plugins.hasListeners('filter:search.query'), | 			searchEnabled: plugins.hasListeners('filter:search.query'), | ||||||
| 			config: res.locals.config, | 			config: res.locals.config, | ||||||
| 			relative_path: nconf.get('relative_path'), | 			relative_path: nconf.get('relative_path'), | ||||||
|   | |||||||
							
								
								
									
										20
									
								
								src/upgrades/1.12.3/update_registration_type.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/upgrades/1.12.3/update_registration_type.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | 'use strict'; | ||||||
|  |  | ||||||
|  | var db = require('../../database'); | ||||||
|  |  | ||||||
|  | module.exports = { | ||||||
|  | 	name: 'Update registration type', | ||||||
|  | 	timestamp: Date.UTC(2019, 5, 4), | ||||||
|  | 	method: function (callback) { | ||||||
|  | 		const meta = require('../../meta'); | ||||||
|  | 		const registrationType = meta.config.registrationType || 'normal'; | ||||||
|  | 		if (registrationType === 'admin-approval' || registrationType === 'admin-approval-ip') { | ||||||
|  | 			db.setObject('config', { | ||||||
|  | 				registrationType: 'normal', | ||||||
|  | 				registrationApprovalType: registrationType, | ||||||
|  | 			}, callback); | ||||||
|  | 		} else { | ||||||
|  | 			setImmediate(callback); | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
|  | }; | ||||||
| @@ -163,15 +163,15 @@ module.exports = function (User) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	User.shouldQueueUser = function (ip, callback) { | 	User.shouldQueueUser = function (ip, callback) { | ||||||
| 		var registrationType = meta.config.registrationType || 'normal'; | 		const registrationApprovalType = meta.config.registrationApprovalType; | ||||||
| 		if (registrationType === 'normal' || registrationType === 'invite-only' || registrationType === 'admin-invite-only') { | 		if (registrationApprovalType === 'admin-approval') { | ||||||
| 			setImmediate(callback, null, false); |  | ||||||
| 		} else if (registrationType === 'admin-approval') { |  | ||||||
| 			setImmediate(callback, null, true); | 			setImmediate(callback, null, true); | ||||||
| 		} else if (registrationType === 'admin-approval-ip') { | 		} else if (registrationApprovalType === 'admin-approval-ip') { | ||||||
| 			db.sortedSetCard('ip:' + ip + ':uid', function (err, count) { | 			db.sortedSetCard('ip:' + ip + ':uid', function (err, count) { | ||||||
| 				callback(err, !!count); | 				callback(err, !!count); | ||||||
| 			}); | 			}); | ||||||
|  | 		} else { | ||||||
|  | 			setImmediate(callback, null, false); | ||||||
| 		} | 		} | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -167,8 +167,6 @@ | |||||||
| 				<label>[[admin/settings/user:registration-type]]</label> | 				<label>[[admin/settings/user:registration-type]]</label> | ||||||
| 				<select class="form-control" data-field="registrationType"> | 				<select class="form-control" data-field="registrationType"> | ||||||
| 					<option value="normal">[[admin/settings/user:registration-type.normal]]</option> | 					<option value="normal">[[admin/settings/user:registration-type.normal]]</option> | ||||||
| 					<option value="admin-approval">[[admin/settings/user:registration-type.admin-approval]]</option> |  | ||||||
| 					<option value="admin-approval-ip">[[admin/settings/user:registration-type.admin-approval-ip]]</option> |  | ||||||
| 					<option value="invite-only">[[admin/settings/user:registration-type.invite-only]]</option> | 					<option value="invite-only">[[admin/settings/user:registration-type.invite-only]]</option> | ||||||
| 					<option value="admin-invite-only">[[admin/settings/user:registration-type.admin-invite-only]]</option> | 					<option value="admin-invite-only">[[admin/settings/user:registration-type.admin-invite-only]]</option> | ||||||
| 					<option value="disabled">[[admin/settings/user:registration-type.disabled]]</option> | 					<option value="disabled">[[admin/settings/user:registration-type.disabled]]</option> | ||||||
| @@ -177,6 +175,17 @@ | |||||||
| 					[[admin/settings/user:registration-type.help, {config.relative_path}]] | 					[[admin/settings/user:registration-type.help, {config.relative_path}]] | ||||||
| 				</p> | 				</p> | ||||||
| 			</div> | 			</div> | ||||||
|  | 			<div class="form-group"> | ||||||
|  | 				<label>[[admin/settings/user:registration-approval-type]]</label> | ||||||
|  | 				<select class="form-control" data-field="registrationApprovalType"> | ||||||
|  | 					<option value="normal">[[admin/settings/user:registration-type.normal]]</option> | ||||||
|  | 					<option value="admin-approval">[[admin/settings/user:registration-type.admin-approval]]</option> | ||||||
|  | 					<option value="admin-approval-ip">[[admin/settings/user:registration-type.admin-approval-ip]]</option> | ||||||
|  | 				</select> | ||||||
|  | 				<p class="help-block"> | ||||||
|  | 					[[admin/settings/user:registration-approval-type.help, {config.relative_path}]] | ||||||
|  | 				</p> | ||||||
|  | 			</div> | ||||||
| 			<div class="form-group"> | 			<div class="form-group"> | ||||||
| 				<label>[[admin/settings/user:max-invites]]</label> | 				<label>[[admin/settings/user:max-invites]]</label> | ||||||
| 				<input type="number" class="form-control" data-field="maximumInvites" placeholder="0"> | 				<input type="number" class="form-control" data-field="maximumInvites" placeholder="0"> | ||||||
|   | |||||||
| @@ -396,9 +396,9 @@ describe('authentication', function () { | |||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
| 	it('should queue user if ip is used before', function (done) { | 	it('should queue user if ip is used before', function (done) { | ||||||
| 		meta.config.registrationType = 'admin-approval-ip'; | 		meta.config.registrationApprovalType = 'admin-approval-ip'; | ||||||
| 		registerUser('another@user.com', 'anotheruser', 'anotherpwd', function (err, response, body) { | 		registerUser('another@user.com', 'anotheruser', 'anotherpwd', function (err, response, body) { | ||||||
| 			meta.config.registrationType = 'normal'; | 			meta.config.registrationApprovalType = 'normal'; | ||||||
| 			assert.ifError(err); | 			assert.ifError(err); | ||||||
| 			assert.equal(response.statusCode, 200); | 			assert.equal(response.statusCode, 200); | ||||||
| 			assert.equal(body.message, '[[register:registration-added-to-queue]]'); | 			assert.equal(body.message, '[[register:registration-added-to-queue]]'); | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								test/user.js
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								test/user.js
									
									
									
									
									
								
							| @@ -1588,13 +1588,11 @@ describe('User', function () { | |||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
| 	describe('approval queue', function () { | 	describe('approval queue', function () { | ||||||
| 		var socketAdmin = require('../src/socket.io/admin'); | 		var oldRegistrationApprovalType; | ||||||
|  |  | ||||||
| 		var oldRegistrationType; |  | ||||||
| 		var adminUid; | 		var adminUid; | ||||||
| 		before(function (done) { | 		before(function (done) { | ||||||
| 			oldRegistrationType = meta.config.registrationType; | 			oldRegistrationApprovalType = meta.config.registrationApprovalType; | ||||||
| 			meta.config.registrationType = 'admin-approval'; | 			meta.config.registrationApprovalType = 'admin-approval'; | ||||||
| 			User.create({ username: 'admin', password: '123456' }, function (err, uid) { | 			User.create({ username: 'admin', password: '123456' }, function (err, uid) { | ||||||
| 				assert.ifError(err); | 				assert.ifError(err); | ||||||
| 				adminUid = uid; | 				adminUid = uid; | ||||||
| @@ -1603,7 +1601,7 @@ describe('User', function () { | |||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		after(function (done) { | 		after(function (done) { | ||||||
| 			meta.config.registrationType = oldRegistrationType; | 			meta.config.registrationApprovalType = oldRegistrationApprovalType; | ||||||
| 			done(); | 			done(); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user