Skip to content

Commit 62e1d96

Browse files
authored
Merge pull request #3964 from HejdaJakub/st-1029_embedded_groups_extension
feat: allow embedded group form item in group applications
2 parents f1c4498 + b4958c6 commit 62e1d96

File tree

39 files changed

+2536
-282
lines changed

39 files changed

+2536
-282
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cz.metacentrum.perun.core.api.exceptions;
2+
3+
/**
4+
* This exception is thrown when the form item does not exist in any application form
5+
*
6+
* @author Jakub Hejda <[email protected]>
7+
*/
8+
public class FormItemNotExistsException extends PerunException {
9+
static final long serialVersionUID = 0;
10+
11+
/**
12+
* Simple constructor with a message
13+
* @param message message with details about the cause
14+
*/
15+
public FormItemNotExistsException(String message) {
16+
super(message);
17+
}
18+
19+
/**
20+
* Constructor with a message and Throwable object
21+
* @param message message with details about the cause
22+
* @param cause Throwable that caused throwing of this exception
23+
*/
24+
public FormItemNotExistsException(String message, Throwable cause) {
25+
super(message, cause);
26+
}
27+
28+
/**
29+
* Constructor with a Throwable object
30+
* @param cause Throwable that caused throwing of this exception
31+
*/
32+
public FormItemNotExistsException(Throwable cause) {
33+
super(cause);
34+
}
35+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cz.metacentrum.perun.core.api.exceptions;
2+
3+
/**
4+
* Exception thrown when relation of two groups as parent-sub should exist, but does not.
5+
*
6+
* @author Dominik Frantisek Bucik <[email protected]>
7+
*/
8+
public class GroupIsNotASubgroupException extends PerunException {
9+
10+
/**
11+
* Constructor without arguments
12+
*/
13+
public GroupIsNotASubgroupException() {}
14+
15+
/**
16+
* Simple constructor with a message
17+
* @param message message with details about the cause
18+
*/
19+
public GroupIsNotASubgroupException(String message) {
20+
super(message);
21+
}
22+
23+
/**
24+
* Constructor with a message and Throwable object
25+
* @param message message with details about the cause
26+
* @param cause Throwable that caused throwing of this exception
27+
*/
28+
public GroupIsNotASubgroupException(String message, Throwable cause) {
29+
super(message, cause);
30+
}
31+
32+
/**
33+
* Constructor with a Throwable object
34+
* @param cause Throwable that caused throwing of this exception
35+
*/
36+
public GroupIsNotASubgroupException(Throwable cause) {
37+
super(cause);
38+
}
39+
}

perun-base/src/main/java/cz/metacentrum/perun/registrar/model/ApplicationFormItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ public static enum Type {
248248
*/
249249
TIMEZONE,
250250
/**
251-
* Special type for specifying if will be allowed to register to group(s) through VO application form. This type
252-
* is represented by standard HTML checkbox.
251+
* Special type for specifying if it will be allowed to register to group(s) through single application form.
252+
* This type is represented by standard HTML checkbox.
253253
*/
254254
EMBEDDED_GROUP_APPLICATION,
255255
/**

perun-base/src/main/resources/perun-roles.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,27 @@ perun_policies:
24652465
include_policies:
24662466
- default_policy
24672467

2468+
getAllGroupsForAutoRegistration_policy:
2469+
policy_roles: []
2470+
include_policies:
2471+
- default_policy
2472+
2473+
getGroupsForAutoRegistration_Vo_ApplicationFormItem_policy:
2474+
policy_roles:
2475+
- VOADMIN: Vo
2476+
- VOOBSERVER: Vo
2477+
include_policies:
2478+
- default_policy
2479+
2480+
getGroupsForAutoRegistration_Group_ApplicationFormItem_policy:
2481+
policy_roles:
2482+
- VOADMIN: Vo
2483+
- VOOBSERVER: Vo
2484+
- GROUPADMIN: Group
2485+
- GROUPOBSERVER: Group
2486+
include_policies:
2487+
- default_policy
2488+
24682489
deleteGroupsFromAutoRegistration_List<Group>_policy:
24692490
policy_roles:
24702491
- GROUPADMIN: Group
@@ -2475,6 +2496,26 @@ perun_policies:
24752496
- MFA: Group
24762497
- MFA: Vo
24772498

2499+
deleteGroupsFromAutoRegistration_List<Group>_ApplicationFormItem_policy:
2500+
policy_roles:
2501+
- GROUPADMIN: Group
2502+
- VOADMIN: Vo
2503+
include_policies:
2504+
- default_policy
2505+
mfa_rules:
2506+
- MFA: Group
2507+
- MFA: Vo
2508+
2509+
deleteGroupsFromAutoRegistration_List<Group>_Group_ApplicationFormItem_policy:
2510+
policy_roles:
2511+
- GROUPADMIN: Group
2512+
- VOADMIN: Vo
2513+
include_policies:
2514+
- default_policy
2515+
mfa_rules:
2516+
- MFA: Group
2517+
- MFA: Vo
2518+
24782519
addGroupsToAutoRegistration_List<Group>_policy:
24792520
policy_roles:
24802521
- GROUPADMIN: Group
@@ -2485,6 +2526,26 @@ perun_policies:
24852526
- MFA: Group
24862527
- MFA: Vo
24872528

2529+
addGroupsToAutoRegistration_List<Group>_ApplicationFormItem_policy:
2530+
policy_roles:
2531+
- GROUPADMIN: Group
2532+
- VOADMIN: Vo
2533+
include_policies:
2534+
- default_policy
2535+
mfa_rules:
2536+
- MFA: Group
2537+
- MFA: Vo
2538+
2539+
addGroupsToAutoRegistration_List<Group>_Group_ApplicationFormItem_policy:
2540+
policy_roles:
2541+
- GROUPADMIN: Group
2542+
- VOADMIN: Vo
2543+
include_policies:
2544+
- default_policy
2545+
mfa_rules:
2546+
- MFA: Group
2547+
- MFA: Vo
2548+
24882549
getIndirectMembershipPaths_Member_Group_policy:
24892550
policy_roles:
24902551
- VOOBSERVER: Vo

perun-base/src/test/resources/test-schema.sql

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- database version 3.2.13 (don't forget to update insert statement at the end of file)
1+
-- database version 3.2.14 (don't forget to update insert statement at the end of file)
22
CREATE EXTENSION IF NOT EXISTS "unaccent";
33
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
44

@@ -1616,8 +1616,16 @@ create table authz (
16161616
);
16171617

16181618
create table groups_to_register (
1619-
group_id integer,
1620-
constraint grpreg_group_fk foreign key (group_id) references groups(id) on delete cascade
1619+
group_id integer,
1620+
constraint grpreg_group_fk foreign key (group_id) references groups(id) on delete cascade
1621+
);
1622+
1623+
create table auto_registration_groups (
1624+
group_id integer not null,
1625+
application_form_item_id integer not null,
1626+
constraint auto_reg_grps_group_fk foreign key (group_id) references groups(id) on delete cascade,
1627+
constraint auto_reg_grps_app_forms_fk foreign key (application_form_item_id) references application_form_items(id) on delete cascade,
1628+
constraint auto_reg_grps_grp_app_form_u unique (group_id, application_form_item_id)
16211629
);
16221630

16231631
create type consent_status as enum (
@@ -1732,6 +1740,7 @@ create unique index idx_grp_nam_vo_parentg_u on groups (name,vo_id,coalesce(pare
17321740
create index idx_namespace on attr_names(namespace);
17331741
create index idx_authz_user_role_id on authz (user_id,role_id);
17341742
create index idx_authz_authz_group_role_id on authz (authorized_group_id,role_id);
1743+
create index idx_auto_reg_grps_grp_app_form on auto_registration_groups (group_id,application_form_item_id);
17351744
create index idx_fk_cabthank_pub on cabinet_thanks(publicationid);
17361745
create index idx_fk_conhubfac_ch on consent_hubs_facilities(consent_hub_id);
17371746
create index idx_fk_conhubfac_fac on consent_hubs_facilities(facility_id);
@@ -1896,7 +1905,7 @@ create index idx_fk_attr_critops ON attribute_critical_actions(attr_id);
18961905
create index app_state_idx ON application (state);
18971906

18981907
-- set initial Perun DB version
1899-
insert into configurations values ('DATABASE VERSION','3.2.13');
1908+
insert into configurations values ('DATABASE VERSION','3.2.14');
19001909
-- insert membership types
19011910
insert into membership_types (id, membership_type, description) values (1, 'DIRECT', 'Member is directly added into group');
19021911
insert into membership_types (id, membership_type, description) values (2, 'INDIRECT', 'Member is added indirectly through UNION relation');

perun-core/src/main/java/cz/metacentrum/perun/core/bl/GroupsManagerBl.java

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException;
2525
import cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException;
2626
import cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException;
27+
import cz.metacentrum.perun.core.api.exceptions.FormItemNotExistsException;
2728
import cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedException;
2829
import cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException;
2930
import cz.metacentrum.perun.core.api.exceptions.GroupExistsException;
@@ -51,6 +52,7 @@
5152
import cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException;
5253
import cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException;
5354
import cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException;
55+
import cz.metacentrum.perun.registrar.model.ApplicationFormItem;
5456

5557
import java.util.List;
5658
import java.util.Map;
@@ -2036,6 +2038,35 @@ public interface GroupsManagerBl {
20362038
*/
20372039
List<Group> getGroupsForAutoRegistration(PerunSession sess, Vo vo);
20382040

2041+
/**
2042+
* Returns all groups which can be registered into during any vo registration.
2043+
* This method serves only for migration to new functionality related to the new table.
2044+
*
2045+
* @param sess session
2046+
* @return list of groups
2047+
*/
2048+
List<Group> getAllGroupsForAutoRegistration(PerunSession sess);
2049+
2050+
/**
2051+
* Returns all groups which can be registered into during vo registration.
2052+
*
2053+
* @param sess session
2054+
* @param vo vo
2055+
* @param formItem application form item
2056+
* @return list of groups
2057+
*/
2058+
List<Group> getGroupsForAutoRegistration(PerunSession sess, Vo vo, ApplicationFormItem formItem);
2059+
2060+
/**
2061+
* Returns all groups which can be registered into during group registration.
2062+
*
2063+
* @param sess session
2064+
* @param registrationGroup group
2065+
* @param formItem application form item
2066+
* @return list of groups
2067+
*/
2068+
List<Group> getGroupsForAutoRegistration(PerunSession sess, Group registrationGroup, ApplicationFormItem formItem);
2069+
20392070
/**
20402071
* Deletes groups from a list of groups which can be registered into during vo registration.
20412072
*
@@ -2044,6 +2075,15 @@ public interface GroupsManagerBl {
20442075
*/
20452076
void deleteGroupsFromAutoRegistration(PerunSession sess, List<Group> groups);
20462077

2078+
/**
2079+
* Deletes groups from a list of groups which can be registered into during vo or group registration.
2080+
*
2081+
* @param sess session
2082+
* @param groups list of groups
2083+
* @param formItem application form item
2084+
*/
2085+
void deleteGroupsFromAutoRegistration(PerunSession sess, List<Group> groups, ApplicationFormItem formItem) throws FormItemNotExistsException;
2086+
20472087
/**
20482088
* Adds groups to a list of groups which can be registered into during vo registration.
20492089
* This will NOT create empty application form for groups and will throw exception if none exists.
@@ -2054,6 +2094,17 @@ public interface GroupsManagerBl {
20542094
*/
20552095
void addGroupsToAutoRegistration(PerunSession sess, List<Group> groups) throws GroupNotAllowedToAutoRegistrationException;
20562096

2097+
/**
2098+
* Adds groups to a list of groups which can be registered into during vo or group registration.
2099+
* This will NOT create empty application form for groups and will throw exception if none exists.
2100+
*
2101+
* @param sess session
2102+
* @param groups list of groups
2103+
* @param formItem application form item
2104+
* @throws GroupNotAllowedToAutoRegistrationException if given group cannot be added to auto registration
2105+
*/
2106+
void addGroupsToAutoRegistration(PerunSession sess, List<Group> groups, ApplicationFormItem formItem) throws GroupNotAllowedToAutoRegistrationException, FormItemNotExistsException;
2107+
20572108
/**
20582109
* Get unique paths of groups via which member is indirectly included to the group.
20592110
* Cuts off after first included group.
@@ -2066,12 +2117,21 @@ public interface GroupsManagerBl {
20662117
List<List<Group>> getIndirectMembershipPaths(PerunSession sess, Member member, Group group) throws MemberNotExistsException, GroupNotExistsException;
20672118

20682119
/**
2069-
* Check if group has automatic registration enabled.
2120+
* Check if group has automatic registration enabled in any form item.
2121+
*
2122+
* @param sess session
2123+
* @param group group to check
2124+
*/
2125+
boolean isGroupForAnyAutoRegistration(PerunSession sess, Group group);
2126+
2127+
/**
2128+
* Check if group has automatic registration enabled in the given form item.
20702129
*
20712130
* @param sess session
20722131
* @param group group to check
2132+
* @param formItems form items for which the group can be configured
20732133
*/
2074-
boolean isGroupForAutoRegistration(PerunSession sess, Group group);
2134+
boolean isGroupForAutoRegistration(PerunSession sess, Group group, List<Integer> formItems);
20752135

20762136
/**
20772137
* Creates enrichedGroup from given group and load attributes with given names.
@@ -2130,4 +2190,5 @@ public interface GroupsManagerBl {
21302190
* @return list of allowed groups to hierarchical VO
21312191
*/
21322192
List<Group> getAllAllowedGroupsToHierarchicalVo(PerunSession sess, Vo vo, Vo memberVo);
2193+
21332194
}

0 commit comments

Comments
 (0)