mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-05-04 18:08:46 +03:00
Compare commits
934 Commits
v24.02.2
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ddfa9b948 | ||
|
|
55317039ac | ||
|
|
24e6087ef8 | ||
|
|
7c1d30bc8f | ||
|
|
c1610c4532 | ||
|
|
2e2f59fa0f | ||
|
|
cc6e9e0546 | ||
|
|
0f59981932 | ||
|
|
a37f903dc7 | ||
|
|
74aa897626 | ||
|
|
4b624596c8 | ||
|
|
00239bb6c8 | ||
|
|
241563e8fc | ||
|
|
e91747785b | ||
|
|
4f370ccddb | ||
|
|
743a21a02f | ||
|
|
0c9fabb6de | ||
|
|
426f9ac493 | ||
|
|
ec0b0384a2 | ||
|
|
e7e019d3d4 | ||
|
|
1339f668eb | ||
|
|
befa3a8fbb | ||
|
|
083fb1a600 | ||
|
|
a2bb5bdf10 | ||
|
|
e274a5fa4e | ||
|
|
18364d1e6e | ||
|
|
0760e677b2 | ||
|
|
208629ee1f | ||
|
|
346dc27979 | ||
|
|
1c1ad1d1b7 | ||
|
|
f14fc68b66 | ||
|
|
93f84a81b2 | ||
|
|
4feb50e7ee | ||
|
|
c7e2b487c1 | ||
|
|
4e3fa4822f | ||
|
|
684a94c419 | ||
|
|
c3c8577f05 | ||
|
|
5fbaab4740 | ||
|
|
3d9d5fef51 | ||
|
|
5e78dc6ed5 | ||
|
|
c33853ed84 | ||
|
|
e033578fea | ||
|
|
a7dd998ac9 | ||
|
|
b9d650785a | ||
|
|
abed4eae0c | ||
|
|
c7d3775bb9 | ||
|
|
0b659671fe | ||
|
|
25790fd024 | ||
|
|
1763ac550b | ||
|
|
fd6867e577 | ||
|
|
5ebc1fe3b0 | ||
|
|
a44756168d | ||
|
|
fa1dc162bd | ||
|
|
5763d26b17 | ||
|
|
04dd9f8e19 | ||
|
|
0120b475eb | ||
|
|
8a59895ba0 | ||
|
|
a9ffd3e0c7 | ||
|
|
4f18fea086 | ||
|
|
362859ac23 | ||
|
|
7cbfd72920 | ||
|
|
49df47836e | ||
|
|
f4c9d2b049 | ||
|
|
60a3b0c0ac | ||
|
|
5f5fea7c83 | ||
|
|
6e7cc169d1 | ||
|
|
6216c89f82 | ||
|
|
404e67afbc | ||
|
|
6d64262a61 | ||
|
|
151823b84e | ||
|
|
27240be499 | ||
|
|
d0d1bb9829 | ||
|
|
7d0237c798 | ||
|
|
f2f76a3c56 | ||
|
|
ec3dd856db | ||
|
|
25ed242f61 | ||
|
|
10c46534e0 | ||
|
|
dd42b9b43f | ||
|
|
9a12e3a8b7 | ||
|
|
7aef0a48b3 | ||
|
|
6808292c90 | ||
|
|
c10b0fd5b9 | ||
|
|
1077a4efd0 | ||
|
|
23f3f35f6b | ||
|
|
229a99ba24 | ||
|
|
8e99fc6783 | ||
|
|
80204518a2 | ||
|
|
a8d96fd389 | ||
|
|
9d15c79fee | ||
|
|
e1de1f0583 | ||
|
|
a2017ffa55 | ||
|
|
9646339933 | ||
|
|
e4383765e1 | ||
|
|
5d547fcf4c | ||
|
|
826b36c985 | ||
|
|
3fa1174e7a | ||
|
|
50e8501027 | ||
|
|
8a221f64e4 | ||
|
|
035be66ebc | ||
|
|
227027fc45 | ||
|
|
0f040fe8b1 | ||
|
|
10ebe53bd9 | ||
|
|
5e12b678c7 | ||
|
|
057d7be0bc | ||
|
|
984a73159f | ||
|
|
a20438b901 | ||
|
|
9d3d0a4a07 | ||
|
|
5038d124e1 | ||
|
|
f7890c2dd9 | ||
|
|
45ae03ceac | ||
|
|
aa0a8dda11 | ||
|
|
120ee38383 | ||
|
|
cd84074cdf | ||
|
|
4949520194 | ||
|
|
46dcc30bf7 | ||
|
|
9f7d3b55dd | ||
|
|
3e5e88dc87 | ||
|
|
c77a0fdff3 | ||
|
|
6a63b38bb3 | ||
|
|
1b17bb3929 | ||
|
|
9fcfc762ec | ||
|
|
c32b1686a9 | ||
|
|
36649a6188 | ||
|
|
ff59bbdc07 | ||
|
|
4dc443b7df | ||
|
|
19f02d927e | ||
|
|
da7bedd2e4 | ||
|
|
20db372596 | ||
|
|
43eed1660c | ||
|
|
e6b754fad0 | ||
|
|
018de5def3 | ||
|
|
5c4fc3dc2c | ||
|
|
07ec880e33 | ||
|
|
ab436ed5c3 | ||
|
|
082befb2fc | ||
|
|
b0a8cb0c5d | ||
|
|
b08d1b36de | ||
|
|
88d86df66f | ||
|
|
38d3697246 | ||
|
|
d93354ff0e | ||
|
|
3336e0c6ae | ||
|
|
8fc9a2af4e | ||
|
|
8aec571123 | ||
|
|
382f4db276 | ||
|
|
d504b19143 | ||
|
|
d87e8d05c7 | ||
|
|
0b48361780 | ||
|
|
2de3247ae4 | ||
|
|
48df2be0d8 | ||
|
|
a4c0556551 | ||
|
|
a941d1b403 | ||
|
|
51f9b63db0 | ||
|
|
90fc02c57f | ||
|
|
4aeb571126 | ||
|
|
3d9aba7b1f | ||
|
|
48cdaab690 | ||
|
|
4f760479c3 | ||
|
|
9211062e8e | ||
|
|
221c6c7e9f | ||
|
|
e2f91c2bbb | ||
|
|
147ff00c7a | ||
|
|
1e768ce33f | ||
|
|
313326b32a | ||
|
|
1d87b513be | ||
|
|
9bf9ae9c37 | ||
|
|
50540e23a1 | ||
|
|
3e1b0587ec | ||
|
|
6661ae8178 | ||
|
|
1ee5711435 | ||
|
|
08e7ba7064 | ||
|
|
34e747162f | ||
|
|
10f5ceee35 | ||
|
|
9886bbd3a0 | ||
|
|
92a3c22b4c | ||
|
|
b5246a28f0 | ||
|
|
ab4b1c8efa | ||
|
|
8890746278 | ||
|
|
dfdcfcfdb8 | ||
|
|
ebceba0afe | ||
|
|
65f7b61c1f | ||
|
|
2fde803c76 | ||
|
|
adfac3e30e | ||
|
|
21730aeb39 | ||
|
|
75231d2d4a | ||
|
|
9d732d8dd8 | ||
|
|
9e8088f186 | ||
|
|
cf847974d2 | ||
|
|
3cd3e73f60 | ||
|
|
bb350639c6 | ||
|
|
9de294343d | ||
|
|
98a09bcc37 | ||
|
|
959981a676 | ||
|
|
674bb84fac | ||
|
|
ba675b6349 | ||
|
|
f073994bc3 | ||
|
|
0f40aeb0d3 | ||
|
|
cdd164e3e3 | ||
|
|
c90816987c | ||
|
|
dd393691b1 | ||
|
|
dd5375f480 | ||
|
|
291a807d98 | ||
|
|
e64fc60bdf | ||
|
|
ad582ab9f8 | ||
|
|
870f3c58c0 | ||
|
|
22a7772c3d | ||
|
|
9934f85ba9 | ||
|
|
73c6bf4f8d | ||
|
|
47f12cc8f6 | ||
|
|
b2f81f5c62 | ||
|
|
1be2969055 | ||
|
|
99a1d82f0a | ||
|
|
f06a6de2e7 | ||
|
|
aaa28186bc | ||
|
|
8ab9252f9b | ||
|
|
befc645705 | ||
|
|
4eb4407ef7 | ||
|
|
5bf2d801cf | ||
|
|
1421ba871d | ||
|
|
563828ba52 | ||
|
|
d40a68b411 | ||
|
|
4a57933cd1 | ||
|
|
1df850ea3e | ||
|
|
7881bddce0 | ||
|
|
570ded10fa | ||
|
|
02d024aa32 | ||
|
|
652124abaf | ||
|
|
751934c84a | ||
|
|
3fd25bd03e | ||
|
|
f0303de2e5 | ||
|
|
0b26573314 | ||
|
|
c21c36e2a6 | ||
|
|
a949900570 | ||
|
|
9c4a9225af | ||
|
|
4627dfd4f7 | ||
|
|
fcacf7cacb | ||
|
|
cbf27d70c8 | ||
|
|
3ad1e31fcc | ||
|
|
082dbc9944 | ||
|
|
abe9c1e5a3 | ||
|
|
ebf82617b8 | ||
|
|
2c81447c9e | ||
|
|
8898647f78 | ||
|
|
ea6344898f | ||
|
|
0bfd79925e | ||
|
|
efff8700d4 | ||
|
|
5754acf2fb | ||
|
|
4c7d6420ee | ||
|
|
146a6c01cc | ||
|
|
f8e4ea82c6 | ||
|
|
047195c033 | ||
|
|
a7b30c284c | ||
|
|
c3412d8c1c | ||
|
|
4db7135231 | ||
|
|
009d146185 | ||
|
|
fcef1a7948 | ||
|
|
08dfff05f4 | ||
|
|
fc10520e10 | ||
|
|
a70c733f27 | ||
|
|
573d692a59 | ||
|
|
419dbadcfd | ||
|
|
33a0237f87 | ||
|
|
5fc11d46d5 | ||
|
|
c8716df284 | ||
|
|
1ac74099ca | ||
|
|
36cb243d5e | ||
|
|
579c1bf424 | ||
|
|
242b7dfb1b | ||
|
|
7d1c316202 | ||
|
|
318b486e0b | ||
|
|
e05ec7da36 | ||
|
|
cee23de6c5 | ||
|
|
1e34954554 | ||
|
|
5ea4e1e935 | ||
|
|
a27ce6e915 | ||
|
|
64b06bcf61 | ||
|
|
cdbac63b40 | ||
|
|
d6296ac7a5 | ||
|
|
481f356068 | ||
|
|
955837c9aa | ||
|
|
c6e35c2e7c | ||
|
|
0436ccfebf | ||
|
|
f5da31037d | ||
|
|
46613f76f6 | ||
|
|
519acaf324 | ||
|
|
849bc4d6c3 | ||
|
|
ee994fa2b7 | ||
|
|
13a79b3f96 | ||
|
|
7c79b10fb6 | ||
|
|
5c481b4282 | ||
|
|
9443682ae4 | ||
|
|
0311e3d2d7 | ||
|
|
a50a256939 | ||
|
|
4830248a1e | ||
|
|
1256b30ad4 | ||
|
|
777cca76da | ||
|
|
a2d13124af | ||
|
|
bd966ef99e | ||
|
|
a6b5733ec2 | ||
|
|
e899066e96 | ||
|
|
f4f2435856 | ||
|
|
fca4a0563e | ||
|
|
0bc9ddd780 | ||
|
|
c66f3b2a37 | ||
|
|
f36e6fb929 | ||
|
|
7bc0d54af1 | ||
|
|
2eefbd21c1 | ||
|
|
a961552c23 | ||
|
|
776ec7b9e7 | ||
|
|
8aa6bdc8ab | ||
|
|
4ab17157b1 | ||
|
|
6d7ffab115 | ||
|
|
c8cfec96dc | ||
|
|
d145efb6f6 | ||
|
|
c54101c603 | ||
|
|
865e5aecc9 | ||
|
|
ae4d1d804a | ||
|
|
5fc19b0edf | ||
|
|
0a73b70b64 | ||
|
|
2668aae09b | ||
|
|
3b9c0b34ae | ||
|
|
53f32849a9 | ||
|
|
7ca8bdc231 | ||
|
|
6621d55f3d | ||
|
|
d55db06c01 | ||
|
|
6b4b500a33 | ||
|
|
5ffec2c52d | ||
|
|
ec07793cda | ||
|
|
61adc735c8 | ||
|
|
7bbf591a7f | ||
|
|
61f8d18af5 | ||
|
|
f786d25f2e | ||
|
|
e62f4426ea | ||
|
|
32ba3a591f | ||
|
|
73025719a4 | ||
|
|
d55684531f | ||
|
|
d15eb129b0 | ||
|
|
3626a2265b | ||
|
|
d13abc7e1d | ||
|
|
2442829ef2 | ||
|
|
795b28162a | ||
|
|
31706ea06b | ||
|
|
4b9e6042d5 | ||
|
|
d279b0830b | ||
|
|
181ab91b1d | ||
|
|
306f41b6f0 | ||
|
|
c1d76d2571 | ||
|
|
f83074d50e | ||
|
|
2be892be70 | ||
|
|
c934b9319f | ||
|
|
35a51197ce | ||
|
|
47fd578edb | ||
|
|
add091305c | ||
|
|
3d017594a8 | ||
|
|
0dcb2ec78c | ||
|
|
9186e77d27 | ||
|
|
6045aff33a | ||
|
|
dca9765d5d | ||
|
|
a37d0c57dc | ||
|
|
054475135a | ||
|
|
02a35b6db4 | ||
|
|
b80992ca59 | ||
|
|
c606970e38 | ||
|
|
dfeca246a0 | ||
|
|
3476d83ecc | ||
|
|
3617ab1540 | ||
|
|
c4839c783a | ||
|
|
a5751a584c | ||
|
|
f518a3be37 | ||
|
|
0208f066c5 | ||
|
|
2d0461b63a | ||
|
|
b913ae703d | ||
|
|
1611b0399f | ||
|
|
8d4b8ff4f3 | ||
|
|
77a88618c2 | ||
|
|
8b062d4795 | ||
|
|
717b516341 | ||
|
|
fda242d3da | ||
|
|
aac547934c | ||
|
|
5c9b90ea0d | ||
|
|
074f193e2f | ||
|
|
7f2604c8e8 | ||
|
|
b71b2a4376 | ||
|
|
68df43e5a8 | ||
|
|
c5ca865723 | ||
|
|
b862f12a50 | ||
|
|
b0f8b11054 | ||
|
|
7650ebf2f9 | ||
|
|
d9ea52522e | ||
|
|
2e718c12e1 | ||
|
|
a43a1832f5 | ||
|
|
c4f7368c1c | ||
|
|
2a32475541 | ||
|
|
1243108e0f | ||
|
|
3280919370 | ||
|
|
d149b809b1 | ||
|
|
eb47e11916 | ||
|
|
9d6bc1ad4d | ||
|
|
30bf0ce632 | ||
|
|
b64c9b31d5 | ||
|
|
f9dbbe5d70 | ||
|
|
05f7f4cb17 | ||
|
|
454b152b95 | ||
|
|
b29fe5c46d | ||
|
|
131ac29df4 | ||
|
|
3a9d18a6cd | ||
|
|
59e2c5e52a | ||
|
|
d29b14ebfd | ||
|
|
cdd446ac73 | ||
|
|
1dd1024eba | ||
|
|
752cfe2f67 | ||
|
|
25baaa8189 | ||
|
|
d2d0331782 | ||
|
|
8121418e18 | ||
|
|
5ab31a8191 | ||
|
|
0e69ab1938 | ||
|
|
058007109e | ||
|
|
b6110ed3cd | ||
|
|
32b29fcdfc | ||
|
|
8f92b6f21b | ||
|
|
62f78f1c6d | ||
|
|
f8c0aaff03 | ||
|
|
a27df485bb | ||
|
|
3e99ce4098 | ||
|
|
ce1e20501c | ||
|
|
295532fa7a | ||
|
|
642ba668b1 | ||
|
|
4f36cdd757 | ||
|
|
8821844c4a | ||
|
|
1262083fcf | ||
|
|
c82fa33210 | ||
|
|
15c79c38db | ||
|
|
e7dcc2dcdf | ||
|
|
099f6104d0 | ||
|
|
8bdf948743 | ||
|
|
e8f44186a8 | ||
|
|
ecda4e1d6f | ||
|
|
64da80cbf4 | ||
|
|
5fa728f28a | ||
|
|
c61ce8dee4 | ||
|
|
f656a82fe7 | ||
|
|
5bfba281fc | ||
|
|
18ede9bbd3 | ||
|
|
2e7544a865 | ||
|
|
5e3c3ad634 | ||
|
|
add238fe9f | ||
|
|
8d159f77e4 | ||
|
|
fa566f156a | ||
|
|
78a0a2f519 | ||
|
|
42cbd6adef | ||
|
|
6117349893 | ||
|
|
1256320c72 | ||
|
|
1ba0d26fdd | ||
|
|
802f69cf35 | ||
|
|
bb44334224 | ||
|
|
9bfcadd95f | ||
|
|
62c8eb3357 | ||
|
|
c03e44124a | ||
|
|
5c6671b3bf | ||
|
|
abe7467ae5 | ||
|
|
0ec0913846 | ||
|
|
e980564fd6 | ||
|
|
8a9215ecad | ||
|
|
304a1d8f91 | ||
|
|
dfbc78947f | ||
|
|
4f5ad171ac | ||
|
|
94b1cffa2d | ||
|
|
13dae24cbe | ||
|
|
6211d6bcfc | ||
|
|
a384599cfa | ||
|
|
dca14feaaa | ||
|
|
d7ccb3ce6a | ||
|
|
6548ea4a12 | ||
|
|
c3a1fabbf0 | ||
|
|
d2542d6265 | ||
|
|
0e343c408f | ||
|
|
5c78f8352e | ||
|
|
35b45a2b8d | ||
|
|
5050719ea3 | ||
|
|
5508c171db | ||
|
|
3b4d3430a5 | ||
|
|
213a86e3c0 | ||
|
|
2b746425c9 | ||
|
|
5c15f4add2 | ||
|
|
92ad81429f | ||
|
|
f1b8e857bf | ||
|
|
c291d27c19 | ||
|
|
f4449928f8 | ||
|
|
45a15b4792 | ||
|
|
2291d78382 | ||
|
|
7901ca9e6b | ||
|
|
a7de251876 | ||
|
|
7bd89316bc | ||
|
|
b9306a9029 | ||
|
|
a208c46b62 | ||
|
|
a65701294e | ||
|
|
69683d50ec | ||
|
|
37d020c083 | ||
|
|
ec79517493 | ||
|
|
d938565839 | ||
|
|
ccd94684eb | ||
|
|
103a8a8e8e | ||
|
|
c13ce18837 | ||
|
|
7093daa49d | ||
|
|
b897af2ed0 | ||
|
|
d28278bba6 | ||
|
|
12cc2f0689 | ||
|
|
bf8a84a8b1 | ||
|
|
4f5f7c10b1 | ||
|
|
a34023f715 | ||
|
|
b2ac3e0834 | ||
|
|
5b0cb3dd50 | ||
|
|
ac0cd9995d | ||
|
|
7e03a973d8 | ||
|
|
d89a2fdb15 | ||
|
|
958b537a49 | ||
|
|
8a66365d48 | ||
|
|
da82e70ca3 | ||
|
|
04cca77ae6 | ||
|
|
c091f67db3 | ||
|
|
7f5fd16dc6 | ||
|
|
0d1a237f81 | ||
|
|
786a434c03 | ||
|
|
25c4f4b02b | ||
|
|
481580be17 | ||
|
|
593645acfe | ||
|
|
b9751807e7 | ||
|
|
ee88832f1a | ||
|
|
dbda82ef92 | ||
|
|
ad8bc5fe21 | ||
|
|
5bf75786c6 | ||
|
|
cf9ccfcd5b | ||
|
|
5116d83d38 | ||
|
|
33b46882f3 | ||
|
|
9a5c287470 | ||
|
|
6effc6d262 | ||
|
|
ff6c5aaecb | ||
|
|
1ff2826678 | ||
|
|
7e31725d48 | ||
|
|
6d7ff59a89 | ||
|
|
980a684b14 | ||
|
|
d56eea9279 | ||
|
|
2be504e0d2 | ||
|
|
c84d999456 | ||
|
|
01825ddb93 | ||
|
|
1f88bc2a59 | ||
|
|
ebe2ca7faf | ||
|
|
f4005a139b | ||
|
|
fca8f928a3 | ||
|
|
ace8af077d | ||
|
|
e50cd33277 | ||
|
|
8486775edf | ||
|
|
5887322178 | ||
|
|
3f86937f74 | ||
|
|
2f119d3033 | ||
|
|
5f07f31c9f | ||
|
|
a71aa241ad | ||
|
|
97b201f61f | ||
|
|
a8ef820443 | ||
|
|
7e1a8e5ec6 | ||
|
|
19ee1c9be7 | ||
|
|
fcf0bf79a9 | ||
|
|
0ece664475 | ||
|
|
509af2463d | ||
|
|
5632fef621 | ||
|
|
8ec26e8083 | ||
|
|
617b2edea0 | ||
|
|
55d074f1a5 | ||
|
|
7e6f6af463 | ||
|
|
d00cf6e1ba | ||
|
|
9fdd100f2d | ||
|
|
57d8449660 | ||
|
|
ebd4604f21 | ||
|
|
36a4d79120 | ||
|
|
f3fa63a5ae | ||
|
|
5164375b18 | ||
|
|
fec44452cb | ||
|
|
18ab38a87b | ||
|
|
0f9957bc03 | ||
|
|
80f258c3c5 | ||
|
|
90341e0e00 | ||
|
|
3298374113 | ||
|
|
227c5e155b | ||
|
|
fdbbcf2b8a | ||
|
|
0a07b0d162 | ||
|
|
94165cc18f | ||
|
|
f5ecd51461 | ||
|
|
e9f906ce56 | ||
|
|
4630f07282 | ||
|
|
978acecdcf | ||
|
|
bc1f1d92e5 | ||
|
|
415cd6a360 | ||
|
|
68ce340741 | ||
|
|
bdca9fc1ce | ||
|
|
edb684c72c | ||
|
|
17f7afe12d | ||
|
|
0a182a45ba | ||
|
|
95d62e7f57 | ||
|
|
9ecc91929a | ||
|
|
f79c6aef8d | ||
|
|
c0dff6d4a6 | ||
|
|
59cfc087e1 | ||
|
|
e2f6e50df4 | ||
|
|
c2c64e207f | ||
|
|
8645aeaa4a | ||
|
|
7681e32dca | ||
|
|
b7476a9e7f | ||
|
|
306b8774c2 | ||
|
|
c40ab4147e | ||
|
|
48c101aa7a | ||
|
|
378f0d595f | ||
|
|
f12946d581 | ||
|
|
d13e4d2eef | ||
|
|
ac27e18933 | ||
|
|
e5a6ccc4d4 | ||
|
|
e42cdbe8e0 | ||
|
|
a6ba8dd68f | ||
|
|
7017a1cae5 | ||
|
|
8120278b8c | ||
|
|
73babcbfe3 | ||
|
|
45189d9517 | ||
|
|
7b84558ca1 | ||
|
|
92cfde495e | ||
|
|
14578c2257 | ||
|
|
8f6f81948e | ||
|
|
c6109c7087 | ||
|
|
8ea3855e02 | ||
|
|
74fce9640e | ||
|
|
259aa829d4 | ||
|
|
c4ec50d437 | ||
|
|
b50b7b667d | ||
|
|
fbeb2e23d4 | ||
|
|
4b60c03caa | ||
|
|
a56a28fbb7 | ||
|
|
4051d5b803 | ||
|
|
87242ce6cb | ||
|
|
72d9ffd8b4 | ||
|
|
f606711463 | ||
|
|
d1f69feb4a | ||
|
|
e4ca3bf132 | ||
|
|
7aaf866064 | ||
|
|
484342f26a | ||
|
|
42ada66fdd | ||
|
|
f732ef05d5 | ||
|
|
4fb4fe0931 | ||
|
|
06ffd8ee72 | ||
|
|
90a8070518 | ||
|
|
3e656efb00 | ||
|
|
7c39dd5cba | ||
|
|
21ccfa97dd | ||
|
|
bf0262d7d1 | ||
|
|
42b9700673 | ||
|
|
42bd07d733 | ||
|
|
6f1c54d018 | ||
|
|
1930af91ce | ||
|
|
e088d09e47 | ||
|
|
209fa04752 | ||
|
|
f41c02cbd7 | ||
|
|
4dc75bad05 | ||
|
|
a3d0f7478f | ||
|
|
b9b5003239 | ||
|
|
2e8d6ce7d9 | ||
|
|
a58102d6ef | ||
|
|
65453bd94e | ||
|
|
d22413b931 | ||
|
|
8b9bcc1768 | ||
|
|
51287d545b | ||
|
|
c314a60a16 | ||
|
|
9b2520aa0c | ||
|
|
346b88ae43 | ||
|
|
2766c76491 | ||
|
|
be6529d0a1 | ||
|
|
b1a3ea1aa4 | ||
|
|
6646dcc24d | ||
|
|
966ff91386 | ||
|
|
cd84d08157 | ||
|
|
93c677a6a9 | ||
|
|
177cfd72bf | ||
|
|
34ade50181 | ||
|
|
e65655594f | ||
|
|
514db60617 | ||
|
|
8bc6e75319 | ||
|
|
2f74cfb42c | ||
|
|
1302e3c959 | ||
|
|
a5b031f906 | ||
|
|
f583354748 | ||
|
|
d12e8ec923 | ||
|
|
89f84c9a95 | ||
|
|
6103a22feb | ||
|
|
42264f402d | ||
|
|
abda9bc00a | ||
|
|
eec639d84e | ||
|
|
56b9107c6b | ||
|
|
b35b62d59f | ||
|
|
1b9310e766 | ||
|
|
a62d8381be | ||
|
|
8b32e6c15a | ||
|
|
c8ccb2bac7 | ||
|
|
ef3de1050f | ||
|
|
2add15bd72 | ||
|
|
e6edd9340e | ||
|
|
654a7a5d03 | ||
|
|
dba8ab947f | ||
|
|
787e06e3d8 | ||
|
|
ccd486f2a9 | ||
|
|
22d078b47f | ||
|
|
03490d6597 | ||
|
|
5f46d71af0 | ||
|
|
4f890c431c | ||
|
|
c110a97d8a | ||
|
|
6872eb802c | ||
|
|
662110c269 | ||
|
|
5083188ed8 | ||
|
|
2036438203 | ||
|
|
476c2be5a6 | ||
|
|
ced66f1671 | ||
|
|
fb49371c6b | ||
|
|
fd07aa0f05 | ||
|
|
16518a4f89 | ||
|
|
bed2c29a33 | ||
|
|
e5b6d28bca | ||
|
|
1c9afcb84e | ||
|
|
3a058a6e34 | ||
|
|
aac7d564c8 | ||
|
|
9aa3442a17 | ||
|
|
c68d154f0f | ||
|
|
1b4ed69f41 | ||
|
|
8cef998f49 | ||
|
|
90d1223acd | ||
|
|
1f2506221a | ||
|
|
9f68ca5358 | ||
|
|
1ebb0f8c93 | ||
|
|
8a13a9df80 | ||
|
|
ddf5f2543c | ||
|
|
dbb2fe3e59 | ||
|
|
aa1fac62d5 | ||
|
|
111a313d51 | ||
|
|
0039f893cc | ||
|
|
ad6b26ba97 | ||
|
|
1ef4044419 | ||
|
|
accf2565a0 | ||
|
|
ec965f28c0 | ||
|
|
ebf95f637a | ||
|
|
abbfd42a6c | ||
|
|
db4208a7eb | ||
|
|
da54e1d87c | ||
|
|
e8532ef4de | ||
|
|
fa6d66db49 | ||
|
|
6604e7365f | ||
|
|
fcc1c2968d | ||
|
|
b3d3b14f79 | ||
|
|
8939f310db | ||
|
|
efec752985 | ||
|
|
e94ad78ea7 | ||
|
|
a27a325af7 | ||
|
|
6b06d490c5 | ||
|
|
13f8f39dd5 | ||
|
|
fe05cff64f | ||
|
|
d86837ac07 | ||
|
|
9a7edc6e52 | ||
|
|
ce8c9dd079 | ||
|
|
c8f6b7e0d6 | ||
|
|
f284d31861 | ||
|
|
76b0d2d5d8 | ||
|
|
2cab778f19 | ||
|
|
c31f8eb2e0 | ||
|
|
b618287585 | ||
|
|
63f4b42453 | ||
|
|
c7c0df0964 | ||
|
|
fb87fb5750 | ||
|
|
634b0aaa07 | ||
|
|
5002a89754 | ||
|
|
b367490edc | ||
|
|
e145f21512 | ||
|
|
ea4c50c2c2 | ||
|
|
47ac0d5c3e | ||
|
|
75f225d6dc | ||
|
|
adb7bf7016 | ||
|
|
897bb338f9 | ||
|
|
767699a066 | ||
|
|
7161f22706 | ||
|
|
ddec8097b7 | ||
|
|
95c3cc5c00 | ||
|
|
60c53705ca | ||
|
|
51d8044a54 | ||
|
|
ce697ab0f5 | ||
|
|
ca310966b2 | ||
|
|
25f92ce584 | ||
|
|
2c96af9aea | ||
|
|
04c7e680fd | ||
|
|
9b0ef85f77 | ||
|
|
a8f1160743 | ||
|
|
feca1f0502 | ||
|
|
d0a5a5ef37 | ||
|
|
97f570a4ee | ||
|
|
9ebbf7ce94 | ||
|
|
c2ecbf071f | ||
|
|
b1c489090e | ||
|
|
c9a03c5b01 | ||
|
|
517c578a5f | ||
|
|
14837e34fb | ||
|
|
f10ec3271a | ||
|
|
4e2820d6e3 | ||
|
|
72a0e081ca | ||
|
|
b1130cb1c3 | ||
|
|
59936631ec | ||
|
|
3af22ce754 | ||
|
|
5546b8ff43 | ||
|
|
a07092b7e6 | ||
|
|
ac01c62e6e | ||
|
|
f47f7dd9d2 | ||
|
|
13d970c7ce | ||
|
|
e2409a5fab | ||
|
|
e30aae3399 | ||
|
|
b81f2b52d0 | ||
|
|
9e43e03db4 | ||
|
|
a475cf68bf | ||
|
|
e889bc680b | ||
|
|
c096b20d9c | ||
|
|
11a7ccc37e | ||
|
|
d9b9e6c0b1 | ||
|
|
f18d42f08e | ||
|
|
4986f008b9 | ||
|
|
a8ce199e0d | ||
|
|
c77e8730d6 | ||
|
|
3406846c82 | ||
|
|
bddc6ae66b | ||
|
|
5c343638b6 | ||
|
|
0722960260 | ||
|
|
e959c468f6 | ||
|
|
ba871ec46a | ||
|
|
bd6e3c022f | ||
|
|
a74e04141c | ||
|
|
7c504a10a8 | ||
|
|
ae98745439 | ||
|
|
57259aee00 | ||
|
|
8759fff116 | ||
|
|
dc1a40ea74 | ||
|
|
483d9bf26c | ||
|
|
b24d60e98d | ||
|
|
0f8bd869d8 | ||
|
|
49546cd627 | ||
|
|
6e852d2e65 | ||
|
|
5a4f595341 | ||
|
|
6019d2ee14 | ||
|
|
f937bf3abb | ||
|
|
586e8963a8 | ||
|
|
bdfa76ed9a | ||
|
|
d133f904d3 | ||
|
|
69af9e0dbd | ||
|
|
72c5141dec | ||
|
|
5651d2c43d | ||
|
|
fc236f930b | ||
|
|
570af500f4 | ||
|
|
38913288d8 | ||
|
|
c14d7d9509 | ||
|
|
79f5be4170 | ||
|
|
a3a776d4a6 | ||
|
|
2b9b0f91cb | ||
|
|
424e8f503e | ||
|
|
d206129f3d | ||
|
|
baad7fa9cb | ||
|
|
d54c7b4783 | ||
|
|
67df127c26 | ||
|
|
3946158e88 | ||
|
|
dd251d9e62 | ||
|
|
5c28bcf865 | ||
|
|
7b3b28d3f8 | ||
|
|
20e86bf376 | ||
|
|
f9e087330b | ||
|
|
b0720777be | ||
|
|
8087123f2e | ||
|
|
4c1c315594 | ||
|
|
f95fb640af | ||
|
|
493d8027cd | ||
|
|
06bb55184c | ||
|
|
6b681961e5 | ||
|
|
e1149a27e9 | ||
|
|
f0dd33c1b4 | ||
|
|
5860e1e2ce | ||
|
|
1c7128c2cb | ||
|
|
40200856af | ||
|
|
bb6670d395 | ||
|
|
0d2a268be0 | ||
|
|
16399b63be | ||
|
|
d949b97cc1 | ||
|
|
8b14a701a4 | ||
|
|
0958909cd9 | ||
|
|
b18cee3dc4 | ||
|
|
31272e60b6 | ||
|
|
1b1cb18839 | ||
|
|
fa543bbd4d | ||
|
|
7d7cd32ca7 | ||
|
|
a71c8c60b7 | ||
|
|
9183e7f2fe | ||
|
|
d640411adb | ||
|
|
dc6013fd7e | ||
|
|
80ac66e0a6 | ||
|
|
f05ec4cc26 | ||
|
|
d9ff001ffe | ||
|
|
0f6cb9ed84 | ||
|
|
dde1f27882 | ||
|
|
f5e6f9574d | ||
|
|
ee40adf11a | ||
|
|
3e23f456fe | ||
|
|
b9e2d33ed4 | ||
|
|
19f78dbe6c | ||
|
|
a33dbcb04a | ||
|
|
58f6219cb3 | ||
|
|
18269f2c60 | ||
|
|
06ef95dc5f | ||
|
|
76c7166268 | ||
|
|
6c063f424c | ||
|
|
3345680f7d | ||
|
|
a2fd80954b | ||
|
|
0c524c7c8f | ||
|
|
5f306a11e7 | ||
|
|
ed956a4cf0 | ||
|
|
55a2a6db88 | ||
|
|
f789359886 | ||
|
|
c221a00e1e | ||
|
|
83913af68b | ||
|
|
fa5395a02b | ||
|
|
85dd71507e | ||
|
|
28d6292278 | ||
|
|
b4b84f81a0 | ||
|
|
2345fd4677 | ||
|
|
3250fc732c | ||
|
|
45d52f27ae | ||
|
|
d6b7717985 | ||
|
|
794671ef32 | ||
|
|
70479df5dc | ||
|
|
07761524af | ||
|
|
2ed931aeed | ||
|
|
c76d12d1de |
@@ -26,6 +26,13 @@ DB_DATABASE=database_database
|
|||||||
DB_USERNAME=database_username
|
DB_USERNAME=database_username
|
||||||
DB_PASSWORD=database_user_password
|
DB_PASSWORD=database_user_password
|
||||||
|
|
||||||
|
# Storage system to use
|
||||||
|
# By default files are stored on the local filesystem, with images being placed in
|
||||||
|
# public web space so they can be efficiently served directly by the web-server.
|
||||||
|
# For other options with different security levels & considerations, refer to:
|
||||||
|
# https://www.bookstackapp.com/docs/admin/upload-config/
|
||||||
|
STORAGE_TYPE=local
|
||||||
|
|
||||||
# Mail system to use
|
# Mail system to use
|
||||||
# Can be 'smtp' or 'sendmail'
|
# Can be 'smtp' or 'sendmail'
|
||||||
MAIL_DRIVER=smtp
|
MAIL_DRIVER=smtp
|
||||||
|
|||||||
@@ -36,10 +36,14 @@ APP_LANG=en
|
|||||||
# APP_LANG will be used if such a header is not provided.
|
# APP_LANG will be used if such a header is not provided.
|
||||||
APP_AUTO_LANG_PUBLIC=true
|
APP_AUTO_LANG_PUBLIC=true
|
||||||
|
|
||||||
# Application timezone
|
# Application timezones
|
||||||
# Used where dates are displayed such as on exported content.
|
# The first option is used to determine what timezone is used for date storage.
|
||||||
|
# Leaving that as "UTC" is advised.
|
||||||
|
# The second option is used to set the timezone which will be used for date
|
||||||
|
# formatting and display. This defaults to the "APP_TIMEZONE" value.
|
||||||
# Valid timezone values can be found here: https://www.php.net/manual/en/timezones.php
|
# Valid timezone values can be found here: https://www.php.net/manual/en/timezones.php
|
||||||
APP_TIMEZONE=UTC
|
APP_TIMEZONE=UTC
|
||||||
|
APP_DISPLAY_TIMEZONE=UTC
|
||||||
|
|
||||||
# Application theme
|
# Application theme
|
||||||
# Used to specific a themes/<APP_THEME> folder where BookStack UI
|
# Used to specific a themes/<APP_THEME> folder where BookStack UI
|
||||||
@@ -56,6 +60,7 @@ APP_PROXIES=null
|
|||||||
|
|
||||||
# Database details
|
# Database details
|
||||||
# Host can contain a port (localhost:3306) or a separate DB_PORT option can be used.
|
# Host can contain a port (localhost:3306) or a separate DB_PORT option can be used.
|
||||||
|
# An ipv6 address can be used via the square bracket format ([::1]).
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_DATABASE=database_database
|
DB_DATABASE=database_database
|
||||||
@@ -215,10 +220,11 @@ LDAP_SERVER=false
|
|||||||
LDAP_BASE_DN=false
|
LDAP_BASE_DN=false
|
||||||
LDAP_DN=false
|
LDAP_DN=false
|
||||||
LDAP_PASS=false
|
LDAP_PASS=false
|
||||||
LDAP_USER_FILTER=false
|
LDAP_USER_FILTER="(&(uid={user}))"
|
||||||
LDAP_VERSION=false
|
LDAP_VERSION=false
|
||||||
LDAP_START_TLS=false
|
LDAP_START_TLS=false
|
||||||
LDAP_TLS_INSECURE=false
|
LDAP_TLS_INSECURE=false
|
||||||
|
LDAP_TLS_CA_CERT=false
|
||||||
LDAP_ID_ATTRIBUTE=uid
|
LDAP_ID_ATTRIBUTE=uid
|
||||||
LDAP_EMAIL_ATTRIBUTE=mail
|
LDAP_EMAIL_ATTRIBUTE=mail
|
||||||
LDAP_DISPLAY_NAME_ATTRIBUTE=cn
|
LDAP_DISPLAY_NAME_ATTRIBUTE=cn
|
||||||
@@ -267,6 +273,7 @@ OIDC_ISSUER_DISCOVER=false
|
|||||||
OIDC_PUBLIC_KEY=null
|
OIDC_PUBLIC_KEY=null
|
||||||
OIDC_AUTH_ENDPOINT=null
|
OIDC_AUTH_ENDPOINT=null
|
||||||
OIDC_TOKEN_ENDPOINT=null
|
OIDC_TOKEN_ENDPOINT=null
|
||||||
|
OIDC_USERINFO_ENDPOINT=null
|
||||||
OIDC_ADDITIONAL_SCOPES=null
|
OIDC_ADDITIONAL_SCOPES=null
|
||||||
OIDC_DUMP_USER_DETAILS=false
|
OIDC_DUMP_USER_DETAILS=false
|
||||||
OIDC_USER_TO_GROUPS=false
|
OIDC_USER_TO_GROUPS=false
|
||||||
@@ -324,6 +331,19 @@ FILE_UPLOAD_SIZE_LIMIT=50
|
|||||||
# Can be 'a4' or 'letter'.
|
# Can be 'a4' or 'letter'.
|
||||||
EXPORT_PAGE_SIZE=a4
|
EXPORT_PAGE_SIZE=a4
|
||||||
|
|
||||||
|
# Export PDF Command
|
||||||
|
# Set a command which can be used to convert a HTML file into a PDF file.
|
||||||
|
# When false this will not be used.
|
||||||
|
# String values represent the command to be called for conversion.
|
||||||
|
# Supports '{input_html_path}' and '{output_pdf_path}' placeholder values.
|
||||||
|
# Example: EXPORT_PDF_COMMAND="/scripts/convert.sh {input_html_path} {output_pdf_path}"
|
||||||
|
EXPORT_PDF_COMMAND=false
|
||||||
|
|
||||||
|
# Export PDF Command Timeout
|
||||||
|
# The number of seconds that the export PDF command will run before a timeout occurs.
|
||||||
|
# Only applies for the EXPORT_PDF_COMMAND option, not for DomPDF or wkhtmltopdf.
|
||||||
|
EXPORT_PDF_COMMAND_TIMEOUT=15
|
||||||
|
|
||||||
# Set path to wkhtmltopdf binary for PDF generation.
|
# Set path to wkhtmltopdf binary for PDF generation.
|
||||||
# Can be 'false' or a path path like: '/home/bins/wkhtmltopdf'
|
# Can be 'false' or a path path like: '/home/bins/wkhtmltopdf'
|
||||||
# When false, BookStack will attempt to find a wkhtmltopdf in the application
|
# When false, BookStack will attempt to find a wkhtmltopdf in the application
|
||||||
@@ -331,10 +351,25 @@ EXPORT_PAGE_SIZE=a4
|
|||||||
# Only used if 'ALLOW_UNTRUSTED_SERVER_FETCHING=true' which disables security protections.
|
# Only used if 'ALLOW_UNTRUSTED_SERVER_FETCHING=true' which disables security protections.
|
||||||
WKHTMLTOPDF=false
|
WKHTMLTOPDF=false
|
||||||
|
|
||||||
# Allow <script> tags in page content
|
# Allow JavaScript, and other potentiall dangerous content in page content.
|
||||||
|
# This also removes CSP-level JavaScript control.
|
||||||
# Note, if set to 'true' the page editor may still escape scripts.
|
# Note, if set to 'true' the page editor may still escape scripts.
|
||||||
|
# DEPRECATED: Use 'APP_CONTENT_FILTERING' instead as detailed below. Activiting this option
|
||||||
|
# effectively sets APP_CONTENT_FILTERING='' (No filtering)
|
||||||
ALLOW_CONTENT_SCRIPTS=false
|
ALLOW_CONTENT_SCRIPTS=false
|
||||||
|
|
||||||
|
# Control the behaviour of content filtering, primarily used for page content.
|
||||||
|
# This setting is a string of characters which represent different available filters:
|
||||||
|
# - j - Filter out JavaScript and unknown binary data based content
|
||||||
|
# - h - Filter out unexpected, and potentially dangerous, HTML elements
|
||||||
|
# - f - Filter out unexpected form elements
|
||||||
|
# - a - Run content through a more complex allowlist filter
|
||||||
|
# This defaults to using all filters, unless ALLOW_CONTENT_SCRIPTS is set to true in which case no filters are used.
|
||||||
|
# Note: These filters are a best-attempt and may not be 100% effective. They are typically a layer used in addition to other security measures.
|
||||||
|
# Note: The default value will always be the most-strict, so it's advised to leave this unset in your own configuration
|
||||||
|
# to ensure you are always using the full range of filters.
|
||||||
|
APP_CONTENT_FILTERING="jfha"
|
||||||
|
|
||||||
# Indicate if robots/crawlers should crawl your instance.
|
# Indicate if robots/crawlers should crawl your instance.
|
||||||
# Can be 'true', 'false' or 'null'.
|
# Can be 'true', 'false' or 'null'.
|
||||||
# The behaviour of the default 'null' option will depend on the 'app-public' admin setting.
|
# The behaviour of the default 'null' option will depend on the 'app-public' admin setting.
|
||||||
|
|||||||
2
.forgejo/CODE_OF_CONDUCT.md
Normal file
2
.forgejo/CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Please find our community rules on our website here:
|
||||||
|
https://www.bookstackapp.com/about/community-rules/
|
||||||
4
.forgejo/FUNDING.yml
Normal file
4
.forgejo/FUNDING.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: [ssddanbrown]
|
||||||
|
ko_fi: ssddanbrown
|
||||||
13
.forgejo/ISSUE_TEMPLATE/config.yml
Normal file
13
.forgejo/ISSUE_TEMPLATE/config.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Community Forum Support
|
||||||
|
url: https://community.bookstackapp.com
|
||||||
|
about: Get support by talking with the BookStack team & community.
|
||||||
|
|
||||||
|
- name: Debugging & Common Issues
|
||||||
|
url: https://www.bookstackapp.com/docs/admin/debugging/
|
||||||
|
about: Find details on how to debug issues and view common issues with their resolutions.
|
||||||
|
|
||||||
|
- name: Official Support Plans
|
||||||
|
url: https://www.bookstackapp.com/support/
|
||||||
|
about: View our official support plans that offer assured support for business.
|
||||||
@@ -33,7 +33,7 @@ body:
|
|||||||
attributes:
|
attributes:
|
||||||
label: Have you searched for an existing open/closed issue?
|
label: Have you searched for an existing open/closed issue?
|
||||||
description: |
|
description: |
|
||||||
To help us keep these issues under control, please ensure you have first [searched our issue list](https://github.com/BookStackApp/BookStack/issues?q=is%3Aissue) for any existing issues that cover the fundamental benefit/goal of your request.
|
To help us keep these issues under control, please ensure you have first [searched our issue list](https://codeberg.org/bookstack/bookstack/issues) for any existing issues that cover the fundamental benefit/goal of your request.
|
||||||
options:
|
options:
|
||||||
- label: I have searched for existing issues and none cover my fundamental request
|
- label: I have searched for existing issues and none cover my fundamental request
|
||||||
required: true
|
required: true
|
||||||
@@ -56,3 +56,13 @@ body:
|
|||||||
description: Add any other context or screenshots about the feature request here.
|
description: Add any other context or screenshots about the feature request here.
|
||||||
validations:
|
validations:
|
||||||
required: false
|
required: false
|
||||||
|
- type: checkboxes
|
||||||
|
id: ai-thoughts
|
||||||
|
attributes:
|
||||||
|
label: Have you used generative AI/LLMs to create any thoughts in this request?
|
||||||
|
description: |
|
||||||
|
We ask that no machine generated thoughts or ideas are provided, to avoid us spending time considering the ideas
|
||||||
|
of a machine instead of a human. Further guidance on this can be found [in the BookStack community rules](https://www.bookstackapp.com/about/community-rules/#use-of-llmsai).
|
||||||
|
options:
|
||||||
|
- label: This request only contains the thoughts & ideas of a human
|
||||||
|
required: true
|
||||||
@@ -15,11 +15,11 @@ body:
|
|||||||
- type: checkboxes
|
- type: checkboxes
|
||||||
id: searchissue
|
id: searchissue
|
||||||
attributes:
|
attributes:
|
||||||
label: Searched GitHub Issues
|
label: Searched Existing Issues
|
||||||
description: |
|
description: |
|
||||||
I have searched for the issue and potential resolutions within the [project's GitHub issue list](https://github.com/BookStackApp/BookStack/issues)
|
I have searched for the issue and potential resolutions within the [project's issue list](https://codeberg.org/bookstack/bookstack/issues)
|
||||||
options:
|
options:
|
||||||
- label: I have searched GitHub for the issue.
|
- label: I have searched for the issue.
|
||||||
required: true
|
required: true
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: scenario
|
id: scenario
|
||||||
@@ -42,6 +42,7 @@ body:
|
|||||||
label: Log Content
|
label: Log Content
|
||||||
description: If the issue has produced an error, provide any [BookStack or server log](https://www.bookstackapp.com/docs/admin/debugging/) content below.
|
description: If the issue has produced an error, provide any [BookStack or server log](https://www.bookstackapp.com/docs/admin/debugging/) content below.
|
||||||
placeholder: Be sure to remove any confidential details in your logs
|
placeholder: Be sure to remove any confidential details in your logs
|
||||||
|
render: text
|
||||||
validations:
|
validations:
|
||||||
required: false
|
required: false
|
||||||
- type: textarea
|
- type: textarea
|
||||||
9
.forgejo/ISSUE_TEMPLATE/z_blank_request.yml
Normal file
9
.forgejo/ISSUE_TEMPLATE/z_blank_request.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
name: Blank Request (Maintainers Only)
|
||||||
|
description: For maintainers only - Start a blank request
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: "**This blank request option is only for existing official maintainers of the project!** Please instead use a different request option. If you use this your issue will be closed off."
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Supported Versions
|
## Supported Versions
|
||||||
|
|
||||||
Only the [latest version](https://github.com/BookStackApp/BookStack/releases) of BookStack is supported.
|
Only the [latest version](https://codeberg.org/bookstack/bookstack/releases) of BookStack is supported.
|
||||||
We generally don't support older versions of BookStack due to maintenance effort and
|
We generally don't support older versions of BookStack due to maintenance effort and
|
||||||
since we aim to provide a fairly stable upgrade path for new versions.
|
since we aim to provide a fairly stable upgrade path for new versions.
|
||||||
|
|
||||||
@@ -12,16 +12,14 @@ If you'd like to be notified of new potential security concerns you can [sign-up
|
|||||||
|
|
||||||
## Reporting a Vulnerability
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
If you've found an issue that likely has no impact to existing users (For example, in a development-only branch)
|
If you've found an issue that likely has no impact to existing users (For example, an issue only in the development branch)
|
||||||
feel free to raise it via a standard GitHub bug report issue.
|
feel free to raise it via a standard Codeberg bug report issue.
|
||||||
|
|
||||||
If the issue could have a security impact to BookStack instances,
|
If the issue could have a security impact to BookStack instances,
|
||||||
please directly contact the lead maintainer [@ssddanbrown](https://github.com/ssddanbrown).
|
please directly contact the lead maintainer via email Dan Brown using the [details found here](https://www.bookstackapp.com/links/contact/).
|
||||||
You will need to log in to be able to see the email address on the [GitHub profile page](https://github.com/ssddanbrown).
|
|
||||||
Alternatively you can send a DM via Mastodon to [@danb@fosstodon.org](https://fosstodon.org/@danb).
|
|
||||||
|
|
||||||
Please be patient while the vulnerability is being reviewed. Deploying the fix to address the vulnerability
|
Please be patient while the vulnerability is being reviewed. Deploying the fix to address the vulnerability
|
||||||
can often take a little time due to the amount of preparation required, to ensure the vulnerability has
|
can often take a little time due to the amount of preparation required, to ensure the vulnerability has
|
||||||
been covered, and to create the content required to adequately notify the user-base.
|
been covered, and to create the content required to adequately notify the user-base.
|
||||||
|
|
||||||
Thank you for keeping BookStack instances safe!
|
Thank you for keeping BookStack instances safe!
|
||||||
11
.forgejo/pull_request_template.md
Normal file
11
.forgejo/pull_request_template.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
## Details
|
||||||
|
|
||||||
|
<!-- Write details of your pull request in here -->
|
||||||
|
<!-- Include references to any relevant issues/discussions -->
|
||||||
|
|
||||||
|
## Checklist
|
||||||
|
|
||||||
|
<!-- Put an 'x' in between the brackets below to confirm these elements -->
|
||||||
|
|
||||||
|
- [ ] I have read the [BookStack community rules](https://www.bookstackapp.com/about/community-rules/).
|
||||||
|
- [ ] This PR does not feature significant use of LLM/AI generation as per the community rules above.
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
name: analyse-php
|
name: analyse-php
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '**.php'
|
- '**.php'
|
||||||
@@ -11,14 +12,16 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/library/node:24-trixie
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: https://code.forgejo.org/actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: https://github.com/shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: 8.1
|
php-version: 8.5
|
||||||
extensions: gd, mbstring, json, curl, xml, mysql, ldap
|
extensions: gd, mbstring, json, curl, xml, mysql, ldap
|
||||||
|
|
||||||
- name: Get Composer Cache Directory
|
- name: Get Composer Cache Directory
|
||||||
@@ -27,14 +30,16 @@ jobs:
|
|||||||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Cache composer packages
|
- name: Cache composer packages
|
||||||
uses: actions/cache@v3
|
uses: https://code.forgejo.org/actions/cache@v5
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.composer-cache.outputs.dir }}
|
path: ${{ steps.composer-cache.outputs.dir }}
|
||||||
key: ${{ runner.os }}-composer-8.1
|
key: ${{ runner.os }}-composer-8.5
|
||||||
restore-keys: ${{ runner.os }}-composer-
|
restore-keys: ${{ runner.os }}-composer-
|
||||||
|
|
||||||
- name: Install composer dependencies
|
- name: Install composer dependencies
|
||||||
run: composer install --prefer-dist --no-interaction --ansi
|
run: composer install --prefer-dist --no-interaction --ansi
|
||||||
|
env:
|
||||||
|
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GH_TOKEN }}"}}'
|
||||||
|
|
||||||
- name: Run static analysis check
|
- name: Run static analysis check
|
||||||
run: composer check-static
|
run: composer check-static
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
name: lint-js
|
name: lint-js
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '**.js'
|
- '**.js'
|
||||||
@@ -13,9 +14,11 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/library/node:24-trixie
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: https://code.forgejo.org/actions/checkout@v6
|
||||||
|
|
||||||
- name: Install NPM deps
|
- name: Install NPM deps
|
||||||
run: npm ci
|
run: npm ci
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
name: lint-php
|
name: lint-php
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '**.php'
|
- '**.php'
|
||||||
@@ -11,14 +12,16 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/library/node:24-trixie
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: https://code.forgejo.org/actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: https://github.com/shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: 8.1
|
php-version: 8.5
|
||||||
tools: phpcs
|
tools: phpcs
|
||||||
|
|
||||||
- name: Run formatting check
|
- name: Run formatting check
|
||||||
33
.forgejo/workflows/sync-translations.yml
Normal file
33
.forgejo/workflows/sync-translations.yml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
name: Crowdin Action
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ development ]
|
||||||
|
paths:
|
||||||
|
- 'lang/**.php'
|
||||||
|
schedule:
|
||||||
|
- cron: '30 4 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
synchronize-with-crowdin:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/library/node:24-trixie
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: https://code.forgejo.org/actions/checkout@v6
|
||||||
|
|
||||||
|
- name: crowdin action
|
||||||
|
uses: https://github.com/crowdin/github-action@v2
|
||||||
|
with:
|
||||||
|
upload_sources: true
|
||||||
|
upload_translations: false
|
||||||
|
download_translations: true
|
||||||
|
localization_branch_name: l10n_development
|
||||||
|
create_pull_request: false
|
||||||
|
github_base_url: codeberg.org
|
||||||
|
env:
|
||||||
|
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
|
||||||
|
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
||||||
32
.forgejo/workflows/test-js.yml
Normal file
32
.forgejo/workflows/test-js.yml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
name: test-js
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '**.js'
|
||||||
|
- '**.ts'
|
||||||
|
- '**.json'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '**.js'
|
||||||
|
- '**.ts'
|
||||||
|
- '**.json'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/library/node:24-trixie
|
||||||
|
steps:
|
||||||
|
- uses: https://code.forgejo.org/actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Install NPM deps
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Run TypeScript type checking
|
||||||
|
run: npm run ts:lint
|
||||||
|
|
||||||
|
- name: Run JavaScript tests
|
||||||
|
run: npm run test
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
name: test-migrations
|
name: test-migrations
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '**.php'
|
- '**.php'
|
||||||
@@ -13,15 +14,25 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/library/node:24-trixie
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php: ['8.0', '8.1', '8.2', '8.3']
|
php: ['8.2', '8.3', '8.4', '8.5']
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: docker.io/library/mariadb:12.2.2-noble
|
||||||
|
env:
|
||||||
|
MARIADB_USER: bookstack-test
|
||||||
|
MARIADB_PASSWORD: bookstack-test
|
||||||
|
MARIADB_DATABASE: bookstack-test
|
||||||
|
MARIADB_ROOT_PASSWORD: password
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: https://code.forgejo.org/actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: https://github.com/shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: ${{ matrix.php }}
|
php-version: ${{ matrix.php }}
|
||||||
extensions: gd, mbstring, json, curl, xml, mysql, ldap
|
extensions: gd, mbstring, json, curl, xml, mysql, ldap
|
||||||
@@ -32,34 +43,31 @@ jobs:
|
|||||||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Cache composer packages
|
- name: Cache composer packages
|
||||||
uses: actions/cache@v3
|
uses: https://code.forgejo.org/actions/cache@v5
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.composer-cache.outputs.dir }}
|
path: ${{ steps.composer-cache.outputs.dir }}
|
||||||
key: ${{ runner.os }}-composer-${{ matrix.php }}
|
key: ${{ runner.os }}-composer-${{ matrix.php }}
|
||||||
restore-keys: ${{ runner.os }}-composer-
|
restore-keys: ${{ runner.os }}-composer-
|
||||||
|
|
||||||
- name: Start MySQL
|
|
||||||
run: |
|
|
||||||
sudo systemctl start mysql
|
|
||||||
|
|
||||||
- name: Create database & user
|
|
||||||
run: |
|
|
||||||
mysql -uroot -proot -e 'CREATE DATABASE IF NOT EXISTS `bookstack-test`;'
|
|
||||||
mysql -uroot -proot -e "CREATE USER 'bookstack-test'@'localhost' IDENTIFIED WITH mysql_native_password BY 'bookstack-test';"
|
|
||||||
mysql -uroot -proot -e "GRANT ALL ON \`bookstack-test\`.* TO 'bookstack-test'@'localhost';"
|
|
||||||
mysql -uroot -proot -e 'FLUSH PRIVILEGES;'
|
|
||||||
|
|
||||||
- name: Install composer dependencies
|
- name: Install composer dependencies
|
||||||
run: composer install --prefer-dist --no-interaction --ansi
|
run: composer install --prefer-dist --no-interaction --ansi
|
||||||
|
env:
|
||||||
|
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GH_TOKEN }}"}}'
|
||||||
|
|
||||||
- name: Start migration test
|
- name: Start migration test
|
||||||
|
env:
|
||||||
|
TEST_DATABASE_URL: 'mysql://bookstack-test:bookstack-test@mysql/bookstack-test'
|
||||||
run: |
|
run: |
|
||||||
php${{ matrix.php }} artisan migrate --force -n --database=mysql_testing
|
php${{ matrix.php }} artisan migrate --force -n --database=mysql_testing
|
||||||
|
|
||||||
- name: Start migration:rollback test
|
- name: Start migration:rollback test
|
||||||
|
env:
|
||||||
|
TEST_DATABASE_URL: 'mysql://bookstack-test:bookstack-test@mysql/bookstack-test'
|
||||||
run: |
|
run: |
|
||||||
php${{ matrix.php }} artisan migrate:rollback --force -n --database=mysql_testing
|
php${{ matrix.php }} artisan migrate:rollback --force -n --database=mysql_testing
|
||||||
|
|
||||||
- name: Start migration rerun test
|
- name: Start migration rerun test
|
||||||
|
env:
|
||||||
|
TEST_DATABASE_URL: 'mysql://bookstack-test:bookstack-test@mysql/bookstack-test'
|
||||||
run: |
|
run: |
|
||||||
php${{ matrix.php }} artisan migrate --force -n --database=mysql_testing
|
php${{ matrix.php }} artisan migrate --force -n --database=mysql_testing
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
name: test-php
|
name: test-php
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '**.php'
|
- '**.php'
|
||||||
@@ -13,15 +14,25 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
if: ${{ github.ref != 'refs/heads/l10n_development' }}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/library/node:24-trixie
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php: ['8.0', '8.1', '8.2', '8.3']
|
php: ['8.2', '8.3', '8.4', '8.5']
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: docker.io/library/mariadb:12.2.2-noble
|
||||||
|
env:
|
||||||
|
MARIADB_USER: bookstack-test
|
||||||
|
MARIADB_PASSWORD: bookstack-test
|
||||||
|
MARIADB_DATABASE: bookstack-test
|
||||||
|
MARIADB_ROOT_PASSWORD: password
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: https://code.forgejo.org/actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: https://github.com/shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: ${{ matrix.php }}
|
php-version: ${{ matrix.php }}
|
||||||
extensions: gd, mbstring, json, curl, xml, mysql, ldap, gmp
|
extensions: gd, mbstring, json, curl, xml, mysql, ldap, gmp
|
||||||
@@ -32,30 +43,25 @@ jobs:
|
|||||||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Cache composer packages
|
- name: Cache composer packages
|
||||||
uses: actions/cache@v3
|
uses: https://code.forgejo.org/actions/cache@v5
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.composer-cache.outputs.dir }}
|
path: ${{ steps.composer-cache.outputs.dir }}
|
||||||
key: ${{ runner.os }}-composer-${{ matrix.php }}
|
key: ${{ runner.os }}-composer-${{ matrix.php }}
|
||||||
restore-keys: ${{ runner.os }}-composer-
|
restore-keys: ${{ runner.os }}-composer-
|
||||||
|
|
||||||
- name: Start Database
|
|
||||||
run: |
|
|
||||||
sudo systemctl start mysql
|
|
||||||
|
|
||||||
- name: Setup Database
|
|
||||||
run: |
|
|
||||||
mysql -uroot -proot -e 'CREATE DATABASE IF NOT EXISTS `bookstack-test`;'
|
|
||||||
mysql -uroot -proot -e "CREATE USER 'bookstack-test'@'localhost' IDENTIFIED WITH mysql_native_password BY 'bookstack-test';"
|
|
||||||
mysql -uroot -proot -e "GRANT ALL ON \`bookstack-test\`.* TO 'bookstack-test'@'localhost';"
|
|
||||||
mysql -uroot -proot -e 'FLUSH PRIVILEGES;'
|
|
||||||
|
|
||||||
- name: Install composer dependencies
|
- name: Install composer dependencies
|
||||||
run: composer install --prefer-dist --no-interaction --ansi
|
run: composer install --prefer-dist --no-interaction --ansi
|
||||||
|
env:
|
||||||
|
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GH_TOKEN }}"}}'
|
||||||
|
|
||||||
- name: Migrate and seed the database
|
- name: Migrate and seed the database
|
||||||
|
env:
|
||||||
|
TEST_DATABASE_URL: 'mysql://bookstack-test:bookstack-test@mysql/bookstack-test'
|
||||||
run: |
|
run: |
|
||||||
php${{ matrix.php }} artisan migrate --force -n --database=mysql_testing
|
php${{ matrix.php }} artisan migrate --force -n --database=mysql_testing
|
||||||
php${{ matrix.php }} artisan db:seed --force -n --class=DummyContentSeeder --database=mysql_testing
|
php${{ matrix.php }} artisan db:seed --force -n --class=DummyContentSeeder --database=mysql_testing
|
||||||
|
|
||||||
- name: Run PHP tests
|
- name: Run PHP tests
|
||||||
|
env:
|
||||||
|
TEST_DATABASE_URL: 'mysql://bookstack-test:bookstack-test@mysql/bookstack-test'
|
||||||
run: php${{ matrix.php }} ./vendor/bin/phpunit
|
run: php${{ matrix.php }} ./vendor/bin/phpunit
|
||||||
86
.github/CODE_OF_CONDUCT.md
vendored
86
.github/CODE_OF_CONDUCT.md
vendored
@@ -1,84 +1,2 @@
|
|||||||
# Contributor Covenant Code of Conduct
|
Please find our community rules on our website here:
|
||||||
|
https://www.bookstackapp.com/about/community-rules/
|
||||||
## Our Pledge
|
|
||||||
|
|
||||||
In the interest of fostering an open and welcoming environment, we as
|
|
||||||
contributors and maintainers pledge to making participation in our project and
|
|
||||||
our community a harassment-free experience for everyone, regardless of age, body
|
|
||||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
||||||
education, socio-economic status, nationality, personal appearance, race,
|
|
||||||
religion, or sexual identity and orientation.
|
|
||||||
|
|
||||||
## Our Standards
|
|
||||||
|
|
||||||
Examples of behavior that contributes to creating a positive environment
|
|
||||||
include:
|
|
||||||
|
|
||||||
* Being respectful of differing viewpoints and experiences
|
|
||||||
* Gracefully accepting constructive criticism
|
|
||||||
* Focusing on what is best for the community
|
|
||||||
* Showing empathy towards other community members
|
|
||||||
|
|
||||||
Examples of unacceptable behavior by participants include:
|
|
||||||
|
|
||||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
||||||
advances
|
|
||||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
||||||
* Public or private harassment
|
|
||||||
* Publishing others' private information, such as a physical or electronic
|
|
||||||
address, without explicit permission
|
|
||||||
* Other conduct which could reasonably be considered inappropriate in a
|
|
||||||
professional setting
|
|
||||||
|
|
||||||
### Project Maintainer Standards
|
|
||||||
|
|
||||||
Project maintainers should generally follow these additional standards:
|
|
||||||
|
|
||||||
* Avoid using a negative or harsh tone in communication, Even if the other party
|
|
||||||
is being negative themselves.
|
|
||||||
* When providing criticism, try to make it constructive to lead the other person
|
|
||||||
down the correct path.
|
|
||||||
* Keep the [project definition](https://github.com/BookStackApp/BookStack#project-definition)
|
|
||||||
in mind when deciding what's in scope of the Project.
|
|
||||||
|
|
||||||
## Our Responsibilities
|
|
||||||
|
|
||||||
Project maintainers are responsible for clarifying the standards of acceptable
|
|
||||||
behavior and are expected to take appropriate and fair corrective action in
|
|
||||||
response to any instances of unacceptable behavior. In addition, Project
|
|
||||||
maintainers are responsible for following the standards themselves.
|
|
||||||
|
|
||||||
Project maintainers have the right and responsibility to remove, edit, or
|
|
||||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
||||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
||||||
permanently any contributor for other behaviors that they deem inappropriate,
|
|
||||||
threatening, offensive, or harmful.
|
|
||||||
|
|
||||||
## Scope
|
|
||||||
|
|
||||||
This Code of Conduct applies both within project spaces and in public spaces
|
|
||||||
when an individual is representing the project or its community. Examples of
|
|
||||||
representing a project or community include using an official project e-mail
|
|
||||||
address, posting via an official social media account, or acting as an appointed
|
|
||||||
representative at an online or offline event. Representation of a project may be
|
|
||||||
further defined and clarified by project maintainers.
|
|
||||||
|
|
||||||
## Enforcement
|
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
||||||
reported by contacting the project team at the email address shown on [the profile here](https://github.com/ssddanbrown). All
|
|
||||||
complaints will be reviewed and investigated and will result in a response that
|
|
||||||
is deemed necessary and appropriate to the circumstances. The project team is
|
|
||||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
||||||
Further details of specific enforcement policies may be posted separately.
|
|
||||||
|
|
||||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
||||||
faith may face temporary or permanent repercussions as determined by other
|
|
||||||
members of the project's leadership.
|
|
||||||
|
|
||||||
## Attribution
|
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
||||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
|
||||||
|
|
||||||
[homepage]: https://www.contributor-covenant.org
|
|
||||||
6
.github/ISSUE_TEMPLATE/config.yml
vendored
6
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,8 +1,8 @@
|
|||||||
blank_issues_enabled: false
|
blank_issues_enabled: false
|
||||||
contact_links:
|
contact_links:
|
||||||
- name: Discord Chat Support
|
- name: Open Issues Here Instead
|
||||||
url: https://discord.gg/ztkBqR2
|
url: https://codeberg.org/bookstack/bookstack/issues
|
||||||
about: Realtime support & chat with the BookStack community and the team.
|
about: This project has migrated to Codeberg, please open issues there instead.
|
||||||
|
|
||||||
- name: Debugging & Common Issues
|
- name: Debugging & Common Issues
|
||||||
url: https://www.bookstackapp.com/docs/admin/debugging/
|
url: https://www.bookstackapp.com/docs/admin/debugging/
|
||||||
|
|||||||
10
.github/pull_request_template.md
vendored
Normal file
10
.github/pull_request_template.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
**Warning:**
|
||||||
|
|
||||||
|
This project has migrated to Codeberg:
|
||||||
|
https://codeberg.org/bookstack/bookstack
|
||||||
|
|
||||||
|
Please open pull requests here instead.
|
||||||
|
|
||||||
|
ANY PULL REQUESTS OPENED HERE WILL BE CLOSED WITHOUT COMMENT OR MERGE.
|
||||||
|
|
||||||
|
---
|
||||||
137
.github/translators.txt
vendored
137
.github/translators.txt
vendored
@@ -141,7 +141,7 @@ Kauê Sena (kaue.sena.ks) :: Portuguese, Brazilian
|
|||||||
MatthieuParis :: French
|
MatthieuParis :: French
|
||||||
Douradinho :: Portuguese, Brazilian; Portuguese
|
Douradinho :: Portuguese, Brazilian; Portuguese
|
||||||
Gaku Yaguchi (tama11) :: Japanese
|
Gaku Yaguchi (tama11) :: Japanese
|
||||||
johnroyer :: Chinese Traditional
|
Zero Huang (johnroyer) :: Chinese Traditional
|
||||||
jackaaa :: Chinese Traditional
|
jackaaa :: Chinese Traditional
|
||||||
Irfan Hukama Arsyad (IrfanArsyad) :: Indonesian
|
Irfan Hukama Arsyad (IrfanArsyad) :: Indonesian
|
||||||
Jeff Huang (s8321414) :: Chinese Traditional
|
Jeff Huang (s8321414) :: Chinese Traditional
|
||||||
@@ -177,7 +177,7 @@ Alexander Predl (Harveyhase68) :: German
|
|||||||
Rem (Rem9000) :: Dutch
|
Rem (Rem9000) :: Dutch
|
||||||
Michał Stelmach (stelmach-web) :: Polish
|
Michał Stelmach (stelmach-web) :: Polish
|
||||||
arniom :: French
|
arniom :: French
|
||||||
REMOVED_USER :: French; Dutch; Portuguese, Brazilian; Portuguese; Turkish;
|
REMOVED_USER :: French; German; Dutch; Portuguese, Brazilian; Portuguese; Turkish;
|
||||||
林祖年 (contagion) :: Chinese Traditional
|
林祖年 (contagion) :: Chinese Traditional
|
||||||
Siamak Guodarzi (siamakgoudarzi88) :: Persian
|
Siamak Guodarzi (siamakgoudarzi88) :: Persian
|
||||||
Lis Maestrelo (lismtrl) :: Portuguese, Brazilian
|
Lis Maestrelo (lismtrl) :: Portuguese, Brazilian
|
||||||
@@ -222,7 +222,7 @@ SmokingCrop :: Dutch
|
|||||||
Maciej Lebiest (Szwendacz) :: Polish
|
Maciej Lebiest (Szwendacz) :: Polish
|
||||||
DiscordDigital :: German; German Informal
|
DiscordDigital :: German; German Informal
|
||||||
Gábor Marton (dodver) :: Hungarian
|
Gábor Marton (dodver) :: Hungarian
|
||||||
Jasell :: Swedish
|
Jakob Åsell (Jasell) :: Swedish
|
||||||
Ghost_chu (ghostchu) :: Chinese Simplified
|
Ghost_chu (ghostchu) :: Chinese Simplified
|
||||||
Ravid Shachar (ravidshachar) :: Hebrew
|
Ravid Shachar (ravidshachar) :: Hebrew
|
||||||
Helga Guchshenskaya (guchshenskaya) :: Russian
|
Helga Guchshenskaya (guchshenskaya) :: Russian
|
||||||
@@ -347,7 +347,7 @@ Taygun Yıldırım (yildirimtaygun) :: Turkish
|
|||||||
robing29 :: German
|
robing29 :: German
|
||||||
Bruno Eduardo de Jesus Barroso (brunoejb) :: Portuguese, Brazilian
|
Bruno Eduardo de Jesus Barroso (brunoejb) :: Portuguese, Brazilian
|
||||||
Igor V Belousov (biv) :: Russian
|
Igor V Belousov (biv) :: Russian
|
||||||
David Bauer (davbauer) :: German
|
David Bauer (davbauer) :: German; German Informal
|
||||||
Guttorm Hveem (guttormhveem) :: Norwegian Nynorsk; Norwegian Bokmal
|
Guttorm Hveem (guttormhveem) :: Norwegian Nynorsk; Norwegian Bokmal
|
||||||
Minh Giang Truong (minhgiang1204) :: Vietnamese
|
Minh Giang Truong (minhgiang1204) :: Vietnamese
|
||||||
Ioannis Ioannides (i.ioannides) :: Greek
|
Ioannis Ioannides (i.ioannides) :: Greek
|
||||||
@@ -389,7 +389,7 @@ Marc Hagen (MarcHagen) :: Dutch
|
|||||||
Kasper Alsøe (zeonos) :: Danish
|
Kasper Alsøe (zeonos) :: Danish
|
||||||
sultani :: Persian
|
sultani :: Persian
|
||||||
renge :: Korean
|
renge :: Korean
|
||||||
TheGatesDev (thegatesdev) :: Dutch
|
Tim (thegatesdev) :: Dutch; German Informal; French; Romanian; Catalan; Czech; Danish; German; Finnish; Hungarian; Italian; Japanese; Korean; Polish; Russian; Ukrainian; Chinese Simplified; Chinese Traditional; Portuguese, Brazilian; Persian; Spanish, Argentina; Croatian; Norwegian Nynorsk; Estonian; Uzbek; Norwegian Bokmal
|
||||||
Irdi (irdiOL) :: Albanian
|
Irdi (irdiOL) :: Albanian
|
||||||
KateBarber :: Welsh
|
KateBarber :: Welsh
|
||||||
Twister (theuncles75) :: Hebrew
|
Twister (theuncles75) :: Hebrew
|
||||||
@@ -410,3 +410,130 @@ cracrayol :: French
|
|||||||
CapuaSC :: Dutch
|
CapuaSC :: Dutch
|
||||||
Guardian75 :: German Informal
|
Guardian75 :: German Informal
|
||||||
mr-kanister :: German
|
mr-kanister :: German
|
||||||
|
Michele Bastianelli (makoblaster) :: Italian
|
||||||
|
jespernissen :: Danish
|
||||||
|
Andrey (avmaksimov) :: Russian
|
||||||
|
Gonzalo Loyola (AlFcl) :: Spanish, Argentina; Spanish
|
||||||
|
grobert63 :: French
|
||||||
|
wusst. (Supporti) :: German
|
||||||
|
MaximMaximS :: Czech
|
||||||
|
damian-klima :: Slovak
|
||||||
|
crow_ :: Latvian
|
||||||
|
JocelynDelalande :: French
|
||||||
|
Jan (JW-CH) :: German Informal
|
||||||
|
Timo B (lommes) :: German Informal
|
||||||
|
Erik Lundstedt (Erik.Lundstedt) :: Swedish
|
||||||
|
yngams (younessmouhid) :: Arabic
|
||||||
|
Ohadp :: Hebrew
|
||||||
|
cbridi :: Portuguese, Brazilian
|
||||||
|
nanangsb :: Indonesian
|
||||||
|
Michal Melich (michalmelich) :: Czech
|
||||||
|
David (david-prv) :: German; German Informal
|
||||||
|
Larry (lahoje) :: Swedish
|
||||||
|
Marcia dos Santos (marciab80) :: Portuguese
|
||||||
|
Ricard López Torres (richilpez.torres) :: Catalan
|
||||||
|
sarahalves7 :: Portuguese, Brazilian
|
||||||
|
petr.husak :: Czech
|
||||||
|
javadataherian :: Persian
|
||||||
|
Ludo-code :: French
|
||||||
|
hollsten :: Swedish
|
||||||
|
Ngoc Lan Phung (lanpncz) :: Vietnamese
|
||||||
|
Worive :: Catalan; French
|
||||||
|
Илья Скаба (skabailya) :: Russian
|
||||||
|
Irjan Olsen (Irch) :: Norwegian Bokmal
|
||||||
|
Aleksandar Jovanovic (jovanoviczaleksandar) :: Serbian (Cyrillic)
|
||||||
|
Red (RedVortex) :: Hebrew
|
||||||
|
xgrug :: Chinese Simplified
|
||||||
|
Calle Calmar (HrCalmar) :: Danish
|
||||||
|
Avishay Rapp (AvishayRapp) :: Hebrew
|
||||||
|
matthias4217 :: French
|
||||||
|
Berke BOYLU2 (berkeboylu2) :: Turkish
|
||||||
|
etwas7B :: German
|
||||||
|
Mohammed srhiri (m.sghiri20) :: Arabic
|
||||||
|
YongMin Kim (kym0118) :: Korean
|
||||||
|
Rivo Zängov (Eraser) :: Estonian
|
||||||
|
Francisco Rafael Fonseca (chicoraf) :: Portuguese, Brazilian
|
||||||
|
ИEØ_ΙΙØZ (NEO_IIOZ) :: Chinese Traditional
|
||||||
|
madnjpn (madnjpn.) :: Georgian
|
||||||
|
Ásgeir Shiny Ásgeirsson (AsgeirShiny) :: Icelandic
|
||||||
|
Mohammad Aftab Uddin (chirohorit) :: Bengali
|
||||||
|
Yannis Karlaftis (meliseus) :: Greek
|
||||||
|
felixxx :: German Informal
|
||||||
|
randi (randi65535) :: Korean
|
||||||
|
test65428 :: Greek
|
||||||
|
zeronell :: Chinese Simplified
|
||||||
|
julien Vinber (julienVinber) :: French
|
||||||
|
Hyunwoo Park (oksure) :: Korean
|
||||||
|
aram.rafeq.7 (aramrafeq2) :: Kurdish
|
||||||
|
Raphael Moreno (RaphaelMoreno) :: Portuguese, Brazilian
|
||||||
|
yn (user99) :: Arabic
|
||||||
|
Pavel Zlatarov (pzlatarov) :: Bulgarian
|
||||||
|
ingelres :: French
|
||||||
|
mabdullah :: Arabic
|
||||||
|
Skrabák Csaba (kekcsi) :: Hungarian
|
||||||
|
Evert Meulie (Evert) :: Norwegian Bokmal
|
||||||
|
Jasper Backer (jasperb) :: Dutch
|
||||||
|
Alexandar Cavdarovski (ace.200112) :: Swedish
|
||||||
|
구닥다리TV (yjj8353) :: Korean
|
||||||
|
Onur Oskay (o.oskay) :: Turkish
|
||||||
|
Sébastien Merveille (SebastienMerv) :: French
|
||||||
|
Maxim Kouznetsov (masya.work) :: Hebrew
|
||||||
|
neodvisnost :: Slovenian
|
||||||
|
Soubi Agatsuma (bisouya) :: Hebrew
|
||||||
|
Ilya Shaulov (ishaulov) :: Russian
|
||||||
|
Konstantin Bobkov (b.konstantv) :: Russian
|
||||||
|
Ruben Sutter (rubensutter) :: German
|
||||||
|
jellium :: French
|
||||||
|
Qxlkdr :: Swedish
|
||||||
|
Hari (muhhari) :: Indonesian
|
||||||
|
仙君御 (xjy) :: Chinese Simplified
|
||||||
|
TapioM :: Finnish
|
||||||
|
lingb58 :: Chinese Traditional
|
||||||
|
Angel Pandey (angel-pandey) :: Nepali
|
||||||
|
Supriya Shrestha (supriyashrestha) :: Nepali
|
||||||
|
gprabhat :: Nepali
|
||||||
|
CellCat :: Chinese Simplified
|
||||||
|
Al Desrahim (aldesrahim) :: Indonesian
|
||||||
|
ahmad abbaspour (deshneh.dar.diss) :: Persian
|
||||||
|
Erjon K. (ekr) :: Albanian
|
||||||
|
LiZerui (iamzrli) :: Chinese Traditional
|
||||||
|
Ticker (ticker.com) :: Hebrew
|
||||||
|
CrazyComputer :: Chinese Simplified
|
||||||
|
Firr (FirrV) :: Russian
|
||||||
|
João Faro (FaroJoaoFaro) :: Portuguese
|
||||||
|
Danilo dos Santos Barbosa (bozochegou) :: Portuguese, Brazilian
|
||||||
|
Chris (furesoft) :: German
|
||||||
|
Silvia Isern (eiendragon) :: Catalan
|
||||||
|
Dennis Kron Pedersen (ahjdp) :: Danish
|
||||||
|
iamwhoiamwhoami :: Swedish
|
||||||
|
Grogui :: French
|
||||||
|
MrCharlesIII :: Arabic
|
||||||
|
David Olsen (dawin) :: Danish
|
||||||
|
ltnzr :: French
|
||||||
|
Frank Holler (holler.frank) :: German; German Informal
|
||||||
|
Korab Arifi (korabidev) :: Albanian
|
||||||
|
Petr Husák (petrhusak) :: Czech
|
||||||
|
Bernardo Maia (bernardo.bmaia2) :: Portuguese, Brazilian
|
||||||
|
Amr (amr3k) :: Arabic
|
||||||
|
Tahsin Ahmed (tahsinahmed2012) :: Bengali
|
||||||
|
bojan_che :: Serbian (Cyrillic)
|
||||||
|
setiawan setiawan (culture.setiawan) :: Indonesian
|
||||||
|
Donald Mac Kenzie (kiuman) :: Norwegian Bokmal
|
||||||
|
Gabriel Silver (GabrielBSilver) :: Hebrew
|
||||||
|
Tomas Darius Davainis (Tomasdd) :: Lithuanian
|
||||||
|
CriedHero :: Chinese Simplified
|
||||||
|
Henrik (henrik2105) :: Norwegian Bokmal
|
||||||
|
FoW (fofwisdom) :: Korean
|
||||||
|
serinf-lauza :: French
|
||||||
|
Diyan Nikolaev (nikolaev.diyan) :: Bulgarian
|
||||||
|
Shadluk Avan (quldosh) :: Uzbek
|
||||||
|
Marci (MartonPoto) :: Hungarian
|
||||||
|
Michał Sadurski (wheeskeey) :: Polish
|
||||||
|
JanDziaslo :: Polish
|
||||||
|
Charllys Fernandes (CharllysFernandes) :: Portuguese, Brazilian
|
||||||
|
Ilgiz Zigangirov (inov8) :: Russian
|
||||||
|
Max Israelsson (Blezie) :: Swedish
|
||||||
|
Skiddybison5924 (chris-devel0per) :: German
|
||||||
|
Veyilla Nightwhisper (Veyilla) :: German
|
||||||
|
João Barbosa (hypeedd) :: Portuguese
|
||||||
|
Abcdefg Hijklmn (collatek) :: Korean
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,6 +2,8 @@
|
|||||||
/node_modules
|
/node_modules
|
||||||
/.vscode
|
/.vscode
|
||||||
/composer
|
/composer
|
||||||
|
/composer.phar
|
||||||
|
/coverage
|
||||||
Homestead.yaml
|
Homestead.yaml
|
||||||
.env
|
.env
|
||||||
.idea
|
.idea
|
||||||
@@ -31,3 +33,4 @@ webpack-stats.json
|
|||||||
phpstan.neon
|
phpstan.neon
|
||||||
esbuild-meta.json
|
esbuild-meta.json
|
||||||
.phpactor.json
|
.phpactor.json
|
||||||
|
/*.zip
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015-2023, Dan Brown and the BookStack Project contributors.
|
Copyright (c) 2015-2026, Dan Brown and the BookStack project contributors.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -32,13 +32,17 @@ class ConfirmEmailController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a notice that a user's email address has not been confirmed,
|
* Shows a notice that a user's email address has not been confirmed,
|
||||||
* Also has the option to re-send the confirmation email.
|
* along with the option to re-send the confirmation email.
|
||||||
*/
|
*/
|
||||||
public function showAwaiting()
|
public function showAwaiting()
|
||||||
{
|
{
|
||||||
$user = $this->loginService->getLastLoginAttemptUser();
|
$user = $this->loginService->getLastLoginAttemptUser();
|
||||||
|
if ($user === null) {
|
||||||
|
$this->showErrorNotification(trans('errors.login_user_not_found'));
|
||||||
|
return redirect('/login');
|
||||||
|
}
|
||||||
|
|
||||||
return view('auth.user-unconfirmed', ['user' => $user]);
|
return view('auth.register-confirm-awaiting');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,19 +94,24 @@ class ConfirmEmailController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Resend the confirmation email.
|
* Resend the confirmation email.
|
||||||
*/
|
*/
|
||||||
public function resend(Request $request)
|
public function resend()
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$user = $this->loginService->getLastLoginAttemptUser();
|
||||||
'email' => ['required', 'email', 'exists:users,email'],
|
if ($user === null) {
|
||||||
]);
|
$this->showErrorNotification(trans('errors.login_user_not_found'));
|
||||||
$user = $this->userRepo->getByEmail($request->get('email'));
|
return redirect('/login');
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->emailConfirmationService->sendConfirmation($user);
|
$this->emailConfirmationService->sendConfirmation($user);
|
||||||
|
} catch (ConfirmationEmailException $e) {
|
||||||
|
$this->showErrorNotification($e->getMessage());
|
||||||
|
|
||||||
|
return redirect('/login');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->showErrorNotification(trans('auth.email_confirm_send_error'));
|
$this->showErrorNotification(trans('auth.email_confirm_send_error'));
|
||||||
|
|
||||||
return redirect('/register/confirm');
|
return redirect('/register/awaiting');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->showSuccessNotification(trans('auth.email_confirm_resent'));
|
$this->showSuccessNotification(trans('auth.email_confirm_resent'));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use BookStack\Activity\ActivityType;
|
|||||||
use BookStack\Http\Controller;
|
use BookStack\Http\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Password;
|
use Illuminate\Support\Facades\Password;
|
||||||
|
use Illuminate\Support\Sleep;
|
||||||
|
|
||||||
class ForgotPasswordController extends Controller
|
class ForgotPasswordController extends Controller
|
||||||
{
|
{
|
||||||
@@ -32,6 +33,10 @@ class ForgotPasswordController extends Controller
|
|||||||
'email' => ['required', 'email'],
|
'email' => ['required', 'email'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Add random pause to the response to help avoid time-base sniffing
|
||||||
|
// of valid resets via slower email send handling.
|
||||||
|
Sleep::for(random_int(1000, 3000))->milliseconds();
|
||||||
|
|
||||||
// We will send the password reset link to this user. Once we have attempted
|
// We will send the password reset link to this user. Once we have attempted
|
||||||
// to send the link, we will examine the response then see the message we
|
// to send the link, we will examine the response then see the message we
|
||||||
// need to show to the user. Finally, we'll send out a proper response.
|
// need to show to the user. Finally, we'll send out a proper response.
|
||||||
@@ -40,11 +45,11 @@ class ForgotPasswordController extends Controller
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($response === Password::RESET_LINK_SENT) {
|
if ($response === Password::RESET_LINK_SENT) {
|
||||||
$this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
|
$this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->input('email'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($response, [Password::RESET_LINK_SENT, Password::INVALID_USER, Password::RESET_THROTTLED])) {
|
if (in_array($response, [Password::RESET_LINK_SENT, Password::INVALID_USER, Password::RESET_THROTTLED])) {
|
||||||
$message = trans('auth.reset_password_sent', ['email' => $request->get('email')]);
|
$message = trans('auth.reset_password_sent', ['email' => $request->input('email')]);
|
||||||
$this->showSuccessNotification($message);
|
$this->showSuccessNotification($message);
|
||||||
|
|
||||||
return redirect('/password/email')->with('status', trans($response));
|
return redirect('/password/email')->with('status', trans($response));
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ trait HandlesPartialLogins
|
|||||||
$user = auth()->user() ?? $loginService->getLastLoginAttemptUser();
|
$user = auth()->user() ?? $loginService->getLastLoginAttemptUser();
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
throw new NotFoundException('A user for this action could not be found');
|
throw new NotFoundException(trans('errors.login_user_not_found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
|
|||||||
@@ -32,12 +32,12 @@ class LoginController extends Controller
|
|||||||
{
|
{
|
||||||
$socialDrivers = $this->socialDriverManager->getActive();
|
$socialDrivers = $this->socialDriverManager->getActive();
|
||||||
$authMethod = config('auth.method');
|
$authMethod = config('auth.method');
|
||||||
$preventInitiation = $request->get('prevent_auto_init') === 'true';
|
$preventInitiation = $request->input('prevent_auto_init') === 'true';
|
||||||
|
|
||||||
if ($request->has('email')) {
|
if ($request->has('email')) {
|
||||||
session()->flashInput([
|
session()->flashInput([
|
||||||
'email' => $request->get('email'),
|
'email' => $request->input('email'),
|
||||||
'password' => (config('app.env') === 'demo') ? $request->get('password', '') : '',
|
'password' => (config('app.env') === 'demo') ? $request->input('password', '') : '',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ class LoginController extends Controller
|
|||||||
public function login(Request $request)
|
public function login(Request $request)
|
||||||
{
|
{
|
||||||
$this->validateLogin($request);
|
$this->validateLogin($request);
|
||||||
$username = $request->get($this->username());
|
$username = $request->input($this->username());
|
||||||
|
|
||||||
// Check login throttling attempts to see if they've gone over the limit
|
// Check login throttling attempts to see if they've gone over the limit
|
||||||
if ($this->hasTooManyLoginAttempts($request)) {
|
if ($this->hasTooManyLoginAttempts($request)) {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class MfaBackupCodesController extends Controller
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$updatedCodes = $codeService->removeInputCodeFromSet($request->get('code'), $codes);
|
$updatedCodes = $codeService->removeInputCodeFromSet($request->input('code'), $codes);
|
||||||
MfaValue::upsertWithValue($user, MfaValue::METHOD_BACKUP_CODES, $updatedCodes);
|
MfaValue::upsertWithValue($user, MfaValue::METHOD_BACKUP_CODES, $updatedCodes);
|
||||||
|
|
||||||
$mfaSession->markVerifiedForUser($user);
|
$mfaSession->markVerifiedForUser($user);
|
||||||
|
|||||||
@@ -51,14 +51,14 @@ class MfaController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function verify(Request $request)
|
public function verify(Request $request)
|
||||||
{
|
{
|
||||||
$desiredMethod = $request->get('method');
|
$desiredMethod = $request->input('method');
|
||||||
$userMethods = $this->currentOrLastAttemptedUser()
|
$userMethods = $this->currentOrLastAttemptedUser()
|
||||||
->mfaValues()
|
->mfaValues()
|
||||||
->get(['id', 'method'])
|
->get(['id', 'method'])
|
||||||
->groupBy('method');
|
->groupBy('method');
|
||||||
|
|
||||||
// Basic search for the default option for a user.
|
// Basic search for the default option for a user.
|
||||||
// (Prioritises totp over backup codes)
|
// (Prioritises TOTP over backup codes)
|
||||||
$method = $userMethods->has($desiredMethod) ? $desiredMethod : $userMethods->keys()->sort()->reverse()->first();
|
$method = $userMethods->has($desiredMethod) ? $desiredMethod : $userMethods->keys()->sort()->reverse()->first();
|
||||||
$otherMethods = $userMethods->keys()->filter(function ($userMethod) use ($method) {
|
$otherMethods = $userMethods->keys()->filter(function ($userMethod) use ($method) {
|
||||||
return $method !== $userMethod;
|
return $method !== $userMethod;
|
||||||
|
|||||||
@@ -19,20 +19,25 @@ class MfaTotpController extends Controller
|
|||||||
|
|
||||||
protected const SETUP_SECRET_SESSION_KEY = 'mfa-setup-totp-secret';
|
protected const SETUP_SECRET_SESSION_KEY = 'mfa-setup-totp-secret';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected TotpService $totp
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a view that generates and displays a TOTP QR code.
|
* Show a view that generates and displays a TOTP QR code.
|
||||||
*/
|
*/
|
||||||
public function generate(TotpService $totp)
|
public function generate()
|
||||||
{
|
{
|
||||||
if (session()->has(static::SETUP_SECRET_SESSION_KEY)) {
|
if (session()->has(static::SETUP_SECRET_SESSION_KEY)) {
|
||||||
$totpSecret = decrypt(session()->get(static::SETUP_SECRET_SESSION_KEY));
|
$totpSecret = decrypt(session()->get(static::SETUP_SECRET_SESSION_KEY));
|
||||||
} else {
|
} else {
|
||||||
$totpSecret = $totp->generateSecret();
|
$totpSecret = $this->totp->generateSecret();
|
||||||
session()->put(static::SETUP_SECRET_SESSION_KEY, encrypt($totpSecret));
|
session()->put(static::SETUP_SECRET_SESSION_KEY, encrypt($totpSecret));
|
||||||
}
|
}
|
||||||
|
|
||||||
$qrCodeUrl = $totp->generateUrl($totpSecret, $this->currentOrLastAttemptedUser());
|
$qrCodeUrl = $this->totp->generateUrl($totpSecret, $this->currentOrLastAttemptedUser());
|
||||||
$svg = $totp->generateQrCodeSvg($qrCodeUrl);
|
$svg = $this->totp->generateQrCodeSvg($qrCodeUrl);
|
||||||
|
|
||||||
$this->setPageTitle(trans('auth.mfa_gen_totp_title'));
|
$this->setPageTitle(trans('auth.mfa_gen_totp_title'));
|
||||||
|
|
||||||
@@ -56,7 +61,7 @@ class MfaTotpController extends Controller
|
|||||||
'code' => [
|
'code' => [
|
||||||
'required',
|
'required',
|
||||||
'max:12', 'min:4',
|
'max:12', 'min:4',
|
||||||
new TotpValidationRule($totpSecret),
|
new TotpValidationRule($totpSecret, $this->totp),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -87,7 +92,7 @@ class MfaTotpController extends Controller
|
|||||||
'code' => [
|
'code' => [
|
||||||
'required',
|
'required',
|
||||||
'max:12', 'min:4',
|
'max:12', 'min:4',
|
||||||
new TotpValidationRule($totpSecret),
|
new TotpValidationRule($totpSecret, $this->totp),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,9 @@ use Illuminate\Http\Request;
|
|||||||
|
|
||||||
class OidcController extends Controller
|
class OidcController extends Controller
|
||||||
{
|
{
|
||||||
protected OidcService $oidcService;
|
public function __construct(
|
||||||
|
protected OidcService $oidcService
|
||||||
public function __construct(OidcService $oidcService)
|
) {
|
||||||
{
|
|
||||||
$this->oidcService = $oidcService;
|
|
||||||
$this->middleware('guard:oidc');
|
$this->middleware('guard:oidc');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +28,7 @@ class OidcController extends Controller
|
|||||||
return redirect('/login');
|
return redirect('/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
session()->flash('oidc_state', $loginDetails['state']);
|
session()->put('oidc_state', time() . ':' . $loginDetails['state']);
|
||||||
|
|
||||||
return redirect($loginDetails['url']);
|
return redirect($loginDetails['url']);
|
||||||
}
|
}
|
||||||
@@ -41,10 +39,16 @@ class OidcController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function callback(Request $request)
|
public function callback(Request $request)
|
||||||
{
|
{
|
||||||
$storedState = session()->pull('oidc_state');
|
|
||||||
$responseState = $request->query('state');
|
$responseState = $request->query('state');
|
||||||
|
$splitState = explode(':', session()->pull('oidc_state', ':'), 2);
|
||||||
|
if (count($splitState) !== 2) {
|
||||||
|
$splitState = [null, null];
|
||||||
|
}
|
||||||
|
|
||||||
if ($storedState !== $responseState) {
|
[$storedStateTime, $storedState] = $splitState;
|
||||||
|
$threeMinutesAgo = time() - 3 * 60;
|
||||||
|
|
||||||
|
if (!$storedState || $storedState !== $responseState || intval($storedStateTime) < $threeMinutesAgo) {
|
||||||
$this->showErrorNotification(trans('errors.oidc_fail_authed', ['system' => config('oidc.name')]));
|
$this->showErrorNotification(trans('errors.oidc_fail_authed', ['system' => config('oidc.name')]));
|
||||||
|
|
||||||
return redirect('/login');
|
return redirect('/login');
|
||||||
@@ -62,7 +66,7 @@ class OidcController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log the user out then start the OIDC RP-initiated logout process.
|
* Log the user out, then start the OIDC RP-initiated logout process.
|
||||||
*/
|
*/
|
||||||
public function logout()
|
public function logout()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,24 +15,13 @@ use Illuminate\Validation\Rules\Password;
|
|||||||
|
|
||||||
class RegisterController extends Controller
|
class RegisterController extends Controller
|
||||||
{
|
{
|
||||||
protected SocialDriverManager $socialDriverManager;
|
|
||||||
protected RegistrationService $registrationService;
|
|
||||||
protected LoginService $loginService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new controller instance.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
SocialDriverManager $socialDriverManager,
|
protected SocialDriverManager $socialDriverManager,
|
||||||
RegistrationService $registrationService,
|
protected RegistrationService $registrationService,
|
||||||
LoginService $loginService
|
protected LoginService $loginService
|
||||||
) {
|
) {
|
||||||
$this->middleware('guest');
|
$this->middleware('guest');
|
||||||
$this->middleware('guard:standard');
|
$this->middleware('guard:standard');
|
||||||
|
|
||||||
$this->socialDriverManager = $socialDriverManager;
|
|
||||||
$this->registrationService = $registrationService;
|
|
||||||
$this->loginService = $loginService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,8 +48,7 @@ class RegisterController extends Controller
|
|||||||
public function postRegister(Request $request)
|
public function postRegister(Request $request)
|
||||||
{
|
{
|
||||||
$this->registrationService->ensureRegistrationAllowed();
|
$this->registrationService->ensureRegistrationAllowed();
|
||||||
$this->validator($request->all())->validate();
|
$userData = $this->validator($request->all())->validate();
|
||||||
$userData = $request->all();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$user = $this->registrationService->registerUser($userData);
|
$user = $this->registrationService->registerUser($userData);
|
||||||
@@ -87,6 +75,8 @@ class RegisterController extends Controller
|
|||||||
'name' => ['required', 'min:2', 'max:100'],
|
'name' => ['required', 'min:2', 'max:100'],
|
||||||
'email' => ['required', 'email', 'max:255', 'unique:users'],
|
'email' => ['required', 'email', 'max:255', 'unique:users'],
|
||||||
'password' => ['required', Password::default()],
|
'password' => ['required', Password::default()],
|
||||||
|
// Basic honey for bots that must not be filled in
|
||||||
|
'username' => ['prohibited'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,11 @@ use Illuminate\Validation\Rules\Password as PasswordRule;
|
|||||||
|
|
||||||
class ResetPasswordController extends Controller
|
class ResetPasswordController extends Controller
|
||||||
{
|
{
|
||||||
protected LoginService $loginService;
|
public function __construct(
|
||||||
|
protected LoginService $loginService
|
||||||
public function __construct(LoginService $loginService)
|
) {
|
||||||
{
|
|
||||||
$this->middleware('guest');
|
$this->middleware('guest');
|
||||||
$this->middleware('guard:standard');
|
$this->middleware('guard:standard');
|
||||||
|
|
||||||
$this->loginService = $loginService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +48,7 @@ class ResetPasswordController extends Controller
|
|||||||
|
|
||||||
// Here we will attempt to reset the user's password. If it is successful we
|
// Here we will attempt to reset the user's password. If it is successful we
|
||||||
// will update the password on an actual user model and persist it to the
|
// will update the password on an actual user model and persist it to the
|
||||||
// database. Otherwise we will parse the error and return the response.
|
// database. Otherwise, we will parse the error and return the response.
|
||||||
$credentials = $request->only('email', 'password', 'password_confirmation', 'token');
|
$credentials = $request->only('email', 'password', 'password_confirmation', 'token');
|
||||||
$response = Password::broker()->reset($credentials, function (User $user, string $password) {
|
$response = Password::broker()->reset($credentials, function (User $user, string $password) {
|
||||||
$user->password = Hash::make($password);
|
$user->password = Hash::make($password);
|
||||||
@@ -66,7 +63,7 @@ class ResetPasswordController extends Controller
|
|||||||
// redirect them back to where they came from with their error message.
|
// redirect them back to where they came from with their error message.
|
||||||
return $response === Password::PASSWORD_RESET
|
return $response === Password::PASSWORD_RESET
|
||||||
? $this->sendResetResponse()
|
? $this->sendResetResponse()
|
||||||
: $this->sendResetFailedResponse($request, $response, $request->get('token'));
|
: $this->sendResetFailedResponse($request, $response, $request->input('token'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class Saml2Controller extends Controller
|
|||||||
*/
|
*/
|
||||||
public function startAcs(Request $request)
|
public function startAcs(Request $request)
|
||||||
{
|
{
|
||||||
$samlResponse = $request->get('SAMLResponse', null);
|
$samlResponse = $request->input('SAMLResponse', null);
|
||||||
|
|
||||||
if (empty($samlResponse)) {
|
if (empty($samlResponse)) {
|
||||||
$this->showErrorNotification(trans('errors.saml_fail_authed', ['system' => config('saml2.name')]));
|
$this->showErrorNotification(trans('errors.saml_fail_authed', ['system' => config('saml2.name')]));
|
||||||
@@ -100,7 +100,7 @@ class Saml2Controller extends Controller
|
|||||||
*/
|
*/
|
||||||
public function processAcs(Request $request)
|
public function processAcs(Request $request)
|
||||||
{
|
{
|
||||||
$acsId = $request->get('id', null);
|
$acsId = $request->input('id', null);
|
||||||
$cacheKey = 'saml2_acs:' . $acsId;
|
$cacheKey = 'saml2_acs:' . $acsId;
|
||||||
$samlResponse = null;
|
$samlResponse = null;
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class SocialController extends Controller
|
|||||||
if ($request->has('error') && $request->has('error_description')) {
|
if ($request->has('error') && $request->has('error_description')) {
|
||||||
throw new SocialSignInException(trans('errors.social_login_bad_response', [
|
throw new SocialSignInException(trans('errors.social_login_bad_response', [
|
||||||
'socialAccount' => $socialDriver,
|
'socialAccount' => $socialDriver,
|
||||||
'error' => $request->get('error_description'),
|
'error' => $request->input('error_description'),
|
||||||
]), '/login');
|
]), '/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class UserInviteController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->userRepo->getById($userId);
|
$user = $this->userRepo->getById($userId);
|
||||||
$user->password = Hash::make($request->get('password'));
|
$user->password = Hash::make($request->input('password'));
|
||||||
$user->email_confirmed = true;
|
$user->email_confirmed = true;
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace BookStack\Access;
|
|||||||
use BookStack\Access\Notifications\ConfirmEmailNotification;
|
use BookStack\Access\Notifications\ConfirmEmailNotification;
|
||||||
use BookStack\Exceptions\ConfirmationEmailException;
|
use BookStack\Exceptions\ConfirmationEmailException;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class EmailConfirmationService extends UserTokenService
|
class EmailConfirmationService extends UserTokenService
|
||||||
{
|
{
|
||||||
@@ -16,8 +17,9 @@ class EmailConfirmationService extends UserTokenService
|
|||||||
* Also removes any existing old ones.
|
* Also removes any existing old ones.
|
||||||
*
|
*
|
||||||
* @throws ConfirmationEmailException
|
* @throws ConfirmationEmailException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendConfirmation(User $user)
|
public function sendConfirmation(User $user): void
|
||||||
{
|
{
|
||||||
if ($user->email_confirmed) {
|
if ($user->email_confirmed) {
|
||||||
throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
|
throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
|
||||||
|
|||||||
@@ -2,60 +2,26 @@
|
|||||||
|
|
||||||
namespace BookStack\Access;
|
namespace BookStack\Access;
|
||||||
|
|
||||||
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Contracts\Auth\Authenticatable;
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
use Illuminate\Contracts\Auth\UserProvider;
|
use Illuminate\Contracts\Auth\UserProvider;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class ExternalBaseUserProvider implements UserProvider
|
class ExternalBaseUserProvider implements UserProvider
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The user model.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LdapUserProvider constructor.
|
|
||||||
*/
|
|
||||||
public function __construct(string $model)
|
|
||||||
{
|
|
||||||
$this->model = $model;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new instance of the model.
|
|
||||||
*
|
|
||||||
* @return Model
|
|
||||||
*/
|
|
||||||
public function createModel()
|
|
||||||
{
|
|
||||||
$class = '\\' . ltrim($this->model, '\\');
|
|
||||||
|
|
||||||
return new $class();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a user by their unique identifier.
|
* Retrieve a user by their unique identifier.
|
||||||
*
|
|
||||||
* @param mixed $identifier
|
|
||||||
*
|
|
||||||
* @return Authenticatable|null
|
|
||||||
*/
|
*/
|
||||||
public function retrieveById($identifier)
|
public function retrieveById(mixed $identifier): ?Authenticatable
|
||||||
{
|
{
|
||||||
return $this->createModel()->newQuery()->find($identifier);
|
return User::query()->find($identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a user by their unique identifier and "remember me" token.
|
* Retrieve a user by their unique identifier and "remember me" token.
|
||||||
*
|
*
|
||||||
* @param mixed $identifier
|
|
||||||
* @param string $token
|
* @param string $token
|
||||||
*
|
|
||||||
* @return Authenticatable|null
|
|
||||||
*/
|
*/
|
||||||
public function retrieveByToken($identifier, $token)
|
public function retrieveByToken(mixed $identifier, $token): null
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -75,32 +41,25 @@ class ExternalBaseUserProvider implements UserProvider
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a user by the given credentials.
|
* Retrieve a user by the given credentials.
|
||||||
*
|
|
||||||
* @param array $credentials
|
|
||||||
*
|
|
||||||
* @return Authenticatable|null
|
|
||||||
*/
|
*/
|
||||||
public function retrieveByCredentials(array $credentials)
|
public function retrieveByCredentials(array $credentials): ?Authenticatable
|
||||||
{
|
{
|
||||||
// Search current user base by looking up a uid
|
return User::query()
|
||||||
$model = $this->createModel();
|
|
||||||
|
|
||||||
return $model->newQuery()
|
|
||||||
->where('external_auth_id', $credentials['external_auth_id'])
|
->where('external_auth_id', $credentials['external_auth_id'])
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a user against the given credentials.
|
* Validate a user against the given credentials.
|
||||||
*
|
|
||||||
* @param Authenticatable $user
|
|
||||||
* @param array $credentials
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function validateCredentials(Authenticatable $user, array $credentials)
|
public function validateCredentials(Authenticatable $user, array $credentials): bool
|
||||||
{
|
{
|
||||||
// Should be done in the guard.
|
// Should be done in the guard.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false)
|
||||||
|
{
|
||||||
|
// No action to perform, any passwords are external in the auth system
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,23 +3,18 @@
|
|||||||
namespace BookStack\Access\Guards;
|
namespace BookStack\Access\Guards;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saml2 Session Guard.
|
* External Auth Session Guard.
|
||||||
*
|
*
|
||||||
* The saml2 login process is async in nature meaning it does not fit very well
|
* The login process for external auth (SAML2/OIDC) is async in nature, meaning it does not fit very well
|
||||||
* into the default laravel 'Guard' auth flow. Instead most of the logic is done
|
* into the default laravel 'Guard' auth flow. Instead, most of the logic is done via the relevant
|
||||||
* via the Saml2 controller & Saml2Service. This class provides a safer, thin
|
* controller and services. This class provides a safer, thin version of SessionGuard.
|
||||||
* version of SessionGuard.
|
|
||||||
*/
|
*/
|
||||||
class AsyncExternalBaseSessionGuard extends ExternalBaseSessionGuard
|
class AsyncExternalBaseSessionGuard extends ExternalBaseSessionGuard
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Validate a user's credentials.
|
* Validate a user's credentials.
|
||||||
*
|
|
||||||
* @param array $credentials
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function validate(array $credentials = [])
|
public function validate(array $credentials = []): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -27,12 +22,9 @@ class AsyncExternalBaseSessionGuard extends ExternalBaseSessionGuard
|
|||||||
/**
|
/**
|
||||||
* Attempt to authenticate a user using the given credentials.
|
* Attempt to authenticate a user using the given credentials.
|
||||||
*
|
*
|
||||||
* @param array $credentials
|
|
||||||
* @param bool $remember
|
* @param bool $remember
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function attempt(array $credentials = [], $remember = false)
|
public function attempt(array $credentials = [], $remember = false): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace BookStack\Access\Guards;
|
|||||||
|
|
||||||
use BookStack\Access\RegistrationService;
|
use BookStack\Access\RegistrationService;
|
||||||
use Illuminate\Auth\GuardHelpers;
|
use Illuminate\Auth\GuardHelpers;
|
||||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||||
use Illuminate\Contracts\Auth\UserProvider;
|
use Illuminate\Contracts\Auth\UserProvider;
|
||||||
use Illuminate\Contracts\Session\Session;
|
use Illuminate\Contracts\Session\Session;
|
||||||
@@ -24,43 +24,31 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
* The name of the Guard. Typically "session".
|
* The name of the Guard. Typically "session".
|
||||||
*
|
*
|
||||||
* Corresponds to guard name in authentication configuration.
|
* Corresponds to guard name in authentication configuration.
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
*/
|
||||||
protected $name;
|
protected readonly string $name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user we last attempted to retrieve.
|
* The user we last attempted to retrieve.
|
||||||
*
|
|
||||||
* @var \Illuminate\Contracts\Auth\Authenticatable
|
|
||||||
*/
|
*/
|
||||||
protected $lastAttempted;
|
protected Authenticatable|null $lastAttempted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The session used by the guard.
|
* The session used by the guard.
|
||||||
*
|
|
||||||
* @var \Illuminate\Contracts\Session\Session
|
|
||||||
*/
|
*/
|
||||||
protected $session;
|
protected Session $session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if the logout method has been called.
|
* Indicates if the logout method has been called.
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
*/
|
||||||
protected $loggedOut = false;
|
protected bool $loggedOut = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to handle common registration actions.
|
* Service to handle common registration actions.
|
||||||
*
|
|
||||||
* @var RegistrationService
|
|
||||||
*/
|
*/
|
||||||
protected $registrationService;
|
protected RegistrationService $registrationService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new authentication guard.
|
* Create a new authentication guard.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function __construct(string $name, UserProvider $provider, Session $session, RegistrationService $registrationService)
|
public function __construct(string $name, UserProvider $provider, Session $session, RegistrationService $registrationService)
|
||||||
{
|
{
|
||||||
@@ -72,13 +60,11 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the currently authenticated user.
|
* Get the currently authenticated user.
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
|
||||||
*/
|
*/
|
||||||
public function user()
|
public function user(): Authenticatable|null
|
||||||
{
|
{
|
||||||
if ($this->loggedOut) {
|
if ($this->loggedOut) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've already retrieved the user for the current request we can just
|
// If we've already retrieved the user for the current request we can just
|
||||||
@@ -101,13 +87,11 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ID for the currently authenticated user.
|
* Get the ID for the currently authenticated user.
|
||||||
*
|
|
||||||
* @return int|null
|
|
||||||
*/
|
*/
|
||||||
public function id()
|
public function id(): int|null
|
||||||
{
|
{
|
||||||
if ($this->loggedOut) {
|
if ($this->loggedOut) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->user()
|
return $this->user()
|
||||||
@@ -117,12 +101,8 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a user into the application without sessions or cookies.
|
* Log a user into the application without sessions or cookies.
|
||||||
*
|
|
||||||
* @param array $credentials
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function once(array $credentials = [])
|
public function once(array $credentials = []): bool
|
||||||
{
|
{
|
||||||
if ($this->validate($credentials)) {
|
if ($this->validate($credentials)) {
|
||||||
$this->setUser($this->lastAttempted);
|
$this->setUser($this->lastAttempted);
|
||||||
@@ -135,12 +115,8 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Log the given user ID into the application without sessions or cookies.
|
* Log the given user ID into the application without sessions or cookies.
|
||||||
*
|
|
||||||
* @param mixed $id
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\Auth\Authenticatable|false
|
|
||||||
*/
|
*/
|
||||||
public function onceUsingId($id)
|
public function onceUsingId($id): Authenticatable|false
|
||||||
{
|
{
|
||||||
if (!is_null($user = $this->provider->retrieveById($id))) {
|
if (!is_null($user = $this->provider->retrieveById($id))) {
|
||||||
$this->setUser($user);
|
$this->setUser($user);
|
||||||
@@ -153,38 +129,26 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a user's credentials.
|
* Validate a user's credentials.
|
||||||
*
|
|
||||||
* @param array $credentials
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function validate(array $credentials = [])
|
public function validate(array $credentials = []): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to authenticate a user using the given credentials.
|
* Attempt to authenticate a user using the given credentials.
|
||||||
*
|
* @param bool $remember
|
||||||
* @param array $credentials
|
|
||||||
* @param bool $remember
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function attempt(array $credentials = [], $remember = false)
|
public function attempt(array $credentials = [], $remember = false): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log the given user ID into the application.
|
* Log the given user ID into the application.
|
||||||
*
|
|
||||||
* @param mixed $id
|
|
||||||
* @param bool $remember
|
* @param bool $remember
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\Auth\Authenticatable|false
|
|
||||||
*/
|
*/
|
||||||
public function loginUsingId($id, $remember = false)
|
public function loginUsingId(mixed $id, $remember = false): Authenticatable|false
|
||||||
{
|
{
|
||||||
// Always return false as to disable this method,
|
// Always return false as to disable this method,
|
||||||
// Logins should route through LoginService.
|
// Logins should route through LoginService.
|
||||||
@@ -194,12 +158,9 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
/**
|
/**
|
||||||
* Log a user into the application.
|
* Log a user into the application.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Contracts\Auth\Authenticatable $user
|
* @param bool $remember
|
||||||
* @param bool $remember
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function login(AuthenticatableContract $user, $remember = false)
|
public function login(Authenticatable $user, $remember = false): void
|
||||||
{
|
{
|
||||||
$this->updateSession($user->getAuthIdentifier());
|
$this->updateSession($user->getAuthIdentifier());
|
||||||
|
|
||||||
@@ -208,12 +169,8 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the session with the given ID.
|
* Update the session with the given ID.
|
||||||
*
|
|
||||||
* @param string $id
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
protected function updateSession($id)
|
protected function updateSession(string|int $id): void
|
||||||
{
|
{
|
||||||
$this->session->put($this->getName(), $id);
|
$this->session->put($this->getName(), $id);
|
||||||
|
|
||||||
@@ -222,10 +179,8 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Log the user out of the application.
|
* Log the user out of the application.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function logout()
|
public function logout(): void
|
||||||
{
|
{
|
||||||
$this->clearUserDataFromStorage();
|
$this->clearUserDataFromStorage();
|
||||||
|
|
||||||
@@ -239,62 +194,48 @@ class ExternalBaseSessionGuard implements StatefulGuard
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the user data from the session and cookies.
|
* Remove the user data from the session and cookies.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
protected function clearUserDataFromStorage()
|
protected function clearUserDataFromStorage(): void
|
||||||
{
|
{
|
||||||
$this->session->remove($this->getName());
|
$this->session->remove($this->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the last user we attempted to authenticate.
|
* Get the last user we attempted to authenticate.
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\Auth\Authenticatable
|
|
||||||
*/
|
*/
|
||||||
public function getLastAttempted()
|
public function getLastAttempted(): Authenticatable
|
||||||
{
|
{
|
||||||
return $this->lastAttempted;
|
return $this->lastAttempted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a unique identifier for the auth session value.
|
* Get a unique identifier for the auth session value.
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'login_' . $this->name . '_' . sha1(static::class);
|
return 'login_' . $this->name . '_' . sha1(static::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the user was authenticated via "remember me" cookie.
|
* Determine if the user was authenticated via "remember me" cookie.
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function viaRemember()
|
public function viaRemember(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the currently cached user.
|
* Return the currently cached user.
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
|
||||||
*/
|
*/
|
||||||
public function getUser()
|
public function getUser(): Authenticatable|null
|
||||||
{
|
{
|
||||||
return $this->user;
|
return $this->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current user.
|
* Set the current user.
|
||||||
*
|
|
||||||
* @param \Illuminate\Contracts\Auth\Authenticatable $user
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
*/
|
||||||
public function setUser(AuthenticatableContract $user)
|
public function setUser(Authenticatable $user): self
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
|
||||||
|
|||||||
@@ -35,13 +35,9 @@ class LdapSessionGuard extends ExternalBaseSessionGuard
|
|||||||
/**
|
/**
|
||||||
* Validate a user's credentials.
|
* Validate a user's credentials.
|
||||||
*
|
*
|
||||||
* @param array $credentials
|
|
||||||
*
|
|
||||||
* @throws LdapException
|
* @throws LdapException
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function validate(array $credentials = [])
|
public function validate(array $credentials = []): bool
|
||||||
{
|
{
|
||||||
$userDetails = $this->ldapService->getUserDetails($credentials['username']);
|
$userDetails = $this->ldapService->getUserDetails($credentials['username']);
|
||||||
|
|
||||||
@@ -57,16 +53,13 @@ class LdapSessionGuard extends ExternalBaseSessionGuard
|
|||||||
/**
|
/**
|
||||||
* Attempt to authenticate a user using the given credentials.
|
* Attempt to authenticate a user using the given credentials.
|
||||||
*
|
*
|
||||||
* @param array $credentials
|
|
||||||
* @param bool $remember
|
* @param bool $remember
|
||||||
*
|
*
|
||||||
* @throws LdapException*@throws \BookStack\Exceptions\JsonDebugException
|
* @throws LdapException
|
||||||
* @throws LoginAttemptException
|
* @throws LoginAttemptException
|
||||||
* @throws JsonDebugException
|
* @throws JsonDebugException
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function attempt(array $credentials = [], $remember = false)
|
public function attempt(array $credentials = [], $remember = false): bool
|
||||||
{
|
{
|
||||||
$username = $credentials['username'];
|
$username = $credentials['username'];
|
||||||
$userDetails = $this->ldapService->getUserDetails($username);
|
$userDetails = $this->ldapService->getUserDetails($username);
|
||||||
|
|||||||
@@ -52,13 +52,25 @@ class Ldap
|
|||||||
*
|
*
|
||||||
* @param resource|\LDAP\Connection $ldapConnection
|
* @param resource|\LDAP\Connection $ldapConnection
|
||||||
*
|
*
|
||||||
* @return resource|\LDAP\Result
|
* @return \LDAP\Result|array|false
|
||||||
*/
|
*/
|
||||||
public function search($ldapConnection, string $baseDn, string $filter, array $attributes = null)
|
public function search($ldapConnection, string $baseDn, string $filter, array $attributes = [])
|
||||||
{
|
{
|
||||||
return ldap_search($ldapConnection, $baseDn, $filter, $attributes);
|
return ldap_search($ldapConnection, $baseDn, $filter, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read an entry from the LDAP tree.
|
||||||
|
*
|
||||||
|
* @param resource|\Ldap\Connection $ldapConnection
|
||||||
|
*
|
||||||
|
* @return \LDAP\Result|array|false
|
||||||
|
*/
|
||||||
|
public function read($ldapConnection, string $baseDn, string $filter, array $attributes = [])
|
||||||
|
{
|
||||||
|
return ldap_read($ldapConnection, $baseDn, $filter, $attributes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get entries from an LDAP search result.
|
* Get entries from an LDAP search result.
|
||||||
*
|
*
|
||||||
@@ -75,7 +87,7 @@ class Ldap
|
|||||||
*
|
*
|
||||||
* @param resource|\LDAP\Connection $ldapConnection
|
* @param resource|\LDAP\Connection $ldapConnection
|
||||||
*/
|
*/
|
||||||
public function searchAndGetEntries($ldapConnection, string $baseDn, string $filter, array $attributes = null): array|false
|
public function searchAndGetEntries($ldapConnection, string $baseDn, string $filter, array $attributes = []): array|false
|
||||||
{
|
{
|
||||||
$search = $this->search($ldapConnection, $baseDn, $filter, $attributes);
|
$search = $this->search($ldapConnection, $baseDn, $filter, $attributes);
|
||||||
|
|
||||||
@@ -87,7 +99,7 @@ class Ldap
|
|||||||
*
|
*
|
||||||
* @param resource|\LDAP\Connection $ldapConnection
|
* @param resource|\LDAP\Connection $ldapConnection
|
||||||
*/
|
*/
|
||||||
public function bind($ldapConnection, string $bindRdn = null, string $bindPassword = null): bool
|
public function bind($ldapConnection, ?string $bindRdn = null, ?string $bindPassword = null): bool
|
||||||
{
|
{
|
||||||
return ldap_bind($ldapConnection, $bindRdn, $bindPassword);
|
return ldap_bind($ldapConnection, $bindRdn, $bindPassword);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,26 @@ class LdapService
|
|||||||
return $users[0];
|
return $users[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the user display name from the (potentially multiple) attributes defined by the configuration.
|
||||||
|
*/
|
||||||
|
protected function getUserDisplayName(array $userDetails, array $displayNameAttrs, string $defaultValue): string
|
||||||
|
{
|
||||||
|
$displayNameParts = [];
|
||||||
|
foreach ($displayNameAttrs as $dnAttr) {
|
||||||
|
$dnComponent = $this->getUserResponseProperty($userDetails, $dnAttr, null);
|
||||||
|
if ($dnComponent) {
|
||||||
|
$displayNameParts[] = $dnComponent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($displayNameParts)) {
|
||||||
|
return $defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(' ', $displayNameParts);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the details of a user from LDAP using the given username.
|
* Get the details of a user from LDAP using the given username.
|
||||||
* User found via configurable user filter.
|
* User found via configurable user filter.
|
||||||
@@ -81,21 +101,25 @@ class LdapService
|
|||||||
{
|
{
|
||||||
$idAttr = $this->config['id_attribute'];
|
$idAttr = $this->config['id_attribute'];
|
||||||
$emailAttr = $this->config['email_attribute'];
|
$emailAttr = $this->config['email_attribute'];
|
||||||
$displayNameAttr = $this->config['display_name_attribute'];
|
$displayNameAttrs = explode('|', $this->config['display_name_attribute']);
|
||||||
$thumbnailAttr = $this->config['thumbnail_attribute'];
|
$thumbnailAttr = $this->config['thumbnail_attribute'];
|
||||||
|
|
||||||
$user = $this->getUserWithAttributes($userName, array_filter([
|
$user = $this->getUserWithAttributes($userName, array_filter([
|
||||||
'cn', 'dn', $idAttr, $emailAttr, $displayNameAttr, $thumbnailAttr,
|
'cn', 'dn', $idAttr, $emailAttr, ...$displayNameAttrs, $thumbnailAttr,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
if (is_null($user)) {
|
if (is_null($user)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$userCn = $this->getUserResponseProperty($user, 'cn', null);
|
$nameDefault = $this->getUserResponseProperty($user, 'cn', null);
|
||||||
|
if (is_null($nameDefault)) {
|
||||||
|
$nameDefault = ldap_explode_dn($user['dn'], 1)[0] ?? $user['dn'];
|
||||||
|
}
|
||||||
|
|
||||||
$formatted = [
|
$formatted = [
|
||||||
'uid' => $this->getUserResponseProperty($user, $idAttr, $user['dn']),
|
'uid' => $this->getUserResponseProperty($user, $idAttr, $user['dn']),
|
||||||
'name' => $this->getUserResponseProperty($user, $displayNameAttr, $userCn),
|
'name' => $this->getUserDisplayName($user, $displayNameAttrs, $nameDefault),
|
||||||
'dn' => $user['dn'],
|
'dn' => $user['dn'],
|
||||||
'email' => $this->getUserResponseProperty($user, $emailAttr, null),
|
'email' => $this->getUserResponseProperty($user, $emailAttr, null),
|
||||||
'avatar' => $thumbnailAttr ? $this->getUserResponseProperty($user, $thumbnailAttr, null) : null,
|
'avatar' => $thumbnailAttr ? $this->getUserResponseProperty($user, $thumbnailAttr, null) : null,
|
||||||
@@ -209,6 +233,12 @@ class LdapService
|
|||||||
$this->ldap->setOption(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
|
$this->ldap->setOption(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure any user-provided CA cert files for LDAP.
|
||||||
|
// This option works globally and must be set before a connection is created.
|
||||||
|
if ($this->config['tls_ca_cert']) {
|
||||||
|
$this->configureTlsCaCerts($this->config['tls_ca_cert']);
|
||||||
|
}
|
||||||
|
|
||||||
$ldapHost = $this->parseServerString($this->config['server']);
|
$ldapHost = $this->parseServerString($this->config['server']);
|
||||||
$ldapConnection = $this->ldap->connect($ldapHost);
|
$ldapConnection = $this->ldap->connect($ldapHost);
|
||||||
|
|
||||||
@@ -223,7 +253,14 @@ class LdapService
|
|||||||
|
|
||||||
// Start and verify TLS if it's enabled
|
// Start and verify TLS if it's enabled
|
||||||
if ($this->config['start_tls']) {
|
if ($this->config['start_tls']) {
|
||||||
$started = $this->ldap->startTls($ldapConnection);
|
try {
|
||||||
|
$started = $this->ldap->startTls($ldapConnection);
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
$error = $exception->getMessage() . ' :: ' . ldap_error($ldapConnection);
|
||||||
|
ldap_get_option($ldapConnection, LDAP_OPT_DIAGNOSTIC_MESSAGE, $detail);
|
||||||
|
Log::info("LDAP STARTTLS failure: {$error} {$detail}");
|
||||||
|
throw new LdapException('Could not start TLS connection. Further details in the application log.');
|
||||||
|
}
|
||||||
if (!$started) {
|
if (!$started) {
|
||||||
throw new LdapException('Could not start TLS connection');
|
throw new LdapException('Could not start TLS connection');
|
||||||
}
|
}
|
||||||
@@ -234,6 +271,33 @@ class LdapService
|
|||||||
return $this->ldapConnection;
|
return $this->ldapConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure TLS CA certs globally for ldap use.
|
||||||
|
* This will detect if the given path is a directory or file, and set the relevant
|
||||||
|
* LDAP TLS options appropriately otherwise throw an exception if no file/folder found.
|
||||||
|
*
|
||||||
|
* Note: When using a folder, certificates are expected to be correctly named by hash
|
||||||
|
* which can be done via the c_rehash utility.
|
||||||
|
*
|
||||||
|
* @throws LdapException
|
||||||
|
*/
|
||||||
|
protected function configureTlsCaCerts(string $caCertPath): void
|
||||||
|
{
|
||||||
|
$errMessage = "Provided path [{$caCertPath}] for LDAP TLS CA certs could not be resolved to an existing location";
|
||||||
|
$path = realpath($caCertPath);
|
||||||
|
if ($path === false) {
|
||||||
|
throw new LdapException($errMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_dir($path)) {
|
||||||
|
$this->ldap->setOption(null, LDAP_OPT_X_TLS_CACERTDIR, $path);
|
||||||
|
} else if (is_file($path)) {
|
||||||
|
$this->ldap->setOption(null, LDAP_OPT_X_TLS_CACERTFILE, $path);
|
||||||
|
} else {
|
||||||
|
throw new LdapException($errMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse an LDAP server string and return the host suitable for a connection.
|
* Parse an LDAP server string and return the host suitable for a connection.
|
||||||
* Is flexible to formats such as 'ldap.example.com:8069' or 'ldaps://ldap.example.com'.
|
* Is flexible to formats such as 'ldap.example.com:8069' or 'ldaps://ldap.example.com'.
|
||||||
@@ -249,13 +313,18 @@ class LdapService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a filter string by injecting common variables.
|
* Build a filter string by injecting common variables.
|
||||||
|
* Both "${var}" and "{var}" style placeholders are supported.
|
||||||
|
* Dollar based are old format but supported for compatibility.
|
||||||
*/
|
*/
|
||||||
protected function buildFilter(string $filterString, array $attrs): string
|
protected function buildFilter(string $filterString, array $attrs): string
|
||||||
{
|
{
|
||||||
$newAttrs = [];
|
$newAttrs = [];
|
||||||
foreach ($attrs as $key => $attrText) {
|
foreach ($attrs as $key => $attrText) {
|
||||||
$newKey = '${' . $key . '}';
|
$escapedText = $this->ldap->escape($attrText);
|
||||||
$newAttrs[$newKey] = $this->ldap->escape($attrText);
|
$oldVarKey = '${' . $key . '}';
|
||||||
|
$newVarKey = '{' . $key . '}';
|
||||||
|
$newAttrs[$oldVarKey] = $escapedText;
|
||||||
|
$newAttrs[$newVarKey] = $escapedText;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strtr($filterString, $newAttrs);
|
return strtr($filterString, $newAttrs);
|
||||||
@@ -276,94 +345,105 @@ class LdapService
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$userGroups = $this->groupFilter($user);
|
$userGroups = $this->extractGroupsFromSearchResponseEntry($user);
|
||||||
$allGroups = $this->getGroupsRecursive($userGroups, []);
|
$allGroups = $this->getGroupsRecursive($userGroups, []);
|
||||||
|
$formattedGroups = $this->extractGroupNamesFromLdapGroupDns($allGroups);
|
||||||
|
|
||||||
if ($this->config['dump_user_groups']) {
|
if ($this->config['dump_user_groups']) {
|
||||||
throw new JsonDebugException([
|
throw new JsonDebugException([
|
||||||
'details_from_ldap' => $user,
|
'details_from_ldap' => $user,
|
||||||
'parsed_direct_user_groups' => $userGroups,
|
'parsed_direct_user_groups' => $userGroups,
|
||||||
'parsed_recursive_user_groups' => $allGroups,
|
'parsed_recursive_user_groups' => $allGroups,
|
||||||
|
'parsed_resulting_group_names' => $formattedGroups,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $allGroups;
|
return $formattedGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function extractGroupNamesFromLdapGroupDns(array $groupDNs): array
|
||||||
|
{
|
||||||
|
$names = [];
|
||||||
|
|
||||||
|
foreach ($groupDNs as $groupDN) {
|
||||||
|
$exploded = $this->ldap->explodeDn($groupDN, 1);
|
||||||
|
if ($exploded !== false && count($exploded) > 0) {
|
||||||
|
$names[] = $exploded[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_unique($names);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the parent groups of an array of groups.
|
* Build an array of all relevant groups DNs after recursively scanning
|
||||||
|
* across parents of the groups given.
|
||||||
*
|
*
|
||||||
* @throws LdapException
|
* @throws LdapException
|
||||||
*/
|
*/
|
||||||
private function getGroupsRecursive(array $groupsArray, array $checked): array
|
protected function getGroupsRecursive(array $groupDNs, array $checked): array
|
||||||
{
|
{
|
||||||
$groupsToAdd = [];
|
$groupsToAdd = [];
|
||||||
foreach ($groupsArray as $groupName) {
|
foreach ($groupDNs as $groupDN) {
|
||||||
if (in_array($groupName, $checked)) {
|
if (in_array($groupDN, $checked)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parentGroups = $this->getGroupGroups($groupName);
|
$parentGroups = $this->getParentsOfGroup($groupDN);
|
||||||
$groupsToAdd = array_merge($groupsToAdd, $parentGroups);
|
$groupsToAdd = array_merge($groupsToAdd, $parentGroups);
|
||||||
$checked[] = $groupName;
|
$checked[] = $groupDN;
|
||||||
}
|
}
|
||||||
|
|
||||||
$groupsArray = array_unique(array_merge($groupsArray, $groupsToAdd), SORT_REGULAR);
|
$uniqueDNs = array_unique(array_merge($groupDNs, $groupsToAdd), SORT_REGULAR);
|
||||||
|
|
||||||
if (empty($groupsToAdd)) {
|
if (empty($groupsToAdd)) {
|
||||||
return $groupsArray;
|
return $uniqueDNs;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getGroupsRecursive($groupsArray, $checked);
|
return $this->getGroupsRecursive($uniqueDNs, $checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the parent groups of a single group.
|
|
||||||
*
|
|
||||||
* @throws LdapException
|
* @throws LdapException
|
||||||
*/
|
*/
|
||||||
private function getGroupGroups(string $groupName): array
|
protected function getParentsOfGroup(string $groupDN): array
|
||||||
{
|
{
|
||||||
|
$groupsAttr = strtolower($this->config['group_attribute']);
|
||||||
$ldapConnection = $this->getConnection();
|
$ldapConnection = $this->getConnection();
|
||||||
$this->bindSystemUser($ldapConnection);
|
$this->bindSystemUser($ldapConnection);
|
||||||
|
|
||||||
$followReferrals = $this->config['follow_referrals'] ? 1 : 0;
|
$followReferrals = $this->config['follow_referrals'] ? 1 : 0;
|
||||||
$this->ldap->setOption($ldapConnection, LDAP_OPT_REFERRALS, $followReferrals);
|
$this->ldap->setOption($ldapConnection, LDAP_OPT_REFERRALS, $followReferrals);
|
||||||
|
$read = $this->ldap->read($ldapConnection, $groupDN, '(objectClass=*)', [$groupsAttr]);
|
||||||
$baseDn = $this->config['base_dn'];
|
$results = $this->ldap->getEntries($ldapConnection, $read);
|
||||||
$groupsAttr = strtolower($this->config['group_attribute']);
|
if ($results['count'] === 0) {
|
||||||
|
|
||||||
$groupFilter = 'CN=' . $this->ldap->escape($groupName);
|
|
||||||
$groups = $this->ldap->searchAndGetEntries($ldapConnection, $baseDn, $groupFilter, [$groupsAttr]);
|
|
||||||
if ($groups['count'] === 0) {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->groupFilter($groups[0]);
|
return $this->extractGroupsFromSearchResponseEntry($results[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter out LDAP CN and DN language in a ldap search return.
|
* Extract an array of group DN values from the given LDAP search response entry
|
||||||
* Gets the base CN (common name) of the string.
|
|
||||||
*/
|
*/
|
||||||
protected function groupFilter(array $userGroupSearchResponse): array
|
protected function extractGroupsFromSearchResponseEntry(array $ldapEntry): array
|
||||||
{
|
{
|
||||||
$groupsAttr = strtolower($this->config['group_attribute']);
|
$groupsAttr = strtolower($this->config['group_attribute']);
|
||||||
$ldapGroups = [];
|
$groupDNs = [];
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
if (isset($userGroupSearchResponse[$groupsAttr]['count'])) {
|
if (isset($ldapEntry[$groupsAttr]['count'])) {
|
||||||
$count = (int) $userGroupSearchResponse[$groupsAttr]['count'];
|
$count = (int) $ldapEntry[$groupsAttr]['count'];
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$dnComponents = $this->ldap->explodeDn($userGroupSearchResponse[$groupsAttr][$i], 1);
|
$dn = $ldapEntry[$groupsAttr][$i];
|
||||||
if (!in_array($dnComponents[0], $ldapGroups)) {
|
if (!in_array($dn, $groupDNs)) {
|
||||||
$ldapGroups[] = $dnComponents[0];
|
$groupDNs[] = $dn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ldapGroups;
|
return $groupDNs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ namespace BookStack\Access;
|
|||||||
use BookStack\Access\Mfa\MfaSession;
|
use BookStack\Access\Mfa\MfaSession;
|
||||||
use BookStack\Activity\ActivityType;
|
use BookStack\Activity\ActivityType;
|
||||||
use BookStack\Exceptions\LoginAttemptException;
|
use BookStack\Exceptions\LoginAttemptException;
|
||||||
|
use BookStack\Exceptions\LoginAttemptInvalidUserException;
|
||||||
use BookStack\Exceptions\StoppedAuthenticationException;
|
use BookStack\Exceptions\StoppedAuthenticationException;
|
||||||
use BookStack\Facades\Activity;
|
use BookStack\Facades\Activity;
|
||||||
use BookStack\Facades\Theme;
|
use BookStack\Facades\Theme;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
use BookStack\Theming\ThemeEvents;
|
use BookStack\Theming\ThemeEvents;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Exception;
|
use Exception;
|
||||||
@@ -29,10 +31,14 @@ class LoginService
|
|||||||
* a reason to (MFA or Unconfirmed Email).
|
* a reason to (MFA or Unconfirmed Email).
|
||||||
* Returns a boolean to indicate the current login result.
|
* Returns a boolean to indicate the current login result.
|
||||||
*
|
*
|
||||||
* @throws StoppedAuthenticationException
|
* @throws StoppedAuthenticationException|LoginAttemptInvalidUserException
|
||||||
*/
|
*/
|
||||||
public function login(User $user, string $method, bool $remember = false): void
|
public function login(User $user, string $method, bool $remember = false): void
|
||||||
{
|
{
|
||||||
|
if ($user->isGuest()) {
|
||||||
|
throw new LoginAttemptInvalidUserException('Login not allowed for guest user');
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->awaitingEmailConfirmation($user) || $this->needsMfaVerification($user)) {
|
if ($this->awaitingEmailConfirmation($user) || $this->needsMfaVerification($user)) {
|
||||||
$this->setLastLoginAttemptedForUser($user, $method, $remember);
|
$this->setLastLoginAttemptedForUser($user, $method, $remember);
|
||||||
|
|
||||||
@@ -45,7 +51,7 @@ class LoginService
|
|||||||
Theme::dispatch(ThemeEvents::AUTH_LOGIN, $method, $user);
|
Theme::dispatch(ThemeEvents::AUTH_LOGIN, $method, $user);
|
||||||
|
|
||||||
// Authenticate on all session guards if a likely admin
|
// Authenticate on all session guards if a likely admin
|
||||||
if ($user->can('users-manage') && $user->can('user-roles-manage')) {
|
if ($user->can(Permission::UsersManage) && $user->can(Permission::UserRolesManage)) {
|
||||||
$guards = ['standard', 'ldap', 'saml2', 'oidc'];
|
$guards = ['standard', 'ldap', 'saml2', 'oidc'];
|
||||||
foreach ($guards as $guard) {
|
foreach ($guards as $guard) {
|
||||||
auth($guard)->login($user);
|
auth($guard)->login($user);
|
||||||
@@ -58,14 +64,14 @@ class LoginService
|
|||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function reattemptLoginFor(User $user)
|
public function reattemptLoginFor(User $user): void
|
||||||
{
|
{
|
||||||
if ($user->id !== ($this->getLastLoginAttemptUser()->id ?? null)) {
|
if ($user->id !== ($this->getLastLoginAttemptUser()->id ?? null)) {
|
||||||
throw new Exception('Login reattempt user does align with current session state');
|
throw new Exception('Login reattempt user does align with current session state');
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastLoginDetails = $this->getLastLoginAttemptDetails();
|
$lastLoginDetails = $this->getLastLoginAttemptDetails();
|
||||||
$this->login($user, $lastLoginDetails['method'], $lastLoginDetails['remember'] ?? false);
|
$this->login($user, $lastLoginDetails['method'], $lastLoginDetails['remember']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,7 +96,7 @@ class LoginService
|
|||||||
{
|
{
|
||||||
$value = session()->get(self::LAST_LOGIN_ATTEMPTED_SESSION_KEY);
|
$value = session()->get(self::LAST_LOGIN_ATTEMPTED_SESSION_KEY);
|
||||||
if (!$value) {
|
if (!$value) {
|
||||||
return ['user_id' => null, 'method' => null];
|
return ['user_id' => null, 'method' => null, 'remember' => false];
|
||||||
}
|
}
|
||||||
|
|
||||||
[$id, $method, $remember, $time] = explode(':', $value);
|
[$id, $method, $remember, $time] = explode(':', $value);
|
||||||
@@ -98,18 +104,18 @@ class LoginService
|
|||||||
if ($time < $hourAgo) {
|
if ($time < $hourAgo) {
|
||||||
$this->clearLastLoginAttempted();
|
$this->clearLastLoginAttempted();
|
||||||
|
|
||||||
return ['user_id' => null, 'method' => null];
|
return ['user_id' => null, 'method' => null, 'remember' => false];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['user_id' => $id, 'method' => $method, 'remember' => boolval($remember)];
|
return ['user_id' => $id, 'method' => $method, 'remember' => boolval($remember)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the last login attempted user.
|
* Set the last login-attempted user.
|
||||||
* Must be only used when credentials are correct and a login could be
|
* Must be only used when credentials are correct and a login could be
|
||||||
* achieved but a secondary factor has stopped the login.
|
* achieved, but a secondary factor has stopped the login.
|
||||||
*/
|
*/
|
||||||
protected function setLastLoginAttemptedForUser(User $user, string $method, bool $remember)
|
protected function setLastLoginAttemptedForUser(User $user, string $method, bool $remember): void
|
||||||
{
|
{
|
||||||
session()->put(
|
session()->put(
|
||||||
self::LAST_LOGIN_ATTEMPTED_SESSION_KEY,
|
self::LAST_LOGIN_ATTEMPTED_SESSION_KEY,
|
||||||
@@ -152,16 +158,40 @@ class LoginService
|
|||||||
*/
|
*/
|
||||||
public function attempt(array $credentials, string $method, bool $remember = false): bool
|
public function attempt(array $credentials, string $method, bool $remember = false): bool
|
||||||
{
|
{
|
||||||
|
if ($this->areCredentialsForGuest($credentials)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$result = auth()->attempt($credentials, $remember);
|
$result = auth()->attempt($credentials, $remember);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
auth()->logout();
|
auth()->logout();
|
||||||
$this->login($user, $method, $remember);
|
try {
|
||||||
|
$this->login($user, $method, $remember);
|
||||||
|
} catch (LoginAttemptInvalidUserException $e) {
|
||||||
|
// Catch and return false for non-login accounts
|
||||||
|
// so it looks like a normal invalid login.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the given credentials are likely for the system guest account.
|
||||||
|
*/
|
||||||
|
protected function areCredentialsForGuest(array $credentials): bool
|
||||||
|
{
|
||||||
|
if (isset($credentials['email'])) {
|
||||||
|
return User::query()->where('email', '=', $credentials['email'])
|
||||||
|
->where('system_name', '=', 'public')
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs the current user out of the application.
|
* Logs the current user out of the application.
|
||||||
* Returns an app post-redirect path.
|
* Returns an app post-redirect path.
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ class MfaSession
|
|||||||
*/
|
*/
|
||||||
public function isRequiredForUser(User $user): bool
|
public function isRequiredForUser(User $user): bool
|
||||||
{
|
{
|
||||||
// TODO - Test both these cases
|
|
||||||
return $user->mfaValues()->exists() || $this->userRoleEnforcesMfa($user);
|
return $user->mfaValues()->exists() || $this->userRoleEnforcesMfa($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace BookStack\Access\Mfa;
|
|||||||
|
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,6 +17,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
*/
|
*/
|
||||||
class MfaValue extends Model
|
class MfaValue extends Model
|
||||||
{
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
protected static $unguarded = true;
|
protected static $unguarded = true;
|
||||||
|
|
||||||
const METHOD_TOTP = 'totp';
|
const METHOD_TOTP = 'totp';
|
||||||
@@ -45,17 +48,16 @@ class MfaValue extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Easily get the decrypted MFA value for the given user and method.
|
* Get the decrypted MFA value for the given user and method.
|
||||||
*/
|
*/
|
||||||
public static function getValueForUser(User $user, string $method): ?string
|
public static function getValueForUser(User $user, string $method): ?string
|
||||||
{
|
{
|
||||||
/** @var MfaValue $mfaVal */
|
|
||||||
$mfaVal = static::query()
|
$mfaVal = static::query()
|
||||||
->where('user_id', '=', $user->id)
|
->where('user_id', '=', $user->id)
|
||||||
->where('method', '=', $method)
|
->where('method', '=', $method)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
return $mfaVal ? $mfaVal->getValue() : null;
|
return $mfaVal?->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,10 +14,9 @@ use PragmaRX\Google2FA\Support\Constants;
|
|||||||
|
|
||||||
class TotpService
|
class TotpService
|
||||||
{
|
{
|
||||||
protected $google2fa;
|
public function __construct(
|
||||||
|
protected Google2FA $google2fa
|
||||||
public function __construct(Google2FA $google2fa)
|
) {
|
||||||
{
|
|
||||||
$this->google2fa = $google2fa;
|
$this->google2fa = $google2fa;
|
||||||
// Use SHA1 as a default, Personal testing of other options in 2021 found
|
// Use SHA1 as a default, Personal testing of other options in 2021 found
|
||||||
// many apps lack support for other algorithms yet still will scan
|
// many apps lack support for other algorithms yet still will scan
|
||||||
@@ -35,7 +34,7 @@ class TotpService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a TOTP URL from secret key.
|
* Generate a TOTP URL from a secret key.
|
||||||
*/
|
*/
|
||||||
public function generateUrl(string $secret, User $user): string
|
public function generateUrl(string $secret, User $user): string
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,36 +2,26 @@
|
|||||||
|
|
||||||
namespace BookStack\Access\Mfa;
|
namespace BookStack\Access\Mfa;
|
||||||
|
|
||||||
use Illuminate\Contracts\Validation\Rule;
|
use Closure;
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
|
||||||
class TotpValidationRule implements Rule
|
class TotpValidationRule implements ValidationRule
|
||||||
{
|
{
|
||||||
protected $secret;
|
|
||||||
protected $totpService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new rule instance.
|
* Create a new rule instance.
|
||||||
* Takes the TOTP secret that must be system provided, not user provided.
|
* Takes the TOTP secret that must be system provided, not user provided.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $secret)
|
public function __construct(
|
||||||
{
|
protected string $secret,
|
||||||
$this->secret = $secret;
|
protected TotpService $totpService,
|
||||||
$this->totpService = app()->make(TotpService::class);
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||||
* Determine if the validation rule passes.
|
|
||||||
*/
|
|
||||||
public function passes($attribute, $value)
|
|
||||||
{
|
{
|
||||||
return $this->totpService->verifyCode($value, $this->secret);
|
$passes = $this->totpService->verifyCode($value, $this->secret);
|
||||||
}
|
if (!$passes) {
|
||||||
|
$fail(trans('validation.totp'));
|
||||||
/**
|
}
|
||||||
* Get the validation error message.
|
|
||||||
*/
|
|
||||||
public function message()
|
|
||||||
{
|
|
||||||
return trans('validation.totp');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,58 +2,8 @@
|
|||||||
|
|
||||||
namespace BookStack\Access\Oidc;
|
namespace BookStack\Access\Oidc;
|
||||||
|
|
||||||
class OidcIdToken
|
class OidcIdToken extends OidcJwtWithClaims implements ProvidesClaims
|
||||||
{
|
{
|
||||||
protected array $header;
|
|
||||||
protected array $payload;
|
|
||||||
protected string $signature;
|
|
||||||
protected string $issuer;
|
|
||||||
protected array $tokenParts = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array[]|string[]
|
|
||||||
*/
|
|
||||||
protected array $keys;
|
|
||||||
|
|
||||||
public function __construct(string $token, string $issuer, array $keys)
|
|
||||||
{
|
|
||||||
$this->keys = $keys;
|
|
||||||
$this->issuer = $issuer;
|
|
||||||
$this->parse($token);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the token content into its components.
|
|
||||||
*/
|
|
||||||
protected function parse(string $token): void
|
|
||||||
{
|
|
||||||
$this->tokenParts = explode('.', $token);
|
|
||||||
$this->header = $this->parseEncodedTokenPart($this->tokenParts[0]);
|
|
||||||
$this->payload = $this->parseEncodedTokenPart($this->tokenParts[1] ?? '');
|
|
||||||
$this->signature = $this->base64UrlDecode($this->tokenParts[2] ?? '') ?: '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a Base64-JSON encoded token part.
|
|
||||||
* Returns the data as a key-value array or empty array upon error.
|
|
||||||
*/
|
|
||||||
protected function parseEncodedTokenPart(string $part): array
|
|
||||||
{
|
|
||||||
$json = $this->base64UrlDecode($part) ?: '{}';
|
|
||||||
$decoded = json_decode($json, true);
|
|
||||||
|
|
||||||
return is_array($decoded) ? $decoded : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base64URL decode. Needs some character conversions to be compatible
|
|
||||||
* with PHP's default base64 handling.
|
|
||||||
*/
|
|
||||||
protected function base64UrlDecode(string $encoded): string
|
|
||||||
{
|
|
||||||
return base64_decode(strtr($encoded, '-_', '+/'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate all possible parts of the id token.
|
* Validate all possible parts of the id token.
|
||||||
*
|
*
|
||||||
@@ -61,91 +11,12 @@ class OidcIdToken
|
|||||||
*/
|
*/
|
||||||
public function validate(string $clientId): bool
|
public function validate(string $clientId): bool
|
||||||
{
|
{
|
||||||
$this->validateTokenStructure();
|
parent::validateCommonTokenDetails($clientId);
|
||||||
$this->validateTokenSignature();
|
|
||||||
$this->validateTokenClaims($clientId);
|
$this->validateTokenClaims($clientId);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a specific claim from this token.
|
|
||||||
* Returns null if it is null or does not exist.
|
|
||||||
*
|
|
||||||
* @return mixed|null
|
|
||||||
*/
|
|
||||||
public function getClaim(string $claim)
|
|
||||||
{
|
|
||||||
return $this->payload[$claim] ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all returned claims within the token.
|
|
||||||
*/
|
|
||||||
public function getAllClaims(): array
|
|
||||||
{
|
|
||||||
return $this->payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace the existing claim data of this token with that provided.
|
|
||||||
*/
|
|
||||||
public function replaceClaims(array $claims): void
|
|
||||||
{
|
|
||||||
$this->payload = $claims;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the structure of the given token and ensure we have the required pieces.
|
|
||||||
* As per https://datatracker.ietf.org/doc/html/rfc7519#section-7.2.
|
|
||||||
*
|
|
||||||
* @throws OidcInvalidTokenException
|
|
||||||
*/
|
|
||||||
protected function validateTokenStructure(): void
|
|
||||||
{
|
|
||||||
foreach (['header', 'payload'] as $prop) {
|
|
||||||
if (empty($this->$prop) || !is_array($this->$prop)) {
|
|
||||||
throw new OidcInvalidTokenException("Could not parse out a valid {$prop} within the provided token");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($this->signature) || !is_string($this->signature)) {
|
|
||||||
throw new OidcInvalidTokenException('Could not parse out a valid signature within the provided token');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the signature of the given token and ensure it validates against the provided key.
|
|
||||||
*
|
|
||||||
* @throws OidcInvalidTokenException
|
|
||||||
*/
|
|
||||||
protected function validateTokenSignature(): void
|
|
||||||
{
|
|
||||||
if ($this->header['alg'] !== 'RS256') {
|
|
||||||
throw new OidcInvalidTokenException("Only RS256 signature validation is supported. Token reports using {$this->header['alg']}");
|
|
||||||
}
|
|
||||||
|
|
||||||
$parsedKeys = array_map(function ($key) {
|
|
||||||
try {
|
|
||||||
return new OidcJwtSigningKey($key);
|
|
||||||
} catch (OidcInvalidKeyException $e) {
|
|
||||||
throw new OidcInvalidTokenException('Failed to read signing key with error: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
}, $this->keys);
|
|
||||||
|
|
||||||
$parsedKeys = array_filter($parsedKeys);
|
|
||||||
|
|
||||||
$contentToSign = $this->tokenParts[0] . '.' . $this->tokenParts[1];
|
|
||||||
/** @var OidcJwtSigningKey $parsedKey */
|
|
||||||
foreach ($parsedKeys as $parsedKey) {
|
|
||||||
if ($parsedKey->verify($contentToSign, $this->signature)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new OidcInvalidTokenException('Token signature could not be validated using the provided keys');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the claims of the token.
|
* Validate the claims of the token.
|
||||||
* As per https://openid.net/specs/openid-connect-basic-1_0.html#IDTokenValidation.
|
* As per https://openid.net/specs/openid-connect-basic-1_0.html#IDTokenValidation.
|
||||||
@@ -156,27 +27,18 @@ class OidcIdToken
|
|||||||
{
|
{
|
||||||
// 1. The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery)
|
// 1. The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery)
|
||||||
// MUST exactly match the value of the iss (issuer) Claim.
|
// MUST exactly match the value of the iss (issuer) Claim.
|
||||||
if (empty($this->payload['iss']) || $this->issuer !== $this->payload['iss']) {
|
// Already done in parent.
|
||||||
throw new OidcInvalidTokenException('Missing or non-matching token issuer value');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. The Client MUST validate that the aud (audience) Claim contains its client_id value registered
|
// 2. The Client MUST validate that the aud (audience) Claim contains its client_id value registered
|
||||||
// at the Issuer identified by the iss (issuer) Claim as an audience. The ID Token MUST be rejected
|
// at the Issuer identified by the iss (issuer) Claim as an audience. The ID Token MUST be rejected
|
||||||
// if the ID Token does not list the Client as a valid audience, or if it contains additional
|
// if the ID Token does not list the Client as a valid audience, or if it contains additional
|
||||||
// audiences not trusted by the Client.
|
// audiences not trusted by the Client.
|
||||||
if (empty($this->payload['aud'])) {
|
// Partially done in parent.
|
||||||
throw new OidcInvalidTokenException('Missing token audience value');
|
|
||||||
}
|
|
||||||
|
|
||||||
$aud = is_string($this->payload['aud']) ? [$this->payload['aud']] : $this->payload['aud'];
|
$aud = is_string($this->payload['aud']) ? [$this->payload['aud']] : $this->payload['aud'];
|
||||||
if (count($aud) !== 1) {
|
if (count($aud) !== 1) {
|
||||||
throw new OidcInvalidTokenException('Token audience value has ' . count($aud) . ' values, Expected 1');
|
throw new OidcInvalidTokenException('Token audience value has ' . count($aud) . ' values, Expected 1');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($aud[0] !== $clientId) {
|
|
||||||
throw new OidcInvalidTokenException('Token audience value did not match the expected client_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. If the ID Token contains multiple audiences, the Client SHOULD verify that an azp Claim is present.
|
// 3. If the ID Token contains multiple audiences, the Client SHOULD verify that an azp Claim is present.
|
||||||
// NOTE: Addressed by enforcing a count of 1 above.
|
// NOTE: Addressed by enforcing a count of 1 above.
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ use phpseclib3\Math\BigInteger;
|
|||||||
|
|
||||||
class OidcJwtSigningKey
|
class OidcJwtSigningKey
|
||||||
{
|
{
|
||||||
/**
|
protected PublicKey $key;
|
||||||
* @var PublicKey
|
|
||||||
*/
|
|
||||||
protected $key;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be created either from a JWK parameter array or local file path to load a certificate from.
|
* Can be created either from a JWK parameter array or local file path to load a certificate from.
|
||||||
@@ -20,15 +17,13 @@ class OidcJwtSigningKey
|
|||||||
* 'file:///var/www/cert.pem'
|
* 'file:///var/www/cert.pem'
|
||||||
* ['kty' => 'RSA', 'alg' => 'RS256', 'n' => 'abc123...'].
|
* ['kty' => 'RSA', 'alg' => 'RS256', 'n' => 'abc123...'].
|
||||||
*
|
*
|
||||||
* @param array|string $jwkOrKeyPath
|
|
||||||
*
|
|
||||||
* @throws OidcInvalidKeyException
|
* @throws OidcInvalidKeyException
|
||||||
*/
|
*/
|
||||||
public function __construct($jwkOrKeyPath)
|
public function __construct(array|string $jwkOrKeyPath)
|
||||||
{
|
{
|
||||||
if (is_array($jwkOrKeyPath)) {
|
if (is_array($jwkOrKeyPath)) {
|
||||||
$this->loadFromJwkArray($jwkOrKeyPath);
|
$this->loadFromJwkArray($jwkOrKeyPath);
|
||||||
} elseif (is_string($jwkOrKeyPath) && strpos($jwkOrKeyPath, 'file://') === 0) {
|
} elseif (str_starts_with($jwkOrKeyPath, 'file://')) {
|
||||||
$this->loadFromPath($jwkOrKeyPath);
|
$this->loadFromPath($jwkOrKeyPath);
|
||||||
} else {
|
} else {
|
||||||
throw new OidcInvalidKeyException('Unexpected type of key value provided');
|
throw new OidcInvalidKeyException('Unexpected type of key value provided');
|
||||||
@@ -38,7 +33,7 @@ class OidcJwtSigningKey
|
|||||||
/**
|
/**
|
||||||
* @throws OidcInvalidKeyException
|
* @throws OidcInvalidKeyException
|
||||||
*/
|
*/
|
||||||
protected function loadFromPath(string $path)
|
protected function loadFromPath(string $path): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$key = PublicKeyLoader::load(
|
$key = PublicKeyLoader::load(
|
||||||
@@ -58,7 +53,7 @@ class OidcJwtSigningKey
|
|||||||
/**
|
/**
|
||||||
* @throws OidcInvalidKeyException
|
* @throws OidcInvalidKeyException
|
||||||
*/
|
*/
|
||||||
protected function loadFromJwkArray(array $jwk)
|
protected function loadFromJwkArray(array $jwk): void
|
||||||
{
|
{
|
||||||
// 'alg' is optional for a JWK, but we will still attempt to validate if
|
// 'alg' is optional for a JWK, but we will still attempt to validate if
|
||||||
// it exists otherwise presume it will be compatible.
|
// it exists otherwise presume it will be compatible.
|
||||||
@@ -82,7 +77,7 @@ class OidcJwtSigningKey
|
|||||||
throw new OidcInvalidKeyException('A "n" parameter on the provided key is expected');
|
throw new OidcInvalidKeyException('A "n" parameter on the provided key is expected');
|
||||||
}
|
}
|
||||||
|
|
||||||
$n = strtr($jwk['n'] ?? '', '-_', '+/');
|
$n = strtr($jwk['n'], '-_', '+/');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$key = PublicKeyLoader::load([
|
$key = PublicKeyLoader::load([
|
||||||
|
|||||||
174
app/Access/Oidc/OidcJwtWithClaims.php
Normal file
174
app/Access/Oidc/OidcJwtWithClaims.php
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Access\Oidc;
|
||||||
|
|
||||||
|
class OidcJwtWithClaims implements ProvidesClaims
|
||||||
|
{
|
||||||
|
protected array $header;
|
||||||
|
protected array $payload;
|
||||||
|
protected string $signature;
|
||||||
|
protected string $issuer;
|
||||||
|
protected array $tokenParts = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array[]|string[]
|
||||||
|
*/
|
||||||
|
protected array $keys;
|
||||||
|
|
||||||
|
public function __construct(string $token, string $issuer, array $keys)
|
||||||
|
{
|
||||||
|
$this->keys = $keys;
|
||||||
|
$this->issuer = $issuer;
|
||||||
|
$this->parse($token);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the token content into its components.
|
||||||
|
*/
|
||||||
|
protected function parse(string $token): void
|
||||||
|
{
|
||||||
|
$this->tokenParts = explode('.', $token);
|
||||||
|
$this->header = $this->parseEncodedTokenPart($this->tokenParts[0]);
|
||||||
|
$this->payload = $this->parseEncodedTokenPart($this->tokenParts[1] ?? '');
|
||||||
|
$this->signature = $this->base64UrlDecode($this->tokenParts[2] ?? '') ?: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a Base64-JSON encoded token part.
|
||||||
|
* Returns the data as a key-value array or empty array upon error.
|
||||||
|
*/
|
||||||
|
protected function parseEncodedTokenPart(string $part): array
|
||||||
|
{
|
||||||
|
$json = $this->base64UrlDecode($part) ?: '{}';
|
||||||
|
$decoded = json_decode($json, true);
|
||||||
|
|
||||||
|
return is_array($decoded) ? $decoded : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base64URL decode. Needs some character conversions to be compatible
|
||||||
|
* with PHP's default base64 handling.
|
||||||
|
*/
|
||||||
|
protected function base64UrlDecode(string $encoded): string
|
||||||
|
{
|
||||||
|
return base64_decode(strtr($encoded, '-_', '+/'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate common parts of OIDC JWT tokens.
|
||||||
|
*
|
||||||
|
* @throws OidcInvalidTokenException
|
||||||
|
*/
|
||||||
|
public function validateCommonTokenDetails(string $clientId): bool
|
||||||
|
{
|
||||||
|
$this->validateTokenStructure();
|
||||||
|
$this->validateTokenSignature();
|
||||||
|
$this->validateCommonClaims($clientId);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch a specific claim from this token.
|
||||||
|
* Returns null if it is null or does not exist.
|
||||||
|
*/
|
||||||
|
public function getClaim(string $claim): mixed
|
||||||
|
{
|
||||||
|
return $this->payload[$claim] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all returned claims within the token.
|
||||||
|
*/
|
||||||
|
public function getAllClaims(): array
|
||||||
|
{
|
||||||
|
return $this->payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace the existing claim data of this token with that provided.
|
||||||
|
*/
|
||||||
|
public function replaceClaims(array $claims): void
|
||||||
|
{
|
||||||
|
$this->payload = $claims;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the structure of the given token and ensure we have the required pieces.
|
||||||
|
* As per https://datatracker.ietf.org/doc/html/rfc7519#section-7.2.
|
||||||
|
*
|
||||||
|
* @throws OidcInvalidTokenException
|
||||||
|
*/
|
||||||
|
protected function validateTokenStructure(): void
|
||||||
|
{
|
||||||
|
foreach (['header', 'payload'] as $prop) {
|
||||||
|
if (empty($this->$prop)) {
|
||||||
|
throw new OidcInvalidTokenException("Could not parse out a valid {$prop} within the provided token");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($this->signature)) {
|
||||||
|
throw new OidcInvalidTokenException('Could not parse out a valid signature within the provided token');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the signature of the given token and ensure it validates against the provided key.
|
||||||
|
*
|
||||||
|
* @throws OidcInvalidTokenException
|
||||||
|
*/
|
||||||
|
protected function validateTokenSignature(): void
|
||||||
|
{
|
||||||
|
if ($this->header['alg'] !== 'RS256') {
|
||||||
|
throw new OidcInvalidTokenException("Only RS256 signature validation is supported. Token reports using {$this->header['alg']}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$parsedKeys = array_map(function ($key) {
|
||||||
|
try {
|
||||||
|
return new OidcJwtSigningKey($key);
|
||||||
|
} catch (OidcInvalidKeyException $e) {
|
||||||
|
throw new OidcInvalidTokenException('Failed to read signing key with error: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}, $this->keys);
|
||||||
|
|
||||||
|
$parsedKeys = array_filter($parsedKeys);
|
||||||
|
|
||||||
|
$contentToSign = $this->tokenParts[0] . '.' . $this->tokenParts[1];
|
||||||
|
/** @var OidcJwtSigningKey $parsedKey */
|
||||||
|
foreach ($parsedKeys as $parsedKey) {
|
||||||
|
if ($parsedKey->verify($contentToSign, $this->signature)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new OidcInvalidTokenException('Token signature could not be validated using the provided keys');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate common claims for OIDC JWT tokens.
|
||||||
|
* As per https://openid.net/specs/openid-connect-basic-1_0.html#IDTokenValidation
|
||||||
|
* and https://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse
|
||||||
|
*
|
||||||
|
* @throws OidcInvalidTokenException
|
||||||
|
*/
|
||||||
|
protected function validateCommonClaims(string $clientId): void
|
||||||
|
{
|
||||||
|
// 1. The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery)
|
||||||
|
// MUST exactly match the value of the iss (issuer) Claim.
|
||||||
|
if (empty($this->payload['iss']) || $this->issuer !== $this->payload['iss']) {
|
||||||
|
throw new OidcInvalidTokenException('Missing or non-matching token issuer value');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. The Client MUST validate that the aud (audience) Claim contains its client_id value registered
|
||||||
|
// at the Issuer identified by the iss (issuer) Claim as an audience. The ID Token MUST be rejected
|
||||||
|
// if the ID Token does not list the Client as a valid audience.
|
||||||
|
if (empty($this->payload['aud'])) {
|
||||||
|
throw new OidcInvalidTokenException('Missing token audience value');
|
||||||
|
}
|
||||||
|
|
||||||
|
$aud = is_string($this->payload['aud']) ? [$this->payload['aud']] : $this->payload['aud'];
|
||||||
|
if (!in_array($clientId, $aud, true)) {
|
||||||
|
throw new OidcInvalidTokenException('Token audience value did not match the expected client_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,10 +18,10 @@ class OidcProviderSettings
|
|||||||
public string $issuer;
|
public string $issuer;
|
||||||
public string $clientId;
|
public string $clientId;
|
||||||
public string $clientSecret;
|
public string $clientSecret;
|
||||||
public ?string $redirectUri;
|
|
||||||
public ?string $authorizationEndpoint;
|
public ?string $authorizationEndpoint;
|
||||||
public ?string $tokenEndpoint;
|
public ?string $tokenEndpoint;
|
||||||
public ?string $endSessionEndpoint;
|
public ?string $endSessionEndpoint;
|
||||||
|
public ?string $userinfoEndpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[]|array[]
|
* @var string[]|array[]
|
||||||
@@ -37,7 +37,7 @@ class OidcProviderSettings
|
|||||||
/**
|
/**
|
||||||
* Apply an array of settings to populate setting properties within this class.
|
* Apply an array of settings to populate setting properties within this class.
|
||||||
*/
|
*/
|
||||||
protected function applySettingsFromArray(array $settingsArray)
|
protected function applySettingsFromArray(array $settingsArray): void
|
||||||
{
|
{
|
||||||
foreach ($settingsArray as $key => $value) {
|
foreach ($settingsArray as $key => $value) {
|
||||||
if (property_exists($this, $key)) {
|
if (property_exists($this, $key)) {
|
||||||
@@ -51,9 +51,9 @@ class OidcProviderSettings
|
|||||||
*
|
*
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
protected function validateInitial()
|
protected function validateInitial(): void
|
||||||
{
|
{
|
||||||
$required = ['clientId', 'clientSecret', 'redirectUri', 'issuer'];
|
$required = ['clientId', 'clientSecret', 'issuer'];
|
||||||
foreach ($required as $prop) {
|
foreach ($required as $prop) {
|
||||||
if (empty($this->$prop)) {
|
if (empty($this->$prop)) {
|
||||||
throw new InvalidArgumentException("Missing required configuration \"{$prop}\" value");
|
throw new InvalidArgumentException("Missing required configuration \"{$prop}\" value");
|
||||||
@@ -73,12 +73,20 @@ class OidcProviderSettings
|
|||||||
public function validate(): void
|
public function validate(): void
|
||||||
{
|
{
|
||||||
$this->validateInitial();
|
$this->validateInitial();
|
||||||
|
|
||||||
$required = ['keys', 'tokenEndpoint', 'authorizationEndpoint'];
|
$required = ['keys', 'tokenEndpoint', 'authorizationEndpoint'];
|
||||||
foreach ($required as $prop) {
|
foreach ($required as $prop) {
|
||||||
if (empty($this->$prop)) {
|
if (empty($this->$prop)) {
|
||||||
throw new InvalidArgumentException("Missing required configuration \"{$prop}\" value");
|
throw new InvalidArgumentException("Missing required configuration \"{$prop}\" value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$endpointProperties = ['tokenEndpoint', 'authorizationEndpoint', 'userinfoEndpoint'];
|
||||||
|
foreach ($endpointProperties as $prop) {
|
||||||
|
if (is_string($this->$prop) && !str_starts_with($this->$prop, 'https://')) {
|
||||||
|
throw new InvalidArgumentException("Endpoint value for \"{$prop}\" must start with https://");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,7 +94,7 @@ class OidcProviderSettings
|
|||||||
*
|
*
|
||||||
* @throws OidcIssuerDiscoveryException
|
* @throws OidcIssuerDiscoveryException
|
||||||
*/
|
*/
|
||||||
public function discoverFromIssuer(ClientInterface $httpClient, Repository $cache, int $cacheMinutes)
|
public function discoverFromIssuer(ClientInterface $httpClient, Repository $cache, int $cacheMinutes): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$cacheKey = 'oidc-discovery::' . $this->issuer;
|
$cacheKey = 'oidc-discovery::' . $this->issuer;
|
||||||
@@ -128,6 +136,10 @@ class OidcProviderSettings
|
|||||||
$discoveredSettings['tokenEndpoint'] = $result['token_endpoint'];
|
$discoveredSettings['tokenEndpoint'] = $result['token_endpoint'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($result['userinfo_endpoint'])) {
|
||||||
|
$discoveredSettings['userinfoEndpoint'] = $result['userinfo_endpoint'];
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($result['jwks_uri'])) {
|
if (!empty($result['jwks_uri'])) {
|
||||||
$keys = $this->loadKeysFromUri($result['jwks_uri'], $httpClient);
|
$keys = $this->loadKeysFromUri($result['jwks_uri'], $httpClient);
|
||||||
$discoveredSettings['keys'] = $this->filterKeys($keys);
|
$discoveredSettings['keys'] = $this->filterKeys($keys);
|
||||||
@@ -175,9 +187,9 @@ class OidcProviderSettings
|
|||||||
/**
|
/**
|
||||||
* Get the settings needed by an OAuth provider, as a key=>value array.
|
* Get the settings needed by an OAuth provider, as a key=>value array.
|
||||||
*/
|
*/
|
||||||
public function arrayForProvider(): array
|
public function arrayForOAuthProvider(): array
|
||||||
{
|
{
|
||||||
$settingKeys = ['clientId', 'clientSecret', 'redirectUri', 'authorizationEndpoint', 'tokenEndpoint'];
|
$settingKeys = ['clientId', 'clientSecret', 'authorizationEndpoint', 'tokenEndpoint', 'userinfoEndpoint'];
|
||||||
$settings = [];
|
$settings = [];
|
||||||
foreach ($settingKeys as $setting) {
|
foreach ($settingKeys as $setting) {
|
||||||
$settings[$setting] = $this->$setting;
|
$settings[$setting] = $this->$setting;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use BookStack\Exceptions\UserRegistrationException;
|
|||||||
use BookStack\Facades\Theme;
|
use BookStack\Facades\Theme;
|
||||||
use BookStack\Http\HttpRequestService;
|
use BookStack\Http\HttpRequestService;
|
||||||
use BookStack\Theming\ThemeEvents;
|
use BookStack\Theming\ThemeEvents;
|
||||||
|
use BookStack\Uploads\UserAvatars;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use League\OAuth2\Client\OptionProvider\HttpBasicAuthOptionProvider;
|
use League\OAuth2\Client\OptionProvider\HttpBasicAuthOptionProvider;
|
||||||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
||||||
@@ -27,7 +27,8 @@ class OidcService
|
|||||||
protected RegistrationService $registrationService,
|
protected RegistrationService $registrationService,
|
||||||
protected LoginService $loginService,
|
protected LoginService $loginService,
|
||||||
protected HttpRequestService $http,
|
protected HttpRequestService $http,
|
||||||
protected GroupSyncService $groupService
|
protected GroupSyncService $groupService,
|
||||||
|
protected UserAvatars $userAvatars
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +49,11 @@ class OidcService
|
|||||||
$url = $provider->getAuthorizationUrl();
|
$url = $provider->getAuthorizationUrl();
|
||||||
session()->put('oidc_pkce_code', $provider->getPkceCode() ?? '');
|
session()->put('oidc_pkce_code', $provider->getPkceCode() ?? '');
|
||||||
|
|
||||||
|
$returnUrl = Theme::dispatch(ThemeEvents::OIDC_AUTH_PRE_REDIRECT, $url);
|
||||||
|
if (is_string($returnUrl)) {
|
||||||
|
$url = $returnUrl;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'state' => $provider->getState(),
|
'state' => $provider->getState(),
|
||||||
@@ -91,10 +97,10 @@ class OidcService
|
|||||||
'issuer' => $config['issuer'],
|
'issuer' => $config['issuer'],
|
||||||
'clientId' => $config['client_id'],
|
'clientId' => $config['client_id'],
|
||||||
'clientSecret' => $config['client_secret'],
|
'clientSecret' => $config['client_secret'],
|
||||||
'redirectUri' => url('/oidc/callback'),
|
|
||||||
'authorizationEndpoint' => $config['authorization_endpoint'],
|
'authorizationEndpoint' => $config['authorization_endpoint'],
|
||||||
'tokenEndpoint' => $config['token_endpoint'],
|
'tokenEndpoint' => $config['token_endpoint'],
|
||||||
'endSessionEndpoint' => is_string($config['end_session_endpoint']) ? $config['end_session_endpoint'] : null,
|
'endSessionEndpoint' => is_string($config['end_session_endpoint']) ? $config['end_session_endpoint'] : null,
|
||||||
|
'userinfoEndpoint' => $config['userinfo_endpoint'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Use keys if configured
|
// Use keys if configured
|
||||||
@@ -129,7 +135,10 @@ class OidcService
|
|||||||
*/
|
*/
|
||||||
protected function getProvider(OidcProviderSettings $settings): OidcOAuthProvider
|
protected function getProvider(OidcProviderSettings $settings): OidcOAuthProvider
|
||||||
{
|
{
|
||||||
$provider = new OidcOAuthProvider($settings->arrayForProvider(), [
|
$provider = new OidcOAuthProvider([
|
||||||
|
...$settings->arrayForOAuthProvider(),
|
||||||
|
'redirectUri' => url('/oidc/callback'),
|
||||||
|
], [
|
||||||
'httpClient' => $this->http->buildClient(5),
|
'httpClient' => $this->http->buildClient(5),
|
||||||
'optionProvider' => new HttpBasicAuthOptionProvider(),
|
'optionProvider' => new HttpBasicAuthOptionProvider(),
|
||||||
]);
|
]);
|
||||||
@@ -156,69 +165,6 @@ class OidcService
|
|||||||
return array_filter($scopeArr);
|
return array_filter($scopeArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate the display name.
|
|
||||||
*/
|
|
||||||
protected function getUserDisplayName(OidcIdToken $token, string $defaultValue): string
|
|
||||||
{
|
|
||||||
$displayNameAttrString = $this->config()['display_name_claims'] ?? '';
|
|
||||||
$displayNameAttrs = explode('|', $displayNameAttrString);
|
|
||||||
|
|
||||||
$displayName = [];
|
|
||||||
foreach ($displayNameAttrs as $dnAttr) {
|
|
||||||
$dnComponent = $token->getClaim($dnAttr) ?? '';
|
|
||||||
if ($dnComponent !== '') {
|
|
||||||
$displayName[] = $dnComponent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($displayName) == 0) {
|
|
||||||
$displayName[] = $defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return implode(' ', $displayName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract the assigned groups from the id token.
|
|
||||||
*
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
protected function getUserGroups(OidcIdToken $token): array
|
|
||||||
{
|
|
||||||
$groupsAttr = $this->config()['groups_claim'];
|
|
||||||
if (empty($groupsAttr)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$groupsList = Arr::get($token->getAllClaims(), $groupsAttr);
|
|
||||||
if (!is_array($groupsList)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_values(array_filter($groupsList, function ($val) {
|
|
||||||
return is_string($val);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract the details of a user from an ID token.
|
|
||||||
*
|
|
||||||
* @return array{name: string, email: string, external_id: string, groups: string[]}
|
|
||||||
*/
|
|
||||||
protected function getUserDetails(OidcIdToken $token): array
|
|
||||||
{
|
|
||||||
$idClaim = $this->config()['external_id_claim'];
|
|
||||||
$id = $token->getClaim($idClaim);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'external_id' => $id,
|
|
||||||
'email' => $token->getClaim('email'),
|
|
||||||
'name' => $this->getUserDisplayName($token, $id),
|
|
||||||
'groups' => $this->getUserGroups($token),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a received access token for a user. Login the user when
|
* Processes a received access token for a user. Login the user when
|
||||||
* they exist, optionally registering them automatically.
|
* they exist, optionally registering them automatically.
|
||||||
@@ -255,34 +201,39 @@ class OidcService
|
|||||||
try {
|
try {
|
||||||
$idToken->validate($settings->clientId);
|
$idToken->validate($settings->clientId);
|
||||||
} catch (OidcInvalidTokenException $exception) {
|
} catch (OidcInvalidTokenException $exception) {
|
||||||
throw new OidcException("ID token validate failed with error: {$exception->getMessage()}");
|
throw new OidcException("ID token validation failed with error: {$exception->getMessage()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$userDetails = $this->getUserDetails($idToken);
|
$userDetails = $this->getUserDetailsFromToken($idToken, $accessToken, $settings);
|
||||||
$isLoggedIn = auth()->check();
|
if (empty($userDetails->email)) {
|
||||||
|
|
||||||
if (empty($userDetails['email'])) {
|
|
||||||
throw new OidcException(trans('errors.oidc_no_email_address'));
|
throw new OidcException(trans('errors.oidc_no_email_address'));
|
||||||
}
|
}
|
||||||
|
if (empty($userDetails->name)) {
|
||||||
|
$userDetails->name = $userDetails->externalId;
|
||||||
|
}
|
||||||
|
|
||||||
|
$isLoggedIn = auth()->check();
|
||||||
if ($isLoggedIn) {
|
if ($isLoggedIn) {
|
||||||
throw new OidcException(trans('errors.oidc_already_logged_in'));
|
throw new OidcException(trans('errors.oidc_already_logged_in'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$user = $this->registrationService->findOrRegister(
|
$user = $this->registrationService->findOrRegister(
|
||||||
$userDetails['name'],
|
$userDetails->name,
|
||||||
$userDetails['email'],
|
$userDetails->email,
|
||||||
$userDetails['external_id']
|
$userDetails->externalId
|
||||||
);
|
);
|
||||||
} catch (UserRegistrationException $exception) {
|
} catch (UserRegistrationException $exception) {
|
||||||
throw new OidcException($exception->getMessage());
|
throw new OidcException($exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->config()['fetch_avatar'] && !$user->avatar()->exists() && $userDetails->picture) {
|
||||||
|
$this->userAvatars->assignToUserFromUrl($user, $userDetails->picture);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->shouldSyncGroups()) {
|
if ($this->shouldSyncGroups()) {
|
||||||
$groups = $userDetails['groups'];
|
|
||||||
$detachExisting = $this->config()['remove_from_groups'];
|
$detachExisting = $this->config()['remove_from_groups'];
|
||||||
$this->groupService->syncUserWithFoundGroups($user, $groups, $detachExisting);
|
$this->groupService->syncUserWithFoundGroups($user, $userDetails->groups ?? [], $detachExisting);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->loginService->login($user, 'oidc');
|
$this->loginService->login($user, 'oidc');
|
||||||
@@ -290,6 +241,45 @@ class OidcService
|
|||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws OidcException
|
||||||
|
*/
|
||||||
|
protected function getUserDetailsFromToken(OidcIdToken $idToken, OidcAccessToken $accessToken, OidcProviderSettings $settings): OidcUserDetails
|
||||||
|
{
|
||||||
|
$userDetails = new OidcUserDetails();
|
||||||
|
$userDetails->populate(
|
||||||
|
$idToken,
|
||||||
|
$this->config()['external_id_claim'],
|
||||||
|
$this->config()['display_name_claims'] ?? '',
|
||||||
|
$this->config()['groups_claim'] ?? ''
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$userDetails->isFullyPopulated($this->shouldSyncGroups()) && !empty($settings->userinfoEndpoint)) {
|
||||||
|
$provider = $this->getProvider($settings);
|
||||||
|
$request = $provider->getAuthenticatedRequest('GET', $settings->userinfoEndpoint, $accessToken->getToken());
|
||||||
|
$response = new OidcUserinfoResponse(
|
||||||
|
$provider->getResponse($request),
|
||||||
|
$settings->issuer,
|
||||||
|
$settings->keys,
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response->validate($idToken->getClaim('sub'), $settings->clientId);
|
||||||
|
} catch (OidcInvalidTokenException $exception) {
|
||||||
|
throw new OidcException("Userinfo endpoint response validation failed with error: {$exception->getMessage()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$userDetails->populate(
|
||||||
|
$response,
|
||||||
|
$this->config()['external_id_claim'],
|
||||||
|
$this->config()['display_name_claims'] ?? '',
|
||||||
|
$this->config()['groups_claim'] ?? ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $userDetails;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the OIDC config from the application.
|
* Get the OIDC config from the application.
|
||||||
*/
|
*/
|
||||||
|
|||||||
87
app/Access/Oidc/OidcUserDetails.php
Normal file
87
app/Access/Oidc/OidcUserDetails.php
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Access\Oidc;
|
||||||
|
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
|
class OidcUserDetails
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public ?string $externalId = null,
|
||||||
|
public ?string $email = null,
|
||||||
|
public ?string $name = null,
|
||||||
|
public ?array $groups = null,
|
||||||
|
public ?string $picture = null,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the user details are fully populated for our usage.
|
||||||
|
*/
|
||||||
|
public function isFullyPopulated(bool $groupSyncActive): bool
|
||||||
|
{
|
||||||
|
$hasEmpty = empty($this->externalId)
|
||||||
|
|| empty($this->email)
|
||||||
|
|| empty($this->name)
|
||||||
|
|| ($groupSyncActive && $this->groups === null);
|
||||||
|
|
||||||
|
return !$hasEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populate user details from the given claim data.
|
||||||
|
*/
|
||||||
|
public function populate(
|
||||||
|
ProvidesClaims $claims,
|
||||||
|
string $idClaim,
|
||||||
|
string $displayNameClaims,
|
||||||
|
string $groupsClaim,
|
||||||
|
): void {
|
||||||
|
$this->externalId = $claims->getClaim($idClaim) ?? $this->externalId;
|
||||||
|
$this->email = $claims->getClaim('email') ?? $this->email;
|
||||||
|
$this->name = static::getUserDisplayName($displayNameClaims, $claims) ?: $this->name;
|
||||||
|
$this->groups = static::getUserGroups($groupsClaim, $claims) ?? $this->groups;
|
||||||
|
$this->picture = static::getPicture($claims) ?: $this->picture;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function getUserDisplayName(string $displayNameClaims, ProvidesClaims $claims): string
|
||||||
|
{
|
||||||
|
$displayNameClaimParts = explode('|', $displayNameClaims);
|
||||||
|
|
||||||
|
$displayName = [];
|
||||||
|
foreach ($displayNameClaimParts as $claim) {
|
||||||
|
$component = $claims->getClaim(trim($claim)) ?? '';
|
||||||
|
if ($component !== '') {
|
||||||
|
$displayName[] = $component;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(' ', $displayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function getUserGroups(string $groupsClaim, ProvidesClaims $claims): ?array
|
||||||
|
{
|
||||||
|
if (empty($groupsClaim)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$groupsList = Arr::get($claims->getAllClaims(), $groupsClaim);
|
||||||
|
if (!is_array($groupsList)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_filter($groupsList, function ($val) {
|
||||||
|
return is_string($val);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function getPicture(ProvidesClaims $claims): ?string
|
||||||
|
{
|
||||||
|
$picture = $claims->getClaim('picture');
|
||||||
|
if (is_string($picture) && str_starts_with($picture, 'http')) {
|
||||||
|
return $picture;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
69
app/Access/Oidc/OidcUserinfoResponse.php
Normal file
69
app/Access/Oidc/OidcUserinfoResponse.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Access\Oidc;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
class OidcUserinfoResponse implements ProvidesClaims
|
||||||
|
{
|
||||||
|
protected array $claims = [];
|
||||||
|
protected ?OidcJwtWithClaims $jwt = null;
|
||||||
|
|
||||||
|
public function __construct(ResponseInterface $response, string $issuer, array $keys)
|
||||||
|
{
|
||||||
|
$contentTypeHeaderValue = $response->getHeader('Content-Type')[0] ?? '';
|
||||||
|
$contentType = strtolower(trim(explode(';', $contentTypeHeaderValue, 2)[0]));
|
||||||
|
|
||||||
|
if ($contentType === 'application/json') {
|
||||||
|
$this->claims = json_decode($response->getBody()->getContents(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($contentType === 'application/jwt') {
|
||||||
|
$this->jwt = new OidcJwtWithClaims($response->getBody()->getContents(), $issuer, $keys);
|
||||||
|
$this->claims = $this->jwt->getAllClaims();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws OidcInvalidTokenException
|
||||||
|
*/
|
||||||
|
public function validate(string $idTokenSub, string $clientId): bool
|
||||||
|
{
|
||||||
|
if (!is_null($this->jwt)) {
|
||||||
|
$this->jwt->validateCommonTokenDetails($clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sub = $this->getClaim('sub');
|
||||||
|
|
||||||
|
// Spec: v1.0 5.3.2: The sub (subject) Claim MUST always be returned in the UserInfo Response.
|
||||||
|
if (!is_string($sub) || empty($sub)) {
|
||||||
|
throw new OidcInvalidTokenException("No valid subject value found in userinfo data");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spec: v1.0 5.3.2: The sub Claim in the UserInfo Response MUST be verified to exactly match the sub Claim in the ID Token;
|
||||||
|
// if they do not match, the UserInfo Response values MUST NOT be used.
|
||||||
|
if ($idTokenSub !== $sub) {
|
||||||
|
throw new OidcInvalidTokenException("Subject value provided in the userinfo endpoint does not match the provided ID token value");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spec v1.0 5.3.4 Defines the following:
|
||||||
|
// Verify that the OP that responded was the intended OP through a TLS server certificate check, per RFC 6125 [RFC6125].
|
||||||
|
// This is effectively done as part of the HTTP request we're making through CURLOPT_SSL_VERIFYHOST on the request.
|
||||||
|
// If the Client has provided a userinfo_encrypted_response_alg parameter during Registration, decrypt the UserInfo Response using the keys specified during Registration.
|
||||||
|
// We don't currently support JWT encryption for OIDC
|
||||||
|
// If the response was signed, the Client SHOULD validate the signature according to JWS [JWS].
|
||||||
|
// This is done as part of the validateCommonClaims above.
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClaim(string $claim): mixed
|
||||||
|
{
|
||||||
|
return $this->claims[$claim] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllClaims(): array
|
||||||
|
{
|
||||||
|
return $this->claims;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
app/Access/Oidc/ProvidesClaims.php
Normal file
17
app/Access/Oidc/ProvidesClaims.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Access\Oidc;
|
||||||
|
|
||||||
|
interface ProvidesClaims
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Fetch a specific claim.
|
||||||
|
* Returns null if it is null or does not exist.
|
||||||
|
*/
|
||||||
|
public function getClaim(string $claim): mixed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all contained claims.
|
||||||
|
*/
|
||||||
|
public function getAllClaims(): array;
|
||||||
|
}
|
||||||
@@ -83,7 +83,7 @@ class RegistrationService
|
|||||||
// Email restriction
|
// Email restriction
|
||||||
$this->ensureEmailDomainAllowed($userEmail);
|
$this->ensureEmailDomainAllowed($userEmail);
|
||||||
|
|
||||||
// Ensure user does not already exist
|
// Ensure the user does not already exist
|
||||||
$alreadyUser = !is_null($this->userRepo->getByEmail($userEmail));
|
$alreadyUser = !is_null($this->userRepo->getByEmail($userEmail));
|
||||||
if ($alreadyUser) {
|
if ($alreadyUser) {
|
||||||
throw new UserRegistrationException(trans('errors.error_user_exists_different_creds', ['email' => $userEmail]), '/login');
|
throw new UserRegistrationException(trans('errors.error_user_exists_different_creds', ['email' => $userEmail]), '/login');
|
||||||
@@ -99,7 +99,7 @@ class RegistrationService
|
|||||||
$newUser = $this->userRepo->createWithoutActivity($userData, $emailConfirmed);
|
$newUser = $this->userRepo->createWithoutActivity($userData, $emailConfirmed);
|
||||||
$newUser->attachDefaultRole();
|
$newUser->attachDefaultRole();
|
||||||
|
|
||||||
// Assign social account if given
|
// Assign a social account if given
|
||||||
if ($socialAccount) {
|
if ($socialAccount) {
|
||||||
$newUser->socialAccounts()->save($socialAccount);
|
$newUser->socialAccounts()->save($socialAccount);
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ class RegistrationService
|
|||||||
Activity::add(ActivityType::AUTH_REGISTER, $socialAccount ?? $newUser);
|
Activity::add(ActivityType::AUTH_REGISTER, $socialAccount ?? $newUser);
|
||||||
Theme::dispatch(ThemeEvents::AUTH_REGISTER, $authSystem, $newUser);
|
Theme::dispatch(ThemeEvents::AUTH_REGISTER, $authSystem, $newUser);
|
||||||
|
|
||||||
// Start email confirmation flow if required
|
// Start the email confirmation flow if required
|
||||||
if ($this->emailConfirmationService->confirmationRequired() && !$emailConfirmed) {
|
if ($this->emailConfirmationService->confirmationRequired() && !$emailConfirmed) {
|
||||||
$newUser->save();
|
$newUser->save();
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class Saml2Service
|
|||||||
* Returns the SAML2 request ID, and the URL to redirect the user to.
|
* Returns the SAML2 request ID, and the URL to redirect the user to.
|
||||||
*
|
*
|
||||||
* @throws Error
|
* @throws Error
|
||||||
* @returns array{url: string, id: ?string}
|
* @return array{url: string, id: ?string}
|
||||||
*/
|
*/
|
||||||
public function logout(User $user): array
|
public function logout(User $user): array
|
||||||
{
|
{
|
||||||
@@ -133,6 +133,7 @@ class Saml2Service
|
|||||||
// value so that the exact encoding format is matched when checking the signature.
|
// value so that the exact encoding format is matched when checking the signature.
|
||||||
// This is primarily due to ADFS encoding query params with lowercase percent encoding while
|
// This is primarily due to ADFS encoding query params with lowercase percent encoding while
|
||||||
// PHP (And most other sensible providers) standardise on uppercase.
|
// PHP (And most other sensible providers) standardise on uppercase.
|
||||||
|
/** @var ?string $samlRedirect */
|
||||||
$samlRedirect = $toolkit->processSLO(true, $requestId, true, null, true);
|
$samlRedirect = $toolkit->processSLO(true, $requestId, true, null, true);
|
||||||
$errors = $toolkit->getErrors();
|
$errors = $toolkit->getErrors();
|
||||||
|
|
||||||
@@ -265,7 +266,7 @@ class Saml2Service
|
|||||||
/**
|
/**
|
||||||
* Extract the details of a user from a SAML response.
|
* Extract the details of a user from a SAML response.
|
||||||
*
|
*
|
||||||
* @return array{external_id: string, name: string, email: string, saml_id: string}
|
* @return array{external_id: string, name: string, email: string|null, saml_id: string}
|
||||||
*/
|
*/
|
||||||
protected function getUserDetails(string $samlID, $samlAttributes): array
|
protected function getUserDetails(string $samlID, $samlAttributes): array
|
||||||
{
|
{
|
||||||
@@ -356,7 +357,7 @@ class Saml2Service
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($userDetails['email'] === null) {
|
if (empty($userDetails['email'])) {
|
||||||
throw new SamlException(trans('errors.saml_no_email_address'));
|
throw new SamlException(trans('errors.saml_no_email_address'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,18 +5,23 @@ namespace BookStack\Access;
|
|||||||
use BookStack\Activity\Models\Loggable;
|
use BookStack\Activity\Models\Loggable;
|
||||||
use BookStack\App\Model;
|
use BookStack\App\Model;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SocialAccount.
|
|
||||||
*
|
|
||||||
* @property string $driver
|
* @property string $driver
|
||||||
* @property User $user
|
* @property User $user
|
||||||
*/
|
*/
|
||||||
class SocialAccount extends Model implements Loggable
|
class SocialAccount extends Model implements Loggable
|
||||||
{
|
{
|
||||||
protected $fillable = ['user_id', 'driver', 'driver_id', 'timestamps'];
|
use HasFactory;
|
||||||
|
|
||||||
public function user()
|
protected $fillable = ['user_id', 'driver', 'driver_id'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<User, $this>
|
||||||
|
*/
|
||||||
|
public function user(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,14 +117,14 @@ class SocialAuthService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When a user is logged in and the social account exists and is already linked to the current user.
|
// When a user is logged in and the social account exists and is already linked to the current user.
|
||||||
if ($isLoggedIn && $socialAccount !== null && $socialAccount->user->id === $currentUser->id) {
|
if ($isLoggedIn && $socialAccount->user->id === $currentUser->id) {
|
||||||
session()->flash('error', trans('errors.social_account_existing', ['socialAccount' => $titleCaseDriver]));
|
session()->flash('error', trans('errors.social_account_existing', ['socialAccount' => $titleCaseDriver]));
|
||||||
|
|
||||||
return redirect('/my-account/auth#social_accounts');
|
return redirect('/my-account/auth#social_accounts');
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a user is logged in, A social account exists but the users do not match.
|
// When a user is logged in, A social account exists but the users do not match.
|
||||||
if ($isLoggedIn && $socialAccount !== null && $socialAccount->user->id != $currentUser->id) {
|
if ($isLoggedIn && $socialAccount->user->id != $currentUser->id) {
|
||||||
session()->flash('error', trans('errors.social_account_already_used_existing', ['socialAccount' => $titleCaseDriver]));
|
session()->flash('error', trans('errors.social_account_already_used_existing', ['socialAccount' => $titleCaseDriver]));
|
||||||
|
|
||||||
return redirect('/my-account/auth#social_accounts');
|
return redirect('/my-account/auth#social_accounts');
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class SocialDriverManager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the names of the active social drivers, keyed by driver id.
|
* Gets the names of the active social drivers, keyed by driver id.
|
||||||
* @returns array<string, string>
|
* @return array<string, string>
|
||||||
*/
|
*/
|
||||||
public function getActive(): array
|
public function getActive(): array
|
||||||
{
|
{
|
||||||
@@ -92,7 +92,7 @@ class SocialDriverManager
|
|||||||
string $driverName,
|
string $driverName,
|
||||||
array $config,
|
array $config,
|
||||||
string $socialiteHandler,
|
string $socialiteHandler,
|
||||||
callable $configureForRedirect = null
|
?callable $configureForRedirect = null
|
||||||
) {
|
) {
|
||||||
$this->validDrivers[] = $driverName;
|
$this->validDrivers[] = $driverName;
|
||||||
config()->set('services.' . $driverName, $config);
|
config()->set('services.' . $driverName, $config);
|
||||||
|
|||||||
10
app/Access/UserInviteException.php
Normal file
10
app/Access/UserInviteException.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Access;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class UserInviteException extends Exception
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -13,11 +13,17 @@ class UserInviteService extends UserTokenService
|
|||||||
/**
|
/**
|
||||||
* Send an invitation to a user to sign into BookStack
|
* Send an invitation to a user to sign into BookStack
|
||||||
* Removes existing invitation tokens.
|
* Removes existing invitation tokens.
|
||||||
|
* @throws UserInviteException
|
||||||
*/
|
*/
|
||||||
public function sendInvitation(User $user)
|
public function sendInvitation(User $user)
|
||||||
{
|
{
|
||||||
$this->deleteByUser($user);
|
$this->deleteByUser($user);
|
||||||
$token = $this->createTokenForUser($user);
|
$token = $this->createTokenForUser($user);
|
||||||
$user->notify(new UserInviteNotification($token));
|
|
||||||
|
try {
|
||||||
|
$user->notify(new UserInviteNotification($token));
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
throw new UserInviteException($exception->getMessage(), $exception->getCode(), $exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use BookStack\Entities\Tools\MixedEntityListLoader;
|
|||||||
use BookStack\Permissions\PermissionApplicator;
|
use BookStack\Permissions\PermissionApplicator;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
|
|
||||||
class ActivityQueries
|
class ActivityQueries
|
||||||
@@ -27,14 +28,14 @@ class ActivityQueries
|
|||||||
public function latest(int $count = 20, int $page = 0): array
|
public function latest(int $count = 20, int $page = 0): array
|
||||||
{
|
{
|
||||||
$activityList = $this->permissions
|
$activityList = $this->permissions
|
||||||
->restrictEntityRelationQuery(Activity::query(), 'activities', 'entity_id', 'entity_type')
|
->restrictEntityRelationQuery(Activity::query(), 'activities', 'loggable_id', 'loggable_type')
|
||||||
->orderBy('created_at', 'desc')
|
->orderBy('created_at', 'desc')
|
||||||
->with(['user'])
|
->with(['user'])
|
||||||
->skip($count * $page)
|
->skip($count * $page)
|
||||||
->take($count)
|
->take($count)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$this->listLoader->loadIntoRelations($activityList->all(), 'entity', false);
|
$this->listLoader->loadIntoRelations($activityList->all(), 'loggable', false);
|
||||||
|
|
||||||
return $this->filterSimilar($activityList);
|
return $this->filterSimilar($activityList);
|
||||||
}
|
}
|
||||||
@@ -59,14 +60,15 @@ class ActivityQueries
|
|||||||
$query->where(function (Builder $query) use ($queryIds) {
|
$query->where(function (Builder $query) use ($queryIds) {
|
||||||
foreach ($queryIds as $morphClass => $idArr) {
|
foreach ($queryIds as $morphClass => $idArr) {
|
||||||
$query->orWhere(function (Builder $innerQuery) use ($morphClass, $idArr) {
|
$query->orWhere(function (Builder $innerQuery) use ($morphClass, $idArr) {
|
||||||
$innerQuery->where('entity_type', '=', $morphClass)
|
$innerQuery->where('loggable_type', '=', $morphClass)
|
||||||
->whereIn('entity_id', $idArr);
|
->whereIn('loggable_id', $idArr);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$activity = $query->orderBy('created_at', 'desc')
|
$activity = $query->orderBy('created_at', 'desc')
|
||||||
->with(['entity' => function (Relation $query) {
|
->with(['loggable' => function (Relation $query) {
|
||||||
|
/** @var MorphTo<Entity, Activity> $query */
|
||||||
$query->withTrashed();
|
$query->withTrashed();
|
||||||
}, 'user.avatar'])
|
}, 'user.avatar'])
|
||||||
->skip($count * ($page - 1))
|
->skip($count * ($page - 1))
|
||||||
@@ -82,7 +84,7 @@ class ActivityQueries
|
|||||||
public function userActivity(User $user, int $count = 20, int $page = 0): array
|
public function userActivity(User $user, int $count = 20, int $page = 0): array
|
||||||
{
|
{
|
||||||
$activityList = $this->permissions
|
$activityList = $this->permissions
|
||||||
->restrictEntityRelationQuery(Activity::query(), 'activities', 'entity_id', 'entity_type')
|
->restrictEntityRelationQuery(Activity::query(), 'activities', 'loggable_id', 'loggable_type')
|
||||||
->orderBy('created_at', 'desc')
|
->orderBy('created_at', 'desc')
|
||||||
->where('user_id', '=', $user->id)
|
->where('user_id', '=', $user->id)
|
||||||
->skip($count * $page)
|
->skip($count * $page)
|
||||||
|
|||||||
@@ -67,6 +67,14 @@ class ActivityType
|
|||||||
const WEBHOOK_UPDATE = 'webhook_update';
|
const WEBHOOK_UPDATE = 'webhook_update';
|
||||||
const WEBHOOK_DELETE = 'webhook_delete';
|
const WEBHOOK_DELETE = 'webhook_delete';
|
||||||
|
|
||||||
|
const IMPORT_CREATE = 'import_create';
|
||||||
|
const IMPORT_RUN = 'import_run';
|
||||||
|
const IMPORT_DELETE = 'import_delete';
|
||||||
|
|
||||||
|
const SORT_RULE_CREATE = 'sort_rule_create';
|
||||||
|
const SORT_RULE_UPDATE = 'sort_rule_update';
|
||||||
|
const SORT_RULE_DELETE = 'sort_rule_delete';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the possible values.
|
* Get all the possible values.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ namespace BookStack\Activity;
|
|||||||
|
|
||||||
use BookStack\Activity\Models\Comment;
|
use BookStack\Activity\Models\Comment;
|
||||||
use BookStack\Entities\Models\Entity;
|
use BookStack\Entities\Models\Entity;
|
||||||
|
use BookStack\Entities\Models\Page;
|
||||||
|
use BookStack\Exceptions\NotifyException;
|
||||||
use BookStack\Facades\Activity as ActivityService;
|
use BookStack\Facades\Activity as ActivityService;
|
||||||
use BookStack\Util\HtmlDescriptionFilter;
|
use BookStack\Util\HtmlDescriptionFilter;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
class CommentRepo
|
class CommentRepo
|
||||||
{
|
{
|
||||||
@@ -17,11 +20,46 @@ class CommentRepo
|
|||||||
return Comment::query()->findOrFail($id);
|
return Comment::query()->findOrFail($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a comment by ID, ensuring it is visible to the user based upon access to the page
|
||||||
|
* which the comment is attached to.
|
||||||
|
*/
|
||||||
|
public function getVisibleById(int $id): Comment
|
||||||
|
{
|
||||||
|
return $this->getQueryForVisible()->findOrFail($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start a query for comments visible to the user.
|
||||||
|
* @return Builder<Comment>
|
||||||
|
*/
|
||||||
|
public function getQueryForVisible(): Builder
|
||||||
|
{
|
||||||
|
return Comment::query()->scopes('visible');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new comment on an entity.
|
* Create a new comment on an entity.
|
||||||
*/
|
*/
|
||||||
public function create(Entity $entity, string $html, ?int $parent_id): Comment
|
public function create(Entity $entity, string $html, ?int $parentId, string $contentRef): Comment
|
||||||
{
|
{
|
||||||
|
// Prevent comments being added to draft pages
|
||||||
|
if ($entity instanceof Page && $entity->draft) {
|
||||||
|
throw new \Exception(trans('errors.cannot_add_comment_to_draft'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate parent ID
|
||||||
|
if ($parentId !== null) {
|
||||||
|
$parentCommentExists = Comment::query()
|
||||||
|
->where('commentable_id', '=', $entity->id)
|
||||||
|
->where('commentable_type', '=', $entity->getMorphClass())
|
||||||
|
->where('local_id', '=', $parentId)
|
||||||
|
->exists();
|
||||||
|
if (!$parentCommentExists) {
|
||||||
|
$parentId = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$userId = user()->id;
|
$userId = user()->id;
|
||||||
$comment = new Comment();
|
$comment = new Comment();
|
||||||
|
|
||||||
@@ -29,12 +67,14 @@ class CommentRepo
|
|||||||
$comment->created_by = $userId;
|
$comment->created_by = $userId;
|
||||||
$comment->updated_by = $userId;
|
$comment->updated_by = $userId;
|
||||||
$comment->local_id = $this->getNextLocalId($entity);
|
$comment->local_id = $this->getNextLocalId($entity);
|
||||||
$comment->parent_id = $parent_id;
|
$comment->parent_id = $parentId;
|
||||||
|
$comment->content_ref = preg_match('/^bkmrk-(.*?):\d+:(\d*-\d*)?$/', $contentRef) === 1 ? $contentRef : '';
|
||||||
|
|
||||||
$entity->comments()->save($comment);
|
$entity->comments()->save($comment);
|
||||||
ActivityService::add(ActivityType::COMMENT_CREATE, $comment);
|
ActivityService::add(ActivityType::COMMENT_CREATE, $comment);
|
||||||
ActivityService::add(ActivityType::COMMENTED_ON, $entity);
|
ActivityService::add(ActivityType::COMMENTED_ON, $entity);
|
||||||
|
|
||||||
|
$comment->refresh()->unsetRelations();
|
||||||
return $comment;
|
return $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +92,45 @@ class CommentRepo
|
|||||||
return $comment;
|
return $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Archive an existing comment.
|
||||||
|
*/
|
||||||
|
public function archive(Comment $comment, bool $log = true): Comment
|
||||||
|
{
|
||||||
|
if ($comment->parent_id) {
|
||||||
|
throw new NotifyException('Only top-level comments can be archived.', '/', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$comment->archived = true;
|
||||||
|
$comment->save();
|
||||||
|
|
||||||
|
if ($log) {
|
||||||
|
ActivityService::add(ActivityType::COMMENT_UPDATE, $comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Un-archive an existing comment.
|
||||||
|
*/
|
||||||
|
public function unarchive(Comment $comment, bool $log = true): Comment
|
||||||
|
{
|
||||||
|
if ($comment->parent_id) {
|
||||||
|
throw new NotifyException('Only top-level comments can be un-archived.', '/', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$comment->archived = false;
|
||||||
|
$comment->save();
|
||||||
|
|
||||||
|
if ($log) {
|
||||||
|
ActivityService::add(ActivityType::COMMENT_UPDATE, $comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $comment;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a comment from the system.
|
* Delete a comment from the system.
|
||||||
*/
|
*/
|
||||||
|
|||||||
29
app/Activity/Controllers/AuditLogApiController.php
Normal file
29
app/Activity/Controllers/AuditLogApiController.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Activity\Controllers;
|
||||||
|
|
||||||
|
use BookStack\Activity\Models\Activity;
|
||||||
|
use BookStack\Http\ApiController;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
|
|
||||||
|
class AuditLogApiController extends ApiController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get a listing of audit log events in the system.
|
||||||
|
* The loggable relation fields currently only relates to core
|
||||||
|
* content types (page, book, bookshelf, chapter) but this may be
|
||||||
|
* used more in the future across other types.
|
||||||
|
* Requires permission to manage both users and system settings.
|
||||||
|
*/
|
||||||
|
public function list()
|
||||||
|
{
|
||||||
|
$this->checkPermission(Permission::SettingsManage);
|
||||||
|
$this->checkPermission(Permission::UsersManage);
|
||||||
|
|
||||||
|
$query = Activity::query()->with(['user']);
|
||||||
|
|
||||||
|
return $this->apiListingResponse($query, [
|
||||||
|
'id', 'type', 'detail', 'user_id', 'loggable_id', 'loggable_type', 'ip', 'created_at',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ namespace BookStack\Activity\Controllers;
|
|||||||
use BookStack\Activity\ActivityType;
|
use BookStack\Activity\ActivityType;
|
||||||
use BookStack\Activity\Models\Activity;
|
use BookStack\Activity\Models\Activity;
|
||||||
use BookStack\Http\Controller;
|
use BookStack\Http\Controller;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
|
use BookStack\Sorting\SortUrl;
|
||||||
use BookStack\Util\SimpleListOptions;
|
use BookStack\Util\SimpleListOptions;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
@@ -12,27 +14,27 @@ class AuditLogController extends Controller
|
|||||||
{
|
{
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->checkPermission('settings-manage');
|
$this->checkPermission(Permission::SettingsManage);
|
||||||
$this->checkPermission('users-manage');
|
$this->checkPermission(Permission::UsersManage);
|
||||||
|
|
||||||
$sort = $request->get('sort', 'activity_date');
|
$sort = $request->input('sort', 'activity_date');
|
||||||
$order = $request->get('order', 'desc');
|
$order = $request->input('order', 'desc');
|
||||||
$listOptions = (new SimpleListOptions('', $sort, $order))->withSortOptions([
|
$listOptions = (new SimpleListOptions('', $sort, $order))->withSortOptions([
|
||||||
'created_at' => trans('settings.audit_table_date'),
|
'created_at' => trans('settings.audit_table_date'),
|
||||||
'type' => trans('settings.audit_table_event'),
|
'type' => trans('settings.audit_table_event'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$filters = [
|
$filters = [
|
||||||
'event' => $request->get('event', ''),
|
'event' => $request->input('event', ''),
|
||||||
'date_from' => $request->get('date_from', ''),
|
'date_from' => $request->input('date_from', ''),
|
||||||
'date_to' => $request->get('date_to', ''),
|
'date_to' => $request->input('date_to', ''),
|
||||||
'user' => $request->get('user', ''),
|
'user' => $request->input('user', ''),
|
||||||
'ip' => $request->get('ip', ''),
|
'ip' => $request->input('ip', ''),
|
||||||
];
|
];
|
||||||
|
|
||||||
$query = Activity::query()
|
$query = Activity::query()
|
||||||
->with([
|
->with([
|
||||||
'entity' => fn ($query) => $query->withTrashed(),
|
'loggable' => fn ($query) => $query->withTrashed(),
|
||||||
'user',
|
'user',
|
||||||
])
|
])
|
||||||
->orderBy($listOptions->getSort(), $listOptions->getOrder());
|
->orderBy($listOptions->getSort(), $listOptions->getOrder());
|
||||||
@@ -65,6 +67,7 @@ class AuditLogController extends Controller
|
|||||||
'filters' => $filters,
|
'filters' => $filters,
|
||||||
'listOptions' => $listOptions,
|
'listOptions' => $listOptions,
|
||||||
'activityTypes' => $types,
|
'activityTypes' => $types,
|
||||||
|
'filterSortUrl' => new SortUrl('settings/audit', array_filter($request->except('page')))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
148
app/Activity/Controllers/CommentApiController.php
Normal file
148
app/Activity/Controllers/CommentApiController.php
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace BookStack\Activity\Controllers;
|
||||||
|
|
||||||
|
use BookStack\Activity\CommentRepo;
|
||||||
|
use BookStack\Activity\Models\Comment;
|
||||||
|
use BookStack\Entities\Queries\PageQueries;
|
||||||
|
use BookStack\Http\ApiController;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The comment data model has a 'local_id' property, which is a unique integer ID
|
||||||
|
* scoped to the page which the comment is on. The 'parent_id' is used for replies
|
||||||
|
* and refers to the 'local_id' of the parent comment on the same page, not the main
|
||||||
|
* globally unique 'id'.
|
||||||
|
*
|
||||||
|
* If you want to get all comments for a page in a tree-like structure, as reflected in
|
||||||
|
* the UI, then that is provided on pages-read API responses.
|
||||||
|
*/
|
||||||
|
class CommentApiController extends ApiController
|
||||||
|
{
|
||||||
|
protected array $rules = [
|
||||||
|
'create' => [
|
||||||
|
'page_id' => ['required', 'integer'],
|
||||||
|
'reply_to' => ['nullable', 'integer'],
|
||||||
|
'html' => ['required', 'string'],
|
||||||
|
'content_ref' => ['string'],
|
||||||
|
],
|
||||||
|
'update' => [
|
||||||
|
'html' => ['string'],
|
||||||
|
'archived' => ['boolean'],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected CommentRepo $commentRepo,
|
||||||
|
protected PageQueries $pageQueries,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a listing of comments visible to the user.
|
||||||
|
*/
|
||||||
|
public function list(): JsonResponse
|
||||||
|
{
|
||||||
|
$query = $this->commentRepo->getQueryForVisible();
|
||||||
|
|
||||||
|
return $this->apiListingResponse($query, [
|
||||||
|
'id', 'commentable_id', 'commentable_type', 'parent_id', 'local_id', 'content_ref', 'created_by', 'updated_by', 'created_at', 'updated_at'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new comment on a page.
|
||||||
|
* If commenting as a reply to an existing comment, the 'reply_to' parameter
|
||||||
|
* should be provided, set to the 'local_id' of the comment being replied to.
|
||||||
|
*/
|
||||||
|
public function create(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$this->checkPermission(Permission::CommentCreateAll);
|
||||||
|
|
||||||
|
$input = $this->validate($request, $this->rules()['create']);
|
||||||
|
$page = $this->pageQueries->findVisibleByIdOrFail($input['page_id']);
|
||||||
|
|
||||||
|
$comment = $this->commentRepo->create(
|
||||||
|
$page,
|
||||||
|
$input['html'],
|
||||||
|
$input['reply_to'] ?? null,
|
||||||
|
$input['content_ref'] ?? '',
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json($comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the details of a single comment, along with its direct replies.
|
||||||
|
*/
|
||||||
|
public function read(string $id): JsonResponse
|
||||||
|
{
|
||||||
|
$comment = $this->commentRepo->getVisibleById(intval($id));
|
||||||
|
$comment->load('createdBy', 'updatedBy');
|
||||||
|
|
||||||
|
$replies = $this->commentRepo->getQueryForVisible()
|
||||||
|
->where('parent_id', '=', $comment->local_id)
|
||||||
|
->where('commentable_id', '=', $comment->commentable_id)
|
||||||
|
->where('commentable_type', '=', $comment->commentable_type)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
/** @var Comment[] $toProcess */
|
||||||
|
$toProcess = [$comment, ...$replies];
|
||||||
|
foreach ($toProcess as $commentToProcess) {
|
||||||
|
$commentToProcess->setAttribute('html', $commentToProcess->safeHtml());
|
||||||
|
$commentToProcess->makeVisible('html');
|
||||||
|
}
|
||||||
|
|
||||||
|
$comment->setRelation('replies', $replies);
|
||||||
|
|
||||||
|
return response()->json($comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the content or archived status of an existing comment.
|
||||||
|
*
|
||||||
|
* Only provide a new archived status if needing to actively change the archive state.
|
||||||
|
* Only top-level comments (non-replies) can be archived or unarchived.
|
||||||
|
*/
|
||||||
|
public function update(Request $request, string $id): JsonResponse
|
||||||
|
{
|
||||||
|
$comment = $this->commentRepo->getVisibleById(intval($id));
|
||||||
|
$this->checkOwnablePermission(Permission::CommentUpdate, $comment);
|
||||||
|
|
||||||
|
$input = $this->validate($request, $this->rules()['update']);
|
||||||
|
$hasHtml = isset($input['html']);
|
||||||
|
|
||||||
|
if (isset($input['archived'])) {
|
||||||
|
if ($input['archived']) {
|
||||||
|
$this->commentRepo->archive($comment, !$hasHtml);
|
||||||
|
} else {
|
||||||
|
$this->commentRepo->unarchive($comment, !$hasHtml);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($hasHtml) {
|
||||||
|
$comment = $this->commentRepo->update($comment, $input['html']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json($comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a single comment from the system.
|
||||||
|
*/
|
||||||
|
public function delete(string $id): Response
|
||||||
|
{
|
||||||
|
$comment = $this->commentRepo->getVisibleById(intval($id));
|
||||||
|
$this->checkOwnablePermission(Permission::CommentDelete, $comment);
|
||||||
|
|
||||||
|
$this->commentRepo->delete($comment);
|
||||||
|
|
||||||
|
return response('', 204);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,11 @@
|
|||||||
namespace BookStack\Activity\Controllers;
|
namespace BookStack\Activity\Controllers;
|
||||||
|
|
||||||
use BookStack\Activity\CommentRepo;
|
use BookStack\Activity\CommentRepo;
|
||||||
|
use BookStack\Activity\Tools\CommentTree;
|
||||||
|
use BookStack\Activity\Tools\CommentTreeNode;
|
||||||
use BookStack\Entities\Queries\PageQueries;
|
use BookStack\Entities\Queries\PageQueries;
|
||||||
use BookStack\Http\Controller;
|
use BookStack\Http\Controller;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
@@ -19,13 +22,14 @@ class CommentController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Save a new comment for a Page.
|
* Save a new comment for a Page.
|
||||||
*
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException|\Exception
|
||||||
*/
|
*/
|
||||||
public function savePageComment(Request $request, int $pageId)
|
public function savePageComment(Request $request, int $pageId)
|
||||||
{
|
{
|
||||||
$input = $this->validate($request, [
|
$input = $this->validate($request, [
|
||||||
'html' => ['required', 'string'],
|
'html' => ['required', 'string'],
|
||||||
'parent_id' => ['nullable', 'integer'],
|
'parent_id' => ['nullable', 'integer'],
|
||||||
|
'content_ref' => ['string'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$page = $this->pageQueries->findVisibleById($pageId);
|
$page = $this->pageQueries->findVisibleById($pageId);
|
||||||
@@ -33,21 +37,14 @@ class CommentController extends Controller
|
|||||||
return response('Not found', 404);
|
return response('Not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent adding comments to draft pages
|
|
||||||
if ($page->draft) {
|
|
||||||
return $this->jsonError(trans('errors.cannot_add_comment_to_draft'), 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new comment.
|
// Create a new comment.
|
||||||
$this->checkPermission('comment-create-all');
|
$this->checkPermission(Permission::CommentCreateAll);
|
||||||
$comment = $this->commentRepo->create($page, $input['html'], $input['parent_id'] ?? null);
|
$contentRef = $input['content_ref'] ?? '';
|
||||||
|
$comment = $this->commentRepo->create($page, $input['html'], $input['parent_id'] ?? null, $contentRef);
|
||||||
|
|
||||||
return view('comments.comment-branch', [
|
return view('comments.comment-branch', [
|
||||||
'readOnly' => false,
|
'readOnly' => false,
|
||||||
'branch' => [
|
'branch' => new CommentTreeNode($comment, 0, []),
|
||||||
'comment' => $comment,
|
|
||||||
'children' => [],
|
|
||||||
]
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,8 +60,8 @@ class CommentController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $this->commentRepo->getById($commentId);
|
$comment = $this->commentRepo->getById($commentId);
|
||||||
$this->checkOwnablePermission('page-view', $comment->entity);
|
$this->checkOwnablePermission(Permission::PageView, $comment->entity);
|
||||||
$this->checkOwnablePermission('comment-update', $comment);
|
$this->checkOwnablePermission(Permission::CommentUpdate, $comment);
|
||||||
|
|
||||||
$comment = $this->commentRepo->update($comment, $input['html']);
|
$comment = $this->commentRepo->update($comment, $input['html']);
|
||||||
|
|
||||||
@@ -74,13 +71,53 @@ class CommentController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark a comment as archived.
|
||||||
|
*/
|
||||||
|
public function archive(int $id)
|
||||||
|
{
|
||||||
|
$comment = $this->commentRepo->getById($id);
|
||||||
|
$this->checkOwnablePermission(Permission::PageView, $comment->entity);
|
||||||
|
if (!userCan(Permission::CommentUpdate, $comment) && !userCan(Permission::CommentDelete, $comment)) {
|
||||||
|
$this->showPermissionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->commentRepo->archive($comment);
|
||||||
|
|
||||||
|
$tree = new CommentTree($comment->entity);
|
||||||
|
return view('comments.comment-branch', [
|
||||||
|
'readOnly' => false,
|
||||||
|
'branch' => $tree->getCommentNodeForId($id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unmark a comment as archived.
|
||||||
|
*/
|
||||||
|
public function unarchive(int $id)
|
||||||
|
{
|
||||||
|
$comment = $this->commentRepo->getById($id);
|
||||||
|
$this->checkOwnablePermission(Permission::PageView, $comment->entity);
|
||||||
|
if (!userCan(Permission::CommentUpdate, $comment) && !userCan(Permission::CommentDelete, $comment)) {
|
||||||
|
$this->showPermissionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->commentRepo->unarchive($comment);
|
||||||
|
|
||||||
|
$tree = new CommentTree($comment->entity);
|
||||||
|
return view('comments.comment-branch', [
|
||||||
|
'readOnly' => false,
|
||||||
|
'branch' => $tree->getCommentNodeForId($id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a comment from the system.
|
* Delete a comment from the system.
|
||||||
*/
|
*/
|
||||||
public function destroy(int $id)
|
public function destroy(int $id)
|
||||||
{
|
{
|
||||||
$comment = $this->commentRepo->getById($id);
|
$comment = $this->commentRepo->getById($id);
|
||||||
$this->checkOwnablePermission('comment-delete', $comment);
|
$this->checkOwnablePermission(Permission::CommentDelete, $comment);
|
||||||
|
|
||||||
$this->commentRepo->delete($comment);
|
$this->commentRepo->delete($comment);
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class FavouriteController extends Controller
|
|||||||
public function index(Request $request, QueryTopFavourites $topFavourites)
|
public function index(Request $request, QueryTopFavourites $topFavourites)
|
||||||
{
|
{
|
||||||
$viewCount = 20;
|
$viewCount = 20;
|
||||||
$page = intval($request->get('page', 1));
|
$page = intval($request->input('page', 1));
|
||||||
$favourites = $topFavourites->run($viewCount + 1, (($page - 1) * $viewCount));
|
$favourites = $topFavourites->run($viewCount + 1, (($page - 1) * $viewCount));
|
||||||
|
|
||||||
$hasMoreLink = ($favourites->count() > $viewCount) ? url('/favourites?page=' . ($page + 1)) : null;
|
$hasMoreLink = ($favourites->count() > $viewCount) ? url('/favourites?page=' . ($page + 1)) : null;
|
||||||
|
|||||||
68
app/Activity/Controllers/TagApiController.php
Normal file
68
app/Activity/Controllers/TagApiController.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace BookStack\Activity\Controllers;
|
||||||
|
|
||||||
|
use BookStack\Activity\TagRepo;
|
||||||
|
use BookStack\Http\ApiController;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoints to query data about tags in the system.
|
||||||
|
* You'll only see results based on tags applied to content you have access to.
|
||||||
|
* There are no general create/update/delete endpoints here since tags do not exist
|
||||||
|
* by themselves, they are managed via the items they are assigned to.
|
||||||
|
*/
|
||||||
|
class TagApiController extends ApiController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected TagRepo $tagRepo,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'listValues' => [
|
||||||
|
'name' => ['required', 'string'],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of tag names used in the system.
|
||||||
|
* Only the name field can be used in filters.
|
||||||
|
*/
|
||||||
|
public function listNames(): JsonResponse
|
||||||
|
{
|
||||||
|
$tagQuery = $this->tagRepo
|
||||||
|
->queryWithTotalsForApi('');
|
||||||
|
|
||||||
|
return $this->apiListingResponse($tagQuery, [
|
||||||
|
'name', 'values', 'usages', 'page_count', 'chapter_count', 'book_count', 'shelf_count',
|
||||||
|
], [], [
|
||||||
|
'name'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of tag values, which have been set for the given tag name,
|
||||||
|
* which must be provided as a query parameter on the request.
|
||||||
|
* Only the value field can be used in filters.
|
||||||
|
*/
|
||||||
|
public function listValues(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$data = $this->validate($request, $this->rules()['listValues']);
|
||||||
|
$name = $data['name'];
|
||||||
|
|
||||||
|
$tagQuery = $this->tagRepo->queryWithTotalsForApi($name);
|
||||||
|
|
||||||
|
return $this->apiListingResponse($tagQuery, [
|
||||||
|
'name', 'value', 'usages', 'page_count', 'chapter_count', 'book_count', 'shelf_count',
|
||||||
|
], [], [
|
||||||
|
'value',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,9 +24,9 @@ class TagController extends Controller
|
|||||||
'usages' => trans('entities.tags_usages'),
|
'usages' => trans('entities.tags_usages'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$nameFilter = $request->get('name', '');
|
$nameFilter = $request->input('name', '');
|
||||||
$tags = $this->tagRepo
|
$tags = $this->tagRepo
|
||||||
->queryWithTotals($listOptions, $nameFilter)
|
->queryWithTotalsForList($listOptions, $nameFilter)
|
||||||
->paginate(50)
|
->paginate(50)
|
||||||
->appends(array_filter(array_merge($listOptions->getPaginationAppends(), [
|
->appends(array_filter(array_merge($listOptions->getPaginationAppends(), [
|
||||||
'name' => $nameFilter,
|
'name' => $nameFilter,
|
||||||
@@ -46,7 +46,7 @@ class TagController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function getNameSuggestions(Request $request)
|
public function getNameSuggestions(Request $request)
|
||||||
{
|
{
|
||||||
$searchTerm = $request->get('search', '');
|
$searchTerm = $request->input('search', '');
|
||||||
$suggestions = $this->tagRepo->getNameSuggestions($searchTerm);
|
$suggestions = $this->tagRepo->getNameSuggestions($searchTerm);
|
||||||
|
|
||||||
return response()->json($suggestions);
|
return response()->json($suggestions);
|
||||||
@@ -57,8 +57,8 @@ class TagController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function getValueSuggestions(Request $request)
|
public function getValueSuggestions(Request $request)
|
||||||
{
|
{
|
||||||
$searchTerm = $request->get('search', '');
|
$searchTerm = $request->input('search', '');
|
||||||
$tagName = $request->get('name', '');
|
$tagName = $request->input('name', '');
|
||||||
$suggestions = $this->tagRepo->getValueSuggestions($searchTerm, $tagName);
|
$suggestions = $this->tagRepo->getValueSuggestions($searchTerm, $tagName);
|
||||||
|
|
||||||
return response()->json($suggestions);
|
return response()->json($suggestions);
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ namespace BookStack\Activity\Controllers;
|
|||||||
use BookStack\Activity\Tools\UserEntityWatchOptions;
|
use BookStack\Activity\Tools\UserEntityWatchOptions;
|
||||||
use BookStack\Entities\Tools\MixedEntityRequestHelper;
|
use BookStack\Entities\Tools\MixedEntityRequestHelper;
|
||||||
use BookStack\Http\Controller;
|
use BookStack\Http\Controller;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class WatchController extends Controller
|
class WatchController extends Controller
|
||||||
{
|
{
|
||||||
public function update(Request $request, MixedEntityRequestHelper $entityHelper)
|
public function update(Request $request, MixedEntityRequestHelper $entityHelper)
|
||||||
{
|
{
|
||||||
$this->checkPermission('receive-notifications');
|
$this->checkPermission(Permission::ReceiveNotifications);
|
||||||
$this->preventGuestAccess();
|
$this->preventGuestAccess();
|
||||||
|
|
||||||
$requestData = $this->validate($request, array_merge([
|
$requestData = $this->validate($request, array_merge([
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use BookStack\Activity\ActivityType;
|
|||||||
use BookStack\Activity\Models\Webhook;
|
use BookStack\Activity\Models\Webhook;
|
||||||
use BookStack\Activity\Queries\WebhooksAllPaginatedAndSorted;
|
use BookStack\Activity\Queries\WebhooksAllPaginatedAndSorted;
|
||||||
use BookStack\Http\Controller;
|
use BookStack\Http\Controller;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
use BookStack\Util\SimpleListOptions;
|
use BookStack\Util\SimpleListOptions;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ class WebhookController extends Controller
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->middleware([
|
$this->middleware([
|
||||||
'can:settings-manage',
|
Permission::SettingsManage->middleware()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use BookStack\App\Model;
|
|||||||
use BookStack\Entities\Models\Entity;
|
use BookStack\Entities\Models\Entity;
|
||||||
use BookStack\Permissions\Models\JointPermission;
|
use BookStack\Permissions\Models\JointPermission;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
@@ -15,26 +16,26 @@ use Illuminate\Support\Str;
|
|||||||
/**
|
/**
|
||||||
* @property string $type
|
* @property string $type
|
||||||
* @property User $user
|
* @property User $user
|
||||||
* @property Entity $entity
|
* @property Entity $loggable
|
||||||
* @property string $detail
|
* @property string $detail
|
||||||
* @property string $entity_type
|
* @property string $loggable_type
|
||||||
* @property int $entity_id
|
* @property int $loggable_id
|
||||||
* @property int $user_id
|
* @property int $user_id
|
||||||
* @property Carbon $created_at
|
* @property Carbon $created_at
|
||||||
* @property Carbon $updated_at
|
|
||||||
*/
|
*/
|
||||||
class Activity extends Model
|
class Activity extends Model
|
||||||
{
|
{
|
||||||
/**
|
use HasFactory;
|
||||||
* Get the entity for this activity.
|
|
||||||
*/
|
|
||||||
public function entity(): MorphTo
|
|
||||||
{
|
|
||||||
if ($this->entity_type === '') {
|
|
||||||
$this->entity_type = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->morphTo('entity');
|
/**
|
||||||
|
* Get the loggable model related to this activity.
|
||||||
|
* Currently only used for entities (previously entity_[id/type] columns).
|
||||||
|
* Could be used for others but will need an audit of uses where assumed
|
||||||
|
* to be entities.
|
||||||
|
*/
|
||||||
|
public function loggable(): MorphTo
|
||||||
|
{
|
||||||
|
return $this->morphTo('loggable');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,8 +48,8 @@ class Activity extends Model
|
|||||||
|
|
||||||
public function jointPermissions(): HasMany
|
public function jointPermissions(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(JointPermission::class, 'entity_id', 'entity_id')
|
return $this->hasMany(JointPermission::class, 'entity_id', 'loggable_id')
|
||||||
->whereColumn('activities.entity_type', '=', 'joint_permissions.entity_type');
|
->whereColumn('activities.loggable_type', '=', 'joint_permissions.entity_type');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,6 +75,6 @@ class Activity extends Model
|
|||||||
*/
|
*/
|
||||||
public function isSimilarTo(self $activityB): bool
|
public function isSimilarTo(self $activityB): bool
|
||||||
{
|
{
|
||||||
return [$this->type, $this->entity_type, $this->entity_id] === [$activityB->type, $activityB->entity_type, $activityB->entity_id];
|
return [$this->type, $this->loggable_type, $this->loggable_id] === [$activityB->type, $activityB->loggable_type, $activityB->loggable_id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,47 +3,70 @@
|
|||||||
namespace BookStack\Activity\Models;
|
namespace BookStack\Activity\Models;
|
||||||
|
|
||||||
use BookStack\App\Model;
|
use BookStack\App\Model;
|
||||||
|
use BookStack\Permissions\Models\JointPermission;
|
||||||
|
use BookStack\Permissions\PermissionApplicator;
|
||||||
use BookStack\Users\Models\HasCreatorAndUpdater;
|
use BookStack\Users\Models\HasCreatorAndUpdater;
|
||||||
|
use BookStack\Users\Models\OwnableInterface;
|
||||||
use BookStack\Util\HtmlContentFilter;
|
use BookStack\Util\HtmlContentFilter;
|
||||||
|
use BookStack\Util\HtmlContentFilterConfig;
|
||||||
|
use BookStack\Util\HtmlToPlainText;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $text - Deprecated & now unused (#4821)
|
|
||||||
* @property string $html
|
* @property string $html
|
||||||
* @property int|null $parent_id - Relates to local_id, not id
|
* @property int|null $parent_id - Relates to local_id, not id
|
||||||
* @property int $local_id
|
* @property int $local_id
|
||||||
* @property string $entity_type
|
* @property string $commentable_type
|
||||||
* @property int $entity_id
|
* @property int $commentable_id
|
||||||
* @property int $created_by
|
* @property string $content_ref
|
||||||
* @property int $updated_by
|
* @property bool $archived
|
||||||
*/
|
*/
|
||||||
class Comment extends Model implements Loggable
|
class Comment extends Model implements Loggable, OwnableInterface
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use HasCreatorAndUpdater;
|
use HasCreatorAndUpdater;
|
||||||
|
|
||||||
protected $fillable = ['parent_id'];
|
protected $fillable = ['parent_id'];
|
||||||
protected $appends = ['created', 'updated'];
|
protected $hidden = ['html'];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'archived' => 'boolean',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the entity that this comment belongs to.
|
* Get the entity that this comment belongs to.
|
||||||
*/
|
*/
|
||||||
public function entity(): MorphTo
|
public function entity(): MorphTo
|
||||||
{
|
{
|
||||||
return $this->morphTo('entity');
|
// We specifically define null here to avoid the different name (commentable)
|
||||||
|
// being used by Laravel eager loading instead of the method name, which it was doing
|
||||||
|
// in some scenarios like when deserialized when going through the queue system.
|
||||||
|
// So we instead specify the type and id column names to use.
|
||||||
|
// Related to:
|
||||||
|
// https://github.com/laravel/framework/pull/24815
|
||||||
|
// https://github.com/laravel/framework/issues/27342
|
||||||
|
// https://github.com/laravel/framework/issues/47953
|
||||||
|
// (and probably more)
|
||||||
|
|
||||||
|
// Ultimately, we could just align the method name to 'commentable' but that would be a potential
|
||||||
|
// breaking change and not really worthwhile in a patch due to the risk of creating extra problems.
|
||||||
|
return $this->morphTo(null, 'commentable_type', 'commentable_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the parent comment this is in reply to (if existing).
|
* Get the parent comment this is in reply to (if existing).
|
||||||
|
* @return BelongsTo<Comment, $this>
|
||||||
*/
|
*/
|
||||||
public function parent(): BelongsTo
|
public function parent(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Comment::class, 'parent_id', 'local_id', 'parent')
|
return $this->belongsTo(Comment::class, 'parent_id', 'local_id', 'parent')
|
||||||
->where('entity_type', '=', $this->entity_type)
|
->where('commentable_type', '=', $this->commentable_type)
|
||||||
->where('entity_id', '=', $this->entity_id);
|
->where('commentable_id', '=', $this->commentable_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,29 +77,36 @@ class Comment extends Model implements Loggable
|
|||||||
return $this->updated_at->timestamp > $this->created_at->timestamp;
|
return $this->updated_at->timestamp > $this->created_at->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get created date as a relative diff.
|
|
||||||
*/
|
|
||||||
public function getCreatedAttribute(): string
|
|
||||||
{
|
|
||||||
return $this->created_at->diffForHumans();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get updated date as a relative diff.
|
|
||||||
*/
|
|
||||||
public function getUpdatedAttribute(): string
|
|
||||||
{
|
|
||||||
return $this->updated_at->diffForHumans();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function logDescriptor(): string
|
public function logDescriptor(): string
|
||||||
{
|
{
|
||||||
return "Comment #{$this->local_id} (ID: {$this->id}) for {$this->entity_type} (ID: {$this->entity_id})";
|
return "Comment #{$this->local_id} (ID: {$this->id}) for {$this->commentable_type} (ID: {$this->commentable_id})";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function safeHtml(): string
|
public function safeHtml(): string
|
||||||
{
|
{
|
||||||
return HtmlContentFilter::removeScriptsFromHtmlString($this->html ?? '');
|
$filter = new HtmlContentFilter(new HtmlContentFilterConfig());
|
||||||
|
return $filter->filterString($this->html ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlainText(): string
|
||||||
|
{
|
||||||
|
$converter = new HtmlToPlainText();
|
||||||
|
return $converter->convert($this->html ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jointPermissions(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(JointPermission::class, 'entity_id', 'commentable_id')
|
||||||
|
->whereColumn('joint_permissions.entity_type', '=', 'comments.commentable_type');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope the query to just the comments visible to the user based upon the
|
||||||
|
* user visibility of what has been commented on.
|
||||||
|
*/
|
||||||
|
public function scopeVisible(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return app()->make(PermissionApplicator::class)
|
||||||
|
->restrictEntityRelationQuery($query, 'comments', 'commentable_id', 'commentable_type');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ namespace BookStack\Activity\Models;
|
|||||||
|
|
||||||
use BookStack\App\Model;
|
use BookStack\App\Model;
|
||||||
use BookStack\Permissions\Models\JointPermission;
|
use BookStack\Permissions\Models\JointPermission;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
|
||||||
class Favourite extends Model
|
class Favourite extends Model
|
||||||
{
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = ['user_id'];
|
protected $fillable = ['user_id'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
20
app/Activity/Models/MentionHistory.php
Normal file
20
app/Activity/Models/MentionHistory.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Activity\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $mentionable_type
|
||||||
|
* @property int $mentionable_id
|
||||||
|
* @property int $from_user_id
|
||||||
|
* @property int $to_user_id
|
||||||
|
* @property Carbon $created_at
|
||||||
|
* @property Carbon $updated_at
|
||||||
|
*/
|
||||||
|
class MentionHistory extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'mention_history';
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string $value
|
* @property string $value
|
||||||
|
* @property int $entity_id
|
||||||
|
* @property string $entity_type
|
||||||
* @property int $order
|
* @property int $order
|
||||||
*/
|
*/
|
||||||
class Tag extends Model
|
class Tag extends Model
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace BookStack\Activity\Models;
|
|||||||
use BookStack\Activity\WatchLevels;
|
use BookStack\Activity\WatchLevels;
|
||||||
use BookStack\Permissions\Models\JointPermission;
|
use BookStack\Permissions\Models\JointPermission;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
@@ -20,6 +21,8 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|||||||
*/
|
*/
|
||||||
class Watch extends Model
|
class Watch extends Model
|
||||||
{
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
|
||||||
public function watchable(): MorphTo
|
public function watchable(): MorphTo
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ namespace BookStack\Activity\Notifications\Handlers;
|
|||||||
use BookStack\Activity\Models\Loggable;
|
use BookStack\Activity\Models\Loggable;
|
||||||
use BookStack\Activity\Notifications\Messages\BaseActivityNotification;
|
use BookStack\Activity\Notifications\Messages\BaseActivityNotification;
|
||||||
use BookStack\Entities\Models\Entity;
|
use BookStack\Entities\Models\Entity;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
use BookStack\Permissions\PermissionApplicator;
|
use BookStack\Permissions\PermissionApplicator;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
abstract class BaseNotificationHandler implements NotificationHandler
|
abstract class BaseNotificationHandler implements NotificationHandler
|
||||||
{
|
{
|
||||||
@@ -18,6 +20,7 @@ abstract class BaseNotificationHandler implements NotificationHandler
|
|||||||
{
|
{
|
||||||
$users = User::query()->whereIn('id', array_unique($userIds))->get();
|
$users = User::query()->whereIn('id', array_unique($userIds))->get();
|
||||||
|
|
||||||
|
/** @var User $user */
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
// Prevent sending to the user that initiated the activity
|
// Prevent sending to the user that initiated the activity
|
||||||
if ($user->id === $initiator->id) {
|
if ($user->id === $initiator->id) {
|
||||||
@@ -25,7 +28,7 @@ abstract class BaseNotificationHandler implements NotificationHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prevent sending of the user does not have notification permissions
|
// Prevent sending of the user does not have notification permissions
|
||||||
if (!$user->can('receive-notifications')) {
|
if (!$user->can(Permission::ReceiveNotifications)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +39,11 @@ abstract class BaseNotificationHandler implements NotificationHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send the notification
|
// Send the notification
|
||||||
$user->notify(new $notification($detail, $initiator));
|
try {
|
||||||
|
$user->notify(new $notification($detail, $initiator));
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
Log::error("Failed to send email notification to user [id:{$user->id}] with error: {$exception->getMessage()}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class CommentCreationNotificationHandler extends BaseNotificationHandler
|
|||||||
$watcherIds = $watchers->getWatcherUserIds();
|
$watcherIds = $watchers->getWatcherUserIds();
|
||||||
|
|
||||||
// Page owner if user preferences allow
|
// Page owner if user preferences allow
|
||||||
if (!$watchers->isUserIgnoring($page->owned_by) && $page->ownedBy) {
|
if ($page->owned_by && !$watchers->isUserIgnoring($page->owned_by) && $page->ownedBy) {
|
||||||
$userNotificationPrefs = new UserNotificationPreferences($page->ownedBy);
|
$userNotificationPrefs = new UserNotificationPreferences($page->ownedBy);
|
||||||
if ($userNotificationPrefs->notifyOnOwnPageComments()) {
|
if ($userNotificationPrefs->notifyOnOwnPageComments()) {
|
||||||
$watcherIds[] = $page->owned_by;
|
$watcherIds[] = $page->owned_by;
|
||||||
@@ -36,7 +36,7 @@ class CommentCreationNotificationHandler extends BaseNotificationHandler
|
|||||||
|
|
||||||
// Parent comment creator if preferences allow
|
// Parent comment creator if preferences allow
|
||||||
$parentComment = $detail->parent()->first();
|
$parentComment = $detail->parent()->first();
|
||||||
if ($parentComment && !$watchers->isUserIgnoring($parentComment->created_by) && $parentComment->createdBy) {
|
if ($parentComment && $parentComment->created_by && !$watchers->isUserIgnoring($parentComment->created_by) && $parentComment->createdBy) {
|
||||||
$parentCommenterNotificationsPrefs = new UserNotificationPreferences($parentComment->createdBy);
|
$parentCommenterNotificationsPrefs = new UserNotificationPreferences($parentComment->createdBy);
|
||||||
if ($parentCommenterNotificationsPrefs->notifyOnCommentReplies()) {
|
if ($parentCommenterNotificationsPrefs->notifyOnCommentReplies()) {
|
||||||
$watcherIds[] = $parentComment->created_by;
|
$watcherIds[] = $parentComment->created_by;
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Activity\Notifications\Handlers;
|
||||||
|
|
||||||
|
use BookStack\Activity\ActivityType;
|
||||||
|
use BookStack\Activity\Models\Activity;
|
||||||
|
use BookStack\Activity\Models\Comment;
|
||||||
|
use BookStack\Activity\Models\Loggable;
|
||||||
|
use BookStack\Activity\Models\MentionHistory;
|
||||||
|
use BookStack\Activity\Notifications\Messages\CommentMentionNotification;
|
||||||
|
use BookStack\Activity\Tools\MentionParser;
|
||||||
|
use BookStack\Entities\Models\Page;
|
||||||
|
use BookStack\Settings\UserNotificationPreferences;
|
||||||
|
use BookStack\Users\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
|
class CommentMentionNotificationHandler extends BaseNotificationHandler
|
||||||
|
{
|
||||||
|
public function handle(Activity $activity, Loggable|string $detail, User $user): void
|
||||||
|
{
|
||||||
|
if (!($detail instanceof Comment) || !($detail->entity instanceof Page)) {
|
||||||
|
throw new \InvalidArgumentException("Detail for comment mention notifications must be a comment on a page");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Page $page */
|
||||||
|
$page = $detail->entity;
|
||||||
|
|
||||||
|
$parser = new MentionParser();
|
||||||
|
$mentionedUserIds = $parser->parseUserIdsFromHtml($detail->html);
|
||||||
|
$realMentionedUsers = User::whereIn('id', $mentionedUserIds)->get();
|
||||||
|
|
||||||
|
$receivingNotifications = $realMentionedUsers->filter(function (User $user) {
|
||||||
|
$prefs = new UserNotificationPreferences($user);
|
||||||
|
return $prefs->notifyOnCommentMentions();
|
||||||
|
});
|
||||||
|
$receivingNotificationsUserIds = $receivingNotifications->pluck('id')->toArray();
|
||||||
|
|
||||||
|
$userMentionsToLog = $realMentionedUsers;
|
||||||
|
|
||||||
|
// When an edit, we check our history to see if we've already notified the user about this comment before
|
||||||
|
// so that we can filter them out to avoid double notifications.
|
||||||
|
if ($activity->type === ActivityType::COMMENT_UPDATE) {
|
||||||
|
$previouslyNotifiedUserIds = $this->getPreviouslyNotifiedUserIds($detail);
|
||||||
|
$receivingNotificationsUserIds = array_values(array_diff($receivingNotificationsUserIds, $previouslyNotifiedUserIds));
|
||||||
|
$userMentionsToLog = $userMentionsToLog->filter(function (User $user) use ($previouslyNotifiedUserIds) {
|
||||||
|
return !in_array($user->id, $previouslyNotifiedUserIds);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logMentions($userMentionsToLog, $detail, $user);
|
||||||
|
$this->sendNotificationToUserIds(CommentMentionNotification::class, $receivingNotificationsUserIds, $user, $detail, $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection<User> $mentionedUsers
|
||||||
|
*/
|
||||||
|
protected function logMentions(Collection $mentionedUsers, Comment $comment, User $fromUser): void
|
||||||
|
{
|
||||||
|
$mentions = [];
|
||||||
|
$now = Carbon::now();
|
||||||
|
|
||||||
|
foreach ($mentionedUsers as $mentionedUser) {
|
||||||
|
$mentions[] = [
|
||||||
|
'mentionable_type' => $comment->getMorphClass(),
|
||||||
|
'mentionable_id' => $comment->id,
|
||||||
|
'from_user_id' => $fromUser->id,
|
||||||
|
'to_user_id' => $mentionedUser->id,
|
||||||
|
'created_at' => $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
MentionHistory::query()->insert($mentions);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getPreviouslyNotifiedUserIds(Comment $comment): array
|
||||||
|
{
|
||||||
|
return MentionHistory::query()
|
||||||
|
->where('mentionable_id', $comment->id)
|
||||||
|
->where('mentionable_type', $comment->getMorphClass())
|
||||||
|
->pluck('to_user_id')
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,8 @@ class PageUpdateNotificationHandler extends BaseNotificationHandler
|
|||||||
throw new \InvalidArgumentException("Detail for page update notifications must be a page");
|
throw new \InvalidArgumentException("Detail for page update notifications must be a page");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get last update from activity
|
// Get the last update from activity
|
||||||
|
/** @var ?Activity $lastUpdate */
|
||||||
$lastUpdate = $detail->activity()
|
$lastUpdate = $detail->activity()
|
||||||
->where('type', '=', ActivityType::PAGE_UPDATE)
|
->where('type', '=', ActivityType::PAGE_UPDATE)
|
||||||
->where('id', '!=', $activity->id)
|
->where('id', '!=', $activity->id)
|
||||||
@@ -38,8 +39,8 @@ class PageUpdateNotificationHandler extends BaseNotificationHandler
|
|||||||
$watchers = new EntityWatchers($detail, WatchLevels::UPDATES);
|
$watchers = new EntityWatchers($detail, WatchLevels::UPDATES);
|
||||||
$watcherIds = $watchers->getWatcherUserIds();
|
$watcherIds = $watchers->getWatcherUserIds();
|
||||||
|
|
||||||
// Add page owner if preferences allow
|
// Add the page owner if preferences allow
|
||||||
if (!$watchers->isUserIgnoring($detail->owned_by) && $detail->ownedBy) {
|
if ($detail->owned_by && !$watchers->isUserIgnoring($detail->owned_by) && $detail->ownedBy) {
|
||||||
$userNotificationPrefs = new UserNotificationPreferences($detail->ownedBy);
|
$userNotificationPrefs = new UserNotificationPreferences($detail->ownedBy);
|
||||||
if ($userNotificationPrefs->notifyOnOwnPageChanges()) {
|
if ($userNotificationPrefs->notifyOnOwnPageChanges()) {
|
||||||
$watcherIds[] = $detail->owned_by;
|
$watcherIds[] = $detail->owned_by;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ abstract class BaseActivityNotification extends MailNotification
|
|||||||
protected function buildReasonFooterLine(LocaleDefinition $locale): LinkedMailMessageLine
|
protected function buildReasonFooterLine(LocaleDefinition $locale): LinkedMailMessageLine
|
||||||
{
|
{
|
||||||
return new LinkedMailMessageLine(
|
return new LinkedMailMessageLine(
|
||||||
url('/preferences/notifications'),
|
url('/my-account/notifications'),
|
||||||
$locale->trans('notifications.footer_reason'),
|
$locale->trans('notifications.footer_reason'),
|
||||||
$locale->trans('notifications.footer_reason_link'),
|
$locale->trans('notifications.footer_reason_link'),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class CommentCreationNotification extends BaseActivityNotification
|
|||||||
$locale->trans('notifications.detail_page_name') => new EntityLinkMessageLine($page),
|
$locale->trans('notifications.detail_page_name') => new EntityLinkMessageLine($page),
|
||||||
$locale->trans('notifications.detail_page_path') => $this->buildPagePathLine($page, $notifiable),
|
$locale->trans('notifications.detail_page_path') => $this->buildPagePathLine($page, $notifiable),
|
||||||
$locale->trans('notifications.detail_commenter') => $this->user->name,
|
$locale->trans('notifications.detail_commenter') => $this->user->name,
|
||||||
$locale->trans('notifications.detail_comment') => strip_tags($comment->html),
|
$locale->trans('notifications.detail_comment') => $comment->getPlainText(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->newMailMessage($locale)
|
return $this->newMailMessage($locale)
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Activity\Notifications\Messages;
|
||||||
|
|
||||||
|
use BookStack\Activity\Models\Comment;
|
||||||
|
use BookStack\Activity\Notifications\MessageParts\EntityLinkMessageLine;
|
||||||
|
use BookStack\Activity\Notifications\MessageParts\ListMessageLine;
|
||||||
|
use BookStack\Entities\Models\Page;
|
||||||
|
use BookStack\Users\Models\User;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
|
||||||
|
class CommentMentionNotification extends BaseActivityNotification
|
||||||
|
{
|
||||||
|
public function toMail(User $notifiable): MailMessage
|
||||||
|
{
|
||||||
|
/** @var Comment $comment */
|
||||||
|
$comment = $this->detail;
|
||||||
|
/** @var Page $page */
|
||||||
|
$page = $comment->entity;
|
||||||
|
|
||||||
|
$locale = $notifiable->getLocale();
|
||||||
|
|
||||||
|
$listLines = array_filter([
|
||||||
|
$locale->trans('notifications.detail_page_name') => new EntityLinkMessageLine($page),
|
||||||
|
$locale->trans('notifications.detail_page_path') => $this->buildPagePathLine($page, $notifiable),
|
||||||
|
$locale->trans('notifications.detail_commenter') => $this->user->name,
|
||||||
|
$locale->trans('notifications.detail_comment') => $comment->getPlainText(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->newMailMessage($locale)
|
||||||
|
->subject($locale->trans('notifications.comment_mention_subject', ['pageName' => $page->getShortName()]))
|
||||||
|
->line($locale->trans('notifications.comment_mention_intro', ['appName' => setting('app-name')]))
|
||||||
|
->line(new ListMessageLine($listLines))
|
||||||
|
->action($locale->trans('notifications.action_view_comment'), $page->getUrl('#comment' . $comment->local_id))
|
||||||
|
->line($this->buildReasonFooterLine($locale));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ use BookStack\Activity\ActivityType;
|
|||||||
use BookStack\Activity\Models\Activity;
|
use BookStack\Activity\Models\Activity;
|
||||||
use BookStack\Activity\Models\Loggable;
|
use BookStack\Activity\Models\Loggable;
|
||||||
use BookStack\Activity\Notifications\Handlers\CommentCreationNotificationHandler;
|
use BookStack\Activity\Notifications\Handlers\CommentCreationNotificationHandler;
|
||||||
|
use BookStack\Activity\Notifications\Handlers\CommentMentionNotificationHandler;
|
||||||
use BookStack\Activity\Notifications\Handlers\NotificationHandler;
|
use BookStack\Activity\Notifications\Handlers\NotificationHandler;
|
||||||
use BookStack\Activity\Notifications\Handlers\PageCreationNotificationHandler;
|
use BookStack\Activity\Notifications\Handlers\PageCreationNotificationHandler;
|
||||||
use BookStack\Activity\Notifications\Handlers\PageUpdateNotificationHandler;
|
use BookStack\Activity\Notifications\Handlers\PageUpdateNotificationHandler;
|
||||||
@@ -14,14 +15,14 @@ use BookStack\Users\Models\User;
|
|||||||
class NotificationManager
|
class NotificationManager
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var class-string<NotificationHandler>[]
|
* @var array<string, class-string<NotificationHandler>[]>
|
||||||
*/
|
*/
|
||||||
protected array $handlers = [];
|
protected array $handlersByActivity = [];
|
||||||
|
|
||||||
public function handle(Activity $activity, string|Loggable $detail, User $user): void
|
public function handle(Activity $activity, string|Loggable $detail, User $user): void
|
||||||
{
|
{
|
||||||
$activityType = $activity->type;
|
$activityType = $activity->type;
|
||||||
$handlersToRun = $this->handlers[$activityType] ?? [];
|
$handlersToRun = $this->handlersByActivity[$activityType] ?? [];
|
||||||
foreach ($handlersToRun as $handlerClass) {
|
foreach ($handlersToRun as $handlerClass) {
|
||||||
/** @var NotificationHandler $handler */
|
/** @var NotificationHandler $handler */
|
||||||
$handler = new $handlerClass();
|
$handler = new $handlerClass();
|
||||||
@@ -34,12 +35,12 @@ class NotificationManager
|
|||||||
*/
|
*/
|
||||||
public function registerHandler(string $activityType, string $handlerClass): void
|
public function registerHandler(string $activityType, string $handlerClass): void
|
||||||
{
|
{
|
||||||
if (!isset($this->handlers[$activityType])) {
|
if (!isset($this->handlersByActivity[$activityType])) {
|
||||||
$this->handlers[$activityType] = [];
|
$this->handlersByActivity[$activityType] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($handlerClass, $this->handlers[$activityType])) {
|
if (!in_array($handlerClass, $this->handlersByActivity[$activityType])) {
|
||||||
$this->handlers[$activityType][] = $handlerClass;
|
$this->handlersByActivity[$activityType][] = $handlerClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,5 +49,7 @@ class NotificationManager
|
|||||||
$this->registerHandler(ActivityType::PAGE_CREATE, PageCreationNotificationHandler::class);
|
$this->registerHandler(ActivityType::PAGE_CREATE, PageCreationNotificationHandler::class);
|
||||||
$this->registerHandler(ActivityType::PAGE_UPDATE, PageUpdateNotificationHandler::class);
|
$this->registerHandler(ActivityType::PAGE_UPDATE, PageUpdateNotificationHandler::class);
|
||||||
$this->registerHandler(ActivityType::COMMENT_CREATE, CommentCreationNotificationHandler::class);
|
$this->registerHandler(ActivityType::COMMENT_CREATE, CommentCreationNotificationHandler::class);
|
||||||
|
$this->registerHandler(ActivityType::COMMENT_CREATE, CommentMentionNotificationHandler::class);
|
||||||
|
$this->registerHandler(ActivityType::COMMENT_UPDATE, CommentMentionNotificationHandler::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ class TagRepo
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a query against all tags in the system.
|
* Start a query against all tags in the system, with total counts for their usage,
|
||||||
|
* suitable for a system interface list with listing options.
|
||||||
*/
|
*/
|
||||||
public function queryWithTotals(SimpleListOptions $listOptions, string $nameFilter): Builder
|
public function queryWithTotalsForList(SimpleListOptions $listOptions, string $nameFilter): Builder
|
||||||
{
|
{
|
||||||
$searchTerm = $listOptions->getSearch();
|
$searchTerm = $listOptions->getSearch();
|
||||||
$sort = $listOptions->getSort();
|
$sort = $listOptions->getSort();
|
||||||
@@ -28,17 +29,35 @@ class TagRepo
|
|||||||
$sort = 'value';
|
$sort = 'value';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$query = $this->baseQueryWithTotals($nameFilter, $searchTerm)
|
||||||
|
->orderBy($sort, $listOptions->getOrder());
|
||||||
|
|
||||||
|
return $this->permissions->restrictEntityRelationQuery($query, 'tags', 'entity_id', 'entity_type');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start a query against all tags in the system, with total counts for their usage,
|
||||||
|
* which can be used via the API.
|
||||||
|
*/
|
||||||
|
public function queryWithTotalsForApi(string $nameFilter): Builder
|
||||||
|
{
|
||||||
|
$query = $this->baseQueryWithTotals($nameFilter, '');
|
||||||
|
return $this->permissions->restrictEntityRelationQuery($query, 'tags', 'entity_id', 'entity_type');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function baseQueryWithTotals(string $nameFilter, string $searchTerm): Builder
|
||||||
|
{
|
||||||
$query = Tag::query()
|
$query = Tag::query()
|
||||||
->select([
|
->select([
|
||||||
'name',
|
'name',
|
||||||
($searchTerm || $nameFilter) ? 'value' : DB::raw('COUNT(distinct value) as `values`'),
|
($searchTerm || $nameFilter) ? 'value' : DB::raw('COUNT(distinct value) as `values`'),
|
||||||
DB::raw('COUNT(id) as usages'),
|
DB::raw('COUNT(id) as usages'),
|
||||||
DB::raw('SUM(IF(entity_type = \'page\', 1, 0)) as page_count'),
|
DB::raw('CAST(SUM(IF(entity_type = \'page\', 1, 0)) as UNSIGNED) as page_count'),
|
||||||
DB::raw('SUM(IF(entity_type = \'chapter\', 1, 0)) as chapter_count'),
|
DB::raw('CAST(SUM(IF(entity_type = \'chapter\', 1, 0)) as UNSIGNED) as chapter_count'),
|
||||||
DB::raw('SUM(IF(entity_type = \'book\', 1, 0)) as book_count'),
|
DB::raw('CAST(SUM(IF(entity_type = \'book\', 1, 0)) as UNSIGNED) as book_count'),
|
||||||
DB::raw('SUM(IF(entity_type = \'bookshelf\', 1, 0)) as shelf_count'),
|
DB::raw('CAST(SUM(IF(entity_type = \'bookshelf\', 1, 0)) as UNSIGNED) as shelf_count'),
|
||||||
])
|
])
|
||||||
->orderBy($sort, $listOptions->getOrder());
|
->whereHas('entity');
|
||||||
|
|
||||||
if ($nameFilter) {
|
if ($nameFilter) {
|
||||||
$query->where('name', '=', $nameFilter);
|
$query->where('name', '=', $nameFilter);
|
||||||
@@ -56,7 +75,7 @@ class TagRepo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->permissions->restrictEntityRelationQuery($query, 'tags', 'entity_id', 'entity_type');
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ class ActivityLogger
|
|||||||
$activity->detail = $detailToStore;
|
$activity->detail = $detailToStore;
|
||||||
|
|
||||||
if ($detail instanceof Entity) {
|
if ($detail instanceof Entity) {
|
||||||
$activity->entity_id = $detail->id;
|
$activity->loggable_id = $detail->id;
|
||||||
$activity->entity_type = $detail->getMorphClass();
|
$activity->loggable_type = $detail->getMorphClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
$activity->save();
|
$activity->save();
|
||||||
@@ -64,9 +64,9 @@ class ActivityLogger
|
|||||||
public function removeEntity(Entity $entity): void
|
public function removeEntity(Entity $entity): void
|
||||||
{
|
{
|
||||||
$entity->activity()->update([
|
$entity->activity()->update([
|
||||||
'detail' => $entity->name,
|
'detail' => $entity->name,
|
||||||
'entity_id' => null,
|
'loggable_id' => null,
|
||||||
'entity_type' => null,
|
'loggable_type' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,20 @@ namespace BookStack\Activity\Tools;
|
|||||||
|
|
||||||
use BookStack\Activity\Models\Comment;
|
use BookStack\Activity\Models\Comment;
|
||||||
use BookStack\Entities\Models\Page;
|
use BookStack\Entities\Models\Page;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
|
|
||||||
class CommentTree
|
class CommentTree
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The built nested tree structure array.
|
* The built nested tree structure array.
|
||||||
* @var array{comment: Comment, depth: int, children: array}[]
|
* @var CommentTreeNode[]
|
||||||
*/
|
*/
|
||||||
protected array $tree;
|
protected array $tree;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A linear array of loaded comments.
|
||||||
|
* @var Comment[]
|
||||||
|
*/
|
||||||
protected array $comments;
|
protected array $comments;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -28,7 +34,7 @@ class CommentTree
|
|||||||
|
|
||||||
public function empty(): bool
|
public function empty(): bool
|
||||||
{
|
{
|
||||||
return count($this->tree) === 0;
|
return count($this->getActive()) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function count(): int
|
public function count(): int
|
||||||
@@ -36,15 +42,41 @@ class CommentTree
|
|||||||
return count($this->comments);
|
return count($this->comments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(): array
|
public function getActive(): array
|
||||||
{
|
{
|
||||||
return $this->tree;
|
return array_values(array_filter($this->tree, fn (CommentTreeNode $node) => !$node->comment->archived));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function activeThreadCount(): int
|
||||||
|
{
|
||||||
|
return count($this->getActive());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArchived(): array
|
||||||
|
{
|
||||||
|
return array_values(array_filter($this->tree, fn (CommentTreeNode $node) => $node->comment->archived));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function archivedThreadCount(): int
|
||||||
|
{
|
||||||
|
return count($this->getArchived());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCommentNodeForId(int $commentId): ?CommentTreeNode
|
||||||
|
{
|
||||||
|
foreach ($this->tree as $node) {
|
||||||
|
if ($node->comment->id === $commentId) {
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canUpdateAny(): bool
|
public function canUpdateAny(): bool
|
||||||
{
|
{
|
||||||
foreach ($this->comments as $comment) {
|
foreach ($this->comments as $comment) {
|
||||||
if (userCan('comment-update', $comment)) {
|
if (userCan(Permission::CommentUpdate, $comment)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,8 +84,17 @@ class CommentTree
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadVisibleHtml(): void
|
||||||
|
{
|
||||||
|
foreach ($this->comments as $comment) {
|
||||||
|
$comment->setAttribute('html', $comment->safeHtml());
|
||||||
|
$comment->makeVisible('html');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Comment[] $comments
|
* @param Comment[] $comments
|
||||||
|
* @return CommentTreeNode[]
|
||||||
*/
|
*/
|
||||||
protected function createTree(array $comments): array
|
protected function createTree(array $comments): array
|
||||||
{
|
{
|
||||||
@@ -77,28 +118,27 @@ class CommentTree
|
|||||||
|
|
||||||
$tree = [];
|
$tree = [];
|
||||||
foreach ($childMap[0] ?? [] as $childId) {
|
foreach ($childMap[0] ?? [] as $childId) {
|
||||||
$tree[] = $this->createTreeForId($childId, 0, $byId, $childMap);
|
$tree[] = $this->createTreeNodeForId($childId, 0, $byId, $childMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tree;
|
return $tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createTreeForId(int $id, int $depth, array &$byId, array &$childMap): array
|
protected function createTreeNodeForId(int $id, int $depth, array &$byId, array &$childMap): CommentTreeNode
|
||||||
{
|
{
|
||||||
$childIds = $childMap[$id] ?? [];
|
$childIds = $childMap[$id] ?? [];
|
||||||
$children = [];
|
$children = [];
|
||||||
|
|
||||||
foreach ($childIds as $childId) {
|
foreach ($childIds as $childId) {
|
||||||
$children[] = $this->createTreeForId($childId, $depth + 1, $byId, $childMap);
|
$children[] = $this->createTreeNodeForId($childId, $depth + 1, $byId, $childMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return new CommentTreeNode($byId[$id], $depth, $children);
|
||||||
'comment' => $byId[$id],
|
|
||||||
'depth' => $depth,
|
|
||||||
'children' => $children,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Comment[]
|
||||||
|
*/
|
||||||
protected function loadComments(): array
|
protected function loadComments(): array
|
||||||
{
|
{
|
||||||
if (!$this->enabled()) {
|
if (!$this->enabled()) {
|
||||||
|
|||||||
23
app/Activity/Tools/CommentTreeNode.php
Normal file
23
app/Activity/Tools/CommentTreeNode.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Activity\Tools;
|
||||||
|
|
||||||
|
use BookStack\Activity\Models\Comment;
|
||||||
|
|
||||||
|
class CommentTreeNode
|
||||||
|
{
|
||||||
|
public Comment $comment;
|
||||||
|
public int $depth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var CommentTreeNode[]
|
||||||
|
*/
|
||||||
|
public array $children;
|
||||||
|
|
||||||
|
public function __construct(Comment $comment, int $depth, array $children)
|
||||||
|
{
|
||||||
|
$this->comment = $comment;
|
||||||
|
$this->depth = $depth;
|
||||||
|
$this->children = $children;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
app/Activity/Tools/MentionParser.php
Normal file
28
app/Activity/Tools/MentionParser.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Activity\Tools;
|
||||||
|
|
||||||
|
use BookStack\Util\HtmlDocument;
|
||||||
|
use DOMElement;
|
||||||
|
|
||||||
|
class MentionParser
|
||||||
|
{
|
||||||
|
public function parseUserIdsFromHtml(string $html): array
|
||||||
|
{
|
||||||
|
$doc = new HtmlDocument($html);
|
||||||
|
|
||||||
|
$ids = [];
|
||||||
|
$mentionLinks = $doc->queryXPath('//a[@data-mention-user-id]');
|
||||||
|
|
||||||
|
foreach ($mentionLinks as $link) {
|
||||||
|
if ($link instanceof DOMElement) {
|
||||||
|
$id = intval($link->getAttribute('data-mention-user-id'));
|
||||||
|
if ($id > 0) {
|
||||||
|
$ids[] = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_unique($ids));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,17 +3,16 @@
|
|||||||
namespace BookStack\Activity\Tools;
|
namespace BookStack\Activity\Tools;
|
||||||
|
|
||||||
use BookStack\Activity\Models\Tag;
|
use BookStack\Activity\Models\Tag;
|
||||||
|
use BookStack\Entities\Models\BookChild;
|
||||||
|
use BookStack\Entities\Models\Entity;
|
||||||
|
use BookStack\Entities\Models\Page;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
|
|
||||||
class TagClassGenerator
|
class TagClassGenerator
|
||||||
{
|
{
|
||||||
protected array $tags;
|
public function __construct(
|
||||||
|
protected Entity $entity
|
||||||
/**
|
) {
|
||||||
* @param Tag[] $tags
|
|
||||||
*/
|
|
||||||
public function __construct(array $tags)
|
|
||||||
{
|
|
||||||
$this->tags = $tags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,14 +21,23 @@ class TagClassGenerator
|
|||||||
public function generate(): array
|
public function generate(): array
|
||||||
{
|
{
|
||||||
$classes = [];
|
$classes = [];
|
||||||
|
$tags = $this->entity->tags->all();
|
||||||
|
|
||||||
foreach ($this->tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$name = $this->normalizeTagClassString($tag->name);
|
array_push($classes, ...$this->generateClassesForTag($tag));
|
||||||
$value = $this->normalizeTagClassString($tag->value);
|
}
|
||||||
$classes[] = 'tag-name-' . $name;
|
|
||||||
if ($value) {
|
if ($this->entity instanceof BookChild && userCan(Permission::BookView, $this->entity->book)) {
|
||||||
$classes[] = 'tag-value-' . $value;
|
$bookTags = $this->entity->book->tags;
|
||||||
$classes[] = 'tag-pair-' . $name . '-' . $value;
|
foreach ($bookTags as $bookTag) {
|
||||||
|
array_push($classes, ...$this->generateClassesForTag($bookTag, 'book-'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->entity instanceof Page && $this->entity->chapter && userCan(Permission::ChapterView, $this->entity->chapter)) {
|
||||||
|
$chapterTags = $this->entity->chapter->tags;
|
||||||
|
foreach ($chapterTags as $chapterTag) {
|
||||||
|
array_push($classes, ...$this->generateClassesForTag($chapterTag, 'chapter-'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +49,22 @@ class TagClassGenerator
|
|||||||
return implode(' ', $this->generate());
|
return implode(' ', $this->generate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
protected function generateClassesForTag(Tag $tag, string $prefix = ''): array
|
||||||
|
{
|
||||||
|
$classes = [];
|
||||||
|
$name = $this->normalizeTagClassString($tag->name);
|
||||||
|
$value = $this->normalizeTagClassString($tag->value);
|
||||||
|
$classes[] = "{$prefix}tag-name-{$name}";
|
||||||
|
if ($value) {
|
||||||
|
$classes[] = "{$prefix}tag-value-{$value}";
|
||||||
|
$classes[] = "{$prefix}tag-pair-{$name}-{$value}";
|
||||||
|
}
|
||||||
|
return $classes;
|
||||||
|
}
|
||||||
|
|
||||||
protected function normalizeTagClassString(string $value): string
|
protected function normalizeTagClassString(string $value): string
|
||||||
{
|
{
|
||||||
$value = str_replace(' ', '', strtolower($value));
|
$value = str_replace(' ', '', strtolower($value));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use BookStack\Activity\WatchLevels;
|
|||||||
use BookStack\Entities\Models\BookChild;
|
use BookStack\Entities\Models\BookChild;
|
||||||
use BookStack\Entities\Models\Entity;
|
use BookStack\Entities\Models\Entity;
|
||||||
use BookStack\Entities\Models\Page;
|
use BookStack\Entities\Models\Page;
|
||||||
|
use BookStack\Permissions\Permission;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ class UserEntityWatchOptions
|
|||||||
|
|
||||||
public function canWatch(): bool
|
public function canWatch(): bool
|
||||||
{
|
{
|
||||||
return $this->user->can('receive-notifications') && !$this->user->isGuest();
|
return $this->user->can(Permission::ReceiveNotifications) && !$this->user->isGuest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWatchLevel(): string
|
public function getWatchLevel(): string
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class WebhookFormatter
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->detail instanceof Model) {
|
if ($this->detail instanceof Model) {
|
||||||
$data['related_item'] = $this->formatModel();
|
$data['related_item'] = $this->formatModel($this->detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
@@ -83,10 +83,8 @@ class WebhookFormatter
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function formatModel(): array
|
protected function formatModel(Model $model): array
|
||||||
{
|
{
|
||||||
/** @var Model $model */
|
|
||||||
$model = $this->detail;
|
|
||||||
$model->unsetRelations();
|
$model->unsetRelations();
|
||||||
|
|
||||||
foreach ($this->modelFormatters as $formatter) {
|
foreach ($this->modelFormatters as $formatter) {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user