forked from nigelgbanks/islandora_rest
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathislandora_rest.module
208 lines (195 loc) · 6.98 KB
/
islandora_rest.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* @file
* Defines all the hooks this module implements.
*/
// Menu items.
define('ISLANDORA_REST_VERSION', 'v1');
define('ISLANDORA_REST_URL_PREFIX', 'islandora/rest/' . ISLANDORA_REST_VERSION);
define('ISLANDORA_REST_OBJECT_MENU', ISLANDORA_REST_URL_PREFIX . '/object');
define('ISLANDORA_REST_DATASTREAM_MENU', ISLANDORA_REST_OBJECT_MENU . '/%/datastream');
define('ISLANDORA_REST_DATASTREAM_TOKEN_MENU', ISLANDORA_REST_DATASTREAM_MENU . '/%/token');
define('ISLANDORA_REST_RELATIONSHIP_MENU', ISLANDORA_REST_OBJECT_MENU . '/%/relationship');
define('ISLANDORA_REST_SOLR_MENU', ISLANDORA_REST_URL_PREFIX . '/solr/%menu_tail');
// Permissions.
define('ISLANDORA_REST_OBJECT_GET_PERM', 'view objects');
define('ISLANDORA_REST_OBJECT_POST_PERM', 'create objects');
define('ISLANDORA_REST_OBJECT_PUT_PERM', 'modify object properties');
define('ISLANDORA_REST_OBJECT_DELETE_PERM', 'delete objects');
define('ISLANDORA_REST_DATASTREAM_GET_PERM', 'view datastreams');
define('ISLANDORA_REST_DATASTREAM_TOKEN_GET_PERM', 'generate datastream token');
define('ISLANDORA_REST_DATASTREAM_POST_PERM', 'create datastreams');
define('ISLANDORA_REST_DATASTREAM_PUT_PERM', 'modify datastreams');
define('ISLANDORA_REST_DATASTREAM_DELETE_PERM', 'delete datastreams');
define('ISLANDORA_REST_RELATIONSHIP_GET_PERM', 'list relationships');
define('ISLANDORA_REST_RELATIONSHIP_POST_PERM', 'create relationships');
define('ISLANDORA_REST_RELATIONSHIP_DELETE_PERM', 'delete relationships');
/**
* Implements hook_menu().
*/
function islandora_rest_menu() {
// We don't use the access callback for any of the REST end-points as we can't
// reliably return JSON from that point.
return array(
ISLANDORA_REST_OBJECT_MENU => array(
'page callback' => 'islandora_rest_object',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
),
ISLANDORA_REST_DATASTREAM_MENU => array(
'page callback' => 'islandora_rest_datastream',
'page arguments' => array(4, 6),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
),
ISLANDORA_REST_DATASTREAM_TOKEN_MENU => array(
'page callback' => 'islandora_rest_datastream_token',
'page arguments' => array(4, 6),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
),
ISLANDORA_REST_RELATIONSHIP_MENU => array(
'page callback' => 'islandora_rest_relationship',
'page arguments' => array(4),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
),
ISLANDORA_REST_SOLR_MENU => array(
'page callback' => 'islandora_rest_solr',
'page arguments' => array(
4,
),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'load arguments' => array(
'%map',
'%index',
),
),
);
}
/**
* Implements hook_permission().
*/
function islandora_rest_permission() {
return array(
ISLANDORA_REST_OBJECT_GET_PERM => array(
'title' => t('View objects'),
'description' => t('Allows users to fetch an objects properties and list its datastreams.'),
),
ISLANDORA_REST_OBJECT_POST_PERM => array(
'title' => t('Create objects'),
'description' => t('Allows users to create objects.'),
),
ISLANDORA_REST_OBJECT_PUT_PERM => array(
'title' => t('Modify object properties'),
'description' => t('Allows users to modify an objects properites.'),
),
ISLANDORA_REST_OBJECT_DELETE_PERM => array(
'title' => t('Delete objects'),
'description' => t('Allows users to delete objects.'),
),
ISLANDORA_REST_DATASTREAM_TOKEN_GET_PERM => array(
'title' => t('Generate Datastream Tokens'),
'description' => t('Allows users to get an authorization token for a datastream.'),
),
ISLANDORA_REST_DATASTREAM_GET_PERM => array(
'title' => t('View datastreams'),
'description' => t('Allows users to get a given datastream content and properties.'),
),
ISLANDORA_REST_DATASTREAM_POST_PERM => array(
'title' => t('Create datastreams'),
'description' => t('Allows users to create datastreams.'),
),
ISLANDORA_REST_DATASTREAM_PUT_PERM => array(
'title' => t('Modify datastreams'),
'description' => t('Allows users to modify existing datastreams and their properties.'),
),
ISLANDORA_REST_DATASTREAM_DELETE_PERM => array(
'title' => t('Delete datastreams'),
'description' => t('Allows users to delete datastreams.'),
),
ISLANDORA_REST_RELATIONSHIP_GET_PERM => array(
'title' => t('List relationships'),
'description' => t('Allows users to list an objects relationships.'),
),
ISLANDORA_REST_RELATIONSHIP_POST_PERM => array(
'title' => t('Create relationships'),
'description' => t('Allows users to create new relationships.'),
),
ISLANDORA_REST_RELATIONSHIP_DELETE_PERM => array(
'title' => t('Delete relationships'),
'description' => t('Allows users to delete existing relationships'),
),
);
}
/**
* Rest end-point for objects.
*
* @note This function exits.
*/
function islandora_rest_object($pid = NULL) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
print islandora_rest_get_response('object', array('pid' => $pid));
exit();
}
/**
* Rest end-point for datastreams.
*
* @note This function exits.
*/
function islandora_rest_datastream($pid, $dsid) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
print islandora_rest_get_response('datastream', array('pid' => $pid, 'dsid' => $dsid));
exit();
}
/**
* Implements hook islandora_object_access().
*/
function islandora_rest_islandora_object_access($op, $object, $user) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
$map = _islandora_rest_permission_map();
if (isset($map[$op])) {
return islandora_object_access($map[$op], $object, $user);
}
}
/**
* Implements hook islandora_datastream_access().
*/
function islandora_rest_islandora_datastream_access($op, $datastream, $user) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
$map = _islandora_rest_permission_map();
if (isset($map[$op])) {
return islandora_datastream_access($map[$op], $datastream, $user);
}
}
/**
* Rest end-point for datastream tokens.
*
* @note This function exits.
*/
function islandora_rest_datastream_token($pid, $dsid) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
print islandora_rest_get_response('datastream_token', array('pid' => $pid, 'dsid' => $dsid));
exit();
}
/**
* Rest end-point for relationships.
*
* @note This function exits.
*/
function islandora_rest_relationship($pid) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
print islandora_rest_get_response('relationship', array('pid' => $pid));
exit();
}
/**
* Rest end-point for making SOLR queries.
*
* @note This function exits.
*/
function islandora_rest_solr($query = NULL) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
print islandora_rest_get_solr_response(array('query' => $query));
exit();
}