[Gruppo-web] [Git][ubuntu-it-web/www][develop] 6 commits: added z-index in cookie-policy
Mattia Rizzolo
gitlab a code.ubuntu-it.org
Lun 9 Ott 2023 22:53:58 BST
Mattia Rizzolo pushed to branch develop at Gruppo Web / Nuovo sito
Commits:
3c49c6de by Mattia at 2023-10-09T23:25:47+02:00
added z-index in cookie-policy
Fixes: https://code.ubuntu-it.org/ubuntu-it-web/www/-/issues/9
- - - - -
6e2b0fbc by Mattia at 2023-10-09T23:25:48+02:00
added constants with UITWWW_DIR and BASE_DIR
- - - - -
1c686d6e by Mattia at 2023-10-09T23:27:24+02:00
set version 22.04.3
Fixes: https://code.ubuntu-it.org/ubuntu-it-web/www/-/issues/12
- - - - -
66623a20 by Mattia at 2023-10-09T23:27:25+02:00
fixed build_scss() to compile static 'website.css'
- - - - -
927cf450 by Mattia at 2023-10-09T23:35:21+02:00
rm src_directory and replaced with UITWWW_DIR
quick code cleanup
- - - - -
cc762496 by Mattia at 2023-10-09T23:35:22+02:00
replaced pkg_resources with os.path with quick code clenaup
Fixes: https://code.ubuntu-it.org/ubuntu-it-web/www/-/issues/13
- - - - -
10 changed files:
- assets/scss/www.scss
- uitwww/auth.py
- + uitwww/constants.py
- uitwww/data/downloads.toml
- uitwww/db.py
- uitwww/download.py
- uitwww/main.py
- uitwww/navbar.py
- uitwww/pages.py
- uitwww/redirects.py
Changes:
=====================================
assets/scss/www.scss
=====================================
@@ -170,3 +170,7 @@ div.page div.row div.col.image-attach-corner {
}
}
}
+
+div.cookie-policy {
+ z-index: 10;
+}
=====================================
uitwww/auth.py
=====================================
@@ -14,18 +14,16 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import functools
+import time
import uuid
-
+import yaml
import flask
+import functools
import flask_openid
-import pkg_resources
-import time
-import yaml
+from .constants import UITWWW_DIR
from uitwww.third_party import openid_teams
-
SESSION_EXPIRES_AFTER = 86400
@@ -148,8 +146,8 @@ class Sessions:
class Permissions:
def __init__(self):
- raw = pkg_resources.resource_string("uitwww", "data/permissions.yml")
- self.config = yaml.safe_load(raw.decode("utf-8"))
+ with open(UITWWW_DIR + "/data/permissions.yml") as fn:
+ self.config = yaml.safe_load(fn.read())
def allowed_teams(self):
"""Return a list of teams allowed to log in"""
@@ -177,6 +175,7 @@ class Permissions:
def permission(perms):
"""Process the endpoint only if the user has permission"""
+
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
@@ -200,6 +199,7 @@ def permission(perms):
return flask.abort(403)
return wrapper
+
return decorator
@@ -277,7 +277,6 @@ def prepare_blueprint(app):
flask.flash("La sessione è stata terminata correttamente.", "success")
return flask.redirect(flask.url_for("pages.index"))
-
@bp.route("/sessions")
@permission("auth.sessions.manage")
def sessions_list():
=====================================
uitwww/constants.py
=====================================
@@ -0,0 +1,4 @@
+import os
+
+UITWWW_DIR = os.path.dirname(os.path.abspath(__file__))
+BASE_DIR = os.path.join(UITWWW_DIR, "..")
=====================================
uitwww/data/downloads.toml
=====================================
@@ -8,8 +8,8 @@ codename = "impish"
lts = false
[releases.lts]
-version = "20.04.3"
-codename = "focal"
+version = "22.04.3"
+codename = "jammy"
lts = true
=====================================
uitwww/db.py
=====================================
@@ -17,9 +17,6 @@
import threading
import sqlite3
-import pkg_resources
-
-
_LOCAL = threading.local()
=====================================
uitwww/download.py
=====================================
@@ -22,15 +22,14 @@ import random
import collections
import flask
-import itsdangerous
import requests
-import pkg_resources
+import itsdangerous
from . import cache
from . import launchpad
+from .constants import UITWWW_DIR
-
-CONFIG_FILE = "data/downloads.toml"
+CONFIG_FILE = "/data/downloads.toml"
CACHE_FILE = "download-cache.json"
CACHE_FILE_VERSION = 1
@@ -39,16 +38,16 @@ class Downloads:
def __init__(self, data_path):
# Load the configuration
- raw = pkg_resources.resource_string("uitwww", CONFIG_FILE)
- self.config = toml.loads(
- raw.decode("utf-8"),
- _dict=collections.OrderedDict,
+ path = UITWWW_DIR + CONFIG_FILE
+ self.config = toml.load(
+ path, _dict=collections.OrderedDict,
)
self._strip_non_lts_releases()
# Save the hash of the configuration
- self._config_hash = "sha1=%s" % hashlib.sha1(raw).hexdigest()
+ with open(path, "rb") as raw:
+ self._config_hash = "sha1=%s" % hashlib.sha1(raw.read()).hexdigest()
self._cache_file = os.path.join(data_path, CACHE_FILE)
@@ -69,7 +68,7 @@ class Downloads:
self._mirrors = {}
for distro in self.config["mirrors"]["for"]:
found_mirrors = list(sorted(launchpad.get_cdimage_mirrors(
- distro, self.config["mirrors"]["country"]
+ distro, self.config["mirrors"]["country"]
)))
if found_mirrors:
self._mirrors[distro] = found_mirrors
=====================================
uitwww/main.py
=====================================
@@ -15,13 +15,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
-import sys
import click
-import subprocess
-
import uitwww
-from uitwww import utils
+
+from .constants import UITWWW_DIR, BASE_DIR
+from .utils import ReverseProxied, GunicornInstance
+from scss.compiler import compile_file
@click.group()
@@ -33,18 +33,15 @@ def cli():
@cli.command("run")
@click.argument("data")
@click.option("-g", "--gunicorn-config", default=None, help="Path to a"
- "gunicorn config file")
+ "gunicorn config file")
@click.option("-p", "--port", default=8000, help="Bind that port")
@click.option("--public", help="Make available to the public", is_flag=True)
@click.option("-w", "--workers", help="Number of workers to start", default=3)
@click.option("-d", "--debug", help="Enable debug mode", is_flag=True)
def run(data, gunicorn_config, port, public, workers, debug):
"""Run the application"""
- # Create the application instance
- src_directory = os.path.dirname(os.path.abspath(__file__))
-
app = uitwww.create_app(data)
- app.wsgi_app = utils.ReverseProxied(app.wsgi_app)
+ app.wsgi_app = ReverseProxied(app.wsgi_app)
host = "127.0.0.1"
if public:
@@ -53,22 +50,22 @@ def run(data, gunicorn_config, port, public, workers, debug):
# In debug mode, run the flask builtin webserver
if debug:
extra_files = [
- os.path.join(src_directory, "data/navbar.yml"),
- os.path.join(src_directory, "data/permissions.yml"),
- os.path.join(src_directory, "data/redirects.yml"),
- os.path.join(src_directory, "data/downloads.toml"),
+ os.path.join(UITWWW_DIR, "data/navbar.yml"),
+ os.path.join(UITWWW_DIR, "data/permissions.yml"),
+ os.path.join(UITWWW_DIR, "data/redirects.yml"),
+ os.path.join(UITWWW_DIR, "data/downloads.toml"),
]
app.run(debug=True, port=port, host=host, extra_files=extra_files)
# Else run the application with gunicorn
else:
options = {
- "bind": host+":"+str(port),
+ "bind": host + ":" + str(port),
"workers": workers,
"accesslog": "-",
"errorlog": "-",
}
- server = utils.GunicornInstance(gunicorn_config, options)
+ server = GunicornInstance(gunicorn_config, options)
server.app = app
try:
@@ -88,16 +85,8 @@ def init(data):
@cli.command("build_scss")
def build_scss():
- """Build the scss file"""
- base_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
- scss_file = open('%s/assets/scss/www.scss' % base_dir, 'rb')
- css_file = open('%s/uitwww/static/website.css' % base_dir, 'wb')
- subprocess.run(
- [sys.executable, '-mscss'],
- stdin=scss_file,
- stdout=css_file,
- check=True,
- )
- css_file.flush()
- scss_file.close()
- css_file.close()
+ """Compile the scss file"""
+ print("Compile the scss file")
+ path = f"{BASE_DIR}/assets/scss/www.scss"
+ with open(f"{BASE_DIR}/uitwww/static/website.css", "w") as fn:
+ fn.write(compile_file(path))
=====================================
uitwww/navbar.py
=====================================
@@ -14,10 +14,10 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import flask
-import json
-import pkg_resources
import yaml
+import flask
+
+from .constants import UITWWW_DIR
class Navbar:
@@ -55,8 +55,8 @@ class Navbar:
def install(self, app):
"""Install this navbar on the app"""
- raw = pkg_resources.resource_string("uitwww", "data/navbar.yml")
- config = yaml.safe_load(raw.decode("utf-8"))
+ with open(UITWWW_DIR + "/data/navbar.yml") as fn:
+ config = yaml.safe_load(fn.read())
self._prepare_navbar_cache(config, [])
# Add the _navbars variable to the templates
=====================================
uitwww/pages.py
=====================================
@@ -15,10 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
-import json
-
import flask
-import pkg_resources
from uitwww import cache
=====================================
uitwww/redirects.py
=====================================
@@ -14,16 +14,17 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import flask
-import pkg_resources
import yaml
+import flask
import hashlib
+from .constants import UITWWW_DIR
+
def prepare_blueprint(app):
"""Prepare a blueprint containing all the redirects"""
- raw = pkg_resources.resource_string("uitwww", "data/redirects.yml")
- config = yaml.safe_load(raw.decode("utf-8"))
+ with open(UITWWW_DIR + "/data/redirects.yml") as fn:
+ config = yaml.safe_load(fn.read())
bp = flask.Blueprint("redirects", __name__)
View it on GitLab: http://code.ubuntu-it.org/ubuntu-it-web/www/-/compare/cbc2b98d7efbc7195390983914e030cc54357453...cc762496464316ce8f3cd1cce18965b3afb25b63
--
View it on GitLab: http://code.ubuntu-it.org/ubuntu-it-web/www/-/compare/cbc2b98d7efbc7195390983914e030cc54357453...cc762496464316ce8f3cd1cce18965b3afb25b63
You're receiving this email because of your account on code.ubuntu-it.org..
-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://liste.ubuntu-it.org/pipermail/gruppo-web/attachments/20231009/2da3e84b/attachment-0001.htm>
Maggiori informazioni sulla lista
Gruppo-web