示例#1
0
  public static Permission fetchById(Long id) {
    if (id == null) throw new RuntimeException("id required");

    Permission perm = Permission.findById(id);
    if (perm == null) throw new RuntimeException("Permission not found");

    return perm;
  }
示例#2
0
文件: Role.java 项目: ukwa/w3act
 /**
  * This method checks whether user has a permission by its id.
  *
  * @param permissionName
  * @return true if exists
  */
 public boolean hasPermission(Long permissionId) {
   if (permissionId != null) {
     Permission permission = Permission.findById(permissionId);
     if (this.permissions.contains(permission)) {
       return true;
     }
   }
   return false;
 }
示例#3
0
  public static void deleteById(Long id) {
    if (id == null) throw new RuntimeException("id required");

    Permission permission = Permission.findById(id);
    if (permission == null) throw new RuntimeException("Permission not found");

    try {
      permission.delete();
    } catch (Throwable e) {
      throw new RuntimeException(
          "Could Not Delete This Permission Cause It is Assigned to Roles !");
    }
  }
示例#4
0
  public static void updateByVO(PermVO vo) {
    vo.validate();
    Permission p = Permission.findById(Long.parseLong(vo.id));
    if (p == null) throw new RuntimeException("Permission not found");

    p.action = vo.action;
    p.desc = vo.desc;

    Permission db_p = Permission.findByAction(p.action);
    if (db_p != null && db_p.id != p.id) throw new RuntimeException("Action duplicate!");

    p.save();
  }