1. PRASHANT NIRGUN
  2. PowerBuilder
  3. Friday, 6 March 2020 11:56 AM UTC

I am using PB 12.5.2 I want to implement Access Control List. ie appliction user or user group has right for CRUD if he has the permission he can able to perform the operation. I created acl, user_permission and group_permission table.

CREATE TABLE `acl` (
`acl_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`company_id` int(10) unsigned NOT NULL,
`module_name` varchar(50) NOT NULL, //Menu Option
`module_type` char(1) NOT NULL, //Master, Report, Transaction, Stock
`table_name` varchar(50) NULL, //table name in case of report set it null
`trade` varchar(30) NOT NULL DEFAULT 'Retail',
PRIMARY KEY (`acl_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 

her for each menu option I created a row in acl table. I managed the pb_add, pb_delete, pb_save button by writing a set_permission_wf() inside my base_w its working fine.

Now I want to hide the menu options, I don't want to hard code the it also Its multi-lingual it contain 2 more menu and some vertical that I am managing from acl.trade column.

How do I iterate menu options, toolbar without hard coding. 

Is there any why I can set multiple menu relations with acl row?

PRASHANT NIRGUN Accepted Answer Pending Moderation
  1. Friday, 6 March 2020 18:35 PM UTC
  2. PowerBuilder
  3. # 1

Thanks it works I created a recursive function and used it for sub menu. Issue is resolved. Just in case if any one interested I used men_item.tag property to store acl_id. reasons are as follows. I also says thanks to Topwiz for dynamicMenu In future I will implement it also.

01 We have 2-3 languages and verticals so menu objects are more

02 in Report Menu We have situation like one permission is enough for group of reports like item list, item list 2 columns, item list 3 columns, Item list Group wise

// *********** UDF: set_menu_option_permission_f ***************

global type set_menu_option_permission_f from function_object
end type

forward prototypes
global function integer set_menu_option_permission_f (menu am_menu)
end prototypes

global function integer set_menu_option_permission_f (menu am_menu);Menu lm_sub_menu
Int li_start, li_max, li_answer, li_counter, li_acl_id
String ls_itemname, ls_value
Boolean lb_view, lb_create, lb_update, lb_delete

li_max = UpperBound(am_menu.Item)

For li_start = 1 To li_max
lm_sub_menu = am_menu.Item[li_start]
ls_itemname = lm_sub_menu.Classname()

li_acl_id = Integer(lm_sub_menu.Tag)
IF li_acl_id > 0 Then
get_module_permission_f(li_acl_id, lb_view, lb_create, lb_update, lb_delete)

lm_sub_menu.Enabled = lb_view
lm_sub_menu.Toolbaritemvisible = lb_view
END IF
li_counter += set_menu_option_permission_f(lm_sub_menu)
Next

return li_max + li_counter
end function

 

global type get_all_module_permission_f from function_object
end type

forward prototypes
global subroutine get_all_module_permission_f (integer ai_acl_id, ref boolean ab_view, ref boolean ab_create, ref boolean ab_update, ref boolean ab_delete)
end prototypes

// ************* UDF get_module_permission *****************

global subroutine get_module_permission_f (integer ai_acl_id, ref boolean ab_view, ref boolean ab_create, ref boolean ab_update, ref boolean ab_delete);Int li_count
Char lc_view, lc_create, lc_update, lc_delete

SELECT view_permission, create_permission, update_permission, delete_permission, count(acl_user_permission_id)
INTO :lc_view, :lc_create, :lc_update, :lc_delete, :li_count
FROM acl_user_permission
WHERE company_id = :sec.co_id AND acl_id = :ai_acl_id AND user_id = :sec.user_id ;

IF li_count = 0 THEN
SELECT view_permission, create_permission, update_permission, delete_permission, count(acl_group_permission_id)
INTO :lc_view, :lc_create, :lc_update, :lc_delete, :li_count
FROM acl_group_permission
WHERE company_id = :sec.co_id AND acl_id = :ai_acl_id AND user_group_id = :sec.user_group_id ;
END IF

IF lc_view = "N" THEN
ab_view = False
Else
ab_view = True
END IF

IF lc_create = "N" THEN
ab_create = False
Else
ab_create = True
END IF

IF lc_update = "N" THEN
ab_update = False
Else
ab_update = True
END IF

IF lc_delete = "N" THEN
ab_delete = False
Else
ab_delete = True
END IF

end subroutine

 

 

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Friday, 6 March 2020 13:47 PM UTC
  2. PowerBuilder
  3. # 2

The window has a property MenuID which is a reference to the currently assigned menu. You can use it in script like this:

Menu lm_menu, lm_item

String ls_itemname

lm_menu = this.MenuID

Menu items have an array property Item that you can loop through:

li_max = UpperBound(lm_menu.Item)

For li_idx = 1 To li_max

   lm_item = lm_menu.Item[li_idx]

   ls_itemname = lm_item.Classname()

Next

You can have a table that has the classname and text of all the menu items that need to be controlled. I would create tables for users, groups, group membership, and assignment of menu items to groups.

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.