Added option to mark a list as not being allowed to be subscribed by public users using the form.
The settings is a checkbox in list create/edit.
This commit is contained in:
		
							parent
							
								
									80cf2c8888
								
							
						
					
					
						commit
						c74232e9c5
					
				
					 7 changed files with 60 additions and 12 deletions
				
			
		| 
						 | 
				
			
			@ -6,7 +6,7 @@ let shortid = require('shortid');
 | 
			
		|||
let segments = require('./segments');
 | 
			
		||||
let _ = require('../translate')._;
 | 
			
		||||
 | 
			
		||||
let allowedKeys = ['description', 'default_form'];
 | 
			
		||||
let allowedKeys = ['description', 'default_form', 'public_subscribe'];
 | 
			
		||||
 | 
			
		||||
module.exports.list = (start, limit, callback) => {
 | 
			
		||||
    db.getConnection((err, connection) => {
 | 
			
		||||
| 
						 | 
				
			
			@ -111,6 +111,8 @@ module.exports.get = (id, callback) => {
 | 
			
		|||
module.exports.create = (list, callback) => {
 | 
			
		||||
 | 
			
		||||
    let data = tools.convertKeys(list);
 | 
			
		||||
    data.publicSubscribe = data.publicSubscribe ? 1 : 0;
 | 
			
		||||
 | 
			
		||||
    let name = (data.name || '').toString().trim();
 | 
			
		||||
 | 
			
		||||
    if (!data) {
 | 
			
		||||
| 
						 | 
				
			
			@ -120,8 +122,8 @@ module.exports.create = (list, callback) => {
 | 
			
		|||
    let keys = ['name'];
 | 
			
		||||
    let values = [name];
 | 
			
		||||
 | 
			
		||||
    Object.keys(list).forEach(key => {
 | 
			
		||||
        let value = list[key].trim();
 | 
			
		||||
    Object.keys(data).forEach(key => {
 | 
			
		||||
        let value = data[key].toString().trim();
 | 
			
		||||
        key = tools.toDbKey(key);
 | 
			
		||||
        if (key === 'description') {
 | 
			
		||||
            value = tools.purifyHTML(value);
 | 
			
		||||
| 
						 | 
				
			
			@ -169,6 +171,7 @@ module.exports.update = (id, updates, callback) => {
 | 
			
		|||
    id = Number(id) || 0;
 | 
			
		||||
 | 
			
		||||
    let data = tools.convertKeys(updates);
 | 
			
		||||
    data.publicSubscribe = data.publicSubscribe ? 1 : 0;
 | 
			
		||||
 | 
			
		||||
    let name = (data.name || '').toString().trim();
 | 
			
		||||
    let keys = ['name'];
 | 
			
		||||
| 
						 | 
				
			
			@ -182,8 +185,8 @@ module.exports.update = (id, updates, callback) => {
 | 
			
		|||
        return callback(new Error(_('List Name must be set')));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Object.keys(updates).forEach(key => {
 | 
			
		||||
        let value = updates[key].trim();
 | 
			
		||||
    Object.keys(data).forEach(key => {
 | 
			
		||||
        let value = data[key].toString().trim();
 | 
			
		||||
        key = tools.toDbKey(key);
 | 
			
		||||
        if (key === 'description') {
 | 
			
		||||
            value = tools.purifyHTML(value);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,3 @@
 | 
			
		|||
{
 | 
			
		||||
    "schemaVersion": 25
 | 
			
		||||
    "schemaVersion": 26
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,6 +82,10 @@ router.get('/create', passport.csrfProtection, (req, res) => {
 | 
			
		|||
 | 
			
		||||
    data.csrfToken = req.csrfToken();
 | 
			
		||||
 | 
			
		||||
    if (!('publicSubscribe' in data)) {
 | 
			
		||||
        data.publicSubscribe = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    res.render('lists/create', data);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -176,9 +176,14 @@ router.get('/subscribe/:cid', (req, res, next) => {
 | 
			
		|||
 | 
			
		||||
router.get('/:cid', passport.csrfProtection, (req, res, next) => {
 | 
			
		||||
    lists.getByCid(req.params.cid, (err, list) => {
 | 
			
		||||
        if (!err && !list) {
 | 
			
		||||
            err = new Error(_('Selected list not found'));
 | 
			
		||||
            err.status = 404;
 | 
			
		||||
        if (!err) {
 | 
			
		||||
            if (!list) {
 | 
			
		||||
                err = new Error(_('Selected list not found'));
 | 
			
		||||
                err.status = 404;
 | 
			
		||||
            } else if (!list.publicSubscribe) {
 | 
			
		||||
                err = new Error(_('The list does not allow public subscriptions.'));
 | 
			
		||||
                err.status = 403;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (err) {
 | 
			
		||||
| 
						 | 
				
			
			@ -501,9 +506,14 @@ router.post('/:cid/subscribe', passport.parseForm, corsOrCsrfProtection, (req, r
 | 
			
		|||
    let testsPass = subTimeTest && addressTest;
 | 
			
		||||
 | 
			
		||||
    lists.getByCid(req.params.cid, (err, list) => {
 | 
			
		||||
        if (!err && !list) {
 | 
			
		||||
            err = new Error(_('Selected list not found'));
 | 
			
		||||
            err.status = 404;
 | 
			
		||||
        if (!err) {
 | 
			
		||||
            if (!list) {
 | 
			
		||||
                err = new Error(_('Selected list not found'));
 | 
			
		||||
                err.status = 404;
 | 
			
		||||
            } else if (!list.publicSubscribe) {
 | 
			
		||||
                err = new Error(_('The list does not allow public subscriptions.'));
 | 
			
		||||
                err.status = 403;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (err) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										11
									
								
								setup/sql/upgrade-00026.sql
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								setup/sql/upgrade-00026.sql
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
# Header section
 | 
			
		||||
# Define incrementing schema version number
 | 
			
		||||
SET @schema_version = '26';
 | 
			
		||||
 | 
			
		||||
# Add field
 | 
			
		||||
ALTER TABLE `lists` ADD COLUMN `public_subscribe` tinyint(1) unsigned DEFAULT 1 NOT NULL AFTER `created`;
 | 
			
		||||
 | 
			
		||||
# Footer section
 | 
			
		||||
LOCK TABLES `settings` WRITE;
 | 
			
		||||
INSERT INTO `settings` (`key`, `value`) VALUES('db_schema_version', @schema_version) ON DUPLICATE KEY UPDATE `value`=@schema_version;
 | 
			
		||||
UNLOCK TABLES;
 | 
			
		||||
| 
						 | 
				
			
			@ -26,6 +26,16 @@
 | 
			
		|||
 | 
			
		||||
    <hr />
 | 
			
		||||
 | 
			
		||||
    <div class="col-sm-offset-2">
 | 
			
		||||
        <div class="checkbox">
 | 
			
		||||
            <label>
 | 
			
		||||
                <input type="checkbox" name="public_subscribe" value="1" {{#if publicSubscribe}} checked {{/if}}> {{#translate}}Allow public users to subscribe themselves{{/translate}}
 | 
			
		||||
            </label>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <hr />
 | 
			
		||||
 | 
			
		||||
    <div class="form-group">
 | 
			
		||||
        <div class="col-sm-offset-2 col-sm-10">
 | 
			
		||||
            <button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-plus"></i> {{#translate}}Create List{{/translate}}</button>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -56,6 +56,16 @@
 | 
			
		|||
 | 
			
		||||
    <hr />
 | 
			
		||||
 | 
			
		||||
    <div class="col-sm-offset-2">
 | 
			
		||||
        <div class="checkbox">
 | 
			
		||||
            <label>
 | 
			
		||||
                <input type="checkbox" name="public_subscribe" value="1" {{#if publicSubscribe}} checked {{/if}}> {{#translate}}Allow public users to subscribe themselves{{/translate}}
 | 
			
		||||
            </label>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <hr />
 | 
			
		||||
 | 
			
		||||
    <div class="form-group">
 | 
			
		||||
        <div class="col-sm-offset-2 col-sm-10">
 | 
			
		||||
            <div class="pull-right">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue