Skip to content

Commit 0463241

Browse files
authored
Merge branch 'main' into containerize-docs-site
2 parents 3aea9ef + 36d86d3 commit 0463241

12 files changed

Lines changed: 214 additions & 116 deletions

File tree

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ gem "webrick", "~> 1.9"
1212
gem 'html-proofer', "~> 3.19.4"
1313

1414
gem 'json'
15+
16+
gem 'erb'

Gemfile.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ GEM
3030
em-websocket (0.5.3)
3131
eventmachine (>= 0.12.9)
3232
http_parser.rb (~> 0)
33+
erb (6.0.4)
3334
ethon (0.16.0)
3435
ffi (>= 1.15.0)
3536
eventmachine (1.2.7)
@@ -221,7 +222,7 @@ GEM
221222
gemoji (>= 3, < 5)
222223
html-pipeline (~> 2.2)
223224
jekyll (>= 3.0, < 5.0)
224-
json (2.19.3)
225+
json (2.19.9)
225226
kramdown (2.4.0)
226227
rexml
227228
kramdown-parser-gfm (1.1.0)
@@ -295,6 +296,7 @@ PLATFORMS
295296
x86_64-linux
296297

297298
DEPENDENCIES
299+
erb
298300
github-pages (= 232)
299301
html-proofer (~> 3.19.4)
300302
json

_docs/developer/developing_the_php_site/controller.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ appropriate [View](view).
1515
A request to view the `UserDetails` page would first hit the
1616
`UserController`, which might look something like this:
1717

18-
```PHP
18+
```php
1919
/**
20-
* Route to view the userDetailsPage.
21-
* @Route("/{_semester}/{_course}/show_user_details", methods={"GET"})
22-
* @AccessControl(role="INSTRUCTOR")
23-
**/
24-
20+
* Route to view the userDetailsPage.
21+
*/
22+
#[AccessControl(role="INSTRUCTOR")]
23+
#[Route("/{_semester}/{_course}/show_user_details", methods={"GET"})]
2524
public function userDetailsPage($user_id) {
2625
$user = $this->core->getQueries()->getUserFromId($user_id);
2726
if ($user) {
@@ -41,7 +40,7 @@ From the website, they can now make a request which routes to the
4140
`userDetails` page. Something like
4241
`f20/sample/show_user_details?user_id="aphacker"`
4342

44-
Because we added `@AccessControl(role="INSTRUCTOR")`, only instructor
43+
Because we added `#[AccessControl(role="INSTRUCTOR")]`, only instructor
4544
level users can access this page.
4645

4746
The `$user_id` parameter to our function is populated from the
@@ -86,9 +85,7 @@ annotation in the docstring for the controller class, like so:
8685
```php
8786
use app\libraries\routers\Enabled;
8887

89-
/**
90-
* @Enabled("forum")
91-
*/
88+
#[Enabled(feature: "forum")]
9289
class ForumController {}
9390
```
9491

_docs/developer/getting_started/worker_vm.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ machines* in addition to your primary vagrant virtual machine.
3535
```
3636
vagrant workers up
3737
```
38+
Alternatively, if you are testing the worker install process, it may be helpful to install the worker machine(s) from scratch.
39+
40+
On Linux or Mac type:
41+
```
42+
FROM_SCRATCH=1 vagrant workers up
43+
```
44+
On Windows with `cmd` type:
45+
```
46+
SET FROM_SCRATCH=1
47+
vagrant workers up
48+
```
49+
3850
_NOTE: Do not use the --provider flag with this command, since it will conflict with the
3951
provider of the main virtual machine._
4052

@@ -80,6 +92,24 @@ __NOTE__: Depending on the performance of your computer and the size of the auto
8092

8193
---
8294

95+
## Removing Worker Machine(s)
96+
97+
If you would like to remove your worker machine(s), run:
98+
```
99+
vagrant workers destroy
100+
```
101+
For each worker machine, you will be prompted on whether you would like to remove it.
102+
103+
Alternatively, you can also destroy worker machines individually using:
104+
```
105+
vagrant destroy 1a2b3c4d
106+
```
107+
Where `1a2b3c4d` is the id of the machine.
108+
109+
_Note: You can find a list of all vagrant machines and their ids using `vagrant global-status` ._
110+
111+
---
112+
83113
## Manual Worker Installation (VirtualBox)
84114

85115
1. Open the Virtual Box application.

_docs/developer/software_and_system_design/router.md

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,36 @@ While most routes in Submitty are specific to one course, there are places that
3030
For those routes, it is simple to set up a route.
3131

3232
```php
33-
/**
34-
* @Route("/home")
35-
*/
33+
#[Route("/home")]
3634
public function showHomepage() {...}
3735
```
3836

3937
#### Route with Course Information
4038

41-
A majority of links in Submitty require course information to return correct contents. Therefore, it is necessary for the router to know which `(term, course)` tuple is requested. It is needed to prepend the route with `/courses/{_term}/{_course}`. The course information will be loaded automatically before calling the function.
39+
A majority of links in Submitty require course information to return correct contents. Therefore, it is necessary for the router to know which `(semester, course)` tuple is requested. It is needed to prepend the route with `/courses/{_semester}/{_course}`. The course information will be loaded automatically before calling the function.
4240

4341
```php
44-
/**
45-
* @Route("/courses/{_term}/{_course}/reports")
46-
*/
42+
#[Route("/courses/{_semester}/{_course}/reports")]
4743
public function showReportPage() {...}
4844
```
4945

50-
To visit the page defined above, simply go to `{base_url}/{current term}/sample/reports`.
46+
To visit the page defined above, simply go to `{base_url}/{current semester}/sample/reports`.
5147

5248
#### Route with Parameters
5349

5450
Sometimes we may want to pass parameters to functions. Wrapping the parameter name with brackets will do the trick.
5551

5652
```php
57-
/**
58-
* @Route("/courses/{_term}/{_course}/student/{gradeable_id}")
59-
*/
60-
public function showHomeworkPage($gradeable_id){...}
53+
#[Route("/courses/{_semester}/{_course}/gradeable/{gradeable_id}")]
54+
public function showHomeworkPage($gradeable_id) {...}
6155
```
6256

63-
Note that `{_term}` and `{_course}` are actually special cases of parameters that are automatically processed by the router.
57+
Note that `{_semester}` and `{_course}` are actually special cases of parameters that are automatically processed by the router.
6458

6559
Also, note that parameters in the `GET` query are passed to the function too without the need for explicit definition as long as parameter names are the same.
6660

6761
```php
68-
/**
69-
* @Route("/authentication/login")
70-
*/
62+
#[Route("/authentication/login")]
7163
public function loginForm($old = null) {...}
7264
```
7365

@@ -78,16 +70,12 @@ The value of `$old` will be set to `Submitty` if you go to `/authentication/logi
7870
In some cases, you may want routes to match number-only parameters, or those not starting with certain words. This could be done by adding a `requirements` field in the route definition.
7971

8072
```php
81-
/**
82-
* @Route("/courses/{_term}/{_course}/notifications/{nid}", requirements={"nid": "[1-9]\d*"})
83-
*/
84-
public function openNotification($nid) {...}
73+
#[Route("/courses/{_semester}/{_course}/notifications/{nid}", requirements: ["nid" => "[1-9]\d*"])]
74+
public function openNotification($nid, $seen) {...}
8575
```
8676

8777
```php
88-
/**
89-
* @Route("/courses/{_term}/{_course}", requirements={"_term": "^(?!api)[^\/]+", "_course": "[^\/]+"})
90-
*/
78+
#[Route('/courses/{_semester}/{_course}', requirements: ['_semester' => '^(?!api)[^\/]+', '_course' => '[^\/]+'])]
9179
public function navigationPage() {...}
9280
```
9381

@@ -98,27 +86,23 @@ To prevent [cross-site request forgery](https://en.wikipedia.org/wiki/Cross-site
9886
Note that, by default, the `methods` of routes are set to be `ALL`, which means the route accepts all kind of requests. Therefore, in some cases one route may be masked by another. If you have two routes with the same name, please specify the `methods` of both.
9987

10088
```php
101-
/**
102-
* @Route("/home/change_username", methods={"POST"})
103-
*/
89+
#[Route("/user_profile/change_preferred_names", methods: ["POST"])]
10490
public function changeUserName(){...}
10591
```
10692

10793
#### Route that Needs Access Control
10894

109-
Access control can be enforced easily via `@AccessControl` annotation. Please add `use app\libraries\routers\AccessControl` to the file before using it.
95+
Access control can be enforced easily via `#[AccessControl(...)]` annotation. Please add `use app\libraries\routers\AccessControl` to the file before using it.
11096

11197
For example, the following route will only allow instructor access.
11298

11399
```php
114-
/**
115-
* @Route("/courses/{_term}/{_course}/course_materials/modify_permission")
116-
* @AccessControl(role="INSTRUCTOR")
117-
*/
100+
#[AccessControl(role: "INSTRUCTOR")]
101+
#[Route("/courses/{_semester}/{_course}/course_materials/modify_timestamp")]
118102
public function modifyCourseMaterialsFilePermission($filename, $checked)
119103
```
120104

121-
For more examples about `@AccessControl`, please read [the documentation in the code](https://github.com/Submitty/Submitty/blob/master/site/app/libraries/routers/AccessControl.php).
105+
For more examples about `#[AccessControl(...)]`, please read [the documentation in the code](https://github.com/Submitty/Submitty/blob/master/site/app/libraries/routers/AccessControl.php).
122106

123107
#### Route for API
124108

@@ -130,20 +114,16 @@ Any route that uses the `/api` goes through a slightly different authentication
130114
For example, the following route is the API for list of courses:
131115

132116
```php
133-
/**
134-
* @Route("/home/courses/new", methods={"POST"})
135-
* @Route("/api/courses", methods={"POST"})
136-
*/
117+
#[Route("/home/courses/new", methods: ["POST"])]
118+
#[Route("/api/courses", methods: ["POST"])]
137119
public function createCourse()
138120
```
139121

140122
And an API route for a method within a course:
141123

142124
```php
143-
/**
144-
* @Route("/courses/{_term}/{_course}/users", methods={"GET"})
145-
* @Route("/api/courses/{_term}/{_course}/users", methods={"GET"})
146-
*/
125+
#[Route("/courses/{_semester}/{_course}/users", methods: ["GET"])]
126+
#[Route("/api/courses/{_semester}/{_course}/users", methods: ["GET"])]
147127
public function getStudents()
148128
```
149129

_docs/developer/software_and_system_design/router_response.md

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ like docstrings. You can think of PHP functions as endpoints that get
1919
mapped to different routes via the router.
2020

2121
```php
22-
/**
23-
* @Route("/courses/{_semester}/{_course}/gradeable/{gradeable_id}/team/new")
24-
*/
25-
public function createNewTeam($gradeable_id){
22+
#[Route("/courses/{_semester}/{_course}/gradeable/{gradeable_id}/team/new")]
23+
public function createNewTeam($gradeable_id) {...}
2624
```
2725

2826
Above is an example route that points to a function in the
@@ -50,10 +48,8 @@ after the base-name matters.
5048
Functions can have multiple parameters sent to them through a URL.
5149

5250
```php
53-
/**
54-
* @Route("/courses/{_semester}/{_course}/example_route/{var1}/{var2}/{var3}")
55-
*/
56-
public function example($var1, $var2, $var3){
51+
#[Route("/courses/{_semester}/{_course}/example_route/{var1}/{var2}/{var3}")]
52+
public function example($var1, $var2, $var3) {...}
5753
```
5854

5955
#### Pattern Matching Route Variables
@@ -73,10 +69,8 @@ request body. By adding `methods={""}` after the URL in a route annotation you
7369
can make sure the router matches certain types of requests only.
7470

7571
```php
76-
/**
77-
* @Route("/courses/{_semester}/{_course}/course_materials/upload", methods={"POST"})
78-
*/
79-
public function ajaxUploadCourseMaterialsFiles() {
72+
#[Route("/courses/{_semester}/{_course}/course_materials/upload", methods: ["POST"])]
73+
public function ajaxUploadCourseMaterialsFiles() {...}
8074
```
8175

8276
The router will automatically check all POST requests for valid
@@ -94,19 +88,17 @@ A PHP function can have multiple routes point towards it. This is
9488
typically done for optional parameters and the API.
9589

9690
```php
97-
/**
98-
* @Route("/courses/{_semester}/{_course}/gradeable/{gradeable_id}")
99-
* @Route("/courses/{_semester}/{_course}/gradeable/{gradeable_id}/{gradeable_version}")
100-
*/
101-
public function showHomeworkPage($gradeable_id, $gradeable_version = null){
91+
#[Route("/courses/{_semester}/{_course}/gradeable/{gradeable_id}")]
92+
#[Route("/courses/{_semester}/{_course}/gradeable/{gradeable_id}/{gradeable_version}", requirements: ["gradeable_version" => "\d+"])]
93+
public function showHomeworkPage($gradeable_id, $gradeable_version = null) {...}
10294
```
10395

10496
The above example allows users to optionally include a
10597
gradeable_version in the URL while still calling the same function.
10698

10799
#### Access Control
108100

109-
The router can also restrict certain users by pattern matching against the user's access group. This can be done by adding the "\@AccessControl" annotation and giving a specific role. The following roles can be used
101+
The router can also restrict certain users by pattern matching against the user's access group. This can be done by adding the `#[AccessControl(...)]` annotation and giving a specific role. The following roles can be used
110102
in this annotation:
111103

112104
* INSTRUCTOR
@@ -115,11 +107,9 @@ in this annotation:
115107
* STUDENT
116108

117109
```php
118-
/**
119-
* @Route("/courses/{_semester}/{_course}/course_materials/edit", methods={"POST"})
120-
* @AccessControl(role="INSTRUCTOR")
121-
*/
122-
public function ajaxEditCourseMaterialsFiles() {
110+
#[AccessControl(role: "INSTRUCTOR")]
111+
#[Route("/courses/{_semester}/{_course}/course_materials/edit", methods: ["POST"])]
112+
public function ajaxEditCourseMaterialsFiles(bool $flush = true) {...}
123113
```
124114

125115
The above example will allow only users with the role "instructor"
@@ -131,30 +121,25 @@ You can also perform access control by restricting users with certain
131121
permissions. This can be done by passing in the "permission" field within the access control annotation.
132122

133123
```php
134-
/**
135-
* @Route(/example/access)
136-
* @AccessControl(permission="path.read.rainbow_grades")
137-
*/
138-
public function examplePermissionAccess(){
124+
#[AccessControl(permission="path.read.rainbow_grades")]
125+
#[Route(/example/access)]
126+
public function examplePermissionAccess() {...}
139127
```
140128

141129
The above access will allow only users with permission to view the
142130
rainbow grades directory. You can view the list of permissions under
143131
[Access.php](https://github.com/Submitty/Submitty/blob/master/site/app/libraries/routers/AccessControl.php)
144132

145-
*Note* You can restrict users by permission and role at the same time by using both parameters : `@AccessControl(role="STUDENT", permission="gradeable.submit.everyone")`
133+
*Note* You can restrict users by permission and role at the same time by using both parameters : `#[AccessControl(role="STUDENT", permission="gradeable.submit.everyone")]`
146134

147135

148136
Certain controllers can have every function restricted to a certain
149137
role, for example the controllers under `site/app/controllers/admin`.
150138
You can annotate access across an entire class at once to prevent writing the same thing over every function.
151139

152140
```php
153-
/**
154-
* Class AdminGradeableController
155-
* @AccessControl(role="INSTRUCTOR")
156-
*/
157-
class AdminGradeableController extends AbstractController {
141+
#[AccessControl(role: "INSTRUCTOR")]
142+
class AdminGradeableController extends AbstractController {...}
158143
```
159144

160145
Every function within `AdminGradeableController.php` will share this
@@ -173,11 +158,9 @@ behave very similarly as well.
173158

174159
API routes always start with `/api/`. The following are examples of valid API routes.
175160

176-
```php
177-
/**
178-
* @Route("/api/courses/{_semester}/{_course}/users", methods={"GET"})
179-
* @Route("/api/courses", methods={"POST"})
180-
*/
161+
```plaintext
162+
#[Route("/api/courses/{_semester}/{_course}/users", methods={"GET"})]
163+
#[Route("/api/courses", methods={"POST"})]
181164
```
182165

183166
#### Different Response Types
@@ -198,12 +181,13 @@ The API is currently a work in progress. Submitty uses a RESTful API design and
198181

199182
## The MultiResponse Object
200183

201-
Here is a basic example of the multiResponse object:
184+
Here is a basic example of the MultiResponse object:
202185
```php
203186
/**
204-
* @Route("/example/method", methods={"GET"})
205-
* @Route("/api/example/method", methods={"GET"})
206-
*/
187+
* @return MultiResponse
188+
*/
189+
#[Route("/example/method", methods={"GET"})]
190+
#[Route("/api/example/method", methods={"GET"})]
207191
public function foo(){
208192
return new MultiResponse(
209193
JsonResponse::getSuccessResponse("It worked!"),
@@ -313,4 +297,4 @@ https://submitty.myuniversity.edu/home/gradeables/foo/bar
313297

314298
### Using the MultiResponse Object
315299

316-
It is recommended you use the MultiResponse object for new controllers moving onwards
300+
It is recommended you use the MultiResponse object for new controllers moving onwards.

0 commit comments

Comments
 (0)