Commit 3fd0d87
committed
Introduce PhraseIdentifier::PATTERN
The `PhraseIdentifier.generate` method is used to generate an identifier
for projects created by teachers and students. However, public projects,
e.g. those created via the `GithubWebhooksController#github_push` [1]
action and those created via the (possibly defunct)
`projects:create_all` rake task [2], have identifiers specified in their
project config via `ProjectImporter` [3].
While there is no *explicit* validation to enforce it, the identifiers
for these public projects seems to follow the pattern described by the
regular expression I have defined in `PhraseIdentifier::PATTERN`, i.e.
kebab-case with digits allowed, at least in the 2nd word [4]. The
pattern could probably be stricter, but since I don't have access to the
production data, it seems safer for it to be more relaxed.
We want admin users in experience-cs to be able to create public scratch
projects via the editor-api API and I think it makes sense to restrict
them to using identifiers following a similar pattern. I plan to add
some validation to enforce that and so we can provide feedback to the
admin user if they choose an identifier with the wrong format. I'll be
able to use this `PhraseIdentifier::PATTERN` in that validation.
[1]: https://github.com/RaspberryPiFoundation/editor-api/blob/f348dfc92fdd8b19fbfd5434e7751340f33b4093/app/controllers/github_webhooks_controller.rb#L6-L8
[2]: https://github.com/RaspberryPiFoundation/editor-api/blob/f348dfc92fdd8b19fbfd5434e7751340f33b4093/lib/tasks/projects.rake#L4-L7
[3]: https://github.com/RaspberryPiFoundation/editor-api/blob/f348dfc92fdd8b19fbfd5434e7751340f33b4093/lib/project_importer.rb
[4]: https://github.com/RaspberryPiFoundation/editor-api/blob/f348dfc92fdd8b19fbfd5434e7751340f33b4093/lib/tasks/project_components/top_5_emoji_list/project_config.yml#L21 parent 57e5349 commit 3fd0d87
2 files changed
+28
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
7 | 25 | | |
8 | 26 | | |
9 | 27 | | |
| |||
18 | 36 | | |
19 | 37 | | |
20 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
21 | 47 | | |
22 | 48 | | |
23 | 49 | | |
| |||
0 commit comments