Skip to content

Commit

Permalink
[ownCloud] Refactor Application (#51)
Browse files Browse the repository at this point in the history
* refactor: initial reformat

Signed-off-by: Mohammad Mahdi Baghbani Pourvahid <[email protected]>

* refactor: controllers

Signed-off-by: Mohammad Mahdi Baghbani Pourvahid <[email protected]>

* refactor: appinfo

Signed-off-by: Mohammad Mahdi Baghbani Pourvahid <[email protected]>

* refactor: app & application

Signed-off-by: Mohammad Mahdi Baghbani Pourvahid <[email protected]>

* refactor: add docs and return types, etc

Signed-off-by: Mohammad Mahdi Baghbani Pourvahid <[email protected]>

* add: license in file header, remove some dead modules

* refactor: more cleanups without breaking the app!

Surprising that after deleting bunch of files it still works :)

Signed-off-by: Mohammad Mahdi Baghbani Pourvahid <[email protected]>

* refactor: wrap up everything remaining

Signed-off-by: Mohammad Mahdi Baghbani Pourvahid <[email protected]>

---------

Signed-off-by: Mohammad Mahdi Baghbani Pourvahid <[email protected]>
  • Loading branch information
MahdiBaghbani authored Sep 13, 2023
1 parent 56b8a67 commit e22483b
Show file tree
Hide file tree
Showing 72 changed files with 17,346 additions and 17,090 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
# do not stop on another job's failure
fail-fast: false
matrix:
php-versions: ['7.4']
databases: ['sqlite']
server-versions: ['master']
php-versions: [ '7.4' ]
databases: [ 'sqlite' ]
server-versions: [ 'master' ]

name: php${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}

steps:
Expand Down Expand Up @@ -68,9 +68,9 @@ jobs:
working-directory: apps/${{ env.APP_NAME }}
run: ./vendor/phpunit/phpunit/phpunit -c phpunit.xml

# - name: PHPUnit integration
# working-directory: apps/${{ env.APP_NAME }}
# run: ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml
# - name: PHPUnit integration
# working-directory: apps/${{ env.APP_NAME }}
# run: ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml

mysql:
runs-on: ubuntu-latest
Expand All @@ -79,10 +79,10 @@ jobs:
# do not stop on another job's failure
fail-fast: false
matrix:
php-versions: ['7.3', '7.4']
databases: ['mysql']
server-versions: ['master']
php-versions: [ '7.3', '7.4' ]
databases: [ 'mysql' ]
server-versions: [ 'master' ]

name: php${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}

services:
Expand Down Expand Up @@ -138,9 +138,9 @@ jobs:
working-directory: apps/${{ env.APP_NAME }}
run: ./vendor/phpunit/phpunit/phpunit -c phpunit.xml

# - name: PHPUnit integration
# working-directory: apps/${{ env.APP_NAME }}
# run: ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml
# - name: PHPUnit integration
# working-directory: apps/${{ env.APP_NAME }}
# run: ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml

pgsql:
runs-on: ubuntu-latest
Expand All @@ -149,10 +149,10 @@ jobs:
# do not stop on another job's failure
fail-fast: false
matrix:
php-versions: ['7.4']
databases: ['pgsql']
server-versions: ['master']
php-versions: [ '7.4' ]
databases: [ 'pgsql' ]
server-versions: [ 'master' ]

name: php${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}

services:
Expand Down
14 changes: 7 additions & 7 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

$config = new Config();
$config
->getFinder()
->ignoreVCSIgnored(true)
->notPath('build')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->in(__DIR__);
->getFinder()
->ignoreVCSIgnored(true)
->notPath('build')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->in(__DIR__);
return $config;
67 changes: 40 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This repository will eventually be moved to [this](https://github.com/sciencemesh/nc-sciencemesh) link.

# ScienceMesh

Place this app in **/var/www/html/apps/**

## Building the app
Expand All @@ -10,29 +11,35 @@ The app can be built by using the provided Makefile by running:
make

This requires the following things to be present:

* make
* which
* tar: for building the archive
* curl: used if phpunit and composer are not installed to fetch them from the web
* npm: for building and testing everything JS, only required if a package.json is placed inside the **js/** folder

The make command will install or update Composer dependencies if a composer.json is present and also **npm run build** if a package.json is present in the **js/** folder. The npm **build** script should use local paths for build systems and package managers, so people that simply want to build the app won't need to install npm libraries globally, e.g.:
The make command will install or update Composer dependencies if a composer.json is present and also **npm run build**
if a package.json is present in the **js/** folder. The npm **build** script should use local paths for build systems
and package managers, so people that simply want to build the app won't need to install npm libraries globally, e.g.:

**package.json**:

```json
"scripts": {
"test": "node node_modules/gulp-cli/bin/gulp.js karma",
"prebuild": "npm install && node_modules/bower/bin/bower install && node_modules/bower/bin/bower update",
"build": "node node_modules/gulp-cli/bin/gulp.js"
}
```
# Before running tests

# Before running tests

* add this app to your Nextcloud instance as /apps/sciencemesh
* run `php -S localhost:8080` in the root of your nextcloud folder (or run it with Apache / nginx / MAMP / etc)
* run `php -S localhost:8080` in the root of your nextcloud folder (or run it with Apache / nginx / MAMP / etc.)
* create a user 'tester' (password e.g. '123')
* log in and enable the 'sciencemesh' app
* in your local reva checkout, run:

```sh
git remote add michielbdejong https://github.com/michielbdejong/reva
git fetch michielbdejong
Expand All @@ -57,12 +64,16 @@ make lint-fix
## Run Reva integration tests

Path: /reva

```sh
git checkout nextcloud-test-improvements
NEXTCLOUD=http://tester:123@localhost:8080/index.php go test -v github.com/cs3org/reva/pkg/storage/fs/nextcloud/...
```

* you should see it run lots of tests, most of which fail in various ways
* look at [this mock](https://github.com/cs3org/reva/blob/de30aee/pkg/storage/fs/nextcloud/nextcloud_server_mock.go#L140-L169) to see the correct params and responses
* look
at [this mock](https://github.com/cs3org/reva/blob/de30aee/pkg/storage/fs/nextcloud/nextcloud_server_mock.go#L140-L169)
to see the correct params and responses

## Run Nextcloud Unit tests

Expand All @@ -73,14 +84,17 @@ You can use the provided Makefile to run all tests by using:
```
XDEBUG=coverage make test
```
or

or

```
XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text
```

This will run the PHP unit and integration tests and if a package.json is present in the **js/** folder will execute **npm run test**

Of course you can also install [PHPUnit](http://phpunit.de/getting-started.html) and use the configurations directly:
This will run the PHP unit and integration tests and if a package.json is present in the **js/** folder will execute *
*npm run test**

Of course, you can also install [PHPUnit](http://phpunit.de/getting-started.html) and use the configurations directly:

phpunit -c phpunit.xml

Expand All @@ -102,65 +116,65 @@ To check the share functionality we will need **4 terminals**.

First make sure to `git checkout rrn-testing`.

### 1) Terminal 1
### 1) Terminal 1

* `cd reva/`

* ` ./cmd/reva/reva -host localhost:17000 -insecure`

### 2) Terminal 2
### 2) Terminal 2

* `cd server/`

* ` php -S localhost:8080`
* `cd server/`

### 3) Terminal 3
* ` php -S localhost:8080`

### 3) Terminal 3

* ` cd /reva/examples/ocmd`

* ` ../../cmd/revad/revad -c ./ocmd-server-2-with-nextcloud.toml`

Note that this is the only difference with the [Reva bulding instructions](https://reva.link/docs/tutorials/share-tutorial/#3-run-reva)
Note that this is the only difference with
the [Reva bulding instructions](https://reva.link/docs/tutorials/share-tutorial/#3-run-reva)

### 4) Terminal 4
### 4) Terminal 4

* ` cd /reva/examples/ocmd`

* `../../cmd/revad/revad -c ocmd-server-1.toml`

# CURL commands

To check the [RevaCotroller.php](https://github.com/pondersource/nc-sciencemesh/blob/6215c61/lib/Controller/RevaController.php) methods you can use these Curl commands:
To check
the [RevaCotroller.php](https://github.com/pondersource/nc-sciencemesh/blob/6215c61/lib/Controller/RevaController.php)
methods you can use these Curl commands:

## Sharing methods:
## Sharing methods:

### addReceivedShare()

curl -v -H 'Content-Type:application/json' -X POST -d '{"md":{"opaque_id":"fileid-einstein%2Fmy-folder"},"g":{"grantee":{"type":1,"Id":{"UserId":{"idp":"cesnet.cz","opaque_id":"marie","type":1}}}},"provider_domain":"cern.ch","resource_type":"file","provider_id":2,"protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://marie:radioactivity@localhost:8080/index.php/apps/sciencemesh/~marie/api/ocm/addReceivedShare


### addSentShare

curl -v -H 'Content-Type:application/json' -X POST -d '{"md":{"storage_id":"123e4567-e89b-12d3-a456-426655440000","opaque_id":"fileid-marie%2FtestFile.json"},"g":{"grantee":{"type":1,"Id":{"UserId":{"idp":"cernbox.cern.ch","opaque_id":"einstein","type":1}}},"permissions":{"permissions":{"get_path":true,"initiate_file_download":true,"list_container":true,"list_file_versions":true,"stat":true}}}}' http://marie:radioactivity@localhost:8080/index.php/apps/sciencemesh/~marie/api/ocm/addSentShare

### ListReceivedShares()

curl -X POST http://marie:radioactivity@localhost:8080/index.php/apps/sciencemesh/~marie/api/ocm/ListReceivedShares

### ListSentShares()

curl -X POST http://marie:radioactivity@localhost:8080/index.php/apps/sciencemesh/~marie/api/ocm/ListSentShares

### Unshare()

### Unshare()

curl -v -H 'Content-Type:application/json' -X POST -d '{"Spec":{"Id":{"opaque_id":"fileid-marie%2FtestFile.json"}}}' http://marie:radioactivity@localhost:8080/index.php/apps/sciencemesh/~marie/api/ocm/Unshare

### GetReceivedShare()

curl -v -H 'Content-Type:application/json' -X POST -d '{"Spec":{"Id":{"opaque_id":"fileid-einstein%2Fmy-folder"}}}' http://marie:radioactivity@localhost:8080/index.php/apps/sciencemesh/~marie/api/ocm/GetReceivedShare


### GetSentShare()

curl -v -H 'Content-Type:application/json' -X POST -d '{"Spec":{"Id":{"opaque_id":"fileid-marie%2FtestFile.json"}}}' http://marie:radioactivity@localhost:8080/index.php/apps/sciencemesh/~marie/api/ocm/GetSentShare
Expand All @@ -169,7 +183,6 @@ To check the [RevaCotroller.php](https://github.com/pondersource/nc-sciencemesh/

curl -v -H 'Content-Type:application/json' -X POST -d '{"ref":{"Spec":{"Id":{"opaque_id":"fileid-marie%2FtestFile.json"}}},"p":{"permissions":{"add_grant":true,"create_container":true,"delete":true,"get_path":true,"get_quota":true,"initiate_file_download":true,"initiate_file_upload":true,"list_grants":true,"list_container":true,"list_file_versions":true,"list_recycle":true,"move":true,"remove_grant":true,"purge_recycle":true,"restore_file_version":true,"restore_recycle_item":true,"stat":true,"update_grant":true,"deny_grant":true}}}' http://marie:radioactivity@localhost:8080/index.php/apps/sciencemesh/~marie/api/ocm/UpdateSentShare


### UpdateReceivedShare()

curl -v -H 'Content-Type:application/json' -X POST -d '{"received_share":{"share":{"id":{},"resource_id":"fileid-einstein%2Fmy-folder","permissions":{"permissions":{"add_grant":true,"create_container":true,"delete":true,"get_path":true,"get_quota":true,"initiate_file_download":true,"initiate_file_upload":true,"list_grants":true,"list_container":true,"list_file_versions":true,"list_recycle":true,"move":true,"remove_grant":true,"purge_recycle":true,"restore_file_version":true,"restore_recycle_item":true,"stat":true,"update_grant":true,"deny_grant":true}},"grantee":{"Id":{"UserId":{"idp":"0.0.0.0:19000","opaque_id":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c","type":1}}},"owner":{"idp":"0.0.0.0:19000","opaque_id":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c","type":1},"creator":{"idp":"0.0.0.0:19000","opaque_id":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c","type":1},"ctime":{"seconds":1234567890},"mtime":{"seconds":1234567890}},"state":2},"field_mask":{"paths":["state"]}}' http://marie:radioactivity@localhost:8080/index.php/apps/sciencemesh/~marie/api/ocm/UpdateReceivedShare
Expand Down
23 changes: 18 additions & 5 deletions appinfo/app.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
<?php
/**
* ownCloud - sciencemesh
*
* This file is licensed under the MIT License. See the LICENCE file.
* @license MIT
* @copyright Sciencemesh 2020 - 2023
*
* @author Michiel De Jong <[email protected]>
* @author Mohammad Mahdi Baghbani Pourvahid <[email protected]>
*/

declare(strict_types=1);

$app = \OC::$server->query(\OCA\ScienceMesh\AppInfo\ScienceMeshApp::class);
use OCA\ScienceMesh\AppInfo\ScienceMeshApp;

$app = OC::$server->query(ScienceMeshApp::class);

\OC::$server->getNavigationManager()->add(function () {
$urlGenerator = \OC::$server->getURLGenerator();
OC::$server->getNavigationManager()->add(function () {
$urlGenerator = OC::$server->getURLGenerator();

return [
// The string under which your app will be referenced in owncloud
Expand All @@ -21,6 +34,6 @@
'icon' => $urlGenerator->imagePath('sciencemesh', 'app.svg'),

// The application's title, used in the navigation & the settings page of your app
'name' => \OC::$server->getL10N('sciencemesh')->t('ScienceMesh'),
'name' => OC::$server->getL10N('sciencemesh')->t('ScienceMesh'),
];
});
});
Loading

0 comments on commit e22483b

Please sign in to comment.