Commit 8cfe9ebb authored by Emma's avatar Emma

remove themes

parent 5a5ab05d
Pipeline #24439883 passed with stage
in 4 minutes and 5 seconds
# Change Log
## v2.0.0 (20xx-xx-xx)
* Remove themes functionality.
## v1.0.0 (2018-06-22)
* Add ability to set default locale via environment variable.
......
......@@ -96,7 +96,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "2.0-dev"
},
"symfony": {
"allow-contrib": true
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "aaae105189a925093efd1f2e7c0379ff",
"content-hash": "4e27383690b853935e133cfd138be481",
"packages": [
{
"name": "composer/ca-bundle",
......
......@@ -36,11 +36,6 @@ delete_forum:
path: /f/{forum_name}/delete
methods: [GET, POST]
forum_appearance:
controller: App\Controller\ForumController::appearance
path: /f/{forum_name}/appearance
methods: [GET, POST]
forum_bans:
controller: App\Controller\ForumController::bans
defaults: { page: 1 }
......
theme_history:
controller: App\Controller\ThemeController::history
defaults: { page: 1}
path: /theme_history/{id}/{page}
methods: [GET]
requirements: { id: "%uuid_regex%", page: \d+ }
create_theme:
controller: App\Controller\ThemeController::create
path: /create_theme
methods: [GET, POST]
edit_theme_css:
controller: App\Controller\ThemeController::editCss
path: /edit_theme/{username}/{name}
methods: [GET, POST]
requirements: { name: .+ }
edit_theme_settings:
controller: App\Controller\ThemeController::editSettings
path: /edit_theme_settings/{username}/{name}
methods: [GET, POST]
requirements: { name: .+ }
theme_revision_source:
controller: App\Controller\ThemeController::source
path: /theme_source/{id}
methods: [GET]
requirements: { id: "%uuid_regex%" }
stylesheet:
controller: App\Controller\ThemeController::stylesheet
defaults: { _format: css }
path: /user_style/{field}/{themeId}.css
methods: [GET]
requirements: { field: common|day|night, themeId: "%uuid_regex%" }
themes:
controller: App\Controller\ThemeController::list
defaults: { page: 1 }
path: /themes/{page}
methods: [GET]
requirements: { page: \d+ }
......@@ -28,9 +28,6 @@ _security:
_submission:
resource: app_routes/submission.yaml
_theme:
resource: app_routes/theme.yaml
_user:
resource: app_routes/user.yaml
......
......@@ -6,7 +6,6 @@ use App\Entity\Forum;
use App\Entity\ForumWebhook;
use App\Entity\Moderator;
use App\Entity\User;
use App\Form\ForumAppearanceType;
use App\Form\ForumBanType;
use App\Form\ForumType;
use App\Form\ForumWebhookType;
......@@ -346,39 +345,6 @@ final class ForumController extends AbstractController {
]);
}
/**
* Alter a forum's appearance.
*
* @IsGranted("moderator", subject="forum")
*
* @param Forum $forum
* @param Request $request
* @param EntityManager $em
*
* @return Response
*/
public function appearance(Forum $forum, Request $request, EntityManager $em) {
$data = ForumData::createFromForum($forum);
$form = $this->createForm(ForumAppearanceType::class, $data);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data->updateForum($forum);
$em->flush();
return $this->redirectToRoute('forum_appearance', [
'forum_name' => $forum->getName(),
]);
}
return $this->render('forum/appearance.html.twig', [
'form' => $form->createView(),
'forum' => $forum,
]);
}
/**
* @param Forum $forum
* @param ForumBanRepository $banRepository
......
<?php
namespace App\Controller;
use App\Entity\Theme;
use App\Entity\ThemeRevision;
use App\Form\Model\ThemeData;
use App\Form\ThemeCssType;
use App\Form\ThemeSettingsType;
use App\Repository\ThemeRepository;
use Doctrine\ORM\EntityManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ThemeController extends AbstractController {
/**
* @param ThemeRepository $themeRepository
* @param int $page
*
* @return Response
*/
public function list(ThemeRepository $themeRepository, int $page) {
return $this->render('theme/list.html.twig', [
'themes' => $themeRepository->findAllPaginated($page),
]);
}
/**
* @IsGranted("ROLE_USER")
*
* @param Request $request
* @param EntityManager $em
*
* @return Response
*/
public function create(Request $request, EntityManager $em) {
$data = new ThemeData($this->getUser());
$form = $this->createForm(ThemeSettingsType::class, $data);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$theme = $data->toTheme();
$em->persist($theme);
$em->flush();
$this->addFlash('success', 'flash.theme_created');
return $this->redirectToRoute('edit_theme_css', [
'name' => $theme->getName(),
'username' => $theme->getAuthor()->getUsername(),
]);
}
return $this->render('theme/create.html.twig', [
'form' => $form->createView(),
]);
}
/**
* @Entity("theme", expr="repository.findOneByUsernameAndName(username, name)")
* @IsGranted("edit", subject="theme")
*
* @param Request $request
* @param EntityManager $em
* @param Theme $theme
*
* @return Response
*/
public function editCss(Request $request, EntityManager $em, Theme $theme) {
$data = ThemeData::createFromTheme($theme);
$form = $this->createForm(ThemeCssType::class, $data);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data->updateTheme($theme);
$em->flush();
$this->addFlash('success', 'flash.theme_updated');
return $this->redirectToRoute('edit_theme_css', [
'username' => $theme->getAuthor()->getUsername(),
'name' => $theme->getName(),
]);
}
return $this->render('theme/edit_css.html.twig', [
'form' => $form->createView(),
'theme' => $theme,
]);
}
/**
* @Entity("theme", expr="repository.findOneByUsernameAndName(username, name)")
* @IsGranted("edit", subject="theme")
*
* @param Request $request
* @param EntityManager $em
* @param Theme $theme
*
* @return Response
*/
public function editSettings(Request $request, EntityManager $em, Theme $theme) {
$data = ThemeData::createFromTheme($theme);
$form = $this->createForm(ThemeSettingsType::class, $data);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data->updateTheme($theme);
$em->flush();
$this->addFlash('success', 'flash.theme_updated');
return $this->redirectToRoute('edit_theme_settings', [
'username' => $theme->getAuthor()->getUsername(),
'name' => $theme->getName(),
]);
}
return $this->render('theme/edit_settings.html.twig', [
'form' => $form->createView(),
'theme' => $theme,
]);
}
/**
* @param Theme $theme
* @param int $page
*
* @return Response
*/
public function history(Theme $theme, int $page) {
return $this->render('theme/history.html.twig', [
'theme' => $theme,
'revisions' => $theme->getPaginatedRevisions($page),
]);
}
public function source(ThemeRevision $revision) {
return $this->render('theme/source.html.twig', [
'revision' => $revision,
]);
}
public function stylesheet(EntityManager $em, Request $request, string $themeId, string $field) {
$response = new Response();
$response->setPublic();
$response->setImmutable();
$response->setMaxAge(86400 * 365);
$response->setEtag($themeId);
if ($response->isNotModified($request)) {
return $response;
}
$theme = $em->find(ThemeRevision::class, $themeId);
if (!$theme) {
throw new NotFoundHttpException('No such revision');
}
$response->setContent($theme->{'get'.ucfirst($field).'Css'}());
return $response;
}
}
......@@ -115,13 +115,6 @@ class Forum {
*/
private $category;
/**
* @ORM\ManyToOne(targetEntity="Theme")
*
* @var Theme|null
*/
private $theme;
/**
* @ORM\OneToMany(targetEntity="ForumLogEntry", mappedBy="forum", cascade={"persist", "remove"})
* @ORM\OrderBy({"timestamp": "DESC"})
......@@ -370,14 +363,6 @@ class Forum {
$this->category = $category;
}
public function getTheme(): ?Theme {
return $this->theme;
}
public function setTheme(?Theme $theme) {
$this->theme = $theme;
}
/**
* @param int $page
* @param int $max
......
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Pagerfanta\Adapter\DoctrineCollectionAdapter;
use Pagerfanta\Pagerfanta;
use Ramsey\Uuid\Uuid;
/**
* @ORM\Entity(repositoryClass="App\Repository\ThemeRepository")
* @ORM\Table(name="themes", uniqueConstraints={
* @ORM\UniqueConstraint(name="themes_author_name_idx", columns={"author_id", "name"})
* })
*/
class Theme {
/**
* @ORM\Column(type="uuid")
* @ORM\Id()
*
* @var Uuid
*/
private $id;
/**
* @ORM\Column(type="text")
*
* @var string
*/
private $name;
/**
* @ORM\JoinColumn(nullable=false)
* @ORM\ManyToOne(targetEntity="User")
*
* @var User
*/
private $author;
/**
* @ORM\OneToMany(targetEntity="ThemeRevision", mappedBy="theme", cascade={"persist"})
* @ORM\OrderBy({"modified": "DESC"})
*
* @var Collection|ThemeRevision[]
*/
private $revisions;
public function __construct(string $name, User $author) {
$this->id = Uuid::uuid4();
$this->name = $name;
$this->author = $author;
$this->revisions = new ArrayCollection();
}
public function getId(): Uuid {
return $this->id;
}
public function getName(): string {
return $this->name;
}
public function setName(string $name) {
$this->name = $name;
}
public function getAuthor(): User {
return $this->author;
}
public function getLatestRevision(): ?ThemeRevision {
$criteria = Criteria::create()
->orderBy(['modified' => 'DESC', 'id' => 'ASC']);
return $this->revisions->matching($criteria)->first() ?: null;
}
public function addRevision(ThemeRevision $revision) {
if (!$this->revisions->contains($revision)) {
$this->revisions->add($revision);
}
}
public function getPaginatedRevisions(int $page, int $maxPerPage = 25) {
$pager = new Pagerfanta(new DoctrineCollectionAdapter($this->revisions));
$pager->setMaxPerPage($maxPerPage);
$pager->setCurrentPage($page);
return $pager;
}
}
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
/**
* @ORM\Entity()
* @ORM\Table(name="theme_revisions")
*/
class ThemeRevision {
/**
* @ORM\Column(type="uuid")
* @ORM\Id()
*
* @var Uuid
*/
private $id;
/**
* @ORM\JoinColumn(nullable=false)
* @ORM\ManyToOne(targetEntity="Theme", inversedBy="revisions")
*
* @var Theme
*/
private $theme;
/**
* @ORM\Column(type="text", nullable=true)
*
* @var string|null
*/
private $commonCss;
/**
* @ORM\Column(type="text", nullable=true)
*
* @var string|null
*/
private $dayCss;
/**
* @ORM\Column(type="text", nullable=true)
*
* @var string|null
*/
private $nightCss;
/**
* @ORM\Column(type="boolean", options={"default": true})
*
* @var bool
*/
private $appendToDefaultStyle;
/**
* @ORM\Column(type="text", nullable=true)
*
* @var string
*/
private $comment;
/**
* @ORM\Column(type="datetimetz")
*
* @var \DateTime
*/
private $modified;
/**
* @ORM\ManyToOne(targetEntity="ThemeRevision")
*
* @var ThemeRevision
*/
private $parent;
public function __construct(
Theme $theme,
?string $commonCss,
?string $dayCss,
?string $nightCss,
bool $appendToDefaultStyle,
?string $comment,
self $parent = null,
\DateTime $modified = null
) {
if (!$commonCss && !$dayCss && !$nightCss) {
throw new \DomainException('At least one CSS field must be filled');
}
if ($parent->parent->parent->parent ?? false) {
throw new \DomainException('A theme cannot have more than three parents');
}
$this->id = Uuid::uuid4();
$this->theme = $theme;
$this->commonCss = $commonCss;
$this->dayCss = $dayCss;
$this->nightCss = $nightCss;
$this->appendToDefaultStyle = $appendToDefaultStyle;
$this->comment = $comment;
$this->parent = $parent;
$this->modified = $modified ?: new \DateTime('@'.time());
$theme->addRevision($this);
}
public function getId(): Uuid {
return $this->id;
}
public function getTheme(): Theme {
return $this->theme;
}
public function getCommonCss(): ?string {
return $this->commonCss;
}
public function getDayCss(): ?string {
return $this->dayCss;
}
public function getNightCss(): ?string {
return $this->nightCss;
}
public function appendToDefaultStyle(): bool {
return $this->appendToDefaultStyle;
}
public function getComment(): ?string {
return $this->comment;
}
public function getParent(): ?self {
return $this->parent;
}
public function getParentCount(): int {
$count = 0;
while (($parent = ($parent ?? $this)->getParent())) {
$count++;
}
return $count;
}
/**
* Get all parents and self in the correct include order.
*
* @return string[]
*/
public function getHierarchy(): array {
$hierarchy = [$this];
while (($parent = ($parent ?? $this)->getParent())) {
array_unshift($hierarchy, $parent);
}
return $hierarchy;
}
public function getModified(): \DateTime {
return $this->modified;
}
}
......@@ -172,13 +172,6 @@ class User implements UserInterface, EquatableInterface {
*/
private $nightMode = false;
/**
* @ORM\Column(type="boolean", options={"default": true})
*
* @var bool
*/
private $showCustomStylesheets = true;
/**
* @ORM\Column(type="boolean", options={"default": false})
*
......@@ -186,13 +179,6 @@ class User implements UserInterface, EquatableInterface {
*/
private $trusted = false;
/**
* @ORM\ManyToOne(targetEntity="Theme")
*
* @var Theme|null
*/
private $preferredTheme;
/**
* @ORM\OneToMany(targetEntity="UserBlock", mappedBy="blocker")
* @ORM\OrderBy({"timestamp": "DESC"})
......@@ -481,14 +467,6 @@ class User implements UserInterface, EquatableInterface {
$this->nightMode = $nightMode;
}
public function isShowCustomStylesheets(): bool {
return $this->showCustomStylesheets;
}
public function setShowCustomStylesheets(bool $showCustomStylesheets) {
$this->showCustomStylesheets = $showCustomStylesheets;
}
public function isTrusted(): bool {
return $this->trusted;
}
......@@ -501,14 +479,6 @@ class User implements UserInterface, EquatableInterface {
$this->trusted = $trusted;
}
public function getPreferredTheme(): ?Theme {
return $this->preferredTheme;
}
public function setPreferredTheme(?Theme $preferredTheme) {
$this->preferredTheme = $preferredTheme;
}
/**
* @param int $page
* @param int $maxPerPage
......
<?php
namespace App\Form;
use App\Form\Model\ForumData;
use App\Form\Type\ThemeSelectorType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ForumAppearanceType extends AbstractType {
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('theme', ThemeSelectorType::class, [
'label' => 'label.theme',
])
->add('save', SubmitType::class, [
'label' => 'label.save_settings',
]);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults([
'data_class' => ForumData::class,
'validation_groups' => ['appearance'],
]);
}
}
......@@ -47,8 +47,6 @@ class ForumData {
private $featured = false;
private $theme;
private $category;
public static function createFromForum(Forum $forum): self {
......@@ -59,7 +57,6 @@ class ForumData {
$self->sidebar = $forum->getSidebar();
$self->description = $forum->getDescription();
$self->featured = $forum->isFeatured();
$self->theme = $forum->getTheme();
$self->category = $forum->getCategory();
return $self;
......@@ -75,7 +72,6 @@ class ForumData {
);
$forum->setFeatured($this->featured);