Skip to content

Conversation

@ZephyrNova47
Copy link
Contributor

@ZephyrNova47 ZephyrNova47 commented Oct 2, 2025

Access Organization by ID

Description

This change adds the ability to access organizations directly by their ID number in addition to the existing slug-based access and search and filtering capabilities. This makes it easier for admins to navigate to organizations directly from the admin interface and provides a more reliable way to access organizations programmatically.

Type of change: New feature

What

ID-based Access

  • Added direct ID-based access to organizations via /organization/id/<number>
  • Added ID column to organization admin list view with clickable links
  • Created new OrganizationByIdMixin for handling ID-based organization access

Admin Interface Enhancements

  • Added search functionality in admin to find organizations by:
    • Name
    • Short name
  • Added filter capabilities for:
    • Open/Closed status (is_open)
    • Listed/Unlisted status (is_unlisted)
  • Added ID column with direct links to organization pages
  • Added search box in the organization list page for users

Why

  • Makes it easier for admins to directly access organizations from the admin interface
  • Provides a more reliable way to access organizations (IDs never change, unlike slugs)
  • Improves admin workflow by showing organization IDs in the admin interface
  • Maintains clear separation between slug-based and ID-based access

Fixes: Add organization ID access #[issue_number]

How Has This Been Tested?

  • Test organization access by ID (e.g., /organization/id/2)
  • Test organization access with invalid ID
  • Test organization access permissions (admin, member, non-member)
  • Test blog post visibility in ID-based access
  • Test admin interface ID column display and links
  • Test slug validation (must start with letters)
  • Test organization subdomain restrictions

Test Configuration:

  • Django 4.2.25
  • Python 3.12.3
  • Local development server

Checklist

  • I have explained the purpose of this PR
  • I have performed a self-review of my own code
  • I have commented my code, particularly in the new OrganizationByIdMixin
  • I have maintained existing functionality for slug-based access
  • I have ensured proper error handling and user messages
  • I have tested both admin and user-facing features
  • No database migrations were needed for this change
  • No breaking changes to existing functionality

Screenshots:

  1. Admin interface showing new ID column
  2. Organization page accessed by ID
  3. Error message for invalid ID

By submitting this pull request, I confirm that my contribution is made under the terms of the AGPL-3.0 License.

Copy link
Contributor

@leduythuccs leduythuccs left a comment

Choose a reason for hiding this comment

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

overall the idea is good but the code should change to avoid duplication

also please remove this file
image

Comment on lines +22 to +30
{% block body %}
<div class="search-container">
<form method="get" class="search-form">
<input type="text" name="search" class="search-input" placeholder="{{ _('Search organizations...') }}"
value="{{ request.GET.search }}">
<button type="submit" class="search-submit"><i class="fa fa-search"></i></button>
</form>
</div>

Copy link
Contributor

Choose a reason for hiding this comment

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

where is the endblock?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

omg =))) let me check

Comment on lines +147 to +149
# Allow superusers and staff to access any organization
if self.request.user.is_superuser or self.request.user.is_staff:
return True
Copy link
Contributor

Choose a reason for hiding this comment

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

this check is redundant, if user is superuser, they already have the judge.edit_organization, also i think better to leave the PrivateOrganizationMixin alone, don't change it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, i understand

Comment on lines +529 to +558
class OrganizationHomeById(TitleMixin, OrganizationByIdMixin, PostListBase):
template_name = 'organization/home.html'

def get_title(self):
return self.organization.name

def get_queryset(self):
queryset = BlogPost.objects.filter(organization=self.organization)

if not self.request.user.has_perm('judge.edit_all_post'):
if not self.can_edit_organization():
if self.request.profile in self.organization:
# Normal user can only view public posts
queryset = queryset.filter(publish_on__lte=timezone.now(), visible=True)
else:
# User cannot view organization blog
# if they are not in the org
# even if the org is public
queryset = BlogPost.objects.none()
else:
# Org admin can view public posts & their own posts
queryset = queryset.filter(Q(visible=True) | Q(authors=self.request.profile))

if self.request.user.is_authenticated:
profile = self.request.profile
queryset = queryset.annotate(
my_vote=FilteredRelation('votes', condition=Q(votes__voter_id=profile.id)),
).annotate(vote_score=Coalesce(F('my_vote__score'), Value(0)))

return queryset.order_by('-sticky', '-publish_on').prefetch_related('authors__user')
Copy link
Contributor

Choose a reason for hiding this comment

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

this is ok but it's make the code duplicated, is there a better way? Perhaps we could inherit the OrganizationHome, and override the get_object/get_query_set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I’ll switch to overriding get_object() or get_queryset() instead that way I can reuse the logic from OrganizationHome and avoid code duplication.

@magnified103 magnified103 linked an issue Dec 15, 2025 that may be closed by this pull request
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.

Organization enhancement

2 participants