Skip to content

Conversation

@NoumbissiValere
Copy link
Contributor

Closed issue by updating organization admin and also added
a couple number of tests for these changes.

Fixes #143

@coveralls
Copy link

coveralls commented Jul 23, 2020

Coverage Status

Coverage increased (+0.02%) to 97.399% when pulling 52be16c on issue-143-administrators_access_organization into be43f32 on master.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress! Sorry for my late response.

For some reason while testing, the permissions were not added to the administrator group correctly in my env.

So I wanted to run the migration backward to run it again and found this:

    raise IrreversibleError("Operation %s in %s is not reversible" % (operation, self))
django.db.migrations.exceptions.IrreversibleError: Operation <RunPython <function allow_admins_change_organization at 0x7fa9626b6dd0>> in openwisp_users.0010_allow_admins_change_organization is not reversible

PS: also rebase on the latest master please

f'admin:{self.app_label}_organization_change', args=[default_org.pk]
)
),
follow=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than following the redirect, assert the status code to ensure it's a redirect and remove the following lines which are not relevant anymore

@NoumbissiValere
Copy link
Contributor Author

Sure. Will do that today

@NoumbissiValere
Copy link
Contributor Author

Good progress! Sorry for my late response.

For some reason while testing, the permissions were not added to the administrator group correctly in my env.

So I wanted to run the migration backward to run it again and found this:

    raise IrreversibleError("Operation %s in %s is not reversible" % (operation, self))
django.db.migrations.exceptions.IrreversibleError: Operation <RunPython <function allow_admins_change_organization at 0x7fa9626b6dd0>> in openwisp_users.0010_allow_admins_change_organization is not reversible

PS: also rebase on the latest master please

@nemesisdesign It says that because I didn't make the migration reversible. I didn't see a reason to make this reversible since its absence will cause other core functionalities which were added to malfunction.

Should i make it reversible?

@nemesifier
Copy link
Member

@nemesisdesign It says that because I didn't make the migration reversible. I didn't see a reason to make this reversible since its absence will cause other core functionalities which were added to malfunction.

Should i make it reversible?

In this case we can simply set the backward migration to noop, no operation, look it up on the django docs please.

@NoumbissiValere NoumbissiValere force-pushed the issue-143-administrators_access_organization branch from 679b46c to 400dbd2 Compare August 11, 2020 15:51
@NoumbissiValere
Copy link
Contributor Author

@nemesisdesign This is ready for review

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress, see my hints below and we're ready to move on

).pk,
]
admins.permissions.add(*permissions)
except ObjectDoesNotExist:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like this is here but it's not being imported at the top, don't you have flake8 configured in your editor to highlight these issues? I wonder why this doesn't pop up in the global flake8 check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nemesisdesign Please i don't understand what you are asking for. it looks like your sentence is missing some words

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no missing word, please read carefully: ObjectDoesNotExist is used here but it's not imported.
Please activate flake8 checks in your editor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a patch for this issue: #157
I will merge that and then you only need to rebase.

content_type__app_label=app_label, codename='change_organizationowner'
).pk,
]
admins.permissions.add(*permissions)
Copy link
Member

@nemesifier nemesifier Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please simplify, we added get_model to avoid those lines, remember?

Group = get_model(apps, 'Group')
try:
    admins = Group.objects.get(name='Administrator')
    permissions = [
        Permission.objects.get(
            content_type__app_label='openwisp_users', codename='change_organization'
        ).pk,
        Permission.objects.get(
            content_type__app_label='openwisp_users', codename='change_organizationowner'
        ).pk,
    ]
    admins.permissions.add(*permissions)

- Only super users have the permission to add and delete organizations.
- Only super users and organization owners have the permission to change the OrganizationOwner inline.
- Only Super users have the permission to delete OrganizationOwner inline.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's an improved version:

Here's a summary of the default permissions:

- All users who belong to the Administrators group and are organization
  managers (``OrganizationUser.is_admin=True``), have the permission to edit
  the organizations details which they administrate.
- Only super users have the permission to add and delete organizations.
- Only super users and organization owners have the permission to change
  the ``OrganizationOwner`` inline or delete the relation.

@NoumbissiValere NoumbissiValere force-pushed the issue-143-administrators_access_organization branch from 400dbd2 to 939836e Compare August 13, 2020 18:44
@NoumbissiValere NoumbissiValere self-assigned this Aug 13, 2020
Closed issue by updating organization admin and also added
a couple number of tests for these changes.

Closes #143
@NoumbissiValere NoumbissiValere force-pushed the issue-143-administrators_access_organization branch from 939836e to a234fec Compare August 13, 2020 21:36
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@nemesifier nemesifier merged commit 2826943 into master Aug 13, 2020
@nemesifier nemesifier deleted the issue-143-administrators_access_organization branch August 13, 2020 22:33
dee077 pushed a commit to dee077/openwisp-users that referenced this pull request Jan 6, 2026
…wisp#152

Made organization field visible when importing a CA or Cert.
Fixes openwisp#152
dee077 pushed a commit to dee077/openwisp-users that referenced this pull request Jan 6, 2026
[bug] Organization field is missing when importing a CA or cert. openwisp#152
dee077 pushed a commit to dee077/openwisp-users that referenced this pull request Jan 6, 2026
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.

[admin] Allow administrator role to access organization admin

3 participants