The Admin ConsoleAdmin Console

This chapter covers the following topics.

Introduction

The Admin Console is a text-based administration tool available in all sections of the Structr UI. The shortcut to toggle the console is Ctrl - Alt - c, on Mac OS Control (or Ctrl) ⌃ - Option (or Alt) ⌥ - c.

The console supports five different modes that you can cycle through using Shift - Tab:

For JavaScript and StructrScript, the output on the console is the same as if you were executing the expression in a scripting context of a content element or template element.

JavaScript

The JavaScript mode is very well suited for performing short administrative tasks such as updating a property on all objects of a type (e.g. change the visibility flags), testing specific statements, or similar tasks.

Mode set to 'JavaScript'.
admin@Structr> $.find('Page').forEach(p => p.visibleToPublicUsers = true);
org.mozilla.javascript.Undefined@0
admin@Structr>

Advanced Example

Since all parts of a Structr application are stored in the database, the JavaScript console can even be used to modify the schema.

Mode set to 'JavaScript'.
admin@Structr> $.create('SchemaNode', { name: 'Project' });
SchemaNode
admin@Structr> $.find('Project');
[]
admin@Structr> $.create('Project', { name: 'Project #1' });
Project
admin@Structr> $.create('Project', { name: 'Project #2' });
Project
admin@Structr> $.find('Project').map(p => p.name).join(', ');
Project #2, Project #1
admin@Structr>

StructrScript

The StructrScript mode can be used to test the behaviour of StructrScript expressions or perform very simple maintenance tasks.

Mode set to 'StructrScript'.
admin@Structr> find('Project')
[d8070ae07cde4b6d9d6302acb6115e91, 9f040115a5744526801a6b1f733b2de6, 7159a1e615f240ada4f160ea7e3280b8]
admin@Structr> join(extract(find('Project'), 'name'), ', ')
Test, Project 1, Important Project
admin@Structr>

Cypher

In Cypher model, the console executes a REPL (Read–Eval–Print Loop) for Cypher expressions, so this is a good place to test-run Cypher statements.

Mode set to 'Cypher'.
admin@Structr> MATCH (n:Project) RETURN n
Query returned 3 objects in 18 ms.
{
"result": [
{
"id": "9f040115a5744526801a6b1f733b2de6",
"type": "Project",
"name": "Project 1"
},
{
"id": "d8070ae07cde4b6d9d6302acb6115e91",
"type": "Project",
"name": "Test"
},
{
"id": "7159a1e615f240ada4f160ea7e3280b8",
"type": "Project",
"name": "Important Project"
}
]
}
admin@Structr>

Please note that by default the number of visible results in the Cypher console is limited to 10. If you run a query that returns more than 10 objects, Structr will show an error message. This number is configurable via application.console.cypher.maxresults in structr.conf

admin@Structr> MATCH (n:AbstractNode) RETURN n
Query returned 3264 objects in 62 ms.
Too many results (> 10), please use LIMIT to reduce the result count of your Cypher query.
admin@Structr>

AdminShell

The AdminShell mode is a text-based interface to the Maintenance Endpoint. It can be used to run Maintenance Commands like “Rebuild Index” or manage users.

Mode set to 'AdminShell'. Type 'help' to get a list of commands.
admin@Structr> help
export - Exports the Structr application to a directory.
export-data - Exports data from the Structr application to a directory.
file-import - Imports files directly from a directory on the server.
help - Prints a list of all commands and a short help text. Use 'help <command> to get more details.
import - Imports a Structr application from a directory.
import-data - Imports data into a Structr application from a directory.
init - Initializes UUIDs, labels and indexes on nodes and relationships.
user - Creates and deletes users, sets passwords.
admin@Structr>

Commands

The following commands can be used in AdminShell mode.

export

export <target>  -  exports this Structr application to the given target directory.

export-data

exportData <target> <types>  -  Exports data from this application to a path in the file system.
<target> - absolute path to the target directory
<types> - comma-separated list of types to export

file-import

file-import <source> <target> <mode> <existing> <index>  -  Import files directly from a server directoy.
<source> - Path to a directory on the server.
<target> - Target path in Structr's virtual file system.
<mode> - Whether to copy or move the files into Structr's files directory. Possible values: copy (default), move
<existing> - How to handle files already existing with the same path in Structr. Possible values: skip (default), overwrite, rename
<index> - Whether new files should be fulltext-indexed after import. Possible values: true (default), false

help

Prints a list of all commands and a short help text. Use 'help <command> to get more details.

import

import <source>  -  imports an application from the given source directory.

import-data

importData <source> <doInnerCallbacks> <doCascadingDelete>  -  Imports data for an application from a path in the file system.
<source> - absolute path to the source directory
<doInnerCallbacks> - (optional) decides if onCreate/onSave methods are run and function properties are evaluated during data deployment. Often this leads to errors because onSave contains validation code which will fail during data deployment. (default = false. Only set to true if you know what you're doing!)
<doCascadingDelete> - (optional) decides if cascadingDelete is enabled during data deployment. This leads to errors because cascading delete triggers onSave methods on remote nodes which will fail during data deployment. (default = false. Only set to true if you know what you're doing!)

init

init [node|rel] index [for <type>] - Rebuilds the node/relationship index.
init [node|rel] ids [for <type>] - Sets UUIDs on nodes and/or relationship.
init [node] labels [for <type>] - Sets labels on nodes and/or relationship.

user

user list                          - lists all user in the database
user add <name> [<e-mail>|isAdmin] - adds a new user with the given name and optional e-mail address
user delete <name> - deletes the user with the given name
user password <name> <password> - sets the password for the given user

REST

The REST mode provides a very simple REST client that runs as if you were to access Structr externally. This means that your requests are made without authentication, as long as you don’t authenticate them. You can use the REST client to simulate access from the outside and test Resource Access Grants etc.

Mode set to 'REST'. Type 'help' to get a list of commands.
anonymous@Structr> help
as - Runs a REST command in the security context of a given user.
auth - Sets authentication information for subsequent requests.
del - Executes a REST DELETE request.
delete - Executes a REST DELETE request.
get - Executes a REST GET request and returns the JSON or parts of it.
help - Prints a list of all commands and a short help text. Use 'help <command> to get more details.
post - Executes a REST POST request.
put - Executes a REST PUT request.
anonymous@Structr>

Commands

The following commands can be used in REST mode. Please refer to the REST Guide for more information about the REST interface and its features.

as

as can be used to run a single command with the credentials of a given user. Please note that you need to know the password to use this command.

anonymous@Structr> help as
as <user:password> <command> - Runs the given command as the given user.
Example
anonymous@Structr> as admin:admin get /Project
GET http://0.0.0.0:8082/structr/rest/Project
HTTP/1.1 200 OK
{
"result": [
{
"id": "d8070ae07cde4b6d9d6302acb6115e91",
"type": "Project",
"name": "Test"
},
{
"id": "9f040115a5744526801a6b1f733b2de6",
"type": "Project",
"name": "Project 1"
},
{
"id": "7159a1e615f240ada4f160ea7e3280b8",
"type": "Project",
"name": "Important Project"
}
],
"query_time": "0.000044398",
"result_count": 3,
"page_count": 1,
"result_count_time": "0.000163029",
"serialization_time": "0.000775854"
}
anonymous@Structr>

auth

auth can be used to configure all subsequent commands in REST mode to be run as the given user. Please note that you need to know the password to use this command.

anonymous@Structr> help auth
auth <username> <password> - Sets authentication information for subsequent requests. Run without parameters to reset credentials.
Example
anonymous@Structr> auth admin admin
admin@Structr> get /Project
GET http://0.0.0.0:8082/structr/rest/Project
HTTP/1.1 200 OK
{
"result": [
{
"id": "d8070ae07cde4b6d9d6302acb6115e91",
"type": "Project",
"name": "Test"
},
{
"id": "9f040115a5744526801a6b1f733b2de6",
"type": "Project",
"name": "Project 1"
},
{
"id": "7159a1e615f240ada4f160ea7e3280b8",
"type": "Project",
"name": "Important Project"
}
],
"query_time": "0.000061141",
"result_count": 3,
"page_count": 1,
"result_count_time": "0.000137478",
"serialization_time": "0.000653689"
}
admin@Structr>

del

del deletes all objects that are selected by the given URI.

anonymous@Structr> help del
delete <URI> - Executes the given DELETE request.
Example
admin@Structr> del /Project/7159a1e615f240ada4f160ea7e3280b8
DELETE http://0.0.0.0:8082/structr/rest/Project/7159a1e615f240ada4f160ea7e3280b8
HTTP/1.1 200 OK
{
"result": [],
"result_count": 1,
"page_count": 1,
"result_count_time": "0.000117125",
"serialization_time": "0.000387572"
}
admin@Structr>

delete

delete is an alias for del, it deletes all objects selected by the given URI.

anonymous@Structr> help delete
delete <URI> - Executes the given DELETE request.
Example
Unnamedadmin@Structr> del /Project/7159a1e615f240ada4f160ea7e3280b8
DELETE http://0.0.0.0:8082/structr/rest/Project/7159a1e615f240ada4f160ea7e3280b8
HTTP/1.1 200 OK
{
"result": [],
"result_count": 1,
"page_count": 1,
"result_count_time": "0.000117125",
"serialization_time": "0.000387572"
}
admin@Structr>

get

get returns a set of objects (zero, one ore more) selected by the given URI, with an optional JSON path to select individual values.

anonymous@Structr> help get
get <URI> [return <jsonPath>] - Executes the given GET request.
Example 1 (Collection resource)
admin@Structr> get /Project
GET http://0.0.0.0:8082/structr/rest/Project
HTTP/1.1 200 OK
{
"result": [
{
"id": "d8070ae07cde4b6d9d6302acb6115e91",
"type": "Project",
"name": "Test"
},
{
"id": "9f040115a5744526801a6b1f733b2de6",
"type": "Project",
"name": "Project 1"
},
{
"id": "7159a1e615f240ada4f160ea7e3280b8",
"type": "Project",
"name": "Important Project"
}
],
"query_time": "0.000043672",
"result_count": 3,
"page_count": 1,
"result_count_time": "0.000098360",
"serialization_time": "0.000535650"
}

admin@Structr>
Example 2 (Entity resource)
admin@Structr> get /Project/7159a1e615f240ada4f160ea7e3280b8
GET http://0.0.0.0:8082/structr/rest/Project/7159a1e615f240ada4f160ea7e3280b8
HTTP/1.1 200 OK
{
"result": {
"id": "7159a1e615f240ada4f160ea7e3280b8",
"type": "Project",
"name": "Important Project"
},
"query_time": "0.000615899",
"result_count": 1,
"page_count": 1,
"result_count_time": "0.000125307",
"serialization_time": "0.000463219"
}

admin@Structr>

help

help prints the help text for the given command.

anonymous@Structr> help help
Prints a list of all commands and a short help text. Use 'help <command> to get more details.

post

post creates new objects or executes schema methods based on the given URI.

anonymous@Structr> help post
post <URI> <JSON> - Executes the given POST request with the given body (optional).
Example
admin@Structr> post /Project { name: "Project Two" }
POST http://0.0.0.0:8082/structr/rest/Project
HTTP/1.1 201 Created
{
"result": [
"61e5023298924ba78113902a224d7eab"
],
"result_count": 1,
"page_count": 1,
"result_count_time": "0.000103878",
"serialization_time": "0.000418174"
}
admin@Structr>

put

put modifies existing objects, addressed by the URI, with the changeset given as a JSON document.

anonymous@Structr> help put
put <URI> <JSON> - Executes the given PUT request with the given body (optional).
Example
admin@Structr> put /Project/61e5023298924ba78113902a224d7eab { name: "Project 2000" }
PUT http://0.0.0.0:8082/structr/rest/Project/61e5023298924ba78113902a224d7eab
HTTP/1.1 200 OK
{
"result": [],
"result_count": 1,
"page_count": 1,
"result_count_time": "0.000122587",
"serialization_time": "0.000398315"
}
admin@Structr>