Skip to content

Commit

Permalink
Merge branch 'master' of github.com:zanata/zanata-platform into eflod…
Browse files Browse the repository at this point in the history
…en/editor-user-roles/ZNTA-2380
  • Loading branch information
efloden committed Feb 21, 2018
2 parents cdec3b1 + 1a74f3a commit 438add0
Show file tree
Hide file tree
Showing 28 changed files with 427 additions and 129 deletions.
@@ -0,0 +1,8 @@
<ruleset comparisonMethod="maven"
xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
<!-- Thanks to Michael Piefel and Philip Helger: https://stackoverflow.com/a/22174801/14379 -->
<ignoreVersions>
<ignoreVersion type="regex">.*[-_\.](alpha|Alpha|ALPHA|b|beta|Beta|BETA|cr|CR|rc|RC|M|EA)[-_\.]?[0-9]*</ignoreVersion>
</ignoreVersions>
</ruleset>
25 changes: 24 additions & 1 deletion parent/pom.xml
Expand Up @@ -596,7 +596,17 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.2</version>
<version>2.5</version>
<configuration>
<rulesUri>classpath:///zanata-build-tools/versions-rules.xml</rulesUri>
</configuration>
<dependencies>
<dependency>
<groupId>org.zanata</groupId>
<artifactId>build-tools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
Expand Down Expand Up @@ -843,6 +853,19 @@
</executions>
</plugin>

<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.1</version>
<extensions>true</extensions>
<configuration>
<!-- The Base URL of Nexus instance where we want to stage -->
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<!-- The server "id" element from settings to use authentication from -->
<serverId>sonatype-staging</serverId>
</configuration>
</plugin>

<!-- Deploy javadocs to OSSRH -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Expand Up @@ -48,21 +48,34 @@ public class ActivateAction implements Serializable {

private static final long serialVersionUID = -8079131168179421345L;
private static final int LINK_ACTIVE_DAYS = 1;
@Inject

private GroupedConversation conversation;
@Inject
private AccountActivationKeyDAO accountActivationKeyDAO;
@Inject
private IdentityManager identityManager;
@Inject
private UrlUtil urlUtil;
@Inject

private FacesMessages facesMessages;
private String activationKey;
private HAccountActivationKey key;
private String resetPasswordKey;
// @Begin(join = true)

@Inject
public ActivateAction(GroupedConversation conversation,
AccountActivationKeyDAO accountActivationKeyDAO,
IdentityManager identityManager,
UrlUtil urlUtil, FacesMessages facesMessages) {
this.conversation = conversation;
this.accountActivationKeyDAO = accountActivationKeyDAO;
this.identityManager = identityManager;
this.urlUtil = urlUtil;
this.facesMessages = facesMessages;
}

@SuppressWarnings("unused")
public ActivateAction() {
}

public void validateActivationKey() {
if (getActivationKey() == null) {
throw new KeyNotFoundException("null activation key");
Expand Down
@@ -0,0 +1,133 @@
/*
* Copyright 2018, 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.action;

import org.apache.deltaspike.core.api.scope.GroupedConversation;
import org.jglue.cdiunit.InRequestScope;
import org.jglue.cdiunit.InSessionScope;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.zanata.dao.AccountActivationKeyDAO;
import org.zanata.exception.ActivationLinkExpiredException;
import org.zanata.exception.KeyNotFoundException;
import org.zanata.model.HAccount;
import org.zanata.model.HAccountActivationKey;
import org.zanata.seam.security.IdentityManager;
import org.zanata.test.CdiUnitRunner;
import org.zanata.ui.faces.FacesMessages;
import org.zanata.util.UrlUtil;

import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import java.util.Date;

import static org.mockito.Mockito.when;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author djansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
@InSessionScope
@InRequestScope
@RunWith(CdiUnitRunner.class)
public class ActivateActionTest {

@Produces
@Mock
private GroupedConversation conversation;
@Produces
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private AccountActivationKeyDAO accountActivationKeyDAO;
@Produces
@Mock
private IdentityManager identityManager;
@Produces
@Mock
private UrlUtil urlUtil;
@Produces
@Mock
private FacesMessages facesMessages;
@Inject
private ActivateAction action;

@Before
public void before() {
action = new ActivateAction(conversation, accountActivationKeyDAO,
identityManager, urlUtil, facesMessages);
}

@Test
public void nullKeyTest() {
action.setActivationKey(null);
try {
action.validateActivationKey();
Assert.fail("Expected KeyNotFoundException");
} catch (KeyNotFoundException knfe) {
assertThat(knfe.getMessage()).contains("null activation key");
}
}

@Test
public void keyNoLongerExists() {
action.setActivationKey("1234567890");
when(accountActivationKeyDAO.findById(action.getActivationKey(), false))
.thenReturn(null);
try {
action.validateActivationKey();
Assert.fail("Expected KeyNotFoundException");
} catch (KeyNotFoundException knfe) {
assertThat(knfe.getMessage()).contains("activation key: 1234567890");
}
}

@Test
public void expiredKeyTest() {
HAccountActivationKey key = new HAccountActivationKey();
key.setCreationDate(new Date(0L));
action.setActivationKey("1234567890");
when(accountActivationKeyDAO.findById(action.getActivationKey(), false))
.thenReturn(key);
try {
action.validateActivationKey();
Assert.fail("Expected ActivationLinkExpiredException");
} catch (ActivationLinkExpiredException alee) {
assertThat(alee.getMessage())
.contains("Activation link expired:1234567890");
}
}

@Test
public void activateTest() {
HAccountActivationKey key = new HAccountActivationKey();
key.setCreationDate(new Date());
HAccount hAccount = new HAccount();
hAccount.setUsername("Aloy");
action.setActivationKey("1234567890");
when(accountActivationKeyDAO.findById(action.getActivationKey(), false))
.thenReturn(key);
action.validateActivationKey();
// TODO ZNTA-2365 action.activate();
}
}
@@ -0,0 +1,66 @@
/*
* Copyright 2018, 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.adapter;

import org.junit.Assert;
import org.junit.Test;
import org.zanata.exception.FileFormatAdapterException;

import java.net.URI;

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

/**
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class AdapterUtilsTest {

@Test
public void testNull() {
try {
AdapterUtils.readStream(URI.create(""));
Assert.fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException iae) {
assertThat(iae.getMessage()).contains("absolute");
}
}

@Test
public void testMalformed() {
try {
AdapterUtils.readStream(URI
.create("http://2aff:eaff:eaff:7aff:8aff:5aff:faff:eaff:8080/foo"));
Assert.fail("Expected FileFormatAdapterException");
} catch (FileFormatAdapterException ffae) {
assertThat(ffae.getMessage()).contains("malformed");
}
}

@Test
public void testAccess() {
try {
AdapterUtils.readStream(URI.create("http://tmp"));
Assert.fail("Expected FileFormatAdapterException");
} catch (FileFormatAdapterException ffae) {
assertThat(ffae.getMessage()).contains("stream");
}
}
}
1 change: 1 addition & 0 deletions server/zanata-frontend/pom.xml
Expand Up @@ -133,6 +133,7 @@
<resources>
<resource>
<directory>src/dist</directory>
<include>messages/*.json</include>
<include>editor.*.cache.js</include>
<include>editor.*.cache.css</include>
<include>editor.*.cache.css.map</include>
Expand Down
7 changes: 7 additions & 0 deletions server/zanata-frontend/src/app/config.js
Expand Up @@ -8,6 +8,12 @@ const rawConfig = window.config
const config = mapValues(rawConfig || {}, (value) =>
isJsonString(value) ? JSON.parse(value) : value)

export const DEFAULT_LOCALE = {
localeId: 'en-US',
name: 'English',
isRTL: false
}

// URL this app is deployed to
export const appUrl = config.appUrl || ''

Expand All @@ -27,3 +33,4 @@ export const isAdmin = config.permission
: false
export const user = config.user
export const allowRegister = config.allowRegister || false
export const appLocale = config.appLocale || DEFAULT_LOCALE['localeId']
Expand Up @@ -4,6 +4,7 @@ export const TOGGLE_INFO_PANEL = 'TOGGLE_INFO_PANEL'
export const TOGGLE_HEADER = 'TOGGLE_HEADER'
export const TOGGLE_KEY_SHORTCUTS = 'TOGGLE_KEY_SHORTCUTS'
export const UI_LOCALES_FETCHED = 'UI_LOCALES_FETCHED'
export const APP_LOCALE_FETCHED = 'APP_LOCALE_FETCHED'
export const CHANGE_UI_LOCALE = 'CHANGE_UI_LOCALE'
export const DOCUMENT_SELECTED = 'DOCUMENT_SELECTED'
export const LOCALE_SELECTED = 'LOCALE_SELECTED'
Expand All @@ -12,3 +13,6 @@ export const HEADER_DATA_FETCHED = 'HEADER_DATA_FETCHED'
export const USER_PERMISSION_REQUEST = 'USER_PERMISSION_REQUEST'
export const USER_PERMISSION_SUCCESS = 'USER_PERMISSION_SUCCESS'
export const USER_PERMISSION_FAILURE = 'USER_PERMISSION_FAILURE'
export const LOCALE_MESSAGES_REQUEST = 'LOCALE_MESSAGES_REQUEST'
export const LOCALE_MESSAGES_SUCCESS = 'LOCALE_MESSAGES_SUCCESS'
export const LOCALE_MESSAGES_FAILURE = 'LOCALE_MESSAGES_FAILURE'
10 changes: 10 additions & 0 deletions server/zanata-frontend/src/app/editor/actions/header-actions.js
Expand Up @@ -2,6 +2,7 @@
import {
fetchStatistics,
fetchLocales,
fetchI18nLocale,
fetchMyInfo,
fetchProjectInfo,
fetchDocuments,
Expand All @@ -15,6 +16,7 @@ import {
TOGGLE_HEADER,
TOGGLE_KEY_SHORTCUTS,
UI_LOCALES_FETCHED,
APP_LOCALE_FETCHED,
CHANGE_UI_LOCALE,
DOCUMENT_SELECTED,
LOCALE_SELECTED,
Expand All @@ -40,6 +42,7 @@ const unwrapResponse = (_dispatch, _errorMsg, response) => {
}

export const uiLocaleFetched = createAction(UI_LOCALES_FETCHED)
export const appLocaleFetched = createAction(APP_LOCALE_FETCHED)

export function fetchUiLocales () {
return (dispatch) => {
Expand All @@ -54,6 +57,13 @@ export function fetchUiLocales () {
}
}

// fetches react-intl translation json files for app i18n
export function fetchAppLocale (locale) {
return (dispatch) => {
dispatch(fetchI18nLocale(locale))
}
}

export const changeUiLocale = createAction(CHANGE_UI_LOCALE)

const decodeDocId = (docId) => {
Expand Down

0 comments on commit 438add0

Please sign in to comment.