-
Notifications
You must be signed in to change notification settings - Fork 99
feat(organization): add tool search, filter and access organization w… #449
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
base: master
Are you sure you want to change the base?
feat(organization): add tool search, filter and access organization w… #449
Conversation
leduythuccs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| {% 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> | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omg =))) let me check
| # Allow superusers and staff to access any organization | ||
| if self.request.user.is_superuser or self.request.user.is_staff: | ||
| return True |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i understand
| 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') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.


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
/organization/id/<number>OrganizationByIdMixinfor handling ID-based organization accessAdmin Interface Enhancements
is_open)is_unlisted)Why
Fixes: Add organization ID access #[issue_number]
How Has This Been Tested?
Test Configuration:
Checklist
Screenshots:
By submitting this pull request, I confirm that my contribution is made under the terms of the AGPL-3.0 License.