Skip to content

Added technograph's blog #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Resources/translations/messages.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ role:

ROLE_ARGENTIQUE_ADMIN: Voir la documentation pour ajouter des photos au site
ROLE_ARGENTIQUE_READ: Voir les photos du site
ROLE_NEWS_ADMIN: Peut modérer les news
ROLE_NEWS_EDIT: Peut modifier les news d'une asso s'il est autorisé
ROLE_NEWS_READ: Peut lire les news d'une asso

ROLE_ASSOS_MEMBERS: Voir la liste des membres d'une association

Expand Down
1 change: 1 addition & 0 deletions app/config/modules.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ modules:
- Etu\Module\UploadBundle\EtuModuleUploadBundle
- Etu\Module\SIABundle\EtuModuleSIABundle
- Etu\Module\BadgesBundle\EtuModuleBadgesBundle
- Etu\Module\NewsBundle\EtuModuleNewsBundle
7 changes: 7 additions & 0 deletions app/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ security:
- ROLE_EVENTS_INTERNAL # can read Private/internal calendar and events

ROLE_USER:
- ROLE_NEWS_READ # Read orga's news

ROLE_STUDENT:
- ROLE_CORE_SUBSCRIBE # User can receive and use subscriptions
Expand All @@ -30,6 +31,7 @@ security:
- ROLE_COVOIT_EDIT # Can answer, post and set alerts on covoit bundle
- ROLE_CUMUL # Can cumul timetables
- ROLE_DAYMAIL_EDIT # Can edit daymail of his organization if authorized
- ROLE_NEWS_EDIT # Can edit news of his organization if authorized
- ROLE_EVENTS_INTERNAL # can read Private/internal calendar and events
- ROLE_EVENTS_ANSWER # Can see answer list
- ROLE_EVENTS_ANSWER_POST # Can post an answer
Expand Down Expand Up @@ -59,6 +61,7 @@ security:
- ROLE_COVOIT_EDIT # Can answer, post and set alerts on covoit bundle
- ROLE_CUMUL # Can cumul timetables
- ROLE_DAYMAIL_EDIT # Can edit daymail of his organization if authorized
- ROLE_NEWS_EDIT # Can edit news of his organization if authorized
- ROLE_EVENTS_INTERNAL # can read Private/internal calendar and events
- ROLE_EVENTS_EDIT # Can edit event of his organization if authorized
- ROLE_TROMBI # Can search on trombi
Expand All @@ -79,6 +82,7 @@ security:
- ROLE_COVOIT # Can read covoit bundle
- ROLE_COVOIT_EDIT # Can answer, post and set alerts on covoit bundle
- ROLE_DAYMAIL_EDIT # Can edit daymail of his organization if authorized
- ROLE_NEWS_EDIT # Can edit news of his organization if authorized
- ROLE_EVENTS_INTERNAL # can read Private/internal calendar and events
- ROLE_EVENTS_EDIT # Can edit event of his organization if authorized
- ROLE_TROMBI # Can search on trombi
Expand All @@ -104,6 +108,7 @@ security:
- ROLE_UV_REVIEW_ADMIN # Can moderate and remove UV review and old exams
- ROLE_BADGE_ADMIN # Can create and attribute badges
- ROLE_WIKI_ADMIN # Can lock, read and write on every admin page on the wiki
- ROLE_NEWS_ADMIN # Edit news

ROLE_SUPERADMIN:
- ROLE_ADMIN
Expand All @@ -120,6 +125,7 @@ security:
- ROLE_CORE_ADMIN_HOME # Can see admin homepage
- ROLE_FORUM_ADMIN # Can moderate forum
- ROLE_UV_REVIEW_ADMIN # Can moderate and remove UV review and old exams
- ROLE_NEWS_ADMIN # Edit news blog

ROLE_ARGENTIQUE:
- ROLE_CORE_ADMIN_HOME # Can see admin homepage
Expand All @@ -141,6 +147,7 @@ security:
- ROLE_CORE_SCHEDULE_OWN # Can read his own schedule
- ROLE_CORE_HOMEPAGE # Can see the private homepage
- ROLE_ARGENTIQUE_READ # View pictures
- ROLE_NEWS_READ # View news
- ROLE_ASSOS_MEMBERS # Read assos member list
- ROLE_BUGS # read bugs list
- ROLE_COVOIT # Can read covoit bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ pour cela, il faut suivre cette convention.
- La configuration est stockée dans `Resources/config`
- Les traductions sont stockées dans `Resources/translations`
- Les extensions Twig sont stockées dans `Twig` et sont suffixées de `Extension`
- Les traductions sont stockées dans `Resources/translations`
- Les commandes sont stockées dans `Command`
- Les types de champs de formulaires sont stockés dans `Form`
- Les classes outils (classes généralistes utiles partout) sont stockés dans `Util`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ user:
notifications: Notifications
event: Evènements
daymail: Daymail
news: News
wiki: Wiki
public: Page publique
sia: Gestionnaire SIA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
</a>
</li>
{% endif %}
{% if membership.hasPermission('news') and etu.modules.isEnabled('news') %}
<li {% if tab == 'memberships_orga_news' %}class="active"{% endif %}>
<a href="{{ path('memberships_orga_news', {'login': membership.organization.login}) }}">
{{ 'user.memberships.menu.news'|trans }}
</a>
</li>
{% endif %}

{% if etu.modules.isEnabled('wiki') %}
<li {% if tab == 'memberships_orga_wiki' %}class="active"{% endif %}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
</li>
{% endif %}

{% if membership.hasPermission('news') and etu.modules.isEnabled('news') %}
<li>
<a href="{{ path('memberships_orga_news', {'login': membership.organization.login}) }}">
{{ 'user.memberships.menu.news'|trans }}
</a>
</li>
{% endif %}

{% if etu.modules.isEnabled('assos') %}
<li>
<a href="{{ path('orgas_view', {'login': membership.organization.login}) }}">
Expand Down
217 changes: 217 additions & 0 deletions src/Etu/Module/NewsBundle/Controller/MainController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
<?php

namespace Etu\Module\NewsBundle\Controller;

use Etu\Core\CoreBundle\Framework\Definition\Controller;

// Import annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Etu\Module\NewsBundle\Entity\Article;

/**
* @Route("/news")
*/
class MainController extends Controller
{
/**
* @Route("", name="news_index")
* @Template()
*/
public function indexAction()
{
$this->denyAccessUnlessGranted('ROLE_NEWS_READ');
/** @var $em EntityManager */
$em = $this->getDoctrine()->getManager();

$query = $em->createQueryBuilder()
->select('a, o')
->from('EtuModuleNewsBundle:Article', 'a')
->leftJoin('a.orga', 'o')
->where('a.publishedAt is not NULL')
->andWhere('a.validatedAt is not NULL');
/** @var $articles Article[] */
$articles = $query
->orderBy('a.createdAt', 'DESC')
->getQuery()
->getResult();
return ['articles' => $articles];
}

/**
* @Route("/moderate", name="news_moderate")
* @Template()
*/
public function moderateAction()
{
$this->denyAccessUnlessGranted('ROLE_NEWS_ADMIN');
/** @var $em EntityManager */
$em = $this->getDoctrine()->getManager();

$query = $em->createQueryBuilder()
->select('a, o')
->from('EtuModuleNewsBundle:Article', 'a')
->leftJoin('a.orga', 'o')
->where('a.validatedAt is NULL')
->andWhere('a.publishedAt is not NULL');
/** @var $articles Article[] */
$articles = $query
->orderBy('a.createdAt', 'DESC')
->getQuery()
->getResult();
return ['articles' => $articles];
}
/**
* @Route("/articles/{id}", name="news_view")
* @Template()
*
* @param mixed $id
*/
public function viewAction($id)
{
$this->denyAccessUnlessGranted('ROLE_NEWS_READ');


/** @var $em EntityManager */
$em = $this->getDoctrine()->getManager();
$query = $em->createQueryBuilder()
->select('a, au, o')
->from('EtuModuleNewsBundle:Article', 'a')
->leftJoin('a.author', 'au')
->leftJoin('a.orga', 'o')
->where('a.id = :id')
->setParameter('id', $id);

/** @var $article Article */
$article = $query
->getQuery()
->setMaxResults(1)
->getOneOrNullResult();

if(!$article){
$this->get('session')->getFlashBag()->set('message', [
'type' => 'error',
'message' => 'news.main.article.notFound',
]);
return $this->redirect($this->generateUrl('news_index'));
}
/** @var $memberships Member[] */
$memberships = $em->createQueryBuilder()
->select('m, o')
->from('EtuUserBundle:Member', 'm')
->leftJoin('m.organization', 'o')
->andWhere('m.user = :user')
->setParameter('user', $this->getUser()->getId())
->orderBy('m.role', 'DESC')
->addOrderBy('o.name', 'ASC')
->getQuery()
->getResult();

$membership = null;

foreach ($memberships as $m) {
if ($m->getOrganization()->getLogin() == $article->getOrga()->getLogin()) {
$membership = $m;
break;
}
}
$canEdit = false;
if($this->isGranted('ROLE_NEWS_EDIT') && $membership != null) {
$canEdit = $membership->hasPermission('news');
}
if(!$this->isGranted('ROLE_NEWS_ADMIN') && !$canEdit && $article->getValidatedAt() == null) {
$this->get('session')->getFlashBag()->set('message', [
'type' => 'error',
'message' => 'news.main.article.notFound',
]);
return $this->redirect($this->generateUrl('news_index'));
}
return [
'article' => $article,
'canEdit' => $canEdit,
];
}


/**
* @Route(
* "/article/{id}/validate",
* name="news_validate"
* )
* @Template()
*
* @param mixed $id
*/
public function validateAction($id)
{
$this->denyAccessUnlessGranted('ROLE_NEWS_ADMIN');

/** @var $em EntityManager */
$em = $this->getDoctrine()->getManager();

/** @var $article Article */
$article = $em->createQueryBuilder()
->select('a')
->from('EtuModuleNewsBundle:Article', 'a')
->where('a.id = :id')
->setParameter('id', $id)
->getQuery()
->setMaxResults(1)
->getOneOrNullResult();

if (!$article) {
throw $this->createNotFoundException('Article not found');
}
$article->setValidatedAt(new \DateTime());
$this->get('session')->getFlashBag()->set('message', [
'type' => 'success',
'message' => 'news.main.article.confirmValidate',
]);

$em->persist($article);
$em->flush();

return $this->redirect($this->generateUrl('news_view', ['id' => $id]));
}

/**
* @Route(
* "/article/{id}/unvalidate",
* name="news_unvalidate"
* )
* @Template()
*
* @param mixed $id
*/
public function unvalidateAction($id)
{
$this->denyAccessUnlessGranted('ROLE_NEWS_ADMIN');

/** @var $em EntityManager */
$em = $this->getDoctrine()->getManager();

/** @var $article Article */
$article = $em->createQueryBuilder()
->select('a')
->from('EtuModuleNewsBundle:Article', 'a')
->where('a.id = :id')
->setParameter('id', $id)
->getQuery()
->setMaxResults(1)
->getOneOrNullResult();

if (!$article) {
throw $this->createNotFoundException('Article not found');
}
$article->setValidatedAt(null);
$this->get('session')->getFlashBag()->set('message', [
'type' => 'warning',
'message' => 'news.main.article.confirmUnvalidate',
]);

$em->persist($article);
$em->flush();

return $this->redirect($this->generateUrl('news_view', ['id' => $id]));
}
}
Loading