   select @branches_acl_object_identity_id_start + BRANCH_ID, 1019, @banned_group_sid_id, @CREATE_CODE_REVIEW_MASK, 0, 0, 0 from BRANCHES;
 insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure)
   select @branches_acl_object_identity_id_start + BRANCH_ID, 1020, @banned_group_sid_id, @VIEW_TOPICS_MASK, 0, 0, 0 from BRANCHES;
+
+-- setting permissions for createPosts users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1022, @createPosts_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1023, @createPosts_group_sid_id, @CREATE_POSTS_MASK, 1, 0, 0 from BRANCHES;
+
+ -- setting permissions for createStickedPosts users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1024, @createStickedPosts_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1025, @createStickedPosts_group_sid_id, @CREATE_POSTS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1026, @createStickedPosts_group_sid_id, @CREATE_STICKED_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+
+ -- setting permissions for createAnnouncements users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1027, @createAnnouncements_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1028, @createAnnouncements_group_sid_id, @CREATE_POSTS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1029, @createAnnouncements_group_sid_id, @CREATE_ANNOUNCEMENTS_MASK, 1, 0, 0 from BRANCHES;
+
+-- setting permissions for editOwnPosts users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1030, @editOwnPosts_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1031, @editOwnPosts_group_sid_id, @CREATE_POSTS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1032, @editOwnPosts_group_sid_id, @EDIT_OWN_POSTS_MASK, 1, 0, 0 from BRANCHES;
+
+-- setting permissions for editOtherPosts users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1033, @editOtherPosts_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1034, @editOtherPosts_group_sid_id, @EDIT_OTHERS_POSTS_MASK, 1, 0, 0 from BRANCHES;
+
+-- setting permissions for deleteOwnPosts users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1035, @deleteOwnPosts_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1036, @deleteOwnPosts_group_sid_id, @CREATE_POSTS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1037, @deleteOwnPosts_group_sid_id, @DELETE_OWN_POSTS_MASK, 1, 0, 0 from BRANCHES;
+
+-- setting permissions for deleteOtherPosts users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1038, @deleteOthersPosts_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1039, @deleteOthersPosts_group_sid_id, @CREATE_POSTS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1040, @deleteOthersPosts_group_sid_id, @DELETE_OTHERS_POSTS_MASK, 1, 0, 0 from BRANCHES;
+
+-- setting permissions for moveTopics users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1041, @moveTopics_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1042, @moveTopics_group_sid_id, @MOVE_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+
+-- setting permissions for closetopics users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1043, @closetopics_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1044, @closetopics_group_sid_id, @CLOSE_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+
+-- setting permissions for createCodeReview users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1045, @createCodeReview_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1046, @createCodeReview_group_sid_id, @CREATE_CODE_REVIEW_MASK, 1, 0, 0 from BRANCHES;
+
+-- setting permissions for leaveCommentsInCodeReview users on all branches
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1047, @leaveCommentsInCodeReview_group_sid_id, @VIEW_TOPICS_MASK, 1, 0, 0 from BRANCHES;
+insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) 
+  select @branches_acl_object_identity_id_start + BRANCH_ID, 1048, @leaveCommentsInCodeReview_group_sid_id, @LEAVE_COMMENTS_IN_CODE_REVIEW_MASK, 1, 0, 0 from BRANCHES;
+
+-- deleting all permissions for all user groups from BRANCH_ID = 51
+delete from acl_entry where acl_object_identity = @branches_acl_object_identity_id_start + 51;
   
 -- personal permissions
 insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure)

insert ignore into acl_class values (@branch_acl_class,'BRANCH'), (@group_acl_class,'GROUP'), (@component_acl_class,'COMPONENT');

insert into acl_sid(principal, sid) values (0, @moderator_group_sid);

SET @admin_group_sid_id := (select id from acl_sid where sid=@admin_group_sid);
SET @registered_group_sid_id := (select id from acl_sid where sid=@registered_group_sid);
SET @banned_group_sid_id := (select id from acl_sid where sid=@banned_group_sid);
SET @moderator_group_sid_id := (select id from acl_sid where sid=@moderator_group_sid);
SET @anonymous_sid_id := (select id from acl_sid where sid='user:anonymousUser');

-- PERMISSIONS BEGIN
SET @SEND_PRIVATE_MESSAGES_MASK := 14;
SET @CREATE_FORUM_FAQ_MASK := 20;
SET @EDIT_OWN_PROFILE_MASK := 15;
SET @EDIT_OTHERS_PROFILE_MASK := 23;

SET @VIEW_TOPICS_MASK := 6;
SET @MOVE_TOPICS_MASK := 8;
SET @CLOSE_TOPICS_MASK := 11;
SET @CREATE_POSTS_MASK := 12;
SET @DELETE_OWN_POSTS_MASK := 7;
SET @DELETE_OTHERS_POSTS_MASK := 13;
SET @EDIT_OWN_POSTS_MASK := 133;
SET @EDIT_OTHERS_POSTS_MASK := 17;
SET @CREATE_ANNOUNCEMENTS_MASK := 18;
SET @CREATE_STICKED_TOPICS_MASK := 19;
SET @CREATE_CODE_REVIEW_MASK := 21;
SET @LEAVE_COMMENTS_IN_CODE_REVIEW_MASK := 22;

SET @ADMIN_MASK := 16;
-- PERMISSIONS END

--  Records for branches will start from this ID+1 in acl_object_identity table
SET @branches_acl_object_identity_id_start = (SELECT MAX(ID) FROM acl_object_identity);

insert into acl_object_identity
 SELECT @branches_acl_object_identity_id_start + BranchTable.BRANCH_ID, @branch_acl_class, BranchTable.BRANCH_ID, NULL, 1, 1

﻿SET @forum_component_id := 2;
-- Update description of FORUM component for new users baing created
update COMPONENTS set DESCRIPTION = 'Available users: admin/admin registered/registered moderator/moderator banned/banned and others'
  where CMP_ID = @forum_component_id;

insert ignore into SECTIONS (SECTION_ID, UUID, `NAME`, DESCRIPTION, POSITION, COMPONENT_ID) VALUES
