diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..5950df3 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,60 @@ +# PHP CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-php/ for more details +# +version: 2 +jobs: + build: + docker: + # Specify the version you desire here + - image: circleci/php:7.3.3 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # Using the RAM variation mitigates I/O contention + # for database intensive operations. + # - image: circleci/mysql:5.7-ram + # + # - image: redis:2.8.19 + + steps: + - checkout + + - run: sudo apt update + - run: sudo docker-php-ext-install pdo_mysql + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "composer.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: + name: Display PHP information + command: | + php -v + composer --version + + - run: + name: Install project dependencies + command: | + composer install -n --prefer-dist + + - save_cache: + key: v1-dependencies-{{ checksum "composer.lock" }} + paths: + - ./vendor + + # prepare the database + #- run: touch storage/testing.sqlite + #- run: php artisan migrate --env=testing --database=sqlite_testing --force + + # run tests + - run: + name: Run Unit tests + command: ./vendor/bin/phpunit -c ./qaTools/phpunit.xml + - run: + name: Run Grumphp + command: ./vendor/bin/grumphp run \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..60de8a1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +# .gitattributes +tests/ export-ignore +docker/ export-ignore +qa/ export-ignore +qaTools/ export-ignore +docs/ export-ignore +database/ export-ignore + +# Auto detect text files and perform LF normalization +* text=auto \ No newline at end of file diff --git a/README.md b/README.md index 3875ceb..1e223e0 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,9 @@ To see what else has been achieved so far, please have a look at the [Milestones If you are considering [Contributing](docs/CONTRIBUTING.md) to the development of PublicWhip v2, please ensure you have read the [Code of Conduct](docs/CODE_OF_CONDUCT.md) first. All contributions to PublicWhip v2 must be licensed under -the [MIT](LICENSE.txt) license allowing free usage of the code in any form without restriction. \ No newline at end of file +the [MIT](LICENSE.txt) license allowing free usage of the code in any form without restriction. + +[![Coverage Status](https://coveralls.io/repos/github/publicwhip/publicwhipv2/badge.svg?branch=master)](https://coveralls.io/github/publicwhip/publicwhipv2?branch=master) +[![CircleCI](https://circleci.com/gh/publicwhip/publicwhipv2/tree/master.svg?style=svg)](https://circleci.com/gh/publicwhip/publicwhipv2/tree/master) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![Slack Join Chat](https://img.shields.io/badge/Slack-Join_Chat-blue.svg)](https://join.slack.com/t/publicwhip/shared_invite/enQtNTczMTg1MTc1Mzc3LTAxMjkyYzNhNWY0NDdmY2EzYjYwNTZjNjQ1YTNiOTQwZWYzM2Q0ZDJjOWU5MTVjNzZmNGFjMzljY2U0ZjA0YjM) \ No newline at end of file diff --git a/composer.json b/composer.json index df37708..8a57d88 100644 --- a/composer.json +++ b/composer.json @@ -1,62 +1,68 @@ { - "name": "bairwell/publicwhip", - "description": "Publicwhip v2 website", - "type": "project", - "homepage": "https://www.publicwhip.org.uk/", - "require": { - "php": ">=7.2", - "ext-pdo": "*", - "slim/slim": "^3", - "psr/log": "^1", - "twig/twig": "^2", - "slim/twig-view": "^2", - "monolog/monolog": "^1.24", - "php-di/php-di": "^6.0", - "php-di/slim-bridge": "^2.0", - "psr/http-message": "^1.0", - "psr/container": "^1", - "slim/csrf": "^0.5", - "slim/flash": "^0.1", - "maximebf/debugbar": "^1.15", - "swiftmailer/swiftmailer": "^5.4", - "illuminate/database": "^5.1", - "illuminate/events": "^5.1", - "illuminate/container": "^5.8", - "illuminate/support": "^5.8", - "illuminate/contracts": "^5.8", - "slim/http-cache": "^0.4.0", - "erusev/parsedown": "^1.7" - }, - "require-dev": { - "phpunit/phpunit": "^8", - "roave/security-advisories": "dev-master", - "phpstan/phpstan-strict-rules": "^0.11", - "phpmd/phpmd": "^2", - "maglnet/composer-require-checker": "^1", - "phpro/grumphp": "^0.15", - "phpstan/phpstan": "^0.11", - "sensiolabs/security-checker": "^5", - "squizlabs/php_codesniffer": "^3", - "infection/infection": "^0.12", - "sebastian/phpcpd": "^4", - "jakub-onderka/php-parallel-lint": "^1.0" - }, - "license": "MIT", - "authors": [ - { - "name": "Richard Bairwell", - "email": "team@publicwhip.org.uk" - } - ], - "support": { - "issues": "https://github.com/publicwhip/publicwhipv2/issues", - "docs": "https://github.com/publicwhip/publicwhip/tree/master/docs", + "name": "bairwell/publicwhip", + "description": "Publicwhip v2 website", + "type": "project", + "homepage": "https://www.publicwhip.org.uk/", + "require": { + "php": ">=7.2", + "ext-pdo": "*", + "slim/slim": "^3", + "psr/log": "^1", + "twig/twig": "^2", + "slim/twig-view": "^2", + "monolog/monolog": "^1.24", + "php-di/php-di": "^6.0", + "php-di/slim-bridge": "^2.0", + "psr/http-message": "^1.0", + "psr/container": "^1", + "slim/csrf": "^0.5", + "slim/flash": "^0.1", + "maximebf/debugbar": "^1.15", + "swiftmailer/swiftmailer": "^5.4", + "illuminate/database": "^5.1", + "illuminate/events": "^5.1", + "illuminate/container": "^5.8", + "illuminate/support": "^5.8", + "illuminate/contracts": "^5.8", + "slim/http-cache": "^0.4.0", + "erusev/parsedown": "^1.7" + }, + "require-dev": { + "phpunit/phpunit": "^8", + "roave/security-advisories": "dev-master", + "phpstan/phpstan-strict-rules": "^0.11", + "phpmd/phpmd": "^2", + "maglnet/composer-require-checker": "^1", + "phpro/grumphp": "^0.15", + "phpstan/phpstan": "^0.11", + "sensiolabs/security-checker": "^5", + "squizlabs/php_codesniffer": "^3", + "infection/infection": "^0.12", + "sebastian/phpcpd": "^4", + "jakub-onderka/php-parallel-lint": "^1.0" + }, + "scripts": { + "style": "phpcs --standard=./qaTools/phpcs.xml", + "test": "phpunit", + "format-code": "php-cs-fixer fix --allow-risky=yes", + "phpstan": "phpstan analyse -l 6 -c qaTools/phpstan.neon src" + }, + "license": "MIT", + "authors": [ + { + "name": "Richard Bairwell", "email": "team@publicwhip.org.uk" - }, - "autoload": { - "psr-4": { - "PublicWhip\\": "src/" - } - }, - "minimum-stability": "stable" + } + ], + "support": { + "issues": "https://github.com/publicwhip/publicwhipv2/issues", + "docs": "https://github.com/publicwhip/publicwhip/tree/master/docs", + "email": "team@publicwhip.org.uk" + }, + "autoload": { + "psr-4": { + "PublicWhip\\": "src/" + } + }, + "minimum-stability": "stable" } diff --git a/composer.lock b/composer.lock index 9253549..62355b9 100644 --- a/composer.lock +++ b/composer.lock @@ -2000,16 +2000,16 @@ }, { "name": "twig/twig", - "version": "v2.7.1", + "version": "v2.7.2", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "c0dd4dc5f44e541c9c0e0506da76aa4f14b41c69" + "reference": "70c59531da43afe598c66135e39cac39475a2f51" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/c0dd4dc5f44e541c9c0e0506da76aa4f14b41c69", - "reference": "c0dd4dc5f44e541c9c0e0506da76aa4f14b41c69", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/70c59531da43afe598c66135e39cac39475a2f51", + "reference": "70c59531da43afe598c66135e39cac39475a2f51", "shasum": "" }, "require": { @@ -2063,7 +2063,7 @@ "keywords": [ "templating" ], - "time": "2019-03-12T15:45:07+00:00" + "time": "2019-03-12T18:48:26+00:00" } ], "packages-dev": [ diff --git a/database/README.md b/database/README.md index 1966d40..d58a3f0 100644 --- a/database/README.md +++ b/database/README.md @@ -6,16 +6,37 @@ It is automatically loaded into docker whenever the `docker-composer up --build` The data was anonymised/reduced using: ```sql +# Remove unwanted tables +SELECT CONCAT('DROP TABLE ',GROUP_CONCAT(CONCAT('`publicwhip-db`.`',table_name,'`')),';') +INTO @dropcmd +FROM information_schema.TABLES +WHERE TABLE_SCHEMA='publicwhip-db' +AND (TABLE_NAME LIKE 'phpbb3\_%' OR TABLE_NAME LIKE 'phpbb_%'); + +PREPARE stmt FROM @dropcmd; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +# Remove private dream mp (policies) entries. +DELETE FROM pw_dyn_dreammp WHERE private=1; +DELETE FROM pw_cache_dreaminfo WHERE dream_id NOT IN (SELECT dream_id FROM pw_dyn_dreammp); +DELETE FROM pw_cache_dreamreal_distance WHERE dream_id NOT IN (SELECT dream_id FROM pw_dyn_dreammp); +DELETE FROM pw_dyn_dreamvote WHERE dream_id NOT IN (SELECT dream_id FROM pw_dyn_dreammp); + +# Remove users which are not used anywhere. DELETE FROM pw_dyn_user WHERE user_id NOT IN ( SELECT DISTINCT(user_id) FROM ( SELECT wm.user_id FROM pw_dyn_wiki_motion AS wm UNION SELECT al.user_id FROM pw_dyn_auditlog AS al +UNION +SELECT dm.user_id FROM pw_dyn_dreammp AS dm ) AS users); - +# anonymise the auditlog UPDATE `pw_dyn_auditlog` SET remote_addr=CONCAT('172.16.',FLOOR(RAND() * 253) +1,'.',FLOOR(RAND() * 253) +1),event='- Removed -'; +# anonymise the users entries UPDATE `pw_dyn_user` SET user_name=CONCAT('User ',user_id), real_name=CONCAT('Real ',user_id,' Name'), email=CONCAT('user',user_id,'@example.com'), @@ -31,19 +52,30 @@ Yes, version 1 does store the passwords in MD5(!). and then exported: ```bash -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_cache_divinfo > pw_cache_divinfo.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_cache_divwiki > pw_cache_divwiki.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_cache_mpinfo > pw_cache_mpinfo.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_cache_partyinfo > pw_cache_partyinfo.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_cache_whip > pw_cache_whip.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_constituency > pw_constituency.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_division > pw_division.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_dyn_auditlog > pw_dyn_auditlog.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_dyn_user > pw_dyn_user.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_dyn_wiki_motion > pw_dyn_wiki_motion.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_moffice > pw_moffice.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_mp > pw_mp.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_vote > pw_vote.sql -docker exec publicwhip-mariadb /usr/bin/mysqldump -u root --password=root publicwhip-db pw_vote_sortorder > pw_vote_sortorder.sql +docker exec -it publicwhip-mariadb /bin/bash + + +mysqldump -u root --password=root publicwhip-db pw_cache_divinfo > /docker-entrypoint-initdb.d/pw_cache_divinfo.sql +mysqldump -u root --password=root publicwhip-db pw_cache_divwiki > /docker-entrypoint-initdb.d/pw_cache_divwiki.sql +mysqldump -u root --password=root publicwhip-db pw_cache_mpinfo > /docker-entrypoint-initdb.d/pw_cache_mpinfo.sql +mysqldump -u root --password=root publicwhip-db pw_cache_partyinfo > /docker-entrypoint-initdb.d/pw_cache_partyinfo.sql +mysqldump -u root --password=root publicwhip-db pw_cache_whip > /docker-entrypoint-initdb.d/pw_cache_whip.sql +mysqldump -u root --password=root publicwhip-db pw_constituency > /docker-entrypoint-initdb.d/pw_constituency.sql +mysqldump -u root --password=root publicwhip-db pw_division > /docker-entrypoint-initdb.d/pw_division.sql +mysqldump -u root --password=root publicwhip-db pw_dyn_auditlog > /docker-entrypoint-initdb.d/pw_dyn_auditlog.sql +mysqldump -u root --password=root publicwhip-db pw_dyn_user > /docker-entrypoint-initdb.d/pw_dyn_user.sql +mysqldump -u root --password=root publicwhip-db pw_dyn_wiki_motion > /docker-entrypoint-initdb.d/pw_dyn_wiki_motion.sql +mysqldump -u root --password=root publicwhip-db pw_moffice > /docker-entrypoint-initdb.d/pw_moffice.sql +mysqldump -u root --password=root publicwhip-db pw_mp > /docker-entrypoint-initdb.d/pw_mp.sql +mysqldump -u root --password=root publicwhip-db pw_vote > /docker-entrypoint-initdb.d/pw_vote.sql +mysqldump -u root --password=root publicwhip-db pw_vote_sortorder > /docker-entrypoint-initdb.d/pw_vote_sortorder.sql +# Now for the policies +mysqldump -u root --password=root publicwhip-db pw_cache_dreaminfo > /docker-entrypoint-initdb.d/pw_cache_dreaminfo.sql +mysqldump -u root --password=root publicwhip-db pw_cache_dreamreal_distance > /docker-entrypoint-initdb.d/pw_cache_dreamreal_distance.sql +mysqldump -u root --password=root publicwhip-db pw_dyn_dreammp > /docker-entrypoint-initdb.d/pw_dyn_dreammp.sql +mysqldump -u root --password=root publicwhip-db pw_dyn_dreamvote > /docker-entrypoint-initdb.d/pw_dyn_dreamvote.sql +# and compress them all +gzip /docker-entrypoint-initdb.d/*.sql + ``` \ No newline at end of file diff --git a/database/pw_cache_dreaminfo.sql.gz b/database/pw_cache_dreaminfo.sql.gz new file mode 100644 index 0000000..9d2d9bd Binary files /dev/null and b/database/pw_cache_dreaminfo.sql.gz differ diff --git a/database/pw_cache_dreamreal_distance.sql.gz b/database/pw_cache_dreamreal_distance.sql.gz new file mode 100644 index 0000000..8f53ea6 Binary files /dev/null and b/database/pw_cache_dreamreal_distance.sql.gz differ diff --git a/database/pw_dyn_dreammp.sql.gz b/database/pw_dyn_dreammp.sql.gz new file mode 100644 index 0000000..d6c7773 Binary files /dev/null and b/database/pw_dyn_dreammp.sql.gz differ diff --git a/database/pw_dyn_dreamvote.sql.gz b/database/pw_dyn_dreamvote.sql.gz new file mode 100644 index 0000000..674bc6f Binary files /dev/null and b/database/pw_dyn_dreamvote.sql.gz differ diff --git a/docs/Milestones.md b/docs/Milestones.md index 2057e24..3eafbe0 100644 --- a/docs/Milestones.md +++ b/docs/Milestones.md @@ -8,7 +8,11 @@ Division motion text is stored in a custom 'wiki' format which needs to be parsed. -* 0.5 - Create basic division editing system (with no authentication) : Estimate 3-4 days +* 0.4.5 - Create basic division editing system (with no authentication) : Estimate 3-4 days + +* 0.5 - Show/List policies (aka "dreams" in v1 database). Estimate 1 day + +* 0.5.5 - Add ability to modify policies. Estimate 2 days. * 0.6 - Add authentication. Estimate 2-3 days. @@ -19,7 +23,7 @@ * 0.7 - Add basic votes display on divisions. Estimate 2-3 days. * 0.8 - Replace existing configuration system to a simpler one using `.env` files. Estimate 1 day * 0.9 - Ensure templates, routing and dependency injector are cached on production. Estimate 1 day -* 0.10 - Get a better web site design in place. +* 0.10 - Get a better web site design in place. Estimate 4 days. * 0.11 - Ensure adequate logging/instrumentation is in place. Estimate 1 day * 0.21 - Get unit test coverage to at least 20% with those tests then being fully mutation covered. Estimate 3-4 days. @@ -50,6 +54,10 @@ ## Completed Milestones (in recently completed order) +* 0.3.1 - Small fixes. + + Added continuous integration settings, missing database tables (for policies), added planned + milestones, fix indentation in composer.json * 0.3 - Prepare for upload to Github. Estimate 1 day. DONE - 2019-03-12 The system should present a basic styled POC (proof-of-concept) website with diff --git a/grumphp.yml b/grumphp.yml index 1db837d..562e83c 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -23,7 +23,7 @@ parameters: level: 7 ignore_patterns: ['web','database','docker','cache','logs','.phpstorm.meta.php','NotFoundHandler.php'] phpversion: - project: '7.3' + project: '7.2' phpunit: config_file: ./qaTools/phpunit.xml securitychecker: ~ diff --git a/src/Web/Controllers/DebugBarController.php b/src/Web/Controllers/DebugBarController.php index fa7cefe..812e1a5 100644 --- a/src/Web/Controllers/DebugBarController.php +++ b/src/Web/Controllers/DebugBarController.php @@ -20,11 +20,25 @@ */ class DebugBarController { - + /** + * @var DebuggerProviderInterface $debuggerProvider + */ private $debuggerProvider; + /** + * @var LoggerInterface $logger + */ private $logger; + /** + * @var CacheProvider $cacheProvider + */ private $cacheProvider; + /** + * DebugBarController constructor. + * @param DebuggerProviderInterface $debuggerProvider + * @param LoggerInterface $logger + * @param CacheProvider $cacheProvider + */ public function __construct( DebuggerProviderInterface $debuggerProvider, LoggerInterface $logger,