From fb0673d5663eb00ae40fe72471882fde9ccf3136 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Tue, 17 May 2022 17:38:10 +0300 Subject: [PATCH] dynamic html load --- docs/ahriman.1 | 34 ++- docs/ahriman.core.database.migrations.rst | 8 + docs/ahriman.web.views.status.rst | 8 - docs/configuration.rst | 2 +- docs/triggers.rst | 2 +- package/share/ahriman/settings/ahriman.ini | 3 +- .../ahriman/templates/build-status.jinja2 | 67 +++--- .../package-actions-script.jinja2 | 95 --------- ...ns-modals.jinja2 => package-modals.jinja2} | 14 +- .../templates/build-status/scripts.jinja2 | 196 ++++++++++++++++++ .../share/ahriman/templates/repo-index.jinja2 | 3 +- .../templates/utils/bootstrap-scripts.jinja2 | 8 +- .../ahriman/templates/utils/style.jinja2 | 6 +- setup.py | 4 +- src/ahriman/application/handlers/status.py | 4 +- src/ahriman/core/auth/auth.py | 4 +- .../database/migrations/m002_user_access.py | 33 +++ src/ahriman/core/status/client.py | 11 +- src/ahriman/core/status/web_client.py | 33 +-- src/ahriman/models/build_status.py | 34 --- src/ahriman/models/internal_status.py | 6 +- src/ahriman/models/user.py | 4 +- src/ahriman/models/user_access.py | 31 ++- src/ahriman/web/middlewares/auth_handler.py | 17 +- src/ahriman/web/routes.py | 11 +- src/ahriman/web/views/base.py | 2 +- src/ahriman/web/views/index.py | 50 +---- src/ahriman/web/views/service/add.py | 2 +- src/ahriman/web/views/service/remove.py | 2 +- src/ahriman/web/views/service/request.py | 2 +- src/ahriman/web/views/service/search.py | 2 +- src/ahriman/web/views/status/ahriman.py | 71 ------- src/ahriman/web/views/status/package.py | 2 +- src/ahriman/web/views/status/packages.py | 2 +- src/ahriman/web/views/status/status.py | 30 ++- src/ahriman/web/views/user/login.py | 2 +- src/ahriman/web/views/user/logout.py | 2 +- .../handlers/test_handler_status.py | 4 +- .../handlers/test_handler_users.py | 2 +- tests/ahriman/application/test_ahriman.py | 4 +- tests/ahriman/application/test_lock.py | 6 +- tests/ahriman/conftest.py | 2 +- tests/ahriman/core/auth/test_auth.py | 2 +- tests/ahriman/core/auth/test_mapping.py | 2 +- .../migrations/test_m002_user_access.py | 8 + .../operations/test_auth_operations.py | 10 +- tests/ahriman/core/status/test_client.py | 13 +- tests/ahriman/core/status/test_web_client.py | 45 +--- tests/ahriman/core/test_util.py | 4 +- tests/ahriman/models/conftest.py | 3 +- tests/ahriman/models/test_build_status.py | 25 --- tests/ahriman/models/test_user.py | 9 +- tests/ahriman/models/test_user_access.py | 51 +++++ tests/ahriman/web/conftest.py | 62 ++++++ .../web/middlewares/test_auth_handler.py | 53 ++++- tests/ahriman/web/views/conftest.py | 64 ------ .../views/service/test_views_service_add.py | 2 +- .../service/test_views_service_remove.py | 2 +- .../service/test_views_service_request.py | 2 +- .../service/test_views_service_search.py | 2 +- .../views/status/test_views_status_ahriman.py | 65 ------ .../views/status/test_views_status_package.py | 2 +- .../status/test_views_status_packages.py | 2 +- .../views/status/test_views_status_status.py | 39 ++++ tests/ahriman/web/views/test_views_index.py | 2 +- .../web/views/user/test_views_user_login.py | 2 +- .../web/views/user/test_views_user_logout.py | 2 +- tests/testresources/core/ahriman.ini | 2 +- 68 files changed, 649 insertions(+), 651 deletions(-) delete mode 100644 package/share/ahriman/templates/build-status/package-actions-script.jinja2 rename package/share/ahriman/templates/build-status/{package-actions-modals.jinja2 => package-modals.jinja2} (81%) create mode 100644 package/share/ahriman/templates/build-status/scripts.jinja2 create mode 100644 src/ahriman/core/database/migrations/m002_user_access.py delete mode 100644 src/ahriman/web/views/status/ahriman.py create mode 100644 tests/ahriman/core/database/migrations/test_m002_user_access.py delete mode 100644 tests/ahriman/web/views/status/test_views_status_ahriman.py diff --git a/docs/ahriman.1 b/docs/ahriman.1 index ddb1fd0b..8f690230 100644 --- a/docs/ahriman.1 +++ b/docs/ahriman.1 @@ -3,7 +3,7 @@ ahriman .SH SYNOPSIS .B ahriman -[-h] [-a ARCHITECTURE] [-c CONFIGURATION] [--force] [-l LOCK] [--no-report] [-q] [--unsafe] [-v] {aur-search,search,help,help-commands-unsafe,key-import,package-add,add,package-update,package-remove,remove,package-status,status,package-status-remove,package-status-update,status-update,patch-add,patch-list,patch-remove,repo-backup,repo-check,check,repo-clean,clean,repo-config,config,repo-rebuild,rebuild,repo-remove-unknown,remove-unknown,repo-restore,repo-setup,init,repo-init,setup,repo-sign,sign,repo-status-update,repo-triggers,repo-update,update,user-add,user-list,user-remove,web} ... +[-h] [-a ARCHITECTURE] [-c CONFIGURATION] [--force] [-l LOCK] [--no-report] [-q] [--unsafe] [-v] {aur-search,search,help,help-commands-unsafe,key-import,package-add,add,package-update,package-remove,remove,package-status,status,package-status-remove,package-status-update,status-update,patch-add,patch-list,patch-remove,repo-backup,repo-check,check,repo-clean,clean,repo-config,config,repo-rebuild,rebuild,repo-remove-unknown,remove-unknown,repo-report,report,repo-restore,repo-setup,init,repo-init,setup,repo-sign,sign,repo-status-update,repo-sync,sync,repo-triggers,repo-update,update,user-add,user-list,user-remove,web} ... .SH DESCRIPTION ArcH Linux ReposItory MANager @@ -97,6 +97,9 @@ rebuild repository \fBahriman\fR \fI\,repo-remove-unknown\/\fR remove unknown packages .TP +\fBahriman\fR \fI\,repo-report\/\fR +generate report +.TP \fBahriman\fR \fI\,repo-restore\/\fR restore repository data .TP @@ -109,6 +112,9 @@ sign packages \fBahriman\fR \fI\,repo-status-update\/\fR update repository status .TP +\fBahriman\fR \fI\,repo-sync\/\fR +sync repository +.TP \fBahriman\fR \fI\,repo-triggers\/\fR run triggers .TP @@ -405,6 +411,11 @@ just perform check for packages without removal \fB\-i\fR, \fB\-\-info\fR show additional package information +.SH COMMAND \fI\,'ahriman repo-report'\/\fR +usage: ahriman repo-report [-h] + +generate repository report according to current settings + .SH COMMAND \fI\,'ahriman repo-restore'\/\fR usage: ahriman repo-restore [-h] [-o OUTPUT] path @@ -485,11 +496,20 @@ update repository status on the status page \fB\-s\fR \fI\,{BuildStatusEnum.Unknown,BuildStatusEnum.Pending,BuildStatusEnum.Building,BuildStatusEnum.Failed,BuildStatusEnum.Success}\/\fR, \fB\-\-status\fR \fI\,{BuildStatusEnum.Unknown,BuildStatusEnum.Pending,BuildStatusEnum.Building,BuildStatusEnum.Failed,BuildStatusEnum.Success}\/\fR new status +.SH COMMAND \fI\,'ahriman repo-sync'\/\fR +usage: ahriman repo-sync [-h] + +sync repository files to remote server according to current settings + .SH COMMAND \fI\,'ahriman repo-triggers'\/\fR -usage: ahriman repo-triggers [-h] +usage: ahriman repo-triggers [-h] [trigger ...] run triggers on empty build result as configured by settings +.TP +\fBtrigger\fR +instead of running all triggers as set by configuration, just process specified ones oin order of metion + .SH COMMAND \fI\,'ahriman repo-update'\/\fR usage: ahriman repo-update [-h] [--dry-run] [-e] [--no-aur] [--no-local] [--no-manual] [--no-vcs] [package ...] @@ -525,7 +545,8 @@ do not include manual updates do not check VCS packages .SH COMMAND \fI\,'ahriman user-add'\/\fR -usage: ahriman user-add [-h] [--as-service] [-p PASSWORD] [-r {UserAccess.Safe,UserAccess.Read,UserAccess.Write}] [-s] +usage: ahriman user-add [-h] [--as-service] [-p PASSWORD] + [-r {UserAccess.Unauthorized,UserAccess.Read,UserAccess.Reporter,UserAccess.Full}] [-s] username update user for web services with the given password and role. In case if password was not entered it will be asked interactively @@ -545,7 +566,7 @@ user password. Blank password will be treated as empty password, which is in par authorization type. .TP -\fB\-r\fR \fI\,{UserAccess.Safe,UserAccess.Read,UserAccess.Write}\/\fR, \fB\-\-role\fR \fI\,{UserAccess.Safe,UserAccess.Read,UserAccess.Write}\/\fR +\fB\-r\fR \fI\,{UserAccess.Unauthorized,UserAccess.Read,UserAccess.Reporter,UserAccess.Full}\/\fR, \fB\-\-role\fR \fI\,{UserAccess.Unauthorized,UserAccess.Read,UserAccess.Reporter,UserAccess.Full}\/\fR user access level .TP @@ -553,7 +574,8 @@ user access level set file permissions to user\-only .SH COMMAND \fI\,'ahriman user-list'\/\fR -usage: ahriman user-list [-h] [-e] [-r {UserAccess.Safe,UserAccess.Read,UserAccess.Write}] [username] +usage: ahriman user-list [-h] [-e] [-r {UserAccess.Unauthorized,UserAccess.Read,UserAccess.Reporter,UserAccess.Full}] + [username] list users from the user mapping and their roles @@ -567,7 +589,7 @@ filter users by username return non\-zero exit status if result is empty .TP -\fB\-r\fR \fI\,{UserAccess.Safe,UserAccess.Read,UserAccess.Write}\/\fR, \fB\-\-role\fR \fI\,{UserAccess.Safe,UserAccess.Read,UserAccess.Write}\/\fR +\fB\-r\fR \fI\,{UserAccess.Unauthorized,UserAccess.Read,UserAccess.Reporter,UserAccess.Full}\/\fR, \fB\-\-role\fR \fI\,{UserAccess.Unauthorized,UserAccess.Read,UserAccess.Reporter,UserAccess.Full}\/\fR filter users by role .SH COMMAND \fI\,'ahriman user-remove'\/\fR diff --git a/docs/ahriman.core.database.migrations.rst b/docs/ahriman.core.database.migrations.rst index 2e3563a3..08dc66fb 100644 --- a/docs/ahriman.core.database.migrations.rst +++ b/docs/ahriman.core.database.migrations.rst @@ -20,6 +20,14 @@ ahriman.core.database.migrations.m001\_package\_source module :no-undoc-members: :show-inheritance: +ahriman.core.database.migrations.m002\_user\_access module +---------------------------------------------------------- + +.. automodule:: ahriman.core.database.migrations.m002_user_access + :members: + :no-undoc-members: + :show-inheritance: + Module contents --------------- diff --git a/docs/ahriman.web.views.status.rst b/docs/ahriman.web.views.status.rst index 334a9dd3..a5dcd410 100644 --- a/docs/ahriman.web.views.status.rst +++ b/docs/ahriman.web.views.status.rst @@ -4,14 +4,6 @@ ahriman.web.views.status package Submodules ---------- -ahriman.web.views.status.ahriman module ---------------------------------------- - -.. automodule:: ahriman.web.views.status.ahriman - :members: - :no-undoc-members: - :show-inheritance: - ahriman.web.views.status.package module --------------------------------------- diff --git a/docs/configuration.rst b/docs/configuration.rst index 1bce3fac..c7356f1b 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -41,7 +41,7 @@ Base authorization settings. ``OAuth`` provider requires ``aioauth-client`` libr * ``max_age`` - parameter which controls both cookie expiration and token expiration inside the service, integer, optional, default is 7 days. * ``oauth_provider`` - OAuth2 provider class name as is in ``aioauth-client`` (e.g. ``GoogleClient``, ``GithubClient`` etc), string, required in case if ``oauth`` is used. * ``oauth_scopes`` - scopes list for OAuth2 provider, which will allow retrieving user email (which is used for checking user permissions), e.g. ``https://www.googleapis.com/auth/userinfo.email`` for ``GoogleClient`` or ``user:email`` for ``GithubClient``, space separated list of strings, required in case if ``oauth`` is used. -* ``safe_build_status`` - allow requesting status page without authorization, boolean, required. +* ``allow_read_only`` - allow requesting status APIs without authorization, boolean, required. * ``salt`` - password hash salt, string, required in case if authorization enabled (automatically generated by ``create-user`` subcommand). Authorized users are stored inside internal database, if any of external provides are used the password field for non-service users must be empty. diff --git a/docs/triggers.rst b/docs/triggers.rst index 7cd8d0ae..c38cee3f 100644 --- a/docs/triggers.rst +++ b/docs/triggers.rst @@ -52,7 +52,7 @@ Obviously you can implement the specified method in class, but for guide purpose self.username = configuration.get("slack", "username") def run(self, result, packages): - notify(result, self.slack_url, channel, username) + notify(result, self.slack_url, self.channel, self.username) Setup the trigger ----------------- diff --git a/package/share/ahriman/settings/ahriman.ini b/package/share/ahriman/settings/ahriman.ini index f3a1ce71..ab3e3472 100644 --- a/package/share/ahriman/settings/ahriman.ini +++ b/package/share/ahriman/settings/ahriman.ini @@ -13,7 +13,7 @@ target = disabled max_age = 604800 oauth_provider = GoogleClient oauth_scopes = https://www.googleapis.com/auth/userinfo.email -safe_build_status = yes +allow_read_only = yes [build] archbuild_flags = @@ -37,7 +37,6 @@ target = console use_utf = yes [email] -full_template_path = /usr/share/ahriman/templates/repo-index.jinja2 no_empty_report = yes template_path = /usr/share/ahriman/templates/email-index.jinja2 ssl = disabled diff --git a/package/share/ahriman/templates/build-status.jinja2 b/package/share/ahriman/templates/build-status.jinja2 index bfbc582f..c1287ef4 100644 --- a/package/share/ahriman/templates/build-status.jinja2 +++ b/package/share/ahriman/templates/build-status.jinja2 @@ -14,28 +14,29 @@

ahriman - {% if auth.authenticated %} - {{ version }} - {{ repository }} - {{ architecture }} - {{ service.status }} - {% endif %} + unknown + unknown + unknown + unknown

{% if not auth.enabled or auth.username is not none %} - - - {% endif %} +
- - - - - - - + + + + + + + - - - {% if auth.authenticated %} - {% for package in packages %} - - - - - - - - - - - {% endfor %} - {% else %} - - - - {% endif %} -
package baseversionpackagesgroupslicenseslast updatestatuspackage baseversionpackagesgroupslicenseslast updatestatus
{% if package.web_url is not none %}{{ package.base }}{% else %}{{ package.base }}{% endif %}{{ package.version }}{{ package.packages|join("
"|safe) }}
{{ package.groups|join("
"|safe) }}
{{ package.licenses|join("
"|safe) }}
{{ package.timestamp }}{{ package.status }}
In order to see statuses you must login first.
@@ -122,11 +103,11 @@ {% include "build-status/login-modal.jinja2" %} {% endif %} - {% include "build-status/package-actions-modals.jinja2" %} + {% include "build-status/package-modals.jinja2" %} {% include "utils/bootstrap-scripts.jinja2" %} - {% include "build-status/package-actions-script.jinja2" %} + {% include "build-status/scripts.jinja2" %} diff --git a/package/share/ahriman/templates/build-status/package-actions-script.jinja2 b/package/share/ahriman/templates/build-status/package-actions-script.jinja2 deleted file mode 100644 index 80c26d48..00000000 --- a/package/share/ahriman/templates/build-status/package-actions-script.jinja2 +++ /dev/null @@ -1,95 +0,0 @@ - \ No newline at end of file diff --git a/package/share/ahriman/templates/build-status/package-actions-modals.jinja2 b/package/share/ahriman/templates/build-status/package-modals.jinja2 similarity index 81% rename from package/share/ahriman/templates/build-status/package-actions-modals.jinja2 rename to package/share/ahriman/templates/build-status/package-modals.jinja2 index 4295184a..91a8880e 100644 --- a/package/share/ahriman/templates/build-status/package-actions-modals.jinja2 +++ b/package/share/ahriman/templates/build-status/package-modals.jinja2 @@ -1,4 +1,4 @@ -