[Templates] "isFeatured" flag not retained when owner is not Root Admin
- 主要語言
- Java
- 星號
- 3.1k
- 分支
- 1.4k
- 平均合併
- 7 天 14 小時
- 30 天內合併 PR
- 31
描述
### 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