| 197 | return self.current_team |
| 198 | |
| 199 | def join( |
| 200 | self, *, organization: Organization, level: OrganizationMembership.Level = OrganizationMembership.Level.MEMBER |
| 201 | ) -> OrganizationMembership: |
| 202 | with transaction.atomic(): |
| 203 | membership = OrganizationMembership.objects.create(user=self, organization=organization, level=level) |
| 204 | self.current_organization = organization |
| 205 | if ( |
| 206 | AvailableFeature.PROJECT_BASED_PERMISSIONING not in organization.available_features |
| 207 | or level >= OrganizationMembership.Level.ADMIN |
| 208 | ): |
| 209 | # If project access control is NOT applicable, simply prefer open projects just in case |
| 210 | self.current_team = organization.teams.order_by("access_control", "id").first() |
| 211 | else: |
| 212 | # If project access control IS applicable, make sure the user is assigned a project they have access to |
| 213 | # We don't need to check for ExplicitTeamMembership as none can exist for a completely new member |
| 214 | self.current_team = organization.teams.order_by("id").filter(access_control=False).first() |
| 215 | self.save() |
| 216 | return membership |
| 217 | |
| 218 | @property |
| 219 | def notification_settings(self) -> Notifications: |