#65 Sphinx Documentation
Merged 5 years ago by jonatoni. Opened 5 years ago by echoduck.
fedora-commops/ echoduck/fedora-happiness-packets sphinx  into  master

file added
+19
@@ -0,0 +1,19 @@ 

+ # Minimal makefile for Sphinx documentation

+ #

+ 

+ # You can set these variables from the command line.

+ SPHINXOPTS    =

+ SPHINXBUILD   = sphinx-build

+ SOURCEDIR     = source

+ BUILDDIR      = build

+ 

+ # Put it first so that "make" without argument is like "make help".

+ help:

+ 	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

+ 

+ .PHONY: help Makefile

+ 

+ # Catch-all target: route all unknown targets to Sphinx using the new

+ # "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).

+ %: Makefile

+ 	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 

\ No newline at end of file

file added
+177
@@ -0,0 +1,177 @@ 

+ # -*- coding: utf-8 -*-

+ #

+ # Configuration file for the Sphinx documentation builder.

+ #

+ # This file does only contain a selection of the most common options. For a

+ # full list see the documentation:

+ # http://www.sphinx-doc.org/en/master/config

+ 

+ # -- Path setup --------------------------------------------------------------

+ 

+ # If extensions (or modules to document with autodoc) are in another directory,

+ # add these directories to sys.path here. If the directory is relative to the

+ # documentation root, use os.path.abspath to make it absolute, like shown here.

+ #

+ # import os

+ # import sys

+ # sys.path.insert(0, os.path.abspath('.'))

+ 

+ 

+ # -- Project information -----------------------------------------------------

+ 

+ project = u'Fedora Happiness Packets'

+ copyright = u'2018, Fedora Project'

+ author = u'Fedora Project'

+ 

+ # The short X.Y version

+ version = u''

+ # The full version, including alpha/beta/rc tags

+ release = u'2018'

+ 

+ 

+ # -- General configuration ---------------------------------------------------

+ 

+ # If your documentation needs a minimal Sphinx version, state it here.

+ #

+ # needs_sphinx = '1.0'

+ 

+ # Add any Sphinx extension module names here, as strings. They can be

+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom

+ # ones.

+ extensions = [

+     'sphinx.ext.autodoc',

+ ]

+ 

+ # Add any paths that contain templates here, relative to this directory.

+ templates_path = ['_templates']

+ 

+ # The suffix(es) of source filenames.

+ # You can specify multiple suffix as a list of string:

+ #

+ # source_suffix = ['.rst', '.md']

+ source_suffix = '.rst'

+ 

+ # The master toctree document.

+ master_doc = 'index'

+ 

+ # The language for content autogenerated by Sphinx. Refer to documentation

+ # for a list of supported languages.

+ #

+ # This is also used if you do content translation via gettext catalogs.

+ # Usually you set "language" from the command line for these cases.

+ language = None

+ 

+ # List of patterns, relative to source directory, that match files and

+ # directories to ignore when looking for source files.

+ # This pattern also affects html_static_path and html_extra_path.

+ exclude_patterns = []

+ 

+ # The name of the Pygments (syntax highlighting) style to use.

+ pygments_style = None

+ 

+ 

+ # -- Options for HTML output -------------------------------------------------

+ 

+ # The theme to use for HTML and HTML Help pages.  See the documentation for

+ # a list of builtin themes.

+ #

+ html_theme = 'alabaster'

+ 

+ # Theme options are theme-specific and customize the look and feel of a theme

+ # further.  For a list of options available for each theme, see the

+ # documentation.

+ #

+ # html_theme_options = {}

+ 

+ # Add any paths that contain custom static files (such as style sheets) here,

+ # relative to this directory. They are copied after the builtin static files,

+ # so a file named "default.css" will overwrite the builtin "default.css".

+ html_static_path = ['_static']

+ 

+ # Custom sidebar templates, must be a dictionary that maps document names

+ # to template names.

+ #

+ # The default sidebars (for documents that don't match any pattern) are

+ # defined by theme itself.  Builtin themes are using these templates by

+ # default: ``['localtoc.html', 'relations.html', 'sourcelink.html',

+ # 'searchbox.html']``.

+ #

+ # html_sidebars = {}

+ 

+ 

+ # -- Options for HTMLHelp output ---------------------------------------------

+ 

+ # Output file base name for HTML help builder.

+ htmlhelp_basename = 'FedoraHappinessPacketsdoc'

+ 

+ 

+ # -- Options for LaTeX output ------------------------------------------------

+ 

+ latex_elements = {

+     # The paper size ('letterpaper' or 'a4paper').

+     #

+     # 'papersize': 'letterpaper',

+ 

+     # The font size ('10pt', '11pt' or '12pt').

+     #

+     # 'pointsize': '10pt',

+ 

+     # Additional stuff for the LaTeX preamble.

+     #

+     # 'preamble': '',

+ 

+     # Latex figure (float) alignment

+     #

+     # 'figure_align': 'htbp',

+ }

+ 

+ # Grouping the document tree into LaTeX files. List of tuples

+ # (source start file, target name, title,

+ #  author, documentclass [howto, manual, or own class]).

+ latex_documents = [

+     (master_doc, 'FedoraHappinessPackets.tex', u'Fedora Happiness Packets Documentation',

+      u'Anna Philips, Fedora Project, and others', 'manual'),

+ ]

+ 

+ 

+ # -- Options for manual page output ------------------------------------------

+ 

+ # One entry per manual page. List of tuples

+ # (source start file, name, description, authors, manual section).

+ man_pages = [

+     (master_doc, 'fedorahappinesspackets', u'Fedora Happiness Packets Documentation',

+      [author], 1)

+ ]

+ 

+ 

+ # -- Options for Texinfo output ----------------------------------------------

+ 

+ # Grouping the document tree into Texinfo files. List of tuples

+ # (source start file, target name, title, author,

+ #  dir menu entry, description, category)

+ texinfo_documents = [

+     (master_doc, 'FedoraHappinessPackets', u'Fedora Happiness Packets Documentation',

+      author, 'FedoraHappinessPackets', 'One line description of project.',

+      'Miscellaneous'),

+ ]

+ 

+ 

+ # -- Options for Epub output -------------------------------------------------

+ 

+ # Bibliographic Dublin Core info.

+ epub_title = project

+ 

+ # The unique identifier of the text. This can be a ISBN number

+ # or the project homepage.

+ #

+ # epub_identifier = ''

+ 

+ # A unique identification for the text.

+ #

+ # epub_uid = ''

+ 

+ # A list of files that should not be packed into the epub file.

+ epub_exclude_files = ['search.html']

+ 

+ 

+ # -- Extension configuration -------------------------------------------------

@@ -0,0 +1,16 @@ 

+ .. Fedora Happiness Packets documentation master file, created by

+    sphinx-quickstart on Sun Dec  2 16:18:13 2018.

+    You can adapt this file completely to your liking, but it should at least

+    contain the root `toctree` directive.

+ 

+ Welcome to Fedora Happiness Packets's documentation!

+ ====================================================

+ 

+ .. toctree::

+    :maxdepth: 2

+ 

+    setup/development

+    setup/authentication

+ 

+    model

+ 

@@ -0,0 +1,40 @@ 

+ ======

+ Model

+ ======

+ 

+ Data Fields

+ ===========

+ 

+ - ``status``: Indicates the status of the message:

+     * 'pending_sender_confirmation': The sender has yet to click on the confirmation email.

+     * 'sent': The sender has confirmed the email, and it has been sent to the recipient.

+     * 'read': The recipient has read the email.

+ - ``sender_name``: Name of the sender of the packet.

+ - ``sender_email``: Email address of sender.

+ - ``sender_email_stripped``: Email address of sender without aliases, to prevent circumvention of the blacklist.

+ - ``sender_email_token``: Prevents CSRF by ensuring the link has been accessed from the email.

+ - ``sender_ip``: IP address of sender: rate-limiting takes place in order to prevent resource abuse.

+ - ``recipient_email``: Name of the recipient of the packet.

+ - ``recipient_email``: Email address of recipient.

+ - ``recipient_email_stripped``: Email address of recipient without aliases, to prevent circumvention of the blacklist.

+ - ``recipient_email_token``: Prevents CSRF by ensuring the link has been accessed from the email.

+ - ``message``: The text content of the message.

+ - ``sender_named``: Boolean indicating whether the sender wishes to reveal their identity to the packet recipient. If false, the recipient receives an anonymous packet.

+ - ``sender_approved_public``: Boolean indicating whether the sender wishes to make the contents of the packet public. (Both the sender and the recipient must approve making the packet public in order for it to be made available publically).

+ - ``sender_approved_public_named``: Boolean indicating whether the sender wishes to make their identity as the packet sender public.

+ - ``recipient_approved_public``: Boolean indicating whether the packet recipient wishes to make its contents public.

+ - ``recipient_approved_public_named``: Boolean indicating whether the recipient wishes to make their identity as the packet recipient public.

+ - ``admin_approved_public``: Boolean field indicating whether this message is allowed to be publically shared.

+ 

+ 

+ Model Functions

+ ===============

+ 

+ - ``save()``: Strips sender and recipient emails, generates a message ID< and saves the message in the database.

+ - ``send_sender_confirmation()``: Sends a confirmation email to the sender of the packet.

+ - ``send_to_recipient()``: Sends the packet to the recipient.

+ 

+ Helper Functions

+ ================

+ 

+ - ``strip_email()``: Removes email aliases and all non-alphanumeric characters, with the exception of the @ symbol.

@@ -0,0 +1,22 @@ 

+ ==============

+ Authentication

+ ==============

+ 

+ The Fedora Happiness Packets project uses Open ID Connect in order to access the Fedora Account System in order to retrieve the user's email and name.

+ This means that in order for packet sending functionality to work, the server that this project is running on must have a client ID and secret from the Fedora Infrastructure OIDC provider.

+ 

+ Development

+ ===========

+ 

+ In order to obtain a Client ID and Secret for a development server, simply run the ``generate_client_secrets.sh`` located at the project root. The script will not run if it finds a client_secrets.json file, preventing API abuse.

+ 

+ Alternatively, you may use the `oidc-register <https://github.com/puiterwijk/oidc-register>`_ tool to generate a client ID. However,the project expects to have a file as returned by the ``generate_client_secrets.sh`` script, so if you have any issues with ``oidc-register``, use the script.

+ 

+ 

+ Staging/Production

+ ==================

+ 

+ File a ticket with the Fedora Infrastructure team: https://pagure.io/fedora-infrastructure/issues

+ 

+ 

+ More information on the authentication structure can be found in the Fedora wiki: https://fedoraproject.org/wiki/Infrastructure/Authentication

@@ -0,0 +1,69 @@ 

+ =========================================

+  Setting up a development environment

+ =========================================

+ 

+ This guide assumes that you are using a Unix-like system e.g a (GNU/)Linux distribution or macOS.

+ 

+ Using Docker

+ ===============

+ 

+ The project comes with a Dockerfile that allows easy deployment of a web server.

+ 

+ 1. Install Docker and Docker Compose on your machine.

+ 2. Run the client secret generation script:: 

+ 

+     chmod +x generate_client_secrets.sh

+     ./generate_client_secrets.sh

+ 

+ Although the Dockerfile runs the script to check if a client_secrets.json file is present, please generate it before starting the Docker container, so that client secrets are not being constantly generated every time the image is rebuilt.

+ 

+ In order to run the web server, alongside the Redis queue and celery worker instance, simply run ``docker-compose up``.

+ 

+ If you have made any changes to the code, the Docker image must be rebuilt; this can be done my running ``docker-compose up --build``.

+ 

+ Since the code is being run in a container, we must enter the shell of the container in order to run tests.

+ Access the shell of the Docker container by running ``docker-compose exec web sh``.

+ 

+ The test suite can be run by running the ``t`` script, which runs the tests with the appropriate testing settings and provides a coverage report.

+ In order to run the script, simply type ``./t`` in the Docker container's shell.

+ 

+ Integration tests are run via the following command: ``./manage.py test -v 2 -p integration_test*.py --settings=happinesspackets.settings.tsting``

+ 

+ 

+ Alternatives to Docker

+ ======================

+ 

+ Should you be unable to run Docker, or prefer to not use it, there is an alternative way of setting up a development environment.

+ 

+ 0. (Optional) Use a virtual environment solution, like virtualenv or Pipenv, in order to prevent dependency conflicts with other projects.

+ 1. Install the development packages: ``pip install -r /requirements/dev.txt`` (Pipenv users can use pipenv install)

+ 2. Export the development settings module as an environment variable: ``export  DJANGO_SETTINGS_MODULE=happinesspackets.settings.dev``

+ 3. Generate the client_secrets.json file (This is needed in order for login functionality to work): ``./generate_client_secrets.sh``.

+    If you get a permission denied error, change the file to an executable: ``chmod +x generate_client_secrets.sh``

+ 4. Collect static resources: ``python manage.py collectstatic``

+ 5. Ensure the database is up to date by running all migrations: ``python manage.py migrate``

+ 

+ In order to ensure the server is fully functional, Redis and Celery must both be configured.

+ 

+ Redis

+ ------

+ 

+ 1. Install redis from your package manager, or follow the instructions on the Redis website.

+ 2. Ensure that the redis server has been started: ``redis-server``

+ 

+ Celery

+ _______

+ 

+ 1. Start the celery worker in the background, or in a separate terminal window: ``celery -A happinesspackets worker -l info``

+ 

+ 

+ The tests can be run directly from the project folder as described in the Using Docker section, without having to run ``docker-compose exec web sh`` beforehand.

+ 

+ As a reference:

+ 

+ - Run tests with testing settings, and produce coverage report: ``./t``

+ - Run integration tests: ``./manage.py test -v 2 -p integration_test*.py --settings=happinesspackets.settings.tsting``

+ 

+ The web server can thus be run via the ``manage.py`` script: ``python manage.py runserver 0.0.0.0:8000``

+ 

+ When the source code is changed, the web server should automatically reload, and apply the new changes.

Added Sphinx documentation regarding:

  • Setting up a development environment, both with and without Docker.
  • Covered how to obtain an OIDC Client ID and secret for development and for staging/production.
  • An overview of the Message model, describing data fields and methods.

Can you leave only Fedora project please?

Please remove this line, we don't include the author.

1 new commit added

  • Removed individual author
5 years ago

@jonatoni Is this PR ready to merge after the updated commit?

Metadata Update from @jflory7:
- Pull-request tagged with: new change, type - docs
- Request assigned

5 years ago

Pull-Request has been merged by jonatoni

5 years ago