Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global: separate commands and output and [more] #23

Merged
merged 1 commit into from
Feb 27, 2020
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
21 changes: 17 additions & 4 deletions docs/develop/cleanup.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# Cleanup after you

## Stop the instance

We have reached the end of this journey, we are going to stop the instance. This will **NOT** destroy images, containers or volumes i.e. your data will be preserved.

``` bash
^C
Stopping server and worker...
Server and worker stopped...
```

## Destroy the instance

Finally, we want to destroy it. This will take us to a clean state. Note that it destroys images, containers and volumes (the ones defined in the `february-release-2/docker-compose.full.yml`. ).
If you want to get to a clean state with no images, containers or volumes, then destroy the instance. This **WILL** permanently erase your volume data (database and Elasticsearch indices).
It destroys the images, containers and volumes defined in the `february-release-2/docker-compose.full.yml`.

Stop the application:
After stopping the application per above, destroy it:

``` console
$ invenio-cli destroy
``` bash
invenio-cli destroy
```
```console
TODO: Revisit destroy command...
```
140 changes: 31 additions & 109 deletions docs/develop/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ For the purpose of this example, we will only allow super users to create record

Open the `invenio.cfg` file with your favorite editor. We will use `vim` to avoid `emacs` and other wars ;).

``` console
$ vim invenio.cfg
``` bash
vim invenio.cfg
```

Let's add the following to the file:
Expand All @@ -27,16 +27,30 @@ class MyRecordPermissionPolicy(RDMRecordPermissionPolicy):
RECORDS_PERMISSIONS_RECORD_POLICY = MyRecordPermissionPolicy
```

When we set `RECORDS_PERMISSIONS_RECORD_POLICY = MyRecordPermissionPolicy`, we are overriding `RECORDS_PERMISSIONS_RECORD_POLICY` provided by [invenio-records-permissions](https://github.com/inveniosoftware/invenio-app-rdm). You will note that `invenio.cfg` is really just a Python module. How convenient!
And stop and start the server:

```bash
^C
Stopping server and worker...
Server and worker stopped...
```
``` bash
invenio-cli run
```

!!! warning
Changes to `invenio.cfg` **MUST** be accompanied by a restart to be picked up. This only restarts the server; it does not destroy any data.

When we set `RECORDS_PERMISSIONS_RECORD_POLICY = MyRecordPermissionPolicy`, we are overriding `RECORDS_PERMISSIONS_RECORD_POLICY` provided by [invenio-records-permissions](https://github.com/inveniosoftware/invenio-records-permissions). You will note that `invenio.cfg` is really just a Python module. How convenient!

**Pro tip** : You can type `can_create = []` to achieve the same effect; any empty permission list only allows super users.

That's it configuration-wise. If we try to create a record through the API, your instance will check if you are a super user before allowing you. The same approach to configuration holds for any other setting you would like to override.

Did the changes work? We are going to try to create a new record:

``` console
$ curl -k -XPOST -H "Content-Type: application/json" https://localhost:5000/api/records/ -d '{
``` bash
curl -k -XPOST -H "Content-Type: application/json" https://localhost:5000/api/records/ -d '{
"_access": {
"metadata_restricted": false,
"files_restricted": false
Expand All @@ -59,10 +73,10 @@ $ curl -k -XPOST -H "Content-Type: application/json" https://localhost:5000/api/
],
"creators": [
{
"name": "Julio Cesar",
"name": "Marcus Junius Brutus",
"type": "Personal",
"given_name": "Julio",
"family_name": "Cesar",
"given_name": "Marcus",
"family_name": "Brutus",
"identifiers": [
{
"identifier": "9999-9999-9999-9999",
Expand All @@ -80,7 +94,7 @@ $ curl -k -XPOST -H "Content-Type: application/json" https://localhost:5000/api/
],
"titles": [
{
"title": "A Romans story",
"title": "A permission story",
"type": "Other",
"lang": "eng"
}
Expand Down Expand Up @@ -109,106 +123,14 @@ $ curl -k -XPOST -H "Content-Type: application/json" https://localhost:5000/api/

As you can see, the server could not know if we are authenticated/superuser and rejected us:

``` console
{"message":"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.","status":401}
``` json
{
"message": "The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.",
"status": 401
}
```

**Advanced example**:

1- Create a user, for example using the web UI (*sign up* button). Alternatively, you can do so with the CLI, executing the following command (Wait until you read point number *2* before executing):

``` console
pipenv run invenio users create user@test.ch --password=123456
```

Note that the user will have ID 1 if it was the first one created.

2- Grant admin access to it. In order to do so, we only have to add the `-a` flag to the previous command:

``` console
pipenv run invenio users create admin@test.ch -a --password=123456
```

Note that this user will have ID 2.

3- Get a token and try to create the record again. You can do so on the UI by going to `settings->applications-->new token`. Alternatively you can do it in the terminal by executing the following command:

``` console
# TODO Wait until invenio-oauthclient REST only is integrated
```

Afterwards we can test if the new permissions are working correctly.

``` console
$ curl -k -XPOST -H "Authorization:Bearer sHHq1K9y7a2v5doKDRSFmSFOxa1tZDHFcbs31npaxm1sFEt27yomLMt0ynkl" -H "Content-Type: application/json" https://localhost:5000/api/records/ -d '{
"_access": {
"metadata_restricted": false,
"files_restricted": false
},
"_owners": [1],
"_created_by": 1,
"access_right": "open",
"resource_type": {
"type": "image",
"subtype": "photo"
},
"identifiers": [
{
"identifier": "10.9999/rdm.9999999",
"scheme": "DOI"
}, {
"identifier": "9999.99999",
"scheme": "arXiv"
}
],
"creators": [
{
"name": "Julio Cesar",
"type": "Personal",
"given_name": "Julio",
"family_name": "Cesar",
"identifiers": [
{
"identifier": "9999-9999-9999-9999",
"scheme": "Orcid"
}
],
"affiliations": [
{
"name": "Entity One",
"identifier": "entity-one",
"scheme": "entity-id-scheme"
}
]
}
],
"titles": [
{
"title": "A Romans story",
"type": "Other",
"lang": "eng"
}
],
"descriptions": [
{
"description": "A story on how Julio Cesar relates to Gladiator.",
"type": "Abstract",
"lang": "eng"
}
],
"community": {
"primary": "Maincom",
"secondary": ["Subcom One", "Subcom Two"]
},
"licenses": [
{
"license": "Berkeley Software Distribution 3",
"uri": "https://opensource.org/licenses/BSD-3-Clause",
"identifier": "BSD-3",
"scheme": "BSD-3"
}
]
}'
```
!!!todo
Document how to generate an API token when permissions via token work.

It works!
Revert the changes in `invenio.cfg` and restart the server to get back to where we were.
44 changes: 33 additions & 11 deletions docs/develop/customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ As we just saw, overriding configured values is an easy and common way of custom

## Update the logo

We are going to change the logo, take an *svg* file and update your **local** static files (You can use the [invenio color logo](https://github.com/inveniosoftware/invenio-theme/blob/master/invenio_theme/static/images/invenio-color.svg)):
We are going to change the logo. Take an *svg* file and copy it to your **local** static files. You can use the [invenio color logo](https://github.com/inveniosoftware/invenio-theme/raw/master/invenio_theme/static/images/invenio-color.svg):

``` console
$ cp ./path/to/new/color/logo.svg static/images/logo.svg
``` bash
cp ./path/to/new/color/logo.svg static/images/logo.svg
```

Then, use the `update` command:

``` bash
invenio-cli update --no-install-js
```
``` console
$ invenio-cli update --no-install-js
# Summarized output
Collecting statics and assets...
Collect static from blueprints.
Created webpack project.
Copying project statics and assets...
Symlinking assets/...
Building assets...
Built webpack project.
```

Passing the `--no-install-js` option, skips re-installation of JS dependencies.
Expand All @@ -26,28 +33,26 @@ Go to the browser [*https://localhost:5000/*](https://localhost:5000) or refresh
!!! warning "That evil cache"
If you do not see it changing, check in an incognito window; the browser might have cached the logo.

Need further customizations? Have you thought of creating your own extensions? How to add them to your InvenioRDM instance is explained in the next section - [here](../extensions/custom.md).

## Change colors

You might also be wondering: *How do I change the colors so I can make my instance look like my institution's theme?*

We are going to change the top header section in the frontpage to apply our custom background color. Open the `assets/scss/<your instance shortname>/variables.scss` file and edit it as below:

``` console
``` scss
$navbar_background_image: unset;
$navbar_background_color: #000000; // Note this hex value is an example. Choose yours.
```

Then, run the `invenio-cli update` command as above and refresh the page! You should be able to see your top header's color changed! You can find all the available variables that you can change [here](https://github.com/inveniosoftware/invenio-app-rdm/blob/master/invenio_app_rdm/theme/assets/scss/invenio_app_rdm/variables.scss).
Then, run the `invenio-cli update` command as above and refresh the page! You should be able to see your top header's color changed! You can find all the available styling variables that you can change [here](https://github.com/inveniosoftware/invenio-app-rdm/blob/master/invenio_app_rdm/theme/assets/scss/invenio_app_rdm/variables.scss).

## Change search results

Changing how your results are presented in the search page is also something quite common.

We are going to update the search result template so we can show more text in the result's description. Create a file called `ResultsItemTemplate.jsx` inside `assets/templates/search` folder and then edit it as below:

```console
```js
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsx is not supported, so the closest to some highlighting we can get is js but it doesn't render quite properly because it's JSX (html tags, curly braces...)

import React from 'react';
import {Item} from 'semantic-ui-react';
import _truncate from 'lodash/truncate';
Expand All @@ -74,14 +79,14 @@ When you click on a search result, you navigate in the details page of a specifi

We are going to configure our instance to use our template for displaying the information in the record's landing page. Open the `invenio.cfg` file and add the below:

```console
```python
from invenio_rdm_records.config import RECORDS_UI_ENDPOINTS
RECORDS_UI_ENDPOINTS['recid'].update(template='my_record_landing_page.html')
```

Then, we create a file `my_record_landing_page.html` inside the `templates` folder and edit it as below:

```console
```jinja
{%- extends 'invenio_rdm_records/record_landing_page.html' %}

{%- block page_body %}
Expand All @@ -90,3 +95,20 @@ Then, we create a file `my_record_landing_page.html` inside the `templates` fold
```

Inside the `page_body` block you can restructure the page as you want! You can check the default record landing page template [here](https://github.com/inveniosoftware/invenio-rdm-records/blob/master/invenio_rdm_records/theme/templates/invenio_rdm_records/record_landing_page.html).

Since we modified `invenio.cfg`, we need to re-start the server to see our changes take effect:

```bash
^C
Stopping server and worker...
Server and worker stopped...
```
```bash
invenio-cli run
```

## Change functionality

Need further customizations? Have you thought of creating your own extensions?

How to make an extension and add it to your InvenioRDM instance is explained in the [Extensions section](../extensions/custom.md).
4 changes: 3 additions & 1 deletion docs/develop/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ We start by creating a new project in a different folder. We will just follow wh
did in the [Preview section](../preview/index.md). Feel free to use your own
project name.

``` bash
invenio-cli init --flavour=RDM
```
``` console
$ invenio-cli init --flavour=RDM
Initializing RDM application...
project_name [My Site]: February Release 2
project_shortname [february-release-2]:
Expand Down
Loading