Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
takeit committed Feb 17, 2015
2 parents 07ec564 + f5da99f commit 5ce4bfd
Show file tree
Hide file tree
Showing 20 changed files with 772 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ notifications:
secure: ArA/zjwjNhHWUQauavuyqkHGD6vGoiav1DJrnw2dl6qPDKXe220i/Y0AbbcSh2BazG1cf2B/nkgoWPPCz+xRN7/6tbNV7AkYuN+y0WomBqx/BMaFr6uofgGa0OABZ3XN/Madx9yOE+3q0iJnje41ymJtdpzC23urZ5ma3jxltBs=
before_script:
- sudo apt-get update > /dev/null
- sudo apt-get install -y --force-yes apache2 libapache2-mod-php5 php5-curl php5-mysql php5-intl php5-gd
- sudo apt-get install -y --force-yes apache2 libapache2-mod-php5 php5-curl php5-mysql php5-intl php5-gd postfix
- echo "$(curl -fsSL https://gist.github.com/ahilles107/8255528/raw/fa949a791fe882323a34decd3b0caf130b6d52d6/travis_newscoop.dev)" | sed -e "s,PATH,`pwd`/newscoop,g" | sudo tee /etc/apache2/sites-available/default > /dev/null
- echo "127.0.0.1 newscoop.dev" | sudo tee -a /etc/hosts
- sudo a2enmod rewrite
Expand Down
13 changes: 13 additions & 0 deletions features/3_api_topics.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Feature: Testing Topics API
And field "parent" in the response should be "(topic_id)"
And field "level" in the response should be "1"

Given that I want to delete an previously created subtopic
And I'm logged in as "testuser" with "testpassword" with client "1_svdg45ew371vtsdgd29fgvwe5v" and secret "h48fgsmv0due4nexjsy40jdf3sswwr"
When I request "<<sub_topic>>"
Then the response status code should be 204
And the response is JSON

Scenario: Getting all the topics
Given that I want to check if there are any topics
And I'm logged in as "testuser" with "testpassword" with client "1_svdg45ew371vtsdgd29fgvwe5v" and secret "h48fgsmv0due4nexjsy40jdf3sswwr"
Expand Down Expand Up @@ -91,6 +97,12 @@ Feature: Testing Topics API
And the response should contain field "translations"
And field "level" in the response should be "0"

Given that I want to delete an previously created topic
And I'm logged in as "testuser" with "testpassword" with client "1_svdg45ew371vtsdgd29fgvwe5v" and secret "h48fgsmv0due4nexjsy40jdf3sswwr"
When I request "<<new_topic>>"
Then the response status code should be 204
And the response is JSON

Scenario: Getting all the topics attached to a given article
Given that I want to check if there are topics attached to the article
When I request "/topics/article/1/en"
Expand Down Expand Up @@ -123,3 +135,4 @@ Feature: Testing Topics API
When I submit "topic" data to "/topics"
Then the response status code should be 409
And the response is JSON
Then save new item location as "root_topic"
49 changes: 49 additions & 0 deletions features/6_api_link_unlink_topic.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Feature: Testing linking/unlinkig topics (follow/unfollow topics by users)
I need to be able to follow/unfollow topics by given users

Scenario: Create a new topic and link it to the user, unlink and delete
Given that I want to make a new topic
And that i have fake "topic" data:
| title | <<sentence>> | 4 |

And I'm logged in as "testuser" with "testpassword" with client "1_svdg45ew371vtsdgd29fgvwe5v" and secret "h48fgsmv0due4nexjsy40jdf3sswwr"
When I submit "topic" data to "/topics"
Then the response status code should be 201
And the response is JSON
Then save new item location as "new_topic"

Given that I want to link that previously created topic to the user
And that i have "link" header with "<$$new_topic$$; rel='topic'>" value
When I request "/users/9"
Then the response status code should be 201
And the response is JSON

Given that I want to check if there are any topics by given user
And I'm logged in as "testuser" with "testpassword" with client "1_svdg45ew371vtsdgd29fgvwe5v" and secret "h48fgsmv0due4nexjsy40jdf3sswwr"
When I request "/users/9/topics"
Then the response status code should be 200
And the response is JSON
And the response should contain field "items"
When I request "/users/9"
Then the response status code should be 200
And the response is JSON
And the response should contain field "topics"

Given that I want to unlink that previously created topic from the user
And that i have "unlink" header with "<$$new_topic$$; rel='topic'>" value
When I request "/users/9"
Then the response status code should be 204
And the response is JSON

Given that I want to delete an previously created topic
And I'm logged in as "testuser" with "testpassword" with client "1_svdg45ew371vtsdgd29fgvwe5v" and secret "h48fgsmv0due4nexjsy40jdf3sswwr"
When I request "<<new_topic>>"
Then the response status code should be 204
And the response is JSON

Given that I want to check if topic was successfully unassigned from the user after deletion
And I'm logged in as "testuser" with "testpassword" with client "1_svdg45ew371vtsdgd29fgvwe5v" and secret "h48fgsmv0due4nexjsy40jdf3sswwr"
When I request "/users/9"
Then the response status code should be 200
And the response is JSON
And in the response there is no field called "topics"
7 changes: 3 additions & 4 deletions newscoop/install/Resources/sql/campsite_core.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2085,9 +2085,8 @@ CREATE TABLE `user_topic` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`user_id` int(11) unsigned NOT NULL,
`topic_id` int(11) unsigned NOT NULL,
`topic_language` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `user_topic` (`user_id`,`topic_id`,`topic_language`)
UNIQUE KEY `user_topic` (`user_id`,`topic_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

Expand Down Expand Up @@ -3425,11 +3424,11 @@ CREATE TABLE IF NOT EXISTS `editorial_comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fk_article_number` int(11) NOT NULL,
`fk_language_id` int(11) NOT NULL,
`comment` text NOT NULL,
`comment` text COLLATE utf8_unicode_ci NOT NULL,
`resolved` int(1) NOT NULL DEFAULT '0',
`fk_parent_id` int(11) DEFAULT NULL,
`user_id` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`is_active` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
7 changes: 3 additions & 4 deletions newscoop/install/Resources/sql/campsite_demo_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2717,9 +2717,8 @@ CREATE TABLE `user_topic` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`user_id` int(11) unsigned NOT NULL,
`topic_id` int(11) unsigned NOT NULL,
`topic_language` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `user_topic` (`user_id`,`topic_id`,`topic_language`)
UNIQUE KEY `user_topic` (`user_id`,`topic_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

Expand Down Expand Up @@ -2766,14 +2765,14 @@ CREATE TABLE IF NOT EXISTS `editorial_comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fk_article_number` int(11) NOT NULL,
`fk_language_id` int(11) NOT NULL,
`comment` text NOT NULL,
`comment` text COLLATE utf8_unicode_ci NOT NULL,
`resolved` int(1) NOT NULL DEFAULT '0',
`fk_parent_id` int(11) DEFAULT NULL,
`user_id` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`is_active` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `editorial_comments` CHANGE `comment` `comment` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE `user_topic` DROP `topic_language`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @copyright 2011 Sourcefabric o.p.s.
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*/

namespace Newscoop\Entity\Repository;

use Doctrine\ORM\EntityRepository;
Expand Down Expand Up @@ -37,7 +36,7 @@ public function findByUser($user, $locale = null)
->leftJoin('ut.topic', 't')
->where('u.id = :user_id')
->setParameters(array(
'user_id' => $userId
'user_id' => $userId,
));

$query = $em->getRepository("Newscoop\NewscoopBundle\Entity\Topic")->setTranslatableHint($qb->getQuery(), $locale);
Expand All @@ -55,7 +54,10 @@ public function findByUser($user, $locale = null)
*/
public function findByTopicAndUser(User $user, Topic $topic)
{
$qb = $this->getEntityManager()
$em = $this->getEntityManager();
$locale = $em->getRepository("Newscoop\NewscoopBundle\Entity\Topic")->getTranslatableTopicLocale($topic);

$qb = $em
->createQueryBuilder()
->select(array('ut'))
->from('Newscoop\Entity\UserTopic', 'ut')
Expand All @@ -68,9 +70,27 @@ public function findByTopicAndUser(User $user, Topic $topic)
->setParameters(array(
'user_id' => $user->getId(),
'topic_id' => $topic->getId(),
'topic_language_id' => $topic->getTranslatableLocale(),
'topic_language_id' => $locale,
));

return $qb->getQuery()->getResult();
}

/**
* Gets the occurence of the user's topic
*
* @param string|int $topicId Topic id
*
* @return Doctrine\ORM\Query
*/
public function getTheOccurrenceOfTheUserTopic($topicId)
{
$query = $this->createQueryBuilder('t')
->select('count(t)')
->where('t.topic = :topicId')
->setParameter('topicId', $topicId)
->getQuery();

return $query;
}
}
50 changes: 38 additions & 12 deletions newscoop/library/Newscoop/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @copyright 2011 Sourcefabric o.p.s.
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*/

namespace Newscoop\Entity;

use Doctrine\ORM\Mapping as ORM;
Expand Down Expand Up @@ -236,6 +235,20 @@ class User implements \Zend_Acl_Role_Interface, UserInterface, AdvancedUserInter
*/
protected $clients;

/**
* @ORM\ManyToMany(targetEntity="Newscoop\NewscoopBundle\Entity\Topic")
* @ORM\JoinTable(name="user_topic",
* joinColumns={
* @ORM\JoinColumn(name="user_id", referencedColumnName="Id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="topic_id", referencedColumnName="id")
* }
* )
* @var Doctrine\Common\Collections\ArrayCollection
*/
protected $topics;

/**
* @param string $email
*/
Expand Down Expand Up @@ -301,7 +314,7 @@ public function setPassword($password)
$this->password = implode(self::HASH_SEP, array(
self::HASH_ALGO,
$salt,
hash(self::HASH_ALGO, $salt . $password),
hash(self::HASH_ALGO, $salt.$password),
));

return $this;
Expand All @@ -319,15 +332,15 @@ public function checkPassword($password)
if ($this->password == sha1($password)) { // update old password on success
$this->setPassword($password);

return TRUE;
return true;
}

return FALSE;
return false;
}

list($algo, $salt, $password_hash) = explode(self::HASH_SEP, $this->password);

return $password_hash === hash($algo, $salt . $password);
return $password_hash === hash($algo, $salt.$password);
}

/**
Expand Down Expand Up @@ -765,7 +778,7 @@ public function getAttribute($name)
return $this->attributes[$name]->getValue();
}

return null;
return;
}

/**
Expand Down Expand Up @@ -865,16 +878,16 @@ public function hasPermission($permission, $resource = null, $action = null)

return true;
} else {
return FALSE;
return false;
}
} catch (\Exception $e) {
return FALSE;
return false;
}
}

public function getCommenters()
{
return $this->commenters;
return $this->commenters;
}

/**
Expand All @@ -887,7 +900,6 @@ public function getComments()
$comments = array();

foreach ($this->commenters as $commenter) {

foreach ($commenter->getComments() as $comment) {
$comments[] = $comment;
}
Expand Down Expand Up @@ -1172,7 +1184,7 @@ public function getDataTableView(Zend_View_Abstract $view)
's' => $status,
'c' => $this->created->format('Y-m-d h:i:s'),
'up' => $this->updated->format('Y-m-d h:i:s'),
've' => ((bool) !$this->isPending() ? 'Yes' : 'No')
've' => ((bool) !$this->isPending() ? 'Yes' : 'No'),
);
}

Expand Down Expand Up @@ -1250,7 +1262,7 @@ public function serialize()
{
return serialize(array(
$this->id,
$this->status
$this->status,
));
}

Expand Down Expand Up @@ -1545,4 +1557,18 @@ public function getObject()
{
return clone $this;
}

/**
* Gets user's topics
*
* @return Doctrine\Common\Collections\ArrayCollection|null
*/
public function getTopics()
{
if ($this->topics->count() > 0) {
return $this->topics;
}

return;
}
}
21 changes: 20 additions & 1 deletion newscoop/library/Newscoop/Entity/UserTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @copyright 2011 Sourcefabric o.p.s.
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*/

namespace Newscoop\Entity;

use Doctrine\ORM\Mapping as ORM;
Expand Down Expand Up @@ -68,4 +67,24 @@ public function getTopicId()
{
return $this->topic->getId();
}

/**
* Gets the value of user.
*
* @return User
*/
public function getUser()
{
return $this->user;
}

/**
* Gets the value of id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
}
4 changes: 1 addition & 3 deletions newscoop/library/Newscoop/Services/EmailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @copyright 2014 Sourcefabric o.p.s.
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*/

namespace Newscoop\Services;

use Newscoop\Entity\User;
Expand Down Expand Up @@ -91,11 +90,10 @@ public function send($placeholder, $message, $to, $from = null, $attachmentDir =
$publicationService = $this->container->get('newscoop_newscoop.publication_service');
$mailer = $this->container->get('mailer');
if (empty($from)) {
$from = 'no-reply@' . $publicationService->getPublicationAlias()->getName();
$from = 'no-reply@'.$publicationService->getPublicationAlias()->getName();
}

try {

$messageToSend = \Swift_Message::newInstance();

if (is_array($to)) {
Expand Down
Loading

0 comments on commit 5ce4bfd

Please sign in to comment.