Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add show_permissions management command #1920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

PravinKamble123
Copy link
Contributor

Summary

This PR adds a new management command show_permissions that allows developers to list model-level permissions in their project.

It supports:

  • Filtering by app or model (e.g., auth.user)
  • An --all flag to include default Django apps like auth, admin, etc.
  • Clean CLI output

Motivation

This is based on an idea and implementation shared by @Kagee . Many thanks to him for the logic and inspiration behind this feature.

Related Issue

Fixes #1916

Labels

This PR falls under:

  • feature request
  • need patch

@trbs
Copy link
Member

trbs commented Apr 4, 2025

Could you take a look at the Django 4.2 tests please ?

browniebroke and others added 3 commits April 4, 2025 16:20
Create a separate section for each field, making it easier to share a link to a specific part
* Use .python_history for shell_plus command

* Update shell_plus.py

* Update shell_plus.py

---------

Co-authored-by: igorgaming <[email protected]>
@PravinKamble123
Copy link
Contributor Author

I'll take a look at the Django 4.2 test failures and investigate what's going wrong. Will update the PR shortly. 🙌

nicolaspanel and others added 9 commits April 4, 2025 16:35
…a `field-type-differ` (django-extensions#1867)

`` lead to fictive differences when comparing AutoField to integer
```
$ python manage.py  sqldiff -a -t
+ Application: admin
|-+ Differences for model: LogEntry
|--+ field 'id' not of same type: db='serial', model='integer'
```
…xtensions#1887)

This fixes an error with runjobs when a jobs.py exists in the
environment.  Modules have no `__path__` member defined unless it's a
package so we should be able to rely on that here.
we are in the process of moving away from setup.py/setup.cfg
but for now add these lines here as well to satisfy pipelines
@trbs
Copy link
Member

trbs commented Apr 5, 2025

One last ask :-) could you add a page to the documentation for show_permissions as well please ?

Thanks !

mounirmesselmeni and others added 8 commits April 5, 2025 13:43
List of backends provided by django-prometheus:

https://github.com/korfuri/django-prometheus/tree/master/django_prometheus/db/backends

This will fix the issue of not being able to reset_db as the backend is unknown.

A workaround I was using in `settings.py` it the following:

```python
if 'reset_db' not in sys.argv:
    DATABASES['default']['ENGINE'] = DATABASES['default']['ENGINE'].replace(
        'django.db.backends', 'django_prometheus.db.backends'
    )
```

Co-authored-by: trbs <[email protected]>
Running `hatch new --init`
@PravinKamble123
Copy link
Contributor Author

PravinKamble123 commented Apr 8, 2025

I hope everything goes well now .

@PravinKamble123
Copy link
Contributor Author

Hi @trbs ,
when run the precommit to all file there were 308 file changes were shown , so i was not sure whether to include them or not

@trbs
Copy link
Member

trbs commented Apr 8, 2025

Think something went wrong in rebasing the PR...
Could it be that the mainline was merged into the PR instead of the PR rebased on the main branch ?

@PravinKamble123
Copy link
Contributor Author

there was a conflict but the was with only my two file show_permissions.py and test_show_permissions.py.

and this 308 changes were happening from whenever i was running the tox in my machine even before the rebasing

@trbs
Copy link
Member

trbs commented Apr 8, 2025

It might be easier to redo this PR...

If you want I can merge the changes in directly as well and give you attribution (but we will lose your commits from the branch)

trbs pushed a commit that referenced this pull request Apr 8, 2025
@trbs
Copy link
Member

trbs commented Apr 8, 2025

I merged it with the correct author commit as well 👍

Thanks @PravinKamble123 for all your hard work on this !

@trbs trbs closed this Apr 8, 2025
@PravinKamble123
Copy link
Contributor Author

i'm sorry for the mess. I will be more careful in future

@trbs
Copy link
Member

trbs commented Apr 8, 2025

i'm sorry for the mess. I will be more careful in future

No worries !

@PravinKamble123
Copy link
Contributor Author

hi @trbs ,
Thank you so much for your patience and for being there for me.
I have learned lot from this PR.
This is my first contribution to any open source.
should I create a new PR for window compatability as we discussed ?
bcs i want to see my name in the contributor list

@trbs
Copy link
Member

trbs commented Apr 8, 2025

Yeah please submit another PR 👍

Btw you on the list in git :-)

git shortlog --summary --numbered --email | grep Pravin
     1	Pravin Kamble <[email protected]>
image

@PravinKamble123
Copy link
Contributor Author

this is only way i can contact you @trbs .
well im trying raise another pr for windows compatability since window don't have make command by default.
I did not forked the django-extensions again since i already did for show_permissions command.
but currently i'm on main branch when i hit "git fetch upsteam" and it fetchs the latest code but right now also when I run the "pre-commit run --all-files" , it still showing the changes in 305 files. why it is comming ?
or do i need to create a new fork

@browniebroke
Copy link
Contributor

Synchronising forks from the command line can be a bit tricky, I would recommend doing it from the GitHub UI which is less error prone:

  1. Go to your fork: https://github.com/PravinKamble123/django-extensions (without branches)

  2. You should see that you fork is "behind"
    image

  3. You should also have a "sync fok" button:
    image

  4. In the drop down, press the green "update branch" button which should do the right thing

  5. Then from your command line, make sure you have a clean working tree:

     ➜ git status
    Found existing alias for "git status". You should use: "gst"
    On branch main
    Your branch is up to date with 'origin/main'.
    
    nothing to commit, working tree clean
    
  6. Switch back to the main branch: git checkout main

  7. Pull the latest changes from your fork: git pull

@PravinKamble123
Copy link
Contributor Author

Synchronising forks from the command line can be a bit tricky, I would recommend doing it from the GitHub UI which is less error prone:

  1. Go to your fork: https://github.com/PravinKamble123/django-extensions (without branches)
  2. You should see that you fork is "behind"
    image
  3. You should also have a "sync fok" button:
    image
  4. In the drop down, press the green "update branch" button which should do the right thing
  5. Then from your command line, make sure you have a clean working tree:
     ➜ git status
    Found existing alias for "git status". You should use: "gst"
    On branch main
    Your branch is up to date with 'origin/main'.
    
    nothing to commit, working tree clean
    
  6. Switch back to the main branch: git checkout main
  7. Pull the latest changes from your fork: git pull

Wowwww Thank you so much for such detail help.
I really appreciate .
@browniebroke 😊🙏

@PravinKamble123
Copy link
Contributor Author

Hi @browniebroke,
still got changes in 311 files when i ran the pre-commit run --all-files
so is this happening bcs I'm on windows

@PravinKamble123
Copy link
Contributor Author

image

@trbs
Copy link
Member

trbs commented Apr 15, 2025

image

(Please consider I have zero experience with windows, so what I say might not be accurate)

Seems that something went wrong with your git repository / the checked out files, it looks like (windows ?) has marked a lot of files as executable this is not allowed.

What I would suggest is to remove this fork (on your local filesystem and probably also in github) and fork it again. Such that you know for sure your starting from a clean and correct fork.

If it happens again than at least you know that you started from a clean setup and have a way to reproduce the problem reliably to try and find out where things go wrong. (Hopefully somebody / stackoverflow can help...)

And latestly if possible for you I would suggest to look into using a Linux (like Debian or Ubuntu) Virtual Machine or WSL, such that you have a more Unix/Linux/Mac like environment which, at least from my perspective, is much easier for any development.

@PravinKamble123
Copy link
Contributor Author

on windows from scratch.
(venv) PS C:\Users\iampb\Documents\temp\django-extensions> pre-commit run --all-files
trim trailing whitespace.................................................Passed
check for added large files..............................................Passed
check python ast.........................................................Passed
check for case conflicts.................................................Passed
check docstring is first.................................................Passed
check json...............................................................Passed
check for merge conflicts................................................Passed
check xml................................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
fix end of files.........................................................Failed

  • hook id: end-of-file-fixer
  • exit code: 1
  • files were modified by this hook

Fixing tests/testapp/templates/hello_world.html

mixed line ending........................................................Failed

  • hook id: mixed-line-ending
  • exit code: 1

tests/test_templatetag

on ubuntu from scratch
(venv) root@19747f323f5d:/home/ubuntu/contributions/django-extensions# pre-commit run --all-files
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/tox-dev/pyproject-fmt.
[INFO] Initializing environment for https://github.com/trbs/pre-commit-hooks-trbs.git.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/tox-dev/pyproject-fmt.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/trbs/pre-commit-hooks-trbs.git.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
trim trailing whitespace.................................................Passed
check for added large files..............................................Passed
check python ast.........................................................Passed
check for case conflicts.................................................Passed
check docstring is first.................................................Passed
check json...............................................................Passed
check for merge conflicts................................................Passed
check xml................................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
fix end of files.........................................................Passed
mixed line ending........................................................Passed
fix python encoding pragma (deprecated)..................................Passed
python tests naming......................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Passed
pyproject-fmt............................................................Passed
Executable bit checker...................................................Passed

@PravinKamble123
Copy link
Contributor Author

PravinKamble123 commented Apr 16, 2025

so it is confirmed on windows it causing the issue.

On Windows, Git doesn't handle Unix-style executable bits and line endings the same way.

  • forbid-executables fails because Windows doesn't respect or properly clear the executable flag.

  • end-of-file-fixer fails due to inconsistent line endings (\r\n vs \n) across platforms.

These issues don’t appear on Unix-based systems, which is why the hooks pass there but not on Windows.

@PravinKamble123
Copy link
Contributor Author

i will use ubuntu from now onwards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is show_permissions a wanted command?