Permalink
Browse files

Implemented accecc restriction on editor

  • Loading branch information...
1 parent 867dc84 commit 718729424965473519a863a0f2d95713eb02ba66 @aeng aeng committed Jan 5, 2012
Showing with 333 additions and 130 deletions.
  1. +3 −0 server/zanata-model/src/main/java/org/zanata/model/HProject.java
  2. +3 −0 server/zanata-model/src/main/java/org/zanata/model/HProjectIteration.java
  3. +2 −5 server/zanata-model/src/main/java/org/zanata/model/SlugEntityBase.java
  4. +100 −0 server/zanata-model/src/main/java/org/zanata/model/type/StatusTypeType.java
  5. +0 −16 server/zanata-war/src/main/java/org/zanata/action/ProjectAction.java
  6. +7 −4 server/zanata-war/src/main/java/org/zanata/action/ProjectHome.java
  7. +0 −5 server/zanata-war/src/main/java/org/zanata/action/ProjectIterationAction.java
  8. +3 −1 server/zanata-war/src/main/java/org/zanata/action/ProjectIterationHome.java
  9. +0 −9 server/zanata-war/src/main/java/org/zanata/action/ProjectPagedListDataModel.java
  10. +33 −0 server/zanata-war/src/main/java/org/zanata/action/SlugHome.java
  11. +1 −1 server/zanata-war/src/main/java/org/zanata/dao/ProjectDAO.java
  12. +37 −14 server/zanata-war/src/main/java/org/zanata/rest/service/TranslationResourcesService.java
  13. +8 −2 .../zanata-war/src/main/java/org/zanata/webtrans/client/editor/table/TableEditorTableDefinition.java
  14. +7 −4 server/zanata-war/src/main/java/org/zanata/webtrans/client/editor/table/TableEditorView.java
  15. +0 −1 server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/TranslationPresenter.java
  16. +27 −6 server/zanata-war/src/main/java/org/zanata/webtrans/server/TranslationWorkspaceManager.java
  17. +41 −4 server/zanata-war/src/main/java/org/zanata/webtrans/server/rpc/ActivateWorkspaceHandler.java
  18. +6 −2 server/zanata-war/src/main/java/org/zanata/webtrans/server/rpc/GetTransMemoryHandler.java
  19. +3 −3 server/zanata-war/src/main/java/org/zanata/webtrans/shared/auth/Identity.java
  20. +1 −1 server/zanata-war/src/main/java/org/zanata/webtrans/shared/auth/Permission.java
  21. +0 −20 server/zanata-war/src/main/java/org/zanata/webtrans/shared/auth/Role.java
  22. +8 −2 server/zanata-war/src/main/java/org/zanata/webtrans/shared/model/WorkspaceContext.java
  23. +2 −2 server/zanata-war/src/main/resources/db/changelogs/db.changelog-1.6.xml
  24. +2 −3 server/zanata-war/src/main/resources/messages.properties
  25. +5 −10 server/zanata-war/src/main/webapp/WEB-INF/layout/iteration_edit_form.xhtml
  26. +0 −2 server/zanata-war/src/main/webapp/WEB-INF/layout/iteration_view_inline.xhtml
  27. +5 −3 server/zanata-war/src/main/webapp/WEB-INF/layout/project_edit_form.xhtml
  28. +6 −1 server/zanata-war/src/main/webapp/project/home.xhtml
  29. +11 −6 server/zanata-war/src/main/webapp/project/project.xhtml
  30. +10 −0 server/zanata-war/src/main/webapp/stylesheet/theme.css
  31. +2 −3 server/zanata-war/src/test/java/org/zanata/webtrans/client/rpc/DummyActivateWorkspaceCommand.java
@@ -34,11 +34,13 @@
import javax.persistence.ManyToMany;
import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.jboss.seam.annotations.security.Restrict;
+import org.zanata.model.type.StatusTypeType;
import org.zanata.rest.dto.Project;
/**
@@ -48,6 +50,7 @@
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "projecttype", discriminatorType = DiscriminatorType.STRING)
+@TypeDef(name = "statusType", typeClass = StatusTypeType.class)
@Restrict
public abstract class HProject extends SlugEntityBase implements Serializable
{
@@ -37,9 +37,11 @@
import javax.persistence.OrderBy;
import org.hibernate.annotations.NaturalId;
+import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.Where;
import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.security.Restrict;
+import org.zanata.model.type.StatusTypeType;
import org.zanata.rest.dto.ProjectIteration;
/**
@@ -48,6 +50,7 @@
*
*/
@Entity
+@TypeDef(name = "statusType", typeClass = StatusTypeType.class)
@Restrict
public class HProjectIteration extends SlugEntityBase
{
@@ -20,11 +20,10 @@
*/
package org.zanata.model;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
import javax.persistence.MappedSuperclass;
import org.hibernate.annotations.NaturalId;
+import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Field;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
@@ -36,7 +35,6 @@
{
private String slug;
- @Enumerated(EnumType.STRING)
private StatusType status;
@NaturalId
@@ -54,6 +52,7 @@ public void setSlug(String slug)
this.slug = slug;
}
+ @Type(type = "statusType")
public StatusType getStatus()
{
return status;
@@ -64,11 +63,9 @@ public void setStatus(StatusType status)
this.status = status;
}
-
@Override
public String toString()
{
return super.toString() + "[slug=" + slug + "]";
}
-
}
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2010, Red Hat, Inc. and individual contributors as indicated by the
+ * @author tags. See the copyright.txt file in the distribution for a full
+ * listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.zanata.model.type;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.hibernate.EntityMode;
+import org.hibernate.HibernateException;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.type.ImmutableType;
+import org.hibernate.type.LiteralType;
+import org.hibernate.type.StringType;
+
+public class StatusTypeType extends ImmutableType implements LiteralType
+{
+
+ private static final long serialVersionUID = 1251881884197592346L;
+
+ @Override
+ public Object get(ResultSet rs, String name) throws HibernateException, SQLException
+ {
+ return fromStringValue((String) new StringType().get(rs, name));
+ }
+
+ @Override
+ public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException
+ {
+ new StringType().set(st, value.toString(), index);
+ }
+
+ @Override
+ public Object fromStringValue(String string)
+ {
+ if (string == null)
+ {
+ return null;
+ }
+ else
+ {
+ return StatusType.valueOf(string);
+ }
+ }
+
+ @Override
+ public int compare(Object x, Object y, EntityMode entityMode)
+ {
+ return x.toString().compareTo(y.toString());
+ }
+
+ @Override
+ public int sqlType()
+ {
+ return new StringType().sqlType();
+ }
+
+ @Override
+ public String toString(Object value) throws HibernateException
+ {
+ return value.toString();
+ }
+
+ @Override
+ public Class<?> getReturnedClass()
+ {
+ return StatusType.class;
+ }
+
+ @Override
+ public String getName()
+ {
+ return "statusType";
+ }
+
+ @Override
+ public String objectToSQLString(Object value, Dialect dialect) throws Exception
+ {
+ return ((LiteralType) new StringType()).objectToSQLString(value.toString(), dialect);
+ }
+
+}
@@ -65,14 +65,6 @@ public boolean getEmpty()
}
else
{
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("===========here3=========");
return projectDAO.getFilteredProjectSize() == 0;
}
}
@@ -85,14 +77,6 @@ public int getPageSize()
}
else
{
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("===========here2=========");
return filteredProjectPagedListDataModel.getPageSize();
}
}
@@ -20,11 +20,13 @@
*/
package org.zanata.action;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.event.ValueChangeEvent;
+import javax.faces.model.SelectItem;
import javax.persistence.NoResultException;
import org.hibernate.Session;
@@ -42,6 +44,7 @@
import org.zanata.model.HLocale;
import org.zanata.model.HPerson;
import org.zanata.model.HProjectIteration;
+import org.zanata.model.type.StatusType;
import org.zanata.service.LocaleService;
@Name("projectHome")
@@ -129,21 +132,21 @@ public String persist()
}
@SuppressWarnings("unchecked")
- public List<HProjectIteration> getActiveIterations()
+ public List<HProjectIteration> getCurrentIterations()
{
- return getEntityManager().createQuery("from HProjectIteration t where t.project.slug = :projectSlug and t.active = true and t.obsolete = false").setParameter("projectSlug", slug).getResultList();
+ return getEntityManager().createQuery("from HProjectIteration t where t.project.slug = :projectSlug and t.status = :status").setParameter("projectSlug", slug).setParameter("status", StatusType.Current).getResultList();
}
@SuppressWarnings("unchecked")
public List<HProjectIteration> getRetiredIterations()
{
- return getEntityManager().createQuery("from HProjectIteration t where t.project.slug = :projectSlug and t.active = false and t.obsolete = false").setParameter("projectSlug", slug).getResultList();
+ return getEntityManager().createQuery("from HProjectIteration t where t.project.slug = :projectSlug and t.status = :status").setParameter("projectSlug", slug).setParameter("status", StatusType.Retired).getResultList();
}
@SuppressWarnings("unchecked")
public List<HProjectIteration> getObsoleteIterations()
{
- return getEntityManager().createQuery("from HProjectIteration t where t.project.slug = :projectSlug and t.obsolete = true").setParameter("projectSlug", slug).getResultList();
+ return getEntityManager().createQuery("from HProjectIteration t where t.project.slug = :projectSlug and t.status = :status").setParameter("projectSlug", slug).setParameter("status", StatusType.Obsolete).getResultList();
}
public String cancel()
@@ -27,10 +27,8 @@
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Identity;
-import org.zanata.dao.ProjectIterationDAO;
import org.zanata.model.HProjectIteration;
import org.zanata.security.BaseSecurityChecker;
@@ -46,9 +44,6 @@
@In
Identity identity;
- @In
- private ProjectIterationDAO projectIterationDAO;
-
private HProjectIteration securedEntity = null;
@@ -20,10 +20,12 @@
*/
package org.zanata.action;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.event.ValueChangeEvent;
+import javax.faces.model.SelectItem;
import javax.persistence.EntityNotFoundException;
import javax.persistence.NoResultException;
@@ -38,6 +40,7 @@
import org.zanata.model.HIterationProject;
import org.zanata.model.HLocale;
import org.zanata.model.HProjectIteration;
+import org.zanata.model.type.StatusType;
import org.zanata.service.LocaleService;
@Name("projectIterationHome")
@@ -191,5 +194,4 @@ else if (iterationCustomizedItems != null)
}
}
}
-
}
@@ -50,15 +50,6 @@ public ProjectPagedListDataModel(boolean filterList)
}
else
{
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("============================");
- System.out.println("===========here5=========");
-
proj = projectDAO.getFilteredOffsetListByCreateDate(startRow, pageSize);
return new DataPage<HProject>(projectDAO.getFilteredProjectSize(), startRow, proj);
}
@@ -20,10 +20,16 @@
*/
package org.zanata.action;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.model.SelectItem;
+
import org.hibernate.Session;
import org.hibernate.criterion.NaturalIdentifier;
import org.jboss.seam.framework.EntityHome;
import org.jboss.seam.security.Identity;
+import org.zanata.model.type.StatusType;
import org.zanata.security.SecurityChecker;
/**
@@ -36,6 +42,8 @@
private static final long serialVersionUID = 1L;
+ private List<SelectItem> statusList = new ArrayList<SelectItem>();
+
@SuppressWarnings("unchecked")
@Override
protected E loadInstance()
@@ -58,4 +66,29 @@ public boolean checkPermission(String operation)
return Identity.instance() != null && Identity.instance().hasPermission(this.getInstance(), operation);
}
+ public List<SelectItem> getStatusList()
+ {
+ if (statusList.isEmpty())
+ {
+ for (StatusType status : StatusType.values())
+ {
+ if (status == StatusType.Obsolete)
+ {
+ if (checkPermission("mark-obsolete"))
+ {
+ SelectItem option = new SelectItem(status, status.name());
+ statusList.add(option);
+ }
+ }
+ else
+ {
+ // no restriction on other status
+ SelectItem option = new SelectItem(status, status.name());
+ statusList.add(option);
+ }
+ }
+ }
+ return statusList;
+ }
+
}
@@ -52,7 +52,7 @@ public HProject getBySlug(String slug)
@SuppressWarnings("unchecked")
public List<HProject> getFilteredOffsetListByCreateDate(int offset, int count)
{
- return getSession().createCriteria(HProject.class).addOrder(Order.desc(ORDERBY_TIMESTAMP)).add(Restrictions.eq("status", StatusType.Obsolete)).setMaxResults(count).setFirstResult(offset).setComment("ProjectDAO.getOffsetListByCreateDate").list();
+ return getSession().createCriteria(HProject.class).addOrder(Order.desc(ORDERBY_TIMESTAMP)).add(Restrictions.ne("status", StatusType.Obsolete)).setMaxResults(count).setFirstResult(offset).setComment("ProjectDAO.getOffsetListByCreateDate").list();
}
public int getFilteredProjectSize()
Oops, something went wrong.

0 comments on commit 7187294

Please sign in to comment.