Skip to main content

Package containing functionality related to django model permissions.

Project description

govtech-csg-xcg-modelpermissions

This package belongs to the eXtended Code Guardrails (XCG) project, which consists of a series of packages that harden the Django web framework to prevent common web application vulnerabilities.

Specifically, this package provides functionality to enforce permissions checks on users when they attempt to perform actions on a Django Model object (e.g. if a request accesses a view that tries to read a set of objects from the database).

By default, modelpermissions checks for permissions at the object level - i.e. the user must have the appropriate permissions for every single model object that they are trying to access/modify. This allows access control to be enforced at the level of single database records.

However, modelpermissions can also be configured to check for permissions at the model level, which means the user must have the appropriate permissions over the entire class of objects This approach is more coarse-grained, but having both options provides developers with the flexibility to determine the granularity of their applications's access control model.

Do note that the README in this repository is intentionally limited in scope and is catered towards developers. For detailed instructions on installation, usage, and community guidelines, please refer to the published documentation at https://xcg.tech.gov.sg.

Security-related matters

For instructions on how to report a vulnerability, refer to the official documentation website.

Additionally, enable email alerts for security issues by "watching" this repository. The "watch" button can be found near the top right corner of this repo's home page, and there are various options for configuring notification volume. To receive security alerts, either enable notifications for "All Activity" or "Custom -> Security alerts".

Installing development dependencies

Before building or testing the package, or committing changes, install the development dependencies into a virtual environment:

# In the project root directory
python -m venv .venv && source .venv/bin/activate
pip install -r requirements-dev.txt

Building

The package can be built using build as the build frontend and setuptools as the build backend.

Run the build command below:

# In the project root directory
python -m build .

This creates a directory named dist/, which should contain 2 files:

  1. A .whl (wheel) file, which is a binary distribution format for Python packages
  2. A .tar.gz file, which is a source distribution format for Python packages

To view the source files included in the source distribution, use the tar utility as follows:

tar --list -f dist/<filename>.tar.gz

To install the package directly from either distribution files:

pip install <name_of_distribution_file>

Testing

As the tests for this package use multiple variants of the Django settings module, a convenience script has been provided for ease of running all test methods. Execute the tests using the commands below:

pip install -e . # Performs an "editable install" of the govtech-csg-xcg-modelpermissions package
cd tests
/bin/bash run_all_tests.sh

Running pre-commit hooks

Note: This section is only relevant if you intend to contribute code

This project uses the pre-commit tool to run Git pre-commit hooks for linting and code quality checks. The pre-commit tool itself should have been installed along with the development dependencies. After cloning the repository for the first time, run the command below to "install" the Git hooks:

pre-commit install

The command above creates a file .git/hooks/pre-commit, which defines the shell commands to run before any Git commit is created.

Subsequently, any invocation of git commit will trigger the commands, rejecting the commit if there are linting errors. Issues should be automatically fixed, but you will need to re-stage the changes before attempting the commit again.

For a list of hooks run by pre-commit, see its configuration file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

govtech-csg-xcg-modelpermissions-0.1.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file govtech-csg-xcg-modelpermissions-0.1.0.tar.gz.

File metadata

File hashes

Hashes for govtech-csg-xcg-modelpermissions-0.1.0.tar.gz
Algorithm Hash digest
SHA256 10ac463789604eff79e10184380b4e340ad1e13d3aad8a66d3f1eedfd7e8dd68
MD5 0f8362f151e7253745ed914fcb697343
BLAKE2b-256 66f2f03b9de395921babdecccc06edf68255503091a088b34a2adbfc7f7a50f7

See more details on using hashes here.

File details

Details for the file govtech_csg_xcg_modelpermissions-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for govtech_csg_xcg_modelpermissions-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06d78edacf7a77b2deab9165c24018a21778f2bf11b4bdc23ed74363e92b056f
MD5 1b383f321a771470ba14d30f133ae5b7
BLAKE2b-256 fa8ff6a9afc9980c2d6d465769013d540e58579dfc3d9b1e2fcfe73982f6b89c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page