[Templates] "isFeatured" flag not retained when owner is not Root Admin
- Vorherrschende Sprache
- Java
- Sterne
- 3.1k
- Forks
- 1.4k
- Ø Merge
- 6 T. 19 Std.
- Gemergte PRs (30 T.)
- 32
Beschreibung
### 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.
Beitragsleitfaden
Rechercherichtung
Beginne in server/src/main/java/com/cloud/template/TemplateAdapterBase.java und konzentriere dich auf prepare(...) sowie den im Issue beschriebenen registerTemplate-API-Pfad. Reproduziere die Anfrage mit account, domainid und isfeatured=true und verfolge anschließend, wie der Wert von featured TemplateProfile erreicht; erledigt ist es, wenn das erstellte Template isfeatured=true für den angegebenen Besitzer, der kein Root-Admin ist, beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- backend, cloud
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100