Tychobra / polished

Authentication and Administration for Shiny apps
https://polished.tech
Other
234 stars 36 forks source link

Can't Assign or Create Roles #60

Closed fernrees closed 4 years ago

fernrees commented 4 years ago

I can't figure out role creation.

When I try to assign roles in user creation with the following code:

polished::create_app_user( db_conn, app_name = "app_name", email = "email", is_admin = F, roles= "LST" )

I get this error:

Error: COPY returned error: ERROR: invalid input syntax for type uuid: "LST" CONTEXT: COPY user_roles, line 1, column role_uid: "LST"

I can create roles in the admin console, but when I try to assign them in there it gives me the following error in the RStudio console:

<Rcpp::exception: COPY returned error: ERROR: null value in column "uid" violates not-null constraint DETAIL: Failing row contains (null, 83a75913-8682-4e73-984b-df9ed4402313, c95ef901-e6dc-4651-a6dc-4cb783ea4aae, polished-iwwgdc, eb5225dc-752b-4201-bbbd-2468c89f3f05, 2020-03-22 16:55:55.384194+00). CONTEXT: COPY user_roles, line 1: "83a75913-8682-4e73-984b-df9ed4402313 c95ef901-e6dc-4651-a6dc-4cb783ea4aae polished-iwwgdc eb5225dc-7...">

Also even after adding roles in that console the postgresql db shows the user_roles table as empty.

merlinoa commented 4 years ago

thanks @cerees . This should be fixed with 3b1e6f9dacc4de1df49229862ca378839854a33c and e5735e7a9fa7d4790e0a9effe5f61088d364d370.

Please reopen if you are still having issues.

FYI - I am planning on removing the user roles from polished as it is not widely used. Let me know if you have a good use case for them.

fernrees commented 4 years ago

I very much like the feature. I'm using it for conditional output. Basic users can view aggregate data, but users with certain role assignments can view more granular individual-level data about their organization.

Would there be an alternative way of doing this without roles?

diegollarrull commented 4 years ago

Please don't remove roles! My entire application renders selectively based on the roles of each user. This is core functionality in every application that handles multiple users.

fernrees commented 4 years ago

I also really like the roles feature.

merlinoa commented 4 years ago

@diegollarrull and @cerees Sorry for the inconvenience, but roles have already been removed. I hope to bring them back at some point, but I was not happy with the previous implementation.

If you need "roles" in your application immediately, you can create a data frame in "global.R" with the user's email and their role, and attach the role to the session$userData$user() at the start of your server function. i.e.

# global.R

roles <- tibble(
  "email" = "user_w_role@example.com",
  "role" = "role_1"
)
# server.R

observe({
  user <- session$userData$user()

  user$roles <- roles %>%
    filter(email == user$email) %>%
    pull("role")

  session$userData$user(user)
})

Once again sorry for this inconvenience. I hope to not have any more breaking changes of this magnitude moving forward.