Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tutor-contrib-scout-apm Experimental
tutor-contrib-lti-store Experimental
tutor-contrib-paragon Production
tutor-contrib-portainer Experimental
tutor-contrib-authz Experimental
=================================== ======================================================

Getting Started
Expand Down
7 changes: 7 additions & 0 deletions plugins/tutor-contrib-authz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.*.swp
!.gitignore
TODO
__pycache__
*.egg-info/
/build/
/dist/
662 changes: 662 additions & 0 deletions plugins/tutor-contrib-authz/LICENSE.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions plugins/tutor-contrib-authz/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
recursive-include tutor_authz/patches *
recursive-include tutor_authz/templates *
30 changes: 30 additions & 0 deletions plugins/tutor-contrib-authz/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.DEFAULT_GOAL := help
.PHONY: docs
SRC_DIRS = ./tutor_authz

# Warning: These checks are not necessarily run on every PR.
test: test-lint test-types test-format # Run some static checks.

test-format: ## Run code formatting tests
ruff format --check --diff ${SRC_DIRS}

test-lint: ## Run code linting tests
ruff check ${SRC_DIRS}

test-types: ## Run type checks.
mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ${SRC_DIRS}

format: ## Format code
ruff format ${SRC_DIRS}

fix-lint: ## Fix lint errors automatically
ruff check --fix ${SRC_DIRS}

version: ## Print the current tutor-contrib-authz version
@python -c 'import io, os; about = {}; exec(io.open(os.path.join("tutor_authz", "__about__.py"), "rt", encoding="utf-8").read(), about); print(about["__version__"])'

ESCAPE = 
help: ## Print this help
@grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \
| sed 's/######* \(.*\)/@ $(ESCAPE)[1;31m\1$(ESCAPE)[0m/g' | tr '@' '\n' \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'
80 changes: 80 additions & 0 deletions plugins/tutor-contrib-authz/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
authz plugin for `Tutor <https://docs.tutor.edly.io>`__
#######################################################

Introduction
============

This plugin creates a new Tutor patch point (``openedx-authz-schema``) that lets other plugins contribute authorization schema YAML fragments. All contributions are combined into a single multi-document YAML file and mounted into the LMS/CMS containers at ``/openedx/config/authz-schema.yml``.

A Django setting ``OPENEDX_AUTHZ_SCHEMA_FILES`` is added to ``openedx-common-settings`` so that the ``load_authz_schema`` management command knows where to find the schema files at initialisation time.

Installation
************

.. code-block:: bash

git clone https://github.com/openedx/openedx-tutor-plugins.git
cd openedx-tutor-plugins/plugins/tutor-contrib-authz
pip install -e .

Usage
*****

.. code-block:: bash

tutor plugins enable authz


Contribute an Authorization Schema
***********************************

1. Create a tutor plugin:

.. code-block:: bash

touch $(tutor config printroot)-plugins/my_authz_schema.py

2. Use the patch ``openedx-authz-schema`` to contribute your authz schema:

.. code-block:: python

from tutor import hooks

hooks.Filters.ENV_PATCHES.add_item(
(
"openedx-authz-schema",
"""
schema_version: "1.0"
priority: 100

role_extensions:
- role: course_editor
add_permissions:
- courses.export_course
remove_permissions:
- courses.manage_tags
display_name: Course author
description: Creates and exports course content for this site.

- role: course_auditor
hidden: true
""",
)
)

3. Run do init commands:

.. code-block:: bash

tutor {dev|local|k8s} do init

4. Alternatively, instead of running the do init commands, you can run the following management command for your schemas to be loaded:

.. code-block:: bash

tutor {dev|local|k8s} exec {cms|lms} ./manage.py load_authz_schema

License
*******

This software is licensed under the terms of the AGPLv3.
65 changes: 65 additions & 0 deletions plugins/tutor-contrib-authz/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# https://packaging.python.org/en/latest/tutorials/packaging-projects/
# https://hatch.pypa.io/latest/config/build/

[project]
name = "tutor-contrib-authz"
description = "authz plugin for Tutor"
authors = [
{ name = "Carlos Marquez"},
{ email = "carlos.marquez@wgu.edu" },
]
license = { text = "AGPL-3.0-only" }

readme = {file = "README.rst", content-type = "text/x-rst"}
requires-python = ">= 3.9"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",

]
dependencies = [
"tutor>=22.0.0,<23.0.0",
]

# These fields will be set by hatch_build.py
dynamic = ["version"]

[project.optional-dependencies]
dev = [
"tutor[dev]>=22.0.0,<23.0.0",
"ruff",
]

[tool.hatch.version]
path = "tutor_authz/__about__.py"

# https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-labels
[project.urls]
Documentation = "https://github.com/openedx/openedx-tutor-plugins#readme"
Issues = "https://github.com/openedx/openedx-tutor-plugins/issues"
Source = "https://github.com/openedx/openedx-tutor-plugins"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["tutor_authz"]

[tool.hatch.build.targets.sdist]
# Disable strict naming, otherwise twine is not able to detect name/version
strict-naming = false
include = [ "/tutor_authz"]
exclude = ["tests*"]

[project.entry-points."tutor.plugin.v1"]
authz = "tutor_authz.plugin"
1 change: 1 addition & 0 deletions plugins/tutor-contrib-authz/tutor_authz/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "22.0.0"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Allows authorization schema discovery for filesystem files
OPENEDX_AUTHZ_SCHEMA_FILES = ["/openedx/config/authz-schema.yml"]
Loading
Loading