mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Update project account for all the events with project account owner, except for create project event (#9572)
This commit is contained in:
parent
6c0492366c
commit
674129cd58
@ -103,7 +103,7 @@ public class AddUserToProjectCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEventDescription() {
|
public String getEventDescription() {
|
||||||
return "Adding user "+getUsername()+" to Project "+getProjectId();
|
return "Adding user " + getUsername() + " to project: " + getProjectId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|||||||
@ -83,7 +83,6 @@ public class DeleteUserFromProjectCmd extends BaseAsyncCmd {
|
|||||||
return "Removing user " + userId + " from project: " + projectId;
|
return "Removing user " + userId + " from project: " + projectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getEntityOwnerId() {
|
public long getEntityOwnerId() {
|
||||||
Project project = _projectService.getProject(projectId);
|
Project project = _projectService.getProject(projectId);
|
||||||
|
|||||||
@ -88,13 +88,13 @@ public class ActionEventInterceptor implements ComponentMethodInterceptor, Metho
|
|||||||
for (ActionEvent actionEvent : getActionEvents(method)) {
|
for (ActionEvent actionEvent : getActionEvents(method)) {
|
||||||
CallContext ctx = CallContext.current();
|
CallContext ctx = CallContext.current();
|
||||||
long userId = ctx.getCallingUserId();
|
long userId = ctx.getCallingUserId();
|
||||||
long accountId = ctx.getProject() != null ? ctx.getProject().getProjectAccountId() : ctx.getCallingAccountId(); //This should be the entity owner id rather than the Calling User Account Id.
|
|
||||||
long startEventId = ctx.getStartEventId();
|
long startEventId = ctx.getStartEventId();
|
||||||
String eventDescription = getEventDescription(actionEvent, ctx);
|
String eventDescription = getEventDescription(actionEvent, ctx);
|
||||||
Long eventResourceId = getEventResourceId(actionEvent, ctx);
|
Long eventResourceId = getEventResourceId(actionEvent, ctx);
|
||||||
String eventResourceType = getEventResourceType(actionEvent, ctx);
|
String eventResourceType = getEventResourceType(actionEvent, ctx);
|
||||||
String eventType = getEventType(actionEvent, ctx);
|
String eventType = getEventType(actionEvent, ctx);
|
||||||
boolean isEventDisplayEnabled = ctx.isEventDisplayEnabled();
|
boolean isEventDisplayEnabled = ctx.isEventDisplayEnabled();
|
||||||
|
long accountId = ActionEventUtils.getOwnerAccountId(ctx, eventType, ctx.getCallingAccountId());
|
||||||
|
|
||||||
if (eventType.equals(""))
|
if (eventType.equals(""))
|
||||||
return;
|
return;
|
||||||
@ -118,13 +118,13 @@ public class ActionEventInterceptor implements ComponentMethodInterceptor, Metho
|
|||||||
for (ActionEvent actionEvent : getActionEvents(method)) {
|
for (ActionEvent actionEvent : getActionEvents(method)) {
|
||||||
CallContext ctx = CallContext.current();
|
CallContext ctx = CallContext.current();
|
||||||
long userId = ctx.getCallingUserId();
|
long userId = ctx.getCallingUserId();
|
||||||
long accountId = ctx.getCallingAccountId();
|
|
||||||
long startEventId = ctx.getStartEventId();
|
long startEventId = ctx.getStartEventId();
|
||||||
String eventDescription = getEventDescription(actionEvent, ctx);
|
String eventDescription = getEventDescription(actionEvent, ctx);
|
||||||
Long eventResourceId = getEventResourceId(actionEvent, ctx);
|
Long eventResourceId = getEventResourceId(actionEvent, ctx);
|
||||||
String eventResourceType = getEventResourceType(actionEvent, ctx);
|
String eventResourceType = getEventResourceType(actionEvent, ctx);
|
||||||
String eventType = getEventType(actionEvent, ctx);
|
String eventType = getEventType(actionEvent, ctx);
|
||||||
boolean isEventDisplayEnabled = ctx.isEventDisplayEnabled();
|
boolean isEventDisplayEnabled = ctx.isEventDisplayEnabled();
|
||||||
|
long accountId = ActionEventUtils.getOwnerAccountId(ctx, eventType, ctx.getCallingAccountId());
|
||||||
|
|
||||||
if (eventType.equals(""))
|
if (eventType.equals(""))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
@ -110,6 +111,8 @@ public class ActionEventUtils {
|
|||||||
*/
|
*/
|
||||||
public static Long onScheduledActionEvent(Long userId, Long accountId, String type, String description, Long resourceId, String resourceType, boolean eventDisplayEnabled, long startEventId) {
|
public static Long onScheduledActionEvent(Long userId, Long accountId, String type, String description, Long resourceId, String resourceType, boolean eventDisplayEnabled, long startEventId) {
|
||||||
Ternary<Long, String, String> resourceDetails = getResourceDetails(resourceId, resourceType, type);
|
Ternary<Long, String, String> resourceDetails = getResourceDetails(resourceId, resourceType, type);
|
||||||
|
CallContext ctx = CallContext.current();
|
||||||
|
accountId = getOwnerAccountId(ctx, type, accountId);
|
||||||
publishOnEventBus(userId, accountId, EventCategory.ACTION_EVENT.getName(), type, com.cloud.event.Event.State.Scheduled, description, resourceDetails.second(), resourceDetails.third());
|
publishOnEventBus(userId, accountId, EventCategory.ACTION_EVENT.getName(), type, com.cloud.event.Event.State.Scheduled, description, resourceDetails.second(), resourceDetails.third());
|
||||||
Event event = persistActionEvent(userId, accountId, null, null, type, Event.State.Scheduled, eventDisplayEnabled, description, resourceDetails.first(), resourceDetails.third(), startEventId);
|
Event event = persistActionEvent(userId, accountId, null, null, type, Event.State.Scheduled, eventDisplayEnabled, description, resourceDetails.first(), resourceDetails.third(), startEventId);
|
||||||
return event.getId();
|
return event.getId();
|
||||||
@ -123,7 +126,7 @@ public class ActionEventUtils {
|
|||||||
public static void onStartedActionEventFromContext(String eventType, String eventDescription, Long resourceId, String resourceType, boolean eventDisplayEnabled) {
|
public static void onStartedActionEventFromContext(String eventType, String eventDescription, Long resourceId, String resourceType, boolean eventDisplayEnabled) {
|
||||||
CallContext ctx = CallContext.current();
|
CallContext ctx = CallContext.current();
|
||||||
long userId = ctx.getCallingUserId();
|
long userId = ctx.getCallingUserId();
|
||||||
long accountId = ctx.getProject() != null ? ctx.getProject().getProjectAccountId() : ctx.getCallingAccountId(); //This should be the entity owner id rather than the Calling User Account Id.
|
long accountId = getOwnerAccountId(ctx, eventType, ctx.getCallingAccountId());
|
||||||
long startEventId = ctx.getStartEventId();
|
long startEventId = ctx.getStartEventId();
|
||||||
|
|
||||||
if (!eventType.equals(""))
|
if (!eventType.equals(""))
|
||||||
@ -393,7 +396,11 @@ public class ActionEventUtils {
|
|||||||
s_logger.trace("Caught exception while populating first class entities for event bus, moving on");
|
s_logger.trace("Caught exception while populating first class entities for event bus, moving on");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getOwnerAccountId(CallContext ctx, String eventType, long callingAccountId) {
|
||||||
|
List<String> mainProjectEvents = List.of(EventTypes.EVENT_PROJECT_CREATE, EventTypes.EVENT_PROJECT_UPDATE, EventTypes.EVENT_PROJECT_DELETE);
|
||||||
|
long accountId = ctx.getProject() != null && !mainProjectEvents.stream().anyMatch(eventType::equalsIgnoreCase) ? ctx.getProject().getProjectAccountId() : callingAccountId; //This should be the entity owner id rather than the Calling User Account Id.
|
||||||
|
return accountId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -279,16 +279,16 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager, C
|
|||||||
assignAccountToProject(project, ownerFinal.getId(), ProjectAccount.Role.Admin,
|
assignAccountToProject(project, ownerFinal.getId(), ProjectAccount.Role.Admin,
|
||||||
Optional.ofNullable(finalUser).map(User::getId).orElse(null), null);
|
Optional.ofNullable(finalUser).map(User::getId).orElse(null), null);
|
||||||
|
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
CallContext.current().setEventDetails("Project id=" + project.getId());
|
CallContext.current().setEventDetails("Project id=" + project.getId());
|
||||||
CallContext.current().putContextParameter(Project.class, project.getUuid());
|
CallContext.current().putContextParameter(Project.class, project.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Increment resource count
|
//Increment resource count
|
||||||
_resourceLimitMgr.incrementResourceCount(ownerFinal.getId(), ResourceType.project);
|
_resourceLimitMgr.incrementResourceCount(ownerFinal.getId(), ResourceType.project);
|
||||||
|
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
messageBus.publish(_name, ProjectManager.MESSAGE_CREATE_TUNGSTEN_PROJECT_EVENT, PublishScope.LOCAL, project);
|
messageBus.publish(_name, ProjectManager.MESSAGE_CREATE_TUNGSTEN_PROJECT_EVENT, PublishScope.LOCAL, project);
|
||||||
@ -1275,7 +1275,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager, C
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACTIVATE, eventDescription = "activating project")
|
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACTIVATE, eventDescription = "activating project", async = true)
|
||||||
@DB
|
@DB
|
||||||
public Project activateProject(final long projectId) {
|
public Project activateProject(final long projectId) {
|
||||||
Account caller = CallContext.current().getCallingAccount();
|
Account caller = CallContext.current().getCallingAccount();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user