mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-08-31 05:16:45 +02:00
Merge remote-tracking branch 'refs/remotes/origin/master' into develop
This commit is contained in:
@@ -648,6 +648,7 @@ describe('Categories', function () {
|
||||
'topics:reply': false,
|
||||
'topics:read': false,
|
||||
'topics:create': false,
|
||||
'topics:tag': false,
|
||||
'topics:delete': false,
|
||||
'posts:edit': false,
|
||||
'upload:post:file': false,
|
||||
@@ -669,6 +670,7 @@ describe('Categories', function () {
|
||||
'groups:topics:delete': false,
|
||||
'groups:topics:create': true,
|
||||
'groups:topics:reply': true,
|
||||
'groups:topics:tag': true,
|
||||
'groups:posts:delete': true,
|
||||
'groups:read': true,
|
||||
'groups:topics:read': true,
|
||||
|
||||
@@ -7,7 +7,9 @@ var nconf = require('nconf');
|
||||
|
||||
var db = require('./mocks/databasemock');
|
||||
var topics = require('../src/topics');
|
||||
var posts = require('../src/posts');
|
||||
var categories = require('../src/categories');
|
||||
var privileges = require('../src/privileges');
|
||||
var meta = require('../src/meta');
|
||||
var User = require('../src/user');
|
||||
var groups = require('../src/groups');
|
||||
@@ -825,7 +827,7 @@ describe('Topic\'s', function () {
|
||||
});
|
||||
|
||||
it('should 404 if tid is not a number', function (done) {
|
||||
request(nconf.get('url') + '/api/topic/teaser/nan', { json: true }, function (err, response, body) {
|
||||
request(nconf.get('url') + '/api/topic/teaser/nan', { json: true }, function (err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.statusCode, 404);
|
||||
done();
|
||||
@@ -858,7 +860,7 @@ describe('Topic\'s', function () {
|
||||
|
||||
|
||||
it('should 404 if tid is not a number', function (done) {
|
||||
request(nconf.get('url') + '/api/topic/pagination/nan', { json: true }, function (err, response, body) {
|
||||
request(nconf.get('url') + '/api/topic/pagination/nan', { json: true }, function (err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.statusCode, 404);
|
||||
done();
|
||||
@@ -866,7 +868,7 @@ describe('Topic\'s', function () {
|
||||
});
|
||||
|
||||
it('should 404 if tid does not exist', function (done) {
|
||||
request(nconf.get('url') + '/api/topic/pagination/1231231', { json: true }, function (err, response, body) {
|
||||
request(nconf.get('url') + '/api/topic/pagination/1231231', { json: true }, function (err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.statusCode, 404);
|
||||
done();
|
||||
@@ -1643,4 +1645,63 @@ describe('Topic\'s', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('tag privilege', function () {
|
||||
var uid;
|
||||
var cid;
|
||||
before(function (done) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
User.create({ username: 'tag_poster' }, next);
|
||||
},
|
||||
function (_uid, next) {
|
||||
uid = _uid;
|
||||
categories.create({ name: 'tag category' }, next);
|
||||
},
|
||||
function (categoryObj, next) {
|
||||
cid = categoryObj.cid;
|
||||
next();
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should fail to post if user does not have tag privilege', function (done) {
|
||||
privileges.categories.rescind(['topics:tag'], cid, 'registered-users', function (err) {
|
||||
assert.ifError(err);
|
||||
topics.post({ uid: uid, cid: cid, tags: ['tag1'], title: 'topic with tags', content: 'some content here' }, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to edit if user does not have tag privilege', function (done) {
|
||||
topics.post({ uid: uid, cid: cid, title: 'topic with tags', content: 'some content here' }, function (err, result) {
|
||||
assert.ifError(err);
|
||||
var pid = result.postData.pid;
|
||||
posts.edit({ pid: pid, uid: uid, content: 'edited content', tags: ['tag2'] }, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to edit topic and add tags if allowed', function (done) {
|
||||
privileges.categories.give(['topics:tag'], cid, 'registered-users', function (err) {
|
||||
assert.ifError(err);
|
||||
topics.post({ uid: uid, cid: cid, tags: ['tag1'], title: 'topic with tags', content: 'some content here' }, function (err, result) {
|
||||
assert.ifError(err);
|
||||
posts.edit({ pid: result.postData.pid, uid: uid, content: 'edited content', tags: ['tag1', 'tag2'] }, function (err, result) {
|
||||
assert.ifError(err);
|
||||
var tags = result.topic.tags.map(function (tag) {
|
||||
return tag.value;
|
||||
});
|
||||
assert(tags.indexOf('tag1') !== -1);
|
||||
assert(tags.indexOf('tag2') !== -1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user