-
Notifications
You must be signed in to change notification settings - Fork 167
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
Grouping feature #719
Merged
Merged
Grouping feature #719
Changes from 14 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1df76b2
inital setup
iamhks ddc3521
code fix
iamhks c79cb46
3rd page code
iamhks f69bb06
backend code
iamhks af76d8c
frontend
iamhks c6ac9c3
backend-2
iamhks fe0671c
frontend 2
iamhks 8b4ed90
package.json
iamhks 71dbc49
team form
iamhks 78dc915
team profile page
iamhks 32f8515
stuck
iamhks bfbfff3
restore old ui
iamhks b7324d4
migration fixes
iamhks aa9842e
tested backend
iamhks 950721f
form all 3 steps and profile page
iamhks 9112df0
edit and delete api integration
iamhks 04b2508
call for testing
iamhks ad65e9b
step 3 and teams page
iamhks fe30318
backend for all teams
iamhks 7ca58a6
migration files
iamhks a45bf6a
url change for all teams
iamhks 9c76954
Merge branch 'master' of https://github.com/iamhks/zubhub into groupi…
iamhks 0386929
Merge branch 'master' of https://github.com/iamhks/zubhub into groupi…
iamhks 2188a56
rebased code
iamhks 1a3ebe6
Merge pull request #1 from iamhks/master
iamhks 1c107f7
UI changes
iamhks 441337c
UX fixes
iamhks ed97ab0
edit-add projects api change
iamhks 4ac6b5a
rebase
iamhks f4eba11
Merge pull request #2 from iamhks/master
iamhks bad5c2f
trying to fix not clickable issue
iamhks 65de286
Merge branch 'grouping-feature' of https://github.com/iamhks/zubhub i…
iamhks 9bc54af
adding team_enabled flag
iamhks 185b126
Revert "adding team_enabled flag"
iamhks ecad2e3
updating the TEAM_ENABLED flag
iamhks 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 contains 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
16 changes: 16 additions & 0 deletions
16
zubhub_backend/zubhub/creators/migrations/0011_delete_creatorgroup.py
This file contains 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,16 @@ | ||
# Generated by Django 3.2 on 2023-07-27 18:38 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('creators', '0010_merge_20220921_2226'), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name='CreatorGroup', | ||
), | ||
] |
16 changes: 16 additions & 0 deletions
16
zubhub_backend/zubhub/creators/migrations/old/0011_delete_creatorgroup.py
This file contains 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,16 @@ | ||
# Generated by Django 3.2 on 2023-07-27 18:38 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('creators', '0010_merge_20220921_2226'), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name='CreatorGroup', | ||
), | ||
] |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -5,8 +5,10 @@ | |
from django.utils.translation import ugettext_lazy as _ | ||
from rest_framework import serializers | ||
from django.contrib.auth import get_user_model | ||
|
||
from django.utils.translation import gettext_lazy as _ | ||
import csv | ||
from .admin import badges | ||
from .models import CreatorGroup, Creator, CreatorGroupMembership | ||
from .models import Location, PhoneNumber | ||
from allauth.account.models import EmailAddress | ||
from rest_auth.registration.serializers import RegisterSerializer | ||
|
@@ -15,6 +17,7 @@ | |
from .utils import setup_user_phone | ||
from projects.models import Comment | ||
from projects.utils import parse_comment_trees | ||
from rest_framework.validators import UniqueValidator | ||
Creator = get_user_model() | ||
|
||
|
||
|
@@ -79,6 +82,17 @@ def get_profile_comments(self, obj): | |
return parse_comment_trees(user, root_comments, creators_dict) | ||
|
||
|
||
class CreatorGroupMinimalSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = CreatorGroup | ||
fields = '__all__' | ||
|
||
class CreatorGroupMembershipSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = CreatorGroupMembership | ||
fields = ('member', 'role') | ||
|
||
|
||
class CreatorSerializer(CreatorMinimalSerializer): | ||
phone = serializers.CharField(allow_blank=True, default="") | ||
email = serializers.EmailField(allow_blank=True, default="") | ||
|
@@ -91,16 +105,18 @@ class CreatorSerializer(CreatorMinimalSerializer): | |
badges = serializers.SlugRelatedField(slug_field="badge_title", | ||
read_only=True, | ||
many=True) | ||
group_memberships = CreatorGroupMembershipSerializer(many=True, read_only=True) | ||
|
||
|
||
class Meta: | ||
model = Creator | ||
|
||
fields = ('id', 'username', 'email', 'phone', 'avatar', 'location', | ||
'comments', 'dateOfBirth', 'bio', 'followers', | ||
'following_count', 'projects_count', 'members_count', 'tags', 'badges') | ||
'following_count', 'projects_count', 'members_count', 'tags', 'badges', 'group_memberships') | ||
|
||
read_only_fields = [ | ||
"id", "projects_count", "following_count", "dateOfBirth", "tags", "badges" | ||
"id", "projects_count", "following_count", "dateOfBirth", "tags", "badges", "group_memberships" | ||
] | ||
|
||
def validate_email(self, email): | ||
|
@@ -246,26 +262,22 @@ class ConfirmGroupInviteSerializer(serializers.Serializer): | |
key = serializers.CharField() | ||
|
||
|
||
class MemberRoleSerializer(serializers.Serializer): | ||
member = serializers.CharField() | ||
role = serializers.ChoiceField(choices=[('admin', 'Admin'), ('member', 'Member')]) | ||
|
||
|
||
class AddGroupMembersSerializer(serializers.Serializer): | ||
group_members = serializers.JSONField(required=False, allow_null=True) | ||
csv = serializers.FileField(required=False, | ||
allow_null=True, | ||
allow_empty_file=True) | ||
group_members = MemberRoleSerializer(many=True, required=True) | ||
|
||
def validate_group_members(self, group_members): | ||
if (len(group_members) == 0 and not self.initial_data.get("csv")): | ||
raise serializers.ValidationError( | ||
_("you must submit group member usernames either through the form or as csv" | ||
)) | ||
return group_members | ||
def validate(self, data): | ||
group_members = data.get('group_members', []) | ||
|
||
def validate_csv(self, csv): | ||
if (not csv and len(self.initial_data.get("group_members")) == 0): | ||
raise serializers.ValidationError( | ||
_("you must submit group member usernames either through the form or as csv" | ||
)) | ||
return csv | ||
if not group_members: | ||
raise serializers.ValidationError(_("You must submit at least one group member.")) | ||
|
||
return data | ||
|
||
|
||
class CustomPasswordResetSerializer(PasswordResetSerializer): | ||
password_reset_form_class = PasswordResetForm | ||
|
@@ -280,3 +292,72 @@ def validate_email(self, value): | |
raise serializers.ValidationError( | ||
_('No account found with this email. Verify and try again.')) | ||
return value | ||
|
||
|
||
class CreatorGroupWithMembershipsSerializer(serializers.ModelSerializer): | ||
members = CreatorGroupMembershipSerializer(many=True) | ||
|
||
class Meta: | ||
model = CreatorGroup | ||
fields = ('groupname', 'description', 'members', 'created_on', 'projects_count') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think |
||
|
||
def to_representation(self, instance): | ||
data = super().to_representation(instance) | ||
data['members'] = CreatorGroupMembershipSerializer(instance.memberships.all(), many=True).data | ||
return data | ||
|
||
|
||
class CreatorGroupSerializer(serializers.ModelSerializer): | ||
members = CreatorGroupMembershipSerializer(many=True, read_only=True) | ||
groupname = serializers.CharField( | ||
max_length=150, | ||
validators=[UniqueValidator(queryset=CreatorGroup.objects.all())], | ||
error_messages={ | ||
'unique': _('A group with that groupname already exists.'), | ||
} | ||
) | ||
|
||
class Meta: | ||
model = CreatorGroup | ||
fields = ('groupname', 'description', 'members', 'created_on', 'projects_count') | ||
|
||
def create(self, validated_data): | ||
members_data = validated_data.pop('members', []) | ||
group = CreatorGroup.objects.create(**validated_data) | ||
for member_data in members_data: | ||
member = member_data['member'] | ||
role = member_data.get('role', 'member') # Default role is 'member' if not provided | ||
CreatorGroupMembership.objects.create(group=group, member=member, role=role) | ||
return group | ||
|
||
def to_representation(self, instance): | ||
data = super().to_representation(instance) | ||
data['members'] = CreatorGroupMembershipSerializer(instance.memberships.all(), many=True).data | ||
return data | ||
|
||
def update(self, instance, validated_data): | ||
instance.groupname = validated_data.get('groupname', instance.groupname) | ||
instance.description = validated_data.get('description', instance.description) | ||
instance.save() | ||
|
||
members_data = validated_data.pop('members', []) | ||
existing_members = set(instance.members.all()) | ||
|
||
for member_data in members_data: | ||
member = member_data['member'] | ||
role = member_data.get('role', 'member') # Default role is 'member' if not provided | ||
|
||
# Check if the member is already part of the group | ||
if member in existing_members: | ||
membership = CreatorGroupMembership.objects.get(group=instance, member=member) | ||
membership.role = role | ||
membership.save() | ||
else: | ||
# If the member is not part of the group, add them with the specified role | ||
CreatorGroupMembership.objects.create(group=instance, member=member, role=role) | ||
|
||
# Remove any members who were not included in the updated data | ||
members_to_remove = existing_members - set([member_data['member'] for member_data in members_data]) | ||
CreatorGroupMembership.objects.filter(group=instance, member__in=members_to_remove).delete() | ||
|
||
return instance |
This file contains 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
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.
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.
@tuxology is there a auto formatter for python? The indentation/styling seems to be off