[Templates] "isFeatured" flag not retained when owner is not Root Admin
- Lingua principale
- Java
- Stelle
- 3.1k
- Fork
- 1.4k
- Merge medio
- 6g 19h
- PR unite (30g)
- 32
Descrizione
### 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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia da server/src/main/java/com/cloud/template/TemplateAdapterBase.java, concentrandoti su prepare(...) e sul percorso dell’API registerTemplate descritto nell’issue. Riproduci la richiesta con account, domainid e isfeatured=true, quindi traccia come il valore di featured raggiunge TemplateProfile; il lavoro è completato quando il template creato conserva isfeatured=true per il proprietario indicato, che non è Root-Admin.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- backend, cloud
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100