-
-
Notifications
You must be signed in to change notification settings - Fork 538
Fix #1786 Refactor slack app admin.py into separate files #1935
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b51d682
refactor slack app admin.py
anurag2787 d92cfcb
Fixed duplication
anurag2787 dec3a60
used mixin base fields
anurag2787 34c61a3
Fix SonarQube warnings
anurag2787 054afe3
removed mixins
anurag2787 9325105
Merge branch 'main' into refactor/slack-admin.py
anurag2787 6349dd2
Merge branch 'main' into refactor/slack-admin.py
anurag2787 bdc2aee
Merge branch 'main' into pr/anurag2787/1935
arkid15r 470e95a
Update code
arkid15r 09e82f0
Merge branch 'main' into refactor/slack-admin.py
arkid15r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| """Slack app admin.""" | ||
|
|
||
| from .conversation import ConversationAdmin | ||
| from .event import EventAdmin | ||
| from .member import MemberAdmin | ||
| from .message import MessageAdmin | ||
| from .workspace import WorkspaceAdmin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """Conversation admin configuration.""" | ||
|
|
||
| from django.contrib import admin | ||
|
|
||
| from apps.slack.models.conversation import Conversation | ||
|
|
||
|
|
||
| class ConversationAdmin(admin.ModelAdmin): | ||
| """Admin for Conversation model.""" | ||
|
|
||
| fieldsets = ( | ||
| ( | ||
| "Conversation Information", | ||
| { | ||
| "fields": ( | ||
| "slack_channel_id", | ||
| "name", | ||
| "created_at", | ||
| "slack_creator_id", | ||
| ) | ||
| }, | ||
| ), | ||
| ( | ||
| "Properties", | ||
| { | ||
| "fields": ( | ||
| "is_private", | ||
| "is_archived", | ||
| "is_general", | ||
| ) | ||
| }, | ||
| ), | ||
| ( | ||
| "Content", | ||
| { | ||
| "fields": ( | ||
| "topic", | ||
| "purpose", | ||
| ) | ||
| }, | ||
| ), | ||
| ( | ||
| "Additional attributes", | ||
| {"fields": ("sync_messages",)}, | ||
| ), | ||
| ) | ||
| list_display = ( | ||
| "name", | ||
| "slack_channel_id", | ||
| "created_at", | ||
| "total_members_count", | ||
| ) | ||
| list_filter = ( | ||
| "sync_messages", | ||
| "is_archived", | ||
| "is_channel", | ||
| "is_general", | ||
| "is_im", | ||
| "is_private", | ||
| ) | ||
| readonly_fields = ( | ||
| "slack_channel_id", | ||
| "created_at", | ||
| "slack_creator_id", | ||
| ) | ||
| search_fields = ( | ||
| "name", | ||
| "topic", | ||
| "purpose", | ||
| "slack_channel_id", | ||
| "slack_creator_id", | ||
| ) | ||
|
|
||
|
|
||
| admin.site.register(Conversation, ConversationAdmin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """Event admin configuration.""" | ||
|
|
||
| from django.contrib import admin | ||
|
|
||
| from apps.slack.models.event import Event | ||
|
|
||
|
|
||
| class EventAdmin(admin.ModelAdmin): | ||
| """Admin for Event model.""" | ||
|
|
||
| list_display = ( | ||
| "nest_created_at", | ||
| "trigger", | ||
| "user_id", | ||
| ) | ||
| list_filter = ("trigger",) | ||
| search_fields = ( | ||
| "channel_id", | ||
| "channel_name", | ||
| "text", | ||
| "user_id", | ||
| "user_name", | ||
| ) | ||
|
|
||
|
|
||
| admin.site.register(Event, EventAdmin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Member admin configuration.""" | ||
|
|
||
| from django.contrib import admin, messages | ||
|
|
||
| from apps.slack.models.member import Member | ||
|
|
||
|
|
||
| class MemberAdmin(admin.ModelAdmin): | ||
| """Admin for Member model.""" | ||
|
|
||
| actions = ("approve_suggested_users",) | ||
| autocomplete_fields = ("user",) | ||
| filter_horizontal = ("suggested_users",) | ||
| list_filter = ( | ||
| "is_bot", | ||
| "workspace", | ||
| ) | ||
| search_fields = ( | ||
| "slack_user_id", | ||
| "username", | ||
| "real_name", | ||
| "email", | ||
| "user__login", | ||
| ) | ||
|
|
||
| def approve_suggested_users(self, request, queryset): | ||
| """Approve all suggested users for selected members, enforcing one-to-one constraints.""" | ||
| for entity in queryset: | ||
| suggestions = entity.suggested_users.all() | ||
|
|
||
| if suggestions.count() == 1: | ||
| entity.user = suggestions.first() # only one suggested user | ||
| entity.save() | ||
| self.message_user( | ||
| request, | ||
| f" assigned user for {entity}.", | ||
| messages.SUCCESS, | ||
| ) | ||
| elif suggestions.count() > 1: | ||
| self.message_user( | ||
| request, | ||
| f"Error: Multiple suggested users found for {entity}. " | ||
| f"Only one user can be assigned due to the one-to-one constraint.", | ||
| messages.ERROR, | ||
| ) | ||
| else: | ||
| self.message_user( | ||
| request, | ||
| f"No suggested users found for {entity}.", | ||
| messages.WARNING, | ||
| ) | ||
|
|
||
| approve_suggested_users.short_description = "Approve the suggested user (if only one exists)" | ||
|
|
||
|
|
||
| admin.site.register(Member, MemberAdmin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """Message admin configuration.""" | ||
|
|
||
| from django.contrib import admin | ||
|
|
||
| from apps.slack.models.message import Message | ||
|
|
||
|
|
||
| class MessageAdmin(admin.ModelAdmin): | ||
| """Admin for Message model.""" | ||
|
|
||
| autocomplete_fields = ( | ||
| "author", | ||
| "conversation", | ||
| "parent_message", | ||
| ) | ||
| list_display = ( | ||
| "created_at", | ||
| "has_replies", | ||
| "author", | ||
| "conversation", | ||
| ) | ||
| list_filter = ( | ||
| "has_replies", | ||
| "conversation", | ||
| ) | ||
| search_fields = ( | ||
| "slack_message_id", | ||
| "raw_data__text", | ||
| ) | ||
|
|
||
|
|
||
| admin.site.register(Message, MessageAdmin) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.