Hello again,
This time I have problem with access control tables. I have 2 tables like these:
Menu Table
------------------------------------------------------------------------- | id | parent | caption | link | ------------------------------------------------------------------------- | mc_transaction | null | Transaction | null | | mc_report | null | Report | null | | mc_transaction_sale | mc_transaction | Sale | transaction/sale | | mc_transaction_purc | mc_transaction | Purchase | transaction/purc | | mc_report_sale | mc_report | Sale | report/sale | | mc_report_purc | mc_report | Purchase | report/purc | | mc_report_stock | mc_report | Stock | null | | mc_report_stock_top | mc_report | Top Active | report/top | | mc_report_stock_vol | mc_report | Stock Volume| report/volumes | -------------------------------------------------------------------------
Access Table
------------------------------------------- | group_id | module_id | access | ------------------------------------------- | admin | mc_transaction_sale | 0b1111 | | admin | mc_transaction_purc | 0b1111 | | admin | mc_report_sale | 0b1111 | | admin | mc_report_purc | 0b1111 | | admin | mc_report_stock_top | 0b1111 | | admin | mc_report_stock_vol | 0b1111 | | oper | mc_transaction_sale | 0b1100 | | oper | mc_transaction_purc | 0b1100 | | manager | mc_transaction_sale | 0b0100 | | manager | mc_transaction_purc | 0b0100 | | manager | mc_report_sale | 0b1111 | | manager | mc_report_purc | 0b1111 | | manager | mc_report_stock_top | 0b1111 | | manager | mc_report_stock_vol | 0b1111 | -------------------------------------------
The ones in bold are primary keys.
Now, module_id represent my modules, it will be used by each modules to authorize user against the access privilege.
I intend to remove all that have "null" links from access table and generate the parents as necessary all the way to top. That way the only visible to user is their customized menu, and they won't see a thing they shouldn't access. I need to rebuild the module parents to a memory based tree before create a UL menu.
I have tried created a view that joins those 2 tables, but I can't set acts as tree to only gather those links with specified group_id. The other solution is to create another tree but how can I gather all necessary parents all the way to topmost menu? And how can I insert and remove a parent nodes on Ruby?
Any idea on how to solve this in Ruby?
Thank you
EDIT: I can use some kind of TreeNode on Java. Is there any in Ruby? Anyone? Nobody can help?