User Permissions: Create multiple checkboxes each related to one bit of an integer field

User Permissions: Create multiple checkboxes each related to one bit of an integer field

jhenryjhenry Posts: 11Questions: 1Answers: 0

We have a slew of pages that different users have different access to. Using Datatables Editor, is it possible to create a form that would allow for multiple checkboxes (64 max with 64-bit field) to be created ad related to one field?

The one field is a 'permissions' field, a 64-bit integer. We have it setup so that each bit that is set in the field grants access to a certain web page....like a users privileges in a database. I am hoping to create an admin page that will allow for simple assignment of user permissions via a checkboxe for each bit as opposed to the way I do it now.....manually, directly in the database.

Am I dreaming here or do I click 'Buy Now'?

Replies

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    Ouch - you are setting 64 bit binary fields manually in the db!? I can see why you might want to get away from that.

    There isn't an out of the box answer to this question I'm afraid, but there are two ways in which it could be done:

    1. Use a custom field that would accept an integer number as a value and split it into its binary components on value set, and then combine the checkbox states back into an integer on get.
    2. Use get and set formatters on the server-side to do the split and combine. Then on the client-side, all it would see is an ordered array for which you could use the checkbox input type.

    I think of those two I would probably prefer option 1 - I think it would be the most flexible of those two.

    That said, for more flexibility I would actually suggest a different approach - a one-to-many join between users and permissions tables. See this example. A bit array if fine, but maintenance of it can be difficult. For example when you go beyond 64 permission types, or if you want to retire an old one. A one-to-many join doesn't have that issue and it also works out of the box with the checkbox input. It would be a new schema design though...!

    Allan

  • jhenryjhenry Posts: 11Questions: 1Answers: 0

    Yes I do...I did bring it on myself though.

    Thanks for the input. I will attempt option 1...just for the sake of learning more about the editors custom features.

    I do however agree that the tables approach would be more flexible. I will implement that approach in the end. My background is more firmware/robotics so space mattered....hence the bit-wise implementation. But, in today's world of $100 terabyte drives, space isn't near as much of an issue. Thanks for the consult.

This discussion has been closed.