diff --git a/server/controllers/article/edit-topic.php b/server/controllers/article/edit-topic.php index 0a0d75ab..4e4adf6b 100755 --- a/server/controllers/article/edit-topic.php +++ b/server/controllers/article/edit-topic.php @@ -57,7 +57,7 @@ class EditTopicController extends Controller { if(Controller::request('icon')) { $topic->icon = Controller::request('icon'); } - if(Controller::request('private') || Controller::request('private') == 0) { + if (Controller::request('private') !== null) { $topic->private = Controller::request('private'); } diff --git a/server/controllers/article/get-all.php b/server/controllers/article/get-all.php index 54aa4214..84bf01e7 100755 --- a/server/controllers/article/get-all.php +++ b/server/controllers/article/get-all.php @@ -35,7 +35,11 @@ class GetAllArticlesController extends Controller { $topicsArray = []; foreach($topics as $topic) { - Controller::isStaffLogged() ? $topicsArray[] = $topic->toArray() : ($topic->private*1 ? null : $topicsArray[] = $topic->toArray()) ; + if (Controller::isStaffLogged()) { + $topicsArray[] = $topic->toArray(); + } else if (!$topic->private) { + $topicsArray[] = $topic->toArray(); + } } Response::respondSuccess($topicsArray); diff --git a/tests/article/article.rb b/tests/article/article.rb index 2b2d3389..c6ad9d08 100644 --- a/tests/article/article.rb +++ b/tests/article/article.rb @@ -6,10 +6,26 @@ describe 'Article path' do icon: 'cogs', iconColor: 'red', csrf_userid: $csrf_userid, - csrf_token: $csrf_token + csrf_token: $csrf_token, + private: 0 }) @topic_id = topic['data']['topicId'] + it 'should create a private topic' do + result = request('/article/add-topic', { + name: 'Private Topic', + icon: 'cogs', + iconColor: 'green', + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + private: 1 + }) + row = $database.getRow('topic', 'Private Topic', 'name') + + result['status'].should.equal('success') + (row['private']).should.equal('1') + end + it 'should create article' do result = request('/article/add', { title: 'Some article', @@ -108,13 +124,39 @@ describe 'Article path' do (result['data'][0]['name']).should.equal('Server management') (result['data'][0]['icon']).should.equal('cogs') (result['data'][0]['iconColor']).should.equal('red') - (result['data'][1]['name']).should.equal('Software installation') - (result['data'][1]['icon']).should.equal('photo') - (result['data'][1]['iconColor']).should.equal('blue') + (result['data'][0]['private']).should.equal('0') + (result['data'][1]['name']).should.equal('Private Topic') + (result['data'][1]['icon']).should.equal('cogs') + (result['data'][1]['iconColor']).should.equal('green') + (result['data'][1]['private']).should.equal('1') + (result['data'][2]['name']).should.equal('Software installation') + (result['data'][2]['icon']).should.equal('photo') + (result['data'][2]['iconColor']).should.equal('blue') + (result['data'][2]['private']).should.equal('0') (result['data'][0]['articles'][0]['title']).should.equal('Some article') (result['data'][0]['articles'][0]['content']).should.equal('This is an article about server management.') (result['data'][0]['articles'][0]['position']).should.equal('1') end + it 'should retrieve public departments' do + request('/user/logout') + Scripts.login('tyrion@opensupports.com', 'tyrionl') + + result = request('/article/get-all', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + (result['status']).should.equal('success') + + (result['data'][0]['name']).should.equal('Server management') + (result['data'][0]['icon']).should.equal('cogs') + (result['data'][0]['iconColor']).should.equal('red') + (result['data'][0]['private']).should.equal('0') + (result['data'][1]['name']).should.equal('Software installation') + (result['data'][1]['icon']).should.equal('photo') + (result['data'][1]['iconColor']).should.equal('blue') + (result['data'][1]['private']).should.equal('0') + + end end