Skip to content

Commit

Permalink
feat: hide from profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Sep 13, 2017
1 parent b355487 commit 5b3bcba
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.enterprise.context.RequestScoped;
import javax.persistence.EntityManager;
import javax.ws.rs.GET;
Expand Down Expand Up @@ -57,6 +58,7 @@
import org.zanata.dao.DocumentDAO;
import org.zanata.dao.PersonDAO;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.dao.ProjectMemberDAO;
import org.zanata.dao.TextFlowTargetHistoryDAO;
import org.zanata.model.HDocument;
import org.zanata.model.HLocale;
Expand All @@ -73,6 +75,7 @@
import org.zanata.rest.dto.stats.contribution.BaseContributionStatistic;
import org.zanata.rest.dto.stats.contribution.ContributionStatistics;
import org.zanata.rest.dto.stats.contribution.LocaleStatistics;
import org.zanata.security.ZanataIdentity;
import org.zanata.service.TranslationStateCache;
import org.zanata.service.impl.LocaleServiceImpl;
import org.zanata.util.DateUtil;
Expand Down Expand Up @@ -112,7 +115,11 @@ public class StatisticsServiceImpl implements StatisticsResource {
@Inject
private EntityManager entityManager;
@Inject
private ProjectMemberDAO projectMemberDAO;
@Inject
private TranslationStateCache translationStateCacheImpl;
@Inject
private ZanataIdentity identity;
// TODO Need to refactor this method to get Message statistic by default.
// This is to be consistent with the UI which uses message stats, and for
// calculating remaining hours.
Expand Down Expand Up @@ -450,7 +457,7 @@ public List<TranslationMatrix> getUserWorkMatrix(
textFlowTargetHistoryDAO.getUserTranslationMatrix(person,
fromDate, toDate, userZoneOpt, systemZone,
new UserMatrixResultTransformer(entityManager,
dateFormatter));
identity, dateFormatter));
return translationMatrixList;
}

Expand Down Expand Up @@ -532,6 +539,7 @@ public static class UserMatrixResultTransformer
private final EntityManager entityManager;
@SuppressFBWarnings("SE_BAD_FIELD")
private final DateTimeFormatter dateFormatter;
private final ZanataIdentity identity;

@Override
public Object transformTuple(Object[] tuple, String[] aliases) {
Expand All @@ -543,6 +551,11 @@ public Object transformTuple(Object[] tuple, String[] aliases) {
String projectSlug = iteration.getProject().getSlug();
String projectName = iteration.getProject().getName();
String versionSlug = iteration.getSlug();
if (!identity.hasPermission(iteration.getProject(), "read")) {
projectSlug = null;
projectName = null;
versionSlug = null;
}
HLocale locale = entityManager.find(HLocale.class,
((BigInteger) tuple[2]).longValue());
String localeDisplayName = locale.retrieveDisplayName();
Expand All @@ -561,8 +574,10 @@ public List transformList(List collection) {

@java.beans.ConstructorProperties({ "entityManager", "dateFormatter" })
public UserMatrixResultTransformer(final EntityManager entityManager,
@Nullable final ZanataIdentity identity,
final DateTimeFormatter dateFormatter) {
this.entityManager = entityManager;
this.identity = identity;
this.dateFormatter = dateFormatter;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,31 @@ public boolean canManageRoles(String target) {
public boolean canCreateProject(HProject target) {
return identity.hasRole("project-creator");
}
/* anyone can read a project */

/**
* Anyone can read a non-private project
* Only project members can read private project
*/
@GrantsPermission(actions = "read")
public boolean canReadProject(HProject target) {
if (isAdmin()) {
return true;
}
if (!target.isPrivateProject()) {
return true;
}
return isProjectMember(target);
}
/* anyone can read a project iteration */

/**
* Anyone can read a non-private project
* Only project members can read private project
*/
@GrantsPermission(actions = "read")
public boolean canReadProjectIteration(HProjectIteration target) {
if (isAdmin()) {
return true;
}
if (!target.getProject().isPrivateProject()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.joda.time.format.DateTimeFormatter;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.zanata.ZanataJpaTest;
import org.zanata.common.ContentState;
import org.zanata.common.LocaleId;
Expand All @@ -28,11 +29,14 @@
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import org.zanata.security.ZanataIdentity;

import static org.assertj.core.api.Assertions.assertThat;

public class TextFlowTargetHistoryDAOTest extends ZanataJpaTest {

private TextFlowTargetHistoryDAO historyDAO;
private ZanataIdentity identity;
private HPerson user;
private HLocale hLocale;
private DateTime today = new DateTime();
Expand All @@ -45,9 +49,10 @@ public class TextFlowTargetHistoryDAOTest extends ZanataJpaTest {

@Before
public void setUp() throws Exception {
identity = Mockito.mock(ZanataIdentity.class);
resultTransformer =
new StatisticsServiceImpl.UserMatrixResultTransformer(getEm(),
dateFormatter);
identity, dateFormatter);
historyDAO = new TextFlowTargetHistoryDAO(getSession()) {

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.zanata.dao.TextFlowTargetDAO;
import org.zanata.exception.InvalidDateParamException;
import org.zanata.jpa.FullText;
import org.zanata.model.HAccount;
import org.zanata.model.HPerson;
import org.zanata.model.HTextFlowTarget;
import org.zanata.rest.NoSuchEntityException;
Expand All @@ -61,6 +62,7 @@
import org.zanata.rest.dto.stats.contribution.BaseContributionStatistic;
import org.zanata.rest.dto.stats.contribution.ContributionStatistics;
import org.zanata.rest.dto.stats.contribution.LocaleStatistics;
import org.zanata.security.annotations.Authenticated;
import org.zanata.service.ValidationService;
import org.zanata.service.impl.TranslationStateCacheImpl;
import org.zanata.service.impl.TranslationStateCacheImpl.DocumentStatisticLoader;
Expand Down Expand Up @@ -98,6 +100,10 @@ public class StatisticsServiceImplTest extends ZanataDbunitJpaTest {
@Produces @Mock ValidationService validationService;
@Produces @Mock @FullText FullTextEntityManager fullTextEntityManager;

@Produces @Authenticated
@Mock
HAccount authenticatedAccount;

@Override
@Produces
protected Session getSession() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React from 'react'
import PropTypes from 'prop-types'
import { isEmpty, isUndefined } from 'lodash'

const CategoryItemMatrix = ({
itemTitle,
itemName,
wordCount,
...props
}) => {
const title = isEmpty(itemTitle) || isUndefined(itemTitle) ||
itemTitle === 'null' ? '' : itemTitle
const name = isEmpty(itemName) || isUndefined(itemName) || itemName === 'null'
? 'N/A' : itemName
return (
<tr>
<td className='l--pad-left-0 l--pad-v-0 w--1'>
{itemTitle} <span className='txt--understated'>({itemName})</span>
{title} <span className='txt--understated'>({name})</span>
</td>
<td className='txt--align-right l--pad-right-0 l--pad-v-0 txt--nowrap'>
{wordCount} <span className='l--pad-left-quarter txt--understated'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
"description": "Title for an item in the activity feed showing a translator has deleted the translation. The inserted section is from ActivityFeedItem.deleted.deletedTranslation",
"defaultMessage": "{name} has {deletedTranslation}"
}
]
]

0 comments on commit 5b3bcba

Please sign in to comment.