Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ services:
- su www-data -c "php /var/www/html/occ group:adduser users user2"
- su www-data -c "git clone -b master https://github.com/nextcloud/activity.git /var/www/html/apps/activity/"
- su www-data -c "php /var/www/html/occ app:enable activity"
- su www-data -c "git clone -b master https://github.com/nextcloud/text.git /var/www/html/apps/text/"
- su www-data -c "php /var/www/html/occ app:enable text"
- /run.sh

trigger:
Expand Down
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168
144
5 changes: 4 additions & 1 deletion scripts/analysis/spotbugs-filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
<Match>
<Class name="~.*\.R\$.*" />
</Match>
<Match>
<Class name="~.*\$\$Parcelable.*" />
</Match>
<Bug pattern="PATH_TRAVERSAL_IN" />
<Bug pattern="ANDROID_EXTERNAL_FILE_ACCESS" />
<Bug pattern="BAS_BLOATED_ASSIGNMENT_SCOPE" />
<Bug pattern="SECHPP" />
<Bug pattern="HTTP_PARAMETER_POLLUTION" />
</FindBugsFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Nextcloud Android Library is available under MIT license
*
* @author Tobias Kaminsky
* Copyright (C) 2019 Tobias Kaminsky
* Copyright (C) 2019 Nextcloud GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package com.nextcloud.android.lib.resources.directediting;

import com.owncloud.android.AbstractIT;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;

import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class DirectEditingCreateFileRemoteOperationTest extends AbstractIT {
@Test
public void createEmptyFile() {
RemoteOperationResult result = new DirectEditingCreateFileRemoteOperation("/test.md",
"text",
"textdocument")
.execute(client);
assertTrue(result.isSuccess());

String url = (String) result.getSingleData();

assertFalse(url.isEmpty());
}

@Test
public void createFileFromTemplate() {
RemoteOperationResult result = new DirectEditingCreateFileRemoteOperation("/test.md",
"text",
"textdocument",
"1")
.execute(client);
assertTrue(result.isSuccess());

String url = (String) result.getSingleData();

assertFalse(url.isEmpty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Nextcloud Android Library is available under MIT license
*
* @author Tobias Kaminsky
* Copyright (C) 2019 Tobias Kaminsky
* Copyright (C) 2019 Nextcloud GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package com.nextcloud.android.lib.resources.directediting;

import com.owncloud.android.AbstractIT;
import com.owncloud.android.lib.common.TemplateList;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class DirectEditingObtainListOfTemplatesRemoteOperationTest extends AbstractIT {

@Test
public void testGetAll() {
RemoteOperationResult result = new DirectEditingObtainListOfTemplatesRemoteOperation("text",
"textdocument")
.execute(client);
assertTrue(result.isSuccess());

TemplateList templateList = (TemplateList) result.getSingleData();

assertEquals("Empty file", templateList.templates.get("empty").title);
assertEquals("md", templateList.templates.get("empty").extension);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2019 Tobias Kaminsky
* Copyright (C) 2019 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

package com.nextcloud.android.lib.resources.directediting;

import com.owncloud.android.AbstractIT;
import com.owncloud.android.lib.common.DirectEditing;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class DirectEditingObtainRemoteOperationTest extends AbstractIT {

@Test
public void testGetAll() {
RemoteOperationResult result = new DirectEditingObtainRemoteOperation().execute(client);
assertTrue(result.isSuccess());

DirectEditing directEditing = (DirectEditing) result.getSingleData();

assertEquals("Nextcloud Text", directEditing.editors.get("text").name);
assertEquals("text/plain", directEditing.editors.get("text").optionalMimetypes.get(0));

assertEquals("New text document", directEditing.creators.get("textdocument").name);
assertFalse(directEditing.creators.get("textdocument").templates);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Nextcloud Android Library is available under MIT license
*
* @author Tobias Kaminsky
* Copyright (C) 2019 Tobias Kaminsky
* Copyright (C) 2019 Nextcloud GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package com.nextcloud.android.lib.resources.directediting;

import com.owncloud.android.AbstractIT;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation;

import junit.framework.TestCase;

import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class DirectEditingOpenFileRemoteOperationTest extends AbstractIT {
@Test
public void createFileFromTemplate() throws IOException {
// create file
String filePath = createFile("text");
String remotePath = "/text.md";
TestCase.assertTrue(new UploadFileRemoteOperation(filePath, remotePath, "text/markdown", "123")
.execute(client).isSuccess());

TestCase.assertTrue(new ReadFileRemoteOperation(remotePath).execute(client).isSuccess());

// open file
RemoteOperationResult result = new DirectEditingOpenFileRemoteOperation(remotePath, "text").execute(client);
assertTrue(result.isSuccess());

String url = (String) result.getSingleData();

assertFalse(url.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public void testGetRemoteCapabilitiesOperation() {
OCCapability capability = (OCCapability) result.getData().get(0);

Assert.assertSame(capability.getRichDocuments(), CapabilityBooleanType.FALSE);

Assert.assertFalse(capability.getDirectEditingEtag().isEmpty());

// TODO assert basic capabilities
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* Nextcloud Android Library is available under MIT license
*
* @author Tobias Kaminsky
* Copyright (C) 2019 Tobias Kaminsky
* Copyright (C) 2019 Nextcloud GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package com.nextcloud.android.lib.resources.directediting;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.json.JSONObject;

import lombok.AllArgsConstructor;

/**
* Create file with direct editing api
*/

@AllArgsConstructor
public class DirectEditingCreateFileRemoteOperation extends RemoteOperation {
private static final String TAG = DirectEditingCreateFileRemoteOperation.class.getSimpleName();
private static final int SYNC_READ_TIMEOUT = 40000;
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
private static final String DIRECT_ENDPOINT = "/ocs/v2.php/apps/files/api/v1/directEditing/create";

private static final String JSON_FORMAT = "?format=json";

private String path;
private String editor;
private String creator;
private String template;

public DirectEditingCreateFileRemoteOperation(String path, String editor, String creator) {
this(path, editor, creator, "");
}

protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result;
PostMethod postMethod = null;

try {
postMethod = new PostMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT);
postMethod.addParameter("path", path);
postMethod.addParameter("editorId", editor);
postMethod.addParameter("creatorId", creator);

if (!template.isEmpty()) {
postMethod.addParameter("templateId", template);
}

// remote request
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);

if (status == HttpStatus.SC_OK) {
String response = postMethod.getResponseBodyAsString();

// Parse the response
JSONObject respJSON = new JSONObject(response);
String url = (String) respJSON.getJSONObject("ocs").getJSONObject("data").get("url");

result = new RemoteOperationResult(true, postMethod);
result.setSingleData(url);
} else {
result = new RemoteOperationResult(false, postMethod);
client.exhaustResponse(postMethod.getResponseBodyAsStream());
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Get all direct editing informations failed: " + result.getLogMessage(),
result.getException());
} finally {
if (postMethod != null) {
postMethod.releaseConnection();
}
}
return result;
}
}
Loading