apache / apache/cloudstack

[Templates] "isFeatured" flag not retained when owner is not Root Admin

未关闭
#11,420 15 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
long-term-plan no-issue-activity type:api-consistency
主要语言
Java
星标
3.1k
派生
1.4k
平均合并
6 天 19 小时
30 天内合并 PR
32

描述

### problem

I'm encountering unexpected behavior in the TemplateAdapterBase.prepare(...) method. Specifically, when creating a new template with the isfeatured flag set, the system ignores this flag unless the template owner is Root Admin. Here's a breakdown of the problematic logic:

https://github.com/apache/cloudstack/blob/7d59bfe2b59eb06a71c68262dfb08de8ee422ad4/server/src/main/java/com/cloud/template/TemplateAdapterBase.java

// File: TemplateAdapterBase.java

```
public TemplateProfile prepare(..., Account templateOwner, ...) throws ResourceAllocationException {
// ...
boolean isAdmin = _accountMgr.isRootAdmin(templateOwner.getId());

// ...
// Lines 225–228: Key decision point:
if (!isAdmin || featured == null) {
featured = Boolean.FALSE;
}
// ...
// Line 280: The TemplateProfile is created with `featured` potentially overwritten
return new TemplateProfile(..., featured, ...);
}
```

According to the current validation logic, if a template is being created (`registerTemplate` API) using the `domainid` and `account` parameters (i.e. on behalf of another account), and` isfeatured=true` is specified, the value of `isfeatured` is automatically overridden and set to `false`.
https://github.com/apache/cloudstack/pull/8210/files

### versions

_No response_

### The steps to reproduce the bug

1. Call the `registerTemplate` API:
```
{
//...
"account": "test-account",
"domainid": "UUID-DOMAIN",
"isfeatured": true
}
```
2. Ensure that the target account (specified via `account` and `domainid`) has the `Domain Admin` role.
3. After registration, check the `isfeatured` flag on the created template.

### What to do about it?

Expected behavior:
If `isfeatured = true` is specified in the API request along with `domainid` and `account` parameters, the `isfeatured` value should be correctly applied.

贡献指南

打开贡献指南

调研方向

从 server/src/main/java/com/cloud/template/TemplateAdapterBase.java 开始,重点查看 prepare(...) 以及 issue 中描述的 registerTemplate API 路径。使用 account、domainid 和 isfeatured=true 重现请求,然后跟踪 featured 值如何传递到 TemplateProfile;对于所述的非 Root-Admin 所有者,创建的模板仍保留 isfeatured=true 即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
backend, cloud
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。