mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-02-25 23:05:06 +08:00
testcase
This commit is contained in:
parent
25b49b9c27
commit
17055d8d65
10 changed files with 195 additions and 48 deletions
|
@ -331,7 +331,7 @@ public class SecurityManager {
|
|||
|
||||
com.rebuild.server.service.bizz.privileges.User accessUser = theUserStore.getUser(user);
|
||||
com.rebuild.server.service.bizz.privileges.User targetUser = theUserStore.getUser(targetUserId);
|
||||
Department accessUserDept = (Department) accessUser.getOwningDept();
|
||||
Department accessUserDept = accessUser.getOwningDept();
|
||||
|
||||
if (BizzDepthEntry.LOCAL.equals(depth)) {
|
||||
allowed = accessUserDept.equals(targetUser.getOwningDept());
|
||||
|
@ -346,7 +346,7 @@ public class SecurityManager {
|
|||
return true;
|
||||
}
|
||||
|
||||
allowed = accessUserDept.isChildrenAll((Department) targetUser.getOwningDept());
|
||||
allowed = accessUserDept.isChildrenAll(targetUser.getOwningDept());
|
||||
if (!allowed) {
|
||||
return allowedViaShare(user, target, action);
|
||||
}
|
||||
|
@ -357,14 +357,14 @@ public class SecurityManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* 通过共享取得的操作权限
|
||||
* 通过共享取得的操作权限(目前只共享了读取权限)
|
||||
*
|
||||
* @param user
|
||||
* @param target
|
||||
* @param action
|
||||
* @return
|
||||
*/
|
||||
private boolean allowedViaShare(ID user, ID target, Permission action) {
|
||||
public boolean allowedViaShare(ID user, ID target, Permission action) {
|
||||
|
||||
// TODO 目前只共享了读取权限
|
||||
// TODO 性能优化-缓存
|
||||
|
@ -372,7 +372,7 @@ public class SecurityManager {
|
|||
if (action != BizzPermission.READ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Entity entity = MetadataHelper.getEntity(target.getEntityCode());
|
||||
if (entity.getMasterEntity() != null) {
|
||||
ID masterId = getMasterRecordId(target);
|
||||
|
|
|
@ -152,6 +152,8 @@ public class TestSupport {
|
|||
}
|
||||
|
||||
/**
|
||||
* 添加一条测试记录。注意调用前设置线程用户 {@link Application#getSessionStore()}
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected static ID addRecordOfTestAllFields() {
|
||||
|
@ -159,12 +161,6 @@ public class TestSupport {
|
|||
Entity test = MetadataHelper.getEntity(TEST_ENTITY);
|
||||
Record record = EntityHelper.forNew(test.getEntityCode(), opUser);
|
||||
record.setString("text", "TEXT-" + RandomUtils.nextLong());
|
||||
try {
|
||||
Application.getSessionStore().set(opUser);
|
||||
record = Application.getGeneralEntityService().create(record);
|
||||
return record.getPrimary();
|
||||
} finally {
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
return Application.getGeneralEntityService().create(record).getPrimary();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
package com.rebuild.server.business.datareport;
|
||||
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import org.junit.Test;
|
||||
|
@ -35,10 +36,16 @@ public class DataReportGeneratorTest extends TestSupport {
|
|||
@Test
|
||||
public void testGenerator() throws Exception {
|
||||
File template = ResourceUtils.getFile("classpath:report-template.xlsx");
|
||||
ID record = addRecordOfTestAllFields();
|
||||
ReportGenerator generator = new ReportGenerator(template, record);
|
||||
generator.setUser(UserService.ADMIN_USER);
|
||||
File file = generator.generate();
|
||||
System.out.println(file);
|
||||
try {
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
|
||||
ID record = addRecordOfTestAllFields();
|
||||
ReportGenerator generator = new ReportGenerator(template, record);
|
||||
generator.setUser(UserService.ADMIN_USER);
|
||||
File file = generator.generate();
|
||||
System.out.println(file);
|
||||
} finally {
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ package com.rebuild.server.business.recyclebin;
|
|||
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -31,8 +33,14 @@ public class RecycleBeanTest extends TestSupport {
|
|||
|
||||
@Test
|
||||
public void serialize() {
|
||||
ID test = addRecordOfTestAllFields();
|
||||
JSON s = new RecycleBean(test).serialize();
|
||||
System.out.println(s);
|
||||
try {
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
|
||||
ID test = addRecordOfTestAllFields();
|
||||
JSON s = new RecycleBean(test).serialize();
|
||||
System.out.println(s);
|
||||
} finally {
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,18 +33,20 @@ public class RecycleRestoreTest extends TestSupport {
|
|||
|
||||
@Test
|
||||
public void restore() {
|
||||
final ID test = addRecordOfTestAllFields();
|
||||
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
ID testId = null;
|
||||
try {
|
||||
Application.getGeneralEntityService().delete(test);
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
|
||||
testId = addRecordOfTestAllFields();
|
||||
Application.getGeneralEntityService().delete(testId);
|
||||
|
||||
} finally {
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
|
||||
Object[] recycle = Application.createQueryNoFilter(
|
||||
"select recycleId from RecycleBin where recordId = ?")
|
||||
.setParameter(1, test)
|
||||
.setParameter(1, testId)
|
||||
.unique();
|
||||
Assert.assertTrue(recycle != null);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
package com.rebuild.server.business.recyclebin;
|
||||
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import org.junit.Test;
|
||||
|
@ -31,17 +32,23 @@ public class RecycleStoreTest extends TestSupport {
|
|||
|
||||
@Test
|
||||
public void store() {
|
||||
ID test1 = addRecordOfTestAllFields();
|
||||
ID test2 = addRecordOfTestAllFields();
|
||||
try {
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
|
||||
RecycleStore recycleStore = new RecycleStore(UserService.ADMIN_USER);
|
||||
recycleStore.add(test1);
|
||||
recycleStore.add(test2);
|
||||
recycleStore.removeLast();
|
||||
ID test1 = addRecordOfTestAllFields();
|
||||
ID test2 = addRecordOfTestAllFields();
|
||||
|
||||
recycleStore.add(test2, test1);
|
||||
RecycleStore recycleStore = new RecycleStore(UserService.ADMIN_USER);
|
||||
recycleStore.add(test1);
|
||||
recycleStore.add(test2);
|
||||
recycleStore.removeLast();
|
||||
|
||||
int s = recycleStore.store();
|
||||
System.out.println(s);
|
||||
recycleStore.add(test2, test1);
|
||||
|
||||
int s = recycleStore.store();
|
||||
System.out.println(s);
|
||||
} finally {
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
rebuild - Building your business-systems freely.
|
||||
Copyright (C) 2019 devezhao <zhaofang123@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rebuild.server.business.trigger.impl;
|
||||
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.business.trigger.ActionType;
|
||||
import com.rebuild.server.business.trigger.TriggerWhen;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import com.rebuild.server.service.configuration.RobotTriggerConfigService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author devezhao zhaofang123@gmail.com
|
||||
* @since 2019/08/27
|
||||
*/
|
||||
public class AutoAssignTest extends TestSupport {
|
||||
|
||||
@Test
|
||||
public void execute() throws Exception {
|
||||
addExtTestEntities(false);
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
|
||||
// 添加配置
|
||||
Application.getSQLExecutor().execute("delete from robot_trigger_config where BELONG_ENTITY = '" + TEST_ENTITY + "'");
|
||||
|
||||
Record autoshareConfig = EntityHelper.forNew(EntityHelper.RobotTriggerConfig, UserService.SYSTEM_USER);
|
||||
autoshareConfig.setString("belongEntity", TEST_ENTITY);
|
||||
autoshareConfig.setInt("when", TriggerWhen.CREATE.getMaskValue());
|
||||
autoshareConfig.setString("actionType", ActionType.AUTOASSIGN.name());
|
||||
String content = "{cascades:null, assignRule:1, assignTo:['" + SIMPLE_USER.toLiteral() + "']}";
|
||||
autoshareConfig.setString("actionContent", content);
|
||||
Application.getBean(RobotTriggerConfigService.class).create(autoshareConfig);
|
||||
|
||||
// 测试执行
|
||||
try {
|
||||
ID testId = addRecordOfTestAllFields();
|
||||
ID owningUser = Application.getRecordOwningCache().getOwningUser(testId);
|
||||
Assert.assertTrue(SIMPLE_USER.equals(owningUser));
|
||||
} finally {
|
||||
Application.getBean(RobotTriggerConfigService.class).delete(autoshareConfig.getPrimary());
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
rebuild - Building your business-systems freely.
|
||||
Copyright (C) 2019 devezhao <zhaofang123@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rebuild.server.business.trigger.impl;
|
||||
|
||||
import cn.devezhao.bizz.privileges.impl.BizzPermission;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.business.trigger.ActionType;
|
||||
import com.rebuild.server.business.trigger.TriggerWhen;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import com.rebuild.server.service.configuration.RobotTriggerConfigService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author devezhao zhaofang123@gmail.com
|
||||
* @since 2019/08/27
|
||||
*/
|
||||
public class AutoShareTest extends TestSupport {
|
||||
|
||||
@Test
|
||||
public void execute() throws Exception {
|
||||
addExtTestEntities(false);
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
|
||||
// 添加配置
|
||||
Application.getSQLExecutor().execute("delete from robot_trigger_config where BELONG_ENTITY = '" + TEST_ENTITY + "'");
|
||||
|
||||
Record autoshareConfig = EntityHelper.forNew(EntityHelper.RobotTriggerConfig, UserService.SYSTEM_USER);
|
||||
autoshareConfig.setString("belongEntity", TEST_ENTITY);
|
||||
autoshareConfig.setInt("when", TriggerWhen.CREATE.getMaskValue());
|
||||
autoshareConfig.setString("actionType", ActionType.AUTOSHARE.name());
|
||||
String content = "{shareTo:['" + SIMPLE_USER.toLiteral() + "']}";
|
||||
autoshareConfig.setString("actionContent", content);
|
||||
Application.getBean(RobotTriggerConfigService.class).create(autoshareConfig);
|
||||
|
||||
// 测试执行
|
||||
try {
|
||||
ID testId = addRecordOfTestAllFields();
|
||||
boolean allowed = Application.getSecurityManager().allowedViaShare(SIMPLE_USER, testId, BizzPermission.READ);
|
||||
Assert.assertTrue(allowed);
|
||||
} finally {
|
||||
Application.getBean(RobotTriggerConfigService.class).delete(autoshareConfig.getPrimary());
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,10 +16,11 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rebuild.server.business.trigger;
|
||||
|
||||
import org.junit.Test;
|
||||
package com.rebuild.server.business.trigger.impl;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.business.trigger.ActionType;
|
||||
|
@ -30,10 +31,7 @@ import com.rebuild.server.metadata.EntityHelper;
|
|||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import com.rebuild.server.service.configuration.RobotTriggerConfigService;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author devezhao zhaofang123@gmail.com
|
|
@ -16,12 +16,10 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rebuild.server.business.trigger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
package com.rebuild.server.business.trigger.impl;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.business.trigger.ActionType;
|
||||
|
@ -31,9 +29,9 @@ import com.rebuild.server.metadata.EntityHelper;
|
|||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import com.rebuild.server.service.configuration.RobotTriggerConfigService;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author devezhao-mbp zhaofang123@gmail.com
|
Loading…
Reference in a new issue