Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Redirect user to project page when self remove as maintainer #838

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/release-notes.md
Expand Up @@ -40,7 +40,7 @@ Example usage in html file: `<link rel="shortcut icon" href="#{assets['img/logo/
* [1165930](https://bugzilla.redhat.com/show_bug.cgi?id=1165930) - 'Copy from previous version' shows if an obsolete version exists
* [1098362](https://bugzilla.redhat.com/show_bug.cgi?id=1098362) - download link in editor doesn't encode properly and result in 404
* [1225689](https://bugzilla.redhat.com/show_bug.cgi?id=1225689) - [Project Version View] Failed to load entries when the doc id contains characters that should be URL encoded

* [1112498](https://bugzilla.redhat.com/show_bug.cgi?id=1112498) - Unable to remove self as maintainer
-----------------------

<h5>New Features</h5>
Expand Down
81 changes: 34 additions & 47 deletions zanata-war/src/main/java/org/zanata/action/ProjectHome.java
Expand Up @@ -52,6 +52,7 @@
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.faces.FacesManager;
import org.jboss.seam.faces.Redirect;
import org.jboss.seam.security.management.JpaIdentityStore;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
Expand All @@ -68,7 +69,6 @@
import org.zanata.model.HProjectIteration;
import org.zanata.model.WebHook;
import org.zanata.model.validator.SlugValidator;
import org.zanata.seam.scope.ConversationScopeMessages;
import org.zanata.security.ZanataIdentity;
import org.zanata.service.LocaleService;
import org.zanata.service.SlugEntityService;
Expand All @@ -79,6 +79,7 @@
import org.zanata.ui.faces.FacesMessages;
import org.zanata.util.CommonMarkRenderer;
import org.zanata.util.ComparatorUtil;
import org.zanata.util.ServiceLocator;
import org.zanata.util.UrlUtil;
import org.zanata.webtrans.shared.model.ValidationAction;
import org.zanata.webtrans.shared.model.ValidationId;
Expand Down Expand Up @@ -131,9 +132,6 @@ public class ProjectHome extends SlugHome<HProject> implements
@In("commonMarkRenderer")
private CommonMarkRenderer renderer;

@In
private ConversationScopeMessages conversationScopeMessages;

@In
private EntityManager entityManager;

Expand Down Expand Up @@ -563,8 +561,8 @@ public void useDefaultLocales() {
removeAliasesForDisabledLocales();
refreshDisabledLocales();
update();
conversationScopeMessages.setMessage(FacesMessage.SEVERITY_INFO,
msgs.get("jsf.project.LanguageUpdateFromGlobal"));
facesMessages.addGlobal(FacesMessage.SEVERITY_INFO,
msgs.get("jsf.project.LanguageUpdateFromGlobal"));
}

private void removeAliasesForDisabledLocales() {
Expand Down Expand Up @@ -671,9 +669,8 @@ public void updateCopyTrans(String action, String value) {
copyTransOptionsModel.getInstance());

update();

conversationScopeMessages.setMessage(FacesMessage.SEVERITY_INFO,
msgs.get("jsf.project.CopyTransOpts.updated"));
facesMessages.addGlobal(FacesMessage.SEVERITY_INFO,
msgs.get("jsf.project.CopyTransOpts.updated"));
}

public void initialize() {
Expand Down Expand Up @@ -808,24 +805,26 @@ public List<HPerson> getInstanceMaintainers() {
return list;
}

@In
private Redirect redirect;

@Restrict("#{s:hasPermission(projectHome.instance, 'update')}")
public String removeMaintainer(HPerson person) {
if (getInstanceMaintainers().size() <= 1) {
conversationScopeMessages
.setMessage(FacesMessage.SEVERITY_INFO,
msgs.get("jsf.project.NeedAtLeastOneMaintainer"));
facesMessages.addGlobal(FacesMessage.SEVERITY_INFO,
msgs.get("jsf.project.NeedAtLeastOneMaintainer"));
} else {
getInstance().getMaintainers().remove(person);
maintainerFilter.reset();
update();

conversationScopeMessages.setMessage(FacesMessage.SEVERITY_INFO,
msgs.format("jsf.project.MaintainerRemoved",
person.getName()));

// force page to do url redirect to project page. See pages.xml
facesMessages.addGlobal(FacesMessage.SEVERITY_INFO,
msgs.format("jsf.project.MaintainerRemoved",
person.getName()));
if (person.equals(authenticatedAccount.getPerson())) {
return "redirect";
redirect.setViewId("/project/project.xhtml");
redirect.setParameter("slug", getSlug());
redirect.execute();
}
}
return "";
Expand All @@ -846,8 +845,8 @@ public void updateRoles(String roleName, boolean isRestricted) {
}
}
update();
conversationScopeMessages.setMessage(FacesMessage.SEVERITY_INFO,
msgs.get("jsf.RolesUpdated"));
facesMessages.addGlobal(FacesMessage.SEVERITY_INFO,
msgs.get("jsf.RolesUpdated"));
}

@Restrict("#{s:hasPermission(projectHome.instance, 'update')}")
Expand All @@ -871,10 +870,9 @@ public void updateStatus(char initial) {
}
}
update();

conversationScopeMessages.setMessage(FacesMessage.SEVERITY_INFO,
msgs.format("jsf.project.status.updated",
EntityStatus.valueOf(initial)));
facesMessages.addGlobal(FacesMessage.SEVERITY_INFO,
msgs.format("jsf.project.status.updated",
EntityStatus.valueOf(initial)));
}

public void deleteSelf() {
Expand Down Expand Up @@ -990,10 +988,9 @@ public void updateValidationOption(String name, String state) {
}
}
update();

conversationScopeMessages.setMessage(FacesMessage.SEVERITY_INFO,
msgs.format("jsf.validation.updated",
validationId.getDisplayName(), state));
facesMessages.addGlobal(FacesMessage.SEVERITY_INFO,
msgs.format("jsf.validation.updated",
validationId.getDisplayName(), state));
}

public List<ValidationAction> getValidationList() {
Expand Down Expand Up @@ -1083,19 +1080,6 @@ protected void updatedMessage() {
// Disable the default message from Seam
}

/**
* This is for autocomplete components of which ConversationScopeMessages
* will be null
*
* @param conversationScopeMessages
*/
private String update(ConversationScopeMessages conversationScopeMessages) {
if (this.conversationScopeMessages == null) {
this.conversationScopeMessages = conversationScopeMessages;
}
return update();
}

private boolean checkViewObsolete() {
return identity != null
&& identity.hasPermission("HProject", "view-obsolete");
Expand All @@ -1115,17 +1099,20 @@ protected List<HPerson> getMaintainers() {
public void onSelectItemAction() {
if (StringUtils.isEmpty(getSelectedItem())) {
return;
}

}

HPerson maintainer = personDAO.findByUsername(getSelectedItem());
getInstance().addMaintainer(maintainer);
update(conversationScopeMessages);
update();
reset();

conversationScopeMessages.setMessage(FacesMessage.SEVERITY_INFO,
msgs.format("jsf.project.MaintainerAdded",
maintainer.getName()));
getFacesMessages().addGlobal(FacesMessage.SEVERITY_INFO,
msgs.format("jsf.project.MaintainerAdded",
maintainer.getName()));
}

private FacesMessages getFacesMessages() {
return ServiceLocator.instance().getInstance(FacesMessages.class);
}
}

Expand Down
7 changes: 0 additions & 7 deletions zanata-war/src/main/webapp/WEB-INF/pages.xml
Expand Up @@ -318,13 +318,6 @@
<param name="slug" value="#{projectHome.slug}" />
<param name="slug" value="#{projectHomeAction.slug}" />
<action execute="#{projectHome.initialize}" />
<navigation from-action="#{projectHome.removeMaintainer}">
<rule if-outcome="redirect">
<redirect view-id="/project/project.xhtml">
<param name="slug" value="#{projectHome.slug}" />
</redirect>
</rule>
</navigation>
<navigation from-action="#{projectHome.update}">
<rule if-outcome="projectSlugUpdated">
<redirect view-id="/project/project.xhtml">
Expand Down