<commit_before>﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace SupportManager.Web.Infrastructure;

public class TeamMemberFilter : IPageFilter
{
    public void OnPageHandlerSelected(PageHandlerSelectedContext context)
    {
    }

    public void OnPageHandlerExecuting(PageHandlerExecutingContext context)
    {
        if (context.ActionDescriptor.AreaName != "Teams") return;

        if (!int.TryParse(context.RouteData.Values["teamId"]?.ToString(), out var teamId))
        {
            context.Result = new BadRequestResult();
            return;
        }

        if (context.HttpContext.User.HasClaim(SupportManagerClaimTypes.TeamMember, teamId.ToString())) return;

        context.Result = new NotFoundResult();
    }

    public void OnPageHandlerExecuted(PageHandlerExecutedContext context)
    {
    }
}<commit_msg>web/TeamMemberFilter: Restrict team admin access<commit_after>﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace SupportManager.Web.Infrastructure;

public class TeamMemberFilter : IPageFilter
{
    public void OnPageHandlerSelected(PageHandlerSelectedContext context)
    {
    }

    public void OnPageHandlerExecuting(PageHandlerExecutingContext context)
    {
        if (context.ActionDescriptor.AreaName != "Teams") return;

        if (!int.TryParse(context.RouteData.Values["teamId"]?.ToString(), out var teamId))
        {
            context.Result = new BadRequestResult();
            return;
        }

        if (!context.HttpContext.User.HasClaim(SupportManagerClaimTypes.TeamMember, teamId.ToString()))
        {
            context.Result = new NotFoundResult();
            return;
        }

        if (context.ActionDescriptor.ViewEnginePath.StartsWith("/Admin") &&
            !context.HttpContext.User.HasClaim(SupportManagerClaimTypes.TeamAdmin, teamId.ToString()))
        {
            context.Result = new ForbidResult();
            return;
        }
    }

    public void OnPageHandlerExecuted(PageHandlerExecutedContext context)
    {
    }
}
{'fraction_non_alphanumeric': 0.09546769527483125, 'fraction_numerical': 0.0, 'mean_word_length': 3.133466135458167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5708277', 'n_tokens_mistral': 545, 'n_tokens_neox': 548, 'n_words': 96}