fix: pre release bug fixes (#3473)

* clear store on signout

* fix: project member list response change

* fix adding member to project

* fix exceptions with invitations

---------

Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
This commit is contained in:
rahulramesha 2024-01-25 16:38:34 +05:30 committed by GitHub
parent c1c2a6ddce
commit a1a24e4574
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 64 additions and 37 deletions

View File

@ -685,6 +685,19 @@ class ProjectMemberViewSet(BaseViewSet):
.order_by("sort_order") .order_by("sort_order")
) )
bulk_project_members = []
member_roles = {member.get("member_id"): member.get("role") for member in members}
# Update roles in the members array based on the member_roles dictionary
for project_member in ProjectMember.objects.filter(project_id=project_id, member_id__in=[member.get("member_id") for member in members]):
project_member.role = member_roles[str(project_member.member_id)]
project_member.is_active = True
bulk_project_members.append(project_member)
# Update the roles of the existing members
ProjectMember.objects.bulk_update(
bulk_project_members, ["is_active", "role"], batch_size=100
)
for member in members: for member in members:
sort_order = [ sort_order = [
project_member.get("sort_order") project_member.get("sort_order")
@ -711,25 +724,6 @@ class ProjectMemberViewSet(BaseViewSet):
) )
) )
# Check if the user is already a member of the project and is inactive
if ProjectMember.objects.filter(
workspace__slug=slug,
project_id=project_id,
member_id=member.get("member_id"),
is_active=False,
).exists():
member_detail = ProjectMember.objects.get(
workspace__slug=slug,
project_id=project_id,
member_id=member.get("member_id"),
is_active=False,
)
# Check if the user has not deactivated the account
user = User.objects.filter(pk=member.get("member_id")).first()
if user.is_active:
member_detail.is_active = True
member_detail.save(update_fields=["is_active"])
project_members = ProjectMember.objects.bulk_create( project_members = ProjectMember.objects.bulk_create(
bulk_project_members, bulk_project_members,
batch_size=10, batch_size=10,
@ -740,8 +734,8 @@ class ProjectMemberViewSet(BaseViewSet):
bulk_issue_props, batch_size=10, ignore_conflicts=True bulk_issue_props, batch_size=10, ignore_conflicts=True
) )
serializer = ProjectMemberSerializer(project_members, many=True) project_members = ProjectMember.objects.filter(project_id=project_id, member_id__in=[member.get("member_id") for member in members])
serializer = ProjectMemberRoleSerializer(project_members, many=True)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
def list(self, request, slug, project_id): def list(self, request, slug, project_id):

View File

@ -99,7 +99,7 @@ export const Invitations: React.FC<Props> = (props) => {
> >
<div className="flex-shrink-0"> <div className="flex-shrink-0">
<div className="grid h-9 w-9 place-items-center rounded"> <div className="grid h-9 w-9 place-items-center rounded">
{invitedWorkspace.logo && invitedWorkspace.logo !== "" ? ( {invitedWorkspace?.logo && invitedWorkspace.logo !== "" ? (
<img <img
src={invitedWorkspace.logo} src={invitedWorkspace.logo}
height="100%" height="100%"
@ -109,13 +109,13 @@ export const Invitations: React.FC<Props> = (props) => {
/> />
) : ( ) : (
<span className="grid h-9 w-9 place-items-center rounded bg-gray-700 px-3 py-1.5 uppercase text-white"> <span className="grid h-9 w-9 place-items-center rounded bg-gray-700 px-3 py-1.5 uppercase text-white">
{invitedWorkspace.name[0]} {invitedWorkspace?.name[0]}
</span> </span>
)} )}
</div> </div>
</div> </div>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<div className="text-sm font-medium">{truncateText(invitedWorkspace.name, 30)}</div> <div className="text-sm font-medium">{truncateText(invitedWorkspace?.name, 30)}</div>
<p className="text-xs text-custom-text-200">{ROLE[invitation.role]}</p> <p className="text-xs text-custom-text-200">{ROLE[invitation.role]}</p>
</div> </div>
<span className={`flex-shrink-0 ${isSelected ? "text-custom-primary-100" : "text-custom-text-200"}`}> <span className={`flex-shrink-0 ${isSelected ? "text-custom-primary-100" : "text-custom-text-200"}`}>

View File

@ -19,20 +19,30 @@ export const MemberSelect: React.FC<Props> = observer((props) => {
project: { projectMemberIds, getProjectMemberDetails }, project: { projectMemberIds, getProjectMemberDetails },
} = useMember(); } = useMember();
const options = projectMemberIds?.map((userId) => { const options = projectMemberIds
const memberDetails = getProjectMemberDetails(userId); ?.map((userId) => {
const memberDetails = getProjectMemberDetails(userId);
return { if (!memberDetails?.member) return;
value: `${memberDetails?.member.id}`,
query: `${memberDetails?.member.display_name}`, return {
content: ( value: `${memberDetails?.member.id}`,
<div className="flex items-center gap-2"> query: `${memberDetails?.member.display_name}`,
<Avatar name={memberDetails?.member.display_name} src={memberDetails?.member.avatar} /> content: (
{memberDetails?.member.display_name} <div className="flex items-center gap-2">
</div> <Avatar name={memberDetails?.member.display_name} src={memberDetails?.member.avatar} />
), {memberDetails?.member.display_name}
}; </div>
}); ),
};
})
.filter((option) => !!option) as
| {
value: string;
query: string;
content: React.JSX.Element;
}[]
| undefined;
const selectedOption = getProjectMemberDetails(value); const selectedOption = getProjectMemberDetails(value);
return ( return (

View File

@ -59,4 +59,23 @@ export class RootStore {
this.projectPages = new ProjectPageStore(this); this.projectPages = new ProjectPageStore(this);
this.dashboard = new DashboardStore(this); this.dashboard = new DashboardStore(this);
} }
resetOnSignout() {
this.workspaceRoot = new WorkspaceRootStore(this);
this.projectRoot = new ProjectRootStore(this);
this.memberRoot = new MemberRootStore(this);
// independent stores
this.cycle = new CycleStore(this);
this.module = new ModulesStore(this);
this.projectView = new ProjectViewStore(this);
this.globalView = new GlobalViewStore(this);
this.issue = new IssueRootStore(this);
this.inbox = new InboxRootStore(this);
this.state = new StateStore(this);
this.label = new LabelStore(this);
this.estimate = new EstimateStore(this);
this.mention = new MentionStore(this);
this.projectPages = new ProjectPageStore(this);
this.dashboard = new DashboardStore(this);
}
} }

View File

@ -249,6 +249,8 @@ export class UserRootStore implements IUserRootStore {
this.currentUserError = null; this.currentUserError = null;
this.isUserLoggedIn = false; this.isUserLoggedIn = false;
}); });
this.membership = new UserMembershipStore(this.rootStore);
this.rootStore.resetOnSignout();
}); });
/** /**
@ -261,5 +263,7 @@ export class UserRootStore implements IUserRootStore {
this.currentUser = null; this.currentUser = null;
this.isUserLoggedIn = false; this.isUserLoggedIn = false;
}); });
this.membership = new UserMembershipStore(this.rootStore);
this.rootStore.resetOnSignout();
}); });
} }