Search in sources :

Example 1 with UserBindWorkspaceModel

use of io.jpom.model.data.UserBindWorkspaceModel in project Jpom by dromara.

the class UserBindWorkspaceService method existsWorkspace.

/**
 * 判断对应的工作空间是否被用户绑定
 *
 * @param workspaceId 工作空间ID
 * @return true 有用户绑定
 */
public boolean existsWorkspace(String workspaceId) {
    UserBindWorkspaceModel userBindWorkspaceModel = new UserBindWorkspaceModel();
    userBindWorkspaceModel.setWorkspaceId(workspaceId);
    return super.exists(userBindWorkspaceModel);
}
Also used : UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel)

Example 2 with UserBindWorkspaceModel

use of io.jpom.model.data.UserBindWorkspaceModel in project Jpom by dromara.

the class UserBindWorkspaceService method listUserWorkspace.

/**
 * 查询用户绑定的工作空间
 *
 * @param userId 用户ID
 * @return list
 */
public List<UserBindWorkspaceModel> listUserWorkspace(String userId) {
    UserBindWorkspaceModel userBindWorkspaceModel = new UserBindWorkspaceModel();
    userBindWorkspaceModel.setUserId(userId);
    return super.listByBean(userBindWorkspaceModel);
}
Also used : UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel)

Example 3 with UserBindWorkspaceModel

use of io.jpom.model.data.UserBindWorkspaceModel in project Jpom by dromara.

the class UserBindWorkspaceService method updateUserWorkspace.

/**
 * 更新用户的工作空间信息
 *
 * @param userId    用户ID
 * @param workspace 工作空间信息
 */
public void updateUserWorkspace(String userId, List<String> workspace) {
    Assert.notEmpty(workspace, "没有任何工作空间信息");
    List<UserBindWorkspaceModel> list = new HashSet<>(workspace).stream().filter(s -> {
        s = StrUtil.removeSuffix(s, SYSTEM_USER);
        s = StrUtil.removeSuffix(s, SSH_COMMAND_NOT_LIMITED);
        MethodFeature[] values = MethodFeature.values();
        for (MethodFeature value : values) {
            s = StrUtil.removeSuffix(s, StrUtil.DASHED + value.name());
        }
        return workspaceService.exists(new WorkspaceModel(s));
    }).map(s -> {
        UserBindWorkspaceModel userBindWorkspaceModel = new UserBindWorkspaceModel();
        userBindWorkspaceModel.setWorkspaceId(s);
        userBindWorkspaceModel.setUserId(userId);
        userBindWorkspaceModel.setId(UserBindWorkspaceModel.getId(userId, s));
        return userBindWorkspaceModel;
    }).collect(Collectors.toList());
    // 删除之前的数据
    UserBindWorkspaceModel userBindWorkspaceModel = new UserBindWorkspaceModel();
    userBindWorkspaceModel.setUserId(userId);
    super.del(super.dataBeanToEntity(userBindWorkspaceModel));
    // 重新入库
    super.insert(list);
}
Also used : UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) WorkspaceService(io.jpom.service.system.WorkspaceService) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) Service(org.springframework.stereotype.Service) Entity(cn.hutool.db.Entity) UserModel(io.jpom.model.data.UserModel) MethodFeature(io.jpom.permission.MethodFeature) BaseDbService(io.jpom.service.h2db.BaseDbService) Assert(org.springframework.util.Assert) UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) MethodFeature(io.jpom.permission.MethodFeature) UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel) HashSet(java.util.HashSet)

Example 4 with UserBindWorkspaceModel

use of io.jpom.model.data.UserBindWorkspaceModel in project Jpom by dromara.

the class UserBindWorkspaceService method exists.

/**
 * 查询用户 是否存在工作空间权限
 *
 * @param userId      用户ID
 * @param workspaceId 工作空间
 * @return true 存在
 */
public boolean exists(String userId, String workspaceId) {
    UserBindWorkspaceModel workspaceModel = new UserBindWorkspaceModel();
    workspaceModel.setId(UserBindWorkspaceModel.getId(userId, workspaceId));
    return this.exists(workspaceModel);
}
Also used : UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel)

Example 5 with UserBindWorkspaceModel

use of io.jpom.model.data.UserBindWorkspaceModel in project Jpom by dromara.

the class UserBindWorkspaceService method listUserWorkspaceInfo.

/**
 * 查询用户绑定的工作空间
 *
 * @param userModel 用户
 * @return list
 */
public List<WorkspaceModel> listUserWorkspaceInfo(UserModel userModel) {
    if (userModel.isSuperSystemUser()) {
        // 超级管理员有所有工作空间权限
        return workspaceService.list();
    }
    UserBindWorkspaceModel userBindWorkspaceModel = new UserBindWorkspaceModel();
    userBindWorkspaceModel.setUserId(userModel.getId());
    List<UserBindWorkspaceModel> userBindWorkspaceModels = super.listByBean(userBindWorkspaceModel);
    Assert.notEmpty(userBindWorkspaceModels, "没有任何工作空间信息");
    List<String> collect = userBindWorkspaceModels.stream().map(UserBindWorkspaceModel::getWorkspaceId).collect(Collectors.toList());
    return workspaceService.listById(collect);
}
Also used : UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel)

Aggregations

UserBindWorkspaceModel (io.jpom.model.data.UserBindWorkspaceModel)6 Entity (cn.hutool.db.Entity)2 StrUtil (cn.hutool.core.util.StrUtil)1 UserModel (io.jpom.model.data.UserModel)1 WorkspaceModel (io.jpom.model.data.WorkspaceModel)1 MethodFeature (io.jpom.permission.MethodFeature)1 BaseDbService (io.jpom.service.h2db.BaseDbService)1 WorkspaceService (io.jpom.service.system.WorkspaceService)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Service (org.springframework.stereotype.Service)1 Assert (org.springframework.util.Assert)1