Search in sources :

Example 1 with Project

use of com.axelor.project.db.Project in project open-platform-demo by axelor.

the class ProjectController method updateDefaultProject.

public void updateDefaultProject(ActionRequest request, ActionResponse response) {
    Long projectId = (Long) request.getContext().get("id");
    Project project = Beans.get(ProjectRepository.class).find(projectId);
    if (project == null || AuthUtils.getUser() == null) {
        return;
    }
    Beans.get(UpdateUserProjectService.class).updateDefaultProject(AuthUtils.getUser(), project);
    response.setNotify(I18n.get("Default project updated."));
}
Also used : Project(com.axelor.project.db.Project) ProjectRepository(com.axelor.project.db.repo.ProjectRepository) UpdateUserProjectService(com.axelor.project.service.UpdateUserProjectService)

Example 2 with Project

use of com.axelor.project.db.Project in project open-platform-demo by axelor.

the class UpdateUserProjectQuickMenu method getItems.

public List<QuickMenuItem> getItems() {
    User user = AuthUtils.getUser();
    if (user == null || !Beans.get(JpaSecurity.class).isPermitted(JpaSecurity.CAN_READ, Project.class)) {
        return Collections.emptyList();
    }
    String action = ProjectController.class.getName() + ":updateDefaultProject";
    List<QuickMenuItem> items = new ArrayList<>();
    for (Project project : Query.of(Project.class).filter("?1 MEMBER OF self.members", user).fetch(10)) {
        boolean isDefaultProject = project.equals(user.getDefaultProject());
        QuickMenuItem item = new QuickMenuItem(project.getName(), action, new Context(project.getId(), Project.class), isDefaultProject);
        items.add(item);
    }
    return items;
}
Also used : Context(com.axelor.rpc.Context) Project(com.axelor.project.db.Project) User(com.axelor.auth.db.User) JpaSecurity(com.axelor.db.JpaSecurity) QuickMenuItem(com.axelor.ui.QuickMenuItem) ArrayList(java.util.ArrayList) ProjectController(com.axelor.project.web.ProjectController)

Aggregations

Project (com.axelor.project.db.Project)2 User (com.axelor.auth.db.User)1 JpaSecurity (com.axelor.db.JpaSecurity)1 ProjectRepository (com.axelor.project.db.repo.ProjectRepository)1 UpdateUserProjectService (com.axelor.project.service.UpdateUserProjectService)1 ProjectController (com.axelor.project.web.ProjectController)1 Context (com.axelor.rpc.Context)1 QuickMenuItem (com.axelor.ui.QuickMenuItem)1 ArrayList (java.util.ArrayList)1