Find

Article
· Aug 26, 2024 1m read

Unwrap roles recursively

Recently I got into a situation where a user had some roles, which granted additional roles, and so on.

As I did not understand where a particular permission came from, I wrote this code which gets an initial set of roles and unwraps them recursively, accounting for any repeats.

/// Recursively unwraps roleset.
/// Accounts for circular dependencies and repeats.
Class Utils.Roles
{

/// roles: comma-separated string of roles
/// showResources: show resources in addition to roles.
/// do ##class(Utils.Roles).Display
ClassMethod Display(roles As %String, showResources As %Boolean = {$$$NO})
{
	new $namespace
	set $namespace = "%SYS"
	set roles = $lfs(roles)
	set i=0
	while i<$ll(roles) {
		do $i(i)
		set role = $lg(roles, i)
		continue:$d(processed(role))=1
		write "Current role: ", role,!
		
		write "Grants roles: "
		set sc = ##class(Security.Roles).Get(role, .p)
		for j=1:1:$l($g(p("GrantedRoles")),",") {
			set grantedrole = $p(p("GrantedRoles"),",", j)
			continue:grantedrole=""
			continue:$lf(roles, grantedrole)
			
			write grantedrole, ", "	
			
			set roles = roles _ $lb(grantedrole)
		}
		
		write:showResources !, "Grants resources: ", p("Resources")
		write !
	}
}

}
 
Spoiler

Code.

2 Comments
Discussion (2)2
Log in or sign up to continue
Announcement
· Aug 26, 2024

[Video] IA Generativa em Uso

Olá, Comunidade!

Você acha que a IA Generativa pode tornar sua vida mais fácil? Veja alguns casos de uso em potencial para GenAI no vídeo mais recente do Learning Services:

Generative AI in Use

Descubra como o GenAI está impactando tudo, desde a área da saúde até o desenvolvimento de software, e como ele pode ser usado para melhorar a produtividade e aumentar a eficiência.

👩‍💻 Pronto para tentar você mesmo?
Aprenda como melhorar suas habilidades de escrita de prompts para aproveitar ao máximo a IA generativa (exercício, 40m).

Discussion (0)1
Log in or sign up to continue
Question
· Aug 26, 2024

Send a request from a class to a different server business service

I have this code and I need to send 

Set tRequest= ##class(Testing.Messages.GatewayCreateFacilityRequest).%New()

Set tRequest.facilityCode ="VINUSE"

 Set tResponse = ##class(Testing.Messages.GatewayCreateFacilityResponse).%New()

need to send a request to a new server:

Server: ECR10 

Namespace: ECR

Business Service: Healthix.Common.Verato.Gateway.Service.HubQueryService

set tResponse = ##class(Testing.Gateway.Service.HubQueryService).%New().CreateFacility(tRequest)

How do I add code to send it to the ECR10 server?

5 Comments
Discussion (5)2
Log in or sign up to continue
Announcement
· Aug 26, 2024

[Video] Pesando os benefícios e riscos da IA ​​generativa

Olá Comunidade!

Como você pode criar uma abordagem equilibrada para usar Generative AI? Obtenha ajuda de especialistas da InterSystems no vídeo mais recente da Learning Services:

Weighing the Benefits and Risks of Generative AI

Aprenda alguns dos principais benefícios do uso de IA generativa, além de estratégias para minimizar riscos — nesta conversa com:

Inscreva-se no canal Learning Services YouTube!

Discussion (0)1
Log in or sign up to continue
Digest
· Aug 26, 2024

Publicações Desenvolvedores InterSystems, Agosto 19 - 25, 2024, Resumo

Agosto 19 - 25, 2024Week at a GlanceInterSystems Developer Community