Skip to content

Commit

Permalink
new: Allow to create and list contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
marien-probesys committed Sep 15, 2023
2 parents e7c0868 + 4174cd5 commit c66bd7e
Show file tree
Hide file tree
Showing 29 changed files with 1,559 additions and 13 deletions.
1 change: 1 addition & 0 deletions assets/icons/contract.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ColorSchemeController from '@/controllers/color_scheme_controller.js';
import EditorController from '@/controllers/editor_controller.js';
import FormNewAnswerController from '@/controllers/form_new_answer_controller.js';
import FormNewAuthorizationController from '@/controllers/form_new_authorization_controller.js';
import FormNewContractController from '@/controllers/form_new_contract_controller.js';
import FormPriorityController from '@/controllers/form_priority_controller.js';
import MessageDocumentsController from '@/controllers/message_documents_controller.js';
import ModalController from '@/controllers/modal_controller.js';
Expand All @@ -28,6 +29,7 @@ application.register('color-scheme', ColorSchemeController);
application.register('editor', EditorController);
application.register('form-new-answer', FormNewAnswerController);
application.register('form-new-authorization', FormNewAuthorizationController);
application.register('form-new-contract', FormNewContractController);
application.register('form-priority', FormPriorityController);
application.register('message-documents', MessageDocumentsController);
application.register('modal', ModalController);
Expand Down
56 changes: 56 additions & 0 deletions assets/javascripts/controllers/form_new_contract_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This file is part of Bileto.
// Copyright 2022-2023 Probesys
// SPDX-License-Identifier: AGPL-3.0-or-later

import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
static get targets () {
return ['startAt', 'endAt'];
}

connect () {
this.refreshMinEndAt();
}

/**
* Set the endAt input value to the end of the year of the startAt value.
*/
updateEndAt () {
const startAtDate = new Date(this.startAtTarget.value);
const endAtDate = new Date(this.endAtTarget.value);

if (isNaN(startAtDate)) {
return;
}

if (isNaN(endAtDate) || startAtDate >= endAtDate) {
// Add 1 day as it may set an invalid date if startAtDate is 31th
// December.
startAtDate.setDate(startAtDate.getDate() + 1);

const startAtYear = startAtDate.getFullYear().toString();
this.endAtTarget.value = startAtYear + '-12-31';
}

this.refreshMinEndAt();
}

/**
* Set the min value of endAt input to the startAt date + 1 day.
*/
refreshMinEndAt () {
const startAtDate = new Date(this.startAtTarget.value);

if (isNaN(startAtDate)) {
return;
}

startAtDate.setDate(startAtDate.getDate() + 1);

const startAtYear = startAtDate.getFullYear().toString();
const startAtMonth = (startAtDate.getMonth() + 1).toString().padStart(2, '0');
const startAtDay = startAtDate.getDate().toString().padStart(2, '0');
this.endAtTarget.min = startAtYear + '-' + startAtMonth + '-' + startAtDay;
}
}
1 change: 1 addition & 0 deletions assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@import "./components/notifications.css";
@import "./components/placeholders.css";
@import "./components/popups.css";
@import "./components/progress.css";
@import "./components/scroll-to-top.css";
@import "./components/sidebar.css";
@import "./components/spinners.css";
Expand Down
4 changes: 2 additions & 2 deletions assets/stylesheets/components/messages.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
}

@media (min-width: 800px) {
.message__box::before {
.message__avatar + .message__box::before {
content: " ";

position: absolute;
Expand All @@ -78,7 +78,7 @@
clip-path: polygon(0 50%, 100% 0, 100% 100%);
}

.message--solution .message__box::before {
.message--solution .message__avatar + .message__box::before {
background-color: var(--color-success7);
}
}
Expand Down
20 changes: 20 additions & 0 deletions assets/stylesheets/components/progress.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This file is part of Bileto. */
/* Copyright 2022-2023 Probesys */
/* SPDX-License-Identifier: AGPL-3.0-or-later */

progress {
display: block;
width: 100%;
height: 2rem;

background-color: var(--color-primary2);
border: 0.25rem solid var(--color-primary11);
border-radius: 0.5rem;

appearance: none;
}

progress::-webkit-progress-bar,
progress::-moz-progress-bar {
background-color: var(--color-primary9);
}
2 changes: 1 addition & 1 deletion docs/developers/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $ make db-setup
Open [localhost:8000](http://localhost:8000) and login with one of the following credentials:

- `alix@example.com` / `secret` (super-admin and technician for all the organizations)
- `benedict@example.com` / `secret` (user in the “Web team” organization)
- `benedict@example.com` / `secret` (salesman for all the organizations)
- `charlie@example.com` / `secret` (user in the “Friendly Coorp” organization)

A note about the `make` commands: they might feel magic, but they are not!
Expand Down
131 changes: 131 additions & 0 deletions migrations/Version20230914073949CreateContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

// This file is part of Bileto.
// Copyright 2022-2023 Probesys
// SPDX-License-Identifier: AGPL-3.0-or-later

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20230914073949CreateContract extends AbstractMigration
{
public function getDescription(): string
{
return 'Create the contract table.';
}

public function up(Schema $schema): void
{
$dbPlatform = $this->connection->getDatabasePlatform();
if ($dbPlatform instanceof PostgreSQLPlatform) {
$this->addSql('CREATE SEQUENCE contract_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql(<<<SQL
CREATE TABLE contract (
id INT NOT NULL,
created_by_id INT NOT NULL,
updated_by_id INT NOT NULL,
organization_id INT NOT NULL,
uid VARCHAR(20) NOT NULL,
created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
name VARCHAR(255) NOT NULL,
start_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
end_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
max_hours INT NOT NULL,
notes TEXT NOT NULL,
PRIMARY KEY(id)
)
SQL);
$this->addSql('CREATE INDEX IDX_E98F2859B03A8386 ON contract (created_by_id)');
$this->addSql('CREATE INDEX IDX_E98F2859896DBBDE ON contract (updated_by_id)');
$this->addSql('CREATE INDEX IDX_E98F285932C8A3DE ON contract (organization_id)');
$this->addSql('COMMENT ON COLUMN contract.created_at IS \'(DC2Type:datetimetz_immutable)\'');
$this->addSql('COMMENT ON COLUMN contract.updated_at IS \'(DC2Type:datetimetz_immutable)\'');
$this->addSql('COMMENT ON COLUMN contract.start_at IS \'(DC2Type:datetimetz_immutable)\'');
$this->addSql('COMMENT ON COLUMN contract.end_at IS \'(DC2Type:datetimetz_immutable)\'');
$this->addSql(<<<SQL
ALTER TABLE contract
ADD CONSTRAINT FK_E98F2859B03A8386
FOREIGN KEY (created_by_id)
REFERENCES "users" (id)
NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
$this->addSql(<<<SQL
ALTER TABLE contract
ADD CONSTRAINT FK_E98F2859896DBBDE
FOREIGN KEY (updated_by_id)
REFERENCES "users" (id)
NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
$this->addSql(<<<SQL
ALTER TABLE contract
ADD CONSTRAINT FK_E98F285932C8A3DE
FOREIGN KEY (organization_id)
REFERENCES organization (id)
NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
} elseif ($dbPlatform instanceof MariaDBPlatform) {
$this->addSql(<<<SQL
CREATE TABLE contract (
id INT AUTO_INCREMENT NOT NULL,
created_by_id INT NOT NULL,
updated_by_id INT NOT NULL,
organization_id INT NOT NULL,
uid VARCHAR(20) NOT NULL,
created_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
name VARCHAR(255) NOT NULL,
start_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
end_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
max_hours INT NOT NULL,
notes LONGTEXT NOT NULL,
INDEX IDX_E98F2859B03A8386 (created_by_id),
INDEX IDX_E98F2859896DBBDE (updated_by_id),
INDEX IDX_E98F285932C8A3DE (organization_id),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
SQL);
$this->addSql(<<<SQL
ALTER TABLE contract
ADD CONSTRAINT FK_E98F2859B03A8386
FOREIGN KEY (created_by_id)
REFERENCES `users` (id)
SQL);
$this->addSql(<<<SQL
ALTER TABLE contract
ADD CONSTRAINT FK_E98F2859896DBBDE
FOREIGN KEY (updated_by_id)
REFERENCES `users` (id)
SQL);
$this->addSql(<<<SQL
ALTER TABLE contract
ADD CONSTRAINT FK_E98F285932C8A3DE
FOREIGN KEY (organization_id)
REFERENCES organization (id)
SQL);
}
}

public function down(Schema $schema): void
{
$dbPlatform = $this->connection->getDatabasePlatform();
if ($dbPlatform instanceof PostgreSQLPlatform) {
$this->addSql('DROP SEQUENCE contract_id_seq CASCADE');
$this->addSql('ALTER TABLE contract DROP CONSTRAINT FK_E98F2859B03A8386');
$this->addSql('ALTER TABLE contract DROP CONSTRAINT FK_E98F2859896DBBDE');
$this->addSql('ALTER TABLE contract DROP CONSTRAINT FK_E98F285932C8A3DE');
$this->addSql('DROP TABLE contract');
} elseif ($dbPlatform instanceof MariaDBPlatform) {
$this->addSql('ALTER TABLE contract DROP FOREIGN KEY FK_E98F2859B03A8386');
$this->addSql('ALTER TABLE contract DROP FOREIGN KEY FK_E98F2859896DBBDE');
$this->addSql('ALTER TABLE contract DROP FOREIGN KEY FK_E98F285932C8A3DE');
$this->addSql('DROP TABLE contract');
}
}
}
2 changes: 1 addition & 1 deletion public/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 20 additions & 2 deletions src/Command/SeedsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
],
]);

$roleSalesman = $this->roleRepository->findOneOrCreateBy([
'name' => 'Salesman',
], [
'description' => 'Manage the contracts.',
'type' => 'orga:user',
'permissions' => [
'orga:create:tickets',
'orga:create:tickets:messages',
'orga:create:tickets:messages:confidential',
'orga:manage:contracts',
'orga:see',
'orga:see:contracts',
'orga:see:contracts:notes',
'orga:see:tickets:all',
'orga:see:tickets:messages:confidential',
],
]);

$roleUser = $this->roleRepository->findOneOrCreateBy([
'name' => 'User',
], [
Expand Down Expand Up @@ -122,7 +140,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
], [
'name' => 'Benedict Aphone',
'password' => $password,
'organization' => $orgaWebDivision,
'organization' => $orgaProbesys,
]);

$userCharlie = $this->userRepository->findOneOrCreateBy([
Expand Down Expand Up @@ -153,7 +171,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if (!$this->authorizationRepository->getOrgaAuthorizationFor($userBenedict, $orgaWebDivision)) {
$this->authorizationRepository->grant($userBenedict, $roleUser, $orgaWebDivision);
$this->authorizationRepository->grant($userBenedict, $roleSalesman, null);
}

if (!$this->authorizationRepository->getOrgaAuthorizationFor($userCharlie, $orgaFriendlyCoorp)) {
Expand Down
Loading

0 comments on commit c66bd7e

Please sign in to comment.