Skip to content

Commit

Permalink
Merge pull request #20 from SE-Stuttgart/dev
Browse files Browse the repository at this point in the history
#### Changelog release 1.1.3

##### For Web Service Users
 - The web service function is renamed from *block_booksearch_get_searched_locations* to *block_booksearch_search_course_book_content*
 - The web service function *block_booksearch_search_course_book_content* no longer requires the parameter userid
	- We expect the web service user to check if the third user should have access to the information provided
	- Parameter Snippet:    
```
/**
 * Returns description of method parameter
 * @return external_function_parameters
 */
public static function execute_parameters() {
	return new external_function_parameters(
		[
			'courseid' => new external_value(PARAM_INT, 'Id of the course the user wants to access', VALUE_REQUIRED),
			'searchstring' => new external_value(PARAM_TEXT, 'String to search for in the course', VALUE_REQUIRED),
			'contextlength' => new external_value(PARAM_INT, 'Number of words surrounding the found query word in each direction', VALUE_DEFAULT, 1),
		]
	);
}
```

 - As the web service may leak course information to non members, we now require the web service user has the capability to share course information with an unknown third user.
	- Therefore the web service user now requires to be a teacher, editing teacher or manager
	- Block usge via the ui still only requires course access
 - The web service function *block_booksearch_search_course_book_content* return value is no longer a JSON string but the datastructure itself.
	- Return Snippet:
```
/**
 * Returns description of the method return values.
 * @return external_value
 */
public static function execute_returns() {
	return new external_multiple_structure(
		new external_single_structure([
			'filename' => new external_value(PARAM_TEXT, 'name of the pdf file that has a matching book.'),
			'pagenumber' => new external_value(PARAM_INT, 'page number this searched occurance happens in filename book.'),
			'bookchapterurl' => new external_value(PARAM_RAW, 'url to pagenumber book chapter.'),
			'contextsnippet' => new external_value(PARAM_RAW, 'text snippet around the occurance.'),
		])
	);
}
```


##### For Developer
 - Reworked how the search works (*amd\src\search_and_display.js* and *classes\search\search.php*)
 - Updated the webservice, no longer in *externallib.php*, now in *classes\external\search_book_content.php* (More info in *Changelog for Web Service Users*
 - Added *styles.css*
 - Refactored *locallib.php* in own classes *classes\search\search.php* for the content search and *classes\data\data.php* for the file search and book pdf matching
 - Removed german language file.
 - Now uses ESM module *block_booksearch/search_and_display* for the ui javascript capabilities instead of plain js in <script>
  • Loading branch information
MakinZeel authored Jul 25, 2024
2 parents 111067c + ae1bc3a commit e680689
Show file tree
Hide file tree
Showing 21 changed files with 1,524 additions and 975 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
.git/
grunt.md
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ This involves the following steps:
3. Create a new specific user.
4. Check user capability: The specified user has to have at least the __webservice/rest:use__ capability. If the user does not have the permission, you can add the permission to a role and then add the user to that role.
5. Select a service: Add the "Booksearch" to custom services.
6. Add functions: Add the "block_booksearch_get_searched_locations" function to the "Booksearch" service.
7. Select a specific user: Add the web services user as an authorised user.
8. The authorized user needs the rights to access the course content.
9. Create a token for a user: Create a token for the web services user.
6. Add functions: Add the "block_booksearch_search_course_book_content" function to the "Booksearch" service. Here you see that the function has the required capability __block/booksearch:searchservice__. The user gets this capability by being a teacher, editing teacher or manager for the course it wants to search, it does not need to be a capability vsible in __Step 3.__. As the user needs to have this capability, he needs to be a teacher, editing teacher or manager for all courses you want to be able to search.
7. Select a specific user: If the services users is not set to _All users_ you need to add the web services user as an authorised user.
8. Create a token for a user: Create a token for the web services user.



Test it by sending an http GET request to
'http://[yourmoodle]/webservice/rest/server.php?wstoken=[user_token]&wsfunction=block_booksearch_get_searched_locations&moodlewsrestformat=json&userid=[user_id]&courseid=[course_id]&searchstring=[search_string]&contextlength=[context_length]'
'http://[yourmoodle]/webservice/rest/server.php?wstoken=[user_token]&wsfunction=block_booksearch_get_searched_locations&moodlewsrestformat=json&courseid=[course_id]&searchstring=[search_string]&contextlength=[context_length]'
where
- yourmoodle: domain of your moodle installation (as developer: probably localhost)
- user_token: token received from moodle for a user which is allowed to use the web service.
- user_id: the id of the user that wants to access the webservice (This user needs to have access to the course content).
- course_id: the id of the course the string is searched in.
- search_string: the search string which is used to search in moodle books and pdfs.
- context_length: the number of word before and after each found string.
Expand Down
11 changes: 11 additions & 0 deletions amd/build/search_and_display.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/search_and_display.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit e680689

Please sign in to comment.