Coder Social home page Coder Social logo

qgis / qgis-feed Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elpaso/qgis-feed

2.0 3.0 7.0 7.36 MB

QGIS Welcome Page News Feed Backend

Shell 0.69% Python 29.53% Dockerfile 0.53% JavaScript 48.42% HTML 15.98% SCSS 2.36% PLpgSQL 0.50% Makefile 1.98%

qgis-feed's Introduction

CircleCI

QGIS Home Page News Feed

This application is the backend part that manages and serves news for the QGIS welcome page.

Installation Guide

Development Environment Installation

For development purposes only, you can run this application in debug mode with docker compose. Some of the docker compose commands are already configured in the Makefile.

  • Build the docker the container
$ make dev-build
  • Create settings_local.py int the qgisfeedproject directory, configure the email sender variables and DB configuration as in the example below:
# The db service in the docker-compose is used by default
# You can specify the databse with the configuration below
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'qgisfeed',
        'USER': 'your_username',
        'PASSWORD': 'your_password',
        'HOST': 'localhost',
        'PORT': '5432'
    }
}
  • Generate the .env from env.template and edit it with your email variables:
cp env.template .env
nano .env

See https://docs.djangoproject.com/en/2.2/topics/email/#module-django.core.mail for further email configuration.

  • To prevent DDOS attacks there is limit in the number of returned records (defaults to 20): it can be configured by overriding the settings in settings_local.py with:
QGISFEED_MAX_RECORDS=40  # default value is 20
  • Start the docker the container
$ make dev-start
  • Run migrations:
$ make dev-migrate
  • Create an admin user and set a password:
$ make dev-createsuperuser
  • Show the development server logs:
$ make dev-logs

A set of test data will be automatically loaded and the application will be available at http://localhost:8000

To enter the control panel http://localhost:8000/admin, two test users are available:

  • Super Admin: the credentials are admin/admin
  • Staff (News Entry Author): the credentials are staff/staff
Production Environment Installation
For production, you can run this application with make commands or docker compose:

Docker configuration should be present in .env file in the main directory, an example is provided in env.template:

# This file can be used as a template for .env
# The values in this file are also the default values.

# Host machine persistent storage directory, this path
# must be an existent directory with r/w permissions for
# the users from the Docker containers.
QGISFEED_DOCKER_SHARED_VOLUME=/shared-volume

# Number of Gunicorn workers (usually: number of cores * 2 + 1)
QGISFEED_GUNICORN_WORKERS=4

# Database name
QGISFEED_DOCKER_DBNAME=qgisfeed
# Database user
QGISFEED_DOCKER_DBUSER=docker
# Database password
QGISFEED_DOCKER_DBPASSWORD=docker
$ make start

A set of test data will be automatically loaded and the application will be available at http://localhost:80

To enter the control panel http://localhost:80/admin, two test users are available:

  • Super Admin: the credentials are admin/admin
  • Staff (News Entry Author): the credentials are staff/staff

Enable SSL Certificate on production using Docker

  1. Generate key using openssl in dhparam directory
openssl dhparam -out /home/web/qgis-feed/dhparam/dhparam-2048.pem 2048
  1. Run the container
$ make start
  1. Update config/nginx/qgisfeed.conf to include the new config file in config/nginx/ssl/qgisfeed.conf
include conf.d/ssl/*.conf;
  1. Restart nginx service
nginx -s reload
  1. To enable a cronjob to automatically renew ssl cert, add scripts/renew_ssl.sh to crontab file.

User guide

Home page

A home page that displays feeds as they are rendered in QGIS is now available at the root of the web server /. Feeds are filterable using the filter widget on the left side. You can directly pass the filter parameters in the url according to the section Available parameters for filters in Endpoint and accepted parameters

Note: When calling the root url from QGIS, the response data is in JSON format. See the section Response data for QGIS in the Endpoint and accepted parameters

Control panel and permissions

Users with staff flag can enter the control panel at /admin and add feed entries, by default entries are not published.

Users with superadmin flag will be notified by email when an entry is added to the feed and will be able to publish the entry.

Appart from superadmin, only users with the permission qgisfeed | Can publish QGIS feed can publish the entry. Like the group qgisfeedentry_authors, the group qgisfeedentry_approver with the permission qgisfeed | Can publish QGIS feed are created when a Save signal from the User model is detected.

For content field, a hard limit on the number of characters allowed is configurable in administration page (Character limit configurations). If not set, max characters value for this field is 500. If you want to add a custom max characters for this field, the field name value should be content.

Manage feeds page

Note: The permissions for this page are the same as described in the Control Panel and permissions.

After logging in with the login screen at /accounts/login/ (can be also accessed from the Login button on the Homepage), users are provided with tools to manage feed items:

  • A list of feed items, sortable and filterable by title, date published, author, language, need review
  • A button to create a new feed item - clicking will take you to a blank feed item form (See Feed item form below)
  • Clicking on an item on the list will take you to a feed item form (See Feed item form below)
Feed item form

The feed item form page is displayed when clicking the New feed item button or an item on the list:

  • The feed item form is displayed on the left with all the widgets needed to edit the entry. On the right, a preview of the entry as it will be rendered in QGIS. Any edits made in the form shall immediately update the preview.
  • In the content widget only the following html tags are allowed: p, strong, italics. A hard limit on the number of characters allowed is configurable in administration page in the model Character limit configurations.
  • Once a feed item is created or modified, there will be a review step where the user is asked to confirm that they have checked everything carefully.
  • The form is placed in the column Need review in the list before final submission.
  • The form must be approved by someone the permission qgisfeed | Can publish QGIS feed before it is published.
Endpoint and accepted parameters

Response data for QGIS

The application has a single endpoint available at the web server root / the reponse is in JSON format.

Example call: http://localhost:8000/

Returned data:

[
  {
    "pk": 1,
    "title": "QGIS acquired by ESRI",
    "image": "http://localhost:8000/media/feedimages/image.png",
    "content": "<p>QGIS is finally part of the ESRI ecosystem, it has been rebranded as CrashGIS to better integrate with ESRI products line.</p>",
    "url": "https://www.qgis.com",
    "sticky": true,
    "publish_from": 1557419128
  },
  {
    "pk": 2,
    "title": "Null Island QGIS Meeting",
    "image": "",
    "content": "<p>Let's dive in the ocean together!</p>",
    "url": null,
    "sticky": false,
    "publish_from": 1557419128
  },
  {
    "pk": 3,
    "title": "QGIS Italian Meeting",
    "image": "",
    "content": "<p>Ciao from Italy!</p>",
    "url": null,
    "sticky": false,
    "publish_from": 1557419128
  }
]

Available parameters for filters

The following parameters can be passed by the client to filter available records.

Parameters are validated and in case they are not valid a Bad Request HTTP error code 400 is returned.

after

When after is passed, only the records that have been published after the given value will be returned.

Accepted values: unix timestamp (UTC)

Example call: http://localhost:8000/?after=1557419013

lang

When lang is passed, the records that have a different lang will be excluded from the results. Only the records with null lang and the records with a matching lang will be returned.

Accepted values: ISO-939-1 two letters language code

Example call: http://localhost:8000/?lang=de

lat lon (location)

When lat and lon are passed, the records that have a location filter set will be returned only if the point defined by lat and lon is within record's location.

Accepted values: ESPG:4326 latitude and longitude

Example call: http://localhost:8000/?lat=44.5&lon=9.23

Runing tests

Run all tests

To run all tests cases in the qgisfeed app, from the main directory:

$ make dev-runtests
Run each test

To run each test case class in the qgisfeed app:

$ docker-compose -f docker-compose.dev.yml exec qgisfeed python qgisfeedproject/manage.py test qgisfeed.tests.QgisFeedEntryTestCase
$ docker-compose -f docker-compose.dev.yml exec qgisfeed python qgisfeedproject/manage.py test qgisfeed.tests.QgisUserVisitTestCase
$ docker-compose -f docker-compose.dev.yml exec qgisfeed python qgisfeedproject/manage.py test qgisfeed.tests.HomePageTestCase
$ docker-compose -f docker-compose.dev.yml exec qgisfeed python qgisfeedproject/manage.py test qgisfeed.tests.LoginTestCase
$ docker-compose -f docker-compose.dev.yml exec qgisfeed python qgisfeedproject/manage.py test qgisfeed.tests.FeedsItemFormTestCase
$ docker-compose -f docker-compose.dev.yml exec qgisfeed python qgisfeedproject/manage.py test qgisfeed.tests.FeedsListViewTestCase

Deployment

Email-sending setup
  • Generate the .env from env.template and edit it with the production email variables:
cp env.template .env
nano .env
Troubleshooting SSL in production

Sometimes it seems our cron does not refresh the certificate. We can fix like this:

Gentle Way

ssh feed.qgis.org
cd /home/web/qgis-feed
scripts/renew_ssl.sh

Now check if your browser is showing the site opening with no SSL errors: https://feed.qgis.org

More crude way

ssh feed.qgis.org
cd /home/web/qgis-feed
docker-compose -f docker-compose-production-ssl.yml up certbot
docker-compose -f docker-compose-production-ssl.yml restart nginx

Now check if your browser is showing the site opening with no SSL errors: https://feed.qgis.org

Backups

If something goes terribly wrong, we keep 7 nights of backups on hetzner

If those are also not useful there are a collection of snapshot backups on hetzner

Last resort: Tim makes backups to his local machine on a semi-regular basis.

Deploying on Rancher

This repository contains a rancher template directory (the template folder in the root of the repo) which can be used to deploy this site onto a host using Rancher. Currently ony Rancher v1.6 (i.e. not v2) is supported.

This guide serves as a quick setup guide to spin up a one of our Rancher catalogue packages.

Prerequisites

This guide assumes that the following steps have been done:

  1. Install Docker: Docker is installed on your server. Use Ubuntu 16.04 for the best results because that is what we are testing on. For quick installation, use the convenience scripts provided by Rancher (make sure you choose a supported version).

  2. Install Rancher: The stable version of Rancher v1 Server has been set up.

If it's not, refer to Rancher quickstart guide. Here is an example of how to run the latest stable release with a persistent mysql database stored on the file system:

mkdir /home/mysql
docker run -d -v /home/mysql:/var/lib/mysql --restart=unless-stopped -p 8080:8080 rancher/server:stable
  1. Create an environment: Once rancher server has been set up. Create an environment. You can create an Rancher environment <rancher url>/settings/env/add.

  2. Set up the Hetzner Machine Driver: This only applies if you are using Hetzner Cloud as your hosting provider. You can automatically manage and deploy hosts on Hetzner using the Admin -> Machine Drivers menu and then enable the Hetzner driver.

  3. Add a host: You need to add a host to the environment has been set up to actually run the instance (the agent could be on the same host as the rancher server but it is not recommended). You can do this by ensuring your chosen environment is active and then from the menu do Environment -> Hosts. If you running on hetzner cloud, choose the Hetzner machine driver and then enter the API key for your Hetzner Cloud project (you can get this key from the Hetzner Cloud admin ui). Alternatively manually set up a linux host with docker on it and then use the manual host setup as directed by the Infrastructure -> Hosts -> Add Host page in Rancher. The process is quite logical and simple and involves pasting a single line of code onto the host that will run the agent. Once the host is set up with a running agent, you should see it join the environment as shown below:

screen shot 2017-11-02 at 19 03 32

  1. ** Installing from the catalogue:** Once Rancher is installed, your environment and host are set up, use the Admin -> Settings menu to add our Rancher catalogue using this URL:

https://github.com/qgis/qgis-feed

Once your settings are saved open a Rancher environment and set up a stack from the catalogue's 'QGIS' section - you will see QGIS-Feed listed there.

Now you can add items from the QGIS catalogue to your stack.

qgis-feed's People

Contributors

borysiasty avatar dimasciput avatar elpaso avatar myarjunar avatar sumandari avatar timlinux avatar xpirix avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

qgis-feed's Issues

Improve feed item form: use rich editor

  • Implement a rich editor like mcedit or even a markdown editor to edit the content field
  • Only the following html tags should be allowed: p, strong, italic
  • Add classical wysiwyg buttons to add these tags
  • There should always be a 'raw' view that can be used to check for hidden characters like \r

Tests cases for login

  • Configure GitHub Actions and create tests cases for login page
  • Update the README on how to run tests

No CSS

image

I guess we are missing the collect static step in the deployed image?

image

Expose somewhere the xml feed adress in the QGIS feed admin backend

Last minor glitch,
in the previous app, it was easy to find the raw xml feed as it was server at the root of the website.
I failed to find it, which is useful for debugging the real output.
@Xpirix Could you add somewhere in the QGIS feed admin screen a link to the xml feed, maybe in the menu bar entry "XML feed" . I am not sure if the feed is RSS compliant, in this case the good old RSS logo could do the trick

Add a form for feed item

  • Create a page for the feed item form
  • On the left side: Show the form itself with all needed widget (Title, image, content, url, sticky entry, sorting order, language filter, spatial filter, publication start, publication end)
  • On the right side: Show a preview of the entry as it will be rendered in QGIS. Any edits made in the form shall immediately update the preview.

Feed entry, set spatial filter windows is empty

@Xpirix
The spatial filter window is empty when I try to submit a new entry.

I am using firefox 107, but chrome with a fesh profile behaves the same . I saw no error in the web developper console, with adblock / javascript blocker deactivated

image

Can't save a feed with different second time

It seems that the form doesn't accept when the second part is different. I didn't succeed in saving it from my phone. But I had this detail on my Firefox desktop and was able to save it with 09/09/2024, 12:00:14 as the end date

image

Improve feed item form: Check data validity

  • If a link is set, the link should be checked for validity
  • There should be a hard limit on the number of characters allowed this should be configurable in admin. A starting default or 500 characters would be good I think

Installation docs are incomplete/buggy

Following instructions in https://github.com/qgis/qgis-feed/blob/master/README.md

  1. the local_settings.py must be located in qgisfeedproject directory

  2. after python manage.py runserver:

<h1>GeoIP2Exception
       at /</h1>
  <pre class="exception_value">GeoIP path must be a valid file or directory.</pre>
  

Request Method: | GET
-- | --
http://localhost:8000/
4.2.7
GeoIP2Exception
GeoIP path must be a valid file or directory.
/home/xxx/.virtualenvs/qgisfeedvenv/lib/python3.10/site-packages/django/contrib/gis/geoip2/base.py, line 118, in __init__
qgisfeed.views.QgisEntriesView
/home/ale/.virtualenvs/qgisfeedvenv/bin/python
3.10.12
['/home/xxx/public_html/django/qgis-feed/qgisfeedproject',  '/usr/lib/python310.zip',  '/usr/lib/python3.10',  '/usr/lib/python3.10/lib-dynload',  '/home/xxx/.virtualenvs/qgisfeedvenv/lib/python3.10/site-packages']
Mon, 13 Nov 2023 08:06:41 +0000

Also send modified items to the client

The client sends a request qith after=<unix timestamp> to get the recent entries, we need to make sure to send also entries which have been modified since the after timestamp, this will make it possible to edit published entries already cached on the client (some work is required client side to make this work) or to unpublish them immediately by setting the expiry date in the past.

Add telemetry logic

Tim : Basically we would like to know by country break down of number of check-ins per day by QGIS version and by OS

Improve security for each server

From @timlinux :

another ticket to work through each server and we set up the hetzner firewall rules

and also to set up tailscale and put ssh behind the vpn so the servers are not directly accessible via ssh

And add the notes for those to your server configuration docs

inconsistent numbers in analytics.qgis.org dashboard

Hi @Xpirix ,
I'm not sure where to create this issue, feel free to move it.

Looking at our analytics dashboard for a qgis conference last week, I found inconsistent - or mis-titled - graphics.

our monthly total opening is (today ) ~ 15 millions openings.

The map by country shows - only for France - 28 Millions in the last 30 days.

Tim gave me access to metabase's backoffice, but I struggle to understand the link between existing graphics and SQL database. I didn't find either by which process the database is filled.

Could you check this ? Or give me some hints to be able to debug the dashboard with you ?

Create a page that list feeds

  • Create a page that contains the list of feed items.
  • This list will be sortable and filterable by date published, author, language
  • This page will show only if the user is logged in.
  • Add tests cases for this page

Add nightly db dump to docker-compose

From @timlinux :

I'm looking at the docker compose and there is no nightly db dump being made.
Can you copy the pattern over from plugins to get nightly backups done
Ideally lets get an external data volume attavhed to that server and drop the dumps in there so we dont fill up the primary disk

Form submission management

  • The form must first be placed in a holding area before final submission. (Published=False)
  • The new feed proposal in the feed area should raise a mail to the admin users with privileges on the django group qgisfeedentry_authors.
  • Create a new permission qgisfeed | Can publish QGIS feed entry so that we can enforce a review workflow
  • The form must be approved by someone with that permission before it is published (Published=True)
  • Add or update tests cases if needed

Clarify who are the reviewers for a feed submission

As a feed editor and reviewer for others, I didn't get any notification when a feed entry was submitted.

As a feed editor, I expect to be able to pick one or several of the django project members with feed edition privileges and that they get a notification.
This notification should provide a direct link to the feed entry and a message like
"
Title : QGIS feed entry review requested
body:
Hi,
%submittinguser% asked you to review the feed entry available at

https://feed.qgis.org/manage/ %feed entry url link%

Your beloved QGIS Feed bot "

Remove lat lon filters

image

They dont make sense to have like this. In future we could have a map and draw a bbox maybe, but for now just remove.

We need a beautiful form for creating new feed entries.

๐Ÿ“’ Note: This is an EPIC ticket - it must be broken out into small individual tasks, each no more than 1 day of work

Background

At the moment we create new feed entries like this:

image

And they come out in the feed like this:

image

The process of authoring the entry is quite tricky and error prone. And worse, errors, once published, cannot be corrected since the user's QGIS session caches the entries locally.

To address this we would like to develop a front end (non django admin based) view for authoring content with the following capabilities and considerations:

Workflow

User has a nice login screen if they visit https://feed.qgis.org/manage

We cannot use the root URL because that is where the feed is published.

After logging in with a beautiful login screen branded with out new QGIS branding, they are provided with tools to manage feed items.

  • A list of feed items, sortable and filterable by date published, author, language
  • A button to create a new feed item - clicking will take you to a blank feed item form
  • Clicking on an item on the list will take you to a feed item form
  • The feed item form shall display on the left, all the widgets needed to edit the entry, and on the right, a preview of the entry as it will be rendered in QGIS. Any edits made in the form shall immediately update the preview.
  • Once a feed item is created or modified, there will be a review step where the user is asked to confirm that they have checked everything carefully
  • The form shall implement such checks as needed to ensure the feed item does not cause issues when rendered in QGIS. This shall include
    • Only the following html tags should be allowed; p, strong, italics. These tags should be editable using a rich editor like mcedit, but there should always be a 'raw' view that can be used to check for hidden characters like \r
    • If a link is set, the link should be checked for validity
    • There should be a hard limit on the number of characters allowed this should be configurable in admin. A starting default or 500 characters would be good I think
    • The form must first be placed in a holding area before final submission
    • The form must be approved by someone with an 'approver' role before it is published

Caution

This feed site is very high traffic and no changes can reduce its stability. Any changes must be covered in tests and demonstrated to be robust.

CC @Xpirix

Bad Request on feed.qgis.org

On my machine I see the following in the lof file Messages:

News feed request failed [error: Error transferring https://feed.qgis.org/?after=1619783203&lang=en_US - server replied: Bad Request]

https://feed.qgis.org/?after=1619783203&lang=en_US

Screenshot-20210515121646-1058x303

Not sure why lang = en_US, but I start QGIS on an english Debian without any language parameter.
Maybe QGIS picks the wrong language param?
So maybe it is a QGIS issue? Created one there too: qgis/QGIS#43232

Error handling when editing and submitting new feed entry

Hi @Xpirix
I tested the new feed on friday to advertise a French QGIS event, and it is a wonderfull work. Kudos.

We noticed some minor glitches, here is the first one.

When editing one entry, an invalid entry is not easy to detect, and it is always possible to submit the form without any error message nor successful writing in the database.
The preview form doesn't show any error, and we have to validate the entry to see some tiny orange warning about invalid forms

image

I suggest the warnings blocking editing are a bit bigger and red.
Ideally, they should appear dynamically when editing with client side logic.
expected this since I was looking at the "XXX words POWERED BY TINY" message, and thought this is where the error message would pop up.

If dynamic client side logic is too hard to implement, showing the warnings and errors could be done in the preview window.

Thanks !

We need to remove the mcedit rich control

See http://osgeo-org.1560.x6.nabble.com/Replace-news-feed-content-editor-with-html-view-td5438293.html

I'd like to raise the notion of replacing the existing rich text
editor on the news feed admin page with a simple plain text box which
accepts raw HTML input.

We've had issues in the past with formatted code being pasted in news
entries which breaks the display/layout of the item on the QGIS
client. And now we have an odd situation with the "A message from
Marco Bernasocchi" news item, where it has a huge blank gap forced
below the news item in QGIS.

This is being caused by this odd HTML block which appears in the item
content, which I cannot find anyway to remove from the rich text
editor:

<span id="docs-internal-guid-cb126a5f-7fff-3d55-2517-e7c137c58311"
style="font-size: 11pt; font-family: Arial; color: #000000;
background-color: transparent; font-weight: 400; font-style: normal;
font-variant: normal; text-decoration: none; vertical-align: baseline;
white-space: pre-wrap;">

Could we remove the rich text editor and replace it with a raw html
entry box, so that news submitters will immediately see if their HTML
content is messy and to make it easier to remove unwanted tags/content
from the items?

CC @nyalldawson

Add a review step

Once a feed item is created or modified, there will be a review step where the user is asked to confirm that they have checked everything carefully.

  • In this page, user will only see the preview of the entry as it will be rendered in QGIS. Then, the user must be able to go back on the editing form or continue the process.
  • A confirmation step will show if no filter and spatial filter has been set

Need to document docker image autobuilding

To set up autobuilds used in the production server:

Go to http://hub.docker.com

Screenshot 2019-09-03 at 10 05 30

Then:

image

You should see the status panel like this:

image

In the Hub repo now go and configure it so that updates to the base image trigger a new build:

image

Also make sure you have set up the tags and pointed to the correct dockerfile.

image

image

The build tags should point to :

  • Dockerfile.production
  • Dockerfile.testing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.