@require_setting('MATRIX_ACCESS_TOKEN')
@login_required
def add_matrix(request, code):
    project = _get_rw_project_for_user(request, code)
    if (request.method == 'POST'):
        form = forms.AddMatrixForm(request.POST)
        if form.is_valid():
            channel = Channel(project=project, kind='matrix')
            channel.value = form.cleaned_data['room_id']
            alias = form.cleaned_data['alias']
            if (not alias.startswith('!')):
                channel.name = alias
            channel.save()
            channel.assign_all_checks()
            messages.success(request, 'The Matrix integration has been added!')
            return redirect('hc-channels', project.code)
    else:
        form = forms.AddMatrixForm()
    ctx = {'page': 'channels', 'project': project, 'form': form, 'matrix_user_id': settings.MATRIX_USER_ID}
    return render(request, 'integrations/add_matrix.html', ctx)
@require_setting('MATRIX_ACCESS_TOKEN')
@login_required
def add_matrix(request, code):
    project = _get_rw_project_for_user(request, code)
    if (request.method == 'POST'):
        form = forms.AddMatrixForm(request.POST)
        if form.is_valid():
            channel = Channel(project=project, kind='matrix')
            channel.value = form.cleaned_data['room_id']
            alias = form.cleaned_data['alias']
            if (not alias.startswith('!')):
                channel.name = alias
            channel.save()
            channel.assign_all_checks()
            messages.success(request, 'The Matrix integration has been added!')
            return redirect('hc-channels', project.code)
    else:
        form = forms.AddMatrixForm()
    ctx = {'page': 'channels', 'project': project, 'form': form, 'matrix_user_id': settings.MATRIX_USER_ID}
    return render(request, 'integrations/add_matrix.html', ctx)