def process_inbound_email(mailfrom, group_id, payload): """ """ from sentry.models import Event, Group from sentry.web.forms import NewNoteForm try: group = Group.objects.select_related("project", "team").get(pk=group_id) except Group.DoesNotExist: logger.warning("Group does not exist: %d", group_id) return user = _get_user_from_email(group, mailfrom) if user is None: logger.warning("Inbound email from unknown address: %s", mailfrom) return event = group.get_latest_event() if event: Event.objects.bind_nodes([event], "data") event.group = group event.project = group.project form = NewNoteForm({"text": payload}) if form.is_valid(): form.save(group, user, event=event)
def process_inbound_email(mailfrom, group_id, payload): """ """ from sentry.models import Event, Group from sentry.web.forms import NewNoteForm try: group = Group.objects.select_related('project', 'team').get(pk=group_id) except Group.DoesNotExist: logger.warning('Group does not exist: %d', group_id) return user = _get_user_from_email(group, mailfrom) if user is None: logger.warning('Inbound email from unknown address: %s', mailfrom) return event = group.get_latest_event() or Event() Event.objects.bind_nodes([event], 'data') event.group = group event.project = group.project form = NewNoteForm({'text': payload}) if form.is_valid(): form.save(event, user)
def process_inbound_email(mailfrom, group_id, payload): """ """ from sentry.models import Group from sentry.web.forms import NewNoteForm try: group = Group.objects.select_related("project").get(pk=group_id) except Group.DoesNotExist: logger.warning("Group does not exist: %d", group_id) return user = _get_user_from_email(group, mailfrom) if user is None: logger.warning("Inbound email from unknown address: %s", mailfrom) return event = group.get_latest_event() if event: event.bind_node_data() event.group = group event.project = group.project form = NewNoteForm({"text": payload}) if form.is_valid(): form.save(group, user, event=event)
def group(request, team, project, group, event_id=None): # It's possible that a message would not be created under certain # circumstances (such as a post_save signal failing) if event_id: event = get_object_or_404(group.event_set, id=event_id) else: event = group.get_latest_event() or Event() Event.objects.bind_nodes([event], 'data') # bind params to group in case they get hit event.group = group event.project = project if request.POST.get('o') == 'note' and request.user.is_authenticated(): add_note_form = NewNoteForm(request.POST) if add_note_form.is_valid(): add_note_form.save(event, request.user) return HttpResponseRedirect(request.path) else: add_note_form = NewNoteForm() activity_qs = Activity.objects.order_by('-datetime').select_related('user') # if event_id: # activity_qs = activity_qs.filter( # Q(event=event) | Q(event__isnull=True), # ) if project in Project.objects.get_for_user(request.user, team=team, superuser=False): # update that the user has seen this group create_or_update(GroupSeen, group=group, user=request.user, project=project, defaults={ 'last_seen': timezone.now(), }) # filter out dupe activity items activity_items = set() activity = [] for item in activity_qs.filter(group=group)[:20]: sig = (item.event_id, item.type, item.ident, item.user_id) # TODO: we could just generate a signature (hash(text)) for notes # so theres no special casing if item.type == Activity.NOTE: activity.append(item) elif sig not in activity_items: activity_items.add(sig) activity.append(item) activity.append( Activity(project=project, group=group, type=Activity.FIRST_SEEN, datetime=group.first_seen)) # trim to latest 5 activity = activity[:7] seen_by = sorted(filter(lambda ls: ls[0] != request.user and ls[0].email, [ (gs.user, gs.last_seen) for gs in GroupSeen.objects.filter(group=group).select_related('user') ]), key=lambda ls: ls[1], reverse=True) seen_by_extra = len(seen_by) - 5 if seen_by_extra < 0: seen_by_extra = 0 seen_by_faces = seen_by[:5] context = { 'add_note_form': add_note_form, 'page': 'details', 'activity': activity, 'seen_by': seen_by, 'seen_by_faces': seen_by_faces, 'seen_by_extra': seen_by_extra, } is_public = group_is_public(group, request.user) if is_public: template = 'sentry/groups/public_details.html' context['PROJECT_LIST'] = [project] else: template = 'sentry/groups/details.html' return render_with_group_context(group, template, context, request, event=event, is_public=is_public)
def group(request, team, project, group, event_id=None): # It's possible that a message would not be created under certain # circumstances (such as a post_save signal failing) if event_id: event = get_object_or_404(group.event_set, id=event_id) else: event = group.get_latest_event() or Event() Event.objects.bind_nodes([event], "data") # bind params to group in case they get hit event.group = group event.project = project if request.POST.get("o") == "note" and request.user.is_authenticated(): add_note_form = NewNoteForm(request.POST) if add_note_form.is_valid(): add_note_form.save(event, request.user) return HttpResponseRedirect(request.path) else: add_note_form = NewNoteForm() if project in Project.objects.get_for_user(request.user, team=team, superuser=False): # update that the user has seen this group create_or_update( GroupSeen, group=group, user=request.user, project=project, defaults={"last_seen": timezone.now()} ) activity_qs = Activity.objects.filter(group=group).order_by("-datetime").select_related("user") # filter out dupe activity items activity_items = set() activity = [] for item in activity_qs[:20]: sig = (item.event_id, item.type, item.ident, item.user_id) # TODO: we could just generate a signature (hash(text)) for notes # so there's no special casing if item.type == Activity.NOTE: activity.append(item) elif sig not in activity_items: activity_items.add(sig) activity.append(item) activity.append(Activity(project=project, group=group, type=Activity.FIRST_SEEN, datetime=group.first_seen)) # trim to latest 5 activity = activity[:7] seen_by = sorted( filter( lambda ls: ls[0] != request.user and ls[0].email, [(gs.user, gs.last_seen) for gs in GroupSeen.objects.filter(group=group).select_related("user")], ), key=lambda ls: ls[1], reverse=True, ) seen_by_extra = len(seen_by) - 5 if seen_by_extra < 0: seen_by_extra = 0 seen_by_faces = seen_by[:5] context = { "add_note_form": add_note_form, "page": "details", "activity": activity, "seen_by": seen_by, "seen_by_faces": seen_by_faces, "seen_by_extra": seen_by_extra, } is_public = group_is_public(group, request.user) if is_public: template = "sentry/groups/public_details.html" context["PROJECT_LIST"] = [project] else: template = "sentry/groups/details.html" return render_with_group_context(group, template, context, request, event=event, is_public=is_public)
def group(request, team, project, group, event_id=None): # It's possible that a message would not be created under certain # circumstances (such as a post_save signal failing) if event_id: event = get_object_or_404(group.event_set, id=event_id) else: event = group.get_latest_event() or Event() # bind params to group in case they get hit event.group = group event.project = project if request.POST.get('o') == 'note' and request.user.is_authenticated(): add_note_form = NewNoteForm(request.POST) if add_note_form.is_valid(): activity = Activity.objects.create( group=group, event=event, project=project, type=Activity.NOTE, user=request.user, data=add_note_form.cleaned_data ) activity.send_notification() return HttpResponseRedirect(request.path) else: add_note_form = NewNoteForm() activity_qs = Activity.objects.order_by('-datetime').select_related('user') if event: activity_qs = activity_qs.filter( Q(event=event) | Q(event__isnull=True), ) if project in Project.objects.get_for_user( request.user, team=team, superuser=False): # update that the user has seen this group create_or_update( GroupSeen, group=group, user=request.user, project=project, defaults={ 'last_seen': timezone.now(), } ) # filter out dupe activity items activity_items = set() activity = [] for item in activity_qs.filter(group=group)[:20]: sig = (item.event_id, item.type, item.ident, item.user_id) # TODO: we could just generate a signature (hash(text)) for notes # so theres no special casing if item.type == Activity.NOTE: activity.append(item) elif sig not in activity_items: activity_items.add(sig) activity.append(item) activity.append(Activity( project=project, group=group, type=Activity.FIRST_SEEN, datetime=group.first_seen)) # trim to latest 5 activity = activity[:7] seen_by = sorted(filter(lambda ls: ls[0] != request.user and ls[0].email, [ (gs.user, gs.last_seen) for gs in GroupSeen.objects.filter( group=group ).select_related('user') ]), key=lambda ls: ls[1], reverse=True) seen_by_extra = len(seen_by) - 5 if seen_by_extra < 0: seen_by_extra = 0 seen_by_faces = seen_by[:5] context = { 'add_note_form': add_note_form, 'page': 'details', 'activity': activity, 'seen_by': seen_by, 'seen_by_faces': seen_by_faces, 'seen_by_extra': seen_by_extra, } is_public = group_is_public(group, request.user) if is_public: template = 'sentry/groups/public_details.html' context['PROJECT_LIST'] = [project] else: template = 'sentry/groups/details.html' return render_with_group_context( group, template, context, request, event=event, is_public=is_public)
def group_details(request, organization, project, group, event_id=None): # It's possible that a message would not be created under certain # circumstances (such as a post_save signal failing) if event_id: event = get_object_or_404(group.event_set, id=event_id) else: event = group.get_latest_event() or Event() Event.objects.bind_nodes([event], 'data') GroupMeta.objects.populate_cache([group]) # bind params to group in case they get hit event.group = group event.project = project if request.POST.get('o') == 'note' and request.user.is_authenticated(): add_note_form = NewNoteForm(request.POST) if add_note_form.is_valid(): add_note_form.save(event, request.user) return HttpResponseRedirect(request.path) else: add_note_form = NewNoteForm() if request.user.is_authenticated() and project.has_access(request.user): # update that the user has seen this group try: create_or_update( GroupSeen, group=group, user=request.user, project=project, values={ 'last_seen': timezone.now(), } ) except DatabaseError as exc: logging.warn(unicode(exc), exc_info=True) activity_qs = Activity.objects.filter( group=group, ).order_by('-datetime').select_related('user') # filter out dupe activity items activity_items = set() activity = [] for item in activity_qs[:20]: sig = (item.event_id, item.type, item.ident, item.user_id) # TODO: we could just generate a signature (hash(text)) for notes # so there's no special casing if item.type == Activity.NOTE: activity.append(item) elif sig not in activity_items: activity_items.add(sig) activity.append(item) activity.append(Activity( project=project, group=group, type=Activity.FIRST_SEEN, datetime=group.first_seen)) # trim to latest 5 activity = activity[:7] seen_by = sorted(filter(lambda ls: ls[0] != request.user and ls[0].email, [ (gs.user, gs.last_seen) for gs in GroupSeen.objects.filter( group=group ).select_related('user') ]), key=lambda ls: ls[1], reverse=True) seen_by_extra = len(seen_by) - 5 if seen_by_extra < 0: seen_by_extra = 0 seen_by_faces = seen_by[:5] context = { 'add_note_form': add_note_form, 'page': 'details', 'activity': activity, 'seen_by': seen_by, 'seen_by_faces': seen_by_faces, 'seen_by_extra': seen_by_extra, } is_public = group_is_public(group, request.user) if is_public: template = 'sentry/groups/public_details.html' context['PROJECT_LIST'] = [project] else: template = 'sentry/groups/details.html' return render_with_group_context( group, template, context, request, event=event, is_public=is_public)