/** * Owners group has an hard coded name, a description based on the organization's name and has all global permissions. */ private GroupDto insertOwnersGroup(DbSession dbSession, OrganizationDto organization) { GroupDto group = dbClient.groupDao().insert(dbSession, new GroupDto() .setOrganizationUuid(organization.getUuid()) .setName(OWNERS_GROUP_NAME) .setDescription(format(OWNERS_GROUP_DESCRIPTION_PATTERN, organization.getName()))); permissionService.getAllOrganizationPermissions().forEach(p -> addPermissionToGroup(dbSession, group, p)); return group; }
public GroupDto create(DbSession dbSession, String organizationUuid) { Optional<GroupDto> existingMembersGroup = dbClient.groupDao().selectByName(dbSession, organizationUuid, DEFAULT_GROUP_NAME); checkArgument(!existingMembersGroup.isPresent(), "The group '%s' already exist on organization '%s'", DEFAULT_GROUP_NAME, organizationUuid); GroupDto defaultGroup = new GroupDto() .setName(DEFAULT_GROUP_NAME) .setDescription("All members of the organization") .setOrganizationUuid(organizationUuid); dbClient.groupDao().insert(dbSession, defaultGroup); dbClient.organizationDao().setDefaultGroupId(dbSession, organizationUuid, defaultGroup); return defaultGroup; }
private List<GroupDto> findGroups(DbSession dbSession, PermissionQuery dbQuery, PermissionTemplateDto template) { List<String> orderedNames = dbClient.permissionTemplateDao().selectGroupNamesByQueryAndTemplate(dbSession, dbQuery, template.getId()); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, template.getOrganizationUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE)); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); }
private List<GroupDto> findGroups(DbSession dbSession, OrganizationDto org, PermissionQuery dbQuery) { List<String> orderedNames = dbClient.groupPermissionDao().selectGroupNamesByQuery(dbSession, dbQuery); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, org.getUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE).setOrganizationUuid(org.getUuid())); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); }
public static GroupDto newGroupDto() { GroupDto group = new GroupDto() .setId(nextInt()) .setOrganizationUuid(randomAlphanumeric(40)) .setName(randomAlphanumeric(255)) .setDescription(randomAlphanumeric(200)) .setCreatedAt(new Date(nextLong())) .setUpdatedAt(new Date(nextLong())); return group; } }
@Test public void fail_with_ISE_if_default_template_must_be_created_and_default_group_does_not_exist() { setDefaultGroupId(new GroupDto().setId(22)); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Default group with id 22 for organization " + db.getDefaultOrganization().getUuid() + " doesn't exist"); underTest.start(); }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = support.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY)); userSession.checkPermission(ADMINISTER, organization); GroupDto group = new GroupDto() .setOrganizationUuid(organization.getUuid()) .setName(request.mandatoryParam(PARAM_GROUP_NAME)) .setDescription(request.param(PARAM_GROUP_DESCRIPTION)); // validations UserGroupValidation.validateGroupName(group.getName()); support.checkNameDoesNotExist(dbSession, group.getOrganizationUuid(), group.getName()); dbClient.groupDao().insert(dbSession, group); dbSession.commit(); writeResponse(request, response, organization, group); } }
public GroupDto create(DbSession dbSession, String organizationUuid) { Optional<GroupDto> existingMembersGroup = dbClient.groupDao().selectByName(dbSession, organizationUuid, DEFAULT_GROUP_NAME); checkArgument(!existingMembersGroup.isPresent(), "The group '%s' already exist on organization '%s'", DEFAULT_GROUP_NAME, organizationUuid); GroupDto defaultGroup = new GroupDto() .setName(DEFAULT_GROUP_NAME) .setDescription("All members of the organization") .setOrganizationUuid(organizationUuid); dbClient.groupDao().insert(dbSession, defaultGroup); dbClient.organizationDao().setDefaultGroupId(dbSession, organizationUuid, defaultGroup); return defaultGroup; }
/** * Owners group has an hard coded name, a description based on the organization's name and has all global permissions. */ private GroupDto insertOwnersGroup(DbSession dbSession, OrganizationDto organization) { GroupDto group = dbClient.groupDao().insert(dbSession, new GroupDto() .setOrganizationUuid(organization.getUuid()) .setName(OWNERS_GROUP_NAME) .setDescription(format(OWNERS_GROUP_DESCRIPTION_PATTERN, organization.getName()))); OrganizationPermission.all().forEach(p -> addPermissionToGroup(dbSession, group, p)); return group; }
private List<GroupDto> findGroups(DbSession dbSession, PermissionQuery dbQuery, PermissionTemplateDto template) { List<String> orderedNames = dbClient.permissionTemplateDao().selectGroupNamesByQueryAndTemplate(dbSession, dbQuery, template.getId()); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, template.getOrganizationUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE)); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); }
private List<GroupDto> findGroups(DbSession dbSession, OrganizationDto org, PermissionQuery dbQuery) { List<String> orderedNames = dbClient.groupPermissionDao().selectGroupNamesByQuery(dbSession, dbQuery); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, org.getUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE).setOrganizationUuid(org.getUuid())); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = support.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY)); userSession.checkPermission(ADMINISTER, organization); GroupDto group = new GroupDto() .setOrganizationUuid(organization.getUuid()) .setName(request.mandatoryParam(PARAM_GROUP_NAME)) .setDescription(request.param(PARAM_GROUP_DESCRIPTION)); // validations UserGroupValidation.validateGroupName(group.getName()); support.checkNameDoesNotExist(dbSession, group.getOrganizationUuid(), group.getName()); dbClient.groupDao().insert(dbSession, group); dbSession.commit(); writeResponse(request, response, organization, group); } }