@@ -653,8 +653,9 @@ private static OpenApiParameter GetOpenApiQueryParameter(string name, string des
653653 /// </summary>
654654 /// <param name="entity">The entity.</param>
655655 /// <param name="dbObject">Database object metadata, indicating entity SourceType</param>
656+ /// <param name="role">Optional role to filter permissions. If null, returns superset of all roles.</param>
656657 /// <returns>Collection of OpenAPI OperationTypes and whether they should be created.</returns>
657- private static Dictionary < OperationType , bool > GetConfiguredRestOperations ( Entity entity , DatabaseObject dbObject )
658+ private static Dictionary < OperationType , bool > GetConfiguredRestOperations ( Entity entity , DatabaseObject dbObject , string ? role = null )
658659 {
659660 Dictionary < OperationType , bool > configuredOperations = new ( )
660661 {
@@ -708,48 +709,55 @@ private static Dictionary<OperationType, bool> GetConfiguredRestOperations(Entit
708709 }
709710 else
710711 {
711- // For tables/views, determine available operations from permissions (superset of all roles)
712+ // For tables/views, determine available operations from permissions
713+ // If role is specified, filter to that role only; otherwise, get superset of all roles
712714 if ( entity ? . Permissions is not null )
713715 {
714716 foreach ( EntityPermission permission in entity . Permissions )
715717 {
716- if ( permission . Actions is null )
718+ // Skip permissions for other roles if a specific role is requested
719+ if ( role is not null && ! string . Equals ( permission . Role , role , StringComparison . OrdinalIgnoreCase ) )
717720 {
718721 continue ;
719722 }
720723
721- foreach ( EntityAction action in permission . Actions )
722- {
723- if ( action . Action == EntityActionOperation . All )
724+ if ( permission . Actions is null )
724725 {
725- configuredOperations [ OperationType . Get ] = true ;
726- configuredOperations [ OperationType . Post ] = true ;
727- configuredOperations [ OperationType . Put ] = true ;
728- configuredOperations [ OperationType . Patch ] = true ;
729- configuredOperations [ OperationType . Delete ] = true ;
726+ continue ;
730727 }
731- else
728+
729+ foreach ( EntityAction action in permission . Actions )
732730 {
733- switch ( action . Action )
731+ if ( action . Action == EntityActionOperation . All )
734732 {
735- case EntityActionOperation . Read :
736- configuredOperations [ OperationType . Get ] = true ;
737- break ;
738- case EntityActionOperation . Create :
739- configuredOperations [ OperationType . Post ] = true ;
740- break ;
741- case EntityActionOperation . Update :
742- configuredOperations [ OperationType . Put ] = true ;
743- configuredOperations [ OperationType . Patch ] = true ;
744- break ;
745- case EntityActionOperation . Delete :
746- configuredOperations [ OperationType . Delete ] = true ;
747- break ;
733+ configuredOperations [ OperationType . Get ] = true ;
734+ configuredOperations [ OperationType . Post ] = true ;
735+ configuredOperations [ OperationType . Put ] = true ;
736+ configuredOperations [ OperationType . Patch ] = true ;
737+ configuredOperations [ OperationType . Delete ] = true ;
738+ }
739+ else
740+ {
741+ switch ( action . Action )
742+ {
743+ case EntityActionOperation . Read :
744+ configuredOperations [ OperationType . Get ] = true ;
745+ break ;
746+ case EntityActionOperation . Create :
747+ configuredOperations [ OperationType . Post ] = true ;
748+ break ;
749+ case EntityActionOperation . Update :
750+ configuredOperations [ OperationType . Put ] = true ;
751+ configuredOperations [ OperationType . Patch ] = true ;
752+ break ;
753+ case EntityActionOperation . Delete :
754+ configuredOperations [ OperationType . Delete ] = true ;
755+ break ;
756+ }
748757 }
749758 }
750759 }
751760 }
752- }
753761 }
754762
755763 return configuredOperations ;
@@ -758,7 +766,10 @@ private static Dictionary<OperationType, bool> GetConfiguredRestOperations(Entit
758766 /// <summary>
759767 /// Checks if an entity has any available REST operations based on its permissions.
760768 /// </summary>
761- private static bool HasAnyAvailableOperations ( Entity entity )
769+ /// <param name="entity">The entity to check.</param>
770+ /// <param name="role">Optional role to filter permissions. If null, checks all roles.</param>
771+ /// <returns>True if the entity has any available operations.</returns>
772+ private static bool HasAnyAvailableOperations ( Entity entity , string ? role = null )
762773 {
763774 if ( entity ? . Permissions is null || entity . Permissions . Length == 0 )
764775 {
@@ -767,6 +778,12 @@ private static bool HasAnyAvailableOperations(Entity entity)
767778
768779 foreach ( EntityPermission permission in entity . Permissions )
769780 {
781+ // Skip permissions for other roles if a specific role is requested
782+ if ( role is not null && ! string . Equals ( permission . Role , role , StringComparison . OrdinalIgnoreCase ) )
783+ {
784+ continue ;
785+ }
786+
770787 if ( permission . Actions ? . Length > 0 )
771788 {
772789 return true ;
@@ -777,13 +794,14 @@ private static bool HasAnyAvailableOperations(Entity entity)
777794 }
778795
779796 /// <summary>
780- /// Filters the exposed column names based on the superset of available fields across all role permissions.
781- /// A field is included if at least one role has access to it (through include/exclude settings) .
797+ /// Filters the exposed column names based on the superset of available fields across role permissions.
798+ /// A field is included if at least one role (or the specified role) has access to it.
782799 /// </summary>
783800 /// <param name="entity">The entity to check permissions for.</param>
784801 /// <param name="exposedColumnNames">All exposed column names from the database.</param>
802+ /// <param name="role">Optional role to filter permissions. If null, returns superset of all roles.</param>
785803 /// <returns>Filtered set of column names that are available based on permissions.</returns>
786- private static HashSet < string > FilterFieldsByPermissions ( Entity entity , HashSet < string > exposedColumnNames )
804+ private static HashSet < string > FilterFieldsByPermissions ( Entity entity , HashSet < string > exposedColumnNames , string ? role = null )
787805 {
788806 if ( entity ? . Permissions is null || entity . Permissions . Length == 0 )
789807 {
@@ -794,6 +812,12 @@ private static HashSet<string> FilterFieldsByPermissions(Entity entity, HashSet<
794812
795813 foreach ( EntityPermission permission in entity . Permissions )
796814 {
815+ // Skip permissions for other roles if a specific role is requested
816+ if ( role is not null && ! string . Equals ( permission . Role , role , StringComparison . OrdinalIgnoreCase ) )
817+ {
818+ continue ;
819+ }
820+
797821 if ( permission . Actions is null )
798822 {
799823 continue ;
0 commit comments