Skip to content

Commit

Permalink
No validation of tenant id in UI #21
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaShchienko committed May 17, 2019
1 parent 546605f commit 7bbc469
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ validation.userBelongsToDifferentTenant=Selected user already belongs to a diffe
createTenantRootGroupButton.caption=Generate group

validation.cannotGenerateGroupNameIsNull=Please enter a tenant name first
validation.tenantGroupAlreadyExist=Access group with the name "%s" already exists
validation.tenantGroupAlreadyExist=Access group with the name "%s" already exists
validation.invalidTenantId=The field "Tenant Id" must contain Latin letters, numbers or "_"
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@
</row>
<row>
<label value="msg://Tenant.tenantId" align="MIDDLE_LEFT"/>
<textField id="tenantIdField" datasource="tenantDs" property="tenantId" width="100%"/>
<textField id="tenantIdField" datasource="tenantDs" property="tenantId" width="100%">
<validator class="com.haulmont.addon.sdbmt.web.tenant.validators.TenantIdValidator"/>
</textField>
</row>
<row>
<label value="msg://Tenant.group" align="MIDDLE_LEFT"/>
<hbox spacing="true">
<pickerField id="groupField" datasource="tenantDs" property="group" width="100%"/>
<button id="createGroupButton" caption="msg://createTenantRootGroupButton.caption" invoke="onCreateTenantRootGroup"/>
<button id="createGroupButton" caption="msg://createTenantRootGroupButton.caption"
invoke="onCreateTenantRootGroup"/>
</hbox>
</row>
<row>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2008-2019 Haulmont.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.haulmont.addon.sdbmt.web.tenant.validators;

import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.components.Field;
import com.haulmont.cuba.gui.components.ValidationException;
import org.apache.commons.lang3.StringUtils;

public class TenantIdValidator implements Field.Validator {

protected Messages messages = AppBeans.get(Messages.class);

@Override
public void validate(Object value) throws ValidationException {
if (StringUtils.isNotEmpty((String) value) && !((String) value).matches("[\\w|\\s]+"))
throw new ValidationException(messages.getMessage(TenantIdValidator.class, "validation.invalidTenantId"));
}
}

0 comments on commit 7bbc469

Please sign in to comment.