From 7d949c07199f0fe09479dc404e2cc763881fd2a3 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Thu, 15 Nov 2018 23:52:46 -0300 Subject: [PATCH 1/3] minor changes feature #331 --- server/controllers/article/edit-topic.php | 2 +- server/controllers/article/get-all.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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); From 79569fcfdeb73ddf3ab5b8d98e4c1bf87c642446 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Fri, 23 Nov 2018 20:43:06 -0300 Subject: [PATCH 2/3] tests --- tests/article/article.rb | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/article/article.rb b/tests/article/article.rb index 2b2d3389..7ab3dc16 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,9 +124,15 @@ 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.') From f9e74d87588ce61b8b6efc868fa793f7e0fcf1d3 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Sat, 24 Nov 2018 23:04:12 -0300 Subject: [PATCH 3/3] test --- tests/article/article.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/article/article.rb b/tests/article/article.rb index 7ab3dc16..c6ad9d08 100644 --- a/tests/article/article.rb +++ b/tests/article/article.rb @@ -139,4 +139,24 @@ describe 'Article path' do (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