Skip to content

Commit

Permalink
Prevent to showing both adding user and importing user/group pages by…
Browse files Browse the repository at this point in the history
… ordinary user.
  • Loading branch information
userlocalhost committed May 14, 2024
1 parent 56d4b37 commit 88ef484
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
### Changed

### Fixed
* Prevent to showing both adding user and importing user/group pages by ordinary user.
Contributed by @userlocalhost, @hinashi

## v3.88.0

Expand Down
11 changes: 10 additions & 1 deletion group/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,16 @@ def test_post_edit_by_guest(self):

self.assertEqual(resp.status_code, 400)

def test_import_user_and_group(self):
def test_import_user_and_group_by_ordinary_user(self):
self.guest_login()

resp = self.client.get(reverse("group:import_user_and_group"))
self.assertEqual(resp.status_code, 400)
self.assertEqual(
resp.content.decode("utf-8"), "This page needs administrative permission to access"
)

def test_import_user_and_group_by_admin_user(self):
self.admin_login()

fp = self.open_fixture_file("import_user_and_group.yaml")
Expand Down
1 change: 1 addition & 0 deletions group/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def export(request):


@http_get
@check_superuser
def import_user_and_group(request):
return render(request, "import_user_and_group.html", {})

Expand Down
11 changes: 10 additions & 1 deletion user/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,16 @@ def test_create_get_without_login(self):
resp = self.client.get(reverse("user:create"))
self.assertEqual(resp.status_code, 303)

def test_create_get_with_login(self):
def test_create_get_with_login_by_normal_user(self):
self._guest_login()

resp = self.client.get(reverse("user:create"))
self.assertEqual(resp.status_code, 400)
self.assertEqual(
resp.content.decode("utf-8"), "This page needs administrative permission to access"
)

def test_create_get_with_login_by_admin_user(self):
self._admin_login()

resp = self.client.get(reverse("user:create"))
Expand Down
1 change: 1 addition & 0 deletions user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def index(request):


@http_get
@check_superuser
def create(request):
return render(request, "create_user.html")

Expand Down

0 comments on commit 88ef484

Please sign in to comment.