def post(self, request, organization): ip_address = request.META["REMOTE_ADDR"] if ratelimiter.is_limited( u"org-join-request:ip:{}".format(ip_address), limit=5, window=60 # 5 per minute ): return Response({"detail": "Rate limit exceeded."}, status=429) serializer = JoinRequestSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=400) result = serializer.validated_data email = result["email"] assignment = experiments.get(org=organization, experiment_name=JOIN_REQUEST_EXPERIMENT) if assignment != 1: return Response(status=403) create_organization_join_request(organization, email, ip_address) return Response(status=204)
def post(self, request, organization): assignment = experiments.get(org=organization, experiment_name=JOIN_REQUEST_EXPERIMENT) if assignment != 1: return Response(status=403) if organization.get_option("sentry:join_requests") is False: return Response( {"detail": "Your organization does not allow join requests."}, status=403) # users can already join organizations with SSO enabled without an invite # so no need to allow requests to join as well if AuthProvider.objects.filter(organization=organization).exists(): return Response(status=403) ip_address = request.META["REMOTE_ADDR"] if ratelimiter.is_limited( u"org-join-request:ip:{}".format(ip_address), limit=5, window=60 # 5 per minute ): return Response({"detail": "Rate limit exceeded."}, status=429) serializer = JoinRequestSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=400) result = serializer.validated_data email = result["email"] create_organization_join_request(organization, email, ip_address) return Response(status=204)
def get(self, request, organization): """ Retrieve the list of rule conditions """ def info_extractor(rule_cls): context = {"id": rule_cls.id, "label": rule_cls.label} if hasattr(rule_cls, "form_fields"): context["formFields"] = rule_cls.form_fields return context experiment_variant = experiments.get( org=organization, experiment_name="AlertDefaultsExperiment" ) if experiment_variant == "3OptionsV1": return Response( [ info_extractor(rule_cls) for rule_type, rule_cls in rules if rule_type.startswith("condition/") ] ) elif experiment_variant == "2OptionsV1": return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_404_NOT_FOUND)
def post(self, request, organization): """ Add a invite request to Organization ```````````````````````````````````` Creates an invite request given an email and sugested role / teams. :pparam string organization_slug: the slug of the organization the member will belong to :param string email: the email address to invite :param string role: the suggested role of the new member :param array teams: the suggested slugs of the teams the member should belong to. :auth: required """ variant = experiments.get(org=organization, experiment_name="ImprovedInvitesExperiment") if variant not in ("all", "invite_request"): return Response(status=403) serializer = OrganizationMemberSerializer( data=request.data, context={ "organization": organization, "allowed_roles": roles.get_all() }, ) if not serializer.is_valid(): return Response(serializer.errors, status=400) result = serializer.validated_data with transaction.atomic(): om = OrganizationMember.objects.create( organization=organization, email=result["email"], role=result["role"], inviter=request.user, invite_status=InviteStatus.REQUESTED_TO_BE_INVITED.value, ) if result["teams"]: lock = locks.get(u"org:member:{}".format(om.id), duration=5) with TimedRetryPolicy(10)(lock.acquire): save_team_assignments(om, result["teams"]) self.create_audit_entry( request=request, organization_id=organization.id, target_object=om.id, data=om.get_audit_log_data(), event=AuditLogEntryEvent.INVITE_REQUEST_ADD, ) om.send_request_notification_email() return Response(serialize(om), status=201)
def get_join_request_link(self, organization): if not organization: return None assignment = experiments.get(org=organization, experiment_name=JOIN_REQUEST_EXPERIMENT) if assignment != 1: return None if organization.get_option("sentry:join_requests") is False: return None return reverse("sentry-join-request", args=[organization.slug])
def get_join_request_link(self, organization): if not organization: return None variant = experiments.get(org=organization, experiment_name="ImprovedInvitesExperiment") if variant not in ("all", "join_request"): return None if organization.get_option("sentry:join_requests") is False: return None join_request_link_viewed.send_robust(sender=self, organization=organization) return reverse("sentry-join-request", args=[organization.slug])
def get(self, request, organization): """ Retrieve the list of rule conditions """ def info_extractor(rule_cls): context = {"id": rule_cls.id, "label": rule_cls.label} if hasattr(rule_cls, "form_fields"): context["formFields"] = rule_cls.form_fields return context # TODO(Jeff): Rename to `AlertDefaultsExperiment` on real experiment run if experiments.get(org=organization, experiment_name="AlertDefaultsExperimentTmp") != 1: return Response(status=status.HTTP_404_NOT_FOUND) return Response([ info_extractor(rule_cls) for rule_type, rule_cls in rules if rule_type.startswith("condition/") ])
def post(self, request, organization): variant = experiments.get(org=organization, experiment_name="ImprovedInvitesExperiment") if variant not in ("all", "join_request"): return Response(status=403) if organization.get_option("sentry:join_requests") is False: return Response( {"detail": "Your organization does not allow join requests."}, status=403) # users can already join organizations with SSO enabled without an invite # so they should join that way and not through a request to the admins if AuthProvider.objects.filter(organization=organization).exists(): return Response(status=403) ip_address = request.META["REMOTE_ADDR"] if ratelimiter.is_limited( u"org-join-request:ip:{}".format(ip_address), limit=5, window=86400, # 5 per day, 60 x 60 x 24 ): return Response({"detail": "Rate limit exceeded."}, status=429) serializer = JoinRequestSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=400) result = serializer.validated_data email = result["email"] member = create_organization_join_request(organization, email, ip_address) if member: send_invite_request_notification_email.delay(member.id) join_request_created.send_robust(sender=self, member=member) return Response(status=204)