datastorm-open / shinymanager

Simple and secure authentification mechanism for single shiny applications.
https://datastorm-open.github.io/shinymanager/
386 stars 79 forks source link

Assign user to multiple user groups #74

Closed pythiantech closed 3 years ago

pythiantech commented 3 years ago

Thank you for creating this excellent package!

This is not a bug. I was wondering if it would be possible to assign a user to multiple groups. In my Shiny application, based on the group that the logged in user belongs to, I am hiding or showing content. However there is a requirement to have a certain user have access to content which is visible to 2 different groups (not admin group). Would it be possible to have this feature?

Wladimir-Sanyer commented 3 years ago

Hello, sorry to bother you but I am making a similar application I would like to know if you found a solution to hide / show things to different users, I tried with an if and input$ go_auth but it did not work for me, you would help me a lot, giving me an idea of ​​your solution

`observeEvent(input$go_auth,{ if (auth$user_info$access=='manager'){ appendTab(inputId = "intabset", tabPanel( title = "Admin", icon = icon("chart-line"), mainPanel(width = 12, style="margin-left:4%; margin-right:4%"), fluidPage(fluidRow( column(12,box(title=" ",status="primary",solidHeader = T,width = 12,align="justify"))) )))

        }else if (auth$user_info$access=="modific"){
            removeTab(inputId = "intabset", 
            )

        }

    }) `
pythiantech commented 3 years ago

@Wladimir-Sanyer like I mentioned, my Shiny application has multiple tabs. Based on the user_group I am using the hideTab() function to hide tabs that I don't want displayed.

res_auth <- secure_server(
        check_credentials = check_credentials(
            'data/users.sqlite'
        )
    )

    observe({
        if(!is.null(res_auth$user)) {
           if(res_auth$user_group == 'faculty') {
            hideTab('nav', 'Course Scheduling', session = getDefaultReactiveDomain())
            hideTab('nav', 'Academic', session = getDefaultReactiveDomain())
            hideTab('nav', 'Onboarding', session = getDefaultReactiveDomain())
            hideTab('nav', 'QP', session = getDefaultReactiveDomain())
            hideTab('nav', 'Simulators', session = getDefaultReactiveDomain())
           } else if(res_auth$user_group == 'student') {
               hideTab('nav', 'Course Scheduling', session = getDefaultReactiveDomain())
               hideTab('nav', 'Academic', session = getDefaultReactiveDomain())
               hideTab('nav', 'QP', session = getDefaultReactiveDomain())
               hideTab('nav', 'Simulators', session = getDefaultReactiveDomain())
           } else if(res_auth$user_group != 'admin') {
              hideTab('nav', 'Edit Database', session = getDefaultReactiveDomain())
            }
        } 
    })