apache / apache/cloudstack

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

オープン
#11,420 コメント 15 件 リアクション 0 件 担当者 0 名 GitHub で見る
long-term-plan no-issue-activity type:api-consistency
主要言語
Java
スター
3.1k
フォーク
1.4k
平均マージ
6日 19時間
マージ済み PR(30日)
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 を短くまとめたダイジェスト。