@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { // starting on ICS, some WebView methods // can only be called on UI threads mCallbackContext = callbackContext; mAction = action; mArgs = args; if (action.equals("saveScreenshot")) { if (PermissionHelper.hasPermission(this, PERMISSIONS[0])) { saveScreenshot(); } else { PermissionHelper.requestPermissions(this, SAVE_SCREENSHOT_SEC, PERMISSIONS); } return true; } else if (action.equals("getScreenshotAsURI")) { if (PermissionHelper.hasPermission(this, PERMISSIONS[0])) { getScreenshotAsURI(); } else { PermissionHelper.requestPermissions(this, SAVE_SCREENSHOT_URI_SEC, PERMISSIONS); } return true; } callbackContext.error("action not found"); return false; }
public void delResource(Long resourceId, String resourceTypeId) { flush(); String applicationID = PermissionHelper.getApplicationID(); String permissionTable = resourceTypeDao.getPermissionTable(applicationID, resourceTypeId); executeHQL( "delete " + permissionTable + " t where t.resourceId = ?", resourceId); // 删除该资源的所有授权信息 }
public void moveResource(Long resourceId, String resourceTypeId) { String applicationID = PermissionHelper.getApplicationID(); String permissionTable = resourceTypeDao.getPermissionTable(applicationID, resourceTypeId); String resourceTable = resourceTypeDao.getResourceTable(applicationID, resourceTypeId); List<?> subTree = getChildrenById(resourceTable, resourceId); // 连同自身节点 IResource resource = (IResource) getEntity(BeanUtil.createClassByName(resourceTable), resourceId); String hql = "from " + permissionTable + " t where t.resourceId = ?"; List<?> parentPermissions = getEntities(hql, resource.getParentId()); String deleteHQL = "delete " + permissionTable + " t where t.resourceId = ? and t.roleId = ? " + " and t.operationId = ? and t.isGrant = ? and t.isPass = ?"; for (Object temp : parentPermissions) { AbstractPermission parentPermission = (AbstractPermission) temp; Integer parentPermissionState = parentPermission.getPermissionState(); // 判断移动后的父节点对各个操作权限的授权是否为全勾;如果为全勾,则移动过去整枝节点的授权状态都为全勾。 if (parentPermissionState.equals(UMConstants.PERMIT_SUB_TREE)) { for (Object node : subTree) { IResource child = (IResource) node; // 先删除已经存在的资源操作的权限 executeHQL( deleteHQL, child.getId(), parentPermission.getRoleId(), parentPermission.getOperationId(), parentPermission.getIsGrant(), parentPermission.getIsPass()); // 重新按(祖)父节点的权限(全勾)进行授权 PermissionHelper.getInstance().createPermission(parentPermission, child, permissionTable); } } // 如果父节点是半勾,则移动过来的整枝权限不变 } // TODO 子节点有权限的操作项而继父节点没有的,暂不予处理。如果要保持界面上统一(子节点有勾选的,父节点也必然被勾选)的话,需要考虑删除子节点的这类权限 }
public void addResource(Long resourceId, String resourceTypeId) { flush(); String applicationID = PermissionHelper.getApplicationID(); String permissionTable = resourceTypeDao.getPermissionTable(applicationID, resourceTypeId); String resourceTable = resourceTypeDao.getResourceTable(applicationID, resourceTypeId); IResource resource = (IResource) getEntity(BeanUtil.createClassByName(resourceTable), resourceId); if (resource == null) { throw new BusinessException("权限补齐时找不到资源对象,请检查资源视图(" + resourceTable + ")中是否包含该对象?是否过滤掉了?"); } String hql = "from " + permissionTable + " t where t.resourceId = ? and t.permissionState = ?"; List<?> parentPermissions = getEntities(hql, resource.getParentId(), UMConstants.PERMIT_SUB_TREE); for (Object temp : parentPermissions) { AbstractPermission parentPermission = (AbstractPermission) temp; PermissionHelper.getInstance().createPermission(parentPermission, resource, permissionTable); } }
public List<?> getParentResourceIds( String applicationId, String resourceTypeId, Long resourceId, String operationId, Long operatorId) { String resourceTable = resourceTypeDao.getResourceTable(PermissionHelper.getApplicationID(), resourceTypeId); Class<?> resourceClazz = BeanUtil.createClassByName(resourceTable); IResource resource = (IResource) getEntity(resourceClazz, resourceId); String permissionTable = resourceTypeDao.getPermissionTable(applicationId, resourceTypeId); String hql = "select distinct t.id from " + resourceClazz.getName() + " t, RoleUserMapping r, " + permissionTable + " v" + " where t.id = v.resourceId and v.roleId = r.id.roleId and r.id.userId = ? and v.operationId = ? and ? like t.decode || '%'"; return getEntities(hql, operatorId, operationId, resource.getDecode()); }