Skip to content

Commit

Permalink
Merge branch 'eclipse-sw360:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdul Kapti authored Apr 27, 2023
2 parents 1f4869d + cd6d5cf commit 4afe6b8
Show file tree
Hide file tree
Showing 55 changed files with 873 additions and 210 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ on:
paths-ignore:
- "**.md"

permissions: write-all

env:
COUCHDB_USER: admin
COUCHDB_PASSWORD: password
Expand Down Expand Up @@ -69,9 +71,9 @@ jobs:
path: |
/usr/local/bin/thrift
/usr/share/thrift/${{ env.THRIFT_VERSION }}
key: ${{ runner.os }}-thrift-${{ hashFiles('/usr/local/bin/thrift') }}
key: ${{ runner.os }}-thrift-${{ env.THRIFT_VERSION }}
restore-keys: |
${{ runner.os }}-thrift-
${{ runner.os }}-thrift-${{ env.THRIFT_VERSION }}
- name: Install Thrift
if: steps.cache-thrift.outputs.cache-hit != 'true'
Expand All @@ -85,7 +87,7 @@ jobs:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
- name: Build SW360
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docker_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ on:
env:
REGISTRY: ghcr.io

permissions: write-all

jobs:
docker_push:
if: ${{ github.event.schedule }} == '0 0 * * *' || ${{ github.event.act }}
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,13 @@ RUN --mount=type=bind,target=/build/sw360,rw \
WORKDIR /sw360_tomcat_webapps/

COPY scripts/create-slim-war-files.sh /bin/slim.sh
COPY --from=sw360clucene /couchdb-lucene.war /sw360_tomcat_webapps

RUN bash /bin/slim.sh

FROM scratch AS sw360
COPY --from=sw360build /sw360_deploy /sw360_deploy
COPY --from=sw360build /sw360_tomcat_webapps /sw360_tomcat_webapps
COPY --from=sw360clucene /couchdb-lucene.war /sw360_tomcat_webapps
COPY --from=sw360build /etc/sw360 /etc/sw360

#--------------------------------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions backend/src/src-licenseinfo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
<groupId>org.spdx</groupId>
<artifactId>tools-java</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
Expand Down
12 changes: 4 additions & 8 deletions backend/src/src-licenses/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
~ SPDX-License-Identifier: EPL-2.0
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -22,7 +22,7 @@
<artifactId>src-licenses</artifactId>
<packaging>jar</packaging>
<name>src-licenses</name>

<properties>
<liferay.petra.function.version>5.1.2</liferay.petra.function.version>
</properties>
Expand All @@ -32,10 +32,6 @@
<groupId>org.spdx</groupId>
<artifactId>tools-java</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
</dependency>
<!-- Needed by spdx-tools -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand All @@ -52,4 +48,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ public RequestStatus updateClearingRequest(ClearingRequest request, User user, S
request.unsetPriority();
}
ClearingRequest currentRequest = getClearingRequestByIdForEdit(request.getId(), user);

if (request.equals(currentRequest)) {
return RequestStatus.SUCCESS;
}
StringBuilder commentText = new StringBuilder("Clearing Request is updated: ");
if (!currentRequest.getClearingState().equals(request.getClearingState())) {
if (ClearingRequestState.CLOSED.equals(currentRequest.getClearingState())
Expand All @@ -217,6 +221,14 @@ public RequestStatus updateClearingRequest(ClearingRequest request, User user, S
.append(ThriftEnumUtils.enumToString(currentRequest.getClearingState())).append("</b> to <b>")
.append(ThriftEnumUtils.enumToString(request.getClearingState())).append("</b>");
}
String oldRequestingUser = CommonUtils.nullToEmptyString(currentRequest.getRequestingUser());
String newRequestingUser = CommonUtils.nullToEmptyString(request.getRequestingUser());
if (!oldRequestingUser.equals(newRequestingUser)) {
commentText = commentText.append("\n\tRequesting User changed from: <b>")
.append(StringUtils.defaultIfBlank(oldRequestingUser, "NULL")).append("</b> to <b>")
.append(StringUtils.defaultIfBlank(newRequestingUser, "NULL")).append("</b>");
}

String oldAgreedClDate = CommonUtils.nullToEmptyString(currentRequest.getAgreedClearingDate());
String newAgreedClDate = CommonUtils.nullToEmptyString(request.getAgreedClearingDate());
if (!oldAgreedClDate.equals(newAgreedClDate)) {
Expand Down Expand Up @@ -254,6 +266,7 @@ public RequestStatus updateClearingRequest(ClearingRequest request, User user, S
clearingRequestRepository.update(request);
projectDatabaseHandler.sendEmailForClearingRequestUpdate(request, projectUrl, user);
return RequestStatus.SUCCESS;

} catch (SW360Exception e) {
log.error("Failed to update clearing request: " + request.getId(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.logging.log4j.Logger;
import org.apache.thrift.TException;
import org.eclipse.sw360.datahandler.common.DatabaseSettings;
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary;
import org.eclipse.sw360.datahandler.thrift.PaginationData;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.users.User;
Expand All @@ -30,6 +31,7 @@

import static org.eclipse.sw360.datahandler.common.SW360Assert.assertNotEmpty;
import static org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull;
import static org.eclipse.sw360.datahandler.common.SW360Assert.assertUser;

/**
* Implementation of the Thrift service
Expand Down Expand Up @@ -101,9 +103,8 @@ public List<User> getAllUsers() {
}

@Override
public RequestStatus addUser(User user) throws TException {
assertNotNull(user);
assertNotNull(user.getEmail());
public AddDocumentRequestSummary addUser(User user) throws TException {
assertUser(user);
return db.addUser(user);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
package org.eclipse.sw360.users.db;

import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.common.DatabaseSettings;
import org.eclipse.sw360.datahandler.couchdb.DatabaseConnector;
import org.eclipse.sw360.datahandler.db.UserRepository;
import org.eclipse.sw360.datahandler.db.UserSearchHandler;
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus;
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary;
import org.eclipse.sw360.datahandler.thrift.PaginationData;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.SW360Exception;
Expand All @@ -39,6 +42,8 @@
*/
public class UserDatabaseHandler {

private static final String LAST_NAME_IS_MANDATORY = "Last Name is mandatory";
private static final String GIVEN_NAME_IS_MANDATORY = "Given Name is mandatory";
/**
* Connection to the couchDB database
*/
Expand Down Expand Up @@ -76,12 +81,24 @@ private void prepareUser(User user) throws SW360Exception {
ThriftValidate.prepareUser(user);
}

public RequestStatus addUser(User user) throws SW360Exception {
public AddDocumentRequestSummary addUser(User user) throws SW360Exception {
prepareUser(user);
AddDocumentRequestSummary addDocReqSummarry = new AddDocumentRequestSummary();
if (CommonUtils.isNullEmptyOrWhitespace(user.getGivenname())) {
return addDocReqSummarry.setMessage(GIVEN_NAME_IS_MANDATORY).setRequestStatus(AddDocumentRequestStatus.INVALID_INPUT);
} else if (CommonUtils.isNullEmptyOrWhitespace(user.getLastname())) {
return addDocReqSummarry.setMessage(LAST_NAME_IS_MANDATORY).setRequestStatus(AddDocumentRequestStatus.INVALID_INPUT);
}

User existingUserInDB = getByEmail(user.getEmail());
if (null != existingUserInDB) {
return addDocReqSummarry.setId(existingUserInDB.getId())
.setRequestStatus(AddDocumentRequestStatus.DUPLICATE);
}
// Add to database
db.add(user);

return RequestStatus.SUCCESS;
return addDocReqSummarry.setId(user.getId()).setRequestStatus(AddDocumentRequestStatus.SUCCESS);
}

public RequestStatus updateUser(User user) throws SW360Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@


public class UserHandlerTest {
private static final String DUMMY_LASTNAME = "Dummy Lastname";

private static final String DUMMY_GIVENNAME = "Dummy Givenname";

private static final String dbName = DatabaseSettingsTest.COUCH_DB_USERS;

private static final String DUMMY_EMAIL_ADDRESS_1 = "dummy.user1@dummy.domain.tld";
Expand All @@ -47,7 +51,7 @@ public void tearDown() throws Exception {

@Test
public void testAddUser() throws Exception {
User userWithComment = new User().setEmail(DUMMY_EMAIL_ADDRESS_1).setCommentMadeDuringModerationRequest(DUMMY_COMMENT);
User userWithComment = new User().setEmail(DUMMY_EMAIL_ADDRESS_1).setCommentMadeDuringModerationRequest(DUMMY_COMMENT).setGivenname(DUMMY_GIVENNAME).setLastname(DUMMY_LASTNAME).setDepartment(DUMMY_DEPARTMENT);

handler.addUser(userWithComment);

Expand All @@ -58,7 +62,7 @@ public void testAddUser() throws Exception {

@Test
public void testUpdateUser() throws Exception {
User userWithoutComment = new User().setEmail(DUMMY_EMAIL_ADDRESS_2);
User userWithoutComment = new User().setEmail(DUMMY_EMAIL_ADDRESS_2).setGivenname(DUMMY_GIVENNAME).setLastname(DUMMY_LASTNAME).setDepartment(DUMMY_DEPARTMENT);

handler.addUser(userWithoutComment); // does not contain a comment

Expand Down
11 changes: 3 additions & 8 deletions backend/src/src-vmcomponents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
~ SPDX-License-Identifier: EPL-2.0
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -30,11 +30,6 @@
<artifactId>src-vulnerabilities</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
Expand All @@ -46,4 +41,4 @@
<version>4.4.4</version>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ private void renderClearingRequest(RenderRequest request, RenderResponse respons
final String clearingId = request.getParameter(CLEARING_REQUEST_ID);
final User user = UserCacheHolder.getUserFromRequest(request);

request.setAttribute(IS_USER_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.SW360_ADMIN, user) ? "Yes" : "No");

if (CommonUtils.isNullEmptyOrWhitespace(clearingId)) {
throw new PortletException("Clearing request ID not set!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ public static AddDocumentRequestSummary updateClearingRequest(PortletRequest req
String isClearingExpertEdit = request.getParameter(PortalConstants.IS_CLEARING_EXPERT);
ModerationService.Iface client = new ThriftClients().makeModerationClient();
ClearingRequest clearingRequest = client.getClearingRequestByIdForEdit(id, user);

String requestingUser = request.getParameter(ClearingRequest._Fields.REQUESTING_USER.toString());
if (CommonUtils.isNullEmptyOrWhitespace(requestingUser)) {
log.warn("Invalid requesting user email: " + requestingUser + " is entered, by user: "+ user.getEmail());
return requestSummary.setMessage("Invalid requesting user email");
}
clearingRequest.setRequestingUser(requestingUser);

String clearingTeam = request.getParameter(ClearingRequest._Fields.CLEARING_TEAM.toString());
if (CommonUtils.isNullEmptyOrWhitespace(clearingTeam)) {
log.warn("Invalid clearingTeam email: " + clearingTeam + " is entered, by user: "+ user.getEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<jsp:useBean id="printDate" class="java.util.Date"/>
<jsp:useBean id="approvedReleaseCount" class="java.lang.Integer" scope="request" />
<jsp:useBean id="PreferredClearingDateLimit" class="java.lang.String" scope="request" />

<jsp:useBean id="isUserAdmin" class="java.lang.String" scope="request" />

<core_rt:if test="${not empty clearingRequest.id}">

Expand Down Expand Up @@ -137,7 +137,19 @@
<tbody>
<tr>
<td><label class="form-group"><liferay-ui:message key="requesting.user" />:</label></td>
<td><sw360:DisplayUserEmail email="${clearingRequest.requestingUser}" /></td>
<td>
<core_rt:choose>
<core_rt:when test="${isUserAdmin == 'Yes' and isEditable}">
<sw360:DisplayUserEdit id="REQUESTING_USER" email="${clearingRequest.requestingUser}" description="" multiUsers="false" />
<div class="invalid-feedback" id="clearingTeamEmailErrorMsg">
<liferay-ui:message key="email.should.be.in.valid.format" />
</div>
</core_rt:when>
<core_rt:otherwise>
<sw360:DisplayUserEmail email="${clearingRequest.requestingUser}" />
</core_rt:otherwise>
</core_rt:choose>
</td>
</tr>
<tr>
<td><label class="form-group"><liferay-ui:message key="created.on" />:</label></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

define('components/includes/releases/regexjs', ['jquery'] , function($) {
function regex(key,value) {
let regexEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
let regexEmail = /^\w+([\.-]\w+)*@\w+([\.-]\w+)*(\.\w{2,3})+$/;
let regexUrl = /^(https?|chrome):\/\/[^\s$.?#].[^\s]*$/g;
let content = '';
if (value.match(regexEmail)) {
Expand Down
Loading

0 comments on commit 4afe6b8

Please sign in to comment.