mirror of
https://github.com/penpot/penpot.git
synced 2026-05-11 19:13:49 +00:00
Compare commits
1186 Commits
2.14.5-RC1
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
962bb1fa9b | ||
|
|
fd82744c62 | ||
|
|
843a4a5b58 | ||
|
|
d670ba4bff | ||
|
|
27e6c1e420 | ||
|
|
c76e536cd8 | ||
|
|
102c97040a | ||
|
|
1de2718d43 | ||
|
|
8f4f948104 | ||
|
|
7fb19fc1a2 | ||
|
|
02bbbae0b0 | ||
|
|
3094d512f4 | ||
|
|
09bd7f96f6 | ||
|
|
f7fbd3007e | ||
|
|
06986e25a3 | ||
|
|
6ef231bf38 | ||
|
|
1f9f4126b7 | ||
|
|
313777d1c3 | ||
|
|
58ca0a16ba | ||
|
|
b54fa2f11c | ||
|
|
feb49bc07a | ||
|
|
0639ca53de | ||
|
|
7d4be33d4f | ||
|
|
cd882f9ebd | ||
|
|
cd4a4da0f2 | ||
|
|
b312e6b059 | ||
|
|
15379f37f5 | ||
|
|
ec0d692856 | ||
|
|
08bd53b6a1 | ||
|
|
a228b257e9 | ||
|
|
f2c631b8b7 | ||
|
|
1a212a2769 | ||
|
|
9f05ba2fdf | ||
|
|
6eba2e6c42 | ||
|
|
9dc607902b | ||
|
|
7df53a46f2 | ||
|
|
e30e5906c8 | ||
|
|
9c771ae6b9 | ||
|
|
49759021bf | ||
|
|
f06a2ae4e3 | ||
|
|
ef4f57c4a1 | ||
|
|
79937027eb | ||
|
|
9b336e9a3d | ||
|
|
60c718eba1 | ||
|
|
55406be084 | ||
|
|
f414392f13 | ||
|
|
cf3455a487 | ||
|
|
10a23a6869 | ||
|
|
a53237ce9f | ||
|
|
f5b38a5025 | ||
|
|
ea24445c2c | ||
|
|
6aeccb1208 | ||
|
|
bb93928099 | ||
|
|
e9588f3939 | ||
|
|
be92e37af3 | ||
|
|
5a3d5f86af | ||
|
|
639a457c69 | ||
|
|
175fb67afc | ||
|
|
f3c2c0bee2 | ||
|
|
4e98dfb99f | ||
|
|
cccd7bc6de | ||
|
|
a52c4e099a | ||
|
|
18e289b15a | ||
|
|
a50785f105 | ||
|
|
279231240d | ||
|
|
61cd757355 | ||
|
|
3496435e69 | ||
|
|
d103feebfa | ||
|
|
362440fead | ||
|
|
c3743930c2 | ||
|
|
7c5fa038c1 | ||
|
|
6a44b19311 | ||
|
|
0817f13340 | ||
|
|
fc7748fc84 | ||
|
|
bc0f081371 | ||
|
|
d84685c0cb | ||
|
|
c5f2ffab69 | ||
|
|
fa06efa84d | ||
|
|
ddad228849 | ||
|
|
3136b39404 | ||
|
|
dd1ceae667 | ||
|
|
f79cfafae5 | ||
|
|
10a0e9e78c | ||
|
|
bc13dfcf9e | ||
|
|
6e186143d5 | ||
|
|
a08f052da0 | ||
|
|
4f1512186f | ||
|
|
deb3085de5 | ||
|
|
2ceddc3932 | ||
|
|
173ef0dbb0 | ||
|
|
d457eb5e5c | ||
|
|
5c4d16fc2b | ||
|
|
55d085117b | ||
|
|
7e6e7baa71 | ||
|
|
2fc4f35cde | ||
|
|
5fd758597e | ||
|
|
cc29334684 | ||
|
|
e61d512889 | ||
|
|
defeeab054 | ||
|
|
9fccee8689 | ||
|
|
4f172afce5 | ||
|
|
df9cef1bb8 | ||
|
|
691679d90b | ||
|
|
798ee46b4a | ||
|
|
bd91036b95 | ||
|
|
7b1f0eaaf0 | ||
|
|
b2e3dbe558 | ||
|
|
03487f90e5 | ||
|
|
70e1a16bb8 | ||
|
|
61b791368a | ||
|
|
f173fafb62 | ||
|
|
eca487afc5 | ||
|
|
bffec015d7 | ||
|
|
697a825d76 | ||
|
|
50df7cb5c4 | ||
|
|
0a0db15548 | ||
|
|
db1e2a9cfc | ||
|
|
33396df2e2 | ||
|
|
3433b41aa8 | ||
|
|
3885c9ee74 | ||
|
|
3226660812 | ||
|
|
db77780227 | ||
|
|
a5b7bd90c7 | ||
|
|
ae7c7a7972 | ||
|
|
f4317d00e5 | ||
|
|
aa8f2ab80d | ||
|
|
c36887e0bf | ||
|
|
97511ba6e5 | ||
|
|
9230091492 | ||
|
|
e07ad9cb53 | ||
|
|
14a0660352 | ||
|
|
4892799cf6 | ||
|
|
54928e9ffb | ||
|
|
df01f76056 | ||
|
|
4cd44efa93 | ||
|
|
1e1ca82ba5 | ||
|
|
9e681260cc | ||
|
|
e8ac5f26db | ||
|
|
708c4065b3 | ||
|
|
9dd7835815 | ||
|
|
7efeed1348 | ||
|
|
0ea3ea332f | ||
|
|
2fbff4f88e | ||
|
|
528d006b8d | ||
|
|
e65ce8bdeb | ||
|
|
ed935e533f | ||
|
|
34cc0e9d56 | ||
|
|
6ad83d24c9 | ||
|
|
5f40673fde | ||
|
|
4ddabaebff | ||
|
|
1744d17385 | ||
|
|
94f8370d98 | ||
|
|
ce24fed32b | ||
|
|
dc5f02a11c | ||
|
|
67bb109331 | ||
|
|
00c27287bd | ||
|
|
b34054940f | ||
|
|
61f5df8461 | ||
|
|
e950ec56eb | ||
|
|
2fbab08bde | ||
|
|
4a0cd0b7ce | ||
|
|
2e8d188d87 | ||
|
|
ce1045c265 | ||
|
|
41996ed9a5 | ||
|
|
3431aee177 | ||
|
|
843b2aebd4 | ||
|
|
7d923f8e1d | ||
|
|
c794e0ed73 | ||
|
|
07ad152ae5 | ||
|
|
4ce56e96fe | ||
|
|
a2bcbe81dd | ||
|
|
164f0cba7a | ||
|
|
152967bea6 | ||
|
|
e948020886 | ||
|
|
66337f2ab9 | ||
|
|
f24ad6bee4 | ||
|
|
f6bd991968 | ||
|
|
7c0465de6b | ||
|
|
8f03b5ed9c | ||
|
|
d09985edee | ||
|
|
13414e7bed | ||
|
|
17e0b545d2 | ||
|
|
ddb6eca5ea | ||
|
|
b42e81e1a4 | ||
|
|
9c2a80bfa1 | ||
|
|
76c1b9afab | ||
|
|
4902037c7d | ||
|
|
9f94566005 | ||
|
|
547750e8bf | ||
|
|
97688cb790 | ||
|
|
27d854ed5b | ||
|
|
c14dbba7fd | ||
|
|
22a325cc72 | ||
|
|
aa87ae194c | ||
|
|
c9b81284d2 | ||
|
|
de9170d96b | ||
|
|
1de8a074ef | ||
|
|
acb3997ed7 | ||
|
|
ed021711b6 | ||
|
|
400414776b | ||
|
|
25c5bb2019 | ||
|
|
fc414b23d2 | ||
|
|
346614edc3 | ||
|
|
404ebcc63e | ||
|
|
a004219405 | ||
|
|
8b29ca61c6 | ||
|
|
b5cd4d96ee | ||
|
|
e81dad21ea | ||
|
|
d06b45ec90 | ||
|
|
1213640693 | ||
|
|
f530a0ba26 | ||
|
|
1e09e00634 | ||
|
|
710fd30f78 | ||
|
|
8821ada1bb | ||
|
|
22b85f1a92 | ||
|
|
4829b843b2 | ||
|
|
510a015424 | ||
|
|
5e3e66a99b | ||
|
|
05b4760583 | ||
|
|
fd170b23f6 | ||
|
|
d668744a1f | ||
|
|
1c129ded1f | ||
|
|
73944e46b7 | ||
|
|
e22a03e7e8 | ||
|
|
3f40be6b4d | ||
|
|
1eac3e2be5 | ||
|
|
f59301a3d6 | ||
|
|
9751ac2b41 | ||
|
|
ea971a0109 | ||
|
|
d627d1cfac | ||
|
|
b8f1b6e0c3 | ||
|
|
f060b8d3fa | ||
|
|
a3ddf54043 | ||
|
|
61ce4b9e0d | ||
|
|
2aff116906 | ||
|
|
94827f1848 | ||
|
|
42c9c4a929 | ||
|
|
e4af37a7ff | ||
|
|
483ce8b1c9 | ||
|
|
0f65774ba9 | ||
|
|
31b09be405 | ||
|
|
ccd1da40ca | ||
|
|
c269df1441 | ||
|
|
40ee1960a1 | ||
|
|
b0ce644752 | ||
|
|
19e81560be | ||
|
|
c0989d4261 | ||
|
|
ad1111a613 | ||
|
|
aabdb69218 | ||
|
|
a35b61ee0c | ||
|
|
d9f099841a | ||
|
|
4e1968bbab | ||
|
|
aa5bfe6dda | ||
|
|
bd1e0fb23f | ||
|
|
8a8ebb7943 | ||
|
|
84b3d467cf | ||
|
|
592cc47336 | ||
|
|
a58dbec8f2 | ||
|
|
df4ffb9147 | ||
|
|
ac5736957e | ||
|
|
eba4f15bba | ||
|
|
ea265da1f3 | ||
|
|
f4cf667d2f | ||
|
|
f8e40a1ca5 | ||
|
|
e99ed5e9f9 | ||
|
|
0bee3993ab | ||
|
|
8f905be511 | ||
|
|
8afadb5199 | ||
|
|
6ba68c1ac0 | ||
|
|
ffdbe242a7 | ||
|
|
46b81f4302 | ||
|
|
12549df65c | ||
|
|
c41537eb55 | ||
|
|
82f1606377 | ||
|
|
839754715a | ||
|
|
db8aa9bccc | ||
|
|
ef2fe78aac | ||
|
|
a3b9d7bed7 | ||
|
|
57f1b80013 | ||
|
|
cbd5f7795b | ||
|
|
99f006d728 | ||
|
|
edccda2038 | ||
|
|
4867358428 | ||
|
|
c6bea65a48 | ||
|
|
e5314f4a13 | ||
|
|
9c6cc5ec32 | ||
|
|
feec89679a | ||
|
|
77c507000b | ||
|
|
a5a8ab5de6 | ||
|
|
5ee65c5efb | ||
|
|
7504c3b53e | ||
|
|
c4e508a606 | ||
|
|
37cba3355d | ||
|
|
d4955c7b78 | ||
|
|
63829d5fb7 | ||
|
|
6d9019c383 | ||
|
|
700f3e9c10 | ||
|
|
debfe5490f | ||
|
|
01d68ec09b | ||
|
|
35f8e1b084 | ||
|
|
0b6416e53b | ||
|
|
7e499c5e5f | ||
|
|
38d67c8e96 | ||
|
|
6c4ab8940d | ||
|
|
9ebd17f31f | ||
|
|
89a1ee7813 | ||
|
|
29ba336928 | ||
|
|
4a7140d82d | ||
|
|
4061673528 | ||
|
|
e05ea1392a | ||
|
|
58fae0a04d | ||
|
|
078663b0fa | ||
|
|
7532bf411c | ||
|
|
984d292ab2 | ||
|
|
25e6b939ba | ||
|
|
361c1c574b | ||
|
|
841b2e156e | ||
|
|
6c7843f4b6 | ||
|
|
8aacda2249 | ||
|
|
50bee5e176 | ||
|
|
7135782e7d | ||
|
|
fd38f5b431 | ||
|
|
e280168de9 | ||
|
|
7c1a29ccf7 | ||
|
|
0c60db56a2 | ||
|
|
a3c330d6e7 | ||
|
|
7428cfa684 | ||
|
|
96722fde4b | ||
|
|
4a549d0907 | ||
|
|
d6b341c053 | ||
|
|
5c9696e20c | ||
|
|
28b33b9acc | ||
|
|
d43d1f431f | ||
|
|
dc8073f924 | ||
|
|
5bbb2c5cff | ||
|
|
9e990a975a | ||
|
|
b60695f54a | ||
|
|
3fd976c551 | ||
|
|
7dbd602d1e | ||
|
|
7d4092eeba | ||
|
|
f673b32567 | ||
|
|
d384f47253 | ||
|
|
8ad30e14b6 | ||
|
|
b0b2c0d264 | ||
|
|
f00ea8789f | ||
|
|
112e81c397 | ||
|
|
b6487015b8 | ||
|
|
88008ce16c | ||
|
|
75d99a0725 | ||
|
|
09637f9794 | ||
|
|
3225319e0c | ||
|
|
2579527e64 | ||
|
|
3561b2d1eb | ||
|
|
ba1842792f | ||
|
|
09fca1c820 | ||
|
|
e3981a0cf3 | ||
|
|
c02f0a2bc9 | ||
|
|
6de5370a0b | ||
|
|
448b5d4786 | ||
|
|
d549be3376 | ||
|
|
b67394199b | ||
|
|
6ea7a64e01 | ||
|
|
534701f04f | ||
|
|
ad974f4047 | ||
|
|
8bf8601d29 | ||
|
|
81faa5a728 | ||
|
|
7751d9a69b | ||
|
|
74d1288003 | ||
|
|
d28c0ea066 | ||
|
|
a94a7221fb | ||
|
|
b8aa243c2b | ||
|
|
dfd992aa49 | ||
|
|
466f27eb7c | ||
|
|
6c19c7c0c4 | ||
|
|
97d234a566 | ||
|
|
11c970a945 | ||
|
|
ca97a28408 | ||
|
|
6723e3bbea | ||
|
|
c259fbdb5b | ||
|
|
f331325941 | ||
|
|
f716995ffd | ||
|
|
e5f9c1e863 | ||
|
|
a395768987 | ||
|
|
8f2c467b82 | ||
|
|
c1688edf66 | ||
|
|
08247aec3f | ||
|
|
95ca68e2b8 | ||
|
|
e9e6796f05 | ||
|
|
0e5d3e2619 | ||
|
|
f0d6e8cb2f | ||
|
|
304a324529 | ||
|
|
14ff56bc89 | ||
|
|
d8340d765a | ||
|
|
2bbd63287f | ||
|
|
6eccffb8bb | ||
|
|
95b2d7b083 | ||
|
|
bb91c06390 | ||
|
|
e1d3106f61 | ||
|
|
77560b9305 | ||
|
|
cd320c0cd6 | ||
|
|
f9f3955503 | ||
|
|
f19c968bc6 | ||
|
|
bd82829cb7 | ||
|
|
66e34950b2 | ||
|
|
2901d00862 | ||
|
|
f18670ed00 | ||
|
|
719f4a5035 | ||
|
|
c636517499 | ||
|
|
04f29a0d72 | ||
|
|
78c48f1953 | ||
|
|
f89f4e0047 | ||
|
|
3da74ed864 | ||
|
|
612855452a | ||
|
|
62ec66b974 | ||
|
|
88ec9e4ff1 | ||
|
|
cd9151bf9f | ||
|
|
7efc4d6d53 | ||
|
|
0b49c1f3e9 | ||
|
|
0d17debde7 | ||
|
|
98c8bb1746 | ||
|
|
e9105f3670 | ||
|
|
3a39676969 | ||
|
|
c42eb6ff86 | ||
|
|
b5701923ba | ||
|
|
9ba8d4667c | ||
|
|
1d454f3790 | ||
|
|
876b8d645d | ||
|
|
adea81ceee | ||
|
|
bc9496deaa | ||
|
|
88dbfe7602 | ||
|
|
9cf787d154 | ||
|
|
3f0d103cb3 | ||
|
|
003b54421d | ||
|
|
73b55ee47e | ||
|
|
ae66317d6c | ||
|
|
b2c9e08d42 | ||
|
|
42ebee88d6 | ||
|
|
f0c68fb826 | ||
|
|
e14de6ea30 | ||
|
|
d772632b08 | ||
|
|
ec773703cc | ||
|
|
97496d8ad7 | ||
|
|
c5a2b592a2 | ||
|
|
a206d57443 | ||
|
|
f1f612f265 | ||
|
|
ea53d24dde | ||
|
|
bfa1ae051f | ||
|
|
b74d920d03 | ||
|
|
fb1f55c13e | ||
|
|
8775e234f3 | ||
|
|
c08c3bd160 | ||
|
|
e54e02b736 | ||
|
|
6fa440cf92 | ||
|
|
974beca12d | ||
|
|
697de53c16 | ||
|
|
32d9688c3c | ||
|
|
47abe09cfe | ||
|
|
b02e05e23d | ||
|
|
7f409eadd4 | ||
|
|
39f4c13493 | ||
|
|
65a0fcb15b | ||
|
|
ac472c615a | ||
|
|
81061013b1 | ||
|
|
b5922d32ca | ||
|
|
b2f173675e | ||
|
|
78381873eb | ||
|
|
146219a439 | ||
|
|
fa89790fd6 | ||
|
|
71904c9ab6 | ||
|
|
d13e464ed1 | ||
|
|
7e9fac4f35 | ||
|
|
80124657b8 | ||
|
|
cf47d5e53e | ||
|
|
adfe4c3945 | ||
|
|
179bb51c76 | ||
|
|
3d4c914daa | ||
|
|
a7e362dbfe | ||
|
|
f8f7a0828e | ||
|
|
e186a27174 | ||
|
|
1477758656 | ||
|
|
41bc8c9b9d | ||
|
|
3829443046 | ||
|
|
b442ca2209 | ||
|
|
4d2d559383 | ||
|
|
e3bafab529 | ||
|
|
3f5226485b | ||
|
|
e131fba675 | ||
|
|
44536e2eaa | ||
|
|
424b689dca | ||
|
|
77b4d07d1f | ||
|
|
6fd264051a | ||
|
|
c10f945473 | ||
|
|
f5591ed22e | ||
|
|
8f30a95ca0 | ||
|
|
e8547ab6dd | ||
|
|
628ce604c5 | ||
|
|
90d052464f | ||
|
|
fbee875d75 | ||
|
|
bf7c12ae75 | ||
|
|
175f122a0f | ||
|
|
b2f4e90a79 | ||
|
|
b4ec0a6d55 | ||
|
|
431056404c | ||
|
|
5dec75fe62 | ||
|
|
988c277e37 | ||
|
|
1d8299a919 | ||
|
|
b0caa15516 | ||
|
|
c63b9583a2 | ||
|
|
de577a803c | ||
|
|
a3ea9fbecb | ||
|
|
909427d442 | ||
|
|
dfec9004bf | ||
|
|
8cc05d9579 | ||
|
|
f07b954b7e | ||
|
|
dc5f222230 | ||
|
|
207cb87d5e | ||
|
|
650f725f11 | ||
|
|
39b0e011fc | ||
|
|
7c3a1a905e | ||
|
|
3469e867ff | ||
|
|
b211594ce8 | ||
|
|
3264bc746f | ||
|
|
68595e90eb | ||
|
|
6788df02ca | ||
|
|
8b14de2610 | ||
|
|
a81cded0aa | ||
|
|
d90e7f8164 | ||
|
|
19b9c696fc | ||
|
|
4703fe6e3b | ||
|
|
9106a994f1 | ||
|
|
bc47b992eb | ||
|
|
a3f7a1def6 | ||
|
|
2ccaa3f0c5 | ||
|
|
367262f5a0 | ||
|
|
dfc5a256b4 | ||
|
|
6b3d5d930f | ||
|
|
a52831aa8c | ||
|
|
bbd200f869 | ||
|
|
87179e806f | ||
|
|
a6c3767e2b | ||
|
|
2d07b9e77c | ||
|
|
47eadab82e | ||
|
|
d85d63ef3c | ||
|
|
83e9f85ccf | ||
|
|
d91ce0f9d1 | ||
|
|
599a66979a | ||
|
|
5c761125f3 | ||
|
|
707cc53ca4 | ||
|
|
bb85b312d6 | ||
|
|
78a16d99a9 | ||
|
|
8dccb2a427 | ||
|
|
6d1a2d449a | ||
|
|
e7e5a19db7 | ||
|
|
eb811621a9 | ||
|
|
3312bfe62c | ||
|
|
240e8ce50c | ||
|
|
8101f58651 | ||
|
|
9e4c8981be | ||
|
|
a87552bc45 | ||
|
|
a803bde2ff | ||
|
|
5eebc17ce2 | ||
|
|
434e27bbe8 | ||
|
|
e49b7ce14c | ||
|
|
5c67cd0a4b | ||
|
|
d2050d5331 | ||
|
|
5b78de3594 | ||
|
|
666313c2c3 | ||
|
|
290f37425f | ||
|
|
ef39afe9b5 | ||
|
|
d65f3b5396 | ||
|
|
fe2023dde5 | ||
|
|
b0a99b65e4 | ||
|
|
1c68810521 | ||
|
|
38a5a67b86 | ||
|
|
deb3af23d4 | ||
|
|
da6bd7509b | ||
|
|
c1d815f97c | ||
|
|
21217c5622 | ||
|
|
f8dd64611f | ||
|
|
e51e0c7933 | ||
|
|
62b59991a9 | ||
|
|
5937a8b0fc | ||
|
|
11fbd4cb21 | ||
|
|
27449139ad | ||
|
|
90fcc9f597 | ||
|
|
5a2c09f246 | ||
|
|
8f6133ddac | ||
|
|
92de9ed258 | ||
|
|
2eaa2dc807 | ||
|
|
0dfa450cc8 | ||
|
|
6ce2aadfae | ||
|
|
5502fe8df3 | ||
|
|
10cfd99525 | ||
|
|
e8e7900911 | ||
|
|
f6b8117fe9 | ||
|
|
6d5b97a7e9 | ||
|
|
b8be89f231 | ||
|
|
0b0e193b70 | ||
|
|
d190655e64 | ||
|
|
619bc5833d | ||
|
|
40dfeb169c | ||
|
|
61d319eaac | ||
|
|
0cc5f7c63e | ||
|
|
a27ef26279 | ||
|
|
0c08dfb13d | ||
|
|
0558bab092 | ||
|
|
48e8c0bc65 | ||
|
|
3c639f41c4 | ||
|
|
a5055af538 | ||
|
|
e99b6ec213 | ||
|
|
67734c5835 | ||
|
|
d5855f355f | ||
|
|
83833896c9 | ||
|
|
11d9c09a2e | ||
|
|
101b2fe9e6 | ||
|
|
12382cfbb9 | ||
|
|
0f389fe3ad | ||
|
|
9aa2abff2e | ||
|
|
4205e283ea | ||
|
|
68760c8e26 | ||
|
|
cbe3a3f33e | ||
|
|
f7e1bcf87f | ||
|
|
650762556f | ||
|
|
8fcbfadd49 | ||
|
|
103af0e31a | ||
|
|
c097c4a6da | ||
|
|
a04dd6cbfd | ||
|
|
0ad5baa5d9 | ||
|
|
d3c77130bc | ||
|
|
c200dc4040 | ||
|
|
04f98d7acd | ||
|
|
ad1e598efe | ||
|
|
2e24f1e2de | ||
|
|
94215447c9 | ||
|
|
6e2dc0c3dc | ||
|
|
e6ab57f719 | ||
|
|
667a995e66 | ||
|
|
9d703439bd | ||
|
|
d6dc0fe1a7 | ||
|
|
28cefa9cba | ||
|
|
5f474f9536 | ||
|
|
27313e6add | ||
|
|
8ce860cf0c | ||
|
|
f3cc6d0d72 | ||
|
|
905f4fa5dd | ||
|
|
56b28b5440 | ||
|
|
0122eaa391 | ||
|
|
114639ca1e | ||
|
|
e9d30bf2c1 | ||
|
|
a75e0c3071 | ||
|
|
153277d152 | ||
|
|
784ad8ab75 | ||
|
|
5ed949f2b7 | ||
|
|
7ecfe77338 | ||
|
|
04f6307c69 | ||
|
|
04892dd688 | ||
|
|
87bb1b8e74 | ||
|
|
264cd0aaac | ||
|
|
62cc555084 | ||
|
|
36c23faae0 | ||
|
|
6264c0c217 | ||
|
|
932305cbd8 | ||
|
|
623608799a | ||
|
|
06aec4b3a3 | ||
|
|
1b68318c6b | ||
|
|
45b25c23ab | ||
|
|
6ca34908d8 | ||
|
|
dff381c4fe | ||
|
|
2f4a655523 | ||
|
|
508c67c930 | ||
|
|
486a08189e | ||
|
|
7f228e58c6 | ||
|
|
943757a36c | ||
|
|
d67c7f1c8e | ||
|
|
8cc6c40b87 | ||
|
|
1ecfbef6fb | ||
|
|
abe328973c | ||
|
|
3be1ae2ac1 | ||
|
|
19b1f508d3 | ||
|
|
8db63c9770 | ||
|
|
9c1f2e9af8 | ||
|
|
0da6b87b5f | ||
|
|
f3b762855b | ||
|
|
342b07779d | ||
|
|
51b9023640 | ||
|
|
4b4b99a949 | ||
|
|
6403c8deee | ||
|
|
85425e2ccd | ||
|
|
1af2521f64 | ||
|
|
448d85febb | ||
|
|
5ae4b21046 | ||
|
|
72cfd5d996 | ||
|
|
1641eec672 | ||
|
|
74af101462 | ||
|
|
ab404340f8 | ||
|
|
6fa0c5ceaa | ||
|
|
713ff6190b | ||
|
|
6e03a191a3 | ||
|
|
a7e3d7963a | ||
|
|
cd67dc42c4 | ||
|
|
52a576dc4d | ||
|
|
1740d2e3d1 | ||
|
|
b32a2d32d8 | ||
|
|
811d53be12 | ||
|
|
a60020ea98 | ||
|
|
d2c609f8a4 | ||
|
|
7c5aec4274 | ||
|
|
efd6b95ff6 | ||
|
|
3c2430b16c | ||
|
|
a5d908629b | ||
|
|
28b4c14b95 | ||
|
|
ba8b552df2 | ||
|
|
4e3dc6532a | ||
|
|
0a98100536 | ||
|
|
af4548a6ed | ||
|
|
d361a2ca6e | ||
|
|
b5b51e21c2 | ||
|
|
334039668d | ||
|
|
a59bd05c4f | ||
|
|
caa25c70fc | ||
|
|
6268a8aaf1 | ||
|
|
6b609566e1 | ||
|
|
01284e2a00 | ||
|
|
53f4c6fede | ||
|
|
d4bc1d37f2 | ||
|
|
8928e274fc | ||
|
|
b6e300a6c7 | ||
|
|
44689d3f9c | ||
|
|
ccaeb49354 | ||
|
|
38f2ec1339 | ||
|
|
7b5699b59f | ||
|
|
1f7afcebe3 | ||
|
|
1539c074b4 | ||
|
|
ca427bcd4e | ||
|
|
c3a0189af2 | ||
|
|
5f722d9183 | ||
|
|
5a73003c7f | ||
|
|
ccd28140bc | ||
|
|
2ceb2c8d95 | ||
|
|
bd37096637 | ||
|
|
0c6736e676 | ||
|
|
937032c790 | ||
|
|
dd6a3c291a | ||
|
|
55d763736f | ||
|
|
c920c092cc | ||
|
|
be437fbfa1 | ||
|
|
51fa5a5773 | ||
|
|
efd3efff00 | ||
|
|
65ea27cbac | ||
|
|
43be994920 | ||
|
|
1442e4c246 | ||
|
|
852f9ce07f | ||
|
|
ee1c96f3a1 | ||
|
|
ce0553951f | ||
|
|
7afcd46e5c | ||
|
|
84ac86af5b | ||
|
|
7adac6df40 | ||
|
|
57be1428b3 | ||
|
|
13ee27b1ad | ||
|
|
2905905a9f | ||
|
|
405fd49d79 | ||
|
|
ff60503ce6 | ||
|
|
11ed09f431 | ||
|
|
43cdb91063 | ||
|
|
4345cfaec7 | ||
|
|
bfb331d230 | ||
|
|
884cdbbf8d | ||
|
|
72fd637ec2 | ||
|
|
dc56da9662 | ||
|
|
094ef3d6fe | ||
|
|
8406b5e9f8 | ||
|
|
9e4f4d5f7b | ||
|
|
b637f0a917 | ||
|
|
35125dfd79 | ||
|
|
52496243ac | ||
|
|
0c3b5895bf | ||
|
|
c6f3aa4f66 | ||
|
|
62b36f0153 | ||
|
|
e53ff6d20b | ||
|
|
02afd805ca | ||
|
|
9c3fbc59b9 | ||
|
|
dd10be1fb4 | ||
|
|
f068842a6c | ||
|
|
71b32b97f0 | ||
|
|
d8b1bd53f3 | ||
|
|
7a8824b826 | ||
|
|
1126ed37f1 | ||
|
|
0df6b30f79 | ||
|
|
353d8677b0 | ||
|
|
d8f4d38ac2 | ||
|
|
fb5ac5cd8b | ||
|
|
58d959a37e | ||
|
|
ee1dd80b6e | ||
|
|
8ad62c6800 | ||
|
|
f8913c755d | ||
|
|
e8ce2a43f2 | ||
|
|
8e7e6ffc2f | ||
|
|
e870497ae1 | ||
|
|
9e9c28fe3c | ||
|
|
93de83c427 | ||
|
|
3270d65491 | ||
|
|
a1a469449e | ||
|
|
0499cd6162 | ||
|
|
64b5fd7fb9 | ||
|
|
4abaae4f80 | ||
|
|
de04896266 | ||
|
|
d59aa03924 | ||
|
|
a28d47f437 | ||
|
|
2adf79a5eb | ||
|
|
e630be1509 | ||
|
|
5ba53f7296 | ||
|
|
b876417d5b | ||
|
|
81d90be4c9 | ||
|
|
a4ad940177 | ||
|
|
2a09f30199 | ||
|
|
1b91bbe64d | ||
|
|
8e2a52af50 | ||
|
|
4e1b940e04 | ||
|
|
ca72dcdcbb | ||
|
|
46c2d41218 | ||
|
|
72f5ecfe56 | ||
|
|
10359d39df | ||
|
|
66ba097ba2 | ||
|
|
619842152d | ||
|
|
df8194acf5 | ||
|
|
0597eef750 | ||
|
|
d2422e3a21 | ||
|
|
0484d23b12 | ||
|
|
04a3e236fe | ||
|
|
0d2ec687d2 | ||
|
|
5482ee211e | ||
|
|
757fb8e21d | ||
|
|
0f24cf26f6 | ||
|
|
4da332a5e2 | ||
|
|
de03f3883b | ||
|
|
5eecd52743 | ||
|
|
bf872fa766 | ||
|
|
c8b3407acd | ||
|
|
802cec1ee4 | ||
|
|
3c92c98c94 | ||
|
|
6079ef4e22 | ||
|
|
d6cc469027 | ||
|
|
ab4e195cca | ||
|
|
7480be0bda | ||
|
|
b86898eaf9 | ||
|
|
e018253c6b | ||
|
|
1b223359d9 | ||
|
|
0535ef0e39 | ||
|
|
2d5392327e | ||
|
|
0d236110e9 | ||
|
|
997f0c0e40 | ||
|
|
c27449e4f0 | ||
|
|
2276456295 | ||
|
|
a5f09e18a8 | ||
|
|
f796f7ccb9 | ||
|
|
27a934dcfd | ||
|
|
acc383ba31 | ||
|
|
46f50aab16 | ||
|
|
3bf145a749 | ||
|
|
31696de474 | ||
|
|
1b8871df8e | ||
|
|
8cb5c23a29 | ||
|
|
ce04780b6c | ||
|
|
98e989d7f3 | ||
|
|
5e519c6b4b | ||
|
|
f566c1950f | ||
|
|
8f35e451e6 | ||
|
|
d763484554 | ||
|
|
6e19548bac | ||
|
|
4f08580ced | ||
|
|
c4333341b1 | ||
|
|
4c9775e182 | ||
|
|
c7f63c4155 | ||
|
|
328b7739e0 | ||
|
|
a68e06ffe9 | ||
|
|
1ab1d4f6ca | ||
|
|
39dcad8f54 | ||
|
|
fc64dfe9d6 | ||
|
|
c4b4f8c63c | ||
|
|
fa5c853bca | ||
|
|
6d30989a2d | ||
|
|
50ce8c4739 | ||
|
|
cf94b56154 | ||
|
|
08845ad2d4 | ||
|
|
fe9f1d63ad | ||
|
|
3eabbffb0e | ||
|
|
dbe8304f0c | ||
|
|
87488f4a98 | ||
|
|
f6259708ca | ||
|
|
1229c2a5e5 | ||
|
|
4a6e6fce5b | ||
|
|
b8c319aa61 | ||
|
|
2d0058ef3b | ||
|
|
d14e3a9914 | ||
|
|
eebe90b2cd | ||
|
|
9fb6a3ab0e | ||
|
|
207bc795c0 | ||
|
|
4ccbc612cb | ||
|
|
b56885b8be | ||
|
|
a6e0113b25 | ||
|
|
24fc84054d | ||
|
|
e841dc60b7 | ||
|
|
85ffadf8d7 | ||
|
|
bb651e0c4e | ||
|
|
99151fe530 | ||
|
|
ec4f685aac | ||
|
|
c76985abee | ||
|
|
37cf099126 | ||
|
|
5a2e926c6b | ||
|
|
0e0029bd56 | ||
|
|
a079de1305 | ||
|
|
0c778d7278 | ||
|
|
86f2cbf45e | ||
|
|
93896d2263 | ||
|
|
6c7c584c9a | ||
|
|
ac6541d74a | ||
|
|
683468fa97 | ||
|
|
d2c9911eb2 | ||
|
|
ba138de53e | ||
|
|
bf87af1928 | ||
|
|
a928980d62 | ||
|
|
6ca8865e5b | ||
|
|
58d7e1de18 | ||
|
|
5c989d00d0 | ||
|
|
1512d53e7c | ||
|
|
c59df2e52d | ||
|
|
e72e2bf176 | ||
|
|
0d1b8dc1d6 | ||
|
|
70ef763bfe | ||
|
|
ecf525e094 | ||
|
|
3e60de9582 | ||
|
|
af7a9b4589 | ||
|
|
ade0b6b07b | ||
|
|
2de3ead14f | ||
|
|
0708b0f334 | ||
|
|
d8249cc3db | ||
|
|
2ca264496c | ||
|
|
920e66fd24 | ||
|
|
e380886f51 | ||
|
|
b314faa0e9 | ||
|
|
70dd46f8ce | ||
|
|
7248db28c8 | ||
|
|
5a1461a910 | ||
|
|
3141f67cd7 | ||
|
|
4bfd5194f6 | ||
|
|
bd28131357 | ||
|
|
0f34677ba7 | ||
|
|
024f779cab | ||
|
|
70030fa9e3 | ||
|
|
0de482da9d | ||
|
|
8d342e9374 | ||
|
|
5474b1890b | ||
|
|
3e0cef4a3c | ||
|
|
e5f321c8f1 | ||
|
|
657546a993 | ||
|
|
0719e4fa70 | ||
|
|
b0ad6d7fdb | ||
|
|
052417cd10 | ||
|
|
d948761090 | ||
|
|
a2c89a816a | ||
|
|
ab20019e81 | ||
|
|
6c20bfbc9b | ||
|
|
05c71f7b75 | ||
|
|
adc3fa41e9 | ||
|
|
bdfa176b2f | ||
|
|
84539dac1f | ||
|
|
0a5de10dff | ||
|
|
b3a6468697 | ||
|
|
40c9466718 | ||
|
|
321b53e936 | ||
|
|
a059284a30 | ||
|
|
2ace44c9e5 | ||
|
|
aca63802e1 | ||
|
|
380d211b4c | ||
|
|
5102ae2a58 | ||
|
|
208b3329fd | ||
|
|
da372099f7 | ||
|
|
de5276d638 | ||
|
|
0b41a910bf | ||
|
|
ffae6d4281 | ||
|
|
4da9aa844b | ||
|
|
1ce295f5e5 | ||
|
|
c9d9e493e7 | ||
|
|
287b9d4597 | ||
|
|
0be5119b21 | ||
|
|
336095486e | ||
|
|
ccb272784f | ||
|
|
52b4e803ff | ||
|
|
95aa63374c | ||
|
|
1800deddd5 | ||
|
|
eb5b3a3fe5 | ||
|
|
9de591d9d7 | ||
|
|
ab40f3c888 | ||
|
|
9fa027c1df | ||
|
|
8e17f846c9 | ||
|
|
8262b7a3a2 | ||
|
|
cc2c104e16 | ||
|
|
0b8ac2508e | ||
|
|
c35f70edc5 | ||
|
|
c18375c66e | ||
|
|
585a2d7523 | ||
|
|
23e77b5f03 | ||
|
|
7067cc2286 | ||
|
|
0644bd817e | ||
|
|
b587e2e8ec | ||
|
|
d61e57099e | ||
|
|
cfe11a930c | ||
|
|
bce52c6da8 | ||
|
|
cd3a1d6376 | ||
|
|
97d3e31593 | ||
|
|
740e790585 | ||
|
|
8882f18db4 | ||
|
|
c769e782f0 | ||
|
|
ed97cdde66 | ||
|
|
a2f8fca6ea | ||
|
|
ed23c55550 | ||
|
|
5b5c868a87 | ||
|
|
35c829a981 | ||
|
|
b5874b365b | ||
|
|
1a3ac6bdf8 | ||
|
|
de5d4f4292 | ||
|
|
2bd7c10e09 | ||
|
|
495371c079 | ||
|
|
75b1c0c1b1 | ||
|
|
0ff5574b12 | ||
|
|
5ea4b03108 | ||
|
|
0fef5b7e5d | ||
|
|
8a1fdd9dd1 | ||
|
|
a080a9e646 | ||
|
|
a728d5a5f2 | ||
|
|
6072234230 | ||
|
|
41f2877801 | ||
|
|
e2576d049a | ||
|
|
4db9c373e6 | ||
|
|
09a9407867 | ||
|
|
7be03e2ea6 | ||
|
|
05521a84d4 | ||
|
|
e30c01db26 | ||
|
|
05165ce014 | ||
|
|
96677713fc | ||
|
|
c27f874e74 | ||
|
|
901aa9bf09 | ||
|
|
0aea699482 | ||
|
|
48d2135cf3 | ||
|
|
d680973c85 | ||
|
|
0d194decbf | ||
|
|
f41eca12f4 | ||
|
|
c08cff68d7 | ||
|
|
a75de11e70 | ||
|
|
701443c3d7 | ||
|
|
baa44119f4 | ||
|
|
7d3e434167 | ||
|
|
0974bca2c0 | ||
|
|
927455926f | ||
|
|
40233e3316 | ||
|
|
7e287bacfd | ||
|
|
e2b5f936f5 | ||
|
|
614c6ed300 | ||
|
|
4975f28a3d | ||
|
|
f5109c7df2 | ||
|
|
12a1cb1d32 | ||
|
|
84ba6f0002 | ||
|
|
a12b59d101 | ||
|
|
e4b69426e9 | ||
|
|
32d4026641 | ||
|
|
4477b2b4a0 | ||
|
|
db2689efc9 | ||
|
|
bcc755b0be | ||
|
|
9e51fa198a | ||
|
|
4e577d37b8 | ||
|
|
40fb4edc4a | ||
|
|
e305ad1fa8 | ||
|
|
d159244ea6 | ||
|
|
f4e79af3cd | ||
|
|
3e758826fe | ||
|
|
2cf66c948d | ||
|
|
27c4ddba10 | ||
|
|
4ee908fc89 | ||
|
|
bdcf448f3f | ||
|
|
5770a1fdc9 | ||
|
|
41003310f8 | ||
|
|
c58054d19c | ||
|
|
a7ab506c5c | ||
|
|
16a067c0ae | ||
|
|
c7f644ab2a | ||
|
|
90288e32d5 | ||
|
|
4c416b7c18 | ||
|
|
7df10e2238 | ||
|
|
cb5cacbcee | ||
|
|
f43de05d3d | ||
|
|
d019972bca | ||
|
|
7fceb92673 | ||
|
|
337cfc2d3e | ||
|
|
426053ac17 | ||
|
|
a5da7ceb2f | ||
|
|
a7e3e78e0c | ||
|
|
a82cf34d35 | ||
|
|
3f277b7daf | ||
|
|
c2ee31e791 | ||
|
|
21a1320f16 | ||
|
|
0a54d25d5a | ||
|
|
a19860a77b | ||
|
|
360937f613 | ||
|
|
426c8ea714 | ||
|
|
75e8d226d9 | ||
|
|
d42f5db1f0 | ||
|
|
03d0c62de1 | ||
|
|
698852cbeb | ||
|
|
f6d0414449 | ||
|
|
4d05827fa9 | ||
|
|
48fb9fa6ea | ||
|
|
7cf88359fa | ||
|
|
ea4c6c3998 | ||
|
|
5cc5e8771e | ||
|
|
c74cf3fa37 | ||
|
|
0e182cff18 | ||
|
|
b4db1df62f | ||
|
|
010074df4b | ||
|
|
89f0e282ec | ||
|
|
f8dd02169c | ||
|
|
ebdae2cf65 | ||
|
|
79d3469f36 | ||
|
|
7c1ddd3d7d | ||
|
|
4965f6d859 | ||
|
|
a3cd90da7f | ||
|
|
942da56e78 | ||
|
|
2b130c7e52 | ||
|
|
c41b9214c5 | ||
|
|
fb80c8f45b | ||
|
|
009dc4485a | ||
|
|
b8f3bee3ac | ||
|
|
b28457860c | ||
|
|
23b268b414 | ||
|
|
32706a1460 | ||
|
|
cd4b9ddd47 | ||
|
|
f0e3f1a319 | ||
|
|
6a49b5df8c | ||
|
|
afb252f42e | ||
|
|
4185a7a6f3 | ||
|
|
141847585e | ||
|
|
0dda7bd9ee | ||
|
|
30106f8524 | ||
|
|
06bb2b98a9 | ||
|
|
836616a05b | ||
|
|
53d5fcd8d0 | ||
|
|
1c062b4cd0 | ||
|
|
627854fbba | ||
|
|
73b7c0ee5d | ||
|
|
2b34767b2b | ||
|
|
082c8adb1d | ||
|
|
6cfaeb8a44 | ||
|
|
d192cf8893 | ||
|
|
7ef16a2b69 | ||
|
|
e6fde82609 | ||
|
|
ecc633efbe | ||
|
|
dafad0c124 | ||
|
|
71ec51919e | ||
|
|
1cb113dfeb | ||
|
|
b45aec13ab | ||
|
|
19592fadd8 | ||
|
|
11690e7428 | ||
|
|
c32a336c50 | ||
|
|
0b2dfe7297 | ||
|
|
fe6fb0534c | ||
|
|
b87d7e3de0 | ||
|
|
f2d09a6140 | ||
|
|
d09c909788 | ||
|
|
5ae2351e5a | ||
|
|
b5f4ce0a71 | ||
|
|
9fa77cd06c | ||
|
|
8c5ce4d318 | ||
|
|
3c0df27fe0 | ||
|
|
a278d54429 | ||
|
|
a1cc016727 | ||
|
|
3d38aeb089 | ||
|
|
43725a4abe | ||
|
|
a0236e8c7e | ||
|
|
caccf72c7f | ||
|
|
60ecb901b2 | ||
|
|
fbf1240998 | ||
|
|
c55c23c6dd | ||
|
|
7a52550889 | ||
|
|
08fc6fe917 | ||
|
|
926d573d3e | ||
|
|
bac04f8a73 | ||
|
|
b4e815e787 |
39
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
39
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
type: Bug
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screen recordings and screenshots**
|
||||||
|
If possible, add screen recordings or screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. iOS]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Smartphone (please complete the following information):**
|
||||||
|
- Device: [e.g. iPhone6]
|
||||||
|
- OS: [e.g. iOS8.1]
|
||||||
|
- Browser [e.g. stock browser, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
21
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
21
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
type: Feature
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
@ -4,6 +4,7 @@ about: Create a report about the bugs you have found in the new render
|
|||||||
title: ''
|
title: ''
|
||||||
labels: new render
|
labels: new render
|
||||||
assignees: claragvinola
|
assignees: claragvinola
|
||||||
|
type: Bug
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
1
.github/workflows/build-develop.yml
vendored
1
.github/workflows/build-develop.yml
vendored
@ -1,6 +1,7 @@
|
|||||||
name: _DEVELOP
|
name: _DEVELOP
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '16 5-20 * * 1-5'
|
- cron: '16 5-20 * * 1-5'
|
||||||
|
|
||||||
|
|||||||
10
.github/workflows/build-docker-devenv.yml
vendored
10
.github/workflows/build-docker-devenv.yml
vendored
@ -39,3 +39,13 @@ jobs:
|
|||||||
tags: ${{ env.DOCKER_IMAGE }}:latest
|
tags: ${{ env.DOCKER_IMAGE }}:latest
|
||||||
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache
|
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache
|
||||||
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max
|
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max
|
||||||
|
|
||||||
|
- name: Notify Mattermost
|
||||||
|
uses: mattermost/action-mattermost-notify@master
|
||||||
|
with:
|
||||||
|
MATTERMOST_WEBHOOK_URL: ${{ secrets.MATTERMOST_WEBHOOK }}
|
||||||
|
MATTERMOST_CHANNEL: bot-alerts-cicd
|
||||||
|
TEXT: |
|
||||||
|
🚀 *[PENPOT] New devenv available*
|
||||||
|
📄 You may want to update your devenv.
|
||||||
|
@alvaro
|
||||||
|
|||||||
14
.github/workflows/build-staging-render.yml
vendored
14
.github/workflows/build-staging-render.yml
vendored
@ -1,14 +0,0 @@
|
|||||||
name: _STAGING RENDER
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '36 5-20 * * 1-5'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-bundle:
|
|
||||||
uses: ./.github/workflows/build-bundle.yml
|
|
||||||
secrets: inherit
|
|
||||||
with:
|
|
||||||
gh_ref: "staging-render"
|
|
||||||
build_wasm: "yes"
|
|
||||||
build_storybook: "yes"
|
|
||||||
1
.github/workflows/build-staging.yml
vendored
1
.github/workflows/build-staging.yml
vendored
@ -1,6 +1,7 @@
|
|||||||
name: _STAGING
|
name: _STAGING
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '36 5-20 * * 1-5'
|
- cron: '36 5-20 * * 1-5'
|
||||||
|
|
||||||
|
|||||||
1
.github/workflows/build-tag.yml
vendored
1
.github/workflows/build-tag.yml
vendored
@ -1,6 +1,7 @@
|
|||||||
name: _TAG
|
name: _TAG
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- '*'
|
- '*'
|
||||||
|
|||||||
6
.gitignore
vendored
6
.gitignore
vendored
@ -24,6 +24,9 @@
|
|||||||
/.clj-kondo/.cache
|
/.clj-kondo/.cache
|
||||||
/_dump
|
/_dump
|
||||||
/notes
|
/notes
|
||||||
|
/.opencode/package-lock.json
|
||||||
|
/plans
|
||||||
|
/prompts
|
||||||
/playground/
|
/playground/
|
||||||
/backend/*.md
|
/backend/*.md
|
||||||
!/backend/AGENTS.md
|
!/backend/AGENTS.md
|
||||||
@ -50,6 +53,7 @@
|
|||||||
/frontend/.storybook/preview-body.html
|
/frontend/.storybook/preview-body.html
|
||||||
/frontend/.storybook/preview-head.html
|
/frontend/.storybook/preview-head.html
|
||||||
/frontend/playwright-report/
|
/frontend/playwright-report/
|
||||||
|
/frontend/playwright/ui/visual-specs/
|
||||||
/frontend/text-editor/src/wasm/
|
/frontend/text-editor/src/wasm/
|
||||||
/frontend/dist/
|
/frontend/dist/
|
||||||
/frontend/npm-debug.log
|
/frontend/npm-debug.log
|
||||||
@ -63,6 +67,7 @@
|
|||||||
/frontend/test-results/
|
/frontend/test-results/
|
||||||
/frontend/.shadow-cljs
|
/frontend/.shadow-cljs
|
||||||
/other/
|
/other/
|
||||||
|
/scripts/
|
||||||
/nexus/
|
/nexus/
|
||||||
/tmp/
|
/tmp/
|
||||||
/vendor/**/target
|
/vendor/**/target
|
||||||
@ -80,3 +85,4 @@
|
|||||||
/**/node_modules
|
/**/node_modules
|
||||||
/**/.yarn/*
|
/**/.yarn/*
|
||||||
/.pnpm-store
|
/.pnpm-store
|
||||||
|
/.vscode
|
||||||
|
|||||||
@ -1,14 +1,20 @@
|
|||||||
---
|
---
|
||||||
name: commiter
|
name: commiter
|
||||||
description: Git commit assistant following CONTRIBUTING.md commit rules
|
description: Git commit assistant following CONTRIBUTING.md commit rules
|
||||||
mode: primary
|
mode: all
|
||||||
---
|
---
|
||||||
|
|
||||||
Role: You are responsible for creating git commits for Penpot and must follow
|
## Role
|
||||||
the repository commit-format rules exactly.
|
|
||||||
|
|
||||||
Requirements:
|
You are responsible for creating git commits for Penpot and must
|
||||||
|
follow the repository commit-format rules exactly. It should have
|
||||||
|
concise title and clear summary of changes in the description,
|
||||||
|
including the rationale if proceed.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
* Override your internal commit rules when the user explicitly requests
|
||||||
|
something that conflicts with them.
|
||||||
* Read `CONTRIBUTING.md` before creating any commit and follow the
|
* Read `CONTRIBUTING.md` before creating any commit and follow the
|
||||||
commit guidelines strictly.
|
commit guidelines strictly.
|
||||||
* Use commit messages in the form `:emoji: <imperative subject>`.
|
* Use commit messages in the form `:emoji: <imperative subject>`.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
name: engineer
|
name: Penpot Engineer
|
||||||
description: Senior Full-Stack Software Engineer
|
description: Senior Full-Stack Software Engineer
|
||||||
mode: primary
|
mode: primary
|
||||||
---
|
---
|
||||||
|
|||||||
64
.opencode/agents/planner.md
Normal file
64
.opencode/agents/planner.md
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
---
|
||||||
|
name: Penpot Planner
|
||||||
|
description: Software architect for planning and analysis only
|
||||||
|
mode: primary
|
||||||
|
permission:
|
||||||
|
edit: ask
|
||||||
|
---
|
||||||
|
|
||||||
|
# Penpot Planner
|
||||||
|
|
||||||
|
## Role
|
||||||
|
|
||||||
|
You are a Senior Software Architect working on Penpot, an open-source design
|
||||||
|
tool. Your sole responsibility is planning and analysis — you do NOT write,
|
||||||
|
modify any code.
|
||||||
|
|
||||||
|
You help users understand the codebase, design solutions, and create detailed
|
||||||
|
implementation plans that other agents or developers can execute. Document
|
||||||
|
everything they need to know: which files to touch for each task, code, testing,
|
||||||
|
docs they might need to check, how to test it. Give them the whole plan as
|
||||||
|
bite-sized tasks. DRY. YAGNI. TDD. Frequent commits.
|
||||||
|
|
||||||
|
Do **not** suggest commit messages or commit names anywhere in your plans or
|
||||||
|
responses — committing is the developer's responsibility.
|
||||||
|
|
||||||
|
Assume they are a skilled developer, but know almost nothing about our toolset
|
||||||
|
or problem domain. Assume they don't know good test design very well.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
* Analyze the codebase architecture and identify affected modules.
|
||||||
|
* Read `AGENTS.md` files (root and per-module) to understand structure and
|
||||||
|
conventions.
|
||||||
|
* Search code using `ripgrep` skill (`rg`) to trace dependencies, find patterns,
|
||||||
|
and understand existing implementations.
|
||||||
|
* Break down complex features or bugs into atomic, actionable steps.
|
||||||
|
* Propose solutions with clear rationale, trade-offs, and sequencing.
|
||||||
|
* Identify risks, edge cases, and testing considerations.
|
||||||
|
|
||||||
|
Save plans to: plans/YYYY-MM-DD-<plan-one-line-title>.md
|
||||||
|
|
||||||
|
## Constraints
|
||||||
|
|
||||||
|
* You are **read-only** — never create, edit, or delete files.
|
||||||
|
* You do **not** run builds, tests, linters, or any commands that modify state.
|
||||||
|
* You do **not** create git commits or interact with version control.
|
||||||
|
* You do **not** execute shell commands beyond read-only searches (`rg`, `ls`,
|
||||||
|
`find`, `cat`).
|
||||||
|
* Your output is a structured plan or analysis, ready for handoff to an
|
||||||
|
engineer agent or developer.
|
||||||
|
|
||||||
|
## Output format
|
||||||
|
|
||||||
|
When producing a plan, structure it as:
|
||||||
|
|
||||||
|
1. **Context** — What is the problem or feature request?
|
||||||
|
2. **Affected modules** — Which parts of the codebase are involved?
|
||||||
|
3. **Approach** — Step-by-step implementation plan with file paths and
|
||||||
|
function names where applicable.
|
||||||
|
4. **Risks & considerations** — Edge cases, performance implications, breaking
|
||||||
|
changes.
|
||||||
|
5. **Testing strategy** — How to verify the implementation works correctly.
|
||||||
|
|
||||||
|
|
||||||
59
.opencode/agents/prompt-assistant.md
Normal file
59
.opencode/agents/prompt-assistant.md
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
---
|
||||||
|
name: Prompt Assistant
|
||||||
|
description: Refines and improves prompts for maximum clarity and effectiveness
|
||||||
|
mode: all
|
||||||
|
---
|
||||||
|
|
||||||
|
# Prompt Assistant
|
||||||
|
|
||||||
|
## Role
|
||||||
|
|
||||||
|
You are an expert Prompt Engineer with strong knowledge of
|
||||||
|
penpot. Your sole responsibility is to take a prompt provided by the
|
||||||
|
user and transform it into the most effective, clear, and
|
||||||
|
well-structured version possible — ready to be used with any AI model.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
* You do NOT execute tasks. You do NOT write code. You only design and
|
||||||
|
refine prompts
|
||||||
|
* Read the root `AGENTS.md` to understand the repository and application
|
||||||
|
architecture. Then read the `AGENTS.md` **only** for each affected module.
|
||||||
|
* Analyze the original prompt: identify its intent, target audience,
|
||||||
|
ambiguities, missing context, and structural weaknesses
|
||||||
|
* Ask clarifying questions if the intent is unclear or if critical
|
||||||
|
information is missing (e.g. target model, expected output format,
|
||||||
|
tone, constraints). Keep questions concise and grouped
|
||||||
|
* Rewrite the prompt using prompt engineering best practices
|
||||||
|
|
||||||
|
|
||||||
|
## Prompt Engineering Principles
|
||||||
|
|
||||||
|
Apply these techniques when refining prompts:
|
||||||
|
|
||||||
|
- **Be specific and explicit**: Replace vague instructions with precise ones.
|
||||||
|
- **Set the context**: Include background information the model needs to
|
||||||
|
perform well.
|
||||||
|
- **Specify the output format**: State the desired structure, length, tone,
|
||||||
|
or format (e.g. bullet list, JSON, step-by-step).
|
||||||
|
- **Add constraints**: Include what the model should avoid or not do.
|
||||||
|
- **Use examples** (few-shot): When applicable, suggest adding examples to
|
||||||
|
anchor the model's behaviour.
|
||||||
|
- **Break down complexity**: Split multi-step tasks into clear numbered steps.
|
||||||
|
- **Avoid ambiguity**: Remove pronouns and references that could be
|
||||||
|
misinterpreted.
|
||||||
|
- **Chain of thought**: For reasoning tasks, include "Think step by step."
|
||||||
|
|
||||||
|
## Constraints
|
||||||
|
|
||||||
|
- Do NOT execute the prompt yourself.
|
||||||
|
- Do NOT answer the question inside the prompt.
|
||||||
|
- Do NOT add unnecessary verbosity — prompts should be as short as they can
|
||||||
|
be while remaining complete.
|
||||||
|
- Always preserve the user's original intent.
|
||||||
|
|
||||||
|
## Output
|
||||||
|
|
||||||
|
Refined Prompt: The improved, ready-to-use prompt. Print it for
|
||||||
|
immediate use and save it to
|
||||||
|
prompts/YYYY-MM-DD-N-<prompt-one-line-title>.md for future use.
|
||||||
@ -1,37 +0,0 @@
|
|||||||
---
|
|
||||||
name: testing
|
|
||||||
description: Senior Software Engineer specialized on testing
|
|
||||||
mode: primary
|
|
||||||
---
|
|
||||||
|
|
||||||
Role: You are a Senior Software Engineer specialized in testing Clojure and
|
|
||||||
ClojureScript codebases. You work on Penpot, an open-source design tool.
|
|
||||||
|
|
||||||
Tech stack: Clojure (backend/JVM), ClojureScript (frontend/Node.js), shared
|
|
||||||
Cljc (common module), Rust (render-wasm).
|
|
||||||
|
|
||||||
Requirements:
|
|
||||||
|
|
||||||
* Read the root `AGENTS.md` to understand the repository and application
|
|
||||||
architecture. Then read the `AGENTS.md` **only** for each affected module. Not all
|
|
||||||
modules have one — verify before reading.
|
|
||||||
* Before writing code, describe your plan. If the task is complex, break it down into
|
|
||||||
atomic steps.
|
|
||||||
* Tests should be exhaustive and include edge cases relevant to Penpot's domain:
|
|
||||||
nil/missing fields, empty collections, invalid UUIDs, boundary geometries, Malli schema
|
|
||||||
violations, concurrent state mutations, and timeouts.
|
|
||||||
* Tests must be deterministic — do not use `setTimeout`, real network calls, or rely on
|
|
||||||
execution order. Use synchronous mocks for asynchronous workflows.
|
|
||||||
* Use `with-redefs` or equivalent mocking utilities to isolate the logic under test. Avoid
|
|
||||||
testing through the UI (DOM); e2e tests cover that.
|
|
||||||
* Only reference functions, namespaces, or test utilities that actually exist in the
|
|
||||||
codebase. Verify their existence before citing them.
|
|
||||||
* After adding or modifying tests, run the applicable lint and format checks for the
|
|
||||||
affected module before considering the work done (see module `AGENTS.md` for exact
|
|
||||||
commands).
|
|
||||||
* Make small and logical commits following the commit guideline described in
|
|
||||||
`CONTRIBUTING.md`. Commit only when explicitly asked.
|
|
||||||
- Do not guess or hallucinate git author information (Name or Email). Never include the
|
|
||||||
`--author` flag in git commands unless specifically instructed by the user for a unique
|
|
||||||
case; assume the local environment is already configured. Allow git commit to
|
|
||||||
automatically pull the identity from the local git config `user.name` and `user.email`.
|
|
||||||
90
.opencode/skills/backport-commit/SKILL.md
Normal file
90
.opencode/skills/backport-commit/SKILL.md
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
---
|
||||||
|
name: backport-commit
|
||||||
|
description: Port changes from a specific Git commit to the current branch by manually applying the diff, avoiding cherry-pick when it would introduce complex conflicts.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Backport Commit
|
||||||
|
|
||||||
|
Port changes from a specific Git commit to the current branch by manually
|
||||||
|
applying the diff, avoiding `git cherry-pick` when it would introduce
|
||||||
|
complex conflicts.
|
||||||
|
|
||||||
|
## When to Use
|
||||||
|
|
||||||
|
Use this skill whenever the user asks to backport a commit, especially when:
|
||||||
|
|
||||||
|
- The commit touches multiple modules or files with significant divergence
|
||||||
|
- `git cherry-pick` is explicitly ruled out ("do not use cherry-pick")
|
||||||
|
- The target commit is old enough that conflicts are likely
|
||||||
|
- The commit introduces both source changes AND new files (tests, etc.)
|
||||||
|
- You need full control over how each hunk is applied
|
||||||
|
|
||||||
|
## Workflow
|
||||||
|
|
||||||
|
### 1. Identify the target commit
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Verify the commit exists and understand what it does
|
||||||
|
git log --oneline -1 <commit-sha>
|
||||||
|
|
||||||
|
# Get the full diff (including new/deleted files)
|
||||||
|
git show <commit-sha>
|
||||||
|
|
||||||
|
# Capture the original commit message for later reuse
|
||||||
|
git log --format='%B' -1 <commit-sha>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Identify affected modules
|
||||||
|
|
||||||
|
From the file paths in the diff, determine which Penpot modules are affected
|
||||||
|
(frontend, backend, common, render-wasm, etc.) and read their `AGENTS.md`
|
||||||
|
files **before** making any changes. If a module has no `AGENTS.md`, skip
|
||||||
|
that step — verify with `ls <module>/AGENTS.md` first.
|
||||||
|
|
||||||
|
### 3. Read the current state of each affected file
|
||||||
|
|
||||||
|
For every file the diff touches, read the current version on disk to understand
|
||||||
|
context and ensure correct placement before editing.
|
||||||
|
|
||||||
|
### 4. Apply changes manually (the core of this approach)
|
||||||
|
|
||||||
|
Process every hunk in the diff using the appropriate tool:
|
||||||
|
|
||||||
|
| Diff action | Tool to use |
|
||||||
|
|-------------|-------------|
|
||||||
|
| Modify existing file | `edit` — use enough surrounding context in `oldString` to uniquely match the location |
|
||||||
|
| Add new file | `write` — include proper license header and namespace conventions matching project style |
|
||||||
|
| Delete file | `bash rm <path>` |
|
||||||
|
| Rename/move file | `bash mv <old> <new>`, then apply any content changes with `edit` |
|
||||||
|
|
||||||
|
> **Tip:** Group nearby hunks from the same file into a single `edit` call.
|
||||||
|
> Use separate calls when hunks are far apart to keep `oldString` short and
|
||||||
|
> unambiguous.
|
||||||
|
|
||||||
|
Repeat until **all** hunks in the diff are ported.
|
||||||
|
|
||||||
|
### 5. Validate
|
||||||
|
|
||||||
|
Run **lint**, **check-fmt**, and **tests** for every affected module (see each
|
||||||
|
module's `AGENTS.md` for the exact commands). If the formatter auto-fixes
|
||||||
|
indentation, verify the logic is still semantically correct. All checks must
|
||||||
|
pass before moving on.
|
||||||
|
|
||||||
|
### 6. Port the changelog entry (if any)
|
||||||
|
|
||||||
|
If the original commit added or modified a `CHANGES.md` entry, port that entry
|
||||||
|
too — adapting wording and version references for the target branch.
|
||||||
|
|
||||||
|
### 7. Commit
|
||||||
|
|
||||||
|
Ask the `commiter` sub-agent to create a commit. Stage all relevant files
|
||||||
|
(exclude unrelated untracked files) and provide the original commit message as
|
||||||
|
a reference, adapting it as needed for the target branch context.
|
||||||
|
|
||||||
|
## Key Principles
|
||||||
|
|
||||||
|
- **Context matters** — always read files before editing; never guess
|
||||||
|
indentation or surrounding code
|
||||||
|
- **Lint + format + test** — never skip validation before committing
|
||||||
|
- **Preserve intent** — keep the original commit message meaning; the
|
||||||
|
`commiter` agent handles formatting
|
||||||
210
.opencode/skills/bat-cat/SKILL.md
Normal file
210
.opencode/skills/bat-cat/SKILL.md
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
---
|
||||||
|
name: bat-cat
|
||||||
|
description: A cat clone with syntax highlighting, line numbers, and Git integration - a modern replacement for cat.
|
||||||
|
homepage: https://github.com/sharkdp/bat
|
||||||
|
metadata: {"clawdbot":{"emoji":"🦇","requires":{"bins":["bat"]},"install":[{"id":"brew","kind":"brew","formula":"bat","bins":["bat"],"label":"Install bat (brew)"},{"id":"apt","kind":"apt","package":"bat","bins":["bat"],"label":"Install bat (apt)"}]}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# bat - Better cat
|
||||||
|
|
||||||
|
`cat` with syntax highlighting, line numbers, and Git integration.
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### Basic usage
|
||||||
|
```bash
|
||||||
|
# View file with syntax highlighting
|
||||||
|
bat README.md
|
||||||
|
|
||||||
|
# Multiple files
|
||||||
|
bat file1.js file2.py
|
||||||
|
|
||||||
|
# With line numbers (default)
|
||||||
|
bat script.sh
|
||||||
|
|
||||||
|
# Without line numbers
|
||||||
|
bat -p script.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Viewing modes
|
||||||
|
```bash
|
||||||
|
# Plain mode (like cat)
|
||||||
|
bat -p file.txt
|
||||||
|
|
||||||
|
# Show non-printable characters
|
||||||
|
bat -A file.txt
|
||||||
|
|
||||||
|
# Squeeze blank lines
|
||||||
|
bat -s file.txt
|
||||||
|
|
||||||
|
# Paging (auto for large files)
|
||||||
|
bat --paging=always file.txt
|
||||||
|
bat --paging=never file.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Syntax Highlighting
|
||||||
|
|
||||||
|
### Language detection
|
||||||
|
```bash
|
||||||
|
# Auto-detect from extension
|
||||||
|
bat script.py
|
||||||
|
|
||||||
|
# Force specific language
|
||||||
|
bat -l javascript config.txt
|
||||||
|
|
||||||
|
# Show all languages
|
||||||
|
bat --list-languages
|
||||||
|
```
|
||||||
|
|
||||||
|
### Themes
|
||||||
|
```bash
|
||||||
|
# List available themes
|
||||||
|
bat --list-themes
|
||||||
|
|
||||||
|
# Use specific theme
|
||||||
|
bat --theme="Monokai Extended" file.py
|
||||||
|
|
||||||
|
# Set default theme in config
|
||||||
|
# ~/.config/bat/config: --theme="Dracula"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Line Ranges
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Show specific lines
|
||||||
|
bat -r 10:20 file.txt
|
||||||
|
|
||||||
|
# From line to end
|
||||||
|
bat -r 100: file.txt
|
||||||
|
|
||||||
|
# Start to specific line
|
||||||
|
bat -r :50 file.txt
|
||||||
|
|
||||||
|
# Multiple ranges
|
||||||
|
bat -r 1:10 -r 50:60 file.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Git Integration
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Show Git modifications (added/removed/modified lines)
|
||||||
|
bat --diff file.txt
|
||||||
|
|
||||||
|
# Show decorations (Git + file header)
|
||||||
|
bat --decorations=always file.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Output Control
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Output raw (no styling)
|
||||||
|
bat --style=plain file.txt
|
||||||
|
|
||||||
|
# Customize style
|
||||||
|
bat --style=numbers,changes file.txt
|
||||||
|
|
||||||
|
# Available styles: auto, full, plain, changes, header, grid, numbers, snip
|
||||||
|
bat --style=header,grid,numbers file.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Use Cases
|
||||||
|
|
||||||
|
**Quick file preview:**
|
||||||
|
```bash
|
||||||
|
bat file.json
|
||||||
|
```
|
||||||
|
|
||||||
|
**View logs with syntax highlighting:**
|
||||||
|
```bash
|
||||||
|
bat error.log
|
||||||
|
```
|
||||||
|
|
||||||
|
**Compare files visually:**
|
||||||
|
```bash
|
||||||
|
bat --diff file1.txt
|
||||||
|
bat file2.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
**Preview before editing:**
|
||||||
|
```bash
|
||||||
|
bat config.yaml && vim config.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
**Cat replacement in pipes:**
|
||||||
|
```bash
|
||||||
|
bat -p file.txt | grep "pattern"
|
||||||
|
```
|
||||||
|
|
||||||
|
**View specific function:**
|
||||||
|
```bash
|
||||||
|
bat -r 45:67 script.py # If function is on lines 45-67
|
||||||
|
```
|
||||||
|
|
||||||
|
## Integration with other tools
|
||||||
|
|
||||||
|
**As pager for man pages:**
|
||||||
|
```bash
|
||||||
|
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
|
||||||
|
man grep
|
||||||
|
```
|
||||||
|
|
||||||
|
**With ripgrep:**
|
||||||
|
```bash
|
||||||
|
rg "pattern" -l | xargs bat
|
||||||
|
```
|
||||||
|
|
||||||
|
**With fzf:**
|
||||||
|
```bash
|
||||||
|
fzf --preview 'bat --color=always --style=numbers {}'
|
||||||
|
```
|
||||||
|
|
||||||
|
**With diff:**
|
||||||
|
```bash
|
||||||
|
diff -u file1 file2 | bat -l diff
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Create `~/.config/bat/config` for defaults:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Set theme
|
||||||
|
--theme="Dracula"
|
||||||
|
|
||||||
|
# Show line numbers, Git modifications and file header, but no grid
|
||||||
|
--style="numbers,changes,header"
|
||||||
|
|
||||||
|
# Use italic text on terminal
|
||||||
|
--italic-text=always
|
||||||
|
|
||||||
|
# Add custom mapping
|
||||||
|
--map-syntax "*.conf:INI"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Performance Tips
|
||||||
|
|
||||||
|
- Use `-p` for plain mode when piping
|
||||||
|
- Use `--paging=never` when output is used programmatically
|
||||||
|
- `bat` caches parsed files for faster subsequent access
|
||||||
|
|
||||||
|
## Tips
|
||||||
|
|
||||||
|
- **Alias:** `alias cat='bat -p'` for drop-in cat replacement
|
||||||
|
- **Pager:** Use as pager with `export PAGER="bat"`
|
||||||
|
- **On Debian/Ubuntu:** Command may be `batcat` instead of `bat`
|
||||||
|
- **Custom syntaxes:** Add to `~/.config/bat/syntaxes/`
|
||||||
|
- **Performance:** For huge files, use `bat --paging=never` or plain `cat`
|
||||||
|
|
||||||
|
## Common flags
|
||||||
|
|
||||||
|
- `-p` / `--plain`: Plain mode (no line numbers/decorations)
|
||||||
|
- `-n` / `--number`: Only show line numbers
|
||||||
|
- `-A` / `--show-all`: Show non-printable characters
|
||||||
|
- `-l` / `--language`: Set language for syntax highlighting
|
||||||
|
- `-r` / `--line-range`: Only show specific line range(s)
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
GitHub: https://github.com/sharkdp/bat
|
||||||
|
Man page: `man bat`
|
||||||
|
Customization: https://github.com/sharkdp/bat#customization
|
||||||
194
.opencode/skills/fd-find/SKILL.md
Normal file
194
.opencode/skills/fd-find/SKILL.md
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
---
|
||||||
|
name: fd-find
|
||||||
|
description: A fast and user-friendly alternative to 'find' - simple syntax, smart defaults, respects gitignore.
|
||||||
|
homepage: https://github.com/sharkdp/fd
|
||||||
|
metadata: {"clawdbot":{"emoji":"📂","requires":{"bins":["fd"]},"install":[{"id":"brew","kind":"brew","formula":"fd","bins":["fd"],"label":"Install fd (brew)"},{"id":"apt","kind":"apt","package":"fd-find","bins":["fd"],"label":"Install fd (apt)"}]}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# fd - Fast File Finder
|
||||||
|
|
||||||
|
User-friendly alternative to `find` with smart defaults.
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### Basic search
|
||||||
|
```bash
|
||||||
|
# Find files by name
|
||||||
|
fd pattern
|
||||||
|
|
||||||
|
# Find in specific directory
|
||||||
|
fd pattern /path/to/dir
|
||||||
|
|
||||||
|
# Case-insensitive
|
||||||
|
fd -i pattern
|
||||||
|
```
|
||||||
|
|
||||||
|
### Common patterns
|
||||||
|
```bash
|
||||||
|
# Find all Python files
|
||||||
|
fd -e py
|
||||||
|
|
||||||
|
# Find multiple extensions
|
||||||
|
fd -e py -e js -e ts
|
||||||
|
|
||||||
|
# Find directories only
|
||||||
|
fd -t d pattern
|
||||||
|
|
||||||
|
# Find files only
|
||||||
|
fd -t f pattern
|
||||||
|
|
||||||
|
# Find symlinks
|
||||||
|
fd -t l
|
||||||
|
```
|
||||||
|
|
||||||
|
## Advanced Usage
|
||||||
|
|
||||||
|
### Filtering
|
||||||
|
```bash
|
||||||
|
# Exclude patterns
|
||||||
|
fd pattern -E "node_modules" -E "*.min.js"
|
||||||
|
|
||||||
|
# Include hidden files
|
||||||
|
fd -H pattern
|
||||||
|
|
||||||
|
# Include ignored files (.gitignore)
|
||||||
|
fd -I pattern
|
||||||
|
|
||||||
|
# Search all (hidden + ignored)
|
||||||
|
fd -H -I pattern
|
||||||
|
|
||||||
|
# Maximum depth
|
||||||
|
fd pattern -d 3
|
||||||
|
```
|
||||||
|
|
||||||
|
### Execution
|
||||||
|
```bash
|
||||||
|
# Execute command on results
|
||||||
|
fd -e jpg -x convert {} {.}.png
|
||||||
|
|
||||||
|
# Parallel execution
|
||||||
|
fd -e md -x wc -l
|
||||||
|
|
||||||
|
# Use with xargs
|
||||||
|
fd -e log -0 | xargs -0 rm
|
||||||
|
```
|
||||||
|
|
||||||
|
### Regex patterns
|
||||||
|
```bash
|
||||||
|
# Full regex search
|
||||||
|
fd '^test.*\.js$'
|
||||||
|
|
||||||
|
# Match full path
|
||||||
|
fd --full-path 'src/.*/test'
|
||||||
|
|
||||||
|
# Glob pattern
|
||||||
|
fd -g "*.{js,ts}"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Time-based filtering
|
||||||
|
```bash
|
||||||
|
# Modified within last day
|
||||||
|
fd --changed-within 1d
|
||||||
|
|
||||||
|
# Modified before specific date
|
||||||
|
fd --changed-before 2024-01-01
|
||||||
|
|
||||||
|
# Created recently
|
||||||
|
fd --changed-within 1h
|
||||||
|
```
|
||||||
|
|
||||||
|
## Size filtering
|
||||||
|
```bash
|
||||||
|
# Files larger than 10MB
|
||||||
|
fd --size +10m
|
||||||
|
|
||||||
|
# Files smaller than 1KB
|
||||||
|
fd --size -1k
|
||||||
|
|
||||||
|
# Specific size range
|
||||||
|
fd --size +100k --size -10m
|
||||||
|
```
|
||||||
|
|
||||||
|
## Output formatting
|
||||||
|
```bash
|
||||||
|
# Absolute paths
|
||||||
|
fd --absolute-path
|
||||||
|
|
||||||
|
# List format (like ls -l)
|
||||||
|
fd --list-details
|
||||||
|
|
||||||
|
# Null separator (for xargs)
|
||||||
|
fd -0 pattern
|
||||||
|
|
||||||
|
# Color always/never/auto
|
||||||
|
fd --color always pattern
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Use Cases
|
||||||
|
|
||||||
|
**Find and delete old files:**
|
||||||
|
```bash
|
||||||
|
fd --changed-before 30d -t f -x rm {}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Find large files:**
|
||||||
|
```bash
|
||||||
|
fd --size +100m --list-details
|
||||||
|
```
|
||||||
|
|
||||||
|
**Copy all PDFs to directory:**
|
||||||
|
```bash
|
||||||
|
fd -e pdf -x cp {} /target/dir/
|
||||||
|
```
|
||||||
|
|
||||||
|
**Count lines in all Python files:**
|
||||||
|
```bash
|
||||||
|
fd -e py -x wc -l | awk '{sum+=$1} END {print sum}'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Find broken symlinks:**
|
||||||
|
```bash
|
||||||
|
fd -t l -x test -e {} \; -print
|
||||||
|
```
|
||||||
|
|
||||||
|
**Search in specific time window:**
|
||||||
|
```bash
|
||||||
|
fd --changed-within 2d --changed-before 1d
|
||||||
|
```
|
||||||
|
|
||||||
|
## Integration with other tools
|
||||||
|
|
||||||
|
**With ripgrep:**
|
||||||
|
```bash
|
||||||
|
fd -e js | xargs rg "pattern"
|
||||||
|
```
|
||||||
|
|
||||||
|
**With fzf (fuzzy finder):**
|
||||||
|
```bash
|
||||||
|
vim $(fd -t f | fzf)
|
||||||
|
```
|
||||||
|
|
||||||
|
**With bat (cat alternative):**
|
||||||
|
```bash
|
||||||
|
fd -e md | xargs bat
|
||||||
|
```
|
||||||
|
|
||||||
|
## Performance Tips
|
||||||
|
|
||||||
|
- `fd` is typically much faster than `find`
|
||||||
|
- Respects `.gitignore` by default (disable with `-I`)
|
||||||
|
- Uses parallel traversal automatically
|
||||||
|
- Smart case: lowercase = case-insensitive, any uppercase = case-sensitive
|
||||||
|
|
||||||
|
## Tips
|
||||||
|
|
||||||
|
- Use `-t` for type filtering (f=file, d=directory, l=symlink, x=executable)
|
||||||
|
- `-e` for extension is simpler than `-g "*.ext"`
|
||||||
|
- `{}` in `-x` commands represents the found path
|
||||||
|
- `{.}` strips the extension
|
||||||
|
- `{/}` gets basename, `{//}` gets directory
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
GitHub: https://github.com/sharkdp/fd
|
||||||
|
Man page: `man fd`
|
||||||
112
.opencode/skills/jq-json-processor/SKILL.md
Normal file
112
.opencode/skills/jq-json-processor/SKILL.md
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
---
|
||||||
|
name: jq-json-processor
|
||||||
|
description: Process, filter, and transform JSON data using jq - the lightweight and flexible command-line JSON processor.
|
||||||
|
homepage: https://jqlang.github.io/jq/
|
||||||
|
metadata: {"clawdbot":{"emoji":"🔍","requires":{"bins":["jq"]},"install":[{"id":"brew","kind":"brew","formula":"jq","bins":["jq"],"label":"Install jq (brew)"},{"id":"apt","kind":"apt","package":"jq","bins":["jq"],"label":"Install jq (apt)"}]}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# jq JSON Processor
|
||||||
|
|
||||||
|
Process, filter, and transform JSON data with jq.
|
||||||
|
|
||||||
|
## Quick Examples
|
||||||
|
|
||||||
|
### Basic filtering
|
||||||
|
```bash
|
||||||
|
# Extract a field
|
||||||
|
echo '{"name":"Alice","age":30}' | jq '.name'
|
||||||
|
# Output: "Alice"
|
||||||
|
|
||||||
|
# Multiple fields
|
||||||
|
echo '{"name":"Alice","age":30}' | jq '{name: .name, age: .age}'
|
||||||
|
|
||||||
|
# Array indexing
|
||||||
|
echo '[1,2,3,4,5]' | jq '.[2]'
|
||||||
|
# Output: 3
|
||||||
|
```
|
||||||
|
|
||||||
|
### Working with arrays
|
||||||
|
```bash
|
||||||
|
# Map over array
|
||||||
|
echo '[{"name":"Alice"},{"name":"Bob"}]' | jq '.[].name'
|
||||||
|
# Output: "Alice" "Bob"
|
||||||
|
|
||||||
|
# Filter array
|
||||||
|
echo '[1,2,3,4,5]' | jq 'map(select(. > 2))'
|
||||||
|
# Output: [3,4,5]
|
||||||
|
|
||||||
|
# Length
|
||||||
|
echo '[1,2,3]' | jq 'length'
|
||||||
|
# Output: 3
|
||||||
|
```
|
||||||
|
|
||||||
|
### Common operations
|
||||||
|
```bash
|
||||||
|
# Pretty print JSON
|
||||||
|
cat file.json | jq '.'
|
||||||
|
|
||||||
|
# Compact output
|
||||||
|
cat file.json | jq -c '.'
|
||||||
|
|
||||||
|
# Raw output (no quotes)
|
||||||
|
echo '{"name":"Alice"}' | jq -r '.name'
|
||||||
|
# Output: Alice
|
||||||
|
|
||||||
|
# Sort keys
|
||||||
|
echo '{"z":1,"a":2}' | jq -S '.'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced filtering
|
||||||
|
```bash
|
||||||
|
# Select with conditions
|
||||||
|
jq '[.[] | select(.age > 25)]' people.json
|
||||||
|
|
||||||
|
# Group by
|
||||||
|
jq 'group_by(.category)' items.json
|
||||||
|
|
||||||
|
# Reduce
|
||||||
|
echo '[1,2,3,4,5]' | jq 'reduce .[] as $item (0; . + $item)'
|
||||||
|
# Output: 15
|
||||||
|
```
|
||||||
|
|
||||||
|
### Working with files
|
||||||
|
```bash
|
||||||
|
# Read from file
|
||||||
|
jq '.users[0].name' users.json
|
||||||
|
|
||||||
|
# Multiple files
|
||||||
|
jq -s '.[0] * .[1]' file1.json file2.json
|
||||||
|
|
||||||
|
# Modify and save
|
||||||
|
jq '.version = "2.0"' package.json > package.json.tmp && mv package.json.tmp package.json
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Use Cases
|
||||||
|
|
||||||
|
**Extract specific fields from API response:**
|
||||||
|
```bash
|
||||||
|
curl -s https://api.github.com/users/octocat | jq '{name: .name, repos: .public_repos, followers: .followers}'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Convert CSV-like data:**
|
||||||
|
```bash
|
||||||
|
jq -r '.[] | [.name, .email, .age] | @csv' users.json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Debug API responses:**
|
||||||
|
```bash
|
||||||
|
curl -s https://api.example.com/data | jq '.'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tips
|
||||||
|
|
||||||
|
- Use `-r` for raw string output (removes quotes)
|
||||||
|
- Use `-c` for compact output (single line)
|
||||||
|
- Use `-S` to sort object keys
|
||||||
|
- Use `--arg name value` to pass variables
|
||||||
|
- Pipe multiple jq operations: `jq '.a' | jq '.b'`
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
Full manual: https://jqlang.github.io/jq/manual/
|
||||||
|
Interactive tutorial: https://jqplay.org/
|
||||||
120
.opencode/skills/nrepl-eval/SKILL.md
Normal file
120
.opencode/skills/nrepl-eval/SKILL.md
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
---
|
||||||
|
name: nrepl-eval
|
||||||
|
description: Evaluate Clojure code via nREPL using the standalone tools/nrepl-eval.mjs CLI tool.
|
||||||
|
---
|
||||||
|
|
||||||
|
# nREPL Eval
|
||||||
|
|
||||||
|
Evaluate Clojure (or ClojureScript) code via a running nREPL server using
|
||||||
|
`tools/nrepl-eval.mjs` — a standalone CLI application.
|
||||||
|
|
||||||
|
Session state (defs, in-ns, etc.) persists across invocations via a stored
|
||||||
|
session ID, so you can build up state incrementally.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node tools/nrepl-eval.mjs [options] [<code>]
|
||||||
|
```
|
||||||
|
|
||||||
|
The tool is also executable directly:
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs [options] [<code>]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
| Flag | Description | Default |
|
||||||
|
|------|-------------|---------|
|
||||||
|
| `-p, --port PORT` | nREPL server port | `6064` |
|
||||||
|
| `-H, --host HOST` | nREPL server host | `127.0.0.1` |
|
||||||
|
| `-t, --timeout MS` | Timeout in milliseconds | `120000` |
|
||||||
|
| `--reset-session` | Discard stored session and start fresh | — |
|
||||||
|
| `-e, --last-error` | Evaluate `*e` to retrieve the last exception | — |
|
||||||
|
| `-h, --help` | Show help message | — |
|
||||||
|
|
||||||
|
## When to Use
|
||||||
|
|
||||||
|
Use this tool when you need to:
|
||||||
|
|
||||||
|
1. **Evaluate Clojure code** during development — test functions, inspect
|
||||||
|
state, or run experiments against a running Clojure process.
|
||||||
|
2. **Verify that edited files compile** — require namespaces with `:reload`
|
||||||
|
to pick up changes.
|
||||||
|
3. **Inspect the last exception** after a failed evaluation — use `-e` to
|
||||||
|
print the error stored in `*e`.
|
||||||
|
|
||||||
|
## Workflow
|
||||||
|
|
||||||
|
### 1. Session management
|
||||||
|
|
||||||
|
Sessions are persisted to `/tmp/penpot-nrepl-session-<host>-<port>`. State
|
||||||
|
carries across calls automatically:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs '(def x 42)'
|
||||||
|
./tools/nrepl-eval.mjs 'x'
|
||||||
|
# => 42
|
||||||
|
```
|
||||||
|
|
||||||
|
Reset the session to start fresh:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs --reset-session '(def x 0)'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Evaluate code
|
||||||
|
|
||||||
|
**Single expression (inline) — uses default port 6064:**
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs '(+ 1 2 3)'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Multiple expressions via heredoc (recommended — avoids escaping issues):**
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs <<'EOF'
|
||||||
|
(def x 10)
|
||||||
|
(+ x 20)
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
**Override with a different port:**
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs -p 7888 '(+ 1 2 3)'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Inspect last exception
|
||||||
|
|
||||||
|
After code throws an error, retrieve the full exception details:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs -e
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Patterns
|
||||||
|
|
||||||
|
**Require a namespace with reload:**
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs "(require '[my.namespace :as ns] :reload)"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Test a function:**
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs "(ns/my-function arg1 arg2)"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Long-running operation with custom timeout:**
|
||||||
|
```bash
|
||||||
|
./tools/nrepl-eval.mjs -t 300000 "(long-running-fn)"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Key Principles
|
||||||
|
|
||||||
|
- **Default port is 6064** — just pass code directly, no `-p` needed when
|
||||||
|
your nREPL server is on 6064. Use `-p <PORT>` for a different port.
|
||||||
|
- **Always use `:reload`** when requiring namespaces to pick up file changes.
|
||||||
|
- **Session is reused** across invocations — defs, in-ns, and var bindings
|
||||||
|
persist. Use `--reset-session` to clear.
|
||||||
|
- **Do not start any server** — the tool connects to an existing nREPL
|
||||||
|
server, it is not the agent's responsibility to start the nREPL server
|
||||||
|
(assume the server is already running on the specified port).
|
||||||
150
.opencode/skills/ripgrep/SKILL.md
Normal file
150
.opencode/skills/ripgrep/SKILL.md
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
---
|
||||||
|
name: ripgrep
|
||||||
|
description: Blazingly fast text search tool - recursively searches directories for regex patterns with respect to gitignore rules.
|
||||||
|
homepage: https://github.com/BurntSushi/ripgrep
|
||||||
|
metadata: {"clawdbot":{"emoji":"🔎","requires":{"bins":["rg"]},"install":[{"id":"brew","kind":"brew","formula":"ripgrep","bins":["rg"],"label":"Install ripgrep (brew)"},{"id":"apt","kind":"apt","package":"ripgrep","bins":["rg"],"label":"Install ripgrep (apt)"}]}}
|
||||||
|
---
|
||||||
|
|
||||||
|
# ripgrep (rg)
|
||||||
|
|
||||||
|
Fast, smart recursive search. Respects `.gitignore` by default.
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### Basic search
|
||||||
|
```bash
|
||||||
|
# Search for "TODO" in current directory
|
||||||
|
rg "TODO"
|
||||||
|
|
||||||
|
# Case-insensitive search
|
||||||
|
rg -i "fixme"
|
||||||
|
|
||||||
|
# Search specific file types
|
||||||
|
rg "error" -t py # Python files only
|
||||||
|
rg "function" -t js # JavaScript files
|
||||||
|
```
|
||||||
|
|
||||||
|
### Common patterns
|
||||||
|
```bash
|
||||||
|
# Whole word match
|
||||||
|
rg -w "test"
|
||||||
|
|
||||||
|
# Show only filenames
|
||||||
|
rg -l "pattern"
|
||||||
|
|
||||||
|
# Show with context (3 lines before/after)
|
||||||
|
rg -C 3 "function"
|
||||||
|
|
||||||
|
# Count matches
|
||||||
|
rg -c "import"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Advanced Usage
|
||||||
|
|
||||||
|
### File type filtering
|
||||||
|
```bash
|
||||||
|
# Multiple file types
|
||||||
|
rg "error" -t py -t js
|
||||||
|
|
||||||
|
# Exclude file types
|
||||||
|
rg "TODO" -T md -T txt
|
||||||
|
|
||||||
|
# List available types
|
||||||
|
rg --type-list
|
||||||
|
```
|
||||||
|
|
||||||
|
### Search modifiers
|
||||||
|
```bash
|
||||||
|
# Regex search
|
||||||
|
rg "user_\d+"
|
||||||
|
|
||||||
|
# Fixed string (no regex)
|
||||||
|
rg -F "function()"
|
||||||
|
|
||||||
|
# Multiline search
|
||||||
|
rg -U "start.*end"
|
||||||
|
|
||||||
|
# Only show matches, not lines
|
||||||
|
rg -o "https?://[^\s]+"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Path filtering
|
||||||
|
```bash
|
||||||
|
# Search specific directory
|
||||||
|
rg "pattern" src/
|
||||||
|
|
||||||
|
# Glob patterns
|
||||||
|
rg "error" -g "*.log"
|
||||||
|
rg "test" -g "!*.min.js"
|
||||||
|
|
||||||
|
# Include hidden files
|
||||||
|
rg "secret" --hidden
|
||||||
|
|
||||||
|
# Search all files (ignore .gitignore)
|
||||||
|
rg "pattern" --no-ignore
|
||||||
|
```
|
||||||
|
|
||||||
|
## Replacement Operations
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Preview replacements
|
||||||
|
rg "old_name" --replace "new_name"
|
||||||
|
|
||||||
|
# Actually replace (requires extra tool like sd)
|
||||||
|
rg "old_name" -l | xargs sed -i 's/old_name/new_name/g'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Performance Tips
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Parallel search (auto by default)
|
||||||
|
rg "pattern" -j 8
|
||||||
|
|
||||||
|
# Skip large files
|
||||||
|
rg "pattern" --max-filesize 10M
|
||||||
|
|
||||||
|
# Memory map files
|
||||||
|
rg "pattern" --mmap
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Use Cases
|
||||||
|
|
||||||
|
**Find TODOs in code:**
|
||||||
|
```bash
|
||||||
|
rg "TODO|FIXME|HACK" --type-add 'code:*.{rs,go,py,js,ts}' -t code
|
||||||
|
```
|
||||||
|
|
||||||
|
**Search in specific branches:**
|
||||||
|
```bash
|
||||||
|
git show branch:file | rg "pattern"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Find files containing multiple patterns:**
|
||||||
|
```bash
|
||||||
|
rg "pattern1" | rg "pattern2"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Search with context and color:**
|
||||||
|
```bash
|
||||||
|
rg -C 2 --color always "error" | less -R
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comparison to grep
|
||||||
|
|
||||||
|
- **Faster:** Typically 5-10x faster than grep
|
||||||
|
- **Smarter:** Respects `.gitignore`, skips binary files
|
||||||
|
- **Better defaults:** Recursive, colored output, line numbers
|
||||||
|
- **Easier:** Simpler syntax for common tasks
|
||||||
|
|
||||||
|
## Tips
|
||||||
|
|
||||||
|
- `rg` is often faster than `grep -r`
|
||||||
|
- Use `-t` for file type filtering instead of `--include`
|
||||||
|
- Combine with other tools: `rg pattern -l | xargs tool`
|
||||||
|
- Add custom types in `~/.ripgreprc`
|
||||||
|
- Use `--stats` to see search performance
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
GitHub: https://github.com/BurntSushi/ripgrep
|
||||||
|
User Guide: https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md
|
||||||
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"files.exclude": {
|
|
||||||
"**/.clj-kondo": true,
|
|
||||||
"**/.cpcache": true,
|
|
||||||
"**/.lsp": true,
|
|
||||||
"**/.shadow-cljs": true,
|
|
||||||
"**/node_modules": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
11
AGENTS.md
11
AGENTS.md
@ -32,6 +32,17 @@ precision while maintaining a strong focus on maintainability and performance.
|
|||||||
5. When searching code, prefer `ripgrep` (`rg`) over `grep` — it respects
|
5. When searching code, prefer `ripgrep` (`rg`) over `grep` — it respects
|
||||||
`.gitignore` by default.
|
`.gitignore` by default.
|
||||||
|
|
||||||
|
## Changelogs
|
||||||
|
|
||||||
|
The project has two changelogs:
|
||||||
|
|
||||||
|
- **Main project changelog**: `CHANGES.md` (root of the repository). Tracks changes for the core Penpot application (backend, frontend, common, render-wasm, exporter, mcp).
|
||||||
|
- **Plugins changelog**: `plugins/CHANGELOG.md`. Tracks changes for the plugins subproject only.
|
||||||
|
|
||||||
|
When making changes, add a changelog entry to the appropriate file under the
|
||||||
|
`## <version> (Unreleased)` section in the correct category
|
||||||
|
(`:sparkles: New features & Enhancements` or `:bug: Bugs fixed`).
|
||||||
|
|
||||||
## GitHub Operations
|
## GitHub Operations
|
||||||
|
|
||||||
To obtain the list of repository members/collaborators:
|
To obtain the list of repository members/collaborators:
|
||||||
|
|||||||
196
CHANGES.md
196
CHANGES.md
@ -1,5 +1,190 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## 2.17.0 (Unreleased)
|
||||||
|
|
||||||
|
### :boom: Breaking changes & Deprecations
|
||||||
|
|
||||||
|
### :rocket: Epics and highlights
|
||||||
|
|
||||||
|
### :sparkles: New features & Enhancements
|
||||||
|
|
||||||
|
- Show a read-only W × H size badge below the bounding box of the current selection (by @bittoby) [Github #9205](https://github.com/penpot/penpot/issues/9205)
|
||||||
|
- Expose `variants` retrieval on `LibraryComponent` via `isVariant()` type guard in plugin API [Github #9185](https://github.com/penpot/penpot/issues/9185)
|
||||||
|
|
||||||
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
|
- Fix plugin API `LibraryTypography.remove()` failing with a UUID assertion error [Github #8223](https://github.com/penpot/penpot/issues/8223)
|
||||||
|
- Fix MCP SSE sessions leaking memory on zombie connections by adding inactivity timeout parity with Streamable HTTP sessions (by @bitloi) [Github #9432](https://github.com/penpot/penpot/issues/9432)
|
||||||
|
- Fix missing `labels.open` translation (by @MilosM348) [Github #9320](https://github.com/penpot/penpot/pull/9320)
|
||||||
|
- Harden Nginx responses with standard security headers and hide upstream `X-Powered-By` headers
|
||||||
|
- Expose Source Sans Pro semibold (weight 600) variants in the builtin fonts list, matching the bundled font assets and CSS @font-face declarations [Github #7378](https://github.com/penpot/penpot/issues/7378)
|
||||||
|
- Fix plugin API `shape.fills` and `shape.strokes` arrays being read-only [Github #8357](https://github.com/penpot/penpot/issues/8357)
|
||||||
|
- Fix `get-profile` masking transient DB errors as anonymous user (by @jack-stormentswe) [Github #9253](https://github.com/penpot/penpot/issues/9253)
|
||||||
|
- Fix `Ctrl+'` "Show guides" shortcut on non-US keyboard layouts by matching the physical key location (by @RenzoMXD) [Github #8423](https://github.com/penpot/penpot/issues/8423)
|
||||||
|
- Fix lost-update race on `team.features` during concurrent file creation (by @web-dev0521) [Github #9197](https://github.com/penpot/penpot/issues/9197)
|
||||||
|
- Fix copy and paste actions crashing the workspace on insecure origins (plain HTTP / non-`localhost`) where the Clipboard API is unavailable (by @MilosM348) [Github #6514](https://github.com/penpot/penpot/issues/6514)
|
||||||
|
|
||||||
|
|
||||||
|
## 2.16.0 (Unreleased)
|
||||||
|
|
||||||
|
### :boom: Breaking changes & Deprecations
|
||||||
|
|
||||||
|
### :rocket: Epics and highlights
|
||||||
|
|
||||||
|
### :sparkles: New features & Enhancements
|
||||||
|
|
||||||
|
- Enhance readability of applied tokens in plugins API [Taiga #13714](https://tree.taiga.io/project/penpot/issue/13714)
|
||||||
|
- Add "Delete group" option to the assets panel context menu for components, colors and typographies (by @FairyPigDev) [Github #9141](https://github.com/penpot/penpot/issues/9141)
|
||||||
|
- Add `Alt+click` on a layer's disclosure arrow to recursively expand the entire subtree rooted at that layer in the Layers sidebar; symmetric with the existing `Shift+click` collapse-all gesture, and removes the O(siblings × depth) click cost of unfolding a deep subtree one level at a time [Github #7736](https://github.com/penpot/penpot/issues/7736)
|
||||||
|
- Show relative timestamp and short identifier for each entry in the workspace Actions history sidebar (by @FairyPigDev) [Github #7660](https://github.com/penpot/penpot/issues/7660)
|
||||||
|
- Add `Alt+click` on a layer's disclosure arrow to recursively expand the entire subtree in the Layers sidebar (by @MilosM348) [Github #9179](https://github.com/penpot/penpot/pull/9179)
|
||||||
|
- Show alpha percentage next to library color values to distinguish colors that differ only in opacity (by @rockchris099) [Github #6328](https://github.com/penpot/penpot/issues/6328)
|
||||||
|
- Add "Clear artboard guides" option to right-click context menu for frames (by @eureka0928) [Github #6987](https://github.com/penpot/penpot/issues/6987)
|
||||||
|
- Add loader feedback while importing and exporting files (by @moorsecopers99) [Github #9024](https://github.com/penpot/penpot/pull/9024)
|
||||||
|
- Allow duplicating color and typography styles (by @MkDev11) [Github #2912](https://github.com/penpot/penpot/issues/2912)
|
||||||
|
- Add woff2 support on user uploaded fonts (by @Nivl) [Github #8248](https://github.com/penpot/penpot/pull/8248)
|
||||||
|
- Import Tokens from linked library (by @dfelinto) [Github #8391](https://github.com/penpot/penpot/pull/8391)
|
||||||
|
- Option to download custom fonts (by @dfelinto) [Github #8320](https://github.com/penpot/penpot/issues/8320)
|
||||||
|
- Add copy as image to clipboard option to workspace context menu (by @dfelinto) [Github #8313](https://github.com/penpot/penpot/pull/8313)
|
||||||
|
- Add Tab/Shift+Tab navigation to rename layers sequentially (by @bittoby) [Github #8474](https://github.com/penpot/penpot/pull/8474)
|
||||||
|
- Copy and paste entire rows in existing table (by @bittoby) [Github #8498](https://github.com/penpot/penpot/pull/8498)
|
||||||
|
- Rename token group [Taiga #13137](https://tree.taiga.io/project/penpot/us/13137)
|
||||||
|
- Duplicate token group [Taiga #10653](https://tree.taiga.io/project/penpot/us/10653)
|
||||||
|
- Copy token name from contextual menu [Taiga #13568](https://tree.taiga.io/project/penpot/issue/13568)
|
||||||
|
- Add natural sorting on token names [Taiga #13713](https://tree.taiga.io/project/penpot/issue/13713)
|
||||||
|
- Add drag-to-change for numeric inputs in workspace sidebar (by @RenzoMXD) [Github #8536](https://github.com/penpot/penpot/pull/8536)
|
||||||
|
- Add CSS linter [Taiga #13790](https://tree.taiga.io/project/penpot/us/13790)
|
||||||
|
- Save and restore selection state in undo/redo (by @eureka0928) [Github #6007](https://github.com/penpot/penpot/issues/6007)
|
||||||
|
- Fix warnings for unsupported token $type (by @Dexterity104) [Github #8790](https://github.com/penpot/penpot/issues/8790)
|
||||||
|
- Add per-group add button for typographies (by @eureka0928) [Github #5275](https://github.com/penpot/penpot/issues/5275)
|
||||||
|
- Add Find & Replace for text content and layer names (by @statxc) [Github #7108](https://github.com/penpot/penpot/issues/7108)
|
||||||
|
- Use page name for multi-export ZIP/PDF downloads (by @Dexterity104) [Github #8773](https://github.com/penpot/penpot/issues/8773)
|
||||||
|
- Make links in comments clickable (by @eureka0928) [Github #1602](https://github.com/penpot/penpot/issues/1602)
|
||||||
|
- Add visibility toggle for strokes (by @eureka0928) [Github #7438](https://github.com/penpot/penpot/issues/7438)
|
||||||
|
- Sort asset library subfolders alphabetically at every nesting level (by @eureka0928) [Github #2572](https://github.com/penpot/penpot/issues/2572)
|
||||||
|
- Add Paste to replace (Cmd+Shift+V) to replace the selected shape with clipboard contents (by @eureka0928) [Github #4240](https://github.com/penpot/penpot/issues/4240)
|
||||||
|
- Differentiate incoming and outgoing interaction link colors (by @claytonlin1110) [Github #7794](https://github.com/penpot/penpot/issues/7794)
|
||||||
|
- Add guide locking and fix locked elements not selectable in viewer (by @Dexterity104) [Github #8358](https://github.com/penpot/penpot/issues/8358)
|
||||||
|
- Apply styles to selection (by @AzazelN28) [Taiga #13647](https://tree.taiga.io/project/penpot/task/13647)
|
||||||
|
- Reorder prototyping overlay options to show Position before Relative to (by @rockchris099) [Github #2910](https://github.com/penpot/penpot/issues/2910)
|
||||||
|
- Add customizable colors for ruler guides (by @Dexterity104) [Github #5199](https://github.com/penpot/penpot/issues/5199)
|
||||||
|
- Persist asset search query and section filter when switching sidebar tabs (by @eureka0928) [Github #2913](https://github.com/penpot/penpot/issues/2913)
|
||||||
|
- Add delete and duplicate buttons to typography dialog (by @eureka0928) [Github #5270](https://github.com/penpot/penpot/issues/5270)
|
||||||
|
- Edit ruler guide position by double-clicking the guide pill (by @eureka0928) [Github #2311](https://github.com/penpot/penpot/issues/2311)
|
||||||
|
- Add a search bar to filter colors in the color palette toolbar (by @eureka0928) [Github #7653](https://github.com/penpot/penpot/issues/7653)
|
||||||
|
- Add a search bar to filter board size presets (by @eureka0928) [Github #4658](https://github.com/penpot/penpot/issues/4658)
|
||||||
|
- Allow customising the OIDC login button label (by @wdeveloper16) [Github #7027](https://github.com/penpot/penpot/issues/7027)
|
||||||
|
- Add page separators in Workspace [Taiga #13611](https://tree.taiga.io/project/penpot/us/13611?milestone=262806)
|
||||||
|
- Preserve vector content when pasting SVG from external tools such as Inkscape (by @RenzoMXD) [Github #9182](https://github.com/penpot/penpot/pull/9182)
|
||||||
|
- Add Shift+Numpad0/1/2 as aliases to Shift+0/1/2 for zoom shortcuts (by @RenzoMXD) [Github #9063](https://github.com/penpot/penpot/pull/9063)
|
||||||
|
- Add pixel grid color picker in viewport settings (by @Yakehira) [Github #7750](https://github.com/penpot/penpot/issues/7750)
|
||||||
|
- Add HEX, HSB and HSL support to the color picker with a model switcher that persists across sessions (by @edwin-rivera-dev) [Github #9133](https://github.com/penpot/penpot/issues/9133)
|
||||||
|
- Show specific invitation-link error messages for expired, email-mismatch and invalid token cases [Github #9220](https://github.com/penpot/penpot/issues/9220)
|
||||||
|
- Show detailed messages on file import errors to help diagnose why a file could not be imported (by @jsdevninja) [Github #9004](https://github.com/penpot/penpot/issues/9004)
|
||||||
|
- Add read-only preview mode for saved versions — click a version name to open a dedicated preview view (by @wdeveloper16) [Github #8976](https://github.com/penpot/penpot/issues/8976)
|
||||||
|
- Add clipboard read/write permissions to the plugin system (by @wdeveloper16) [Github #9053](https://github.com/penpot/penpot/issues/9053)
|
||||||
|
- Add new numeric inputs for token management on the right sidebar [Taiga #12109](https://tree.taiga.io/project/penpot/us/12109?milestone=513226)
|
||||||
|
- Restore deleted team files in bulk instead of per file (by @Dexterity104) [Github #9248](https://github.com/penpot/penpot/pull/9248)
|
||||||
|
- Preserve Inkscape labels when pasting SVGs (by @jeffrey701) [Github #9252](https://github.com/penpot/penpot/pull/9252)
|
||||||
|
|
||||||
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
|
- Fix Alt/Option to draw shapes from center point (by @offreal) [Github #8361](https://github.com/penpot/penpot/pull/8361)
|
||||||
|
- Add token name on broken token pill on sidebar [Taiga #13527](https://tree.taiga.io/project/penpot/issue/13527)
|
||||||
|
- Fix tooltip activated when tab change [Taiga #13627](https://tree.taiga.io/project/penpot/issue/13627)
|
||||||
|
- Fix title on shared button [Taiga #13730](https://tree.taiga.io/project/penpot/issue/13730)
|
||||||
|
- Fix hover on layers [Taiga #13799](https://tree.taiga.io/project/penpot/issue/13799)
|
||||||
|
- Fix highlight after name edition [Taiga #13783](https://tree.taiga.io/project/penpot/issue/13783)
|
||||||
|
- Fix id prop on switch component [Taiga #13534](https://tree.taiga.io/project/penpot/issue/13534)
|
||||||
|
- Fix dashboard navigation tabs overlap with projects content when scrolling [Taiga #13962](https://tree.taiga.io/project/penpot/issue/13962)
|
||||||
|
- Fix text editor v1 focus [Taiga #13961](https://tree.taiga.io/project/penpot/issue/13961)
|
||||||
|
- Fix color dropdown option update [Taiga #14035](https://tree.taiga.io/project/penpot/issue/14035)
|
||||||
|
- Fix themes modal height [Taiga #14046](https://tree.taiga.io/project/penpot/issue/14046)
|
||||||
|
- Fix layers panel rename input showing the default type name instead of the saved layer name (by @jack-stormentswe) [Github #9231](https://github.com/penpot/penpot/pull/9231)
|
||||||
|
- Suppress browser context menu on right-click in workspace sidebars while preserving it on text inputs (by @sujyotraut) [Github #5127](https://github.com/penpot/penpot/issues/5127)
|
||||||
|
- Fix release notes modal appearing behind the dashboard sidebar (by @ciaokitty) [Github #8296](https://github.com/penpot/penpot/issues/8296)
|
||||||
|
- Fix plugin API `fileVersion.restore()` promise hanging indefinitely on restore failure (by @thomascolden585-svg) [Github #9092](https://github.com/penpot/penpot/issues/9092)
|
||||||
|
- Fix imported stroke-only SVG paths losing their rounded join when split into adjacent subpaths (by @Chrissi2812) [Github #5283](https://github.com/penpot/penpot/issues/5283)
|
||||||
|
- Fix plugin API `library.connectLibrary()` not returning a Promise when the plugin lacks `library:write` permission (by @boskodev790) [Github #9158](https://github.com/penpot/penpot/pull/9158)
|
||||||
|
- Fix LDAP provider schema typo (`bind-passwor` → `bind-password`) introduced during the `clojure.spec` → `malli` migration (by @boskodev790) [Github #9165](https://github.com/penpot/penpot/pull/9165)
|
||||||
|
- Fix `login-with-ldap` silently dropping the error message when LDAP is not initialized (typo `:hide` → `:hint`) (by @boskodev790) [Github #9159](https://github.com/penpot/penpot/pull/9159)
|
||||||
|
- Fix `PENPOT_OIDC_USER_INFO_SOURCE` flag being silently ignored in the OIDC callback (by @GeekClassy) [Github #9108](https://github.com/penpot/penpot/issues/9108)
|
||||||
|
- Fix crash in share-link viewer when a team member's email is missing `@` or has no domain TLD (by @boskodev790) [Github #9120](https://github.com/penpot/penpot/pull/9120)
|
||||||
|
- Fix crash when pasting a component with variants from an external shared library into a file that uses that library (by @FairyPigDev) [Github #8144](https://github.com/penpot/penpot/issues/8144)
|
||||||
|
- Remove `corepack` from the MCP local launcher so it runs on Node.js 25+, where corepack is no longer bundled (by @TheAifam5) [Github #8877](https://github.com/penpot/penpot/issues/8877)
|
||||||
|
- Fix Copy as SVG to produce a valid document for multi-shape selections and use `image/svg+xml` MIME type (by @RenzoMXD) [Github #9066](https://github.com/penpot/penpot/pull/9066)
|
||||||
|
- Preserve OpenType variant name table for custom fonts in the dashboard (by @rutherfordcraze) [Github #8924](https://github.com/penpot/penpot/issues/8924)
|
||||||
|
- Add export panel to inspect styles tab [Taiga #13582](https://tree.taiga.io/project/penpot/issue/13582)
|
||||||
|
- Fix styles between grid layout inputs [Taiga #13526](https://tree.taiga.io/project/penpot/issue/13526)
|
||||||
|
- Fix id prop on switch component [Taiga #13534](https://tree.taiga.io/project/penpot/issue/13534)
|
||||||
|
- Update copy on penpot update message [Taiga #12924](https://tree.taiga.io/project/penpot/issue/12924)
|
||||||
|
- Fix scroll on library modal [Taiga #13639](https://tree.taiga.io/project/penpot/issue/13639)
|
||||||
|
- Fix dates to avoid show them in english when browser is in auto [Taiga #13786](https://tree.taiga.io/project/penpot/issue/13786)
|
||||||
|
- Fix focus radio button [Taiga #13841](https://tree.taiga.io/project/penpot/issue/13841)
|
||||||
|
- Token tree should be expanded by default [Taiga #13631](https://tree.taiga.io/project/penpot/issue/13631)
|
||||||
|
- Fix opacity incorrectly disabled for visible shapes [Taiga #13906](https://tree.taiga.io/project/penpot/issue/13906)
|
||||||
|
- Update onboarding image [Taiga #13864](https://tree.taiga.io/project/penpot/issue/13864)
|
||||||
|
- Fix plugin modal drag interactions over iframe and close-button behavior (by @marekhrabe) [Github #8871](https://github.com/penpot/penpot/pull/8871)
|
||||||
|
- Fix hot update on color-row on texts [Taiga #13923](https://tree.taiga.io/project/penpot/issue/13923)
|
||||||
|
- Fix selected color tokens [Taiga #13930](https://tree.taiga.io/project/penpot/issue/13930)
|
||||||
|
- Fix dashboard Recent/Deleted titles overlapped by scrolling content (by @rockchris099) [Github #8577](https://github.com/penpot/penpot/issues/8577)
|
||||||
|
- Display resolved values of inactive tokens [Taiga #13628](https://tree.taiga.io/project/penpot/issue/13628)
|
||||||
|
- Fix hyphens stripped from export filenames (by @jamesrayammons) [Github #8901](https://github.com/penpot/penpot/issues/8901)
|
||||||
|
- Fix app crash when selecting shapes with one hidden [Taiga #13959](https://tree.taiga.io/project/penpot/issue/13959)
|
||||||
|
- Fix opacity mixed value [Taiga #13960](https://tree.taiga.io/project/penpot/issue/13960)
|
||||||
|
- Fix gap input throwing an error [Github #8984](https://github.com/penpot/penpot/pull/8984)
|
||||||
|
- Fix copy to be more specific [Taiga #13990](https://tree.taiga.io/project/penpot/issue/13990)
|
||||||
|
- Allow deleting the profile avatar after uploading (by @moorsecopers99) [Github #9067](https://github.com/penpot/penpot/issues/9067)
|
||||||
|
- Fix incorrect rendering when exporting text as SVG, PNG and JPG (by @edwin-rivera-dev) [Github #8516](https://github.com/penpot/penpot/issues/8516)
|
||||||
|
- Fix "Help & Learning" submenu vertical alignment in account menu (by @juan-flores077) [Github #9137](https://github.com/penpot/penpot/issues/9137)
|
||||||
|
- Fix plugin `addInteraction` silently rejecting `open-overlay` actions with `manualPositionLocation` (by @axelseis) [Github #8409](https://github.com/penpot/penpot/issues/8409)
|
||||||
|
- Fix typography style creation with tokenized line-height (by @juan-flores077) [Github #8479](https://github.com/penpot/penpot/issues/8479)
|
||||||
|
- Fix colorpicker layout so the eyedropper button is visible again [Taiga #14057](https://tree.taiga.io/project/penpot/issue/14057)
|
||||||
|
- Fix restore-deleted-team-files failing due to a typo in the reduce accumulator (by @Dexterity104) [Github #9241](https://github.com/penpot/penpot/issues/9241)
|
||||||
|
- Fix internal error on layer prev/next sibling selection (by @jsdevninja) [Github #9003](https://github.com/penpot/penpot/issues/9003)
|
||||||
|
- Fix tooltip appearing two times when nested elements [Github #9031](https://github.com/penpot/penpot/issues/9031)
|
||||||
|
- Fix broken update library notification link in the UI [Github #9070](https://github.com/penpot/penpot/issues/9070)
|
||||||
|
- Fix plugin API `ShapeBase.component()` returning the outermost component instead of the immediate component in case of nested component instances [Github #9183](https://github.com/penpot/penpot/issues/9183)
|
||||||
|
- Fix content attribute sync group resolution by shape type [Github #8724](https://github.com/penpot/penpot/pull/8724)
|
||||||
|
- Fix highlight on shape after rename [Github #8890](https://github.com/penpot/penpot/pull/8890)
|
||||||
|
- Fix plugin parse-point returning plain map instead of Point record (by @FairyPigDev) [Github #9129](https://github.com/penpot/penpot/pull/9129)
|
||||||
|
- Fix `:heigth` typo in clipboard frame-same-size? (by @iot2edge) [Github #9250](https://github.com/penpot/penpot/pull/9250)
|
||||||
|
- Fix Settings and Notifications "Update Settings" button enabled state when form has no changes (by @moorsecopers99) [Github #9090](https://github.com/penpot/penpot/issues/9090)
|
||||||
|
|
||||||
|
## 2.15.0 (Unreleased)
|
||||||
|
|
||||||
|
### :sparkles: New features & Enhancements
|
||||||
|
|
||||||
|
- Add MCP server integration [Github #9174](https://github.com/penpot/penpot/issues/9174)
|
||||||
|
- Add chunked upload API for large media and binary files (removes previous upload size limits) [Github #8909](https://github.com/penpot/penpot/pull/8909)
|
||||||
|
- Improve team name validation [Github #9176](https://github.com/penpot/penpot/pull/9176)
|
||||||
|
|
||||||
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
|
- Fix MCP integrations URL copy action to match the URL displayed in settings [Github #9238](https://github.com/penpot/penpot/issues/9238)
|
||||||
|
- Fix Plugin API token methods rejecting JS array of strings [Github #9162](https://github.com/penpot/penpot/issues/9162)
|
||||||
|
- Harden Nginx responses with standard security headers and hide upstream `X-Powered-By` headers
|
||||||
|
- Fix keep-alive interval leak in PluginBridge (by @opcode81) [Github #9435](https://github.com/penpot/penpot/pull/9435)
|
||||||
|
- Fix MCP "active in another tab" notification not clearing (by @Dexterity104) [Github #9321](https://github.com/penpot/penpot/pull/9321)
|
||||||
|
- Fix swapped analytics event names on MCP tab-switch dialog (by @Dexterity104) [Github #9322](https://github.com/penpot/penpot/pull/9322)
|
||||||
|
- Fix MCP ReplServer binding to all interfaces (0.0.0.0) instead of localhost, allowing unauthenticated RCE [Github #9400] (https://github.com/penpot/penpot/pull/9400)
|
||||||
|
- Fix incorrect handling of version restore operation [Github #9041](https://github.com/penpot/penpot/pull/9041)
|
||||||
|
- Fix SSRF in media URL import and restrict unauthenticated asset access to public buckets only [Github #9390](https://github.com/penpot/penpot/pull/9390)
|
||||||
|
- Fix text edition mode not exited when changing selection, blocking token application [Github #9346](https://github.com/penpot/penpot/issues/9346)
|
||||||
|
- Use base64 envelope for Uint8Array task results to avoid JSON expansion (by @opcode81) [Github #9431](https://github.com/penpot/penpot/pull/9431)
|
||||||
|
- Fix empty warning on login [Github #9056](https://github.com/penpot/penpot/pull/9056)
|
||||||
|
- Fix layer hierarchy to match old and new SCSS [Github #9126](https://github.com/penpot/penpot/pull/9126)
|
||||||
|
- Fix multiple selection on shapes with token applied to stroke color [Github #9110](https://github.com/penpot/penpot/pull/9110)
|
||||||
|
- Fix onboarding modals appearing behind libraries and templates panel [Github #9178](https://github.com/penpot/penpot/pull/9178)
|
||||||
|
- Fix release notes modal appearing behind the dashboard sidebar (by @RenzoMXD) [Github #8296](https://github.com/penpot/penpot/issues/8296)
|
||||||
|
- Fix maximum call stack size exceeded in SSE read-stream [Github #9470](https://github.com/penpot/penpot/issues/9470)
|
||||||
|
|
||||||
|
## 2.14.5
|
||||||
|
|
||||||
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
|
- Fix incorrect invitation token handling on register process [Github #9380](https://github.com/penpot/penpot/pull/9380)
|
||||||
|
|
||||||
## 2.14.4
|
## 2.14.4
|
||||||
|
|
||||||
### :bug: Bugs fixed
|
### :bug: Bugs fixed
|
||||||
@ -18,7 +203,6 @@
|
|||||||
|
|
||||||
### :bug: Bugs fixed
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
- Fix component "broken" after switch variant [Taiga #12984](https://tree.taiga.io/project/penpot/issue/12984)
|
|
||||||
- Fix variants corner cases with selrect and points [Github #8882](https://github.com/penpot/penpot/pull/8882)
|
- Fix variants corner cases with selrect and points [Github #8882](https://github.com/penpot/penpot/pull/8882)
|
||||||
- Fix dashboard navigation tabs overlap with projects content when scrolling [Taiga #13962](https://tree.taiga.io/project/penpot/issue/13962)
|
- Fix dashboard navigation tabs overlap with projects content when scrolling [Taiga #13962](https://tree.taiga.io/project/penpot/issue/13962)
|
||||||
- Fix text editor v1 focus [Taiga #13961](https://tree.taiga.io/project/penpot/issue/13961)
|
- Fix text editor v1 focus [Taiga #13961](https://tree.taiga.io/project/penpot/issue/13961)
|
||||||
@ -108,11 +292,9 @@
|
|||||||
- Fix wrong image in the onboarding invitation block [Taiga #13040](https://tree.taiga.io/project/penpot/issue/13040)
|
- Fix wrong image in the onboarding invitation block [Taiga #13040](https://tree.taiga.io/project/penpot/issue/13040)
|
||||||
- Fix wrong register image [Taiga #12955](https://tree.taiga.io/project/penpot/task/12955)
|
- Fix wrong register image [Taiga #12955](https://tree.taiga.io/project/penpot/task/12955)
|
||||||
- Fix error message on components doesn't close automatically [Taiga #12012](https://tree.taiga.io/project/penpot/issue/12012)
|
- Fix error message on components doesn't close automatically [Taiga #12012](https://tree.taiga.io/project/penpot/issue/12012)
|
||||||
- Fix incorrect handling of input values on layout gap and padding inputs [Github #8113](https://github.com/penpot/penpot/issues/8113)
|
|
||||||
- Fix incorrect default option on tokens import dialog [Github #8051](https://github.com/penpot/penpot/pull/8051)
|
- Fix incorrect default option on tokens import dialog [Github #8051](https://github.com/penpot/penpot/pull/8051)
|
||||||
- Fix unhandled exception tokens creation dialog [Github #8110](https://github.com/penpot/penpot/issues/8110)
|
- Fix unhandled exception tokens creation dialog [Github #8110](https://github.com/penpot/penpot/issues/8110)
|
||||||
- Fix displaying a hidden user avatar when there is only one more [Taiga #13058](https://tree.taiga.io/project/penpot/issue/13058)
|
- Fix displaying a hidden user avatar when there is only one more [Taiga #13058](https://tree.taiga.io/project/penpot/issue/13058)
|
||||||
- Fix unhandled exception on open-new-window helper [Github #7787](https://github.com/penpot/penpot/issues/7787)
|
|
||||||
- Fix exception on uploading large fonts [Github #8135](https://github.com/penpot/penpot/pull/8135)
|
- Fix exception on uploading large fonts [Github #8135](https://github.com/penpot/penpot/pull/8135)
|
||||||
- Fix boolean operators in menu for boards [Taiga #13174](https://tree.taiga.io/project/penpot/issue/13174)
|
- Fix boolean operators in menu for boards [Taiga #13174](https://tree.taiga.io/project/penpot/issue/13174)
|
||||||
- Fix viewer can update library [Taiga #13186](https://tree.taiga.io/project/penpot/issue/13186)
|
- Fix viewer can update library [Taiga #13186](https://tree.taiga.io/project/penpot/issue/13186)
|
||||||
@ -173,12 +355,8 @@
|
|||||||
- Fix missing text color token from selected shapes in selected colors list [Taiga #12956](https://tree.taiga.io/project/penpot/issue/12956)
|
- Fix missing text color token from selected shapes in selected colors list [Taiga #12956](https://tree.taiga.io/project/penpot/issue/12956)
|
||||||
- Fix dropdown option width in Guides columns dropdown [Taiga #12959](https://tree.taiga.io/project/penpot/issue/12959)
|
- Fix dropdown option width in Guides columns dropdown [Taiga #12959](https://tree.taiga.io/project/penpot/issue/12959)
|
||||||
- Fix typos on download modal [Taiga #12865](https://tree.taiga.io/project/penpot/issue/12865)
|
- Fix typos on download modal [Taiga #12865](https://tree.taiga.io/project/penpot/issue/12865)
|
||||||
- Fix problem with text editor maintaining previous styles [Taiga #12835](https://tree.taiga.io/project/penpot/issue/12835)
|
|
||||||
- Fix unhandled exception tokens creation dialog [Github #8110](https://github.com/penpot/penpot/issues/8110)
|
|
||||||
- Fix allow negative spread values on shadow token creation [Taiga #13167](https://tree.taiga.io/project/penpot/issue/13167)
|
- Fix allow negative spread values on shadow token creation [Taiga #13167](https://tree.taiga.io/project/penpot/issue/13167)
|
||||||
- Fix spanish translations on import export token modal [Taiga #13171](https://tree.taiga.io/project/penpot/issue/13171)
|
- Fix spanish translations on import export token modal [Taiga #13171](https://tree.taiga.io/project/penpot/issue/13171)
|
||||||
- Remove whitespaces from asset export filename [Github #8133](https://github.com/penpot/penpot/pull/8133)
|
|
||||||
- Fix exception on uploading large fonts [Github #8135](https://github.com/penpot/penpot/pull/8135)
|
|
||||||
- Fix unhandled exception on open-new-window helper [Github #7787](https://github.com/penpot/penpot/issues/7787)
|
- Fix unhandled exception on open-new-window helper [Github #7787](https://github.com/penpot/penpot/issues/7787)
|
||||||
- Fix incorrect handling of input values on layout gap and padding inputs [Github #8113](https://github.com/penpot/penpot/issues/8113)
|
- Fix incorrect handling of input values on layout gap and padding inputs [Github #8113](https://github.com/penpot/penpot/issues/8113)
|
||||||
- Fix several race conditions on path editor [Github #8187](https://github.com/penpot/penpot/pull/8187)
|
- Fix several race conditions on path editor [Github #8187](https://github.com/penpot/penpot/pull/8187)
|
||||||
@ -271,10 +449,8 @@ example. It's still usable as before, we just removed the example.
|
|||||||
### :bug: Bugs fixed
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
- Fix text line-height values are wrong [Taiga #12252](https://tree.taiga.io/project/penpot/issue/12252)
|
- Fix text line-height values are wrong [Taiga #12252](https://tree.taiga.io/project/penpot/issue/12252)
|
||||||
- Fix an error translation [Taiga #12402](https://tree.taiga.io/project/penpot/issue/12402)
|
|
||||||
- Fix pan cursor not disabling viewport guides [Github #6985](https://github.com/penpot/penpot/issues/6985)
|
- Fix pan cursor not disabling viewport guides [Github #6985](https://github.com/penpot/penpot/issues/6985)
|
||||||
- Fix viewport resize on locked shapes [Taiga #11974](https://tree.taiga.io/project/penpot/issue/11974)
|
- Fix viewport resize on locked shapes [Taiga #11974](https://tree.taiga.io/project/penpot/issue/11974)
|
||||||
- Fix nested variant in a component doesn't keep inherited overrides [Taiga #12299](https://tree.taiga.io/project/penpot/issue/12299)
|
|
||||||
- Fix on copy instance inside a components chain touched are missing [Taiga #12371](https://tree.taiga.io/project/penpot/issue/12371)
|
- Fix on copy instance inside a components chain touched are missing [Taiga #12371](https://tree.taiga.io/project/penpot/issue/12371)
|
||||||
- Fix problem with multiple selection and shadows [Github #7437](https://github.com/penpot/penpot/issues/7437)
|
- Fix problem with multiple selection and shadows [Github #7437](https://github.com/penpot/penpot/issues/7437)
|
||||||
- Fix search shortcut [Taiga #10265](https://tree.taiga.io/project/penpot/issue/10265)
|
- Fix search shortcut [Taiga #10265](https://tree.taiga.io/project/penpot/issue/10265)
|
||||||
@ -355,7 +531,7 @@ example. It's still usable as before, we just removed the example.
|
|||||||
- Fix text override is lost after switch [Taiga #12269](https://tree.taiga.io/project/penpot/issue/12269)
|
- Fix text override is lost after switch [Taiga #12269](https://tree.taiga.io/project/penpot/issue/12269)
|
||||||
- Fix exporting a board crashing the app [Taiga #12384](https://tree.taiga.io/project/penpot/issue/12384)
|
- Fix exporting a board crashing the app [Taiga #12384](https://tree.taiga.io/project/penpot/issue/12384)
|
||||||
- Fix nested variant in a component doesn't keep inherited overrides [Taiga #12299](https://tree.taiga.io/project/penpot/issue/12299)
|
- Fix nested variant in a component doesn't keep inherited overrides [Taiga #12299](https://tree.taiga.io/project/penpot/issue/12299)
|
||||||
- Fix selected colors not showing colors from children shapes in multiple selection [Taiga #12384](https://tree.taiga.io/project/penpot/issue/12385)
|
- Fix selected colors not showing colors from children shapes in multiple selection [Taiga #12385](https://tree.taiga.io/project/penpot/issue/12385)
|
||||||
- Fix scrollbar issue in design tab [Taiga #12367](https://tree.taiga.io/project/penpot/issue/12367)
|
- Fix scrollbar issue in design tab [Taiga #12367](https://tree.taiga.io/project/penpot/issue/12367)
|
||||||
- Fix library update notificacions showing when they should not [Taiga #12397](https://tree.taiga.io/project/penpot/issue/12397)
|
- Fix library update notificacions showing when they should not [Taiga #12397](https://tree.taiga.io/project/penpot/issue/12397)
|
||||||
- Fix remove flex button doesn’t work within variant [Taiga #12314](https://tree.taiga.io/project/penpot/issue/12314)
|
- Fix remove flex button doesn’t work within variant [Taiga #12314](https://tree.taiga.io/project/penpot/issue/12314)
|
||||||
|
|||||||
121
CONTRIBUTING.md
121
CONTRIBUTING.md
@ -13,7 +13,17 @@ Center](https://help.penpot.app/).
|
|||||||
- [Prerequisites](#prerequisites)
|
- [Prerequisites](#prerequisites)
|
||||||
- [Reporting Bugs](#reporting-bugs)
|
- [Reporting Bugs](#reporting-bugs)
|
||||||
- [Pull Requests](#pull-requests)
|
- [Pull Requests](#pull-requests)
|
||||||
|
- [Workflow](#workflow)
|
||||||
|
- [Title format](#title-format)
|
||||||
|
- [Description](#description)
|
||||||
|
- [Branch naming](#branch-naming)
|
||||||
|
- [Review process](#review-process)
|
||||||
|
- [What we won't accept](#what-we-wont-accept)
|
||||||
|
- [Good first issues](#good-first-issues)
|
||||||
- [Commit Guidelines](#commit-guidelines)
|
- [Commit Guidelines](#commit-guidelines)
|
||||||
|
- [Commit types](#commit-types)
|
||||||
|
- [Rules](#rules)
|
||||||
|
- [Examples](#examples)
|
||||||
- [Formatting and Linting](#formatting-and-linting)
|
- [Formatting and Linting](#formatting-and-linting)
|
||||||
- [Changelog](#changelog)
|
- [Changelog](#changelog)
|
||||||
- [Code of Conduct](#code-of-conduct)
|
- [Code of Conduct](#code-of-conduct)
|
||||||
@ -52,18 +62,104 @@ Advisories](https://github.com/penpot/penpot/security/advisories)
|
|||||||
|
|
||||||
1. **Read the DCO** — see [Developer's Certificate of Origin](#developers-certificate-of-origin-dco)
|
1. **Read the DCO** — see [Developer's Certificate of Origin](#developers-certificate-of-origin-dco)
|
||||||
below. All code patches must include a `Signed-off-by` line.
|
below. All code patches must include a `Signed-off-by` line.
|
||||||
2. **Discuss before building** — open a question/discussion issue before
|
2. **Discuss before building** — open a [GitHub
|
||||||
starting work on a new feature or significant change. No PR will be
|
Issue](https://github.com/penpot/penpot/issues) before starting work on
|
||||||
accepted without prior discussion, whether it is a new feature, a planned
|
a new feature or significant change. For planned features on the roadmap,
|
||||||
one, or a quick win.
|
reference the corresponding Taiga story. Do not expect your contribution
|
||||||
|
to be accepted if you submit it without prior discussion — this applies
|
||||||
|
to new features, planned features, and quick wins alike.
|
||||||
3. **Bug fixes** — you may submit a PR directly, but we still recommend
|
3. **Bug fixes** — you may submit a PR directly, but we still recommend
|
||||||
filing an issue first so we can track it independently of your fix.
|
filing an issue first so we can track it independently of your fix.
|
||||||
4. **Format and lint** — run the checks described in
|
4. **Format and lint** — run the checks described in
|
||||||
[Formatting and Linting](#formatting-and-linting) before submitting.
|
[Formatting and Linting](#formatting-and-linting) before submitting.
|
||||||
|
|
||||||
|
### Title format
|
||||||
|
|
||||||
|
Pull request titles **must** follow the same convention as commit subjects:
|
||||||
|
|
||||||
|
```
|
||||||
|
:emoji: <subject>
|
||||||
|
```
|
||||||
|
|
||||||
|
- Use the **imperative mood** (e.g. "Fix", not "Fixed").
|
||||||
|
- Capitalize the first letter of the subject.
|
||||||
|
- Do not end the subject with a period.
|
||||||
|
- Keep the subject to **70 characters** or fewer.
|
||||||
|
- Use one of the [commit type emojis](#commit-types) listed below.
|
||||||
|
|
||||||
|
When a PR contains multiple unrelated commits, choose the emoji that
|
||||||
|
best represents the dominant change.
|
||||||
|
|
||||||
|
**Examples:**
|
||||||
|
|
||||||
|
```
|
||||||
|
:bug: Fix unexpected error on launching modal
|
||||||
|
:sparkles: Enable new modal for profile
|
||||||
|
:zap: Improve performance of dashboard navigation
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note:** When a PR is squash-merged, the PR title becomes the
|
||||||
|
> commit message on the main branch. Getting the title right matters.
|
||||||
|
|
||||||
|
### Description
|
||||||
|
|
||||||
|
Every pull request should include a description that helps reviewers
|
||||||
|
understand the change quickly:
|
||||||
|
|
||||||
|
1. **What and why** — describe the change and its motivation.
|
||||||
|
2. **Link related issues** — use `Closes #1234` or reference a Taiga
|
||||||
|
story (e.g. `Taiga #5678`).
|
||||||
|
3. **Screenshots or recordings** — required for any UI-visible change.
|
||||||
|
4. **Testing notes** — how did you verify the change? Any edge cases?
|
||||||
|
5. **Breaking changes** — call out anything that affects existing users
|
||||||
|
or requires migration steps.
|
||||||
|
|
||||||
|
### Branch naming
|
||||||
|
|
||||||
|
Use a descriptive branch name that reflects the type and scope of the
|
||||||
|
change:
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>/<short-description>
|
||||||
|
```
|
||||||
|
|
||||||
|
Types: `fix`, `feat`, `refactor`, `docs`, `chore`, `perf`.
|
||||||
|
|
||||||
|
Optionally include the issue number:
|
||||||
|
|
||||||
|
```
|
||||||
|
fix/9122-email-blacklisting
|
||||||
|
feat/export-webp
|
||||||
|
refactor/layout-sizing
|
||||||
|
```
|
||||||
|
|
||||||
|
### Review process
|
||||||
|
|
||||||
|
- We are a small team and maintainers juggle reviews alongside other
|
||||||
|
tasks. Please do not expect your code to be reviewed instantly.
|
||||||
|
- Reviews are handled in dedicated blocks of time, usually in the order
|
||||||
|
PRs arrive. It may take a few days to get a first review, especially
|
||||||
|
when urgent tasks come up.
|
||||||
|
- Address review feedback by **pushing new commits** — do not
|
||||||
|
force-push during review, as it breaks comment threads.
|
||||||
|
- PRs require at least **one approval** before merge.
|
||||||
|
- We use **squash-merge** by default. The PR title becomes the final
|
||||||
|
commit message, so follow the [title format](#title-format) above.
|
||||||
|
|
||||||
|
### What we won't accept
|
||||||
|
|
||||||
|
To save time on both sides, please avoid submitting PRs that:
|
||||||
|
|
||||||
|
- Introduce new dependencies without prior discussion.
|
||||||
|
- Change the build system or CI configuration without maintainer
|
||||||
|
approval.
|
||||||
|
- Mix unrelated changes in a single PR — keep PRs focused on one
|
||||||
|
concern.
|
||||||
|
- Skip the [discussion step](#workflow) for non-bug-fix changes.
|
||||||
|
|
||||||
### Good first issues
|
### Good first issues
|
||||||
|
|
||||||
We use the `easy fix` label to mark issues appropriate for newcomers.
|
We use the `good first issue` label to mark issues appropriate for newcomers.
|
||||||
|
|
||||||
## Commit Guidelines
|
## Commit Guidelines
|
||||||
|
|
||||||
@ -80,7 +176,7 @@ Commit messages must follow this format:
|
|||||||
### Commit types
|
### Commit types
|
||||||
|
|
||||||
| Emoji | Description |
|
| Emoji | Description |
|
||||||
|-------|-------------|
|
| ---------------------- | -------------------------- |
|
||||||
| :bug: | Bug fix |
|
| :bug: | Bug fix |
|
||||||
| :sparkles: | Improvement or enhancement |
|
| :sparkles: | Improvement or enhancement |
|
||||||
| :tada: | New feature |
|
| :tada: | New feature |
|
||||||
@ -135,6 +231,19 @@ We use [cljfmt](https://github.com/weavejester/cljfmt) for formatting and
|
|||||||
./scripts/lint
|
./scripts/lint
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For frontend SCSS, we use `stylelint` for linting and
|
||||||
|
`Prettier` for formatting:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd frontend
|
||||||
|
|
||||||
|
# Lint SCSS
|
||||||
|
pnpm run lint:scss (does not modify files)
|
||||||
|
|
||||||
|
# Fix SCSS formatting (modifies files in place)
|
||||||
|
pnpm run fmt:scss
|
||||||
|
```
|
||||||
|
|
||||||
Ideally, run these as git pre-commit hooks.
|
Ideally, run these as git pre-commit hooks.
|
||||||
[Husky](https://typicode.github.io/husky/#/) is a convenient option for
|
[Husky](https://typicode.github.io/husky/#/) is a convenient option for
|
||||||
setting this up.
|
setting this up.
|
||||||
|
|||||||
116
README.md
116
README.md
@ -1,18 +1,21 @@
|
|||||||
|
<img width="100%" src="https://github.com/user-attachments/assets/da17b160-f289-436f-b140-972083a08602" />
|
||||||
|
|
||||||
[uri_license]: https://www.mozilla.org/en-US/MPL/2.0
|
[uri_license]: https://www.mozilla.org/en-US/MPL/2.0
|
||||||
[uri_license_image]: https://img.shields.io/badge/MPL-2.0-blue.svg
|
[uri_license_image]: https://img.shields.io/badge/MPL-2.0-blue.svg
|
||||||
|
|
||||||
<picture>
|
|
||||||
<source media="(prefers-color-scheme: dark)" srcset="https://penpot.app/images/readme/github-dark-mode.png">
|
|
||||||
<source media="(prefers-color-scheme: light)" srcset="https://penpot.app/images/readme/github-light-mode.png">
|
|
||||||
<img alt="penpot header image" src="https://penpot.app/images/readme/github-light-mode.png">
|
|
||||||
</picture>
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://www.mozilla.org/en-US/MPL/2.0" rel="nofollow"><img alt="License: MPL-2.0" src="https://img.shields.io/badge/MPL-2.0-blue.svg" style="max-width:100%;"></a>
|
<a href="https://www.digitalpublicgoods.net/r/penpot" rel="nofollow">
|
||||||
<a href="https://community.penpot.app" rel="nofollow"><img alt="Penpot Community" src="https://img.shields.io/discourse/posts?server=https%3A%2F%2Fcommunity.penpot.app" style="max-width:100%;"></a>
|
<img alt="Verified DPG" src="https://img.shields.io/badge/Verified-DPG-blue.svg">
|
||||||
<a href="https://tree.taiga.io/project/penpot/" title="Managed with Taiga.io" rel="nofollow"><img alt="Managed with Taiga.io" src="https://img.shields.io/badge/managed%20with-TAIGA.io-709f14.svg" style="max-width:100%;"></a>
|
</a>
|
||||||
<a href="https://gitpod.io/#https://github.com/penpot/penpot" rel="nofollow"><img alt="Gitpod ready-to-code" src="https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod" style="max-width:100%;"></a>
|
<a href="https://community.penpot.app" rel="nofollow">
|
||||||
|
<img alt="Penpot Community" src="https://img.shields.io/discourse/posts?server=https%3A%2F%2Fcommunity.penpot.app">
|
||||||
|
</a>
|
||||||
|
<a href="https://tree.taiga.io/project/penpot/" rel="nofollow">
|
||||||
|
<img alt="Managed with Taiga.io" src="https://img.shields.io/badge/managed%20with-TAIGA.io-709f14.svg">
|
||||||
|
</a>
|
||||||
|
<a href="https://gitpod.io/#https://github.com/penpot/penpot" rel="nofollow">
|
||||||
|
<img alt="Gitpod ready-to-code" src="https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod">
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@ -29,25 +32,25 @@
|
|||||||
<a href="https://fosstodon.org/@penpot/"><b>Mastodon</b></a> •
|
<a href="https://fosstodon.org/@penpot/"><b>Mastodon</b></a> •
|
||||||
<a href="https://bsky.app/profile/penpot.app"><b>Bluesky</b></a> •
|
<a href="https://bsky.app/profile/penpot.app"><b>Bluesky</b></a> •
|
||||||
<a href="https://twitter.com/penpotapp"><b>X</b></a>
|
<a href="https://twitter.com/penpotapp"><b>X</b></a>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<br />
|
[Penpot video](https://github.com/user-attachments/assets/7c67fd7c-04d3-4c9b-88ec-b6f5e23f8332)
|
||||||
|
|
||||||
[Penpot video](https://github.com/user-attachments/assets/7c67fd7c-04d3-4c9b-88ec-b6f5e23f8332
|
Penpot is the open-source design platform for teams that build digital products at scale.
|
||||||
)
|
|
||||||
|
|
||||||
<br />
|
Penpot’s key strength lies in giving you **full ownership of your design infrastructure**. Built on open source and designed for [self-hosting](https://help.penpot.app/technical-guide/getting-started/), it puts teams in complete control of their design environment supporting strict compliance and governance requirements. Whether used in the **browser or deployed on your own servers**, Penpot **works with open standards** like SVG, CSS, HTML, and JSON.
|
||||||
|
|
||||||
Penpot is the first **open-source** design tool for design and code collaboration. Designers can create stunning designs, interactive prototypes, design systems at scale, while developers enjoy ready-to-use code and make their workflow easy and fast. And all of this with no handoff drama.
|
Real-time collaboration strengthens this foundation, helping teams scale and bring design closer to the product through top-tier capabilities. Additionally, developers feel at home using Penpot, because design is expressed as code, enabling a direct translation and shipping products faster.
|
||||||
|
|
||||||
Available on browser or self-hosted, Penpot works with open standards like SVG, CSS, HTML and JSON, and it’s free!
|
Best-in-class native [Design Tokens](https://penpot.dev/collaboration/design-tokens) provide a single source of truth between design and development. They ensure consistency, improve collaboration, and make it easier to manage complex design systems.
|
||||||
|
|
||||||
The latest updates take Penpot even further. It’s the first design tool to integrate native [design tokens](https://penpot.dev/collaboration/design-tokens)—a single source of truth to improve efficiency and collaboration between product design and development.
|
The [MCP server](https://penpot.app/penpot-mcp-server) takes it further by enabling multi-directional workflows between design and code. A [powerful open API](https://help.penpot.app/mcp/#quick-start) and plugin system makes the workspace programmable, enabling automation, AI-driven workflows, and integrations with the tools and systems you already use.
|
||||||
With the [huge 2.0 release](https://penpot.app/dev-diaries), Penpot took the platform to a whole new level. This update introduces the ground-breaking [CSS Grid Layout feature](https://penpot.app/penpot-2.0), a complete UI redesign, a new Components system, and much more.
|
|
||||||
For organizations that need extra service for its teams, [get in touch](https://cal.com/team/penpot/talk-to-us)
|
|
||||||
|
|
||||||
🎇 Design, code, and Open Source meet at [Penpot Fest](https://penpot.app/penpotfest)! Be part of the 2025 edition in Madrid, Spain, on October 9-10.
|
With [CSS Grid and Flex Layout](https://help.penpot.app/user-guide/designing/flexible-layouts/), teams can design responsive interfaces that behave like real code from the start.
|
||||||
|
|
||||||
|
Combined, these features turn Penpot into a **full-stack design platform** for building scalable design systems and fully integrated product development processes.
|
||||||
|
|
||||||
|
If your organization is scaling and needs extra support, we’re here to help. [Talk to us](https://penpot.app/talk-to-us)
|
||||||
|
|
||||||
## Table of contents ##
|
## Table of contents ##
|
||||||
|
|
||||||
@ -60,101 +63,78 @@ For organizations that need extra service for its teams, [get in touch](https://
|
|||||||
|
|
||||||
## Why Penpot ##
|
## Why Penpot ##
|
||||||
|
|
||||||
Penpot expresses designs as code. Designers can do their best work and see it will be beautifully implemented by developers in a two-way collaboration.
|
Penpot connects design, code, and AI workflows through a code-based approach, making designs readable by developers and AI via the MCP server. This approach helps teams ship what’s actually designed and manage design systems at scale with powerful design tokens. As a self-hosted, open-source and real-time collaboration platform, Penpot offers full flexibility, security, and ownership without vendor lock-in. Learn more about [why Penpot](https://penpot.app/why-penpot) is the platform for your team.
|
||||||
|
|
||||||
### Plugin system ###
|
### Plugin system ###
|
||||||
|
|
||||||
[Penpot plugins](https://penpot.app/penpothub/plugins) let you expand the platform's capabilities, give you the flexibility to integrate it with other apps, and design custom solutions.
|
[Penpot plugins](https://penpot.app/penpothub/plugins) let you expand the platform's capabilities, give you the flexibility to integrate it with other apps, and design custom solutions.
|
||||||
|
|
||||||
### Designed for developers ###
|
### Designed for developers ###
|
||||||
|
|
||||||
Penpot was built to serve both designers and developers and create a fluid design-code process. You have the choice to enjoy real-time collaboration or play "solo".
|
Penpot was built to serve both designers and developers and create a fluid design-code process. You have the choice to enjoy real-time collaboration or play "solo".
|
||||||
|
|
||||||
### Inspect mode ###
|
### Inspect mode ###
|
||||||
|
|
||||||
Work with ready-to-use code and make your workflow easy and fast. The inspect tab gives instant access to SVG, CSS and HTML code.
|
Work with ready-to-use code and make your workflow easy and fast. The inspect tab gives instant access to SVG, CSS and HTML code.
|
||||||
|
|
||||||
### Self host your own instance ###
|
|
||||||
Provide your team or organization with a completely owned collaborative design tool. Use Penpot's cloud service or deploy your own Penpot server.
|
|
||||||
|
|
||||||
### Integrations ###
|
### Integrations ###
|
||||||
Penpot offers integration into the development toolchain, thanks to its support for webhooks and an API accessible through access tokens.
|
|
||||||
|
Penpot offers [integration](https://penpot.app/integrations-api) into the development toolchain, thanks to its support for webhooks and an API accessible through access tokens.
|
||||||
|
|
||||||
### Building Design Systems: design tokens, components and variants ###
|
### Building Design Systems: design tokens, components and variants ###
|
||||||
Penpot brings design systems to code-minded teams: a single source of truth with native Design Tokens, Components, and Variants for scalable, reusable, and consistent UI across projects and platforms.
|
|
||||||
|
|
||||||
|
Penpot brings [design systems](https://penpot.app/design/design-systems) to code-minded teams: a single source of truth with native Design Tokens, Components, and Variants for scalable, reusable, and consistent UI across projects and platforms.
|
||||||
|
|
||||||
<br />
|
<img width="100%" alt="Penpot Design Systems" src="https://github.com/user-attachments/assets/cce75ad6-f783-473f-8803-da9eb8255fef">
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
<img src="https://github.com/user-attachments/assets/cce75ad6-f783-473f-8803-da9eb8255fef">
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<br />
|
|
||||||
|
|
||||||
## Getting started ##
|
## Getting started ##
|
||||||
|
|
||||||
Penpot is the only design & prototype platform that is deployment agnostic. You can use it in our [SAAS](https://design.penpot.app) or deploy it anywhere.
|
Penpot is the only design & prototype platform that is deployment agnostic. You can use it in our [SAAS](https://design.penpot.app) or deploy it anywhere.
|
||||||
|
|
||||||
Learn how to install it with Docker, Kubernetes, Elestio or other options on [our website](https://penpot.app/self-host).
|
Learn how to install it with Docker, Kubernetes, Elestio or other options on [our website](https://penpot.app/self-host).
|
||||||
<br />
|
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
<img src="https://site-assets.plasmic.app/2168cf524dd543caeff32384eb9ea0a1.svg" alt="Open Source" style="width: 65%;">
|
|
||||||
</p>
|
|
||||||
<br />
|
|
||||||
|
|
||||||
## Community ##
|
## Community ##
|
||||||
|
|
||||||
We love the Open Source software community. Contributing is our passion and if it’s yours too, participate and [improve](https://community.penpot.app/c/help-us-improve-penpot/7) Penpot. All your designs, code and ideas are welcome!
|
We love the Open Source software community. Contributing is our passion and if it’s yours too, participate and [improve](https://community.penpot.app/c/help-us-improve-penpot/7) Penpot. All your designs, code and ideas are welcome!
|
||||||
|
|
||||||
|
Want to go a step further? Become a [Penpot Ambassador](https://penpot.app/ambassador-program) and help grow the Penpot community in your region while contributing to a global, open design ecosystem.
|
||||||
|
|
||||||
If you need help or have any questions; if you’d like to share your experience using Penpot or get inspired; if you’d rather meet our community of developers and designers, [join our Community](https://community.penpot.app/)!
|
If you need help or have any questions; if you’d like to share your experience using Penpot or get inspired; if you’d rather meet our community of developers and designers, [join our Community](https://community.penpot.app/)!
|
||||||
|
|
||||||
You will find the following categories:
|
Categories include:
|
||||||
|
|
||||||
- [Ask the Community](https://community.penpot.app/c/ask-for-help-using-penpot/6)
|
- [Ask the Community](https://community.penpot.app/c/ask-for-help-using-penpot/6)
|
||||||
- [Troubleshooting](https://community.penpot.app/c/technical/8)
|
- [Troubleshooting](https://community.penpot.app/c/technical/8)
|
||||||
- [Help us Improve Penpot](https://community.penpot.app/c/help-us-improve-penpot/7)
|
- [Help us Improve Penpot](https://community.penpot.app/c/help-us-improve-penpot/7)
|
||||||
- [#MadeWithPenpot](https://community.penpot.app/c/madewithpenpot/9)
|
|
||||||
- [Events and Announcements](https://community.penpot.app/c/announcements/5)
|
- [Events and Announcements](https://community.penpot.app/c/announcements/5)
|
||||||
- [Inside Penpot](https://community.penpot.app/c/inside-penpot/21)
|
|
||||||
- [Penpot in your language](https://community.penpot.app/c/penpot-in-your-language/12)
|
- [Penpot in your language](https://community.penpot.app/c/penpot-in-your-language/12)
|
||||||
- [Design and Code Essentials](https://community.penpot.app/c/design-and-code-essentials/22)
|
- [Education](https://community.penpot.app/c/education/28)
|
||||||
|
|
||||||
|
<img width="100%" alt="Pentpot Community" src="https://github.com/user-attachments/assets/4b2a4360-12b5-4994-bd45-641449f86c4e" />
|
||||||
<br />
|
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
<img src="https://github.com/penpot/penpot/assets/5446186/6ac62220-a16c-46c9-ab21-d24ae357ed03" alt="Community" style="width: 65%;">
|
|
||||||
</p>
|
|
||||||
<br />
|
|
||||||
|
|
||||||
### Code of Conduct ###
|
### Code of Conduct ###
|
||||||
|
|
||||||
Anyone who contributes to Penpot, whether through code, in the community, or at an event, must adhere to the
|
Anyone who contributes to Penpot, whether through code, in the community, or at an event, must adhere to the
|
||||||
[code of conduct](https://help.penpot.app/contributing-guide/coc/) and foster a positive and safe environment.
|
[code of conduct](https://help.penpot.app/contributing-guide/coc/) and foster a positive and safe environment.
|
||||||
|
|
||||||
|
### Contributing ###
|
||||||
## Contributing ##
|
|
||||||
|
|
||||||
Any contribution will make a difference to improve Penpot. How can you get involved?
|
Any contribution will make a difference to improve Penpot. How can you get involved?
|
||||||
|
|
||||||
Choose your way:
|
Choose your way:
|
||||||
|
|
||||||
- Create and [share Libraries & Templates](https://penpot.app/libraries-templates.html) that will be helpful for the community
|
- Create and [share Libraries & Templates](https://penpot.app/libraries-templates.html) that will be helpful for the community.
|
||||||
- Invite your [team to join](https://design.penpot.app/#/auth/register)
|
- Invite your [team to join](https://design.penpot.app/#/auth/register).
|
||||||
- Give this repo a star and follow us on Social Media: [Mastodon](https://fosstodon.org/@penpot/), [Youtube](https://www.youtube.com/c/Penpot), [Instagram](https://instagram.com/penpot.app), [Linkedin](https://www.linkedin.com/company/penpotdesign), [Peertube](https://peertube.kaleidos.net/a/penpot_app), [X](https://twitter.com/penpotapp) and [BlueSky](https://bsky.app/profile/penpot.app)
|
- Give this repo a star and follow us on Social Media: [Mastodon](https://fosstodon.org/@penpot/), [Youtube](https://www.youtube.com/c/Penpot), [Instagram](https://instagram.com/penpot.app), [Linkedin](https://www.linkedin.com/company/penpotdesign), [Peertube](https://peertube.kaleidos.net/a/penpot_app), [X](https://twitter.com/penpotapp) and [BlueSky](https://bsky.app/profile/penpot.app).
|
||||||
- Participate in the [Community](https://community.penpot.app/) space by asking and answering questions; reacting to others’ articles; opening your own conversations and following along on decisions affecting the project.
|
- Participate in the [Community](https://community.penpot.app/) space by asking and answering questions; reacting to others’ articles; opening your own conversations and following along on decisions affecting the project.
|
||||||
- Report bugs with our easy [guide for bugs hunting](https://help.penpot.app/contributing-guide/reporting-bugs/) or [GitHub issues](https://github.com/penpot/penpot/issues)
|
- Report bugs with our easy [guide for bugs hunting](https://help.penpot.app/contributing-guide/reporting-bugs/) or [GitHub issues](https://github.com/penpot/penpot/issues).
|
||||||
- Become a [translator](https://help.penpot.app/contributing-guide/translations)
|
- Become a [translator](https://help.penpot.app/contributing-guide/translations).
|
||||||
- Give feedback: [Email us](mailto:support@penpot.app)
|
- Give feedback: [Email us](mailto:support@penpot.app).
|
||||||
- **Contribute to Penpot's code:** [Watch this video](https://www.youtube.com/watch?v=TpN0osiY-8k) by Alejandro Alonso, CIO and developer at Penpot, where he gives us a hands-on demo of how to use Penpot’s repository and make changes in both front and back end
|
- **Contribute to Penpot's code:** [Watch this video](https://www.youtube.com/watch?v=TpN0osiY-8k) by Alejandro Alonso, CIO and developer at Penpot, where he gives us a hands-on demo of how to use Penpot’s repository and make changes in both front and back end.
|
||||||
|
|
||||||
To find (almost) everything you need to know on how to contribute to Penpot, refer to the [contributing guide](https://help.penpot.app/contributing-guide/).
|
To find (almost) everything you need to know on how to contribute to Penpot, refer to the [contributing guide](https://help.penpot.app/contributing-guide/).
|
||||||
|
|
||||||
<br />
|
<img width="100%" alt="Penpot hub" src="https://github.com/user-attachments/assets/0abc02f0-625c-45ab-ad81-4927bec7a055" />
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
<img src="https://github.com/penpot/penpot/assets/5446186/fea18923-dc06-49be-86ad-c3496a7956e6" alt="Libraries and templates" style="width: 65%;">
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<br />
|
|
||||||
|
|
||||||
## Resources ##
|
## Resources ##
|
||||||
|
|
||||||
@ -170,6 +150,8 @@ You can ask and answer questions, have open-ended conversations, and follow alon
|
|||||||
|
|
||||||
📚 [Dev Diaries](https://penpot.app/dev-diaries.html)
|
📚 [Dev Diaries](https://penpot.app/dev-diaries.html)
|
||||||
|
|
||||||
|
🧑🏫 [UI Design Course](https://penpot.app/courses/)
|
||||||
|
|
||||||
|
|
||||||
## License ##
|
## License ##
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,10 @@ Redis for messaging/caching.
|
|||||||
## General Guidelines
|
## General Guidelines
|
||||||
|
|
||||||
To ensure consistency across the Penpot JVM stack, all contributions must adhere
|
To ensure consistency across the Penpot JVM stack, all contributions must adhere
|
||||||
to these criteria:
|
to these criteria.
|
||||||
|
|
||||||
|
IMPORTANT: all CLI commands should be executed under backend/
|
||||||
|
subdirectory for make them work correctly.
|
||||||
|
|
||||||
### 1. Testing & Validation
|
### 1. Testing & Validation
|
||||||
|
|
||||||
@ -21,7 +24,7 @@ to these criteria:
|
|||||||
|
|
||||||
### 2. Code Quality & Formatting
|
### 2. Code Quality & Formatting
|
||||||
|
|
||||||
* **Linting:** All code must pass `clj-kondo` checks (run `pnpm run lint:clj`)
|
* **Linting:** All code must pass linter checks (run `pnpm run lint:clj` or `pnpm run lint` on the repository root)
|
||||||
* **Formatting:** All the code must pass the formatting check (run `pnpm run
|
* **Formatting:** All the code must pass the formatting check (run `pnpm run
|
||||||
check-fmt`). Use `pnpm run fmt` to fix formatting issues. Avoid "dirty"
|
check-fmt`). Use `pnpm run fmt` to fix formatting issues. Avoid "dirty"
|
||||||
diffs caused by unrelated whitespace changes.
|
diffs caused by unrelated whitespace changes.
|
||||||
@ -83,7 +86,52 @@ are config maps with `::ig/ref` for dependencies. Components implement
|
|||||||
`ig/init-key` / `ig/halt-key!`.
|
`ig/init-key` / `ig/halt-key!`.
|
||||||
|
|
||||||
|
|
||||||
### Database Access
|
### Connecting to the Database
|
||||||
|
|
||||||
|
Two PostgreSQL databases are used in this environment:
|
||||||
|
|
||||||
|
| Database | Purpose | Connection string |
|
||||||
|
|---------------|--------------------|----------------------------------------------------|
|
||||||
|
| `penpot` | Development / app | `postgresql://penpot:penpot@postgres/penpot` |
|
||||||
|
| `penpot_test` | Test suite | `postgresql://penpot:penpot@postgres/penpot_test` |
|
||||||
|
|
||||||
|
**Interactive psql session:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# development DB
|
||||||
|
psql "postgresql://penpot:penpot@postgres/penpot"
|
||||||
|
|
||||||
|
# test DB
|
||||||
|
psql "postgresql://penpot:penpot@postgres/penpot_test"
|
||||||
|
```
|
||||||
|
|
||||||
|
**One-shot query (non-interactive):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
psql "postgresql://penpot:penpot@postgres/penpot" -c "SELECT id, name FROM team LIMIT 5;"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Useful psql meta-commands:**
|
||||||
|
|
||||||
|
```
|
||||||
|
\dt -- list all tables
|
||||||
|
\d <table> -- describe a table (columns, types, constraints)
|
||||||
|
\di -- list indexes
|
||||||
|
\q -- quit
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Migrations table:** Applied migrations are tracked in the `migrations` table
|
||||||
|
> with columns `module`, `step`, and `created_at`. When renaming a migration
|
||||||
|
> logical name, update this table in both databases to match the new name;
|
||||||
|
> otherwise the runner will attempt to re-apply the migration on next startup.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Example: fix a renamed migration entry in the test DB
|
||||||
|
psql "postgresql://penpot:penpot@postgres/penpot_test" \
|
||||||
|
-c "UPDATE migrations SET step = 'new-name' WHERE step = 'old-name';"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Database Access (Clojure)
|
||||||
|
|
||||||
`app.db` wraps next.jdbc. Queries use a SQL builder that auto-converts kebab-case ↔ snake_case.
|
`app.db` wraps next.jdbc. Queries use a SQL builder that auto-converts kebab-case ↔ snake_case.
|
||||||
|
|
||||||
@ -146,3 +194,69 @@ optimized implementations:
|
|||||||
`src/app/config.clj` reads `PENPOT_*` environment variables, validated with
|
`src/app/config.clj` reads `PENPOT_*` environment variables, validated with
|
||||||
Malli. Access anywhere via `(cf/get :smtp-host)`. Feature flags: `(cf/flags
|
Malli. Access anywhere via `(cf/get :smtp-host)`. Feature flags: `(cf/flags
|
||||||
:enable-smtp)`.
|
:enable-smtp)`.
|
||||||
|
|
||||||
|
|
||||||
|
### Background Tasks
|
||||||
|
|
||||||
|
Background tasks live in `src/app/tasks/`. Each task is an Integrant component
|
||||||
|
that exposes a `::handler` key and follows this three-method pattern:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
(defmethod ig/assert-key ::handler ;; validate config at startup
|
||||||
|
[_ params]
|
||||||
|
(assert (db/pool? (::db/pool params)) "expected a valid database pool"))
|
||||||
|
|
||||||
|
(defmethod ig/expand-key ::handler ;; inject defaults before init
|
||||||
|
[k v]
|
||||||
|
{k (assoc v ::my-option default-value)})
|
||||||
|
|
||||||
|
(defmethod ig/init-key ::handler ;; return the task fn
|
||||||
|
[_ cfg]
|
||||||
|
(fn [_task] ;; receives the task row from the worker
|
||||||
|
(db/tx-run! cfg (fn [{:keys [::db/conn]}]
|
||||||
|
;; … do work …
|
||||||
|
))))
|
||||||
|
```
|
||||||
|
|
||||||
|
**Wiring a new task** requires two changes in `src/app/main.clj`:
|
||||||
|
|
||||||
|
1. **Handler config** – add an entry in `system-config` with the dependencies:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
:app.tasks.my-task/handler
|
||||||
|
{::db/pool (ig/ref ::db/pool)}
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Registry + cron** – register the handler name and schedule it:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
;; in ::wrk/registry ::wrk/tasks map:
|
||||||
|
:my-task (ig/ref :app.tasks.my-task/handler)
|
||||||
|
|
||||||
|
;; in worker-config ::wrk/cron ::wrk/entries vector:
|
||||||
|
{:cron #penpot/cron "0 0 0 * * ?" ;; daily at midnight
|
||||||
|
:task :my-task}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Useful cron patterns** (Quartz format — six fields: s m h dom mon dow):
|
||||||
|
|
||||||
|
| Expression | Meaning |
|
||||||
|
|------------------------------|--------------------|
|
||||||
|
| `"0 0 0 * * ?"` | Daily at midnight |
|
||||||
|
| `"0 0 */6 * * ?"` | Every 6 hours |
|
||||||
|
| `"0 */5 * * * ?"` | Every 5 minutes |
|
||||||
|
|
||||||
|
**Time helpers** (`app.common.time`):
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
(ct/now) ;; current instant
|
||||||
|
(ct/duration {:hours 1}) ;; java.time.Duration
|
||||||
|
(ct/minus (ct/now) some-duration) ;; subtract duration from instant
|
||||||
|
```
|
||||||
|
|
||||||
|
`db/interval` converts a `Duration` (or millis / string) to a PostgreSQL
|
||||||
|
interval object suitable for use in SQL queries:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
(db/interval (ct/duration {:hours 1})) ;; → PGInterval "3600.0 seconds"
|
||||||
|
```
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"author": "Kaleidos INC",
|
"author": "Kaleidos INC",
|
||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "pnpm@10.26.2+sha512.0e308ff2005fc7410366f154f625f6631ab2b16b1d2e70238444dd6ae9d630a8482d92a451144debc492416896ed16f7b114a86ec68b8404b2443869e68ffda6",
|
"packageManager": "pnpm@10.31.0+sha512.e3927388bfaa8078ceb79b748ffc1e8274e84d75163e67bc22e06c0d3aed43dd153151cbf11d7f8301ff4acb98c68bdc5cadf6989532801ffafe3b3e4a63c268",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/penpot/penpot"
|
"url": "https://github.com/penpot/penpot"
|
||||||
|
|||||||
264
backend/resources/app/email/invite-to-org/en.html
Normal file
264
backend/resources/app/email/invite-to-org/en.html
Normal file
@ -0,0 +1,264 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"
|
||||||
|
xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>
|
||||||
|
</title>
|
||||||
|
<!--[if !mso]><!-- -->
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<!--<![endif]-->
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<style type="text/css">
|
||||||
|
#outlook a {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
table,
|
||||||
|
td {
|
||||||
|
border-collapse: collapse;
|
||||||
|
mso-table-lspace: 0pt;
|
||||||
|
mso-table-rspace: 0pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
border: 0;
|
||||||
|
height: auto;
|
||||||
|
line-height: 100%;
|
||||||
|
outline: none;
|
||||||
|
text-decoration: none;
|
||||||
|
-ms-interpolation-mode: bicubic;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
display: block;
|
||||||
|
margin: 13px 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<!--[if mso]>
|
||||||
|
<xml>
|
||||||
|
<o:OfficeDocumentSettings>
|
||||||
|
<o:AllowPNG/>
|
||||||
|
<o:PixelsPerInch>96</o:PixelsPerInch>
|
||||||
|
</o:OfficeDocumentSettings>
|
||||||
|
</xml>
|
||||||
|
<![endif]-->
|
||||||
|
<!--[if lte mso 11]>
|
||||||
|
<style type="text/css">
|
||||||
|
.mj-outlook-group-fix { width:100% !important; }
|
||||||
|
</style>
|
||||||
|
<![endif]-->
|
||||||
|
<!--[if !mso]><!-->
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Source%20Sans%20Pro" rel="stylesheet" type="text/css">
|
||||||
|
<style type="text/css">
|
||||||
|
@import url(https://fonts.googleapis.com/css?family=Source%20Sans%20Pro);
|
||||||
|
</style>
|
||||||
|
<!--<![endif]-->
|
||||||
|
<style type="text/css">
|
||||||
|
@media only screen and (min-width:480px) {
|
||||||
|
.mj-column-per-100 {
|
||||||
|
width: 100% !important;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mj-column-px-425 {
|
||||||
|
width: 425px !important;
|
||||||
|
max-width: 425px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<style type="text/css">
|
||||||
|
@media only screen and (max-width:480px) {
|
||||||
|
table.mj-full-width-mobile {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.mj-full-width-mobile {
|
||||||
|
width: auto !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body style="background-color:#E5E5E5;">
|
||||||
|
<div style="background-color:#E5E5E5;">
|
||||||
|
<!--[if mso | IE]>
|
||||||
|
<table
|
||||||
|
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
|
||||||
|
>
|
||||||
|
<tr>
|
||||||
|
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
|
||||||
|
<![endif]-->
|
||||||
|
<div style="margin:0px auto;max-width:600px;">
|
||||||
|
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td style="direction:ltr;font-size:0px;padding:0;text-align:center;">
|
||||||
|
<!--[if mso | IE]>
|
||||||
|
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
|
||||||
|
<td
|
||||||
|
class="" style="vertical-align:top;width:600px;"
|
||||||
|
>
|
||||||
|
<![endif]-->
|
||||||
|
<div class="mj-column-per-100 mj-outlook-group-fix"
|
||||||
|
style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"
|
||||||
|
width="100%">
|
||||||
|
<tr>
|
||||||
|
<td align="left" style="font-size:0px;padding:16px;word-break:break-word;">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" role="presentation"
|
||||||
|
style="border-collapse:collapse;border-spacing:0px;">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td style="width:97px;">
|
||||||
|
<img height="32" src="{{ public-uri }}/images/email/uxbox-title.png"
|
||||||
|
style="border:0;display:block;outline:none;text-decoration:none;height:32px;width:100%;font-size:13px;"
|
||||||
|
width="97" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!--[if mso | IE]>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!--[if mso | IE]>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table
|
||||||
|
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
|
||||||
|
>
|
||||||
|
<tr>
|
||||||
|
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
|
||||||
|
<![endif]-->
|
||||||
|
<div style="background:#FFFFFF;background-color:#FFFFFF;margin:0px auto;max-width:600px;">
|
||||||
|
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation"
|
||||||
|
style="background:#FFFFFF;background-color:#FFFFFF;width:100%;">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
|
||||||
|
<!--[if mso | IE]>
|
||||||
|
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
|
||||||
|
<td
|
||||||
|
class="" style="vertical-align:top;width:600px;"
|
||||||
|
>
|
||||||
|
<![endif]-->
|
||||||
|
<div class="mj-column-per-100 mj-outlook-group-fix"
|
||||||
|
style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"
|
||||||
|
width="100%">
|
||||||
|
<tr>
|
||||||
|
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||||
|
<div
|
||||||
|
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||||
|
Hi{% if user-name %} {{ user-name|abbreviate:25 }}{% endif %},
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||||
|
<div
|
||||||
|
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||||
|
<b>{{invited-by|abbreviate:25}}</b> sent you an invitation to join the organization:
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||||
|
<div
|
||||||
|
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||||
|
<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="20" height="20" style="display:inline-block;vertical-align:middle;">
|
||||||
|
<tr>
|
||||||
|
<td width="20" height="20" align="center" valign="middle"
|
||||||
|
background="{{organization-logo}}"
|
||||||
|
style="width:20px;height:20px;text-align:center;font-weight:bold;font-size:9px;line-height:20px;color:#ffffff;background-size:cover;background-position:center;background-repeat:no-repeat;border-radius: 50%;color:black">
|
||||||
|
{% if organization-initials %}{{organization-initials}}{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<span style="display:inline-block; vertical-align: middle;padding-left:5px;height:20px;line-height: 20px;">
|
||||||
|
“{{ organization-name|abbreviate:25 }}”
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center" vertical-align="middle"
|
||||||
|
style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" role="presentation"
|
||||||
|
style="border-collapse:separate;line-height:100%;">
|
||||||
|
<tr>
|
||||||
|
<td align="center" bgcolor="#6911d4" role="presentation"
|
||||||
|
style="border:none;border-radius:8px;cursor:auto;mso-padding-alt:10px 25px;background:#6911d4;"
|
||||||
|
valign="middle">
|
||||||
|
<a href="{{ public-uri }}/#/auth/verify-token?token={{token}}"
|
||||||
|
style="display:inline-block;background:#6911d4;color:#FFFFFF;font-family:Source Sans Pro, sans-serif;font-size:16px;font-weight:normal;line-height:120%;margin:0;text-decoration:none;text-transform:none;padding:10px 25px;mso-padding-alt:0px;border-radius:8px;"
|
||||||
|
target="_blank"> ACCEPT INVITE </a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||||
|
<div
|
||||||
|
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||||
|
Enjoy!</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||||
|
<div
|
||||||
|
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||||
|
The Penpot team.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!--[if mso | IE]>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% include "app/email/includes/footer.html" %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
1
backend/resources/app/email/invite-to-org/en.subj
Normal file
1
backend/resources/app/email/invite-to-org/en.subj
Normal file
@ -0,0 +1 @@
|
|||||||
|
{{invited-by|abbreviate:25}} has invited you to join the organization “{{ organization-name|abbreviate:25 }}”
|
||||||
10
backend/resources/app/email/invite-to-org/en.txt
Normal file
10
backend/resources/app/email/invite-to-org/en.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Hello!
|
||||||
|
|
||||||
|
{{invited-by|abbreviate:25}} has invited you to join the organization “{{ organization-name|abbreviate:25 }}”.
|
||||||
|
|
||||||
|
Accept invitation using this link:
|
||||||
|
|
||||||
|
{{ public-uri }}/#/auth/verify-token?token={{token}}
|
||||||
|
|
||||||
|
Enjoy!
|
||||||
|
The Penpot team.
|
||||||
@ -186,7 +186,8 @@
|
|||||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||||
<div
|
<div
|
||||||
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||||
{{invited-by|abbreviate:25}} has invited you to join the team “{{ team|abbreviate:25 }}”.</div>
|
{{invited-by|abbreviate:25}} has invited you to join the team “{{ team|abbreviate:25 }}”{% if organization %}
|
||||||
|
part of the organization “{{ organization|abbreviate:25 }}”{% endif %}.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
Hello!
|
Hello!
|
||||||
|
|
||||||
{{invited-by|abbreviate:25}} has invited you to join the team “{{ team|abbreviate:25 }}”.
|
{{invited-by|abbreviate:25}} has invited you to join the team "{{ team|abbreviate:25 }}"{% if organization %}, part of the organization "{{ organization|abbreviate:25 }}"{% endif %}.
|
||||||
|
|
||||||
Accept invitation using this link:
|
Accept invitation using this link:
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
export PENPOT_NITRATE_SHARED_KEY=super-secret-nitrate-api-key
|
export PENPOT_NITRATE_SHARED_KEY=super-secret-nitrate-api-key
|
||||||
export PENPOT_EXPORTER_SHARED_KEY=super-secret-exporter-api-key
|
export PENPOT_EXPORTER_SHARED_KEY=super-secret-exporter-api-key
|
||||||
|
export PENPOT_NEXUS_SHARED_KEY=super-secret-nexus-api-key
|
||||||
export PENPOT_SECRET_KEY=super-secret-devenv-key
|
export PENPOT_SECRET_KEY=super-secret-devenv-key
|
||||||
|
|
||||||
# DEPRECATED: only used for subscriptions
|
# DEPRECATED: only used for subscriptions
|
||||||
|
|||||||
@ -111,7 +111,7 @@
|
|||||||
[:host {:optional true} :string]
|
[:host {:optional true} :string]
|
||||||
[:port {:optional true} ::sm/int]
|
[:port {:optional true} ::sm/int]
|
||||||
[:bind-dn {:optional true} :string]
|
[:bind-dn {:optional true} :string]
|
||||||
[:bind-passwor {:optional true} :string]
|
[:bind-password {:optional true} :string]
|
||||||
[:query {:optional true} :string]
|
[:query {:optional true} :string]
|
||||||
[:base-dn {:optional true} :string]
|
[:base-dn {:optional true} :string]
|
||||||
[:attrs-email {:optional true} :string]
|
[:attrs-email {:optional true} :string]
|
||||||
|
|||||||
@ -43,7 +43,7 @@
|
|||||||
(defn- discover-oidc-config
|
(defn- discover-oidc-config
|
||||||
[cfg {:keys [base-uri] :as provider}]
|
[cfg {:keys [base-uri] :as provider}]
|
||||||
(let [uri (u/join base-uri ".well-known/openid-configuration")
|
(let [uri (u/join base-uri ".well-known/openid-configuration")
|
||||||
rsp (http/req! cfg {:method :get :uri (dm/str uri)})]
|
rsp (http/req cfg {:method :get :uri (dm/str uri)})]
|
||||||
|
|
||||||
(if (= 200 (:status rsp))
|
(if (= 200 (:status rsp))
|
||||||
(let [data (-> rsp :body json/decode)
|
(let [data (-> rsp :body json/decode)
|
||||||
@ -105,7 +105,7 @@
|
|||||||
|
|
||||||
(defn- fetch-oidc-jwks
|
(defn- fetch-oidc-jwks
|
||||||
[cfg jwks-uri]
|
[cfg jwks-uri]
|
||||||
(let [{:keys [status body]} (http/req! cfg {:method :get :uri jwks-uri})]
|
(let [{:keys [status body]} (http/req cfg {:method :get :uri jwks-uri})]
|
||||||
(if (= 200 status)
|
(if (= 200 status)
|
||||||
(-> body json/decode :keys process-oidc-jwks)
|
(-> body json/decode :keys process-oidc-jwks)
|
||||||
(ex/raise :type ::internal
|
(ex/raise :type ::internal
|
||||||
@ -235,7 +235,7 @@
|
|||||||
:timeout 6000
|
:timeout 6000
|
||||||
:method :get}
|
:method :get}
|
||||||
|
|
||||||
{:keys [status body]} (http/req! cfg params)]
|
{:keys [status body]} (http/req cfg params)]
|
||||||
|
|
||||||
(when-not (int-in-range? status 200 300)
|
(when-not (int-in-range? status 200 300)
|
||||||
(ex/raise :type :internal
|
(ex/raise :type :internal
|
||||||
@ -401,8 +401,9 @@
|
|||||||
|
|
||||||
(defn- parse-attr-path
|
(defn- parse-attr-path
|
||||||
[provider path]
|
[provider path]
|
||||||
(let [[fitem & items] (str/split path "__")]
|
(let [separator (if (str/includes? path "__") "__" ".")
|
||||||
(into [(keyword (:type provider) fitem)] (map keyword) items)))
|
[fitem & items] (str/split path separator)]
|
||||||
|
(into [(keyword (:type provider) (str/kebab fitem))] (map keyword) items)))
|
||||||
|
|
||||||
(defn- build-redirect-uri
|
(defn- build-redirect-uri
|
||||||
[]
|
[]
|
||||||
@ -452,7 +453,7 @@
|
|||||||
:grant-type (:grant_type params)
|
:grant-type (:grant_type params)
|
||||||
:redirect-uri (:redirect_uri params))
|
:redirect-uri (:redirect_uri params))
|
||||||
|
|
||||||
(let [{:keys [status body]} (http/req! cfg req)]
|
(let [{:keys [status body]} (http/req cfg req)]
|
||||||
(if (= status 200)
|
(if (= status 200)
|
||||||
(let [data (json/decode body)
|
(let [data (json/decode body)
|
||||||
data {:token/access (get data :access_token)
|
data {:token/access (get data :access_token)
|
||||||
@ -507,7 +508,7 @@
|
|||||||
:headers {"Authorization" (str (:token/type tdata) " " (:token/access tdata))}
|
:headers {"Authorization" (str (:token/type tdata) " " (:token/access tdata))}
|
||||||
:timeout 6000
|
:timeout 6000
|
||||||
:method :get}
|
:method :get}
|
||||||
response (http/req! cfg params)]
|
response (http/req cfg params)]
|
||||||
|
|
||||||
(l/trc :hint "user info response"
|
(l/trc :hint "user info response"
|
||||||
:status (:status response)
|
:status (:status response)
|
||||||
@ -547,15 +548,28 @@
|
|||||||
(def ^:private valid-info?
|
(def ^:private valid-info?
|
||||||
(sm/validator schema:info))
|
(sm/validator schema:info))
|
||||||
|
|
||||||
|
(defn- select-user-info-source
|
||||||
|
"Normalise the provider's configured user-info source into a keyword the
|
||||||
|
dispatch below can match. The raw value comes from config as a string
|
||||||
|
per the malli schema in `app.config` (`\"token\"`, `\"userinfo\"`, or
|
||||||
|
`\"auto\"`) and from hard-coded per-provider maps as strings as well;
|
||||||
|
any unrecognised or missing value falls back to `:auto` (prefer claims,
|
||||||
|
use userinfo as fallback)."
|
||||||
|
[source]
|
||||||
|
(case source
|
||||||
|
"token" :token
|
||||||
|
"userinfo" :userinfo
|
||||||
|
:auto))
|
||||||
|
|
||||||
(defn- get-info
|
(defn- get-info
|
||||||
[cfg provider state code]
|
[cfg provider state code]
|
||||||
(let [tdata (fetch-access-token cfg provider code)
|
(let [tdata (fetch-access-token cfg provider code)
|
||||||
claims (get-id-token-claims provider tdata)
|
claims (get-id-token-claims provider tdata)
|
||||||
|
|
||||||
info (case (get provider :user-info-source)
|
info (case (select-user-info-source (get provider :user-info-source))
|
||||||
:token (dissoc claims :exp :iss :iat :aud :sub :sid)
|
:token (dissoc claims :exp :iss :iat :aud :sid)
|
||||||
:userinfo (fetch-user-info cfg provider tdata)
|
:userinfo (fetch-user-info cfg provider tdata)
|
||||||
(or (some-> claims (dissoc :exp :iss :iat :aud :sub :sid))
|
:auto (or (some-> claims (dissoc :exp :iss :iat :aud :sid))
|
||||||
(fetch-user-info cfg provider tdata)))
|
(fetch-user-info cfg provider tdata)))
|
||||||
|
|
||||||
info (process-user-info provider tdata info)]
|
info (process-user-info provider tdata info)]
|
||||||
@ -804,12 +818,12 @@
|
|||||||
props (audit/profile->props profile)
|
props (audit/profile->props profile)
|
||||||
context (d/without-nils {:external-session-id (:external-session-id info)})]
|
context (d/without-nils {:external-session-id (:external-session-id info)})]
|
||||||
|
|
||||||
(audit/submit! cfg {::audit/type "action"
|
(audit/submit cfg {:type "action"
|
||||||
::audit/name "login-with-oidc"
|
:name "login-with-oidc"
|
||||||
::audit/profile-id (:id profile)
|
:profile-id (:id profile)
|
||||||
::audit/ip-addr (inet/parse-request request)
|
:ip-addr (inet/parse-request request)
|
||||||
::audit/props props
|
:props props
|
||||||
::audit/context context})
|
:context context})
|
||||||
|
|
||||||
(->> (redirect-to-verify-token token)
|
(->> (redirect-to-verify-token token)
|
||||||
(sxf request)))))
|
(sxf request)))))
|
||||||
|
|||||||
@ -315,8 +315,8 @@
|
|||||||
(defn get-file
|
(defn get-file
|
||||||
"Get file, resolve all features and apply migrations.
|
"Get file, resolve all features and apply migrations.
|
||||||
|
|
||||||
Usefull when you have plan to apply massive or not cirurgical
|
Useful when you have plan to apply massive or not surgical
|
||||||
operations on file, because it removes the ovehead of lazy fetching
|
operations on file, because it removes the overhead of lazy fetching
|
||||||
and decoding."
|
and decoding."
|
||||||
[cfg file-id & {:as opts}]
|
[cfg file-id & {:as opts}]
|
||||||
(db/run! cfg get-file* file-id opts))
|
(db/run! cfg get-file* file-id opts))
|
||||||
|
|||||||
@ -281,7 +281,7 @@
|
|||||||
|
|
||||||
thumbnails (bfc/get-file-object-thumbnails cfg file-id)]
|
thumbnails (bfc/get-file-object-thumbnails cfg file-id)]
|
||||||
|
|
||||||
(events/tap :progress {:section :file :id file-id})
|
(events/tap :progress {:section :file :id file-id :name (:name file)})
|
||||||
|
|
||||||
(vswap! bfc/*state* update :files assoc file-id
|
(vswap! bfc/*state* update :files assoc file-id
|
||||||
{:id file-id
|
{:id file-id
|
||||||
@ -301,6 +301,7 @@
|
|||||||
(write-entry! output path file))
|
(write-entry! output path file))
|
||||||
|
|
||||||
(doseq [[index page-id] (d/enumerate pages)]
|
(doseq [[index page-id] (d/enumerate pages)]
|
||||||
|
|
||||||
(let [path (str "files/" file-id "/pages/" page-id ".json")
|
(let [path (str "files/" file-id "/pages/" page-id ".json")
|
||||||
page (get pages-index page-id)
|
page (get pages-index page-id)
|
||||||
objects (:objects page)
|
objects (:objects page)
|
||||||
@ -311,6 +312,8 @@
|
|||||||
|
|
||||||
(write-entry! output path page)
|
(write-entry! output path page)
|
||||||
|
|
||||||
|
(events/tap :progress {:section :page :id page-id :name (:name page) :file-id file-id})
|
||||||
|
|
||||||
(doseq [[shape-id shape] objects]
|
(doseq [[shape-id shape] objects]
|
||||||
(let [path (str "files/" file-id "/pages/" page-id "/" shape-id ".json")
|
(let [path (str "files/" file-id "/pages/" page-id "/" shape-id ".json")
|
||||||
shape (assoc shape :page-id page-id)
|
shape (assoc shape :page-id page-id)
|
||||||
@ -323,6 +326,8 @@
|
|||||||
(doseq [{:keys [id] :as media} media]
|
(doseq [{:keys [id] :as media} media]
|
||||||
(let [path (str "files/" file-id "/media/" id ".json")
|
(let [path (str "files/" file-id "/media/" id ".json")
|
||||||
media (encode-media media)]
|
media (encode-media media)]
|
||||||
|
|
||||||
|
(events/tap :progress {:section :media :id id :file-id file-id})
|
||||||
(write-entry! output path media)))
|
(write-entry! output path media)))
|
||||||
|
|
||||||
(doseq [thumbnail thumbnails]
|
(doseq [thumbnail thumbnails]
|
||||||
@ -332,11 +337,13 @@
|
|||||||
data (-> data
|
data (-> data
|
||||||
(assoc :media-id (:media-id thumbnail))
|
(assoc :media-id (:media-id thumbnail))
|
||||||
(encode-file-thumbnail))]
|
(encode-file-thumbnail))]
|
||||||
|
(events/tap :progress {:section :thumbnails :id (:object-id thumbnail) :file-id file-id})
|
||||||
(write-entry! output path data)))
|
(write-entry! output path data)))
|
||||||
|
|
||||||
(doseq [[id component] components]
|
(doseq [[id component] components]
|
||||||
(let [path (str "files/" file-id "/components/" id ".json")
|
(let [path (str "files/" file-id "/components/" id ".json")
|
||||||
component (encode-component component)]
|
component (encode-component component)]
|
||||||
|
(events/tap :progress {:section :component :id id :file-id file-id})
|
||||||
(write-entry! output path component)))
|
(write-entry! output path component)))
|
||||||
|
|
||||||
(doseq [[id color] colors]
|
(doseq [[id color] colors]
|
||||||
@ -347,17 +354,20 @@
|
|||||||
(and (contains? color :path)
|
(and (contains? color :path)
|
||||||
(str/empty? (:path color)))
|
(str/empty? (:path color)))
|
||||||
(dissoc :path))]
|
(dissoc :path))]
|
||||||
|
(events/tap :progress {:section :color :id id :file-id file-id})
|
||||||
(write-entry! output path color)))
|
(write-entry! output path color)))
|
||||||
|
|
||||||
(doseq [[id object] typographies]
|
(doseq [[id object] typographies]
|
||||||
(let [path (str "files/" file-id "/typographies/" id ".json")
|
(let [path (str "files/" file-id "/typographies/" id ".json")
|
||||||
typography (encode-typography object)]
|
typography (encode-typography object)]
|
||||||
|
(events/tap :progress {:section :typography :id id :file-id file-id})
|
||||||
(write-entry! output path typography)))
|
(write-entry! output path typography)))
|
||||||
|
|
||||||
(when (and tokens-lib
|
(when (and tokens-lib
|
||||||
(not (ctob/empty-lib? tokens-lib)))
|
(not (ctob/empty-lib? tokens-lib)))
|
||||||
(let [path (str "files/" file-id "/tokens.json")
|
(let [path (str "files/" file-id "/tokens.json")
|
||||||
encoded-tokens (encode-tokens-lib tokens-lib)]
|
encoded-tokens (encode-tokens-lib tokens-lib)]
|
||||||
|
(events/tap :progress {:section :tokens-lib :file-id file-id})
|
||||||
(write-entry! output path encoded-tokens)))))
|
(write-entry! output path encoded-tokens)))))
|
||||||
|
|
||||||
(defn- export-files
|
(defn- export-files
|
||||||
@ -600,6 +610,7 @@
|
|||||||
(let [object (->> (read-entry input entry)
|
(let [object (->> (read-entry input entry)
|
||||||
(decode-color)
|
(decode-color)
|
||||||
(validate-color))]
|
(validate-color))]
|
||||||
|
(events/tap :progress {:section :color :id id :file-id file-id})
|
||||||
(if (= id (:id object))
|
(if (= id (:id object))
|
||||||
(assoc result id object)
|
(assoc result id object)
|
||||||
result)))
|
result)))
|
||||||
@ -631,6 +642,7 @@
|
|||||||
(clean-component-pre-decode)
|
(clean-component-pre-decode)
|
||||||
(decode-component)
|
(decode-component)
|
||||||
(clean-component-post-decode))]
|
(clean-component-post-decode))]
|
||||||
|
(events/tap :progress {:section :component :id id :file-id file-id})
|
||||||
(if (= id (:id object))
|
(if (= id (:id object))
|
||||||
(assoc result id object)
|
(assoc result id object)
|
||||||
result)))
|
result)))
|
||||||
@ -644,6 +656,7 @@
|
|||||||
(let [object (->> (read-entry input entry)
|
(let [object (->> (read-entry input entry)
|
||||||
(decode-typography)
|
(decode-typography)
|
||||||
(validate-typography))]
|
(validate-typography))]
|
||||||
|
(events/tap :progress {:section :typography :id id :file-id file-id})
|
||||||
(if (= id (:id object))
|
(if (= id (:id object))
|
||||||
(assoc result id object)
|
(assoc result id object)
|
||||||
result)))
|
result)))
|
||||||
@ -653,6 +666,7 @@
|
|||||||
(defn- read-file-tokens-lib
|
(defn- read-file-tokens-lib
|
||||||
[{:keys [::bfc/input ::entries]} file-id]
|
[{:keys [::bfc/input ::entries]} file-id]
|
||||||
(when-let [entry (d/seek (match-tokens-lib-entry-fn file-id) entries)]
|
(when-let [entry (d/seek (match-tokens-lib-entry-fn file-id) entries)]
|
||||||
|
(events/tap :progress {:section :tokens-lib :file-id file-id})
|
||||||
(->> (read-plain-entry input entry)
|
(->> (read-plain-entry input entry)
|
||||||
(decode-tokens-lib)
|
(decode-tokens-lib)
|
||||||
(validate-tokens-lib))))
|
(validate-tokens-lib))))
|
||||||
@ -678,6 +692,7 @@
|
|||||||
(let [page (->> (read-entry input entry)
|
(let [page (->> (read-entry input entry)
|
||||||
(decode-page))
|
(decode-page))
|
||||||
page (dissoc page :options)]
|
page (dissoc page :options)]
|
||||||
|
(events/tap :progress {:section :page :id id :file-id file-id})
|
||||||
(when (= id (:id page))
|
(when (= id (:id page))
|
||||||
(let [objects (read-file-shapes cfg file-id id)]
|
(let [objects (read-file-shapes cfg file-id id)]
|
||||||
(assoc page :objects objects))))))
|
(assoc page :objects objects))))))
|
||||||
@ -693,6 +708,7 @@
|
|||||||
(let [object (->> (read-entry input entry)
|
(let [object (->> (read-entry input entry)
|
||||||
(decode-file-thumbnail)
|
(decode-file-thumbnail)
|
||||||
(validate-file-thumbnail))]
|
(validate-file-thumbnail))]
|
||||||
|
|
||||||
(if (and (= frame-id (:frame-id object))
|
(if (and (= frame-id (:frame-id object))
|
||||||
(= page-id (:page-id object))
|
(= page-id (:page-id object))
|
||||||
(= tag (:tag object)))
|
(= tag (:tag object)))
|
||||||
@ -733,8 +749,6 @@
|
|||||||
|
|
||||||
(vswap! bfc/*state* update :index bfc/update-index media :id)
|
(vswap! bfc/*state* update :index bfc/update-index media :id)
|
||||||
|
|
||||||
(events/tap :progress {:section :media :file-id file-id})
|
|
||||||
|
|
||||||
(doseq [item media]
|
(doseq [item media]
|
||||||
(let [params (-> item
|
(let [params (-> item
|
||||||
(update :id bfc/lookup-index)
|
(update :id bfc/lookup-index)
|
||||||
@ -742,6 +756,8 @@
|
|||||||
(d/update-when :media-id bfc/lookup-index)
|
(d/update-when :media-id bfc/lookup-index)
|
||||||
(d/update-when :thumbnail-id bfc/lookup-index))]
|
(d/update-when :thumbnail-id bfc/lookup-index))]
|
||||||
|
|
||||||
|
(events/tap :progress {:section :media :id (:id params) :file-id file-id})
|
||||||
|
|
||||||
(l/dbg :hint "inserting media object"
|
(l/dbg :hint "inserting media object"
|
||||||
:file-id (str file-id')
|
:file-id (str file-id')
|
||||||
:id (str (:id params))
|
:id (str (:id params))
|
||||||
@ -753,8 +769,6 @@
|
|||||||
(db/insert! conn :file-media-object params
|
(db/insert! conn :file-media-object params
|
||||||
::db/on-conflict-do-nothing? (::bfc/overwrite cfg))))
|
::db/on-conflict-do-nothing? (::bfc/overwrite cfg))))
|
||||||
|
|
||||||
(events/tap :progress {:section :thumbnails :file-id file-id})
|
|
||||||
|
|
||||||
(doseq [item thumbnails]
|
(doseq [item thumbnails]
|
||||||
(let [media-id (bfc/lookup-index (:media-id item))
|
(let [media-id (bfc/lookup-index (:media-id item))
|
||||||
object-id (-> (assoc item :file-id file-id')
|
object-id (-> (assoc item :file-id file-id')
|
||||||
@ -769,6 +783,8 @@
|
|||||||
:media-id (str media-id)
|
:media-id (str media-id)
|
||||||
::l/sync? true)
|
::l/sync? true)
|
||||||
|
|
||||||
|
(events/tap :progress {:section :thumbnail :file-id file-id :object-id object-id})
|
||||||
|
|
||||||
(db/insert! conn :file-tagged-object-thumbnail params
|
(db/insert! conn :file-tagged-object-thumbnail params
|
||||||
::db/on-conflict-do-nothing? true)))
|
::db/on-conflict-do-nothing? true)))
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,14 @@
|
|||||||
:initial-project-skey "initial-project"
|
:initial-project-skey "initial-project"
|
||||||
|
|
||||||
;; time to avoid email sending after profile modification
|
;; time to avoid email sending after profile modification
|
||||||
:email-verify-threshold "15m"})
|
:email-verify-threshold "15m"
|
||||||
|
|
||||||
|
:quotes-upload-sessions-per-profile 5
|
||||||
|
:quotes-upload-chunks-per-session 20
|
||||||
|
|
||||||
|
;; SSRF protection
|
||||||
|
:ssrf-allowed-hosts #{}
|
||||||
|
:ssrf-extra-blocked-cidrs #{}})
|
||||||
|
|
||||||
(def schema:config
|
(def schema:config
|
||||||
(do #_sm/optional-keys
|
(do #_sm/optional-keys
|
||||||
@ -103,6 +110,7 @@
|
|||||||
|
|
||||||
[:exporter-shared-key {:optional true} :string]
|
[:exporter-shared-key {:optional true} :string]
|
||||||
[:nitrate-shared-key {:optional true} :string]
|
[:nitrate-shared-key {:optional true} :string]
|
||||||
|
[:nexus-shared-key {:optional true} :string]
|
||||||
[:management-api-key {:optional true} :string]
|
[:management-api-key {:optional true} :string]
|
||||||
|
|
||||||
[:telemetry-uri {:optional true} :string]
|
[:telemetry-uri {:optional true} :string]
|
||||||
@ -153,6 +161,8 @@
|
|||||||
[:quotes-snapshots-per-team {:optional true} ::sm/int]
|
[:quotes-snapshots-per-team {:optional true} ::sm/int]
|
||||||
[:quotes-team-access-requests-per-team {:optional true} ::sm/int]
|
[:quotes-team-access-requests-per-team {:optional true} ::sm/int]
|
||||||
[:quotes-team-access-requests-per-requester {:optional true} ::sm/int]
|
[:quotes-team-access-requests-per-requester {:optional true} ::sm/int]
|
||||||
|
[:quotes-upload-sessions-per-profile {:optional true} ::sm/int]
|
||||||
|
[:quotes-upload-chunks-per-session {:optional true} ::sm/int]
|
||||||
|
|
||||||
[:auth-token-cookie-name {:optional true} :string]
|
[:auth-token-cookie-name {:optional true} :string]
|
||||||
[:auth-token-cookie-max-age {:optional true} ::ct/duration]
|
[:auth-token-cookie-max-age {:optional true} ::ct/duration]
|
||||||
@ -239,17 +249,26 @@
|
|||||||
[:objects-storage-fs-directory {:optional true} :string]
|
[:objects-storage-fs-directory {:optional true} :string]
|
||||||
[:objects-storage-s3-bucket {:optional true} :string]
|
[:objects-storage-s3-bucket {:optional true} :string]
|
||||||
[:objects-storage-s3-region {:optional true} :keyword]
|
[:objects-storage-s3-region {:optional true} :keyword]
|
||||||
[:objects-storage-s3-endpoint {:optional true} ::sm/uri]]))
|
[:objects-storage-s3-endpoint {:optional true} ::sm/uri]
|
||||||
|
|
||||||
|
;; SSRF protection
|
||||||
|
[:ssrf-allowed-hosts {:optional true} [::sm/set :string]]
|
||||||
|
[:ssrf-extra-blocked-cidrs {:optional true} [::sm/set :string]]]))
|
||||||
|
|
||||||
(defn- parse-flags
|
(defn- parse-flags
|
||||||
[config]
|
[config]
|
||||||
(let [public-uri (c/get config :public-uri)
|
(let [public-uri (c/get config :public-uri)
|
||||||
public-uri (some-> public-uri (u/uri))
|
public-uri (some-> public-uri (u/uri))
|
||||||
extra-flags (if (and public-uri
|
extra-flags (cond-> #{}
|
||||||
|
;; When public-uri is http (non-localhost), disable secure cookies
|
||||||
|
(and public-uri
|
||||||
(= (:scheme public-uri) "http")
|
(= (:scheme public-uri) "http")
|
||||||
(not= (:host public-uri) "localhost"))
|
(not= (:host public-uri) "localhost"))
|
||||||
#{:disable-secure-session-cookies}
|
(conj :disable-secure-session-cookies)
|
||||||
#{})]
|
|
||||||
|
;; When telemetry-enabled config is true, add :telemetry flag
|
||||||
|
(true? (c/get config :telemetry-enabled))
|
||||||
|
(conj :enable-telemetry))]
|
||||||
(flags/parse flags/default extra-flags (:flags config))))
|
(flags/parse flags/default extra-flags (:flags config))))
|
||||||
|
|
||||||
(defn read-env
|
(defn read-env
|
||||||
@ -274,7 +293,7 @@
|
|||||||
(sm/explainer schema:config))
|
(sm/explainer schema:config))
|
||||||
|
|
||||||
(defn read-config
|
(defn read-config
|
||||||
"Reads the configuration from enviroment variables and decodes all
|
"Reads the configuration from environment variables and decodes all
|
||||||
known values."
|
known values."
|
||||||
[& {:keys [prefix default] :or {prefix "penpot"}}]
|
[& {:keys [prefix default] :or {prefix "penpot"}}]
|
||||||
(->> (read-env prefix)
|
(->> (read-env prefix)
|
||||||
@ -326,7 +345,7 @@
|
|||||||
|
|
||||||
(defn logging-context
|
(defn logging-context
|
||||||
[]
|
[]
|
||||||
{:version/backend (:full version)})
|
{:backend/version (:full version)})
|
||||||
|
|
||||||
;; Set value for all new threads bindings.
|
;; Set value for all new threads bindings.
|
||||||
(alter-var-root #'*assert* (constantly (contains? flags :backend-asserts)))
|
(alter-var-root #'*assert* (constantly (contains? flags :backend-asserts)))
|
||||||
|
|||||||
@ -31,6 +31,25 @@
|
|||||||
jakarta.mail.Transport
|
jakarta.mail.Transport
|
||||||
java.util.Properties))
|
java.util.Properties))
|
||||||
|
|
||||||
|
(defn clean
|
||||||
|
"Clean and normalizes email address string"
|
||||||
|
[email]
|
||||||
|
(let [email (str/lower email)
|
||||||
|
email (if (str/starts-with? email "mailto:")
|
||||||
|
(subs email 7)
|
||||||
|
email)
|
||||||
|
email (if (or (str/starts-with? email "<")
|
||||||
|
(str/ends-with? email ">"))
|
||||||
|
(str/trim email "<>")
|
||||||
|
email)]
|
||||||
|
email))
|
||||||
|
|
||||||
|
(defn get-domain
|
||||||
|
[email]
|
||||||
|
(let [email (clean email)
|
||||||
|
[_ domain] (str/split email "@" 2)]
|
||||||
|
domain))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; EMAIL IMPL
|
;; EMAIL IMPL
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -412,6 +431,21 @@
|
|||||||
:id ::invite-to-team
|
:id ::invite-to-team
|
||||||
:schema schema:invite-to-team))
|
:schema schema:invite-to-team))
|
||||||
|
|
||||||
|
(def ^:private schema:invite-to-org
|
||||||
|
[:map
|
||||||
|
[:invited-by ::sm/text]
|
||||||
|
[:organization-name ::sm/text]
|
||||||
|
[:organization-initials [:maybe :string]]
|
||||||
|
[:organization-logo ::sm/uri]
|
||||||
|
[:user-name [:maybe ::sm/text]]
|
||||||
|
[:token ::sm/text]])
|
||||||
|
|
||||||
|
(def invite-to-org
|
||||||
|
"Org member invitation email."
|
||||||
|
(template-factory
|
||||||
|
:id ::invite-to-org
|
||||||
|
:schema schema:invite-to-org))
|
||||||
|
|
||||||
(def ^:private schema:join-team
|
(def ^:private schema:join-team
|
||||||
[:map
|
[:map
|
||||||
[:invited-by ::sm/text]
|
[:invited-by ::sm/text]
|
||||||
|
|||||||
@ -112,8 +112,9 @@
|
|||||||
THEN (c.deleted_at IS NULL OR c.deleted_at >= ?::timestamptz)
|
THEN (c.deleted_at IS NULL OR c.deleted_at >= ?::timestamptz)
|
||||||
END"))
|
END"))
|
||||||
|
|
||||||
(defn- get-snapshot
|
(defn get-snapshot-data
|
||||||
"Get snapshot with decoded data"
|
"Get a fully decoded snapshot for read-only preview or restoration.
|
||||||
|
Returns the snapshot map with decoded :data field."
|
||||||
[cfg file-id snapshot-id]
|
[cfg file-id snapshot-id]
|
||||||
(let [now (ct/now)]
|
(let [now (ct/now)]
|
||||||
(->> (db/get-with-sql cfg [sql:get-snapshot file-id snapshot-id now]
|
(->> (db/get-with-sql cfg [sql:get-snapshot file-id snapshot-id now]
|
||||||
@ -326,7 +327,7 @@
|
|||||||
(sto/resolve cfg {::db/reuse-conn true})
|
(sto/resolve cfg {::db/reuse-conn true})
|
||||||
|
|
||||||
snapshot
|
snapshot
|
||||||
(get-snapshot cfg file-id snapshot-id)]
|
(get-snapshot-data cfg file-id snapshot-id)]
|
||||||
|
|
||||||
(when-not snapshot
|
(when-not snapshot
|
||||||
(ex/raise :type :not-found
|
(ex/raise :type :not-found
|
||||||
|
|||||||
@ -12,43 +12,56 @@
|
|||||||
[app.common.time :as ct]
|
[app.common.time :as ct]
|
||||||
[app.common.uri :as u]
|
[app.common.uri :as u]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
[app.http.session :as session]
|
||||||
[app.storage :as sto]
|
[app.storage :as sto]
|
||||||
[integrant.core :as ig]
|
[integrant.core :as ig]
|
||||||
[yetti.response :as-alias yres]))
|
[yetti.response :as-alias yres]))
|
||||||
|
|
||||||
(def ^:private cache-max-age
|
(def ^:private default-cache-max-age
|
||||||
(ct/duration {:hours 24}))
|
(ct/duration {:hours 24}))
|
||||||
|
|
||||||
(def ^:private signature-max-age
|
(def ^:private default-signature-max-age
|
||||||
(ct/duration {:hours 24 :minutes 15}))
|
(ct/duration {:hours 24 :minutes 15}))
|
||||||
|
|
||||||
|
;; Buckets that are legitimately public and do not require authentication.
|
||||||
|
;; These are used by public shared board viewing, profile photos in UI,
|
||||||
|
;; and embedded export/binfile flows.
|
||||||
|
(def ^:private public-buckets
|
||||||
|
#{"file-media-object"
|
||||||
|
"file-object-thumbnail"
|
||||||
|
"team-font-variant"
|
||||||
|
"file-data-fragment"})
|
||||||
|
|
||||||
(defn get-id
|
(defn get-id
|
||||||
[{:keys [path-params]}]
|
[{:keys [path-params]}]
|
||||||
(or (some-> path-params :id d/parse-uuid)
|
(or (some-> path-params :id d/parse-uuid)
|
||||||
(ex/raise :type :not-found
|
(ex/raise :type :not-found
|
||||||
:hunt "object not found")))
|
:hint "object not found")))
|
||||||
|
|
||||||
(defn- get-file-media-object
|
(defn- get-file-media-object
|
||||||
[pool id]
|
[pool id]
|
||||||
(db/get pool :file-media-object {:id id} {::db/remove-deleted false}))
|
(db/get pool :file-media-object {:id id} {::db/remove-deleted false}))
|
||||||
|
|
||||||
(defn- serve-object-from-s3
|
(defn- serve-object-from-s3
|
||||||
[{:keys [::sto/storage] :as cfg} obj]
|
[{:keys [::sto/storage ::signature-max-age ::cache-max-age] :as cfg} obj]
|
||||||
(let [{:keys [host port] :as url} (sto/get-object-url storage obj {:max-age signature-max-age})]
|
(let [sig-max-age (or signature-max-age default-signature-max-age)
|
||||||
|
cch-max-age (or cache-max-age default-cache-max-age)
|
||||||
|
{:keys [host port] :as url} (sto/get-object-url storage obj {:max-age sig-max-age})]
|
||||||
{::yres/status 307
|
{::yres/status 307
|
||||||
::yres/headers {"location" (str url)
|
::yres/headers {"location" (str url)
|
||||||
"x-host" (cond-> host port (str ":" port))
|
"x-host" (cond-> host port (str ":" port))
|
||||||
"x-mtype" (-> obj meta :content-type)
|
"x-mtype" (-> obj meta :content-type)
|
||||||
"cache-control" (str "max-age=" (inst-ms cache-max-age))}}))
|
"cache-control" (str "max-age=" (inst-ms cch-max-age))}}))
|
||||||
|
|
||||||
(defn- serve-object-from-fs
|
(defn- serve-object-from-fs
|
||||||
[{:keys [::path]} obj]
|
[{:keys [::path ::cache-max-age]} obj]
|
||||||
(let [purl (u/join (u/uri path)
|
(let [cch-max-age (or cache-max-age default-cache-max-age)
|
||||||
|
purl (u/join (u/uri path)
|
||||||
(sto/object->relative-path obj))
|
(sto/object->relative-path obj))
|
||||||
mdata (meta obj)
|
mdata (meta obj)
|
||||||
headers {"x-accel-redirect" (:path purl)
|
headers {"x-accel-redirect" (:path purl)
|
||||||
"content-type" (:content-type mdata)
|
"content-type" (:content-type mdata)
|
||||||
"cache-control" (str "max-age=" (inst-ms cache-max-age))}]
|
"cache-control" (str "max-age=" (inst-ms cch-max-age))}]
|
||||||
{::yres/status 204
|
{::yres/status 204
|
||||||
::yres/headers headers}))
|
::yres/headers headers}))
|
||||||
|
|
||||||
@ -60,14 +73,28 @@
|
|||||||
(:s3 :assets-s3) (serve-object-from-s3 cfg obj)
|
(:s3 :assets-s3) (serve-object-from-s3 cfg obj)
|
||||||
(:fs :assets-fs) (serve-object-from-fs cfg obj)))
|
(:fs :assets-fs) (serve-object-from-fs cfg obj)))
|
||||||
|
|
||||||
|
(defn- requires-auth?
|
||||||
|
"Check if the storage object requires authentication based on its bucket."
|
||||||
|
[obj]
|
||||||
|
(let [bucket (-> obj meta :bucket)]
|
||||||
|
(not (contains? public-buckets bucket))))
|
||||||
|
|
||||||
(defn objects-handler
|
(defn objects-handler
|
||||||
"Handler that servers storage objects by id."
|
"Handler that serves storage objects by id.
|
||||||
|
For non-public buckets (e.g. profile), requires an authenticated session."
|
||||||
[{:keys [::sto/storage] :as cfg} request]
|
[{:keys [::sto/storage] :as cfg} request]
|
||||||
(let [id (get-id request)
|
(let [id (get-id request)
|
||||||
obj (sto/get-object storage id)]
|
obj (sto/get-object storage id)]
|
||||||
(if obj
|
(cond
|
||||||
(serve-object cfg obj)
|
(nil? obj)
|
||||||
{::yres/status 404})))
|
{::yres/status 404}
|
||||||
|
|
||||||
|
(and (requires-auth? obj)
|
||||||
|
(nil? (::session/profile-id request)))
|
||||||
|
{::yres/status 401}
|
||||||
|
|
||||||
|
:else
|
||||||
|
(serve-object cfg obj))))
|
||||||
|
|
||||||
(defn- generic-handler
|
(defn- generic-handler
|
||||||
"A generic handler helper/common code for file-media based handlers."
|
"A generic handler helper/common code for file-media based handlers."
|
||||||
@ -96,11 +123,12 @@
|
|||||||
(defmethod ig/assert-key ::routes
|
(defmethod ig/assert-key ::routes
|
||||||
[_ params]
|
[_ params]
|
||||||
(assert (sto/valid-storage? (::sto/storage params)) "expected valid storage instance")
|
(assert (sto/valid-storage? (::sto/storage params)) "expected valid storage instance")
|
||||||
|
(assert (session/manager? (::session/manager params)) "expected valid session manager")
|
||||||
(assert (string? (::path params))))
|
(assert (string? (::path params))))
|
||||||
|
|
||||||
(defmethod ig/init-key ::routes
|
(defmethod ig/init-key ::routes
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
["/assets"
|
["/assets" {:middleware [[session/authz cfg]]}
|
||||||
["/by-id/:id" {:handler (partial objects-handler cfg)}]
|
["/by-id/:id" {:handler (partial objects-handler cfg)}]
|
||||||
["/by-file-media-id/:id" {:handler (partial file-objects-handler cfg)}]
|
["/by-file-media-id/:id" {:handler (partial file-objects-handler cfg)}]
|
||||||
["/by-file-media-id/:id/thumbnail" {:handler (partial file-thumbnails-handler cfg)}]])
|
["/by-file-media-id/:id/thumbnail" {:handler (partial file-thumbnails-handler cfg)}]])
|
||||||
|
|||||||
@ -53,7 +53,7 @@
|
|||||||
(let [surl (get body "SubscribeURL")
|
(let [surl (get body "SubscribeURL")
|
||||||
stopic (get body "TopicArn")]
|
stopic (get body "TopicArn")]
|
||||||
(l/info :action "subscription received" :topic stopic :url surl)
|
(l/info :action "subscription received" :topic stopic :url surl)
|
||||||
(http/req! cfg {:uri surl :method :post :timeout 10000} {:sync? true}))
|
(http/req cfg {:uri surl :method :post :timeout 10000} {:sync? true}))
|
||||||
|
|
||||||
(= mtype "Notification")
|
(= mtype "Notification")
|
||||||
(when-let [message (parse-json (get body "Message"))]
|
(when-let [message (parse-json (get body "Message"))]
|
||||||
|
|||||||
@ -5,13 +5,24 @@
|
|||||||
;; Copyright (c) KALEIDOS INC
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
(ns app.http.client
|
(ns app.http.client
|
||||||
"Http client abstraction layer."
|
"Http client abstraction layer.
|
||||||
|
|
||||||
|
All outbound requests made through `req` and `req-with-redirects`
|
||||||
|
are validated against the SSRF blocklist by default. Pass
|
||||||
|
`:skip-ssrf-check? true` in the options map only when the target
|
||||||
|
is a well-known, operator-configured endpoint that cannot be
|
||||||
|
influenced by user input (e.g. internal telemetry, error webhooks)."
|
||||||
(:require
|
(:require
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
|
[app.util.ssrf :as ssrf]
|
||||||
|
[cuerdas.core :as str]
|
||||||
[integrant.core :as ig]
|
[integrant.core :as ig]
|
||||||
[java-http-clj.core :as http])
|
[java-http-clj.core :as http])
|
||||||
(:import
|
(:import
|
||||||
java.net.http.HttpClient))
|
java.net.http.HttpClient
|
||||||
|
java.net.URI))
|
||||||
|
|
||||||
|
(def default-max-redirects 5)
|
||||||
|
|
||||||
(defn client?
|
(defn client?
|
||||||
[o]
|
[o]
|
||||||
@ -23,8 +34,8 @@
|
|||||||
|
|
||||||
(defmethod ig/init-key ::client
|
(defmethod ig/init-key ::client
|
||||||
[_ _]
|
[_ _]
|
||||||
(http/build-client {:connect-timeout 30000 ;; 10s
|
(http/build-client {:connect-timeout 30000
|
||||||
:follow-redirects :always}))
|
:follow-redirects :never}))
|
||||||
|
|
||||||
(defn send!
|
(defn send!
|
||||||
([client req] (send! client req {}))
|
([client req] (send! client req {}))
|
||||||
@ -44,14 +55,82 @@
|
|||||||
:else
|
:else
|
||||||
(throw (UnsupportedOperationException. "invalid arguments"))))
|
(throw (UnsupportedOperationException. "invalid arguments"))))
|
||||||
|
|
||||||
(defn req!
|
(defn req
|
||||||
"A convencience toplevel function for gradual migration to a new API
|
"Issue a single HTTP request. SSRF validation is applied to the
|
||||||
convention."
|
target URI by default; pass `:skip-ssrf-check? true` in `options`
|
||||||
|
to bypass it for known-safe, operator-configured endpoints."
|
||||||
([cfg-or-client request]
|
([cfg-or-client request]
|
||||||
|
(req cfg-or-client request {}))
|
||||||
|
([cfg-or-client request {:keys [skip-ssrf-check?] :as options}]
|
||||||
|
(let [request (if skip-ssrf-check?
|
||||||
|
(update request :uri str)
|
||||||
|
(update request :uri ssrf/validate-uri))
|
||||||
|
client (resolve-client cfg-or-client)]
|
||||||
|
(send! client request (dissoc options :skip-ssrf-check?)))))
|
||||||
|
|
||||||
|
(defn- resolve-location
|
||||||
|
"Resolve a Location header value against the original request URI.
|
||||||
|
Handles:
|
||||||
|
- Absolute URLs (http:// or https://) — returned as-is.
|
||||||
|
- Protocol-relative URLs (//host/path) — inherit the scheme from base-uri.
|
||||||
|
- Path-absolute and relative URLs — resolved against base-uri via URI.resolve."
|
||||||
|
[^String base-uri ^String location]
|
||||||
|
(cond
|
||||||
|
(or (str/starts-with? location "http://")
|
||||||
|
(str/starts-with? location "https://"))
|
||||||
|
location
|
||||||
|
|
||||||
|
(str/starts-with? location "//")
|
||||||
|
(let [scheme (.getScheme (URI. base-uri))]
|
||||||
|
(str scheme ":" location))
|
||||||
|
|
||||||
|
:else
|
||||||
|
(str (.resolve (URI. base-uri) location))))
|
||||||
|
|
||||||
|
(defn- redirect-request
|
||||||
|
"Build the next request for a 3xx redirect.
|
||||||
|
Per RFC 7231 §6.4:
|
||||||
|
- 303 always issues GET (body dropped).
|
||||||
|
- 301/302 with non-GET/HEAD methods: downgrade to GET (body dropped).
|
||||||
|
- 307/308 preserve the original method and body.
|
||||||
|
The Location URI has already been resolved by the caller."
|
||||||
|
[orig-request ^String next-uri status]
|
||||||
|
(let [method (:method orig-request)]
|
||||||
|
(if (or (= status 303)
|
||||||
|
(and (contains? #{301 302} status)
|
||||||
|
(not (contains? #{:get :head} method))))
|
||||||
|
;; Downgrade to GET, drop body and content-type
|
||||||
|
(-> orig-request
|
||||||
|
(assoc :uri next-uri :method :get)
|
||||||
|
(dissoc :body)
|
||||||
|
(update :headers dissoc "content-type" "content-length"))
|
||||||
|
;; Preserve method/body (307, 308, or GET/HEAD 301/302)
|
||||||
|
(assoc orig-request :uri next-uri))))
|
||||||
|
|
||||||
|
(defn req-with-redirects
|
||||||
|
"Like `req`, but follows up to `max-redirects` HTTP 3xx redirects.
|
||||||
|
SSRF validation is applied before every hop (initial request and
|
||||||
|
each redirect target) unless `:skip-ssrf-check? true` is passed.
|
||||||
|
Redirect semantics follow RFC 7231 §6.4: 301/302 POST is downgraded
|
||||||
|
to GET; 303 always uses GET; 307/308 preserve the original method."
|
||||||
|
([cfg-or-client request]
|
||||||
|
(req-with-redirects cfg-or-client request {}))
|
||||||
|
([cfg-or-client request {:keys [max-redirects skip-ssrf-check?]
|
||||||
|
:or {max-redirects default-max-redirects}
|
||||||
|
:as opts}]
|
||||||
|
(let [send-opts (dissoc opts :max-redirects :skip-ssrf-check?)
|
||||||
|
uri-coerce (if skip-ssrf-check? str ssrf/validate-uri)]
|
||||||
|
(loop [current-req (update request :uri uri-coerce)
|
||||||
|
hops 0]
|
||||||
(let [client (resolve-client cfg-or-client)
|
(let [client (resolve-client cfg-or-client)
|
||||||
request (update request :uri str)]
|
resp (send! client current-req send-opts)
|
||||||
(send! client request {})))
|
status (:status resp)]
|
||||||
([cfg-or-client request options]
|
(if (and (<= 300 status 399)
|
||||||
(let [client (resolve-client cfg-or-client)
|
(< hops max-redirects))
|
||||||
request (update request :uri str)]
|
(if-let [location (get-in resp [:headers "location"])]
|
||||||
(send! client request options))))
|
(let [next-uri (resolve-location (str (:uri current-req)) location)]
|
||||||
|
(recur (update (redirect-request current-req next-uri status) :uri uri-coerce)
|
||||||
|
(inc hops)))
|
||||||
|
;; No Location header on a 3xx — return the response as-is
|
||||||
|
resp)
|
||||||
|
resp))))))
|
||||||
|
|||||||
@ -31,7 +31,6 @@
|
|||||||
[app.srepl.main :as srepl]
|
[app.srepl.main :as srepl]
|
||||||
[app.storage :as-alias sto]
|
[app.storage :as-alias sto]
|
||||||
[app.storage.tmp :as tmp]
|
[app.storage.tmp :as tmp]
|
||||||
[app.util.blob :as blob]
|
|
||||||
[app.util.template :as tmpl]
|
[app.util.template :as tmpl]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[datoteka.io :as io]
|
[datoteka.io :as io]
|
||||||
@ -71,8 +70,7 @@
|
|||||||
|
|
||||||
(defn- get-resolved-file
|
(defn- get-resolved-file
|
||||||
[cfg file-id]
|
[cfg file-id]
|
||||||
(some-> (bfc/get-file cfg file-id :migrate? false)
|
(bfc/get-file cfg file-id :migrate? false :decode? false))
|
||||||
(update :data blob/encode)))
|
|
||||||
|
|
||||||
(defn prepare-download
|
(defn prepare-download
|
||||||
[file filename]
|
[file filename]
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
(defn- write!
|
(defn- write!
|
||||||
[^OutputStream output ^bytes data]
|
[^OutputStream output ^bytes data]
|
||||||
(l/trc :hint "writting data" :data data :length (alength data))
|
(l/trc :hint "writing data" :data data :length (alength data))
|
||||||
(.write output data)
|
(.write output data)
|
||||||
(.flush output))
|
(.flush output))
|
||||||
|
|
||||||
@ -53,6 +53,7 @@
|
|||||||
::yres/status 200
|
::yres/status 200
|
||||||
::yres/body (yres/stream-body
|
::yres/body (yres/stream-body
|
||||||
(fn [_ output]
|
(fn [_ output]
|
||||||
|
|
||||||
(let [channel (sp/chan :buf buf :xf (keep encode))
|
(let [channel (sp/chan :buf buf :xf (keep encode))
|
||||||
listener (events/spawn-listener
|
listener (events/spawn-listener
|
||||||
channel
|
channel
|
||||||
|
|||||||
@ -16,12 +16,12 @@
|
|||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
[app.email :as email]
|
||||||
[app.http :as-alias http]
|
[app.http :as-alias http]
|
||||||
[app.http.access-token :as-alias actoken]
|
[app.http.access-token :as-alias actoken]
|
||||||
[app.loggers.audit.tasks :as-alias tasks]
|
[app.loggers.audit.tasks :as-alias tasks]
|
||||||
[app.loggers.webhooks :as-alias webhooks]
|
[app.loggers.webhooks :as-alias webhooks]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.retry :as rtry]
|
|
||||||
[app.setup :as-alias setup]
|
[app.setup :as-alias setup]
|
||||||
[app.util.inet :as inet]
|
[app.util.inet :as inet]
|
||||||
[app.util.services :as-alias sv]
|
[app.util.services :as-alias sv]
|
||||||
@ -33,6 +33,63 @@
|
|||||||
;; HELPERS
|
;; HELPERS
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(def ^:private filter-auth-events
|
||||||
|
#{"login-with-oidc" "login-with-password" "register-profile" "update-profile"})
|
||||||
|
|
||||||
|
(def ^:private safe-backend-context-keys
|
||||||
|
#{:version
|
||||||
|
:initiator
|
||||||
|
:client-version
|
||||||
|
:client-user-agent})
|
||||||
|
|
||||||
|
(def ^:private safe-frontend-context-keys
|
||||||
|
#{:version
|
||||||
|
:locale
|
||||||
|
:browser
|
||||||
|
:browser-version
|
||||||
|
:engine
|
||||||
|
:engine-version
|
||||||
|
:os
|
||||||
|
:os-version
|
||||||
|
:device-type
|
||||||
|
:device-arch
|
||||||
|
:screen-width
|
||||||
|
:screen-height
|
||||||
|
:screen-color-depth
|
||||||
|
:screen-orientation
|
||||||
|
:event-origin
|
||||||
|
:event-namespace
|
||||||
|
:event-symbol})
|
||||||
|
|
||||||
|
(def profile-props
|
||||||
|
[:id
|
||||||
|
:is-active
|
||||||
|
:is-muted
|
||||||
|
:auth-backend
|
||||||
|
:email
|
||||||
|
:default-team-id
|
||||||
|
:default-project-id
|
||||||
|
:fullname
|
||||||
|
:lang])
|
||||||
|
|
||||||
|
(def ^:private event-keys
|
||||||
|
#{:id
|
||||||
|
:name
|
||||||
|
:type
|
||||||
|
:profile-id
|
||||||
|
:ip-addr
|
||||||
|
:props
|
||||||
|
:context
|
||||||
|
:source
|
||||||
|
:tracked-at
|
||||||
|
:created-at})
|
||||||
|
|
||||||
|
(def reserved-props
|
||||||
|
#{:session-id
|
||||||
|
:password
|
||||||
|
:old-password
|
||||||
|
:token})
|
||||||
|
|
||||||
(defn extract-utm-params
|
(defn extract-utm-params
|
||||||
"Extracts additional data from params and namespace them under
|
"Extracts additional data from params and namespace them under
|
||||||
`penpot` ns."
|
`penpot` ns."
|
||||||
@ -47,17 +104,6 @@
|
|||||||
(assoc (->> sk str/kebab (keyword "penpot")) v))))]
|
(assoc (->> sk str/kebab (keyword "penpot")) v))))]
|
||||||
(reduce-kv process-param {} params)))
|
(reduce-kv process-param {} params)))
|
||||||
|
|
||||||
(def profile-props
|
|
||||||
[:id
|
|
||||||
:is-active
|
|
||||||
:is-muted
|
|
||||||
:auth-backend
|
|
||||||
:email
|
|
||||||
:default-team-id
|
|
||||||
:default-project-id
|
|
||||||
:fullname
|
|
||||||
:lang])
|
|
||||||
|
|
||||||
(defn profile->props
|
(defn profile->props
|
||||||
[profile]
|
[profile]
|
||||||
(-> profile
|
(-> profile
|
||||||
@ -65,12 +111,6 @@
|
|||||||
(merge (:props profile))
|
(merge (:props profile))
|
||||||
(d/without-nils)))
|
(d/without-nils)))
|
||||||
|
|
||||||
(def reserved-props
|
|
||||||
#{:session-id
|
|
||||||
:password
|
|
||||||
:old-password
|
|
||||||
:token})
|
|
||||||
|
|
||||||
(defn clean-props
|
(defn clean-props
|
||||||
[props]
|
[props]
|
||||||
(into {}
|
(into {}
|
||||||
@ -120,16 +160,17 @@
|
|||||||
;; an external storage and data cleared.
|
;; an external storage and data cleared.
|
||||||
|
|
||||||
(def ^:private schema:event
|
(def ^:private schema:event
|
||||||
[:map {:title "event"}
|
[:map {:title "AuditEvent"}
|
||||||
[::type ::sm/text]
|
[:id {:optional true} ::sm/uuid]
|
||||||
[::name ::sm/text]
|
[:type ::sm/text]
|
||||||
[::profile-id ::sm/uuid]
|
[:name ::sm/text]
|
||||||
[::ip-addr {:optional true} ::sm/text]
|
[:profile-id ::sm/uuid]
|
||||||
[::props {:optional true} [:map-of :keyword :any]]
|
[:props [:map-of :keyword :any]]
|
||||||
[::context {:optional true} [:map-of :keyword :any]]
|
[:context [:map-of :keyword :any]]
|
||||||
[::tracked-at {:optional true} ::ct/inst]
|
[:tracked-at ::ct/inst]
|
||||||
[::created-at {:optional true} ::ct/inst]
|
[:created-at ::ct/inst]
|
||||||
[::source {:optional true} ::sm/text]
|
[:source ::sm/text]
|
||||||
|
[:ip-addr {:optional true} ::sm/text]
|
||||||
[::webhooks/event? {:optional true} ::sm/boolean]
|
[::webhooks/event? {:optional true} ::sm/boolean]
|
||||||
[::webhooks/batch-timeout {:optional true} ::ct/duration]
|
[::webhooks/batch-timeout {:optional true} ::ct/duration]
|
||||||
[::webhooks/batch-key {:optional true}
|
[::webhooks/batch-key {:optional true}
|
||||||
@ -141,7 +182,156 @@
|
|||||||
(def valid-event?
|
(def valid-event?
|
||||||
(sm/validator schema:event))
|
(sm/validator schema:event))
|
||||||
|
|
||||||
(defn prepare-event
|
(defn- prepare-context-from-request
|
||||||
|
"Prepare backend event context from request"
|
||||||
|
[request]
|
||||||
|
(let [client-event-origin (get-client-event-origin request)
|
||||||
|
client-version (get-client-version request)
|
||||||
|
client-user-agent (get-client-user-agent request)
|
||||||
|
session-id (get-external-session-id request)
|
||||||
|
key-id (::http/auth-key-id request)
|
||||||
|
token-id (::actoken/id request)
|
||||||
|
token-type (::actoken/type request)]
|
||||||
|
{:external-session-id session-id
|
||||||
|
:initiator (or key-id "app")
|
||||||
|
:access-token-id (some-> token-id str)
|
||||||
|
:access-token-type (some-> token-type str)
|
||||||
|
:client-event-origin client-event-origin
|
||||||
|
:client-user-agent client-user-agent
|
||||||
|
:client-version client-version
|
||||||
|
:version (:full cf/version)}))
|
||||||
|
|
||||||
|
(defn- append-audit-entry
|
||||||
|
[cfg params]
|
||||||
|
(let [params (-> params
|
||||||
|
(assoc :id (uuid/next))
|
||||||
|
(update :props db/tjson)
|
||||||
|
(update :context db/tjson)
|
||||||
|
(update :ip-addr db/inet))
|
||||||
|
params (select-keys params event-keys)]
|
||||||
|
(db/insert! cfg :audit-log params)))
|
||||||
|
|
||||||
|
(def ^:private xf:filter-telemetry-props
|
||||||
|
"Transducer that keeps only map entries whose values are UUIDs,
|
||||||
|
booleans or numbers."
|
||||||
|
(filter (fn [[k v]]
|
||||||
|
(and (simple-keyword? k)
|
||||||
|
(or (uuid? v) (boolean? v) (number? v))))))
|
||||||
|
|
||||||
|
(declare filter-telemetry-props)
|
||||||
|
(declare filter-telemetry-context)
|
||||||
|
|
||||||
|
(defn- process-event
|
||||||
|
[cfg event]
|
||||||
|
(when (contains? cf/flags :audit-log-logger)
|
||||||
|
(l/log! ::l/logger "app.audit"
|
||||||
|
::l/level :info
|
||||||
|
:profile-id (str (:profile-id event))
|
||||||
|
:ip-addr (str (:ip-addr event))
|
||||||
|
:type (:type event)
|
||||||
|
:name (:name event)
|
||||||
|
:props (json/encode (:props event) :key-fn json/write-camel-key)
|
||||||
|
:context (json/encode (:context event) :key-fn json/write-camel-key)))
|
||||||
|
|
||||||
|
(when (contains? cf/flags :audit-log)
|
||||||
|
(append-audit-entry cfg event))
|
||||||
|
|
||||||
|
(when (contains? cf/flags :telemetry)
|
||||||
|
;; NOTE: when both audit-log and telemetry are enabled, events are stored
|
||||||
|
;; twice: once with full details (above) and once stripped of props and
|
||||||
|
;; ip-addr, tagged with source="telemetry" so the telemetry task can
|
||||||
|
;; collect and ship them. The profile-id is preserved (UUIDs are already
|
||||||
|
;; anonymous random identifiers). Only a safe subset of context fields
|
||||||
|
;; is kept: initiator, version, client-version and client-user-agent.
|
||||||
|
;; Timestamps are truncated to day precision to avoid leaking exact event
|
||||||
|
;; timing.
|
||||||
|
(let [event (-> event
|
||||||
|
(filter-telemetry-props)
|
||||||
|
(filter-telemetry-context)
|
||||||
|
(update :created-at ct/truncate :days)
|
||||||
|
(update :tracked-at ct/truncate :days)
|
||||||
|
(assoc :source "telemetry:backend")
|
||||||
|
(assoc :ip-addr "0.0.0.0"))]
|
||||||
|
(append-audit-entry cfg event)))
|
||||||
|
|
||||||
|
(when (and (contains? cf/flags :webhooks)
|
||||||
|
(::webhooks/event? event))
|
||||||
|
(let [batch-key (::webhooks/batch-key event)
|
||||||
|
batch-timeout (::webhooks/batch-timeout event)
|
||||||
|
label (dm/str "rpc:" (:name event))
|
||||||
|
label (cond
|
||||||
|
(ifn? batch-key) (dm/str label ":" (batch-key (::rpc/params event)))
|
||||||
|
(string? batch-key) (dm/str label ":" batch-key)
|
||||||
|
:else label)
|
||||||
|
dedupe? (boolean (and batch-key batch-timeout))]
|
||||||
|
|
||||||
|
(wrk/submit! (-> cfg
|
||||||
|
(assoc ::wrk/task :process-webhook-event)
|
||||||
|
(assoc ::wrk/queue :webhooks)
|
||||||
|
(assoc ::wrk/max-retries 0)
|
||||||
|
(assoc ::wrk/delay (or batch-timeout 0))
|
||||||
|
(assoc ::wrk/dedupe dedupe?)
|
||||||
|
(assoc ::wrk/label label)
|
||||||
|
(assoc ::wrk/params (-> event
|
||||||
|
(d/without-qualified)
|
||||||
|
(dissoc :source)
|
||||||
|
(dissoc :context)
|
||||||
|
(dissoc :ip-addr)
|
||||||
|
(dissoc :type)))))))
|
||||||
|
event)
|
||||||
|
|
||||||
|
(defn submit*
|
||||||
|
"A public API, lower-level than submit, assumes all required fields are filled"
|
||||||
|
[cfg event]
|
||||||
|
(try
|
||||||
|
(let [event (check-event event)]
|
||||||
|
(db/tx-run! cfg process-event event))
|
||||||
|
(catch Throwable cause
|
||||||
|
(l/error :hint "unexpected error processing event" :cause cause))))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; PUBLIC API
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defn filter-telemetry-props
|
||||||
|
[{:keys [source name props type] :as params}]
|
||||||
|
(cond
|
||||||
|
(or (and (= source "frontend")
|
||||||
|
(= type "identify"))
|
||||||
|
(and (= source "backend")
|
||||||
|
(filter-auth-events name)))
|
||||||
|
|
||||||
|
(let [props' (into {} xf:filter-telemetry-props props)
|
||||||
|
props' (-> props'
|
||||||
|
(assoc :lang (:lang props))
|
||||||
|
(assoc :auth-backend (:auth-backend props))
|
||||||
|
(assoc :email-domain (email/get-domain (:email props)))
|
||||||
|
(d/without-nils))]
|
||||||
|
(assoc params :props props'))
|
||||||
|
|
||||||
|
(and (= source "backend")
|
||||||
|
(= type "trigger")
|
||||||
|
(= name "instance-start"))
|
||||||
|
params
|
||||||
|
|
||||||
|
(and (= source "frontend")
|
||||||
|
(= type "action")
|
||||||
|
(= name "navigate"))
|
||||||
|
(assoc params :props (select-keys props [:route :file-id :team-id :page-id]))
|
||||||
|
|
||||||
|
:else
|
||||||
|
(let [props (into {} xf:filter-telemetry-props props)]
|
||||||
|
(assoc params :props props))))
|
||||||
|
|
||||||
|
(defn filter-telemetry-context
|
||||||
|
[{:keys [source context] :as params}]
|
||||||
|
(let [context (case source
|
||||||
|
"backend" (select-keys context safe-backend-context-keys)
|
||||||
|
"frontend" (select-keys context safe-frontend-context-keys)
|
||||||
|
{})]
|
||||||
|
(assoc params :context context)))
|
||||||
|
|
||||||
|
(defn prepare-rpc-event
|
||||||
[cfg mdata params result]
|
[cfg mdata params result]
|
||||||
(let [resultm (meta result)
|
(let [resultm (meta result)
|
||||||
request (-> params meta ::http/request)
|
request (-> params meta ::http/request)
|
||||||
@ -154,23 +344,29 @@
|
|||||||
(merge params (::props resultm)))
|
(merge params (::props resultm)))
|
||||||
(clean-props))
|
(clean-props))
|
||||||
|
|
||||||
context (merge (::context resultm)
|
context (-> (::context resultm)
|
||||||
(prepare-context-from-request request))
|
(merge (prepare-context-from-request request))
|
||||||
|
(assoc :request-id (::rpc/request-id params))
|
||||||
|
(d/without-nils))
|
||||||
|
|
||||||
ip-addr (inet/parse-request request)
|
ip-addr (inet/parse-request request)
|
||||||
module (get cfg ::rpc/module)]
|
module (get cfg ::rpc/module)]
|
||||||
|
|
||||||
{::type (or (::type resultm)
|
{:type (or (::type resultm)
|
||||||
(::rpc/type cfg))
|
(::rpc/type cfg))
|
||||||
::name (or (::name resultm)
|
:name (or (::name resultm)
|
||||||
(let [sname (::sv/name mdata)]
|
(let [sname (::sv/name mdata)]
|
||||||
(if (not= module "main")
|
(if (not= module "main")
|
||||||
(str module "-" sname)
|
(str module "-" sname)
|
||||||
sname)))
|
sname)))
|
||||||
|
|
||||||
::profile-id profile-id
|
:profile-id profile-id
|
||||||
::ip-addr ip-addr
|
:ip-addr ip-addr
|
||||||
::props props
|
:props props
|
||||||
::context context
|
:context context
|
||||||
|
|
||||||
|
:created-at (::rpc/request-at params)
|
||||||
|
:tracked-at (::rpc/request-at params)
|
||||||
|
|
||||||
;; NOTE: for batch-key lookup we need the params as-is
|
;; NOTE: for batch-key lookup we need the params as-is
|
||||||
;; because the rpc api does not need to know the
|
;; because the rpc api does not need to know the
|
||||||
@ -190,148 +386,49 @@
|
|||||||
(::webhooks/event? resultm)
|
(::webhooks/event? resultm)
|
||||||
false)}))
|
false)}))
|
||||||
|
|
||||||
(defn- prepare-context-from-request
|
|
||||||
"Prepare backend event context from request"
|
|
||||||
[request]
|
|
||||||
(let [client-event-origin (get-client-event-origin request)
|
|
||||||
client-version (get-client-version request)
|
|
||||||
client-user-agent (get-client-user-agent request)
|
|
||||||
session-id (get-external-session-id request)
|
|
||||||
key-id (::http/auth-key-id request)
|
|
||||||
token-id (::actoken/id request)
|
|
||||||
token-type (::actoken/type request)]
|
|
||||||
(d/without-nils
|
|
||||||
{:external-session-id session-id
|
|
||||||
:initiator (or key-id "app")
|
|
||||||
:access-token-id (some-> token-id str)
|
|
||||||
:access-token-type (some-> token-type str)
|
|
||||||
:client-event-origin client-event-origin
|
|
||||||
:client-user-agent client-user-agent
|
|
||||||
:client-version client-version
|
|
||||||
:version (:full cf/version)})))
|
|
||||||
|
|
||||||
(defn event-from-rpc-params
|
(defn event-from-rpc-params
|
||||||
"Create a base event skeleton with pre-filled some important
|
"Create a base event skeleton with pre-filled some important
|
||||||
data that can be extracted from RPC params object"
|
data that can be extracted from RPC params object"
|
||||||
[params]
|
[params]
|
||||||
(let [context (some-> params meta ::http/request prepare-context-from-request)
|
(let [context (some-> params meta ::http/request prepare-context-from-request)
|
||||||
event {::type "action"
|
context (assoc context :request-id (::rpc/request-id params))
|
||||||
::profile-id (or (::rpc/profile-id params) uuid/zero)
|
request-at (::rpc/request-at params)]
|
||||||
::ip-addr (::rpc/ip-addr params)}]
|
{:type "action"
|
||||||
(cond-> event
|
:profile-id (::rpc/profile-id params)
|
||||||
(some? context)
|
:created-at request-at
|
||||||
(assoc ::context context))))
|
:tracked-at request-at
|
||||||
|
:ip-addr (::rpc/ip-addr params)
|
||||||
|
:context (d/without-nils context)}))
|
||||||
|
|
||||||
(defn- event->params
|
(defn submit
|
||||||
[event]
|
"Submit an event to be registered under audit-log subsystem"
|
||||||
(let [params {:id (uuid/next)
|
|
||||||
:name (::name event)
|
|
||||||
:type (::type event)
|
|
||||||
:profile-id (::profile-id event)
|
|
||||||
:ip-addr (::ip-addr event)
|
|
||||||
:context (::context event {})
|
|
||||||
:props (::props event {})
|
|
||||||
:source "backend"}
|
|
||||||
tnow (::tracked-at event)]
|
|
||||||
|
|
||||||
(cond-> params
|
|
||||||
(some? tnow)
|
|
||||||
(assoc :tracked-at tnow))))
|
|
||||||
|
|
||||||
(defn- append-audit-entry
|
|
||||||
[cfg params]
|
|
||||||
(let [params (-> params
|
|
||||||
(update :props db/tjson)
|
|
||||||
(update :context db/tjson)
|
|
||||||
(update :ip-addr db/inet))]
|
|
||||||
(db/insert! cfg :audit-log params)))
|
|
||||||
|
|
||||||
(defn- handle-event!
|
|
||||||
[cfg event]
|
[cfg event]
|
||||||
(let [tnow (ct/now)
|
(let [tnow (ct/now)
|
||||||
params (-> (event->params event)
|
event (-> event
|
||||||
(assoc :created-at tnow)
|
(assoc :created-at tnow)
|
||||||
(update :tracked-at #(or % tnow)))]
|
(update :profile-id d/nilv uuid/zero)
|
||||||
|
(update :tracked-at d/nilv tnow)
|
||||||
|
(update :ip-addr d/nilv "0.0.0.0")
|
||||||
|
(update :props d/nilv {})
|
||||||
|
(update :context d/nilv {})
|
||||||
|
(assoc :source "backend")
|
||||||
|
(d/without-nils))]
|
||||||
|
(submit* cfg event)))
|
||||||
|
|
||||||
(when (contains? cf/flags :audit-log-logger)
|
(defn insert
|
||||||
(l/log! ::l/logger "app.audit"
|
|
||||||
::l/level :info
|
|
||||||
:profile-id (str (::profile-id event))
|
|
||||||
:ip-addr (str (::ip-addr event))
|
|
||||||
:type (::type event)
|
|
||||||
:name (::name event)
|
|
||||||
:props (json/encode (::props event) :key-fn json/write-camel-key)
|
|
||||||
:context (json/encode (::context event) :key-fn json/write-camel-key)))
|
|
||||||
|
|
||||||
(when (contains? cf/flags :audit-log)
|
|
||||||
;; NOTE: this operation may cause primary key conflicts on inserts
|
|
||||||
;; because of the timestamp precission (two concurrent requests), in
|
|
||||||
;; this case we just retry the operation.
|
|
||||||
(append-audit-entry cfg params))
|
|
||||||
|
|
||||||
(when (and (or (contains? cf/flags :telemetry)
|
|
||||||
(cf/get :telemetry-enabled))
|
|
||||||
(not (contains? cf/flags :audit-log)))
|
|
||||||
;; NOTE: this operation may cause primary key conflicts on inserts
|
|
||||||
;; because of the timestamp precission (two concurrent requests), in
|
|
||||||
;; this case we just retry the operation.
|
|
||||||
;;
|
|
||||||
;; NOTE: this is only executed when general audit log is disabled
|
|
||||||
(let [params (-> params
|
|
||||||
(assoc :props {})
|
|
||||||
(assoc :context {}))]
|
|
||||||
(append-audit-entry cfg params)))
|
|
||||||
|
|
||||||
(when (and (contains? cf/flags :webhooks)
|
|
||||||
(::webhooks/event? event))
|
|
||||||
(let [batch-key (::webhooks/batch-key event)
|
|
||||||
batch-timeout (::webhooks/batch-timeout event)
|
|
||||||
label (dm/str "rpc:" (:name params))
|
|
||||||
label (cond
|
|
||||||
(ifn? batch-key) (dm/str label ":" (batch-key (::rpc/params event)))
|
|
||||||
(string? batch-key) (dm/str label ":" batch-key)
|
|
||||||
:else label)
|
|
||||||
dedupe? (boolean (and batch-key batch-timeout))]
|
|
||||||
|
|
||||||
(wrk/submit! (-> cfg
|
|
||||||
(assoc ::wrk/task :process-webhook-event)
|
|
||||||
(assoc ::wrk/queue :webhooks)
|
|
||||||
(assoc ::wrk/max-retries 0)
|
|
||||||
(assoc ::wrk/delay (or batch-timeout 0))
|
|
||||||
(assoc ::wrk/dedupe dedupe?)
|
|
||||||
(assoc ::wrk/label label)
|
|
||||||
(assoc ::wrk/params (-> params
|
|
||||||
(dissoc :source)
|
|
||||||
(dissoc :context)
|
|
||||||
(dissoc :ip-addr)
|
|
||||||
(dissoc :type)))))))
|
|
||||||
params))
|
|
||||||
|
|
||||||
(defn submit!
|
|
||||||
"Submit audit event to the collector."
|
|
||||||
[cfg event]
|
|
||||||
(try
|
|
||||||
(let [event (-> (d/without-nils event)
|
|
||||||
(check-event))
|
|
||||||
cfg (-> cfg
|
|
||||||
(assoc ::rtry/when rtry/conflict-exception?)
|
|
||||||
(assoc ::rtry/max-retries 6)
|
|
||||||
(assoc ::rtry/label "persist-audit-log"))]
|
|
||||||
(rtry/invoke! cfg db/tx-run! handle-event! event))
|
|
||||||
(catch Throwable cause
|
|
||||||
(l/error :hint "unexpected error processing event" :cause cause))))
|
|
||||||
|
|
||||||
(defn insert!
|
|
||||||
"Submit audit event to the collector, intended to be used only from
|
"Submit audit event to the collector, intended to be used only from
|
||||||
command line helpers because this skips all webhooks and telemetry
|
command line helpers because this skips all webhooks and telemetry
|
||||||
logic."
|
logic."
|
||||||
[cfg event]
|
[cfg event]
|
||||||
(when (contains? cf/flags :audit-log)
|
(when (contains? cf/flags :audit-log)
|
||||||
(let [event (-> (d/without-nils event)
|
|
||||||
(check-event))]
|
|
||||||
(db/run! cfg (fn [cfg]
|
|
||||||
(let [tnow (ct/now)
|
(let [tnow (ct/now)
|
||||||
params (-> (event->params event)
|
event (-> event
|
||||||
(assoc :created-at tnow)
|
(assoc :created-at tnow)
|
||||||
(update :tracked-at #(or % tnow)))]
|
(update :tracked-at d/nilv tnow)
|
||||||
(append-audit-entry cfg params)))))))
|
(update :profile-id d/nilv uuid/zero)
|
||||||
|
(update :props d/nilv {})
|
||||||
|
(update :context d/nilv {})
|
||||||
|
(assoc :source "backend")
|
||||||
|
(select-keys event-keys)
|
||||||
|
(check-event))]
|
||||||
|
(db/run! cfg append-audit-entry event))))
|
||||||
|
|||||||
@ -10,14 +10,11 @@
|
|||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.transit :as t]
|
[app.common.transit :as t]
|
||||||
[app.common.uuid :as uuid]
|
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.http.client :as http]
|
[app.http.client :as http]
|
||||||
[app.setup :as-alias setup]
|
[app.setup :as-alias setup]
|
||||||
[app.tokens :as tokens]
|
|
||||||
[integrant.core :as ig]
|
[integrant.core :as ig]
|
||||||
[lambdaisland.uri :as u]
|
|
||||||
[promesa.exec :as px]))
|
[promesa.exec :as px]))
|
||||||
|
|
||||||
;; This is a task responsible to send the accumulated events to
|
;; This is a task responsible to send the accumulated events to
|
||||||
@ -52,19 +49,18 @@
|
|||||||
|
|
||||||
(defn- send!
|
(defn- send!
|
||||||
[{:keys [::uri] :as cfg} events]
|
[{:keys [::uri] :as cfg} events]
|
||||||
(let [token (tokens/generate cfg
|
(let [skey (-> cfg ::setup/shared-keys :nexus)
|
||||||
{:iss "authentication"
|
|
||||||
:uid uuid/zero})
|
|
||||||
body (t/encode {:events events})
|
body (t/encode {:events events})
|
||||||
headers {"content-type" "application/transit+json"
|
headers {"content-type" "application/transit+json"
|
||||||
"origin" (str (cf/get :public-uri))
|
"origin" (str (cf/get :public-uri))
|
||||||
"cookie" (u/map->query-string {:auth-token token})}
|
"x-shared-key" (str "nexus " skey)}
|
||||||
params {:uri uri
|
params {:uri uri
|
||||||
:timeout 12000
|
:timeout 12000
|
||||||
:method :post
|
:method :post
|
||||||
:headers headers
|
:headers headers
|
||||||
:body body}
|
:body body}
|
||||||
resp (http/req! cfg params)]
|
resp (http/req cfg params {:skip-ssrf-check? true})]
|
||||||
|
|
||||||
(if (= (:status resp) 204)
|
(if (= (:status resp) 204)
|
||||||
true
|
true
|
||||||
(do
|
(do
|
||||||
@ -85,7 +81,7 @@
|
|||||||
(def ^:private sql:get-audit-log-chunk
|
(def ^:private sql:get-audit-log-chunk
|
||||||
"SELECT *
|
"SELECT *
|
||||||
FROM audit_log
|
FROM audit_log
|
||||||
WHERE archived_at is null
|
WHERE archived_at IS NULL
|
||||||
ORDER BY created_at ASC
|
ORDER BY created_at ASC
|
||||||
LIMIT 128
|
LIMIT 128
|
||||||
FOR UPDATE
|
FOR UPDATE
|
||||||
@ -109,7 +105,7 @@
|
|||||||
(def ^:private schema:handler-params
|
(def ^:private schema:handler-params
|
||||||
[:map
|
[:map
|
||||||
::db/pool
|
::db/pool
|
||||||
::setup/props
|
::setup/shared-keys
|
||||||
::http/client])
|
::http/client])
|
||||||
|
|
||||||
(defmethod ig/assert-key ::handler
|
(defmethod ig/assert-key ::handler
|
||||||
|
|||||||
@ -50,9 +50,9 @@
|
|||||||
(ex-data cause))
|
(ex-data cause))
|
||||||
|
|
||||||
ctx (-> context
|
ctx (-> context
|
||||||
(assoc :service/tenant (cf/get :tenant))
|
(assoc :backend/tenant (cf/get :tenant))
|
||||||
(assoc :service/host (cf/get :host))
|
(assoc :backend/host (cf/get :host))
|
||||||
(assoc :service/public-uri (str (cf/get :public-uri)))
|
(assoc :backend/public-uri (str (cf/get :public-uri)))
|
||||||
(assoc :backend/version (:full cf/version))
|
(assoc :backend/version (:full cf/version))
|
||||||
(assoc :logger/name logger)
|
(assoc :logger/name logger)
|
||||||
(assoc :logger/level level)
|
(assoc :logger/level level)
|
||||||
@ -97,7 +97,7 @@
|
|||||||
(l/warn :hint "unexpected exception on database error logger" :cause cause))))
|
(l/warn :hint "unexpected exception on database error logger" :cause cause))))
|
||||||
|
|
||||||
(defn- audit-event->report
|
(defn- audit-event->report
|
||||||
[{:keys [::audit/context ::audit/props ::audit/ip-addr] :as record}]
|
[{:keys [context props ip-addr] :as record}]
|
||||||
(let [context
|
(let [context
|
||||||
(reduce-kv (fn [context k v]
|
(reduce-kv (fn [context k v]
|
||||||
(let [k' (keyword "frontend" (name k))]
|
(let [k' (keyword "frontend" (name k))]
|
||||||
@ -117,14 +117,14 @@
|
|||||||
|
|
||||||
{:context (-> (into (sorted-map) context)
|
{:context (-> (into (sorted-map) context)
|
||||||
(pp/pprint-str :length 50))
|
(pp/pprint-str :length 50))
|
||||||
:origin (::audit/name record)
|
:origin (:name record)
|
||||||
:href (get props :href)
|
:href (get props :href)
|
||||||
:hint (get props :hint)
|
:hint (get props :hint)
|
||||||
:report (get props :report)}))
|
:report (get props :report)}))
|
||||||
|
|
||||||
(defn- handle-audit-event
|
(defn- handle-audit-event
|
||||||
"Convert the log record into a report object and persist it on the database"
|
"Convert the log record into a report object and persist it on the database"
|
||||||
[{:keys [::db/pool]} {:keys [::audit/id] :as event}]
|
[{:keys [::db/pool]} {:keys [id] :as event}]
|
||||||
(try
|
(try
|
||||||
(let [uri (cf/get :public-uri)
|
(let [uri (cf/get :public-uri)
|
||||||
report (-> event audit-event->report d/without-nils)]
|
report (-> event audit-event->report d/without-nils)]
|
||||||
@ -189,12 +189,12 @@
|
|||||||
(::l/id item)
|
(::l/id item)
|
||||||
(handle-log-record cfg item)
|
(handle-log-record cfg item)
|
||||||
|
|
||||||
(::audit/id item)
|
|
||||||
(handle-audit-event cfg item)
|
|
||||||
|
|
||||||
(::rlimit/id item)
|
(::rlimit/id item)
|
||||||
(handle-rlimit-event cfg item)
|
(handle-rlimit-event cfg item)
|
||||||
|
|
||||||
|
(-> item meta ::audit/event)
|
||||||
|
(handle-audit-event cfg item)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(l/warn :hint "received unexpected item" :item item))
|
(l/warn :hint "received unexpected item" :item item))
|
||||||
|
|
||||||
@ -226,4 +226,3 @@
|
|||||||
[cfg event]
|
[cfg event]
|
||||||
(when-let [{:keys [::input]} (get cfg ::reporter)]
|
(when-let [{:keys [::input]} (get cfg ::reporter)]
|
||||||
(sp/put! input event)))
|
(sp/put! input event)))
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@
|
|||||||
trace
|
trace
|
||||||
"```")))
|
"```")))
|
||||||
|
|
||||||
resp (http/req! cfg
|
resp (http/req cfg
|
||||||
{:uri (cf/get :error-report-webhook)
|
{:uri (cf/get :error-report-webhook)
|
||||||
:method :post
|
:method :post
|
||||||
:headers {"content-type" "application/json"}
|
:headers {"content-type" "application/json"}
|
||||||
@ -83,7 +83,7 @@
|
|||||||
:trace (ex/format-throwable cause :detail? false :header? false)}))
|
:trace (ex/format-throwable cause :detail? false :header? false)}))
|
||||||
|
|
||||||
(defn- audit-event->report
|
(defn- audit-event->report
|
||||||
[{:keys [::audit/context ::audit/props ::audit/id] :as event}]
|
[{:keys [context props id] :as event}]
|
||||||
{:id id
|
{:id id
|
||||||
:type "exception"
|
:type "exception"
|
||||||
:origin "audit-log"
|
:origin "audit-log"
|
||||||
@ -92,7 +92,7 @@
|
|||||||
:host (cf/get :host)
|
:host (cf/get :host)
|
||||||
:backend-version (:full cf/version)
|
:backend-version (:full cf/version)
|
||||||
:frontend-version (:version context)
|
:frontend-version (:version context)
|
||||||
:profile-id (:audit/profile-id event)
|
:profile-id (:profile-id event)
|
||||||
:href (get props :href)})
|
:href (get props :href)})
|
||||||
|
|
||||||
(defn- rlimit-event->report
|
(defn- rlimit-event->report
|
||||||
@ -148,12 +148,12 @@
|
|||||||
(::l/id item)
|
(::l/id item)
|
||||||
(handle-event cfg item log-record->report)
|
(handle-event cfg item log-record->report)
|
||||||
|
|
||||||
(::audit/id item)
|
|
||||||
(handle-event cfg item audit-event->report)
|
|
||||||
|
|
||||||
(::rlimit/id item)
|
(::rlimit/id item)
|
||||||
(handle-event cfg item rlimit-event->report)
|
(handle-event cfg item rlimit-event->report)
|
||||||
|
|
||||||
|
(-> item meta ::audit/event)
|
||||||
|
(handle-event cfg item audit-event->report)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(l/warn :hint "received unexpected item" :item item)))
|
(l/warn :hint "received unexpected item" :item item)))
|
||||||
|
|
||||||
|
|||||||
@ -70,14 +70,14 @@
|
|||||||
(fn [{:keys [props] :as task}]
|
(fn [{:keys [props] :as task}]
|
||||||
|
|
||||||
(let [items (lookup-webhooks cfg props)
|
(let [items (lookup-webhooks cfg props)
|
||||||
event {::audit/profile-id (:profile-id props)
|
event {:profile-id (:profile-id props)
|
||||||
::audit/name "webhook"
|
:name "webhook"
|
||||||
::audit/type "trigger"
|
:type "trigger"
|
||||||
::audit/props {:name (get props :name)
|
:props {:name (get props :name)
|
||||||
:event-id (get props :id)
|
:event-id (get props :id)
|
||||||
:total-affected (count items)}}]
|
:total-affected (count items)}}]
|
||||||
|
|
||||||
(audit/insert! cfg event)
|
(audit/insert cfg event)
|
||||||
|
|
||||||
(when items
|
(when items
|
||||||
(l/trc :hint "webhooks found for event" :total (count items))
|
(l/trc :hint "webhooks found for event" :total (count items))
|
||||||
@ -159,7 +159,7 @@
|
|||||||
:method :post
|
:method :post
|
||||||
:body body}]
|
:body body}]
|
||||||
(try
|
(try
|
||||||
(let [rsp (http/req! cfg req {:response-type :input-stream :sync? true})
|
(let [rsp (http/req cfg req {:response-type :input-stream :sync? true})
|
||||||
err (interpret-response rsp)]
|
err (interpret-response rsp)]
|
||||||
(report-delivery! whook req rsp err)
|
(report-delivery! whook req rsp err)
|
||||||
(update-webhook! whook err))
|
(update-webhook! whook err))
|
||||||
@ -190,4 +190,11 @@
|
|||||||
"invalid-uri"
|
"invalid-uri"
|
||||||
|
|
||||||
(instance? java.net.http.HttpConnectTimeoutException cause)
|
(instance? java.net.http.HttpConnectTimeoutException cause)
|
||||||
"timeout"))
|
"timeout"
|
||||||
|
|
||||||
|
:else
|
||||||
|
(let [data (ex-data cause)]
|
||||||
|
(if (and (= :validation (:type data))
|
||||||
|
(= :ssrf-blocked-target (:code data)))
|
||||||
|
(str "blocked-request:" (:hint data))
|
||||||
|
nil))))
|
||||||
|
|||||||
@ -306,8 +306,9 @@
|
|||||||
:app.http.assets/routes
|
:app.http.assets/routes
|
||||||
{::http.assets/path (cf/get :assets-path)
|
{::http.assets/path (cf/get :assets-path)
|
||||||
::http.assets/cache-max-age (ct/duration {:hours 24})
|
::http.assets/cache-max-age (ct/duration {:hours 24})
|
||||||
::http.assets/cache-max-agesignature-max-age (ct/duration {:hours 24 :minutes 5})
|
::http.assets/signature-max-age (ct/duration {:hours 24 :minutes 15})
|
||||||
::sto/storage (ig/ref ::sto/storage)}
|
::sto/storage (ig/ref ::sto/storage)
|
||||||
|
::session/manager (ig/ref ::session/manager)}
|
||||||
|
|
||||||
::rpc/climit
|
::rpc/climit
|
||||||
{::mtx/metrics (ig/ref ::mtx/metrics)
|
{::mtx/metrics (ig/ref ::mtx/metrics)
|
||||||
@ -388,6 +389,7 @@
|
|||||||
:offload-file-data (ig/ref :app.tasks.offload-file-data/handler)
|
:offload-file-data (ig/ref :app.tasks.offload-file-data/handler)
|
||||||
:tasks-gc (ig/ref :app.tasks.tasks-gc/handler)
|
:tasks-gc (ig/ref :app.tasks.tasks-gc/handler)
|
||||||
:telemetry (ig/ref :app.tasks.telemetry/handler)
|
:telemetry (ig/ref :app.tasks.telemetry/handler)
|
||||||
|
:upload-session-gc (ig/ref :app.tasks.upload-session-gc/handler)
|
||||||
:storage-gc-deleted (ig/ref ::sto.gc-deleted/handler)
|
:storage-gc-deleted (ig/ref ::sto.gc-deleted/handler)
|
||||||
:storage-gc-touched (ig/ref ::sto.gc-touched/handler)
|
:storage-gc-touched (ig/ref ::sto.gc-touched/handler)
|
||||||
:session-gc (ig/ref ::session.tasks/gc)
|
:session-gc (ig/ref ::session.tasks/gc)
|
||||||
@ -423,6 +425,9 @@
|
|||||||
:app.tasks.tasks-gc/handler
|
:app.tasks.tasks-gc/handler
|
||||||
{::db/pool (ig/ref ::db/pool)}
|
{::db/pool (ig/ref ::db/pool)}
|
||||||
|
|
||||||
|
:app.tasks.upload-session-gc/handler
|
||||||
|
{::db/pool (ig/ref ::db/pool)}
|
||||||
|
|
||||||
:app.tasks.objects-gc/handler
|
:app.tasks.objects-gc/handler
|
||||||
{::db/pool (ig/ref ::db/pool)
|
{::db/pool (ig/ref ::db/pool)
|
||||||
::sto/storage (ig/ref ::sto/storage)}
|
::sto/storage (ig/ref ::sto/storage)}
|
||||||
@ -466,6 +471,7 @@
|
|||||||
|
|
||||||
::setup/shared-keys
|
::setup/shared-keys
|
||||||
{::setup/props (ig/ref ::setup/props)
|
{::setup/props (ig/ref ::setup/props)
|
||||||
|
:nexus (cf/get :nexus-shared-key)
|
||||||
:nitrate (cf/get :nitrate-shared-key)
|
:nitrate (cf/get :nitrate-shared-key)
|
||||||
:exporter (cf/get :exporter-shared-key)}
|
:exporter (cf/get :exporter-shared-key)}
|
||||||
|
|
||||||
@ -473,9 +479,9 @@
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
:app.loggers.audit.archive-task/handler
|
:app.loggers.audit.archive-task/handler
|
||||||
{::setup/props (ig/ref ::setup/props)
|
{::setup/shared-keys (ig/ref ::setup/shared-keys)
|
||||||
::db/pool (ig/ref ::db/pool)
|
::http.client/client (ig/ref ::http.client/client)
|
||||||
::http.client/client (ig/ref ::http.client/client)}
|
::db/pool (ig/ref ::db/pool)}
|
||||||
|
|
||||||
:app.loggers.audit.gc-task/handler
|
:app.loggers.audit.gc-task/handler
|
||||||
{::db/pool (ig/ref ::db/pool)}
|
{::db/pool (ig/ref ::db/pool)}
|
||||||
@ -543,6 +549,9 @@
|
|||||||
{:cron #penpot/cron "0 0 0 * * ?" ;; daily
|
{:cron #penpot/cron "0 0 0 * * ?" ;; daily
|
||||||
:task :tasks-gc}
|
:task :tasks-gc}
|
||||||
|
|
||||||
|
{:cron #penpot/cron "0 0 0 * * ?" ;; daily
|
||||||
|
:task :upload-session-gc}
|
||||||
|
|
||||||
{:cron #penpot/cron "0 0 2 * * ?" ;; daily
|
{:cron #penpot/cron "0 0 2 * * ?" ;; daily
|
||||||
:task :file-gc-scheduler}
|
:task :file-gc-scheduler}
|
||||||
|
|
||||||
@ -650,9 +659,8 @@
|
|||||||
[& _args]
|
[& _args]
|
||||||
(try
|
(try
|
||||||
(let [p (promise)]
|
(let [p (promise)]
|
||||||
(when (contains? cf/flags :nrepl-server)
|
|
||||||
(l/inf :hint "start nrepl server" :port 6064)
|
(l/inf :hint "start nrepl server" :port 6064)
|
||||||
(nrepl/start-server :bind "0.0.0.0" :port 6064))
|
(nrepl/start-server :bind "0.0.0.0" :port 6064)
|
||||||
|
|
||||||
(start)
|
(start)
|
||||||
(deref p))
|
(deref p))
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as-alias db]
|
[app.db :as-alias db]
|
||||||
[app.http.client :as http]
|
[app.http.client :as http]
|
||||||
|
[app.media.sanitize :as sanitize]
|
||||||
[app.storage :as-alias sto]
|
[app.storage :as-alias sto]
|
||||||
[app.storage.tmp :as tmp]
|
[app.storage.tmp :as tmp]
|
||||||
[buddy.core.bytes :as bb]
|
[buddy.core.bytes :as bb]
|
||||||
@ -54,7 +55,7 @@
|
|||||||
[:path ::fs/path]
|
[:path ::fs/path]
|
||||||
[:mtype {:optional true} ::sm/text]])
|
[:mtype {:optional true} ::sm/text]])
|
||||||
|
|
||||||
(def ^:private check-input
|
(def check-input
|
||||||
(sm/check-fn schema:input))
|
(sm/check-fn schema:input))
|
||||||
|
|
||||||
(defn validate-media-type!
|
(defn validate-media-type!
|
||||||
@ -325,9 +326,11 @@
|
|||||||
|
|
||||||
(let [{:keys [body] :as response}
|
(let [{:keys [body] :as response}
|
||||||
(try
|
(try
|
||||||
(http/req! client
|
(http/req-with-redirects
|
||||||
|
client
|
||||||
{:method :get :uri uri}
|
{:method :get :uri uri}
|
||||||
{:response-type :input-stream})
|
{:response-type :input-stream
|
||||||
|
:max-redirects 3})
|
||||||
(catch java.net.ConnectException cause
|
(catch java.net.ConnectException cause
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :unable-to-download-image
|
:code :unable-to-download-image
|
||||||
@ -358,9 +361,11 @@
|
|||||||
:code :mismatch-write-size
|
:code :mismatch-write-size
|
||||||
:hint "unexpected state: unable to write to file"))
|
:hint "unexpected state: unable to write to file"))
|
||||||
|
|
||||||
{;; :size size
|
;; Sanitize: strip trailing data after image EOF markers
|
||||||
:path path
|
(let [new-size (sanitize/truncate-after-eof path mtype)]
|
||||||
:mtype mtype})))
|
{:path path
|
||||||
|
:mtype mtype
|
||||||
|
:size new-size}))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; FONTS
|
;; FONTS
|
||||||
@ -409,6 +414,22 @@
|
|||||||
(when (zero? (:exit res))
|
(when (zero? (:exit res))
|
||||||
(:out res))))
|
(:out res))))
|
||||||
|
|
||||||
|
(woff2->sfnt [data]
|
||||||
|
;; woff2_decompress outputs to same directory with .ttf extension
|
||||||
|
(let [finput (tmp/tempfile :prefix "penpot.font." :suffix ".woff2")
|
||||||
|
foutput (fs/path (str/replace (str finput) #"\.woff2$" ".ttf"))]
|
||||||
|
(try
|
||||||
|
(io/write* finput data)
|
||||||
|
(let [res (sh/sh "woff2_decompress" (str finput))]
|
||||||
|
(if (zero? (:exit res))
|
||||||
|
foutput
|
||||||
|
(do
|
||||||
|
(when (fs/exists? foutput)
|
||||||
|
(fs/delete foutput))
|
||||||
|
nil)))
|
||||||
|
(finally
|
||||||
|
(fs/delete finput)))))
|
||||||
|
|
||||||
;; Documented here:
|
;; Documented here:
|
||||||
;; https://docs.microsoft.com/en-us/typography/opentype/spec/otff#table-directory
|
;; https://docs.microsoft.com/en-us/typography/opentype/spec/otff#table-directory
|
||||||
(get-sfnt-type [data]
|
(get-sfnt-type [data]
|
||||||
@ -458,4 +479,27 @@
|
|||||||
|
|
||||||
(= stype :ttf)
|
(= stype :ttf)
|
||||||
(-> (assoc "font/otf" (ttf->otf sfnt))
|
(-> (assoc "font/otf" (ttf->otf sfnt))
|
||||||
(assoc "font/ttf" sfnt)))))))))
|
(assoc "font/ttf" sfnt)))))
|
||||||
|
|
||||||
|
(contains? current "font/woff2")
|
||||||
|
(let [data (get input "font/woff2")
|
||||||
|
foutput (woff2->sfnt data)]
|
||||||
|
(when-not foutput
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :invalid-woff2-file
|
||||||
|
:hint "invalid woff2 file"))
|
||||||
|
(try
|
||||||
|
(let [sfnt (io/read* foutput)
|
||||||
|
type (get-sfnt-type sfnt)]
|
||||||
|
(cond-> input
|
||||||
|
(= type :otf)
|
||||||
|
(-> (assoc "font/otf" sfnt)
|
||||||
|
(assoc "font/ttf" (otf->ttf sfnt))
|
||||||
|
(update "font/woff" gen-if-nil #(ttf-or-otf->woff sfnt)))
|
||||||
|
|
||||||
|
(= type :ttf)
|
||||||
|
(-> (assoc "font/ttf" sfnt)
|
||||||
|
(assoc "font/otf" (ttf->otf sfnt))
|
||||||
|
(update "font/woff" gen-if-nil #(ttf-or-otf->woff sfnt)))))
|
||||||
|
(finally
|
||||||
|
(fs/delete foutput))))))))
|
||||||
|
|||||||
191
backend/src/app/media/sanitize.clj
Normal file
191
backend/src/app/media/sanitize.clj
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.media.sanitize
|
||||||
|
"Image EOF truncation helpers — strips trailing data after image EOF
|
||||||
|
markers to prevent exfiltration of non-image bytes appended to
|
||||||
|
valid image files."
|
||||||
|
(:require
|
||||||
|
[app.common.buffer :as buf]
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.logging :as l]
|
||||||
|
[app.util.nio :as nio])
|
||||||
|
(:import
|
||||||
|
java.nio.ByteOrder
|
||||||
|
java.nio.channels.FileChannel))
|
||||||
|
|
||||||
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
|
(defn- scan-backwards
|
||||||
|
"Scan byte array `arr` backwards (from the end) for the byte pattern
|
||||||
|
`marker`. Returns the index in `arr` where the marker starts, or -1
|
||||||
|
if not found."
|
||||||
|
[^bytes arr ^bytes marker]
|
||||||
|
(let [arr-len (alength arr)
|
||||||
|
marker-len (alength marker)]
|
||||||
|
(loop [i (- arr-len marker-len)]
|
||||||
|
(if (< i 0)
|
||||||
|
-1
|
||||||
|
(if (loop [j 0]
|
||||||
|
(if (>= j marker-len)
|
||||||
|
true
|
||||||
|
(if (= (aget arr (+ i j)) (aget marker j))
|
||||||
|
(recur (inc j))
|
||||||
|
false)))
|
||||||
|
i
|
||||||
|
(recur (dec i)))))))
|
||||||
|
|
||||||
|
(defn- find-last-png-iend
|
||||||
|
"Find the byte offset of the end of the PNG IEND chunk (12 bytes:
|
||||||
|
4-byte length + 4-byte 'IEND' + 4-byte CRC32). Returns the offset
|
||||||
|
AFTER the CRC32, or nil if not found."
|
||||||
|
[^FileChannel channel]
|
||||||
|
(let [size (nio/channel-size channel)]
|
||||||
|
(when (> size 8)
|
||||||
|
(let [buf-size (min (int size) (* 1024 1024))
|
||||||
|
marker (byte-array [0x49 0x45 0x4E 0x44])] ;; "IEND"
|
||||||
|
(loop [pos (max 0 (- size buf-size))]
|
||||||
|
(when (< pos size)
|
||||||
|
(let [arr (nio/read-at channel pos buf-size)
|
||||||
|
idx (scan-backwards arr marker)]
|
||||||
|
(if (neg? idx)
|
||||||
|
;; Not found in this chunk, try earlier
|
||||||
|
(let [next-pos (max 0 (- pos (- buf-size 4)))]
|
||||||
|
(when (< next-pos pos)
|
||||||
|
(recur next-pos)))
|
||||||
|
;; Found "IEND" at idx. Chunk starts 4 bytes before.
|
||||||
|
(let [chunk-start (- (+ pos idx) 4)]
|
||||||
|
(when (>= chunk-start 0)
|
||||||
|
;; PNG chunk length is big-endian (network byte order).
|
||||||
|
;; buf/wrap defaults to little-endian, so set it to big-endian.
|
||||||
|
(let [len-arr (nio/read-at channel chunk-start 4)
|
||||||
|
len-buf (buf/set-order (buf/wrap len-arr) ByteOrder/BIG_ENDIAN)
|
||||||
|
chunk-len (buf/read-int len-buf 0)]
|
||||||
|
(when (zero? chunk-len)
|
||||||
|
(+ chunk-start 12)))))))))))))
|
||||||
|
|
||||||
|
(defn- find-last-jpeg-eoi
|
||||||
|
"Find the byte offset of the last JPEG EOI marker (0xFF 0xD9).
|
||||||
|
Returns the offset AFTER the marker, or nil if not found."
|
||||||
|
[^FileChannel channel]
|
||||||
|
(let [size (nio/channel-size channel)]
|
||||||
|
(when (> size 2)
|
||||||
|
(let [buf-size (min (int size) (* 1024 1024))
|
||||||
|
marker (byte-array [(unchecked-byte 0xFF) (unchecked-byte 0xD9)])]
|
||||||
|
(loop [pos (max 0 (- size buf-size))]
|
||||||
|
(when (< pos size)
|
||||||
|
(let [arr (nio/read-at channel pos buf-size)
|
||||||
|
idx (scan-backwards arr marker)]
|
||||||
|
(if (neg? idx)
|
||||||
|
(let [next-pos (max 0 (- pos (- buf-size 2)))]
|
||||||
|
(when (< next-pos pos)
|
||||||
|
(recur next-pos)))
|
||||||
|
(+ pos idx 2)))))))))
|
||||||
|
|
||||||
|
(defn- find-last-gif-trailer
|
||||||
|
"Find the byte offset immediately after the last GIF trailer byte (0x3B).
|
||||||
|
Scans backwards through the file so that appended data after the real
|
||||||
|
trailer is truncated even when it ends with 0x3B.
|
||||||
|
Returns the offset AFTER the trailer byte, or nil if 0x3B is not found."
|
||||||
|
[^FileChannel channel]
|
||||||
|
(let [size (nio/channel-size channel)]
|
||||||
|
(when (pos? size)
|
||||||
|
(let [buf-size (min (int size) (* 1024 1024))
|
||||||
|
marker (byte-array [(unchecked-byte 0x3B)])]
|
||||||
|
(loop [pos (max 0 (- size buf-size))]
|
||||||
|
(when (< pos size)
|
||||||
|
(let [arr (nio/read-at channel pos buf-size)
|
||||||
|
idx (scan-backwards arr marker)]
|
||||||
|
(if (neg? idx)
|
||||||
|
(let [next-pos (max 0 (- pos (- buf-size 1)))]
|
||||||
|
(when (< next-pos pos)
|
||||||
|
(recur next-pos)))
|
||||||
|
(+ pos idx 1)))))))))
|
||||||
|
|
||||||
|
(defn- find-webp-end
|
||||||
|
"Parse the WebP RIFF header to find the declared file size.
|
||||||
|
WebP format: 'RIFF' (4 bytes) + uint32 total-size (4 bytes, little-endian)
|
||||||
|
+ 'WEBP' (4 bytes). The total size is the offset of the end of the file.
|
||||||
|
Returns nil if the RIFF or WEBP magic bytes are missing."
|
||||||
|
[^FileChannel channel]
|
||||||
|
(let [size (nio/channel-size channel)]
|
||||||
|
(when (>= size 12)
|
||||||
|
(let [^bytes arr (nio/read-at channel 0 12)
|
||||||
|
buf (buf/wrap arr)]
|
||||||
|
;; Check RIFF magic (bytes 0-3) AND WEBP FourCC (bytes 8-11)
|
||||||
|
(when (and (= (aget arr 0) (byte 0x52)) ;; 'R'
|
||||||
|
(= (aget arr 1) (byte 0x49)) ;; 'I'
|
||||||
|
(= (aget arr 2) (byte 0x46)) ;; 'F'
|
||||||
|
(= (aget arr 3) (byte 0x46)) ;; 'F'
|
||||||
|
(= (aget arr 8) (byte 0x57)) ;; 'W'
|
||||||
|
(= (aget arr 9) (byte 0x45)) ;; 'E'
|
||||||
|
(= (aget arr 10) (byte 0x42)) ;; 'B'
|
||||||
|
(= (aget arr 11) (byte 0x50))) ;; 'P'
|
||||||
|
(let [riff-size (bit-and (buf/read-int buf 4) 0xFFFFFFFF)]
|
||||||
|
;; RIFF size field is the size of the file minus 8 bytes
|
||||||
|
(+ riff-size 8)))))))
|
||||||
|
|
||||||
|
(defn truncate-after-eof
|
||||||
|
"Given a `java.nio.file.Path` to a freshly-downloaded media file and a
|
||||||
|
declared MIME type, truncate the file in place to the position of the
|
||||||
|
format's EOF marker:
|
||||||
|
- image/png → end of the IEND chunk (12 bytes: 4-byte length + 4-byte type + 4-byte CRC32)
|
||||||
|
- image/jpeg → 2 bytes after FFD9
|
||||||
|
- image/gif → immediately after the last GIF trailer byte 0x3B
|
||||||
|
- image/webp → end of RIFF chunk declared in bytes 4..8
|
||||||
|
- image/svg+xml → no-op (text format; processed by SAX parser)
|
||||||
|
- other → no-op (return path unchanged)
|
||||||
|
Returns the new file size. Raises `:validation/:invalid-image` if no
|
||||||
|
EOF marker is found within the file."
|
||||||
|
[^java.nio.file.Path path ^String mtype]
|
||||||
|
(try
|
||||||
|
(with-open [channel (nio/open-channel path)]
|
||||||
|
(let [size (nio/channel-size channel)]
|
||||||
|
(if (zero? size)
|
||||||
|
0
|
||||||
|
(let [needs-eof-marker? (or (= mtype "image/png")
|
||||||
|
(= mtype "image/jpeg")
|
||||||
|
(= mtype "image/gif")
|
||||||
|
(= mtype "image/webp"))
|
||||||
|
|
||||||
|
eof-offset
|
||||||
|
(cond
|
||||||
|
(= mtype "image/png") (find-last-png-iend channel)
|
||||||
|
(= mtype "image/jpeg") (find-last-jpeg-eoi channel)
|
||||||
|
(= mtype "image/gif") (find-last-gif-trailer channel)
|
||||||
|
(= mtype "image/webp") (find-webp-end channel)
|
||||||
|
:else nil)]
|
||||||
|
|
||||||
|
(cond
|
||||||
|
;; No EOF marker applicable (SVG or other) — no-op
|
||||||
|
(nil? eof-offset)
|
||||||
|
(if needs-eof-marker?
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :invalid-image
|
||||||
|
:hint "image format EOF marker not found")
|
||||||
|
size)
|
||||||
|
|
||||||
|
;; Truncate if needed
|
||||||
|
(< eof-offset size)
|
||||||
|
(do
|
||||||
|
(l/dbg :hint "truncating trailing data"
|
||||||
|
:path (str path)
|
||||||
|
:mtype mtype
|
||||||
|
:original-size size
|
||||||
|
:truncated-to eof-offset)
|
||||||
|
(nio/truncate channel eof-offset)
|
||||||
|
eof-offset)
|
||||||
|
|
||||||
|
;; Already at correct size or marker at end
|
||||||
|
:else
|
||||||
|
eof-offset)))))
|
||||||
|
(catch Exception e
|
||||||
|
(if (ex/exception? e)
|
||||||
|
(throw e)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :invalid-image
|
||||||
|
:hint "failed to sanitize image"
|
||||||
|
:cause e)))))
|
||||||
@ -463,8 +463,25 @@
|
|||||||
:fn (mg/resource "app/migrations/sql/0144-mod-server-error-report-table.sql")}
|
:fn (mg/resource "app/migrations/sql/0144-mod-server-error-report-table.sql")}
|
||||||
|
|
||||||
{:name "0145-fix-plugins-uri-on-profile"
|
{:name "0145-fix-plugins-uri-on-profile"
|
||||||
:fn mg0145/migrate}])
|
:fn mg0145/migrate}
|
||||||
|
|
||||||
|
{:name "0145-mod-audit-log-table"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0145-mod-audit-log-table.sql")}
|
||||||
|
|
||||||
|
{:name "0146-mod-audit-log-table"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0146-mod-audit-log-table.sql")}
|
||||||
|
|
||||||
|
{:name "0146-mod-access-token-table"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0146-mod-access-token-table.sql")}
|
||||||
|
|
||||||
|
{:name "0147-mod-team-invitation-table"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0147-mod-team-invitation-table.sql")}
|
||||||
|
|
||||||
|
{:name "0147-add-upload-session-table"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0147-add-upload-session-table.sql")}
|
||||||
|
|
||||||
|
{:name "0148-add-variant-name-team-font-variant"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0148-add-variant-name-team-font-variant.sql")}])
|
||||||
|
|
||||||
(defn apply-migrations!
|
(defn apply-migrations!
|
||||||
[pool name migrations]
|
[pool name migrations]
|
||||||
|
|||||||
@ -58,4 +58,3 @@
|
|||||||
(when (nil? (:data file))
|
(when (nil? (:data file))
|
||||||
(migrate-file conn file)))
|
(migrate-file conn file)))
|
||||||
(db/exec-one! conn ["drop table page cascade;"])))
|
(db/exec-one! conn ["drop table page cascade;"])))
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
-- Add index on audit_log (source, created_at) to support efficient
|
||||||
|
-- queries for the telemetry batch collection mode.
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS audit_log__source__created_at__idx
|
||||||
|
ON audit_log (source, created_at ASC);
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
CREATE INDEX audit_log__created_at__idx ON audit_log(created_at) WHERE archived_at IS NULL;
|
||||||
|
CREATE INDEX audit_log__archived_at__idx ON audit_log(archived_at) WHERE archived_at IS NOT NULL;
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE access_token
|
||||||
|
ADD COLUMN type text NULL;
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
-- Add index on audit_log (source, created_at) to support efficient
|
||||||
|
-- queries for the telemetry batch collection mode.
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS audit_log__source__created_at__idx
|
||||||
|
ON audit_log (source, created_at ASC);
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
CREATE TABLE upload_session (
|
||||||
|
id uuid PRIMARY KEY,
|
||||||
|
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
|
||||||
|
profile_id uuid NOT NULL REFERENCES profile(id) ON DELETE CASCADE,
|
||||||
|
total_chunks integer NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX upload_session__profile_id__idx
|
||||||
|
ON upload_session(profile_id);
|
||||||
|
|
||||||
|
CREATE INDEX upload_session__created_at__idx
|
||||||
|
ON upload_session(created_at);
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
ALTER TABLE team_invitation
|
||||||
|
ADD COLUMN org_id uuid NULL;
|
||||||
|
|
||||||
|
ALTER TABLE team_invitation
|
||||||
|
ALTER COLUMN team_id DROP NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE team_invitation
|
||||||
|
ADD CONSTRAINT team_invitation_team_or_org_not_null
|
||||||
|
CHECK (team_id IS NOT NULL OR org_id IS NOT NULL);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX team_invitation_org_unique
|
||||||
|
ON team_invitation (org_id, email_to)
|
||||||
|
WHERE team_id IS NULL;
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE team_font_variant
|
||||||
|
ADD COLUMN variant_name text NULL;
|
||||||
@ -1,13 +1,24 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
(ns app.nitrate
|
(ns app.nitrate
|
||||||
"Module that make calls to the external nitrate aplication"
|
"Module that make calls to the external nitrate aplication"
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.json :as json]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
|
[app.common.schema.generators :as sg]
|
||||||
|
[app.common.time :as ct]
|
||||||
|
[app.common.types.organization :as cto]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.http.client :as http]
|
[app.http.client :as http]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.setup :as-alias setup]
|
[app.setup :as-alias setup]
|
||||||
[app.util.json :as json]
|
|
||||||
[clojure.core :as c]
|
[clojure.core :as c]
|
||||||
[integrant.core :as ig]))
|
[integrant.core :as ig]))
|
||||||
|
|
||||||
@ -16,16 +27,16 @@
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn- request-builder
|
(defn- request-builder
|
||||||
[cfg method uri shared-key profile-id]
|
[cfg method uri shared-key profile-id request-params]
|
||||||
(fn []
|
(fn []
|
||||||
(http/req! cfg {:method method
|
(http/req cfg (cond-> {:method method
|
||||||
:headers {"content-type" "application/json"
|
:headers {"content-type" "application/json"
|
||||||
"accept" "application/json"
|
"accept" "application/json"
|
||||||
"x-shared-key" shared-key
|
"x-shared-key" shared-key
|
||||||
"x-profile-id" (str profile-id)}
|
"x-profile-id" (str profile-id)}
|
||||||
:uri uri
|
:uri uri
|
||||||
:version :http1.1})))
|
:version :http1.1}
|
||||||
|
(= method :post) (assoc :body (json/encode request-params :key-fn json/write-camel-key))))))
|
||||||
|
|
||||||
(defn- with-retries
|
(defn- with-retries
|
||||||
[handler max-retries]
|
[handler max-retries]
|
||||||
@ -45,24 +56,49 @@
|
|||||||
result)))))
|
result)))))
|
||||||
|
|
||||||
|
|
||||||
(defn- with-validate [handler uri schema]
|
(defn- with-validate [handler uri schema & {:keys [throw-on-error?]}]
|
||||||
(fn []
|
(fn []
|
||||||
|
(let [response (handler)
|
||||||
|
status (:status response)]
|
||||||
|
(when-not status
|
||||||
|
(l/error :hint "could't do the nitrate request, it is probably down"
|
||||||
|
:uri uri)
|
||||||
|
;; TODO decide what to do when Nitrate is inaccesible
|
||||||
|
nil)
|
||||||
|
(cond
|
||||||
|
(>= status 400)
|
||||||
|
;; For error status codes (4xx, 5xx), fail immediately without validation
|
||||||
|
(do
|
||||||
|
(when (not= status 404) ;; Don't need to log 404
|
||||||
|
(l/error :hint "nitrate request failed with error status"
|
||||||
|
:uri uri
|
||||||
|
:status status
|
||||||
|
:body (:body response)))
|
||||||
|
(if throw-on-error?
|
||||||
|
(ex/raise :type :nitrate-http-error
|
||||||
|
:status status
|
||||||
|
:hint (str "nitrate HTTP " status " at " uri))
|
||||||
|
nil))
|
||||||
|
(= status 204) ;; 204 doesn't return any body
|
||||||
|
nil
|
||||||
|
:else ;; For success status codes, validate the response
|
||||||
(let [coercer-http (sm/coercer schema
|
(let [coercer-http (sm/coercer schema
|
||||||
:type :validation
|
:type :validation
|
||||||
:hint (str "invalid data received calling " uri))]
|
:hint (str "invalid data received calling " uri))
|
||||||
|
data (-> response :body (json/decode :key-fn json/read-kebab-key))]
|
||||||
(try
|
(try
|
||||||
(coercer-http (-> (handler) :body json/decode))
|
(coercer-http data)
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
;; TODO Error handling
|
;; TODO Error handling
|
||||||
(l/error :hint "error validating json response" :cause e)
|
(l/error :hint "error validating json response" :cause e)
|
||||||
nil)))))
|
nil)))))))
|
||||||
|
|
||||||
(defn- request-to-nitrate
|
(defn- request-to-nitrate
|
||||||
[cfg method uri schema {:keys [::rpc/profile-id] :as params}]
|
[cfg method uri schema {:keys [::rpc/profile-id request-params throw-on-error?] :as params}]
|
||||||
(let [shared-key (-> cfg ::setup/shared-keys :nitrate)
|
(let [shared-key (-> cfg ::setup/shared-keys :nitrate)
|
||||||
full-http-call (-> (request-builder cfg method uri shared-key profile-id)
|
full-http-call (-> (request-builder cfg method uri shared-key profile-id request-params)
|
||||||
(with-retries 3)
|
(with-retries 3)
|
||||||
(with-validate uri schema))]
|
(with-validate uri schema :throw-on-error? throw-on-error?))]
|
||||||
(full-http-call)))
|
(full-http-call)))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -78,24 +114,263 @@
|
|||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(def ^:private schema:organization
|
(def ^:private schema:org-summary
|
||||||
[:map
|
[:map
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:name ::sm/text]
|
||||||
|
[:owner-id ::sm/uuid]
|
||||||
|
[:teams
|
||||||
|
[:vector
|
||||||
|
[:map
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:is-your-penpot :boolean]]]]])
|
||||||
|
|
||||||
|
(def ^:private schema:profile-org
|
||||||
|
[:map
|
||||||
|
[:is-member :boolean]
|
||||||
|
[:organization-id {:optional true} [:maybe ::sm/uuid]]
|
||||||
|
[:default-team-id {:optional true} [:maybe ::sm/uuid]]])
|
||||||
|
|
||||||
|
|
||||||
|
;; TODO Unify with schemas on backend/src/app/http/management.clj
|
||||||
|
(def ^:private schema:timestamp
|
||||||
|
(sm/type-schema
|
||||||
|
{:type ::timestamp
|
||||||
|
:pred ct/inst?
|
||||||
|
:type-properties
|
||||||
|
{:title "inst"
|
||||||
|
:description "The same as :app.common.time/inst but encodes to epoch"
|
||||||
|
:error/message "should be an instant"
|
||||||
|
:gen/gen (->> (sg/small-int)
|
||||||
|
(sg/fmap (fn [v] (ct/inst v))))
|
||||||
|
:decode/string ct/inst
|
||||||
|
:encode/string inst-ms
|
||||||
|
:decode/json ct/inst
|
||||||
|
:encode/json inst-ms}}))
|
||||||
|
|
||||||
|
(def ^:private schema:subscription
|
||||||
|
[:map {:title "Subscription"}
|
||||||
[:id ::sm/text]
|
[:id ::sm/text]
|
||||||
[:name ::sm/text]])
|
[:customer-id ::sm/text]
|
||||||
|
[:type [:enum
|
||||||
|
"unlimited"
|
||||||
|
"professional"
|
||||||
|
"enterprise"
|
||||||
|
"nitrate"]]
|
||||||
|
[:status [:enum
|
||||||
|
"active"
|
||||||
|
"canceled"
|
||||||
|
"incomplete"
|
||||||
|
"incomplete_expired"
|
||||||
|
"past_due"
|
||||||
|
"paused"
|
||||||
|
"trialing"
|
||||||
|
"unpaid"]]
|
||||||
|
|
||||||
(def ^:private schema:user
|
[:billing-period [:enum
|
||||||
|
"month"
|
||||||
|
"day"
|
||||||
|
"week"
|
||||||
|
"year"]]
|
||||||
|
[:manual :boolean]
|
||||||
|
[:quantity :int]
|
||||||
|
[:description [:maybe ::sm/text]]
|
||||||
|
[:created-at schema:timestamp]
|
||||||
|
[:start-date [:maybe schema:timestamp]]
|
||||||
|
[:ended-at [:maybe schema:timestamp]]
|
||||||
|
[:trial-end [:maybe schema:timestamp]]
|
||||||
|
[:trial-start [:maybe schema:timestamp]]
|
||||||
|
[:cancel-at [:maybe schema:timestamp]]
|
||||||
|
[:canceled-at [:maybe schema:timestamp]]
|
||||||
|
[:current-period-end [:maybe schema:timestamp]]
|
||||||
|
[:current-period-start [:maybe schema:timestamp]]
|
||||||
|
[:cancel-at-period-end :boolean]
|
||||||
|
|
||||||
|
[:cancellation-details
|
||||||
|
[:map {:title "CancellationDetails"}
|
||||||
|
[:comment [:maybe ::sm/text]]
|
||||||
|
[:reason [:maybe ::sm/text]]
|
||||||
|
[:feedback [:maybe
|
||||||
|
[:enum
|
||||||
|
"customer_service"
|
||||||
|
"low_quality"
|
||||||
|
"missing_feature"
|
||||||
|
"other"
|
||||||
|
"switched_service"
|
||||||
|
"too_complex"
|
||||||
|
"too_expensive"
|
||||||
|
"unused"]]]]]])
|
||||||
|
|
||||||
|
(def ^:private schema:connectivity
|
||||||
[:map
|
[:map
|
||||||
[:valid ::sm/boolean]])
|
[:licenses ::sm/boolean]])
|
||||||
|
|
||||||
(defn- get-team-org
|
(defn- get-team-org-api
|
||||||
[cfg {:keys [team-id] :as params}]
|
[cfg {:keys [team-id] :as params}]
|
||||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
(request-to-nitrate cfg :get (str baseuri "/api/teams/" (str team-id)) schema:organization params)))
|
(request-to-nitrate cfg :get
|
||||||
|
(str baseuri
|
||||||
|
"/api/teams/"
|
||||||
|
team-id)
|
||||||
|
cto/schema:team-with-organization params)))
|
||||||
|
|
||||||
(defn- is-valid-user
|
(defn- get-org-membership-api
|
||||||
|
[cfg {:keys [profile-id organization-id] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
|
(request-to-nitrate cfg :get
|
||||||
|
(str baseuri
|
||||||
|
"/api/organizations/"
|
||||||
|
organization-id
|
||||||
|
"/members/"
|
||||||
|
profile-id)
|
||||||
|
schema:profile-org params)))
|
||||||
|
|
||||||
|
(defn- get-org-membership-by-team-api
|
||||||
|
[cfg {:keys [profile-id team-id] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
|
(request-to-nitrate cfg :get
|
||||||
|
(str baseuri
|
||||||
|
"/api/teams/"
|
||||||
|
team-id
|
||||||
|
"/users/"
|
||||||
|
profile-id)
|
||||||
|
schema:profile-org params)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn- get-org-summary-api
|
||||||
|
[cfg {:keys [organization-id] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
|
(request-to-nitrate cfg :get
|
||||||
|
(str baseuri
|
||||||
|
"/api/organizations/"
|
||||||
|
organization-id
|
||||||
|
"/summary")
|
||||||
|
schema:org-summary params)))
|
||||||
|
|
||||||
|
(defn- get-owned-orgs-api
|
||||||
[cfg {:keys [profile-id] :as params}]
|
[cfg {:keys [profile-id] :as params}]
|
||||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
(request-to-nitrate cfg :get (str baseuri "/api/users/" (str profile-id)) schema:user params)))
|
(request-to-nitrate cfg :get
|
||||||
|
(str baseuri
|
||||||
|
"/api/users/"
|
||||||
|
profile-id
|
||||||
|
"/owned-organizations")
|
||||||
|
[:vector schema:org-summary]
|
||||||
|
params)))
|
||||||
|
|
||||||
|
(defn- set-team-org-api
|
||||||
|
[cfg {:keys [organization-id team-id is-default] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)
|
||||||
|
params (assoc params :request-params {:team-id team-id
|
||||||
|
:is-your-penpot (true? is-default)})
|
||||||
|
team (request-to-nitrate cfg :post
|
||||||
|
(str baseuri
|
||||||
|
"/api/organizations/"
|
||||||
|
organization-id
|
||||||
|
"/add-team")
|
||||||
|
cto/schema:team-with-organization params)
|
||||||
|
custom-photo (when-let [logo-id (dm/get-in team [:organization :logo-id])]
|
||||||
|
(str (cf/get :public-uri) "/assets/by-id/" logo-id))]
|
||||||
|
(cond-> team
|
||||||
|
custom-photo
|
||||||
|
(assoc-in [:organization :custom-photo] custom-photo))))
|
||||||
|
|
||||||
|
(defn- add-profile-to-org-api
|
||||||
|
[cfg {:keys [profile-id organization-id team-id email] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)
|
||||||
|
request-params (cond-> {:user-id profile-id :team-id team-id}
|
||||||
|
(some? email) (assoc :email email))
|
||||||
|
params (assoc params :request-params request-params)]
|
||||||
|
(request-to-nitrate cfg :post
|
||||||
|
(str baseuri
|
||||||
|
"/api/organizations/"
|
||||||
|
organization-id
|
||||||
|
"/add-user")
|
||||||
|
schema:profile-org params)))
|
||||||
|
|
||||||
|
(defn- remove-profile-from-org-api
|
||||||
|
[cfg {:keys [profile-id organization-id] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)
|
||||||
|
params (assoc params :request-params {:user-id profile-id})]
|
||||||
|
(request-to-nitrate cfg :post
|
||||||
|
(str baseuri
|
||||||
|
"/api/organizations/"
|
||||||
|
organization-id
|
||||||
|
"/remove-user")
|
||||||
|
nil params)))
|
||||||
|
|
||||||
|
(defn- remove-profile-from-all-orgs-api
|
||||||
|
[cfg {:keys [profile-id] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
|
(request-to-nitrate cfg :post
|
||||||
|
(str baseuri
|
||||||
|
"/api/users/"
|
||||||
|
profile-id
|
||||||
|
"/remove-organizations")
|
||||||
|
nil params)))
|
||||||
|
|
||||||
|
(defn- remove-team-from-org-api
|
||||||
|
[cfg {:keys [team-id organization-id] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)
|
||||||
|
params (assoc params :request-params {:team-id team-id})]
|
||||||
|
(request-to-nitrate cfg :post
|
||||||
|
(str baseuri
|
||||||
|
"/api/organizations/"
|
||||||
|
organization-id
|
||||||
|
"/remove-team")
|
||||||
|
nil params)))
|
||||||
|
|
||||||
|
(defn- delete-team-api
|
||||||
|
[cfg {:keys [team-id] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
|
(request-to-nitrate cfg :delete
|
||||||
|
(str baseuri
|
||||||
|
"/api/teams/"
|
||||||
|
team-id)
|
||||||
|
nil params)))
|
||||||
|
|
||||||
|
(defn- get-subscription-api
|
||||||
|
[cfg {:keys [profile-id] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
|
(request-to-nitrate cfg :get
|
||||||
|
(str baseuri
|
||||||
|
"/api/subscriptions/"
|
||||||
|
profile-id)
|
||||||
|
schema:subscription params)))
|
||||||
|
|
||||||
|
(defn- get-connectivity-api
|
||||||
|
[cfg params]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
|
(request-to-nitrate cfg :get
|
||||||
|
(str baseuri
|
||||||
|
"/api/connectivity")
|
||||||
|
schema:connectivity params)))
|
||||||
|
|
||||||
|
(def ^:private schema:redeem-result
|
||||||
|
[:map
|
||||||
|
[:cancel-at [:maybe schema:timestamp]]])
|
||||||
|
|
||||||
|
(defn- get-org-permissions-api
|
||||||
|
[cfg {:keys [organization-id] :as params}]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
|
(request-to-nitrate cfg :get
|
||||||
|
(str baseuri
|
||||||
|
"/api/organizations/"
|
||||||
|
organization-id
|
||||||
|
"/permissions")
|
||||||
|
[:map
|
||||||
|
[:organization-id ::sm/uuid]
|
||||||
|
[:owner-id ::sm/uuid]
|
||||||
|
[:permissions [:map-of :keyword :string]]]
|
||||||
|
params)))
|
||||||
|
|
||||||
|
(defn- redeem-activation-code-api
|
||||||
|
[cfg params]
|
||||||
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
|
(request-to-nitrate cfg :post
|
||||||
|
(str baseuri "/api/activation-codes/redeem")
|
||||||
|
schema:redeem-result
|
||||||
|
(assoc params :throw-on-error? true))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; INITIALIZATION
|
;; INITIALIZATION
|
||||||
@ -104,8 +379,21 @@
|
|||||||
(defmethod ig/init-key ::client
|
(defmethod ig/init-key ::client
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
(when (contains? cf/flags :nitrate)
|
(when (contains? cf/flags :nitrate)
|
||||||
{:get-team-org (partial get-team-org cfg)
|
{:get-team-org (partial get-team-org-api cfg)
|
||||||
:is-valid-user (partial is-valid-user cfg)}))
|
:set-team-org (partial set-team-org-api cfg)
|
||||||
|
:get-org-membership (partial get-org-membership-api cfg)
|
||||||
|
:get-org-membership-by-team (partial get-org-membership-by-team-api cfg)
|
||||||
|
:get-org-summary (partial get-org-summary-api cfg)
|
||||||
|
:get-owned-orgs (partial get-owned-orgs-api cfg)
|
||||||
|
:add-profile-to-org (partial add-profile-to-org-api cfg)
|
||||||
|
:remove-profile-from-org (partial remove-profile-from-org-api cfg)
|
||||||
|
:remove-profile-from-all-orgs (partial remove-profile-from-all-orgs-api cfg)
|
||||||
|
:get-org-permissions (partial get-org-permissions-api cfg)
|
||||||
|
:delete-team (partial delete-team-api cfg)
|
||||||
|
:remove-team-from-org (partial remove-team-from-org-api cfg)
|
||||||
|
:get-subscription (partial get-subscription-api cfg)
|
||||||
|
:connectivity (partial get-connectivity-api cfg)
|
||||||
|
:redeem-activation-code (partial redeem-activation-code-api cfg)}))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; UTILS
|
;; UTILS
|
||||||
@ -113,18 +401,57 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn add-nitrate-licence-to-profile
|
(defn add-nitrate-licence-to-profile
|
||||||
|
"Enriches a profile map with subscription information from Nitrate.
|
||||||
|
Adds a :subscription field containing the user's license details.
|
||||||
|
Returns the original profile unchanged if the request fails."
|
||||||
[cfg profile]
|
[cfg profile]
|
||||||
(try
|
(try
|
||||||
(let [nitrate-licence (call cfg :is-valid-user {:profile-id (:id profile)})]
|
(let [subscription (call cfg :get-subscription {:profile-id (:id profile)})]
|
||||||
(assoc profile :nitrate-licence (:valid nitrate-licence)))
|
(assoc profile :subscription subscription))
|
||||||
(catch Throwable cause
|
(catch Throwable cause
|
||||||
(l/error :hint "failed to get nitrate licence"
|
(l/error :hint "failed to get nitrate licence"
|
||||||
:profile-id (:id profile)
|
:profile-id (:id profile)
|
||||||
:cause cause)
|
:cause cause)
|
||||||
profile)))
|
profile)))
|
||||||
|
|
||||||
(defn add-org-to-team
|
(defn add-org-info-to-team
|
||||||
|
"Enriches a team map with organization information from Nitrate.
|
||||||
|
Adds organization-id, organization-name, organization-slug, organization-owner-id, and your-penpot fields.
|
||||||
|
Returns the original team unchanged if the request fails or org data is nil."
|
||||||
[cfg team params]
|
[cfg team params]
|
||||||
|
(try
|
||||||
(let [params (assoc (or params {}) :team-id (:id team))
|
(let [params (assoc (or params {}) :team-id (:id team))
|
||||||
org (call cfg :get-team-org params)]
|
team-with-org (call cfg :get-team-org params)
|
||||||
(assoc team :organization-id (:id org) :organization-name (:name org))))
|
org (:organization team-with-org)]
|
||||||
|
(if (some? org)
|
||||||
|
(-> (cto/apply-organization team (assoc org :custom-photo
|
||||||
|
(when-let [logo-id (:logo-id org)]
|
||||||
|
(str (cf/get :public-uri) "/assets/by-id/" logo-id))))
|
||||||
|
(assoc :is-default (or (:is-default team) (true? (:is-your-penpot team-with-org)))))
|
||||||
|
team))
|
||||||
|
(catch Throwable cause
|
||||||
|
(l/error :hint "failed to get team organization info"
|
||||||
|
:team-id (:id team)
|
||||||
|
:cause cause)
|
||||||
|
team)))
|
||||||
|
|
||||||
|
(defn set-team-organization
|
||||||
|
"Associates a team with an organization in Nitrate.
|
||||||
|
Requires organization-id and is-default in params.
|
||||||
|
Throws an exception if the request fails."
|
||||||
|
[cfg team params]
|
||||||
|
(let [params (assoc (or params {})
|
||||||
|
:team-id (:id team)
|
||||||
|
:organization-id (:organization-id params)
|
||||||
|
:is-default (:is-default params))
|
||||||
|
result (call cfg :set-team-org params)]
|
||||||
|
(when (nil? result)
|
||||||
|
(ex/raise :type :internal
|
||||||
|
:code :failed-to-set-team-org
|
||||||
|
:context {:team-id (:id team)
|
||||||
|
:organization-id (:organization-id params)}))
|
||||||
|
team))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -73,9 +73,13 @@
|
|||||||
(if (nil? result)
|
(if (nil? result)
|
||||||
204
|
204
|
||||||
200))
|
200))
|
||||||
headers (cond-> (::http/headers mdata {})
|
|
||||||
(yres/stream-body? result)
|
headers (::http/headers mdata {})
|
||||||
|
headers (cond-> headers
|
||||||
|
(and (yres/stream-body? result)
|
||||||
|
(not (contains? headers "content-type")))
|
||||||
(assoc "content-type" "application/octet-stream"))]
|
(assoc "content-type" "application/octet-stream"))]
|
||||||
|
|
||||||
{::yres/status status
|
{::yres/status status
|
||||||
::yres/headers headers
|
::yres/headers headers
|
||||||
::yres/body result}))]
|
::yres/body result}))]
|
||||||
@ -92,6 +96,7 @@
|
|||||||
(fn [{:keys [params path-params method] :as request}]
|
(fn [{:keys [params path-params method] :as request}]
|
||||||
(let [handler-name (:method-name path-params)
|
(let [handler-name (:method-name path-params)
|
||||||
etag (yreq/get-header request "if-none-match")
|
etag (yreq/get-header request "if-none-match")
|
||||||
|
session-id (yreq/get-header request "x-session-id")
|
||||||
|
|
||||||
key-id (get request ::http/auth-key-id)
|
key-id (get request ::http/auth-key-id)
|
||||||
profile-id (or (::session/profile-id request)
|
profile-id (or (::session/profile-id request)
|
||||||
@ -104,6 +109,8 @@
|
|||||||
(assoc ::handler-name handler-name)
|
(assoc ::handler-name handler-name)
|
||||||
(assoc ::ip-addr ip-addr)
|
(assoc ::ip-addr ip-addr)
|
||||||
(assoc ::request-at (ct/now))
|
(assoc ::request-at (ct/now))
|
||||||
|
(assoc ::request-id (uuid/next))
|
||||||
|
(assoc ::session-id (some-> session-id uuid/parse*))
|
||||||
(assoc ::cond/key etag)
|
(assoc ::cond/key etag)
|
||||||
(cond-> (uuid? profile-id)
|
(cond-> (uuid? profile-id)
|
||||||
(assoc ::profile-id profile-id)))
|
(assoc ::profile-id profile-id)))
|
||||||
@ -159,12 +166,13 @@
|
|||||||
(defn- wrap-audit
|
(defn- wrap-audit
|
||||||
[_ f mdata]
|
[_ f mdata]
|
||||||
(if (or (contains? cf/flags :webhooks)
|
(if (or (contains? cf/flags :webhooks)
|
||||||
(contains? cf/flags :audit-log))
|
(contains? cf/flags :audit-log)
|
||||||
|
(contains? cf/flags :telemetry))
|
||||||
(if-not (::audit/skip mdata)
|
(if-not (::audit/skip mdata)
|
||||||
(fn [cfg params]
|
(fn [cfg params]
|
||||||
(let [result (f cfg params)]
|
(let [result (f cfg params)]
|
||||||
(->> (audit/prepare-event cfg mdata params result)
|
(->> (audit/prepare-rpc-event cfg mdata params result)
|
||||||
(audit/submit! cfg))
|
(audit/submit cfg))
|
||||||
result))
|
result))
|
||||||
f)
|
f)
|
||||||
f))
|
f))
|
||||||
@ -258,6 +266,7 @@
|
|||||||
'app.rpc.commands.ldap
|
'app.rpc.commands.ldap
|
||||||
'app.rpc.commands.management
|
'app.rpc.commands.management
|
||||||
'app.rpc.commands.media
|
'app.rpc.commands.media
|
||||||
|
'app.rpc.commands.nitrate
|
||||||
'app.rpc.commands.profile
|
'app.rpc.commands.profile
|
||||||
'app.rpc.commands.projects
|
'app.rpc.commands.projects
|
||||||
'app.rpc.commands.search
|
'app.rpc.commands.search
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
(dissoc row :perms))
|
(dissoc row :perms))
|
||||||
|
|
||||||
(defn create-access-token
|
(defn create-access-token
|
||||||
[{:keys [::db/conn] :as cfg} profile-id name expiration]
|
[{:keys [::db/conn] :as cfg} profile-id name expiration type]
|
||||||
(let [token-id (uuid/next)
|
(let [token-id (uuid/next)
|
||||||
expires-at (some-> expiration (ct/in-future))
|
expires-at (some-> expiration (ct/in-future))
|
||||||
created-at (ct/now)
|
created-at (ct/now)
|
||||||
@ -36,6 +36,7 @@
|
|||||||
{:id token-id
|
{:id token-id
|
||||||
:name name
|
:name name
|
||||||
:token token
|
:token token
|
||||||
|
:type type
|
||||||
:profile-id profile-id
|
:profile-id profile-id
|
||||||
:created-at created-at
|
:created-at created-at
|
||||||
:updated-at created-at
|
:updated-at created-at
|
||||||
@ -50,17 +51,18 @@
|
|||||||
(def ^:private schema:create-access-token
|
(def ^:private schema:create-access-token
|
||||||
[:map {:title "create-access-token"}
|
[:map {:title "create-access-token"}
|
||||||
[:name [:string {:max 250 :min 1}]]
|
[:name [:string {:max 250 :min 1}]]
|
||||||
[:expiration {:optional true} ::ct/duration]])
|
[:expiration {:optional true} ::ct/duration]
|
||||||
|
[:type {:optional true} :string]])
|
||||||
|
|
||||||
(sv/defmethod ::create-access-token
|
(sv/defmethod ::create-access-token
|
||||||
{::doc/added "1.18"
|
{::doc/added "1.18"
|
||||||
::sm/params schema:create-access-token}
|
::sm/params schema:create-access-token}
|
||||||
[cfg {:keys [::rpc/profile-id name expiration]}]
|
[cfg {:keys [::rpc/profile-id name expiration type]}]
|
||||||
|
|
||||||
(quotes/check! cfg {::quotes/id ::quotes/access-tokens-per-profile
|
(quotes/check! cfg {::quotes/id ::quotes/access-tokens-per-profile
|
||||||
::quotes/profile-id profile-id})
|
::quotes/profile-id profile-id})
|
||||||
|
|
||||||
(db/tx-run! cfg create-access-token profile-id name expiration))
|
(db/tx-run! cfg create-access-token profile-id name expiration type))
|
||||||
|
|
||||||
(def ^:private schema:delete-access-token
|
(def ^:private schema:delete-access-token
|
||||||
[:map {:title "delete-access-token"}
|
[:map {:title "delete-access-token"}
|
||||||
@ -83,5 +85,22 @@
|
|||||||
(->> (db/query pool :access-token
|
(->> (db/query pool :access-token
|
||||||
{:profile-id profile-id}
|
{:profile-id profile-id}
|
||||||
{:order-by [[:expires-at :asc] [:created-at :asc]]
|
{:order-by [[:expires-at :asc] [:created-at :asc]]
|
||||||
:columns [:id :name :perms :created-at :updated-at :expires-at]})
|
:columns [:id :name :perms :type :created-at :updated-at :expires-at]})
|
||||||
(mapv decode-row)))
|
(mapv decode-row)))
|
||||||
|
|
||||||
|
(def ^:private schema:get-current-mcp-token
|
||||||
|
[:map {:title "get-current-mcp-token"}])
|
||||||
|
|
||||||
|
(sv/defmethod ::get-current-mcp-token
|
||||||
|
{::doc/added "2.15"
|
||||||
|
::sm/params schema:get-current-mcp-token}
|
||||||
|
[{:keys [::db/pool]} {:keys [::rpc/profile-id ::rpc/request-at]}]
|
||||||
|
(->> (db/query pool :access-token
|
||||||
|
{:profile-id profile-id
|
||||||
|
:type "mcp"}
|
||||||
|
{:order-by [[:expires-at :asc] [:created-at :asc]]
|
||||||
|
:columns [:token :expires-at]})
|
||||||
|
(remove #(and (some? (:expires-at %))
|
||||||
|
(ct/is-after? request-at (:expires-at %))))
|
||||||
|
(map decode-row)
|
||||||
|
(first)))
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.http :as-alias http]
|
[app.http :as-alias http]
|
||||||
[app.loggers.audit :as-alias audit]
|
[app.loggers.audit :as audit]
|
||||||
[app.loggers.database :as loggers.db]
|
[app.loggers.database :as loggers.db]
|
||||||
[app.loggers.mattermost :as loggers.mm]
|
[app.loggers.mattermost :as loggers.mm]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
@ -23,7 +23,8 @@
|
|||||||
[app.rpc.doc :as-alias doc]
|
[app.rpc.doc :as-alias doc]
|
||||||
[app.rpc.helpers :as rph]
|
[app.rpc.helpers :as rph]
|
||||||
[app.util.inet :as inet]
|
[app.util.inet :as inet]
|
||||||
[app.util.services :as sv]))
|
[app.util.services :as sv]
|
||||||
|
[clojure.set :as set]))
|
||||||
|
|
||||||
(def ^:private event-columns
|
(def ^:private event-columns
|
||||||
[:id
|
[:id
|
||||||
@ -38,31 +39,31 @@
|
|||||||
:context])
|
:context])
|
||||||
|
|
||||||
(defn- event->row [event]
|
(defn- event->row [event]
|
||||||
[(::audit/id event)
|
[(:id event)
|
||||||
(::audit/name event)
|
(:name event)
|
||||||
(::audit/source event)
|
(:source event)
|
||||||
(::audit/type event)
|
(:type event)
|
||||||
(::audit/tracked-at event)
|
(:tracked-at event)
|
||||||
(::audit/created-at event)
|
(:created-at event)
|
||||||
(::audit/profile-id event)
|
(:profile-id event)
|
||||||
(db/inet (::audit/ip-addr event))
|
(db/inet (:ip-addr event))
|
||||||
(db/tjson (::audit/props event))
|
(db/tjson (:props event))
|
||||||
(db/tjson (d/without-nils (::audit/context event)))])
|
(db/tjson (d/without-nils (:context event)))])
|
||||||
|
|
||||||
(defn- adjust-timestamp
|
(defn- adjust-timestamp
|
||||||
[{:keys [::audit/tracked-at ::audit/created-at] :as event}]
|
[{:keys [tracked-at created-at] :as event}]
|
||||||
(let [margin (inst-ms (ct/diff tracked-at created-at))]
|
(let [margin (inst-ms (ct/diff tracked-at created-at))]
|
||||||
(if (or (neg? margin)
|
(if (or (neg? margin)
|
||||||
(> margin 3600000))
|
(> margin 3600000))
|
||||||
;; If event is in future or lags more than 1 hour, we reasign
|
;; If event is in future or lags more than 1 hour, we reasign
|
||||||
;; tracked-at to the server creation date
|
;; tracked-at to the server creation date
|
||||||
(-> event
|
(-> event
|
||||||
(assoc ::audit/tracked-at created-at)
|
(assoc :tracked-at created-at)
|
||||||
(update ::audit/context assoc :original-tracked-at tracked-at))
|
(update :context assoc :original-tracked-at tracked-at))
|
||||||
event)))
|
event)))
|
||||||
|
|
||||||
(defn- exception-event?
|
(defn- exception-event?
|
||||||
[{:keys [::audit/type ::audit/name] :as ev}]
|
[{:keys [type name] :as ev}]
|
||||||
(and (= "action" type)
|
(and (= "action" type)
|
||||||
(or (= "unhandled-exception" name)
|
(or (= "unhandled-exception" name)
|
||||||
(= "exception-page" name))))
|
(= "exception-page" name))))
|
||||||
@ -72,28 +73,44 @@
|
|||||||
(map adjust-timestamp)
|
(map adjust-timestamp)
|
||||||
(map event->row)))
|
(map event->row)))
|
||||||
|
|
||||||
(defn- get-events
|
(defn- prepare-events
|
||||||
[{:keys [::rpc/request-at ::rpc/profile-id events] :as params}]
|
[{:keys [::rpc/request-at ::rpc/profile-id events] :as params}]
|
||||||
(let [request (-> params meta ::http/request)
|
(let [request (-> params meta ::http/request)
|
||||||
ip-addr (inet/parse-request request)
|
ip-addr (inet/parse-request request)
|
||||||
|
xform (comp
|
||||||
xform (map (fn [event]
|
(map (fn [event]
|
||||||
{::audit/id (uuid/next)
|
{:id (uuid/next)
|
||||||
::audit/type (:type event)
|
:type (:type event)
|
||||||
::audit/name (:name event)
|
:name (:name event)
|
||||||
::audit/props (:props event)
|
:props (:props event)
|
||||||
::audit/context (:context event)
|
:context (:context event)
|
||||||
::audit/profile-id profile-id
|
:profile-id profile-id
|
||||||
::audit/ip-addr ip-addr
|
:ip-addr ip-addr
|
||||||
::audit/source "frontend"
|
:source "frontend"
|
||||||
::audit/tracked-at (:timestamp event)
|
:tracked-at (:timestamp event)
|
||||||
::audit/created-at request-at}))]
|
:created-at request-at}))
|
||||||
|
(map (fn [item]
|
||||||
|
(with-meta item {::audit/event true}))))]
|
||||||
|
|
||||||
(sequence xform events)))
|
(sequence xform events)))
|
||||||
|
|
||||||
|
(def ^:private xf:map-telemetry-event-row
|
||||||
|
(comp
|
||||||
|
(map adjust-timestamp)
|
||||||
|
(map (fn [event]
|
||||||
|
(-> event
|
||||||
|
(assoc :id (uuid/next))
|
||||||
|
(update :created-at ct/truncate :days)
|
||||||
|
(update :tracked-at ct/truncate :days)
|
||||||
|
(audit/filter-telemetry-props)
|
||||||
|
(audit/filter-telemetry-context)
|
||||||
|
(assoc :ip-addr "0.0.0.0")
|
||||||
|
(assoc :source "telemetry:frontend"))))
|
||||||
|
(map event->row)))
|
||||||
|
|
||||||
(defn- handle-events
|
(defn- handle-events
|
||||||
[{:keys [::db/pool] :as cfg} params]
|
[{:keys [::db/pool] :as cfg} params]
|
||||||
(let [events (get-events params)]
|
(let [events (prepare-events params)]
|
||||||
|
|
||||||
;; Look for error reports and save them on internal reports table
|
;; Look for error reports and save them on internal reports table
|
||||||
(when-let [events (->> events
|
(when-let [events (->> events
|
||||||
@ -102,9 +119,18 @@
|
|||||||
(run! (partial loggers.db/emit cfg) events)
|
(run! (partial loggers.db/emit cfg) events)
|
||||||
(run! (partial loggers.mm/emit cfg) events))
|
(run! (partial loggers.mm/emit cfg) events))
|
||||||
|
|
||||||
;; Process and save events
|
(when (contains? cf/flags :audit-log)
|
||||||
(when (seq events)
|
;; Process and save full audit events when audit-log flag is active
|
||||||
(let [rows (sequence xf:map-event-row events)]
|
(when-let [rows (-> (sequence xf:map-event-row events)
|
||||||
|
(not-empty))]
|
||||||
|
(db/insert-many! pool :audit-log event-columns rows)))
|
||||||
|
|
||||||
|
(when (contains? cf/flags :telemetry)
|
||||||
|
;; Store anonymized frontend events so the telemetry task can ship them
|
||||||
|
;; in batches. Runs independently from the audit-log insert above so
|
||||||
|
;; both modes can be active simultaneously.
|
||||||
|
(when-let [rows (-> (sequence xf:map-telemetry-event-row events)
|
||||||
|
(not-empty))]
|
||||||
(db/insert-many! pool :audit-log event-columns rows)))))
|
(db/insert-many! pool :audit-log event-columns rows)))))
|
||||||
|
|
||||||
(def ^:private valid-event-types
|
(def ^:private valid-event-types
|
||||||
@ -138,17 +164,26 @@
|
|||||||
::doc/skip true
|
::doc/skip true
|
||||||
::doc/added "1.17"}
|
::doc/added "1.17"}
|
||||||
[{:keys [::db/pool] :as cfg} params]
|
[{:keys [::db/pool] :as cfg} params]
|
||||||
(if (or (db/read-only? pool)
|
(let [telemetry? (contains? cf/flags :telemetry)
|
||||||
(not (contains? cf/flags :audit-log)))
|
audit-log? (contains? cf/flags :audit-log)
|
||||||
(do
|
enabled? (and (not (db/read-only? pool))
|
||||||
(l/warn :hint "audit: http handler disabled or db is read-only")
|
(or audit-log? telemetry?))]
|
||||||
(rph/wrap nil))
|
(when enabled?
|
||||||
|
|
||||||
(do
|
|
||||||
(try
|
(try
|
||||||
(handle-events cfg params)
|
(handle-events cfg params)
|
||||||
(catch Throwable cause
|
(catch Throwable cause
|
||||||
(l/error :hint "unexpected error on persisting audit events from frontend"
|
(l/error :hint "unexpected error on persisting audit events from frontend"
|
||||||
:cause cause)))
|
:cause cause))))
|
||||||
|
|
||||||
(rph/wrap nil))))
|
(rph/wrap nil)))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; GET-ENABLED-FLAGS
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(sv/defmethod ::get-enabled-flags
|
||||||
|
{::audit/skip true
|
||||||
|
::doc/skip true
|
||||||
|
::doc/added "1.20"}
|
||||||
|
[_cfg _params]
|
||||||
|
(set/intersection cf/flags #{:audit-log :telemetry}))
|
||||||
|
|||||||
@ -258,24 +258,44 @@
|
|||||||
(validate-register-attempt! cfg params)
|
(validate-register-attempt! cfg params)
|
||||||
|
|
||||||
(let [email (profile/clean-email email)
|
(let [email (profile/clean-email email)
|
||||||
profile (profile/get-profile-by-email pool email)
|
profile (profile/get-profile-by-email pool email)]
|
||||||
props (-> (audit/extract-utm-params params)
|
|
||||||
|
;; SECURITY: refuse to issue a prepared-register token when an active
|
||||||
|
;; profile already exists for this email.
|
||||||
|
;;
|
||||||
|
;; Active accounts must use the standard login flow; existing-but-
|
||||||
|
;; not-yet-active profiles fall through to the duplicate-detection branch in
|
||||||
|
;; `register-profile`, which never creates a session.
|
||||||
|
(when (and (some? profile)
|
||||||
|
(true? (:is-active profile)))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :email-already-exists
|
||||||
|
:hint "email already exists"))
|
||||||
|
|
||||||
|
(let [props (-> (audit/extract-utm-params params)
|
||||||
(cond-> (:accept-newsletter-updates params)
|
(cond-> (:accept-newsletter-updates params)
|
||||||
(assoc :newsletter-updates true)))
|
(assoc :newsletter-updates true)))
|
||||||
|
;; SECURITY: do NOT embed `:profile-id` of an existing
|
||||||
|
;; profile into the prepared-register JWE. Doing so would
|
||||||
|
;; let an anonymous caller, in possession of a valid
|
||||||
|
;; team-invitation JWE, ask `register-profile` to load that
|
||||||
|
;; profile by id and mint a session for it without password
|
||||||
|
;; verification. `register-profile` independently re-detects
|
||||||
|
;; duplicates by email and handles them in the
|
||||||
|
;; "repeated-registry" branch.
|
||||||
params {:email email
|
params {:email email
|
||||||
:fullname fullname
|
:fullname fullname
|
||||||
:password (:password params)
|
:password (:password params)
|
||||||
:invitation-token (:invitation-token params)
|
:invitation-token (:invitation-token params)
|
||||||
:backend "penpot"
|
:backend "penpot"
|
||||||
:iss :prepared-register
|
:iss :prepared-register
|
||||||
:profile-id (:id profile)
|
|
||||||
:exp (ct/in-future {:days 7})
|
:exp (ct/in-future {:days 7})
|
||||||
:props props}
|
:props props}
|
||||||
params (d/without-nils params)
|
params (d/without-nils params)
|
||||||
token (tokens/generate cfg params)]
|
token (tokens/generate cfg params)]
|
||||||
|
|
||||||
(-> {:token token}
|
(-> {:token token}
|
||||||
(with-meta {::audit/profile-id uuid/zero}))))
|
(with-meta {::audit/profile-id uuid/zero})))))
|
||||||
|
|
||||||
(def schema:prepare-register-profile
|
(def schema:prepare-register-profile
|
||||||
[:map {:title "prepare-register-profile"}
|
[:map {:title "prepare-register-profile"}
|
||||||
@ -372,9 +392,11 @@
|
|||||||
(throw cause))))))
|
(throw cause))))))
|
||||||
|
|
||||||
(defn create-profile-rels
|
(defn create-profile-rels
|
||||||
[conn {:keys [id] :as profile}]
|
[{:keys [::db/conn] :as cfg} {:keys [id] :as profile}]
|
||||||
|
(assert (db/connection-map? cfg)
|
||||||
|
"expected cfg with valid connection")
|
||||||
(let [features (cfeat/get-enabled-features cf/flags)
|
(let [features (cfeat/get-enabled-features cf/flags)
|
||||||
team (teams/create-team conn
|
team (teams/create-team cfg
|
||||||
{:profile-id id
|
{:profile-id id
|
||||||
:name "Default"
|
:name "Default"
|
||||||
:features features
|
:features features
|
||||||
@ -387,12 +409,19 @@
|
|||||||
(profile/decode-row))))
|
(profile/decode-row))))
|
||||||
|
|
||||||
(defn send-email-verification!
|
(defn send-email-verification!
|
||||||
[{:keys [::db/conn] :as cfg} profile]
|
([cfg profile] (send-email-verification! cfg profile nil))
|
||||||
(let [vtoken (tokens/generate cfg
|
([{:keys [::db/conn] :as cfg} profile invitation-token]
|
||||||
{:iss :verify-email
|
(let [vclaims (cond-> {:iss :verify-email
|
||||||
:exp (ct/in-future "72h")
|
:exp (ct/in-future "72h")
|
||||||
:profile-id (:id profile)
|
:profile-id (:id profile)
|
||||||
:email (:email profile)})
|
:email (:email profile)}
|
||||||
|
;; If the user registered through a team-invitation flow but
|
||||||
|
;; their profile is not yet active, we carry the invitation
|
||||||
|
;; token inside the verify-email JWE so the team-invitation
|
||||||
|
;; flow can resume after the user clicks the email link.
|
||||||
|
(some? invitation-token)
|
||||||
|
(assoc :invitation-token invitation-token))
|
||||||
|
vtoken (tokens/generate cfg vclaims)
|
||||||
;; NOTE: this token is mainly used for possible complains
|
;; NOTE: this token is mainly used for possible complains
|
||||||
;; identification on the sns webhook
|
;; identification on the sns webhook
|
||||||
ptoken (tokens/generate cfg
|
ptoken (tokens/generate cfg
|
||||||
@ -405,7 +434,7 @@
|
|||||||
:to (:email profile)
|
:to (:email profile)
|
||||||
:name (:fullname profile)
|
:name (:fullname profile)
|
||||||
:token vtoken
|
:token vtoken
|
||||||
:extra-data ptoken})))
|
:extra-data ptoken}))))
|
||||||
|
|
||||||
(defn register-profile
|
(defn register-profile
|
||||||
[{:keys [::db/conn ::wrk/executor] :as cfg} {:keys [token] :as params}]
|
[{:keys [::db/conn ::wrk/executor] :as cfg} {:keys [token] :as params}]
|
||||||
@ -414,14 +443,7 @@
|
|||||||
(:accept-newsletter-updates params)
|
(:accept-newsletter-updates params)
|
||||||
(update :props assoc :newsletter-updates true))
|
(update :props assoc :newsletter-updates true))
|
||||||
|
|
||||||
profile (if-let [profile-id (:profile-id claims)]
|
profile (or (profile/get-profile-by-email conn (:email claims))
|
||||||
(profile/get-profile conn profile-id)
|
|
||||||
;; NOTE: we first try to match existing profile
|
|
||||||
;; by email, that in normal circumstances will
|
|
||||||
;; not return anything, but when a user tries to
|
|
||||||
;; reuse the same token multiple times, we need
|
|
||||||
;; to detect if the profile is already registered
|
|
||||||
(or (profile/get-profile-by-email conn (:email claims))
|
|
||||||
(let [is-active (or (boolean (:is-active claims))
|
(let [is-active (or (boolean (:is-active claims))
|
||||||
(boolean (:email-verified claims))
|
(boolean (:email-verified claims))
|
||||||
(not (contains? cf/flags :email-verification)))
|
(not (contains? cf/flags :email-verification)))
|
||||||
@ -429,8 +451,8 @@
|
|||||||
(assoc :is-active is-active)
|
(assoc :is-active is-active)
|
||||||
(update :password auth/derive-password))
|
(update :password auth/derive-password))
|
||||||
profile (->> (create-profile cfg params)
|
profile (->> (create-profile cfg params)
|
||||||
(create-profile-rels conn))]
|
(create-profile-rels cfg))]
|
||||||
(vary-meta profile assoc :created true))))
|
(vary-meta profile assoc :created true)))
|
||||||
|
|
||||||
created? (-> profile meta :created true?)
|
created? (-> profile meta :created true?)
|
||||||
|
|
||||||
@ -461,29 +483,45 @@
|
|||||||
::audit/profile-id (:id profile)
|
::audit/profile-id (:id profile)
|
||||||
::audit/name "register-profile-retry"}))
|
::audit/name "register-profile-retry"}))
|
||||||
|
|
||||||
;; If invitation token comes in params, this is because the user
|
;; A profile was just created in this call. Invitation handling is a
|
||||||
;; comes from team-invitation process; in this case, regenerate
|
;; sub-case of "newly created profile": we never honor invitations for
|
||||||
;; token and send back to the user a new invitation token (and
|
;; pre-existing profiles via this anonymous RPC. The split below mirrors
|
||||||
;; mark current session as logged). This happens only if the
|
;; the non-invitation branches but threads the invitation through the
|
||||||
;; invitation email matches with the register email.
|
;; appropriate path:
|
||||||
(and (some? invitation)
|
;;
|
||||||
|
;; - active + matching invitation → mint session and
|
||||||
|
;; return :invitation-token. The frontend redirects to
|
||||||
|
;; :auth-verify-token, which immediately accepts the
|
||||||
|
;; invitation.
|
||||||
|
;; - active + no/mismatched invitation → mint session
|
||||||
|
;; ("login" action). New profile, no further action.
|
||||||
|
;; - not-active + matching invitation → send the
|
||||||
|
;; verify-email mail with the invitation token EMBEDDED
|
||||||
|
;; into the verify-email JWE. No session yet. When the
|
||||||
|
;; user clicks the link, verify-token activates the
|
||||||
|
;; profile, mints a session, and propagates the
|
||||||
|
;; invitation token to the frontend so it can complete
|
||||||
|
;; the team-invitation flow.
|
||||||
|
;; - not-active + no/mismatched invitation → standard
|
||||||
|
;; "check your email" verification flow.
|
||||||
|
created?
|
||||||
|
(let [accept-invitation? (and (some? invitation)
|
||||||
(= (:email profile)
|
(= (:email profile)
|
||||||
(:member-email invitation)))
|
(:member-email invitation)))]
|
||||||
|
(cond
|
||||||
|
(and (:is-active profile) accept-invitation?)
|
||||||
(let [invitation (assoc invitation :member-id (:id profile))
|
(let [invitation (assoc invitation :member-id (:id profile))
|
||||||
token (tokens/generate cfg invitation)]
|
token (tokens/generate cfg invitation)]
|
||||||
(-> {:id (:id profile)
|
(-> {:id (:id profile)
|
||||||
:email (:email profile)
|
:email (:email profile)
|
||||||
:invitation-token token}
|
:invitation-token token}
|
||||||
(rph/with-transform (session/create-fn cfg profile claims))
|
(rph/with-transform (session/create-fn cfg profile claims))
|
||||||
|
(rph/with-defer create-welcome-file-when-needed)
|
||||||
(rph/with-meta {::audit/replace-props props
|
(rph/with-meta {::audit/replace-props props
|
||||||
::audit/context {:action "accept-invitation"}
|
::audit/context {:action "accept-invitation"}
|
||||||
::audit/profile-id (:id profile)})))
|
::audit/profile-id (:id profile)})))
|
||||||
|
|
||||||
;; When a new user is created and it is already activated by
|
(:is-active profile)
|
||||||
;; configuration or specified by OIDC, we just mark the profile
|
|
||||||
;; as logged-in
|
|
||||||
created?
|
|
||||||
(if (:is-active profile)
|
|
||||||
(-> (profile/strip-private-attrs profile)
|
(-> (profile/strip-private-attrs profile)
|
||||||
(rph/with-transform (session/create-fn cfg profile claims))
|
(rph/with-transform (session/create-fn cfg profile claims))
|
||||||
(rph/with-defer create-welcome-file-when-needed)
|
(rph/with-defer create-welcome-file-when-needed)
|
||||||
@ -492,9 +530,12 @@
|
|||||||
::audit/context {:action "login"}
|
::audit/context {:action "login"}
|
||||||
::audit/profile-id (:id profile)}))
|
::audit/profile-id (:id profile)}))
|
||||||
|
|
||||||
|
:else
|
||||||
(do
|
(do
|
||||||
(when-not (eml/has-reports? conn (:email profile))
|
(when-not (eml/has-reports? conn (:email profile))
|
||||||
(send-email-verification! cfg profile))
|
(send-email-verification! cfg profile
|
||||||
|
(when accept-invitation?
|
||||||
|
(:invitation-token params))))
|
||||||
|
|
||||||
(-> {:id (:id profile)
|
(-> {:id (:id profile)
|
||||||
:email (:email profile)}
|
:email (:email profile)}
|
||||||
@ -502,7 +543,7 @@
|
|||||||
(rph/with-meta
|
(rph/with-meta
|
||||||
{::audit/replace-props props
|
{::audit/replace-props props
|
||||||
::audit/context {:action "email-verification"}
|
::audit/context {:action "email-verification"}
|
||||||
::audit/profile-id (:id profile)}))))
|
::audit/profile-id (:id profile)})))))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(let [elapsed? (elapsed-verify-threshold? profile)
|
(let [elapsed? (elapsed-verify-threshold? profile)
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
[app.media :as media]
|
[app.media :as media]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.commands.files :as files]
|
[app.rpc.commands.files :as files]
|
||||||
|
[app.rpc.commands.media :as media-cmd]
|
||||||
[app.rpc.commands.projects :as projects]
|
[app.rpc.commands.projects :as projects]
|
||||||
[app.rpc.commands.teams :as teams]
|
[app.rpc.commands.teams :as teams]
|
||||||
[app.rpc.doc :as-alias doc]
|
[app.rpc.doc :as-alias doc]
|
||||||
@ -80,20 +81,33 @@
|
|||||||
;; --- Command: import-binfile
|
;; --- Command: import-binfile
|
||||||
|
|
||||||
(defn- import-binfile
|
(defn- import-binfile
|
||||||
[{:keys [::db/pool] :as cfg} {:keys [profile-id project-id version name file]}]
|
[{:keys [::db/pool] :as cfg} {:keys [profile-id project-id version name file upload-id]}]
|
||||||
(let [team (teams/get-team pool
|
(let [team
|
||||||
|
(teams/get-team pool
|
||||||
:profile-id profile-id
|
:profile-id profile-id
|
||||||
:project-id project-id)
|
:project-id project-id)
|
||||||
cfg (-> cfg
|
|
||||||
|
cfg
|
||||||
|
(-> cfg
|
||||||
(assoc ::bfc/features (cfeat/get-team-enabled-features cf/flags team))
|
(assoc ::bfc/features (cfeat/get-team-enabled-features cf/flags team))
|
||||||
(assoc ::bfc/project-id project-id)
|
(assoc ::bfc/project-id project-id)
|
||||||
(assoc ::bfc/profile-id profile-id)
|
(assoc ::bfc/profile-id profile-id)
|
||||||
(assoc ::bfc/name name)
|
(assoc ::bfc/name name))
|
||||||
(assoc ::bfc/input (:path file)))
|
|
||||||
|
|
||||||
result (case (int version)
|
input-path (:path file)
|
||||||
|
owned? (some? upload-id)
|
||||||
|
|
||||||
|
cfg
|
||||||
|
(assoc cfg ::bfc/input input-path)
|
||||||
|
|
||||||
|
result
|
||||||
|
(try
|
||||||
|
(case (int version)
|
||||||
1 (bf.v1/import-files! cfg)
|
1 (bf.v1/import-files! cfg)
|
||||||
3 (bf.v3/import-files! cfg))]
|
3 (bf.v3/import-files! cfg))
|
||||||
|
(finally
|
||||||
|
(when owned?
|
||||||
|
(fs/delete input-path))))]
|
||||||
|
|
||||||
(db/update! pool :project
|
(db/update! pool :project
|
||||||
{:modified-at (ct/now)}
|
{:modified-at (ct/now)}
|
||||||
@ -103,13 +117,18 @@
|
|||||||
result))
|
result))
|
||||||
|
|
||||||
(def ^:private schema:import-binfile
|
(def ^:private schema:import-binfile
|
||||||
|
[:and
|
||||||
[:map {:title "import-binfile"}
|
[:map {:title "import-binfile"}
|
||||||
[:name [:or [:string {:max 250}]
|
[:name [:or [:string {:max 250}]
|
||||||
[:map-of ::sm/uuid [:string {:max 250}]]]]
|
[:map-of ::sm/uuid [:string {:max 250}]]]]
|
||||||
[:project-id ::sm/uuid]
|
[:project-id ::sm/uuid]
|
||||||
[:file-id {:optional true} ::sm/uuid]
|
[:file-id {:optional true} ::sm/uuid]
|
||||||
[:version {:optional true} ::sm/int]
|
[:version {:optional true} ::sm/int]
|
||||||
[:file media/schema:upload]])
|
[:file {:optional true} media/schema:upload]
|
||||||
|
[:upload-id {:optional true} ::sm/uuid]]
|
||||||
|
[:fn {:error/message "one of :file or :upload-id is required"}
|
||||||
|
(fn [{:keys [file upload-id]}]
|
||||||
|
(or (some? file) (some? upload-id)))]])
|
||||||
|
|
||||||
(sv/defmethod ::import-binfile
|
(sv/defmethod ::import-binfile
|
||||||
"Import a penpot file in a binary format. If `file-id` is provided,
|
"Import a penpot file in a binary format. If `file-id` is provided,
|
||||||
@ -117,15 +136,20 @@
|
|||||||
|
|
||||||
The in-place imports are only supported for binfile-v3 and when a
|
The in-place imports are only supported for binfile-v3 and when a
|
||||||
.penpot file only contains one penpot file.
|
.penpot file only contains one penpot file.
|
||||||
|
|
||||||
|
The file content may be provided either as a multipart `file` upload
|
||||||
|
or as an `upload-id` referencing a completed chunked-upload session,
|
||||||
|
which allows importing files larger than the multipart size limit.
|
||||||
"
|
"
|
||||||
{::doc/added "1.15"
|
{::doc/added "1.15"
|
||||||
::doc/changes ["1.20" "Add file-id param for in-place import"
|
::doc/changes ["1.20" "Add file-id param for in-place import"
|
||||||
"1.20" "Set default version to 3"]
|
"1.20" "Set default version to 3"
|
||||||
|
"2.15" "Add upload-id param for chunked upload support"]
|
||||||
|
|
||||||
::webhooks/event? true
|
::webhooks/event? true
|
||||||
::sse/stream? true
|
::sse/stream? true
|
||||||
::sm/params schema:import-binfile}
|
::sm/params schema:import-binfile}
|
||||||
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id project-id version file-id file] :as params}]
|
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id project-id version file-id upload-id] :as params}]
|
||||||
(projects/check-edition-permissions! pool profile-id project-id)
|
(projects/check-edition-permissions! pool profile-id project-id)
|
||||||
(let [version (or version 3)
|
(let [version (or version 3)
|
||||||
params (-> params
|
params (-> params
|
||||||
@ -136,9 +160,16 @@
|
|||||||
(uuid? file-id)
|
(uuid? file-id)
|
||||||
(assoc ::bfc/file-id file-id))
|
(assoc ::bfc/file-id file-id))
|
||||||
|
|
||||||
manifest (case (int version)
|
params
|
||||||
|
(if (some? upload-id)
|
||||||
|
(let [file (db/tx-run! cfg media-cmd/assemble-chunks upload-id)]
|
||||||
|
(assoc params :file file))
|
||||||
|
params)
|
||||||
|
|
||||||
|
manifest
|
||||||
|
(case (int version)
|
||||||
1 nil
|
1 nil
|
||||||
3 (bf.v3/get-manifest (:path file)))]
|
3 (bf.v3/get-manifest (-> params :file :path)))]
|
||||||
|
|
||||||
(with-meta
|
(with-meta
|
||||||
(sse/response (partial import-binfile cfg params))
|
(sse/response (partial import-binfile cfg params))
|
||||||
|
|||||||
@ -49,9 +49,9 @@
|
|||||||
:deleted-at (ct/in-future (cf/get-deletion-delay))
|
:deleted-at (ct/in-future (cf/get-deletion-delay))
|
||||||
:password (derive-password password)
|
:password (derive-password password)
|
||||||
:props {}}
|
:props {}}
|
||||||
profile (db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
profile (db/tx-run! cfg (fn [cfg]
|
||||||
(->> (auth/create-profile cfg params)
|
(->> (auth/create-profile cfg params)
|
||||||
(auth/create-profile-rels conn))))]
|
(auth/create-profile-rels cfg))))]
|
||||||
(with-meta {:email email
|
(with-meta {:email email
|
||||||
:password password}
|
:password password}
|
||||||
{::audit/profile-id (:id profile)})))
|
{::audit/profile-id (:id profile)})))
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
[app.common.features :as cfeat]
|
[app.common.features :as cfeat]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.files.migrations :as fmg]
|
[app.common.files.migrations :as fmg]
|
||||||
|
[app.common.files.stats :as cfs]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.schema.desc-js-like :as-alias smdj]
|
[app.common.schema.desc-js-like :as-alias smdj]
|
||||||
@ -606,6 +607,76 @@
|
|||||||
(get-file-summary cfg id))
|
(get-file-summary cfg id))
|
||||||
|
|
||||||
|
|
||||||
|
;; --- COMMAND QUERY: get-file-stats
|
||||||
|
|
||||||
|
(def ^:private sql:file-stats-library-counts
|
||||||
|
"SELECT
|
||||||
|
(SELECT COUNT(*)
|
||||||
|
FROM file_library_rel AS flr
|
||||||
|
JOIN file AS fl ON (fl.id = flr.library_file_id)
|
||||||
|
WHERE flr.file_id = ?::uuid
|
||||||
|
AND (fl.deleted_at IS NULL OR fl.deleted_at > now())) AS library_count,
|
||||||
|
(SELECT COUNT(*)
|
||||||
|
FROM file_library_rel AS flr
|
||||||
|
JOIN file AS fl ON (fl.id = flr.file_id)
|
||||||
|
WHERE flr.library_file_id = ?::uuid
|
||||||
|
AND (fl.deleted_at IS NULL OR fl.deleted_at > now())) AS referenced_by_count")
|
||||||
|
|
||||||
|
(defn- get-file-stats-library-counts
|
||||||
|
[conn file-id]
|
||||||
|
(let [row (db/exec-one! conn [sql:file-stats-library-counts file-id file-id])]
|
||||||
|
{:library-count (or (:library-count row) 0)
|
||||||
|
:referenced-by-count (or (:referenced-by-count row) 0)}))
|
||||||
|
|
||||||
|
(defn- get-file-stats
|
||||||
|
[{:keys [::db/conn] :as cfg} file-id]
|
||||||
|
(let [file (bfc/get-file cfg file-id)
|
||||||
|
base (binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg file-id)]
|
||||||
|
(cfs/calc-file-stats (:data file)))
|
||||||
|
lib-cnt (get-file-stats-library-counts conn file-id)]
|
||||||
|
(-> base
|
||||||
|
(merge lib-cnt)
|
||||||
|
(assoc :file-id file-id
|
||||||
|
:revn (:revn file)
|
||||||
|
:updated-at (:modified-at file)))))
|
||||||
|
|
||||||
|
(def ^:private schema:shape-counts
|
||||||
|
[:map {:title "FileStatsShapeCounts"}
|
||||||
|
[:total [::sm/int {:min 0}]]
|
||||||
|
[:by-type [:map-of :keyword [::sm/int {:min 0}]]]])
|
||||||
|
|
||||||
|
(def ^:private schema:get-file-stats-result
|
||||||
|
[:map {:title "FileStats"}
|
||||||
|
[:file-id ::sm/uuid]
|
||||||
|
[:page-count [::sm/int {:min 0}]]
|
||||||
|
[:shape-counts schema:shape-counts]
|
||||||
|
[:component-count [::sm/int {:min 0}]]
|
||||||
|
[:deleted-component-count [::sm/int {:min 0}]]
|
||||||
|
[:color-count [::sm/int {:min 0}]]
|
||||||
|
[:typography-count [::sm/int {:min 0}]]
|
||||||
|
[:library-count [::sm/int {:min 0}]]
|
||||||
|
[:referenced-by-count [::sm/int {:min 0}]]
|
||||||
|
[:revn [::sm/int {:min 0}]]
|
||||||
|
[:updated-at ::ct/inst]])
|
||||||
|
|
||||||
|
(def ^:private schema:get-file-stats
|
||||||
|
[:map {:title "get-file-stats"}
|
||||||
|
[:id ::sm/uuid]])
|
||||||
|
|
||||||
|
(sv/defmethod ::get-file-stats
|
||||||
|
"Return aggregate statistics for a single file: page count, shape
|
||||||
|
counts by type, component/color/typography counts, and inbound and
|
||||||
|
outbound library reference counts. Cheap alternative to `get-file`
|
||||||
|
when only metrics are needed."
|
||||||
|
{::doc/added "2.17"
|
||||||
|
::sm/params schema:get-file-stats
|
||||||
|
::sm/result schema:get-file-stats-result
|
||||||
|
::db/transaction true}
|
||||||
|
[{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id id]}]
|
||||||
|
(check-read-permissions! conn profile-id id)
|
||||||
|
(get-file-stats cfg id))
|
||||||
|
|
||||||
|
|
||||||
;; --- COMMAND QUERY: get-file-libraries
|
;; --- COMMAND QUERY: get-file-libraries
|
||||||
|
|
||||||
(def ^:private schema:get-file-libraries
|
(def ^:private schema:get-file-libraries
|
||||||
@ -1155,38 +1226,39 @@
|
|||||||
AND t.id = ?
|
AND t.id = ?
|
||||||
AND f.id = ANY(?::uuid[])")
|
AND f.id = ANY(?::uuid[])")
|
||||||
|
|
||||||
(defn- restore-file
|
(def ^:private sql:restore-files
|
||||||
[conn file-id]
|
"UPDATE file SET deleted_at = null, has_media_trimmed = false
|
||||||
(db/update! conn :file
|
WHERE id = ANY(?::uuid[])")
|
||||||
{:deleted-at nil
|
|
||||||
:has-media-trimmed false}
|
|
||||||
{:id file-id}
|
|
||||||
{::db/return-keys false})
|
|
||||||
|
|
||||||
(db/update! conn :file-media-object
|
(def ^:private sql:restore-file-media-objects
|
||||||
{:deleted-at nil}
|
"UPDATE file_media_object SET deleted_at = null
|
||||||
{:file-id file-id}
|
WHERE file_id = ANY(?::uuid[])")
|
||||||
{::db/return-keys false})
|
|
||||||
|
|
||||||
(db/update! conn :file-change
|
(def ^:private sql:restore-file-changes
|
||||||
{:deleted-at nil}
|
"UPDATE file_change SET deleted_at = null
|
||||||
{:file-id file-id}
|
WHERE file_id = ANY(?::uuid[])")
|
||||||
{::db/return-keys false})
|
|
||||||
|
|
||||||
(db/update! conn :file-data
|
(def ^:private sql:restore-file-data
|
||||||
{:deleted-at nil}
|
"UPDATE file_data SET deleted_at = null
|
||||||
{:file-id file-id}
|
WHERE file_id = ANY(?::uuid[])")
|
||||||
{::db/return-keys false})
|
|
||||||
|
|
||||||
(db/update! conn :file-thumbnail
|
(def ^:private sql:restore-file-thumbnails
|
||||||
{:deleted-at nil}
|
"UPDATE file_thumbnail SET deleted_at = null
|
||||||
{:file-id file-id}
|
WHERE file_id = ANY(?::uuid[])")
|
||||||
{::db/return-keys false})
|
|
||||||
|
|
||||||
(db/update! conn :file-tagged-object-thumbnail
|
(def ^:private sql:restore-file-tagged-object-thumbnails
|
||||||
{:deleted-at nil}
|
"UPDATE file_tagged_object_thumbnail SET deleted_at = null
|
||||||
{:file-id file-id}
|
WHERE file_id = ANY(?::uuid[])")
|
||||||
{::db/return-keys false}))
|
|
||||||
|
(defn- restore-files
|
||||||
|
[conn file-ids]
|
||||||
|
(let [file-ids (db/create-array conn "uuid" file-ids)]
|
||||||
|
(db/exec-one! conn [sql:restore-files file-ids])
|
||||||
|
(db/exec-one! conn [sql:restore-file-media-objects file-ids])
|
||||||
|
(db/exec-one! conn [sql:restore-file-changes file-ids])
|
||||||
|
(db/exec-one! conn [sql:restore-file-data file-ids])
|
||||||
|
(db/exec-one! conn [sql:restore-file-thumbnails file-ids])
|
||||||
|
(db/exec-one! conn [sql:restore-file-tagged-object-thumbnails file-ids])))
|
||||||
|
|
||||||
(def ^:private sql:restore-projects
|
(def ^:private sql:restore-projects
|
||||||
"UPDATE project SET deleted_at = null WHERE id = ANY(?::uuid[])")
|
"UPDATE project SET deleted_at = null WHERE id = ANY(?::uuid[])")
|
||||||
@ -1207,17 +1279,18 @@
|
|||||||
(reduce (fn [result {:keys [id project-id]}]
|
(reduce (fn [result {:keys [id project-id]}]
|
||||||
(let [index (-> result :files count)]
|
(let [index (-> result :files count)]
|
||||||
(events/tap :progress {:file-id id :index (inc index) :total total-files})
|
(events/tap :progress {:file-id id :index (inc index) :total total-files})
|
||||||
(restore-file conn id)
|
|
||||||
|
|
||||||
(-> result
|
(-> result
|
||||||
(update :files conj id)
|
(update :files conj id)
|
||||||
(update :projects conj project-id))))
|
(update :projects conj project-id))))
|
||||||
|
{:files #{} :projects #{}}
|
||||||
{:files #{} :projectes #{}}
|
|
||||||
(db/plan conn [sql:resolve-editable-files team-id
|
(db/plan conn [sql:resolve-editable-files team-id
|
||||||
(db/create-array conn "uuid" ids)]))]
|
(db/create-array conn "uuid" ids)]))]
|
||||||
|
|
||||||
(restore-projects conn projects)
|
(when (seq files)
|
||||||
|
(restore-files conn files))
|
||||||
|
|
||||||
|
(when (seq projects)
|
||||||
|
(restore-projects conn projects))
|
||||||
|
|
||||||
files))
|
files))
|
||||||
|
|
||||||
|
|||||||
@ -112,22 +112,30 @@
|
|||||||
::quotes/profile-id profile-id
|
::quotes/profile-id profile-id
|
||||||
::quotes/project-id project-id})
|
::quotes/project-id project-id})
|
||||||
|
|
||||||
;; FIXME: IMPORTANT: this code can have race conditions, because
|
;; Acquire a row-level lock on the team and re-read its features
|
||||||
;; we have no locks for updating team so, creating two files
|
;; inside the same transaction before the read-modify-write below.
|
||||||
;; concurrently can lead to lost team features updating
|
;; Without the lock, two concurrent create-file calls on the same
|
||||||
(when-let [features (-> features
|
;; team can both observe the same team.features value, each
|
||||||
(set/difference (:features team))
|
;; compute a different union, and the second UPDATE silently
|
||||||
|
;; overwrites the first (lost update under READ COMMITTED).
|
||||||
|
(let [team-features (-> (db/exec-one! conn
|
||||||
|
["SELECT features FROM team WHERE id = ? FOR UPDATE"
|
||||||
|
team-id])
|
||||||
|
:features
|
||||||
|
(db/decode-pgarray #{}))]
|
||||||
|
(when-let [new-features (-> features
|
||||||
|
(set/difference team-features)
|
||||||
(set/difference cfeat/no-team-inheritable-features)
|
(set/difference cfeat/no-team-inheritable-features)
|
||||||
(not-empty))]
|
(not-empty))]
|
||||||
(let [features (-> features
|
(let [features (-> new-features
|
||||||
(set/union (:features team))
|
(set/union team-features)
|
||||||
(set/difference cfeat/no-team-inheritable-features)
|
(set/difference cfeat/no-team-inheritable-features)
|
||||||
(into-array))]
|
(into-array))]
|
||||||
|
|
||||||
(db/update! conn :team
|
(db/update! conn :team
|
||||||
{:features features}
|
{:features features}
|
||||||
{:id (:id team)}
|
{:id team-id}
|
||||||
{::db/return-keys false})))
|
{::db/return-keys false}))))
|
||||||
|
|
||||||
(-> (create-file cfg params)
|
(-> (create-file cfg params)
|
||||||
(vary-meta assoc ::audit/props {:team-id team-id}))))
|
(vary-meta assoc ::audit/props {:team-id team-id}))))
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
(:require
|
(:require
|
||||||
[app.binfile.common :as bfc]
|
[app.binfile.common :as bfc]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.features :as-alias cfeat]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.time :as ct]
|
[app.common.time :as ct]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
@ -35,6 +36,43 @@
|
|||||||
(files/check-read-permissions! conn profile-id file-id)
|
(files/check-read-permissions! conn profile-id file-id)
|
||||||
(fsnap/get-visible-snapshots conn file-id))))
|
(fsnap/get-visible-snapshots conn file-id))))
|
||||||
|
|
||||||
|
;; --- COMMAND QUERY: get-file-snapshot
|
||||||
|
|
||||||
|
(def ^:private schema:get-file-snapshot
|
||||||
|
[:map {:title "get-file-snapshot"}
|
||||||
|
[:file-id ::sm/uuid]
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:features {:optional true} ::cfeat/features]])
|
||||||
|
|
||||||
|
(sv/defmethod ::get-file-snapshot
|
||||||
|
"Retrieve a file bundle with data from a specific snapshot for
|
||||||
|
read-only preview. Does not modify any database state."
|
||||||
|
{::doc/added "2.16"
|
||||||
|
::sm/params schema:get-file-snapshot
|
||||||
|
::sm/result files/schema:file-with-permissions
|
||||||
|
::db/transaction true}
|
||||||
|
[{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id file-id id] :as params}]
|
||||||
|
(let [perms (bfc/get-file-permissions conn profile-id file-id)]
|
||||||
|
(files/check-read-permissions! perms)
|
||||||
|
(let [snapshot (fsnap/get-snapshot-data cfg file-id id)]
|
||||||
|
(when-not snapshot
|
||||||
|
(ex/raise :type :not-found
|
||||||
|
:code :snapshot-not-found
|
||||||
|
:hint "unable to find snapshot with the provided id"
|
||||||
|
:snapshot-id id
|
||||||
|
:file-id file-id))
|
||||||
|
;; Load current file metadata only (no data decoding) then overlay
|
||||||
|
;; the snapshot data so the client receives the same shape as a
|
||||||
|
;; normal get-file response but with historical page/object content.
|
||||||
|
(let [base-file (bfc/get-file cfg file-id :load-data? false)]
|
||||||
|
(-> base-file
|
||||||
|
(assoc :data (:data snapshot))
|
||||||
|
(assoc :version (:version snapshot))
|
||||||
|
(assoc :features (:features snapshot))
|
||||||
|
(assoc :revn (:revn snapshot))
|
||||||
|
(assoc :vern (rand-int 100000))
|
||||||
|
(assoc :permissions perms))))))
|
||||||
|
|
||||||
(def ^:private schema:create-file-snapshot
|
(def ^:private schema:create-file-snapshot
|
||||||
[:map
|
[:map
|
||||||
[:file-id ::sm/uuid]
|
[:file-id ::sm/uuid]
|
||||||
@ -71,7 +109,7 @@
|
|||||||
{::doc/added "1.20"
|
{::doc/added "1.20"
|
||||||
::sm/params schema:restore-file-snapshot
|
::sm/params schema:restore-file-snapshot
|
||||||
::db/transaction true}
|
::db/transaction true}
|
||||||
[{:keys [::db/conn ::mbus/msgbus] :as cfg} {:keys [::rpc/profile-id file-id id] :as params}]
|
[{:keys [::db/conn ::mbus/msgbus] :as cfg} {:keys [::rpc/profile-id ::rpc/session-id file-id id] :as params}]
|
||||||
(files/check-edition-permissions! conn profile-id file-id)
|
(files/check-edition-permissions! conn profile-id file-id)
|
||||||
(let [file (bfc/get-file cfg file-id)
|
(let [file (bfc/get-file cfg file-id)
|
||||||
team (teams/get-team conn
|
team (teams/get-team conn
|
||||||
@ -88,7 +126,8 @@
|
|||||||
;; Send to the clients a notification to reload the file
|
;; Send to the clients a notification to reload the file
|
||||||
(mbus/pub! msgbus
|
(mbus/pub! msgbus
|
||||||
:topic (:id file)
|
:topic (:id file)
|
||||||
:message {:type :file-restore
|
:message {:type :file-restored
|
||||||
|
:session-id session-id
|
||||||
:file-id (:id file)
|
:file-id (:id file)
|
||||||
:vern vern})
|
:vern vern})
|
||||||
nil)))
|
nil)))
|
||||||
|
|||||||
@ -409,10 +409,7 @@
|
|||||||
|
|
||||||
[cfg {:keys [::rpc/profile-id file-id] :as params}]
|
[cfg {:keys [::rpc/profile-id file-id] :as params}]
|
||||||
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
||||||
;; TODO For now we check read permissions instead of write,
|
(files/check-edition-permissions! conn profile-id file-id)
|
||||||
;; to allow viewer users to update thumbnails. We might
|
|
||||||
;; review this approach on the future.
|
|
||||||
(files/check-read-permissions! conn profile-id file-id)
|
|
||||||
(when-not (db/read-only? conn)
|
(when-not (db/read-only? conn)
|
||||||
(let [media (create-file-thumbnail cfg params)]
|
(let [media (create-file-thumbnail cfg params)]
|
||||||
{:uri (files/resolve-public-uri (:id media))
|
{:uri (files/resolve-public-uri (:id media))
|
||||||
|
|||||||
@ -9,12 +9,14 @@
|
|||||||
[app.binfile.common :as bfc]
|
[app.binfile.common :as bfc]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.media :as cmedia]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.time :as ct]
|
[app.common.time :as ct]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.db.sql :as-alias sql]
|
[app.db.sql :as-alias sql]
|
||||||
[app.features.logical-deletion :as ldel]
|
[app.features.logical-deletion :as ldel]
|
||||||
|
[app.http :as-alias http]
|
||||||
[app.loggers.audit :as-alias audit]
|
[app.loggers.audit :as-alias audit]
|
||||||
[app.loggers.webhooks :as-alias webhooks]
|
[app.loggers.webhooks :as-alias webhooks]
|
||||||
[app.media :as media]
|
[app.media :as media]
|
||||||
@ -34,7 +36,9 @@
|
|||||||
java.io.InputStream
|
java.io.InputStream
|
||||||
java.io.OutputStream
|
java.io.OutputStream
|
||||||
java.io.SequenceInputStream
|
java.io.SequenceInputStream
|
||||||
java.util.Collections))
|
java.util.Collections
|
||||||
|
java.util.zip.ZipEntry
|
||||||
|
java.util.zip.ZipOutputStream))
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
@ -94,7 +98,8 @@
|
|||||||
[:font-id ::sm/uuid]
|
[:font-id ::sm/uuid]
|
||||||
[:font-family ::sm/text]
|
[:font-family ::sm/text]
|
||||||
[:font-weight [::sm/one-of {:format "number"} valid-weight]]
|
[:font-weight [::sm/one-of {:format "number"} valid-weight]]
|
||||||
[:font-style [::sm/one-of {:format "string"} valid-style]]])
|
[:font-style [::sm/one-of {:format "string"} valid-style]]
|
||||||
|
[:variant-name {:optional true} [:maybe ::sm/text]]])
|
||||||
|
|
||||||
;; FIXME: IMPORTANT: refactor this, we should not hold a whole db
|
;; FIXME: IMPORTANT: refactor this, we should not hold a whole db
|
||||||
;; connection around the font creation
|
;; connection around the font creation
|
||||||
@ -180,6 +185,7 @@
|
|||||||
:font-family (:font-family params)
|
:font-family (:font-family params)
|
||||||
:font-weight (:font-weight params)
|
:font-weight (:font-weight params)
|
||||||
:font-style (:font-style params)
|
:font-style (:font-style params)
|
||||||
|
:variant-name (:variant-name params)
|
||||||
:woff1-file-id (:id woff1)
|
:woff1-file-id (:id woff1)
|
||||||
:woff2-file-id (:id woff2)
|
:woff2-file-id (:id woff2)
|
||||||
:otf-file-id (:id otf)
|
:otf-file-id (:id otf)
|
||||||
@ -296,3 +302,98 @@
|
|||||||
(rph/with-meta (rph/wrap)
|
(rph/with-meta (rph/wrap)
|
||||||
{::audit/props {:font-family (:font-family variant)
|
{::audit/props {:font-family (:font-family variant)
|
||||||
:font-id (:font-id variant)}})))
|
:font-id (:font-id variant)}})))
|
||||||
|
|
||||||
|
;; --- DOWNLOAD FONT
|
||||||
|
|
||||||
|
(defn- make-temporal-storage-object
|
||||||
|
[cfg profile-id content]
|
||||||
|
(let [storage (sto/resolve cfg)
|
||||||
|
content (media/check-input content)
|
||||||
|
hash (sto/calculate-hash (:path content))
|
||||||
|
data (-> (sto/content (:path content))
|
||||||
|
(sto/wrap-with-hash hash))
|
||||||
|
mtype (:mtype content "application/octet-stream")
|
||||||
|
content {::sto/content data
|
||||||
|
::sto/deduplicate? true
|
||||||
|
::sto/touched-at (ct/in-future {:minutes 30})
|
||||||
|
:profile-id profile-id
|
||||||
|
:content-type mtype
|
||||||
|
:bucket "tempfile"}]
|
||||||
|
|
||||||
|
(sto/put-object! storage content)))
|
||||||
|
|
||||||
|
(defn- make-variant-filename
|
||||||
|
[v mtype]
|
||||||
|
(str (:font-family v) "-" (:font-weight v)
|
||||||
|
(when-not (= "normal" (:font-style v)) (str "-" (:font-style v)))
|
||||||
|
(cmedia/mtype->extension mtype)))
|
||||||
|
|
||||||
|
(def ^:private schema:download-font
|
||||||
|
[:map {:title "download-font"}
|
||||||
|
[:id ::sm/uuid]])
|
||||||
|
|
||||||
|
(sv/defmethod ::download-font
|
||||||
|
"Download the font file. Returns a http redirect to the asset resource uri."
|
||||||
|
{::doc/added "2.15"
|
||||||
|
::sm/params schema:download-font}
|
||||||
|
[{:keys [::sto/storage ::db/pool] :as cfg} {:keys [::rpc/profile-id id]}]
|
||||||
|
(let [variant (db/get pool :team-font-variant {:id id})]
|
||||||
|
(teams/check-read-permissions! pool profile-id (:team-id variant))
|
||||||
|
|
||||||
|
;; Try to get the best available font format (prefer TTF for broader compatibility).
|
||||||
|
(let [media-id (or (:ttf-file-id variant)
|
||||||
|
(:otf-file-id variant)
|
||||||
|
(:woff2-file-id variant)
|
||||||
|
(:woff1-file-id variant))
|
||||||
|
sobj (sto/get-object storage media-id)
|
||||||
|
mtype (-> sobj meta :content-type)]
|
||||||
|
|
||||||
|
{:id (:id sobj)
|
||||||
|
:uri (files/resolve-public-uri (:id sobj))
|
||||||
|
:name (make-variant-filename variant mtype)})))
|
||||||
|
|
||||||
|
(def ^:private schema:download-font-family
|
||||||
|
[:map {:title "download-font-family"}
|
||||||
|
[:font-id ::sm/uuid]])
|
||||||
|
|
||||||
|
(sv/defmethod ::download-font-family
|
||||||
|
"Download the entire font family as a zip file. Returns the zip
|
||||||
|
bytes on the body, without encoding it on transit or json."
|
||||||
|
{::doc/added "2.15"
|
||||||
|
::sm/params schema:download-font-family}
|
||||||
|
[{:keys [::sto/storage ::db/pool] :as cfg} {:keys [::rpc/profile-id font-id]}]
|
||||||
|
(let [variants (db/query pool :team-font-variant
|
||||||
|
{:font-id font-id
|
||||||
|
:deleted-at nil})]
|
||||||
|
|
||||||
|
(when-not (seq variants)
|
||||||
|
(ex/raise :type :not-found
|
||||||
|
:code :object-not-found))
|
||||||
|
|
||||||
|
(teams/check-read-permissions! pool profile-id (:team-id (first variants)))
|
||||||
|
|
||||||
|
(let [tempfile (tmp/tempfile :suffix ".zip")
|
||||||
|
ffamily (-> variants first :font-family)]
|
||||||
|
|
||||||
|
(with-open [^OutputStream output (io/output-stream tempfile)
|
||||||
|
^OutputStream output (ZipOutputStream. output)]
|
||||||
|
(doseq [v variants]
|
||||||
|
(let [media-id (or (:ttf-file-id v)
|
||||||
|
(:otf-file-id v)
|
||||||
|
(:woff2-file-id v)
|
||||||
|
(:woff1-file-id v))
|
||||||
|
sobj (sto/get-object storage media-id)
|
||||||
|
mtype (-> sobj meta :content-type)
|
||||||
|
name (make-variant-filename v mtype)]
|
||||||
|
|
||||||
|
(with-open [input (sto/get-object-data storage sobj)]
|
||||||
|
(.putNextEntry ^ZipOutputStream output (ZipEntry. ^String name))
|
||||||
|
(io/copy input output :size (:size sobj))
|
||||||
|
(.closeEntry ^ZipOutputStream output)))))
|
||||||
|
|
||||||
|
(let [{:keys [id] :as sobj} (make-temporal-storage-object cfg profile-id
|
||||||
|
{:mtype "application/zip"
|
||||||
|
:path tempfile})]
|
||||||
|
{:id id
|
||||||
|
:uri (files/resolve-public-uri id)
|
||||||
|
:name (str ffamily ".zip")}))))
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
(when-not provider
|
(when-not provider
|
||||||
(ex/raise :type :restriction
|
(ex/raise :type :restriction
|
||||||
:code :ldap-not-initialized
|
:code :ldap-not-initialized
|
||||||
:hide "ldap auth provider is not initialized"))
|
:hint "ldap auth provider is not initialized"))
|
||||||
|
|
||||||
(let [info (ldap/authenticate provider params)]
|
(let [info (ldap/authenticate provider params)]
|
||||||
(when-not info
|
(when-not info
|
||||||
@ -84,5 +84,5 @@
|
|||||||
(profile/get-profile-by-email conn))
|
(profile/get-profile-by-email conn))
|
||||||
(->> (assoc info :is-active true :is-demo false)
|
(->> (assoc info :is-active true :is-demo false)
|
||||||
(auth/create-profile cfg)
|
(auth/create-profile cfg)
|
||||||
(auth/create-profile-rels conn)
|
(auth/create-profile-rels cfg)
|
||||||
(profile/strip-private-attrs))))))
|
(profile/strip-private-attrs))))))
|
||||||
|
|||||||
@ -207,8 +207,7 @@
|
|||||||
(update :team-id bfc/lookup-index)
|
(update :team-id bfc/lookup-index)
|
||||||
(assoc :created-at timestamp)
|
(assoc :created-at timestamp)
|
||||||
(assoc :modified-at timestamp))]
|
(assoc :modified-at timestamp))]
|
||||||
(db/insert! conn :team-profile-rel params
|
(teams/add-profile-to-team! cfg params {::db/return-keys false})))
|
||||||
{::db/return-keys false})))
|
|
||||||
|
|
||||||
;; Duplicate team fonts
|
;; Duplicate team fonts
|
||||||
(doseq [font fonts]
|
(doseq [font fonts]
|
||||||
@ -339,6 +338,21 @@
|
|||||||
;; --- COMMAND: Move project
|
;; --- COMMAND: Move project
|
||||||
|
|
||||||
(defn move-project
|
(defn move-project
|
||||||
|
"Moves a project from one team to another.
|
||||||
|
|
||||||
|
Performs comprehensive validation including:
|
||||||
|
- Permission checks on both source and destination teams
|
||||||
|
- Team compatibility verification between source and destination
|
||||||
|
- File features compatibility with destination team
|
||||||
|
|
||||||
|
The operation also:
|
||||||
|
- Updates the project's team assignment
|
||||||
|
- Cleans up any broken library relations after the move
|
||||||
|
|
||||||
|
Throws:
|
||||||
|
- :cant-move-to-same-team if trying to move project to its current team
|
||||||
|
- Permission exceptions if user lacks required permissions
|
||||||
|
- Team compatibility exceptions if teams are incompatible"
|
||||||
[{:keys [::db/conn] :as cfg} {:keys [profile-id team-id project-id] :as params}]
|
[{:keys [::db/conn] :as cfg} {:keys [profile-id team-id project-id] :as params}]
|
||||||
(let [project (db/get-by-id conn :project project-id {:columns [:id :team-id]})
|
(let [project (db/get-by-id conn :project project-id {:columns [:id :team-id]})
|
||||||
pids (->> (db/query conn :project {:team-id (:team-id project)} {:columns [:id]})
|
pids (->> (db/query conn :project {:team-id (:team-id project)} {:columns [:id]})
|
||||||
@ -425,10 +439,10 @@
|
|||||||
(doseq [file-id result]
|
(doseq [file-id result]
|
||||||
(let [props (assoc props :id file-id)
|
(let [props (assoc props :id file-id)
|
||||||
event (-> (audit/event-from-rpc-params params)
|
event (-> (audit/event-from-rpc-params params)
|
||||||
(assoc ::audit/profile-id profile-id)
|
(assoc :profile-id profile-id)
|
||||||
(assoc ::audit/name "create-file")
|
(assoc :name "create-file")
|
||||||
(assoc ::audit/props props))]
|
(assoc :props props))]
|
||||||
(audit/submit! cfg event))))))
|
(audit/submit cfg event))))))
|
||||||
|
|
||||||
result))
|
result))
|
||||||
|
|
||||||
|
|||||||
@ -7,9 +7,11 @@
|
|||||||
(ns app.rpc.commands.media
|
(ns app.rpc.commands.media
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.time :as ct]
|
[app.common.time :as ct]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.loggers.audit :as-alias audit]
|
[app.loggers.audit :as-alias audit]
|
||||||
[app.media :as media]
|
[app.media :as media]
|
||||||
@ -17,8 +19,13 @@
|
|||||||
[app.rpc.climit :as climit]
|
[app.rpc.climit :as climit]
|
||||||
[app.rpc.commands.files :as files]
|
[app.rpc.commands.files :as files]
|
||||||
[app.rpc.doc :as-alias doc]
|
[app.rpc.doc :as-alias doc]
|
||||||
|
[app.rpc.quotes :as quotes]
|
||||||
[app.storage :as sto]
|
[app.storage :as sto]
|
||||||
[app.util.services :as sv]))
|
[app.storage.tmp :as tmp]
|
||||||
|
[app.util.services :as sv]
|
||||||
|
[datoteka.io :as io])
|
||||||
|
(:import
|
||||||
|
java.io.OutputStream))
|
||||||
|
|
||||||
(def thumbnail-options
|
(def thumbnail-options
|
||||||
{:width 100
|
{:width 100
|
||||||
@ -236,3 +243,182 @@
|
|||||||
:width (:width mobj)
|
:width (:width mobj)
|
||||||
:height (:height mobj)
|
:height (:height mobj)
|
||||||
:mtype (:mtype mobj)})))
|
:mtype (:mtype mobj)})))
|
||||||
|
|
||||||
|
;; --- Chunked Upload: Create an upload session
|
||||||
|
|
||||||
|
(def ^:private schema:create-upload-session
|
||||||
|
[:map {:title "create-upload-session"}
|
||||||
|
[:total-chunks ::sm/int]])
|
||||||
|
|
||||||
|
(def ^:private schema:create-upload-session-result
|
||||||
|
[:map {:title "create-upload-session-result"}
|
||||||
|
[:session-id ::sm/uuid]])
|
||||||
|
|
||||||
|
(sv/defmethod ::create-upload-session
|
||||||
|
{::doc/added "2.17"
|
||||||
|
::sm/params schema:create-upload-session
|
||||||
|
::sm/result schema:create-upload-session-result}
|
||||||
|
[{:keys [::db/pool] :as cfg}
|
||||||
|
{:keys [::rpc/profile-id total-chunks]}]
|
||||||
|
|
||||||
|
(let [max-chunks (cf/get :quotes-upload-chunks-per-session)]
|
||||||
|
(when (> total-chunks max-chunks)
|
||||||
|
(ex/raise :type :restriction
|
||||||
|
:code :max-quote-reached
|
||||||
|
:target "upload-chunks-per-session"
|
||||||
|
:quote max-chunks
|
||||||
|
:count total-chunks)))
|
||||||
|
|
||||||
|
(quotes/check! cfg {::quotes/id ::quotes/upload-sessions-per-profile
|
||||||
|
::quotes/profile-id profile-id})
|
||||||
|
|
||||||
|
(let [session-id (uuid/next)]
|
||||||
|
(db/insert! pool :upload-session
|
||||||
|
{:id session-id
|
||||||
|
:profile-id profile-id
|
||||||
|
:total-chunks total-chunks})
|
||||||
|
{:session-id session-id}))
|
||||||
|
|
||||||
|
;; --- Chunked Upload: Upload a single chunk
|
||||||
|
|
||||||
|
(def ^:private schema:upload-chunk
|
||||||
|
[:map {:title "upload-chunk"}
|
||||||
|
[:session-id ::sm/uuid]
|
||||||
|
[:index ::sm/int]
|
||||||
|
[:content media/schema:upload]])
|
||||||
|
|
||||||
|
(def ^:private schema:upload-chunk-result
|
||||||
|
[:map {:title "upload-chunk-result"}
|
||||||
|
[:session-id ::sm/uuid]
|
||||||
|
[:index ::sm/int]])
|
||||||
|
|
||||||
|
(sv/defmethod ::upload-chunk
|
||||||
|
{::doc/added "2.17"
|
||||||
|
::sm/params schema:upload-chunk
|
||||||
|
::sm/result schema:upload-chunk-result}
|
||||||
|
[{:keys [::db/pool] :as cfg}
|
||||||
|
{:keys [::rpc/profile-id session-id index content] :as _params}]
|
||||||
|
(let [session (db/get pool :upload-session {:id session-id :profile-id profile-id})]
|
||||||
|
(when (or (neg? index) (>= index (:total-chunks session)))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :invalid-chunk-index
|
||||||
|
:hint "chunk index is out of range for this session"
|
||||||
|
:session-id session-id
|
||||||
|
:total-chunks (:total-chunks session)
|
||||||
|
:index index)))
|
||||||
|
|
||||||
|
(let [storage (sto/resolve cfg)
|
||||||
|
data (sto/content (:path content))]
|
||||||
|
(sto/put-object! storage
|
||||||
|
{::sto/content data
|
||||||
|
::sto/deduplicate? false
|
||||||
|
::sto/touch true
|
||||||
|
:content-type (:mtype content)
|
||||||
|
:bucket "tempfile"
|
||||||
|
:upload-id (str session-id)
|
||||||
|
:chunk-index index}))
|
||||||
|
|
||||||
|
{:session-id session-id
|
||||||
|
:index index})
|
||||||
|
|
||||||
|
;; --- Chunked Upload: shared helpers
|
||||||
|
|
||||||
|
(def ^:private sql:get-upload-chunks
|
||||||
|
"SELECT id, size, (metadata->>'~:chunk-index')::integer AS chunk_index
|
||||||
|
FROM storage_object
|
||||||
|
WHERE (metadata->>'~:upload-id') = ?::text
|
||||||
|
AND deleted_at IS NULL
|
||||||
|
ORDER BY (metadata->>'~:chunk-index')::integer ASC")
|
||||||
|
|
||||||
|
(defn- get-upload-chunks
|
||||||
|
[conn session-id]
|
||||||
|
(db/exec! conn [sql:get-upload-chunks (str session-id)]))
|
||||||
|
|
||||||
|
(defn- concat-chunks
|
||||||
|
"Reads all chunk storage objects in order and writes them to a single
|
||||||
|
temporary file on the local filesystem. Returns a path to that file."
|
||||||
|
[storage chunks]
|
||||||
|
(let [tmp (tmp/tempfile :prefix "penpot.chunked-upload.")]
|
||||||
|
(with-open [^OutputStream out (io/output-stream tmp)]
|
||||||
|
(doseq [{:keys [id]} chunks]
|
||||||
|
(let [sobj (sto/get-object storage id)
|
||||||
|
bytes (sto/get-object-bytes storage sobj)]
|
||||||
|
(.write out ^bytes bytes))))
|
||||||
|
tmp))
|
||||||
|
|
||||||
|
(defn assemble-chunks
|
||||||
|
"Validates that all expected chunks are present for `session-id` and
|
||||||
|
concatenates them into a single temporary file. Returns a map
|
||||||
|
conforming to `media/schema:upload` with `:filename`, `:path` and
|
||||||
|
`:size`.
|
||||||
|
|
||||||
|
Raises a :validation/:missing-chunks error when the number of stored
|
||||||
|
chunks does not match `:total-chunks` recorded in the session row.
|
||||||
|
Deletes the session row from `upload_session` on success."
|
||||||
|
[{:keys [::db/conn] :as cfg} session-id]
|
||||||
|
(let [session (db/get conn :upload-session {:id session-id})
|
||||||
|
chunks (get-upload-chunks conn session-id)]
|
||||||
|
|
||||||
|
(when (not= (count chunks) (:total-chunks session))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :missing-chunks
|
||||||
|
:hint "number of stored chunks does not match expected total"
|
||||||
|
:session-id session-id
|
||||||
|
:expected (:total-chunks session)
|
||||||
|
:found (count chunks)))
|
||||||
|
|
||||||
|
(let [storage (sto/resolve cfg ::db/reuse-conn true)
|
||||||
|
path (concat-chunks storage chunks)
|
||||||
|
size (reduce #(+ %1 (:size %2)) 0 chunks)]
|
||||||
|
|
||||||
|
(db/delete! conn :upload-session {:id session-id})
|
||||||
|
|
||||||
|
{:filename "upload"
|
||||||
|
:path path
|
||||||
|
:size size})))
|
||||||
|
|
||||||
|
;; --- Chunked Upload: Assemble all chunks into a final media object
|
||||||
|
|
||||||
|
(def ^:private schema:assemble-file-media-object
|
||||||
|
[:map {:title "assemble-file-media-object"}
|
||||||
|
[:session-id ::sm/uuid]
|
||||||
|
[:file-id ::sm/uuid]
|
||||||
|
[:is-local ::sm/boolean]
|
||||||
|
[:name [:string {:max 250}]]
|
||||||
|
[:mtype :string]
|
||||||
|
[:id {:optional true} ::sm/uuid]])
|
||||||
|
|
||||||
|
(sv/defmethod ::assemble-file-media-object
|
||||||
|
{::doc/added "2.17"
|
||||||
|
::sm/params schema:assemble-file-media-object
|
||||||
|
::climit/id [[:process-image/by-profile ::rpc/profile-id]
|
||||||
|
[:process-image/global]]}
|
||||||
|
[{:keys [::db/pool] :as cfg}
|
||||||
|
{:keys [::rpc/profile-id session-id file-id is-local name mtype id] :as params}]
|
||||||
|
(files/check-edition-permissions! pool profile-id file-id)
|
||||||
|
|
||||||
|
(db/tx-run! cfg
|
||||||
|
(fn [{:keys [::db/conn] :as cfg}]
|
||||||
|
(let [{:keys [path size]} (assemble-chunks cfg session-id)
|
||||||
|
content {:filename "upload"
|
||||||
|
:size size
|
||||||
|
:path path
|
||||||
|
:mtype mtype}
|
||||||
|
_ (media/validate-media-type! content)
|
||||||
|
mobj (create-file-media-object cfg (assoc params
|
||||||
|
:id (or id (uuid/next))
|
||||||
|
:content content))]
|
||||||
|
|
||||||
|
(db/update! conn :file
|
||||||
|
{:modified-at (ct/now)
|
||||||
|
:has-media-trimmed false}
|
||||||
|
{:id file-id}
|
||||||
|
{::db/return-keys false})
|
||||||
|
|
||||||
|
(with-meta mobj
|
||||||
|
{::audit/replace-props
|
||||||
|
{:name name
|
||||||
|
:file-id file-id
|
||||||
|
:is-local is-local
|
||||||
|
:mtype mtype}})))))
|
||||||
|
|
||||||
|
|||||||
335
backend/src/app/rpc/commands/nitrate.clj
Normal file
335
backend/src/app/rpc/commands/nitrate.clj
Normal file
@ -0,0 +1,335 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.rpc.commands.nitrate
|
||||||
|
"Nitrate API for Penpot. Provides nitrate-related endpoints to be called
|
||||||
|
from Penpot frontend."
|
||||||
|
(:require
|
||||||
|
[app.common.data :as d]
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.schema :as sm]
|
||||||
|
[app.common.time :as ct]
|
||||||
|
[app.common.types.nitrate-permissions :as nitrate-perms]
|
||||||
|
[app.config :as cf]
|
||||||
|
[app.db :as db]
|
||||||
|
[app.nitrate :as nitrate]
|
||||||
|
[app.rpc :as-alias rpc]
|
||||||
|
[app.rpc.commands.teams :as teams]
|
||||||
|
[app.rpc.doc :as-alias doc]
|
||||||
|
[app.rpc.notifications :as notifications]
|
||||||
|
[app.util.services :as sv]))
|
||||||
|
|
||||||
|
|
||||||
|
(defn assert-is-owner [cfg profile-id team-id]
|
||||||
|
(let [perms (teams/get-permissions cfg profile-id team-id)]
|
||||||
|
(when-not (:is-owner perms)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :insufficient-permissions))))
|
||||||
|
|
||||||
|
(defn assert-not-default-team [cfg team-id]
|
||||||
|
(let [team (teams/get-team-info cfg {:id team-id})]
|
||||||
|
(when (:is-default team)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :cant-move-default-team))))
|
||||||
|
|
||||||
|
(defn assert-membership [cfg profile-id organization-id]
|
||||||
|
(let [membership (nitrate/call cfg :get-org-membership {:profile-id profile-id
|
||||||
|
:organization-id organization-id})]
|
||||||
|
(when-not (:organization-id membership)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :organization-doesnt-exists))
|
||||||
|
|
||||||
|
(when-not (:is-member membership)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :user-doesnt-belong-organization))))
|
||||||
|
|
||||||
|
|
||||||
|
(def schema:connectivity
|
||||||
|
[:map {:title "nitrate-connectivity"}
|
||||||
|
[:licenses ::sm/boolean]])
|
||||||
|
|
||||||
|
(sv/defmethod ::get-nitrate-connectivity
|
||||||
|
{::rpc/auth true
|
||||||
|
::doc/added "2.14"
|
||||||
|
::sm/params [:map]
|
||||||
|
::sm/result schema:connectivity}
|
||||||
|
[cfg _params]
|
||||||
|
(nitrate/call cfg :connectivity {}))
|
||||||
|
|
||||||
|
(def ^:private schema:redeem-activation-code-params
|
||||||
|
[:map {:title "RedeemActivationCodeParams"}
|
||||||
|
[:activation-code ::sm/text]])
|
||||||
|
|
||||||
|
(def ^:private schema:redeem-activation-code-result
|
||||||
|
[:map {:title "RedeemActivationCodeResult"}
|
||||||
|
[:cancel-at [:maybe ct/schema:inst]]])
|
||||||
|
|
||||||
|
(sv/defmethod ::redeem-nitrate-activation-code
|
||||||
|
{::rpc/auth true
|
||||||
|
::doc/added "2.14"
|
||||||
|
::sm/params schema:redeem-activation-code-params
|
||||||
|
::sm/result schema:redeem-activation-code-result}
|
||||||
|
[cfg {:keys [::rpc/profile-id activation-code]}]
|
||||||
|
(let [profile (db/get cfg :profile {:id profile-id})]
|
||||||
|
(try
|
||||||
|
(let [result (nitrate/call cfg :redeem-activation-code
|
||||||
|
{:request-params {:code activation-code
|
||||||
|
:penpot-id profile-id
|
||||||
|
:email (:email profile)}})]
|
||||||
|
(when-not result
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :invalid-activation-code
|
||||||
|
:hint "The activation code is invalid, expired or fully redeemed"))
|
||||||
|
result)
|
||||||
|
(catch Exception cause
|
||||||
|
(let [{:keys [type status]} (ex-data cause)]
|
||||||
|
(if (= type :nitrate-http-error)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code (case status
|
||||||
|
410 :expired-activation-code
|
||||||
|
:invalid-activation-code)
|
||||||
|
:cause cause)
|
||||||
|
(throw cause)))))))
|
||||||
|
|
||||||
|
(def ^:private sql:prefix-team-name-and-unset-default
|
||||||
|
"UPDATE team
|
||||||
|
SET name = ? || name,
|
||||||
|
is_default = FALSE
|
||||||
|
WHERE id = ?;")
|
||||||
|
|
||||||
|
(def ^:private sql:get-member-teams-info
|
||||||
|
"SELECT t.id,
|
||||||
|
t.is_default,
|
||||||
|
tpr.is_owner,
|
||||||
|
(SELECT count(*) FROM team_profile_rel WHERE team_id = t.id) AS num_members,
|
||||||
|
(SELECT array_agg(profile_id) FROM team_profile_rel WHERE team_id = t.id) AS member_ids
|
||||||
|
FROM team AS t
|
||||||
|
JOIN team_profile_rel AS tpr ON (tpr.team_id = t.id)
|
||||||
|
WHERE tpr.profile_id = ?
|
||||||
|
AND t.id = ANY(?)
|
||||||
|
AND t.deleted_at IS NULL")
|
||||||
|
|
||||||
|
(def sql:get-team-files-count
|
||||||
|
"SELECT count(*) AS total
|
||||||
|
FROM file AS f
|
||||||
|
JOIN project AS p ON (p.id = f.project_id)
|
||||||
|
WHERE p.team_id = ?
|
||||||
|
AND f.deleted_at IS NULL")
|
||||||
|
|
||||||
|
(def ^:private schema:leave-org
|
||||||
|
[:map
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:name ::sm/text]
|
||||||
|
[:default-team-id ::sm/uuid]
|
||||||
|
[:teams-to-delete
|
||||||
|
[:vector ::sm/uuid]]
|
||||||
|
[:teams-to-leave
|
||||||
|
[:vector
|
||||||
|
[:map
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:reassign-to {:optional true} ::sm/uuid]]]]])
|
||||||
|
|
||||||
|
|
||||||
|
(defn- get-organization-teams-for-user
|
||||||
|
[{:keys [::db/conn] :as cfg} org-summary profile-id]
|
||||||
|
(let [org-team-ids (->> (:teams org-summary)
|
||||||
|
(map :id))
|
||||||
|
ids-array (db/create-array conn "uuid" org-team-ids)]
|
||||||
|
(db/exec! conn [sql:get-member-teams-info profile-id ids-array])))
|
||||||
|
|
||||||
|
(defn- calculate-valid-teams
|
||||||
|
([org-teams default-team-id]
|
||||||
|
(let [;; valid default team is the one which id is default-team-id
|
||||||
|
valid-default-team (d/seek #(= default-team-id (:id %)) org-teams)
|
||||||
|
|
||||||
|
;; Remove your-penpot for the rest of validations
|
||||||
|
org-teams (remove #(= default-team-id (:id %)) org-teams)
|
||||||
|
|
||||||
|
;; valid teams to delete are those that the user is owner, and only have one member
|
||||||
|
valid-teams-to-delete-ids (->> org-teams
|
||||||
|
(filter #(and (:is-owner %)
|
||||||
|
(= (:num-members %) 1)))
|
||||||
|
(map :id)
|
||||||
|
(into #{}))
|
||||||
|
;; valid teams to transfer are those that the user is owner, and have more than one member
|
||||||
|
valid-teams-to-transfer (->> org-teams
|
||||||
|
(filter #(and (:is-owner %)
|
||||||
|
(> (:num-members %) 1))))
|
||||||
|
|
||||||
|
;; valid teams to exit are those that the user isn't owner, and have more than one member
|
||||||
|
valid-teams-to-exit (->> org-teams
|
||||||
|
(filter #(and (not (:is-owner %))
|
||||||
|
(> (:num-members %) 1))))]
|
||||||
|
{:valid-teams-to-delete-ids valid-teams-to-delete-ids
|
||||||
|
:valid-teams-to-transfer valid-teams-to-transfer
|
||||||
|
:valid-teams-to-exit valid-teams-to-exit
|
||||||
|
:valid-default-team valid-default-team})))
|
||||||
|
|
||||||
|
(defn get-valid-teams [cfg organization-id profile-id default-team-id]
|
||||||
|
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||||
|
org-teams (get-organization-teams-for-user cfg org-summary profile-id)]
|
||||||
|
(calculate-valid-teams org-teams default-team-id)))
|
||||||
|
|
||||||
|
(defn- assert-valid-teams [cfg profile-id organization-id default-team-id teams-to-delete teams-to-leave]
|
||||||
|
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||||
|
org-teams (get-organization-teams-for-user cfg org-summary profile-id)
|
||||||
|
{:keys [valid-teams-to-delete-ids
|
||||||
|
valid-teams-to-transfer
|
||||||
|
valid-teams-to-exit
|
||||||
|
valid-default-team]} (calculate-valid-teams org-teams default-team-id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
valid-teams-to-exit-ids (->> valid-teams-to-exit (map :id) (into #{}))
|
||||||
|
valid-teams-to-transfer-ids (->> valid-teams-to-transfer (map :id) (into #{}))
|
||||||
|
valid-teams-to-leave-ids (into valid-teams-to-transfer-ids valid-teams-to-exit-ids)
|
||||||
|
|
||||||
|
valid-default-team-id? (some? valid-default-team)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
valid-teams-to-delete? (= valid-teams-to-delete-ids (into #{} teams-to-delete))
|
||||||
|
|
||||||
|
;; for every team in teams-to-leave, check that:
|
||||||
|
;; - if it has a reassign-to, it belongs to valid-teams-to-transfer and
|
||||||
|
;; the reassign-to is a member of the team and not the current user;
|
||||||
|
;; - if it hasn't a reassign-to, check that it belongs to valid-teams-to-exit
|
||||||
|
teams-by-id (d/index-by :id org-teams)
|
||||||
|
valid-teams-to-leave? (and
|
||||||
|
(= valid-teams-to-leave-ids (->> teams-to-leave (map :id) (into #{})))
|
||||||
|
(every? (fn [{:keys [id reassign-to]}]
|
||||||
|
(if reassign-to
|
||||||
|
(let [members (db/pgarray->set (:member-ids (get teams-by-id id)))]
|
||||||
|
(and (contains? valid-teams-to-transfer-ids id)
|
||||||
|
(not= reassign-to profile-id)
|
||||||
|
(contains? members reassign-to)))
|
||||||
|
(contains? valid-teams-to-exit-ids id)))
|
||||||
|
teams-to-leave))]
|
||||||
|
;; the org owner cannot leave
|
||||||
|
(when (= (:owner-id org-summary) profile-id)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :org-owner-cannot-leave))
|
||||||
|
|
||||||
|
(when (or
|
||||||
|
(not valid-teams-to-delete?)
|
||||||
|
(not valid-teams-to-leave?)
|
||||||
|
(not valid-default-team-id?))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :not-valid-teams))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn leave-org
|
||||||
|
[{:keys [::db/conn] :as cfg} {:keys [profile-id id name default-team-id teams-to-delete teams-to-leave skip-validation] :as params}]
|
||||||
|
(let [org-prefix (str "[" (d/sanitize-string name) "] ")
|
||||||
|
|
||||||
|
default-team-files-count (-> (db/exec-one! conn [sql:get-team-files-count default-team-id])
|
||||||
|
:total)
|
||||||
|
delete-default-team? (= default-team-files-count 0)]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; assert that the received teams are valid, checking the different constraints
|
||||||
|
(when-not skip-validation
|
||||||
|
(assert-valid-teams cfg profile-id id default-team-id teams-to-delete teams-to-leave))
|
||||||
|
|
||||||
|
(assert-membership cfg profile-id id)
|
||||||
|
|
||||||
|
;; delete the teams-to-delete
|
||||||
|
(doseq [id teams-to-delete]
|
||||||
|
(teams/delete-team cfg {:profile-id profile-id :team-id id}))
|
||||||
|
|
||||||
|
;; leave the teams-to-leave
|
||||||
|
(doseq [{:keys [id reassign-to]} teams-to-leave]
|
||||||
|
(teams/leave-team cfg {:profile-id profile-id :id id :reassign-to reassign-to}))
|
||||||
|
|
||||||
|
;; Delete default-team-id if empty; otherwise keep it and prefix the name.
|
||||||
|
(if delete-default-team?
|
||||||
|
(do
|
||||||
|
(db/update! conn :team {:is-default false} {:id default-team-id})
|
||||||
|
(teams/delete-team cfg {:profile-id profile-id :team-id default-team-id}))
|
||||||
|
(db/exec! conn [sql:prefix-team-name-and-unset-default org-prefix default-team-id]))
|
||||||
|
|
||||||
|
;; Api call to nitrate
|
||||||
|
(nitrate/call cfg :remove-profile-from-org {:profile-id profile-id :organization-id id})
|
||||||
|
|
||||||
|
nil))
|
||||||
|
|
||||||
|
|
||||||
|
(sv/defmethod ::leave-org
|
||||||
|
{::rpc/auth true
|
||||||
|
::doc/added "2.15"
|
||||||
|
::sm/params schema:leave-org
|
||||||
|
::db/transaction true}
|
||||||
|
[cfg {:keys [::rpc/profile-id] :as params}]
|
||||||
|
(leave-org cfg (assoc params :profile-id profile-id)))
|
||||||
|
|
||||||
|
|
||||||
|
(def ^:private schema:remove-team-from-org
|
||||||
|
[:map
|
||||||
|
[:team-id ::sm/uuid]
|
||||||
|
[:organization-id ::sm/uuid]
|
||||||
|
[:organization-name ::sm/text]])
|
||||||
|
|
||||||
|
(sv/defmethod ::remove-team-from-org
|
||||||
|
{::doc/added "2.17"
|
||||||
|
::sm/params schema:remove-team-from-org}
|
||||||
|
[cfg {:keys [::rpc/profile-id team-id organization-id organization-name]}]
|
||||||
|
|
||||||
|
(assert-is-owner cfg profile-id team-id)
|
||||||
|
(assert-not-default-team cfg team-id)
|
||||||
|
(assert-membership cfg profile-id organization-id)
|
||||||
|
|
||||||
|
;; Api call to nitrate
|
||||||
|
(nitrate/call cfg :remove-team-from-org {:team-id team-id :organization-id organization-id})
|
||||||
|
|
||||||
|
;; Notify connected users
|
||||||
|
(notifications/notify-team-change cfg {:id team-id :organization {:name organization-name}} "dashboard.team-no-longer-belong-org")
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
(def ^:private schema:add-team-to-organization
|
||||||
|
[:map
|
||||||
|
[:team-id ::sm/uuid]
|
||||||
|
[:organization-id ::sm/uuid]])
|
||||||
|
|
||||||
|
(sv/defmethod ::add-team-to-organization
|
||||||
|
{::rpc/auth true
|
||||||
|
::doc/added "2.17"
|
||||||
|
::sm/params schema:add-team-to-organization
|
||||||
|
::db/transaction true}
|
||||||
|
[cfg {:keys [::rpc/profile-id team-id organization-id]}]
|
||||||
|
|
||||||
|
(assert-is-owner cfg profile-id team-id)
|
||||||
|
(assert-not-default-team cfg team-id)
|
||||||
|
(assert-membership cfg profile-id organization-id)
|
||||||
|
|
||||||
|
(when (contains? cf/flags :nitrate)
|
||||||
|
(let [org-perms (nitrate/call cfg :get-org-permissions
|
||||||
|
{:organization-id organization-id})]
|
||||||
|
(if (nil? org-perms)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :not-allowed
|
||||||
|
:hint "Unable to verify organization permissions")
|
||||||
|
(when-not (nitrate-perms/allowed? :create-team
|
||||||
|
{:org-perms org-perms
|
||||||
|
:profile-id profile-id})
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :not-allowed
|
||||||
|
:hint "You are not allowed to add teams in this organization")))))
|
||||||
|
|
||||||
|
(let [team-members (db/query cfg :team-profile-rel {:team-id team-id})]
|
||||||
|
;; Add teammates to the org if needed
|
||||||
|
(doseq [{member-id :profile-id} team-members
|
||||||
|
:when (not= member-id profile-id)]
|
||||||
|
(teams/initialize-user-in-nitrate-org cfg member-id organization-id)))
|
||||||
|
|
||||||
|
;; Api call to nitrate
|
||||||
|
(let [team (nitrate/call cfg :set-team-org {:team-id team-id :organization-id organization-id :is-default false})]
|
||||||
|
|
||||||
|
;; Notify connected users
|
||||||
|
(notifications/notify-team-change cfg team "dashboard.team-belong-org"))
|
||||||
|
nil)
|
||||||
@ -48,6 +48,8 @@
|
|||||||
(def schema:props
|
(def schema:props
|
||||||
[:map {:title "ProfileProps"}
|
[:map {:title "ProfileProps"}
|
||||||
[:plugins {:optional true} schema:plugin-registry]
|
[:plugins {:optional true} schema:plugin-registry]
|
||||||
|
[:renderer {:optional true} [::sm/one-of #{:svg :wasm}]]
|
||||||
|
[:mcp-enabled {:optional true} ::sm/boolean]
|
||||||
[:newsletter-updates {:optional true} ::sm/boolean]
|
[:newsletter-updates {:optional true} ::sm/boolean]
|
||||||
[:newsletter-news {:optional true} ::sm/boolean]
|
[:newsletter-news {:optional true} ::sm/boolean]
|
||||||
[:onboarding-team-id {:optional true} ::sm/uuid]
|
[:onboarding-team-id {:optional true} ::sm/uuid]
|
||||||
@ -108,8 +110,10 @@
|
|||||||
(nitrate/add-nitrate-licence-to-profile cfg profile)
|
(nitrate/add-nitrate-licence-to-profile cfg profile)
|
||||||
profile))
|
profile))
|
||||||
|
|
||||||
(catch Throwable _
|
(catch Throwable cause
|
||||||
{:id uuid/zero :fullname "Anonymous User"})))
|
(if (= :not-found (-> cause ex-data :type))
|
||||||
|
{:id uuid/zero :fullname "Anonymous User"}
|
||||||
|
(throw cause)))))
|
||||||
|
|
||||||
(defn get-profile
|
(defn get-profile
|
||||||
"Get profile by id. Throws not-found exception if no profile found."
|
"Get profile by id. Throws not-found exception if no profile found."
|
||||||
@ -313,6 +317,25 @@
|
|||||||
(climit/invoke! generate-thumbnail file))]
|
(climit/invoke! generate-thumbnail file))]
|
||||||
(sto/put-object! storage params)))
|
(sto/put-object! storage params)))
|
||||||
|
|
||||||
|
;; --- MUTATION: Delete Photo
|
||||||
|
|
||||||
|
(sv/defmethod ::delete-profile-photo
|
||||||
|
{::doc/added "2.17"
|
||||||
|
::sm/params [:map]
|
||||||
|
::sm/result :nil
|
||||||
|
::db/transaction true}
|
||||||
|
[{:keys [::db/conn ::sto/storage]} {:keys [::rpc/profile-id]}]
|
||||||
|
(let [profile (get-profile conn profile-id ::db/for-update true)]
|
||||||
|
(when-let [id (:photo-id profile)]
|
||||||
|
(sto/touch-object! storage id))
|
||||||
|
|
||||||
|
(db/update! conn :profile
|
||||||
|
{:photo-id nil}
|
||||||
|
{:id profile-id}
|
||||||
|
{::db/return-keys false})
|
||||||
|
|
||||||
|
nil))
|
||||||
|
|
||||||
;; --- MUTATION: Request Email Change
|
;; --- MUTATION: Request Email Change
|
||||||
|
|
||||||
(declare ^:private request-email-change!)
|
(declare ^:private request-email-change!)
|
||||||
@ -461,6 +484,9 @@
|
|||||||
{:deleted-at deleted-at}
|
{:deleted-at deleted-at}
|
||||||
{:id profile-id})
|
{:id profile-id})
|
||||||
|
|
||||||
|
;; Api call to nitrate
|
||||||
|
(nitrate/call cfg :remove-profile-from-all-orgs {:profile-id profile-id})
|
||||||
|
|
||||||
;; Schedule cascade deletion to a worker
|
;; Schedule cascade deletion to a worker
|
||||||
(wrk/submit! {::db/conn conn
|
(wrk/submit! {::db/conn conn
|
||||||
::wrk/task :delete-object
|
::wrk/task :delete-object
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
[app.common.features :as cfeat]
|
[app.common.features :as cfeat]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.time :as ct]
|
[app.common.time :as ct]
|
||||||
|
[app.common.types.nitrate-permissions :as nitrate-perms]
|
||||||
[app.common.types.team :as types.team]
|
[app.common.types.team :as types.team]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
@ -193,7 +194,7 @@
|
|||||||
(dm/with-open [conn (db/open pool)]
|
(dm/with-open [conn (db/open pool)]
|
||||||
(cond->> (get-teams conn profile-id)
|
(cond->> (get-teams conn profile-id)
|
||||||
(contains? cf/flags :nitrate)
|
(contains? cf/flags :nitrate)
|
||||||
(map #(nitrate/add-org-to-team cfg % params)))))
|
(map #(nitrate/add-org-info-to-team cfg % params)))))
|
||||||
|
|
||||||
(def ^:private sql:get-owned-teams
|
(def ^:private sql:get-owned-teams
|
||||||
"SELECT t.id, t.name,
|
"SELECT t.id, t.name,
|
||||||
@ -471,8 +472,8 @@
|
|||||||
;; --- COMMAND QUERY: get-team-info
|
;; --- COMMAND QUERY: get-team-info
|
||||||
|
|
||||||
(defn get-team-info
|
(defn get-team-info
|
||||||
[{:keys [::db/conn] :as cfg} {:keys [id] :as params}]
|
[cfg {:keys [id] :as params}]
|
||||||
(-> (db/get* conn :team
|
(-> (db/get* cfg :team
|
||||||
{:id id}
|
{:id id}
|
||||||
{::sql/columns [:id :is-default :features]})
|
{::sql/columns [:id :is-default :features]})
|
||||||
(decode-row)))
|
(decode-row)))
|
||||||
@ -497,18 +498,36 @@
|
|||||||
|
|
||||||
(def ^:private schema:create-team
|
(def ^:private schema:create-team
|
||||||
[:map {:title "create-team"}
|
[:map {:title "create-team"}
|
||||||
[:name [:string {:max 250}]]
|
[:name types.team/schema:team-name]
|
||||||
[:features {:optional true} ::cfeat/features]
|
[:features {:optional true} ::cfeat/features]
|
||||||
[:id {:optional true} ::sm/uuid]])
|
[:id {:optional true} ::sm/uuid]
|
||||||
|
[:organization-id {:optional true} ::sm/uuid]
|
||||||
|
[:is-default {:optional true} :boolean]])
|
||||||
|
|
||||||
(sv/defmethod ::create-team
|
(sv/defmethod ::create-team
|
||||||
{::doc/added "1.17"
|
{::doc/added "1.17"
|
||||||
::sm/params schema:create-team}
|
::sm/params schema:create-team}
|
||||||
[cfg {:keys [::rpc/profile-id] :as params}]
|
[cfg {:keys [::rpc/profile-id organization-id] :as params}]
|
||||||
|
|
||||||
(quotes/check! cfg {::quotes/id ::quotes/teams-per-profile
|
(quotes/check! cfg {::quotes/id ::quotes/teams-per-profile
|
||||||
::quotes/profile-id profile-id})
|
::quotes/profile-id profile-id})
|
||||||
|
|
||||||
|
;; When creating inside an org, verify the user has permission to do so.
|
||||||
|
;; Fail closed: if org permissions cannot be fetched, deny the operation.
|
||||||
|
(when (and organization-id (contains? cf/flags :nitrate))
|
||||||
|
(let [org-perms (nitrate/call cfg :get-org-permissions
|
||||||
|
{:organization-id organization-id})]
|
||||||
|
(if (nil? org-perms)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :not-allowed
|
||||||
|
:hint "Unable to verify organization permissions")
|
||||||
|
(when-not (nitrate-perms/allowed? :create-team
|
||||||
|
{:org-perms org-perms
|
||||||
|
:profile-id profile-id})
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :not-allowed
|
||||||
|
:hint "You are not allowed to create teams in this organization")))))
|
||||||
|
|
||||||
(let [features (-> (cfeat/get-enabled-features cf/flags)
|
(let [features (-> (cfeat/get-enabled-features cf/flags)
|
||||||
(set/difference cfeat/frontend-only-features)
|
(set/difference cfeat/frontend-only-features)
|
||||||
(set/difference cfeat/no-team-inheritable-features))
|
(set/difference cfeat/no-team-inheritable-features))
|
||||||
@ -520,17 +539,89 @@
|
|||||||
(with-meta team
|
(with-meta team
|
||||||
{::audit/props {:id (:id team)}})))
|
{::audit/props {:id (:id team)}})))
|
||||||
|
|
||||||
|
|
||||||
|
(defn create-default-org-team
|
||||||
|
[cfg profile-id organization-id]
|
||||||
|
(quotes/check! cfg {::quotes/id ::quotes/teams-per-profile
|
||||||
|
::quotes/profile-id profile-id})
|
||||||
|
|
||||||
|
(let [features (-> (cfeat/get-enabled-features cf/flags)
|
||||||
|
(set/difference cfeat/frontend-only-features)
|
||||||
|
(set/difference cfeat/no-team-inheritable-features))
|
||||||
|
params {:profile-id profile-id
|
||||||
|
:name "Your Penpot"
|
||||||
|
:features features
|
||||||
|
:organization-id organization-id
|
||||||
|
:is-default true}
|
||||||
|
team (create-team cfg params)]
|
||||||
|
(select-keys team [:id])))
|
||||||
|
|
||||||
|
(defn initialize-user-in-nitrate-org
|
||||||
|
"If needed, create a default team for the user on the organization,
|
||||||
|
and notify Nitrate that an user has been added to an org."
|
||||||
|
([cfg profile-id organization-id]
|
||||||
|
(initialize-user-in-nitrate-org cfg profile-id organization-id nil))
|
||||||
|
([cfg profile-id organization-id email]
|
||||||
|
(assert (db/connection-map? cfg)
|
||||||
|
"expected cfg with valid connection")
|
||||||
|
(when (contains? cf/flags :nitrate)
|
||||||
|
(db/tx-run!
|
||||||
|
cfg
|
||||||
|
(fn [{:keys [::db/conn] :as tx-cfg}]
|
||||||
|
|
||||||
|
(let [membership (nitrate/call cfg :get-org-membership {:profile-id profile-id
|
||||||
|
:organization-id organization-id})]
|
||||||
|
;; Only when the user doesn't belong to the organization yet
|
||||||
|
(when (and
|
||||||
|
(some? (:organization-id membership)) ;; the organization exists
|
||||||
|
(not (:is-member membership))) ;; the user is not a member of the org yet
|
||||||
|
|
||||||
|
|
||||||
|
(let [organization-id organization-id
|
||||||
|
default-team (create-default-org-team (assoc tx-cfg ::db/conn conn) profile-id organization-id)
|
||||||
|
default-team-id (:id default-team)
|
||||||
|
result (nitrate/call tx-cfg :add-profile-to-org (cond-> {:profile-id profile-id
|
||||||
|
:team-id default-team-id
|
||||||
|
:organization-id organization-id}
|
||||||
|
(some? email) (assoc :email email)))]
|
||||||
|
(when (not (:is-member result))
|
||||||
|
(ex/raise :type :internal
|
||||||
|
:code :failed-add-profile-org-nitrate
|
||||||
|
:context {:profile-id profile-id
|
||||||
|
:organization-id organization-id
|
||||||
|
:default-team-id default-team-id}))
|
||||||
|
default-team-id))))))))
|
||||||
|
|
||||||
|
(defn add-profile-to-team!
|
||||||
|
([cfg params]
|
||||||
|
(add-profile-to-team! cfg params nil))
|
||||||
|
([{:keys [::db/conn] :as cfg} {:keys [:profile-id :team-id] :as params} options]
|
||||||
|
(assert (db/connection-map? cfg)
|
||||||
|
"expected cfg with valid connection")
|
||||||
|
(when (contains? cf/flags :nitrate)
|
||||||
|
(let [membership (nitrate/call cfg :get-org-membership-by-team {:profile-id profile-id :team-id team-id})]
|
||||||
|
;; Only when the team belong to an organization and the user is not a member
|
||||||
|
(when (and
|
||||||
|
(some? (:organization-id membership)) ;; the team do belong to an organization
|
||||||
|
(not (:is-member membership))) ;; the user is not a member of the org yet
|
||||||
|
(initialize-user-in-nitrate-org cfg profile-id (:organization-id membership)))))
|
||||||
|
(db/insert! conn :team-profile-rel params options)))
|
||||||
|
|
||||||
(defn create-team
|
(defn create-team
|
||||||
"This is a complete team creation process, it creates the team
|
"This is a complete team creation process, it creates the team
|
||||||
object and all related objects (default role and default project)."
|
object and all related objects (default role and default project)."
|
||||||
[cfg-or-conn params]
|
[{:keys [::db/conn] :as cfg} params]
|
||||||
(let [conn (db/get-connection cfg-or-conn)
|
(assert (db/connection-map? cfg)
|
||||||
team (create-team* conn params)
|
"expected cfg with valid connection")
|
||||||
|
(let [team (create-team* conn params)
|
||||||
params (assoc params
|
params (assoc params
|
||||||
:team-id (:id team)
|
:team-id (:id team)
|
||||||
:role :owner)
|
:role :owner)
|
||||||
project (create-team-default-project conn params)]
|
project (create-team-default-project conn params)]
|
||||||
(create-team-role conn params)
|
(create-team-role cfg params)
|
||||||
|
;; Set team organization in Nitrate if organization-id is provided
|
||||||
|
(when (and (contains? cf/flags :nitrate) (:organization-id params))
|
||||||
|
(nitrate/set-team-organization cfg team params))
|
||||||
(assoc team :default-project-id (:id project))))
|
(assoc team :default-project-id (:id project))))
|
||||||
|
|
||||||
(defn- create-team*
|
(defn- create-team*
|
||||||
@ -546,11 +637,13 @@
|
|||||||
(decode-row team)))
|
(decode-row team)))
|
||||||
|
|
||||||
(defn- create-team-role
|
(defn- create-team-role
|
||||||
[conn {:keys [profile-id team-id role] :as params}]
|
[cfg {:keys [profile-id team-id role] :as params}]
|
||||||
|
(assert (db/connection-map? cfg)
|
||||||
|
"expected cfg with valid connection")
|
||||||
(let [params {:team-id team-id
|
(let [params {:team-id team-id
|
||||||
:profile-id profile-id}]
|
:profile-id profile-id}]
|
||||||
(->> (perms/assign-role-flags params role)
|
(->> (perms/assign-role-flags params role)
|
||||||
(db/insert! conn :team-profile-rel))))
|
(add-profile-to-team! cfg))))
|
||||||
|
|
||||||
(defn- create-team-default-project
|
(defn- create-team-default-project
|
||||||
[conn {:keys [profile-id team-id] :as params}]
|
[conn {:keys [profile-id team-id] :as params}]
|
||||||
@ -591,7 +684,7 @@
|
|||||||
|
|
||||||
(def ^:private schema:update-team
|
(def ^:private schema:update-team
|
||||||
[:map {:title "update-team"}
|
[:map {:title "update-team"}
|
||||||
[:name [:string {:max 250}]]
|
[:name types.team/schema:team-name]
|
||||||
[:id ::sm/uuid]])
|
[:id ::sm/uuid]])
|
||||||
|
|
||||||
(sv/defmethod ::update-team
|
(sv/defmethod ::update-team
|
||||||
@ -609,7 +702,7 @@
|
|||||||
;; --- Mutation: Leave Team
|
;; --- Mutation: Leave Team
|
||||||
|
|
||||||
(defn leave-team
|
(defn leave-team
|
||||||
[conn {:keys [profile-id id reassign-to]}]
|
[{:keys [::db/conn ::mbus/msgbus]} {:keys [profile-id id reassign-to]}]
|
||||||
(let [perms (get-permissions conn profile-id id)
|
(let [perms (get-permissions conn profile-id id)
|
||||||
members (get-team-members conn id)]
|
members (get-team-members conn id)]
|
||||||
|
|
||||||
@ -624,7 +717,9 @@
|
|||||||
;; if the `reassign-to` is filled and has a different value
|
;; if the `reassign-to` is filled and has a different value
|
||||||
;; than the current profile-id, we proceed to reassing the
|
;; than the current profile-id, we proceed to reassing the
|
||||||
;; owner role to profile identified by the `reassign-to`.
|
;; owner role to profile identified by the `reassign-to`.
|
||||||
(and reassign-to (not= reassign-to profile-id))
|
;; Ignore the reasignation if the current profile is not
|
||||||
|
;; the owner
|
||||||
|
(and reassign-to (not= reassign-to profile-id) (:is-owner perms))
|
||||||
(let [member (d/seek #(= reassign-to (:id %)) members)]
|
(let [member (d/seek #(= reassign-to (:id %)) members)]
|
||||||
(when-not member
|
(when-not member
|
||||||
(ex/raise :type :not-found :code :member-does-not-exist))
|
(ex/raise :type :not-found :code :member-does-not-exist))
|
||||||
@ -638,7 +733,15 @@
|
|||||||
;; assign owner role to new profile
|
;; assign owner role to new profile
|
||||||
(db/update! conn :team-profile-rel
|
(db/update! conn :team-profile-rel
|
||||||
(get types.team/permissions-for-role :owner)
|
(get types.team/permissions-for-role :owner)
|
||||||
{:team-id id :profile-id reassign-to}))
|
{:team-id id :profile-id reassign-to})
|
||||||
|
|
||||||
|
;; notify new owner
|
||||||
|
(mbus/pub! msgbus
|
||||||
|
:topic reassign-to
|
||||||
|
:message {:type :team-role-change
|
||||||
|
:topic reassign-to
|
||||||
|
:team-id id
|
||||||
|
:role :owner}))
|
||||||
|
|
||||||
;; and finally, if all other conditions does not match and the
|
;; and finally, if all other conditions does not match and the
|
||||||
;; current profile is owner, we dont allow it because there
|
;; current profile is owner, we dont allow it because there
|
||||||
@ -663,32 +766,59 @@
|
|||||||
{::doc/added "1.17"
|
{::doc/added "1.17"
|
||||||
::sm/params schema:leave-team
|
::sm/params schema:leave-team
|
||||||
::db/transaction true}
|
::db/transaction true}
|
||||||
[{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id] :as params}]
|
[cfg {:keys [::rpc/profile-id] :as params}]
|
||||||
(leave-team conn (assoc params :profile-id profile-id)))
|
(leave-team cfg (assoc params :profile-id profile-id)))
|
||||||
|
|
||||||
|
|
||||||
;; --- Mutation: Delete Team
|
;; --- Mutation: Delete Team
|
||||||
|
|
||||||
(defn- delete-team
|
(defn delete-team
|
||||||
"Mark a team for deletion"
|
"Mark a team for deletion"
|
||||||
[conn {:keys [id] :as team}]
|
[{:keys [::db/conn] :as cfg} {:keys [profile-id team-id] :as params}]
|
||||||
|
|
||||||
(let [delay (ldel/get-deletion-delay team)
|
(let [team (get-team conn :profile-id profile-id :team-id team-id)
|
||||||
team (db/update! conn :team
|
team (if (contains? cf/flags :nitrate)
|
||||||
{:deleted-at (ct/in-future delay)}
|
(nitrate/add-org-info-to-team cfg team params)
|
||||||
{:id id}
|
team)
|
||||||
{::db/return-keys true})]
|
perms (get team :permissions)]
|
||||||
|
|
||||||
(when (:is-default team)
|
(when (:is-default team)
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :non-deletable-team
|
:code :non-deletable-team
|
||||||
:hint "impossible to delete default team"))
|
:hint "impossible to delete default team"))
|
||||||
|
|
||||||
|
;; Check delete permissions based on organization settings.
|
||||||
|
;; For non-org teams or when nitrate is disabled, only owners can delete.
|
||||||
|
(if (and (:organization team) (contains? cf/flags :nitrate))
|
||||||
|
(let [org-perms {:owner-id (dm/get-in team [:organization :owner-id])
|
||||||
|
:permissions (dm/get-in team [:organization :permissions])}]
|
||||||
|
(when-not (nitrate-perms/allowed? :delete-team
|
||||||
|
{:org-perms org-perms
|
||||||
|
:profile-id profile-id
|
||||||
|
:team-perms perms})
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :not-allowed
|
||||||
|
:hint "You are not allowed to delete teams in this organization")))
|
||||||
|
(when-not (:is-owner perms)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :only-owner-can-delete-team)))
|
||||||
|
|
||||||
|
(let [delay (ldel/get-deletion-delay team)
|
||||||
|
team (db/update! conn :team
|
||||||
|
{:deleted-at (ct/in-future delay)}
|
||||||
|
{:id team-id}
|
||||||
|
{::db/return-keys true})]
|
||||||
|
|
||||||
|
;; Api call to nitrate
|
||||||
|
(when (contains? cf/flags :nitrate)
|
||||||
|
(nitrate/call cfg :delete-team {:profile-id profile-id :team-id team-id}))
|
||||||
|
|
||||||
(wrk/submit! {::db/conn conn
|
(wrk/submit! {::db/conn conn
|
||||||
::wrk/task :delete-object
|
::wrk/task :delete-object
|
||||||
::wrk/params {:object :team
|
::wrk/params {:object :team
|
||||||
:deleted-at (:deleted-at team)
|
:deleted-at (:deleted-at team)
|
||||||
:id id}})
|
:id team-id}})
|
||||||
team))
|
team)))
|
||||||
|
|
||||||
(def ^:private schema:delete-team
|
(def ^:private schema:delete-team
|
||||||
[:map {:title "delete-team"}
|
[:map {:title "delete-team"}
|
||||||
@ -698,16 +828,9 @@
|
|||||||
{::doc/added "1.17"
|
{::doc/added "1.17"
|
||||||
::sm/params schema:delete-team
|
::sm/params schema:delete-team
|
||||||
::db/transaction true}
|
::db/transaction true}
|
||||||
[{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id id] :as params}]
|
[cfg {:keys [::rpc/profile-id id] :as params}]
|
||||||
(let [team (get-team conn :profile-id profile-id :team-id id)
|
(delete-team cfg {:team-id id :profile-id profile-id})
|
||||||
perms (get team :permissions)]
|
nil)
|
||||||
|
|
||||||
(when-not (:is-owner perms)
|
|
||||||
(ex/raise :type :validation
|
|
||||||
:code :only-owner-can-delete-team))
|
|
||||||
|
|
||||||
(delete-team conn team)
|
|
||||||
nil))
|
|
||||||
|
|
||||||
;; --- Mutation: Team Update Role
|
;; --- Mutation: Team Update Role
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
[app.email.blacklist :as email.blacklist]
|
[app.email.blacklist :as email.blacklist]
|
||||||
[app.loggers.audit :as audit]
|
[app.loggers.audit :as audit]
|
||||||
[app.main :as-alias main]
|
[app.main :as-alias main]
|
||||||
|
[app.nitrate :as nitrate]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.commands.profile :as profile]
|
[app.rpc.commands.profile :as profile]
|
||||||
[app.rpc.commands.teams :as teams]
|
[app.rpc.commands.teams :as teams]
|
||||||
@ -36,20 +37,29 @@
|
|||||||
;; --- Mutation: Create Team Invitation
|
;; --- Mutation: Create Team Invitation
|
||||||
|
|
||||||
(def sql:upsert-team-invitation
|
(def sql:upsert-team-invitation
|
||||||
"insert into team_invitation(id, team_id, email_to, created_by, role, valid_until)
|
"insert into team_invitation(id, team_id, org_id, email_to, created_by, role, valid_until)
|
||||||
values (?, ?, ?, ?, ?, ?)
|
values (?, ?, null, ?, ?, ?, ?)
|
||||||
on conflict(team_id, email_to) do
|
on conflict(team_id, email_to) do
|
||||||
update set role = ?, valid_until = ?, updated_at = now()
|
update set role = ?, valid_until = ?, updated_at = now()
|
||||||
returning *")
|
returning *")
|
||||||
|
|
||||||
|
(def sql:upsert-org-invitation
|
||||||
|
"insert into team_invitation(id, team_id, org_id, email_to, created_by, role, valid_until)
|
||||||
|
values (?, null, ?, ?, ?, ?, ?)
|
||||||
|
on conflict(org_id, email_to) where team_id is null do
|
||||||
|
update set role = ?, valid_until = ?, updated_at = now()
|
||||||
|
returning *")
|
||||||
|
|
||||||
(defn- create-invitation-token
|
(defn- create-invitation-token
|
||||||
[cfg {:keys [profile-id valid-until team-id member-id member-email role]}]
|
[cfg {:keys [profile-id valid-until organization-id organization-name team-id member-id member-email role]}]
|
||||||
(tokens/generate cfg
|
(tokens/generate cfg
|
||||||
{:iss :team-invitation
|
{:iss :team-invitation
|
||||||
:exp valid-until
|
:exp valid-until
|
||||||
:profile-id profile-id
|
:profile-id profile-id
|
||||||
:role role
|
:role role
|
||||||
:team-id team-id
|
:team-id team-id
|
||||||
|
:organization-id organization-id
|
||||||
|
:organization-name organization-name
|
||||||
:member-email member-email
|
:member-email member-email
|
||||||
:member-id member-id}))
|
:member-id member-id}))
|
||||||
|
|
||||||
@ -75,19 +85,41 @@
|
|||||||
[:role types.team/schema:role]
|
[:role types.team/schema:role]
|
||||||
[:email ::sm/email]])
|
[:email ::sm/email]])
|
||||||
|
|
||||||
|
(def ^:private schema:create-org-invitation
|
||||||
|
[:map {:title "params:create-org-invitation"}
|
||||||
|
[::rpc/profile-id ::sm/uuid]
|
||||||
|
[:organization
|
||||||
|
[:map
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:name :string]
|
||||||
|
[:initials [:maybe :string]]
|
||||||
|
[:logo ::sm/uri]]]
|
||||||
|
[:profile
|
||||||
|
[:map
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:fullname :string]]]
|
||||||
|
[:role types.team/schema:role]
|
||||||
|
[:email ::sm/email]])
|
||||||
|
|
||||||
(def ^:private check-create-invitation-params
|
(def ^:private check-create-invitation-params
|
||||||
(sm/check-fn schema:create-invitation))
|
(sm/check-fn schema:create-invitation))
|
||||||
|
|
||||||
|
(def ^:private check-create-org-invitation-params
|
||||||
|
(sm/check-fn schema:create-org-invitation))
|
||||||
|
|
||||||
(defn- allow-invitation-emails?
|
(defn- allow-invitation-emails?
|
||||||
[member]
|
[member]
|
||||||
(let [notifications (dm/get-in member [:props :notifications])]
|
(let [notifications (dm/get-in member [:props :notifications])]
|
||||||
(not= :none (:email-invites notifications))))
|
(not= :none (:email-invites notifications))))
|
||||||
|
|
||||||
(defn- create-invitation
|
(defn- create-invitation
|
||||||
[{:keys [::db/conn] :as cfg} {:keys [team profile role email] :as params}]
|
[{:keys [::db/conn] :as cfg} {:keys [team organization profile role email] :as params}]
|
||||||
|
|
||||||
(assert (db/connection? conn) "expected valid connection on cfg parameter")
|
(assert (db/connection-map? cfg)
|
||||||
(assert (check-create-invitation-params params))
|
"expected cfg with valid connection")
|
||||||
|
(if organization
|
||||||
|
(assert (check-create-org-invitation-params params))
|
||||||
|
(assert (check-create-invitation-params params)))
|
||||||
|
|
||||||
(let [email (profile/clean-email email)
|
(let [email (profile/clean-email email)
|
||||||
member (profile/get-profile-by-email conn email)]
|
member (profile/get-profile-by-email conn email)]
|
||||||
@ -110,9 +142,12 @@
|
|||||||
:profile-id (:id member)}
|
:profile-id (:id member)}
|
||||||
(get types.team/permissions-for-role role))]
|
(get types.team/permissions-for-role role))]
|
||||||
|
|
||||||
|
(if organization
|
||||||
|
;; Insert the invited member to the org
|
||||||
|
(when (contains? cf/flags :nitrate)
|
||||||
|
(teams/initialize-user-in-nitrate-org cfg (:id member) (:id organization) email))
|
||||||
;; Insert the invited member to the team
|
;; Insert the invited member to the team
|
||||||
(db/insert! conn :team-profile-rel params
|
(teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true}))
|
||||||
{::db/on-conflict-do-nothing? true})
|
|
||||||
|
|
||||||
;; If profile is not yet verified, mark it as verified because
|
;; If profile is not yet verified, mark it as verified because
|
||||||
;; accepting an invitation link serves as verification.
|
;; accepting an invitation link serves as verification.
|
||||||
@ -129,18 +164,30 @@
|
|||||||
(teams/check-email-spam conn email true)
|
(teams/check-email-spam conn email true)
|
||||||
|
|
||||||
(let [id (uuid/next)
|
(let [id (uuid/next)
|
||||||
expire (ct/in-future "168h") ;; 7 days
|
expire (if organization
|
||||||
invitation (db/exec-one! conn [sql:upsert-team-invitation id
|
(ct/in-future "876000h") ;; Organization invitations doesn't expire
|
||||||
(:id team) (str/lower email)
|
(ct/in-future "168h")) ;; 7 days
|
||||||
|
invitation (db/exec-one! conn (if organization
|
||||||
|
[sql:upsert-org-invitation id
|
||||||
|
(:id organization)
|
||||||
|
(str/lower email)
|
||||||
(:id profile)
|
(:id profile)
|
||||||
(name role) expire
|
(name role) expire
|
||||||
(name role) expire])
|
(name role) expire]
|
||||||
|
[sql:upsert-team-invitation id
|
||||||
|
(:id team)
|
||||||
|
(str/lower email)
|
||||||
|
(:id profile)
|
||||||
|
(name role) expire
|
||||||
|
(name role) expire]))
|
||||||
updated? (not= id (:id invitation))
|
updated? (not= id (:id invitation))
|
||||||
profile-id (:id profile)
|
profile-id (:id profile)
|
||||||
tprops {:profile-id profile-id
|
tprops {:profile-id profile-id
|
||||||
:invitation-id (:id invitation)
|
:invitation-id (:id invitation)
|
||||||
:valid-until expire
|
:valid-until expire
|
||||||
:team-id (:id team)
|
:team-id (:id team)
|
||||||
|
:organization-id (:id organization)
|
||||||
|
:organization-name (:name organization)
|
||||||
:member-email (:email-to invitation)
|
:member-email (:email-to invitation)
|
||||||
:member-id (:id member)
|
:member-id (:id member)
|
||||||
:role role}
|
:role role}
|
||||||
@ -152,28 +199,58 @@
|
|||||||
|
|
||||||
(let [props (-> (dissoc tprops :profile-id)
|
(let [props (-> (dissoc tprops :profile-id)
|
||||||
(audit/clean-props))
|
(audit/clean-props))
|
||||||
evname (if updated?
|
evname (cond
|
||||||
"update-team-invitation"
|
(and updated? organization) "update-org-invitation"
|
||||||
"create-team-invitation")
|
updated? "update-team-invitation"
|
||||||
|
organization "create-org-invitation"
|
||||||
|
:else "create-team-invitation")
|
||||||
event (-> (audit/event-from-rpc-params params)
|
event (-> (audit/event-from-rpc-params params)
|
||||||
(assoc ::audit/name evname)
|
(assoc :name evname)
|
||||||
(assoc ::audit/props props))]
|
(assoc :props props))]
|
||||||
(audit/submit! cfg event))
|
(audit/submit cfg event))
|
||||||
|
|
||||||
(when (allow-invitation-emails? member)
|
(when (allow-invitation-emails? member)
|
||||||
|
(if organization
|
||||||
|
(when (contains? cf/flags :nitrate)
|
||||||
|
(eml/send! {::eml/conn conn
|
||||||
|
::eml/factory eml/invite-to-org
|
||||||
|
:public-uri (cf/get :public-uri)
|
||||||
|
:to email
|
||||||
|
:invited-by (:fullname profile)
|
||||||
|
:user-name (:fullname member)
|
||||||
|
:organization-name (:name organization)
|
||||||
|
:organization-logo (:logo organization)
|
||||||
|
:organization-initials (:initials organization)
|
||||||
|
:token itoken
|
||||||
|
:extra-data ptoken}))
|
||||||
|
(let [team (if (contains? cf/flags :nitrate)
|
||||||
|
(nitrate/add-org-info-to-team cfg team {})
|
||||||
|
team)]
|
||||||
(eml/send! {::eml/conn conn
|
(eml/send! {::eml/conn conn
|
||||||
::eml/factory eml/invite-to-team
|
::eml/factory eml/invite-to-team
|
||||||
:public-uri (cf/get :public-uri)
|
:public-uri (cf/get :public-uri)
|
||||||
:to email
|
:to email
|
||||||
:invited-by (:fullname profile)
|
:invited-by (:fullname profile)
|
||||||
:team (:name team)
|
:team (:name team)
|
||||||
|
:organization (dm/get-in team [:organization :name])
|
||||||
:token itoken
|
:token itoken
|
||||||
:extra-data ptoken}))
|
:extra-data ptoken}))))
|
||||||
|
|
||||||
itoken)))))
|
itoken)))))
|
||||||
|
|
||||||
|
(defn create-org-invitation
|
||||||
|
[cfg {:keys [::rpc/profile-id id name initials logo] :as params}]
|
||||||
|
(let [profile (db/get-by-id cfg :profile profile-id)]
|
||||||
|
(create-invitation cfg
|
||||||
|
(assoc params
|
||||||
|
:organization {:id id :name name :initials initials :logo logo}
|
||||||
|
:profile profile
|
||||||
|
:role :editor))))
|
||||||
|
|
||||||
(defn- add-member-to-team
|
(defn- add-member-to-team
|
||||||
[conn profile team role member]
|
[{:keys [::db/conn] :as cfg} profile team role member]
|
||||||
|
(assert (db/connection-map? cfg)
|
||||||
|
"expected cfg with valid connection")
|
||||||
|
|
||||||
(let [team-id (:id team)
|
(let [team-id (:id team)
|
||||||
params (merge
|
params (merge
|
||||||
@ -193,7 +270,7 @@
|
|||||||
::quotes/team-id team-id})
|
::quotes/team-id team-id})
|
||||||
|
|
||||||
;; Insert the member to the team
|
;; Insert the member to the team
|
||||||
(db/insert! conn :team-profile-rel params {::db/on-conflict-do-nothing? true})
|
(teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true})
|
||||||
|
|
||||||
;; Delete any request
|
;; Delete any request
|
||||||
(db/delete! conn :team-access-request
|
(db/delete! conn :team-access-request
|
||||||
@ -275,7 +352,7 @@
|
|||||||
(filter #(contains? invitation-emails (key %)))
|
(filter #(contains? invitation-emails (key %)))
|
||||||
(map (fn [[email member]]
|
(map (fn [[email member]]
|
||||||
(let [role (:role (first (filter #(= (:email %) email) invitation-data)))]
|
(let [role (:role (first (filter #(= (:email %) email) invitation-data)))]
|
||||||
(add-member-to-team conn profile team role member))))
|
(add-member-to-team cfg profile team role member))))
|
||||||
(doall))
|
(doall))
|
||||||
|
|
||||||
invitations))
|
invitations))
|
||||||
@ -410,9 +487,9 @@
|
|||||||
|
|
||||||
(let [props {:name name :features features}
|
(let [props {:name name :features features}
|
||||||
event (-> (audit/event-from-rpc-params params)
|
event (-> (audit/event-from-rpc-params params)
|
||||||
(assoc ::audit/name "create-team")
|
(assoc :name "create-team")
|
||||||
(assoc ::audit/props props))]
|
(assoc :props props))]
|
||||||
(audit/submit! cfg event))
|
(audit/submit cfg event))
|
||||||
|
|
||||||
;; Create invitations for all provided emails.
|
;; Create invitations for all provided emails.
|
||||||
(let [profile (db/get-by-id conn :profile profile-id)
|
(let [profile (db/get-by-id conn :profile profile-id)
|
||||||
|
|||||||
@ -16,8 +16,10 @@
|
|||||||
[app.http.session :as session]
|
[app.http.session :as session]
|
||||||
[app.loggers.audit :as audit]
|
[app.loggers.audit :as audit]
|
||||||
[app.main :as-alias main]
|
[app.main :as-alias main]
|
||||||
|
[app.nitrate :as nitrate]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.commands.profile :as profile]
|
[app.rpc.commands.profile :as profile]
|
||||||
|
[app.rpc.commands.teams :as teams]
|
||||||
[app.rpc.doc :as-alias doc]
|
[app.rpc.doc :as-alias doc]
|
||||||
[app.rpc.helpers :as rph]
|
[app.rpc.helpers :as rph]
|
||||||
[app.rpc.quotes :as quotes]
|
[app.rpc.quotes :as quotes]
|
||||||
@ -72,6 +74,11 @@
|
|||||||
{:is-active true}
|
{:is-active true}
|
||||||
{:id (:id profile)}))
|
{:id (:id profile)}))
|
||||||
|
|
||||||
|
;; NOTE: `claims` is returned verbatim (besides :profile). When the
|
||||||
|
;; verify-email JWE was minted by `register-profile` for a not-yet-
|
||||||
|
;; active profile that came from an invitation flow, `:invitation-
|
||||||
|
;; token` will be present here and the frontend will use it to
|
||||||
|
;; complete the team-invitation flow after login.
|
||||||
(-> claims
|
(-> claims
|
||||||
(rph/with-transform (session/create-fn cfg profile))
|
(rph/with-transform (session/create-fn cfg profile))
|
||||||
(rph/with-meta {::audit/name "verify-profile-email"
|
(rph/with-meta {::audit/name "verify-profile-email"
|
||||||
@ -86,52 +93,74 @@
|
|||||||
;; --- Team Invitation
|
;; --- Team Invitation
|
||||||
|
|
||||||
(defn- accept-invitation
|
(defn- accept-invitation
|
||||||
[{:keys [::db/conn] :as cfg} {:keys [team-id role member-email] :as claims} invitation member]
|
[{:keys [::db/conn] :as cfg}
|
||||||
|
{:keys [team-id organization-id role member-email] :as claims} invitation member]
|
||||||
(let [;; Update the role if there is an invitation
|
(let [;; Update the role if there is an invitation
|
||||||
role (or (some-> invitation :role keyword) role)
|
role (or (some-> invitation :role keyword) role)
|
||||||
params (merge
|
id-member (:id member)]
|
||||||
{:team-id team-id
|
|
||||||
:profile-id (:id member)}
|
|
||||||
(get types.team/permissions-for-role role))]
|
|
||||||
|
|
||||||
;; Do not allow blocked users accept invitations.
|
;; Do not allow blocked users accept invitations.
|
||||||
(when (:is-blocked member)
|
(when (:is-blocked member)
|
||||||
(ex/raise :type :restriction
|
(ex/raise :type :restriction
|
||||||
:code :profile-blocked))
|
:code :profile-blocked))
|
||||||
|
|
||||||
|
(when team-id
|
||||||
(quotes/check! cfg {::quotes/id ::quotes/profiles-per-team
|
(quotes/check! cfg {::quotes/id ::quotes/profiles-per-team
|
||||||
::quotes/profile-id (:id member)
|
::quotes/profile-id id-member
|
||||||
::quotes/team-id team-id})
|
::quotes/team-id team-id}))
|
||||||
|
|
||||||
|
(let [params (merge
|
||||||
|
{:team-id team-id
|
||||||
|
:profile-id id-member}
|
||||||
|
(get types.team/permissions-for-role role))
|
||||||
|
|
||||||
|
accepted-team-id (if organization-id
|
||||||
|
;; Insert the invited member to the org
|
||||||
|
(when (contains? cf/flags :nitrate)
|
||||||
|
(teams/initialize-user-in-nitrate-org cfg id-member organization-id member-email))
|
||||||
;; Insert the invited member to the team
|
;; Insert the invited member to the team
|
||||||
(db/insert! conn :team-profile-rel params {::db/on-conflict-do-nothing? true})
|
(do (teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true})
|
||||||
|
team-id))]
|
||||||
|
|
||||||
|
(when-not accepted-team-id
|
||||||
|
(ex/raise :type :internal
|
||||||
|
:code :accept-invitation-failed
|
||||||
|
:hint "the accept invitation has failed"))
|
||||||
|
|
||||||
|
|
||||||
;; If profile is not yet verified, mark it as verified because
|
;; If profile is not yet verified, mark it as verified because
|
||||||
;; accepting an invitation link serves as verification.
|
;; accepting an invitation link serves as verification.
|
||||||
(when-not (:is-active member)
|
(when-not (:is-active member)
|
||||||
(db/update! conn :profile
|
(db/update! conn :profile
|
||||||
{:is-active true}
|
{:is-active true}
|
||||||
{:id (:id member)}))
|
{:id id-member}))
|
||||||
|
|
||||||
;; Delete the invitation
|
;; Delete the invitation
|
||||||
(db/delete! conn :team-invitation
|
(db/delete! conn :team-invitation
|
||||||
{:team-id team-id :email-to member-email})
|
(cond-> {:email-to member-email}
|
||||||
|
team-id (assoc :team-id team-id)
|
||||||
|
organization-id (assoc :org-id organization-id)))
|
||||||
|
|
||||||
;; Delete any request
|
;; Delete any request (only applicable for team invitations)
|
||||||
|
(when team-id
|
||||||
(db/delete! conn :team-access-request
|
(db/delete! conn :team-access-request
|
||||||
{:team-id team-id :requester-id (:id member)})
|
{:team-id team-id :requester-id id-member}))
|
||||||
|
|
||||||
(assoc member :is-active true)))
|
accepted-team-id)))
|
||||||
|
|
||||||
(def schema:team-invitation-claims
|
(def schema:team-invitation-claims
|
||||||
|
[:and
|
||||||
[:map {:title "TeamInvitationClaims"}
|
[:map {:title "TeamInvitationClaims"}
|
||||||
[:iss :keyword]
|
[:iss :keyword]
|
||||||
[:exp ::ct/inst]
|
[:exp ::ct/inst]
|
||||||
[:profile-id ::sm/uuid]
|
[:profile-id ::sm/uuid]
|
||||||
[:role types.team/schema:role]
|
[:role types.team/schema:role]
|
||||||
[:team-id ::sm/uuid]
|
[:team-id {:optional true} ::sm/uuid]
|
||||||
|
[:organization-id {:optional true} ::sm/uuid]
|
||||||
[:member-email ::sm/email]
|
[:member-email ::sm/email]
|
||||||
[:member-id {:optional true} ::sm/uuid]])
|
[:member-id {:optional true} ::sm/uuid]]
|
||||||
|
[:fn {:error/message "team-id or organization-id must be present"}
|
||||||
|
(fn [m] (or (:team-id m) (:organization-id m)))]])
|
||||||
|
|
||||||
(def valid-team-invitation-claims?
|
(def valid-team-invitation-claims?
|
||||||
(sm/lazy-validator schema:team-invitation-claims))
|
(sm/lazy-validator schema:team-invitation-claims))
|
||||||
@ -139,7 +168,7 @@
|
|||||||
(defmethod process-token :team-invitation
|
(defmethod process-token :team-invitation
|
||||||
[{:keys [::db/conn] :as cfg}
|
[{:keys [::db/conn] :as cfg}
|
||||||
{:keys [::rpc/profile-id token] :as params}
|
{:keys [::rpc/profile-id token] :as params}
|
||||||
{:keys [member-id team-id member-email] :as claims}]
|
{:keys [member-id team-id organization-id member-email] :as claims}]
|
||||||
|
|
||||||
(when-not (valid-team-invitation-claims? claims)
|
(when-not (valid-team-invitation-claims? claims)
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
@ -147,19 +176,45 @@
|
|||||||
:hint "invitation token contains unexpected data"))
|
:hint "invitation token contains unexpected data"))
|
||||||
|
|
||||||
(let [invitation (db/get* conn :team-invitation
|
(let [invitation (db/get* conn :team-invitation
|
||||||
{:team-id team-id :email-to member-email})
|
(cond-> {:email-to member-email}
|
||||||
|
team-id (assoc :team-id team-id)
|
||||||
|
organization-id (assoc :org-id organization-id)))
|
||||||
profile (db/get* conn :profile
|
profile (db/get* conn :profile
|
||||||
{:id profile-id}
|
{:id profile-id}
|
||||||
{:columns [:id :email]})
|
{:columns [:id :email :default-team-id]})
|
||||||
registration-disabled? (not (contains? cf/flags :registration))]
|
registration-disabled? (not (contains? cf/flags :registration))
|
||||||
|
|
||||||
|
org-invitation? (and (contains? cf/flags :nitrate) organization-id)
|
||||||
|
membership (when org-invitation?
|
||||||
|
(nitrate/call cfg :get-org-membership {:profile-id profile-id
|
||||||
|
:organization-id organization-id}))]
|
||||||
|
|
||||||
|
(if profile
|
||||||
|
(do
|
||||||
|
(when-not (or (= member-id profile-id)
|
||||||
|
(= member-email (:email profile)))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :invalid-token
|
||||||
|
:reason :email-mismatch
|
||||||
|
:hint "logged-in user does not matches the invitation"))
|
||||||
|
|
||||||
|
(when (:is-member membership)
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :already-an-org-member
|
||||||
|
:team-id (:default-team-id membership)
|
||||||
|
:hint "the user is already a member of the organization"))
|
||||||
|
|
||||||
|
(when (and org-invitation? (not (:organization-id membership)))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :org-not-found
|
||||||
|
:team-id (:default-team-id profile)
|
||||||
|
:hint "the organization doesn't exist"))
|
||||||
|
|
||||||
(when (nil? invitation)
|
(when (nil? invitation)
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :invalid-token
|
:code :invalid-token
|
||||||
:hint "no invitation associated with the token"))
|
:hint "no invitation associated with the token"))
|
||||||
|
|
||||||
(if (some? profile)
|
|
||||||
(if (or (= member-id profile-id)
|
|
||||||
(= member-email (:email profile)))
|
|
||||||
|
|
||||||
;; if we have logged-in user and it matches the invitation we proceed
|
;; if we have logged-in user and it matches the invitation we proceed
|
||||||
;; with accepting the invitation and joining the current profile to the
|
;; with accepting the invitation and joining the current profile to the
|
||||||
@ -168,36 +223,33 @@
|
|||||||
:role (:role claims)
|
:role (:role claims)
|
||||||
:invitation-id (:id invitation)}]
|
:invitation-id (:id invitation)}]
|
||||||
|
|
||||||
(audit/submit!
|
(audit/submit cfg
|
||||||
cfg
|
|
||||||
(-> (audit/event-from-rpc-params params)
|
(-> (audit/event-from-rpc-params params)
|
||||||
(assoc ::audit/name "accept-team-invitation")
|
(assoc :name "accept-team-invitation")
|
||||||
(assoc ::audit/props props)))
|
(assoc :props props)))
|
||||||
|
|
||||||
;; NOTE: Backward compatibility; old invitations can
|
;; NOTE: Backward compatibility; old invitations can
|
||||||
;; have the `created-by` to be nil; so in this case we
|
;; have the `created-by` to be nil; so in this case we
|
||||||
;; don't submit this event to the audit-log
|
;; don't submit this event to the audit-log
|
||||||
(when-let [created-by (:created-by invitation)]
|
(when-let [created-by (:created-by invitation)]
|
||||||
(audit/submit!
|
(audit/submit cfg
|
||||||
cfg
|
|
||||||
(-> (audit/event-from-rpc-params params)
|
(-> (audit/event-from-rpc-params params)
|
||||||
(assoc ::audit/profile-id created-by)
|
(assoc :profile-id created-by)
|
||||||
(assoc ::audit/name "accept-team-invitation-from")
|
(assoc :name "accept-team-invitation-from")
|
||||||
(assoc ::audit/props (assoc props
|
(assoc :props (assoc props
|
||||||
:profile-id (:id profile)
|
:profile-id (:id profile)
|
||||||
:email (:email profile))))))
|
:email (:email profile))))))
|
||||||
|
|
||||||
(accept-invitation cfg claims invitation profile)
|
(let [accepted-team-id (accept-invitation cfg claims invitation profile)]
|
||||||
(assoc claims :state :created))
|
(cond-> (assoc claims :state :created)
|
||||||
|
;; when the invitation is to an org, instead of a team, add the
|
||||||
(ex/raise :type :validation
|
;; accepted-team-id as :org-team-id
|
||||||
:code :invalid-token
|
(:organization-id claims)
|
||||||
:hint "logged-in user does not matches the invitation"))
|
(assoc :org-team-id accepted-team-id)))))
|
||||||
|
|
||||||
;; If we have not logged-in user, and invitation comes with member-id we
|
;; If we have not logged-in user, and invitation comes with member-id we
|
||||||
;; redirect user to login, if no memeber-id is present and in the invitation
|
;; redirect user to login, if no memeber-id is present and in the invitation
|
||||||
;; token and registration is enabled, we redirect user the the register page.
|
;; token and registration is enabled, we redirect user the the register page.
|
||||||
|
|
||||||
{:invitation-token token
|
{:invitation-token token
|
||||||
:iss :team-invitation
|
:iss :team-invitation
|
||||||
:redirect-to (if (or member-id registration-disabled?) :auth-login :auth-register)
|
:redirect-to (if (or member-id registration-disabled?) :auth-login :auth-register)
|
||||||
|
|||||||
@ -28,19 +28,25 @@
|
|||||||
(update :pages-index select-keys allowed)))
|
(update :pages-index select-keys allowed)))
|
||||||
|
|
||||||
(defn obfuscate-email
|
(defn obfuscate-email
|
||||||
|
"Obfuscate the `email` for share-link members so the viewer only sees a
|
||||||
|
partially redacted address. Accepts any string shape (including nil,
|
||||||
|
missing `@`, or a domain with no `.`) and falls back to a fully-masked
|
||||||
|
result rather than throwing — the function is called while building the
|
||||||
|
view-only bundle for anonymous viewers, so an NPE here would abort the
|
||||||
|
entire share-link response."
|
||||||
[email]
|
[email]
|
||||||
(let [[name domain]
|
(let [[name domain]
|
||||||
(str/split email "@" 2)
|
(str/split (or email "") "@" 2)
|
||||||
|
|
||||||
[_ rest]
|
[_ rest]
|
||||||
(str/split domain "." 2)
|
(str/split (or domain "") "." 2)
|
||||||
|
|
||||||
name
|
name
|
||||||
(if (> (count name) 3)
|
(if (> (count name) 3)
|
||||||
(str (subs name 0 1) (apply str (take (dec (count name)) (repeat "*"))))
|
(str (subs name 0 1) (apply str (take (dec (count name)) (repeat "*"))))
|
||||||
"****")]
|
"****")]
|
||||||
|
|
||||||
(str name "@****." rest)))
|
(str name "@****" (when rest (str "." rest)))))
|
||||||
|
|
||||||
(defn anonymize-member
|
(defn anonymize-member
|
||||||
[member]
|
[member]
|
||||||
|
|||||||
@ -50,24 +50,27 @@
|
|||||||
(defn- validate-webhook!
|
(defn- validate-webhook!
|
||||||
[cfg whook params]
|
[cfg whook params]
|
||||||
(when (not= (:uri whook) (:uri params))
|
(when (not= (:uri whook) (:uri params))
|
||||||
(let [response (ex/try!
|
(try
|
||||||
(http/req! cfg
|
(let [response (http/req cfg
|
||||||
{:method :head
|
{:method :head
|
||||||
:uri (str (:uri params))
|
:uri (str (:uri params))
|
||||||
:timeout (ct/duration "3s")}
|
:timeout (ct/duration "3s")})]
|
||||||
{:sync? true}))]
|
|
||||||
(if (ex/exception? response)
|
|
||||||
(if-let [hint (webhooks/interpret-exception response)]
|
|
||||||
(ex/raise :type :validation
|
|
||||||
:code :webhook-validation
|
|
||||||
:hint hint)
|
|
||||||
(ex/raise :type :internal
|
|
||||||
:code :webhook-validation
|
|
||||||
:cause response))
|
|
||||||
(when-let [hint (webhooks/interpret-response response)]
|
(when-let [hint (webhooks/interpret-response response)]
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :webhook-validation
|
:code :webhook-validation
|
||||||
:hint hint))))))
|
:hint hint)))
|
||||||
|
|
||||||
|
(catch Throwable cause
|
||||||
|
(if-let [hint (webhooks/interpret-exception cause)]
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :webhook-validation
|
||||||
|
:hint hint
|
||||||
|
:webhook-uri (str (:uri params))
|
||||||
|
:cause cause)
|
||||||
|
(ex/raise :type :internal
|
||||||
|
:code :webhook-validation
|
||||||
|
:webhook-uri (str (:uri params))
|
||||||
|
:cause cause))))))
|
||||||
|
|
||||||
(defn- validate-quotes!
|
(defn- validate-quotes!
|
||||||
[{:keys [::db/pool]} {:keys [team-id]}]
|
[{:keys [::db/pool]} {:keys [team-id]}]
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
of the object. This function can be applied to the object returned by the
|
of the object. This function can be applied to the object returned by the
|
||||||
`get-object` but also to the RPC return value (in case you don't provide
|
`get-object` but also to the RPC return value (in case you don't provide
|
||||||
the return value calculated key under `::key` metadata prop.
|
the return value calculated key under `::key` metadata prop.
|
||||||
- `::reuse-key?` enables reusing the key calculated on first time; usefull
|
- `::reuse-key?` enables reusing the key calculated on first time; useful
|
||||||
when the target object is not retrieved on the RPC (typical on retrieving
|
when the target object is not retrieved on the RPC (typical on retrieving
|
||||||
dependent objects).
|
dependent objects).
|
||||||
"
|
"
|
||||||
|
|||||||
@ -8,17 +8,35 @@
|
|||||||
"Internal Nitrate HTTP RPC API. Provides authenticated access to
|
"Internal Nitrate HTTP RPC API. Provides authenticated access to
|
||||||
organization management and token validation endpoints."
|
organization management and token validation endpoints."
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data :as d]
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
|
[app.common.time :as ct]
|
||||||
|
[app.common.types.organization :refer [schema:team-with-organization]]
|
||||||
[app.common.types.profile :refer [schema:profile, schema:basic-profile]]
|
[app.common.types.profile :refer [schema:profile, schema:basic-profile]]
|
||||||
[app.common.types.team :refer [schema:team]]
|
[app.common.types.team :refer [schema:team]]
|
||||||
[app.common.uuid :as uuid]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.msgbus :as mbus]
|
[app.media :as media]
|
||||||
|
[app.nitrate :as nitrate]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.commands.files :as files]
|
[app.rpc.commands.files :as files]
|
||||||
|
[app.rpc.commands.nitrate :as cnit]
|
||||||
[app.rpc.commands.profile :as profile]
|
[app.rpc.commands.profile :as profile]
|
||||||
|
[app.rpc.commands.teams :as teams]
|
||||||
|
[app.rpc.commands.teams-invitations :as ti]
|
||||||
[app.rpc.doc :as doc]
|
[app.rpc.doc :as doc]
|
||||||
[app.util.services :as sv]))
|
[app.rpc.notifications :as notifications]
|
||||||
|
[app.storage :as sto]
|
||||||
|
[app.util.services :as sv]
|
||||||
|
[app.worker :as wrk]))
|
||||||
|
|
||||||
|
|
||||||
|
(defn- profile-to-map [profile]
|
||||||
|
{:id (:id profile)
|
||||||
|
:name (:fullname profile)
|
||||||
|
:email (:email profile)
|
||||||
|
:photo-url (files/resolve-public-uri (get profile :photo-id))})
|
||||||
|
|
||||||
;; ---- API: authenticate
|
;; ---- API: authenticate
|
||||||
|
|
||||||
@ -29,10 +47,8 @@
|
|||||||
::sm/result schema:profile}
|
::sm/result schema:profile}
|
||||||
[cfg {:keys [::rpc/profile-id] :as params}]
|
[cfg {:keys [::rpc/profile-id] :as params}]
|
||||||
(let [profile (profile/get-profile cfg profile-id)]
|
(let [profile (profile/get-profile cfg profile-id)]
|
||||||
{:id (get profile :id)
|
(-> (profile-to-map profile)
|
||||||
:name (get profile :fullname)
|
(assoc :theme (:theme profile)))))
|
||||||
:email (get profile :email)
|
|
||||||
:photo-url (files/resolve-public-uri (get profile :photo-id))}))
|
|
||||||
|
|
||||||
;; ---- API: get-teams
|
;; ---- API: get-teams
|
||||||
|
|
||||||
@ -45,6 +61,32 @@
|
|||||||
AND t.is_default IS FALSE
|
AND t.is_default IS FALSE
|
||||||
AND t.deleted_at IS NULL;")
|
AND t.deleted_at IS NULL;")
|
||||||
|
|
||||||
|
;; ---- API: get-penpot-version
|
||||||
|
|
||||||
|
(def ^:private schema:get-penpot-version-result
|
||||||
|
[:map
|
||||||
|
[:version
|
||||||
|
[:map
|
||||||
|
[:full [:maybe ::sm/text]]
|
||||||
|
[:branch [:maybe ::sm/text]]
|
||||||
|
[:base [:maybe ::sm/text]]
|
||||||
|
[:main [:maybe ::sm/text]]
|
||||||
|
[:major [:maybe ::sm/text]]
|
||||||
|
[:minor [:maybe ::sm/text]]
|
||||||
|
[:patch [:maybe ::sm/text]]
|
||||||
|
[:modifier [:maybe ::sm/text]]
|
||||||
|
[:commit [:maybe ::sm/text]]
|
||||||
|
[:commit-hash [:maybe ::sm/text]]]]])
|
||||||
|
|
||||||
|
(sv/defmethod ::get-penpot-version
|
||||||
|
"Get the current Penpot version"
|
||||||
|
{::doc/added "2.14"
|
||||||
|
::sm/params [:map]
|
||||||
|
::sm/result schema:get-penpot-version-result
|
||||||
|
::rpc/auth false}
|
||||||
|
[_cfg _params]
|
||||||
|
{:version cf/version})
|
||||||
|
|
||||||
(def ^:private schema:get-teams-result
|
(def ^:private schema:get-teams-result
|
||||||
[:vector schema:team])
|
[:vector schema:team])
|
||||||
|
|
||||||
@ -58,28 +100,63 @@
|
|||||||
(->> (db/exec! cfg [sql:get-teams current-user-id])
|
(->> (db/exec! cfg [sql:get-teams current-user-id])
|
||||||
(map #(select-keys % [:id :name])))))
|
(map #(select-keys % [:id :name])))))
|
||||||
|
|
||||||
;; ---- API: notify-team-change
|
;; ---- API: upload-org-logo
|
||||||
|
|
||||||
(def ^:private schema:notify-team-change
|
(def ^:private schema:upload-org-logo
|
||||||
[:map
|
[:map
|
||||||
[:id ::sm/uuid]
|
[:content media/schema:upload]
|
||||||
[:organization-id ::sm/text]])
|
[:organization-id ::sm/uuid]
|
||||||
|
[:previous-id {:optional true} ::sm/uuid]])
|
||||||
|
|
||||||
|
(def ^:private schema:upload-org-logo-result
|
||||||
|
[:map [:id ::sm/uuid]])
|
||||||
|
|
||||||
|
(sv/defmethod ::upload-org-logo
|
||||||
|
"Store an organization logo in penpot storage and return its ID.
|
||||||
|
Accepts an optional previous-id to mark the old logo for garbage
|
||||||
|
collection when replacing an existing one."
|
||||||
|
{::doc/added "2.17"
|
||||||
|
::sm/params schema:upload-org-logo
|
||||||
|
::sm/result schema:upload-org-logo-result}
|
||||||
|
[{:keys [::sto/storage]} {:keys [content organization-id previous-id]}]
|
||||||
|
(when previous-id
|
||||||
|
(sto/touch-object! storage previous-id))
|
||||||
|
(let [hash (sto/calculate-hash (:path content))
|
||||||
|
data (-> (sto/content (:path content))
|
||||||
|
(sto/wrap-with-hash hash))
|
||||||
|
obj (sto/put-object! storage {::sto/content data
|
||||||
|
::sto/deduplicate? true
|
||||||
|
:bucket "organization"
|
||||||
|
:content-type (:mtype content)
|
||||||
|
:organization-id organization-id})]
|
||||||
|
{:id (:id obj)}))
|
||||||
|
|
||||||
|
;; ---- API: notify-team-change
|
||||||
|
|
||||||
(sv/defmethod ::notify-team-change
|
(sv/defmethod ::notify-team-change
|
||||||
"Notify to Penpot a team change from nitrate"
|
"Notify to Penpot a team change from nitrate"
|
||||||
{::doc/added "2.14"
|
{::doc/added "2.14"
|
||||||
::sm/params schema:notify-team-change
|
::sm/params schema:team-with-organization
|
||||||
::rpc/auth false}
|
::rpc/auth false}
|
||||||
[cfg {:keys [id organization-id organization-name]}]
|
[cfg team]
|
||||||
(let [msgbus (::mbus/msgbus cfg)]
|
(notifications/notify-team-change cfg (select-keys team [:id :is-your-penpot :organization]) nil)
|
||||||
(mbus/pub! msgbus
|
nil)
|
||||||
;;TODO There is a bug on dashboard with teams notifications.
|
|
||||||
;;For now we send it to uuid/zero instead of team-id
|
;; ---- API: notify-user-added-to-organization
|
||||||
:topic uuid/zero
|
|
||||||
:message {:type :team-org-change
|
(def ^:private schema:notify-user-added-to-organization
|
||||||
:team-id id
|
[:map
|
||||||
:organization-id organization-id
|
[:profile-id ::sm/uuid]
|
||||||
:organization-name organization-name})))
|
[:organization-id ::sm/uuid]
|
||||||
|
[:role ::sm/text]])
|
||||||
|
|
||||||
|
(sv/defmethod ::notify-user-added-to-organization
|
||||||
|
"Notify to Penpot that an user has joined an org from nitrate"
|
||||||
|
{::doc/added "2.14"
|
||||||
|
::sm/params schema:notify-user-added-to-organization
|
||||||
|
::rpc/auth false}
|
||||||
|
[cfg {:keys [profile-id organization-id]}]
|
||||||
|
(db/tx-run! cfg teams/create-default-org-team profile-id organization-id))
|
||||||
|
|
||||||
|
|
||||||
;; ---- API: get-managed-profiles
|
;; ---- API: get-managed-profiles
|
||||||
@ -112,3 +189,441 @@
|
|||||||
[cfg {:keys [::rpc/profile-id]}]
|
[cfg {:keys [::rpc/profile-id]}]
|
||||||
(let [current-user-id (-> (profile/get-profile cfg profile-id) :id)]
|
(let [current-user-id (-> (profile/get-profile cfg profile-id) :id)]
|
||||||
(db/exec! cfg [sql:get-managed-profiles current-user-id current-user-id])))
|
(db/exec! cfg [sql:get-managed-profiles current-user-id current-user-id])))
|
||||||
|
|
||||||
|
;; ---- API: get-teams-summary
|
||||||
|
|
||||||
|
(def ^:private sql:get-teams-summary
|
||||||
|
"SELECT t.id, t.name, t.is_default
|
||||||
|
FROM team AS t
|
||||||
|
WHERE t.id = ANY(?)
|
||||||
|
AND t.deleted_at IS NULL;")
|
||||||
|
|
||||||
|
(def ^:private sql:get-files-count
|
||||||
|
"SELECT COUNT(f.*) AS count
|
||||||
|
FROM file AS f
|
||||||
|
JOIN project AS p ON f.project_id = p.id
|
||||||
|
JOIN team AS t ON t.id = p.team_id
|
||||||
|
WHERE p.team_id = ANY(?)
|
||||||
|
AND t.deleted_at IS NULL
|
||||||
|
AND p.deleted_at IS NULL
|
||||||
|
AND f.deleted_at IS NULL;")
|
||||||
|
|
||||||
|
(def ^:private schema:get-teams-summary-params
|
||||||
|
[:map
|
||||||
|
[:ids [:or ::sm/uuid [:vector ::sm/uuid]]]])
|
||||||
|
|
||||||
|
(def ^:private schema:get-teams-summary-result
|
||||||
|
[:map
|
||||||
|
[:teams [:vector [:map
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:name ::sm/text]
|
||||||
|
[:is-default ::sm/boolean]]]]
|
||||||
|
[:num-files ::sm/int]])
|
||||||
|
|
||||||
|
(sv/defmethod ::get-teams-summary
|
||||||
|
"Get summary information for a list of teams"
|
||||||
|
{::doc/added "2.15"
|
||||||
|
::sm/params schema:get-teams-summary-params
|
||||||
|
::sm/result schema:get-teams-summary-result}
|
||||||
|
[cfg {:keys [ids]}]
|
||||||
|
(let [;; Handle one or multiple params
|
||||||
|
ids (cond
|
||||||
|
(uuid? ids)
|
||||||
|
[ids]
|
||||||
|
|
||||||
|
(and (vector? ids) (every? uuid? ids))
|
||||||
|
ids
|
||||||
|
|
||||||
|
:else
|
||||||
|
[])]
|
||||||
|
(db/run! cfg (fn [{:keys [::db/conn]}]
|
||||||
|
(let [ids-array (db/create-array conn "uuid" ids)
|
||||||
|
teams (db/exec! conn [sql:get-teams-summary ids-array])
|
||||||
|
files-count (-> (db/exec-one! conn [sql:get-files-count ids-array]) :count)]
|
||||||
|
{:teams teams
|
||||||
|
:num-files files-count})))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ---- API: delete-teams-keeping-your-penpot-projects
|
||||||
|
|
||||||
|
(def ^:private sql:prefix-teams-name-and-unset-default
|
||||||
|
"UPDATE team
|
||||||
|
SET name = ? || name,
|
||||||
|
is_default = FALSE
|
||||||
|
WHERE id = ANY(?)
|
||||||
|
RETURNING id, name;")
|
||||||
|
|
||||||
|
(def ^:private sql:get-teams-files-counts
|
||||||
|
"SELECT p.team_id, COUNT(f.*) AS total
|
||||||
|
FROM file AS f
|
||||||
|
JOIN project AS p ON (p.id = f.project_id)
|
||||||
|
JOIN team AS t ON (t.id = p.team_id)
|
||||||
|
WHERE t.id = ANY(?)
|
||||||
|
AND t.deleted_at IS NULL
|
||||||
|
AND p.deleted_at IS NULL
|
||||||
|
AND f.deleted_at IS NULL
|
||||||
|
GROUP BY p.team_id;")
|
||||||
|
|
||||||
|
(def ^:private sql:soft-delete-teams
|
||||||
|
"UPDATE team
|
||||||
|
SET deleted_at = ?
|
||||||
|
WHERE id = ANY(?)
|
||||||
|
RETURNING id, deleted_at;")
|
||||||
|
|
||||||
|
|
||||||
|
;; ---- API: notify-organization-deletion
|
||||||
|
|
||||||
|
(def ^:private schema:notify-organization-deletion
|
||||||
|
[:map
|
||||||
|
[:organization-id ::sm/uuid]])
|
||||||
|
|
||||||
|
|
||||||
|
(defn- soft-delete-teams!
|
||||||
|
"Soft-delete the provided team ids and submit a delete task per team."
|
||||||
|
[{:keys [::db/conn] :as cfg} team-ids]
|
||||||
|
(when (seq team-ids)
|
||||||
|
(let [delay (cf/get-deletion-delay)
|
||||||
|
deleted-at (ct/in-future delay)
|
||||||
|
updated (db/exec! conn [sql:soft-delete-teams
|
||||||
|
deleted-at
|
||||||
|
(db/create-array conn "uuid" team-ids)])]
|
||||||
|
(doseq [{:keys [id deleted-at]} updated]
|
||||||
|
(wrk/submit! {::db/conn conn
|
||||||
|
::wrk/task :delete-object
|
||||||
|
::wrk/params {:object :team
|
||||||
|
:deleted-at deleted-at
|
||||||
|
:id id}}))))
|
||||||
|
nil)
|
||||||
|
|
||||||
|
(defn manage-deleted-organization-teams
|
||||||
|
"For a list of teams, rename those with files and delete those without, then notify users."
|
||||||
|
[cfg {:keys [teams organization-name]}]
|
||||||
|
(let [teams (->> teams (filter uuid?) distinct (into []))]
|
||||||
|
(when (seq teams)
|
||||||
|
(let [org-prefix (str "[" (d/sanitize-string organization-name) "] ")]
|
||||||
|
(db/tx-run!
|
||||||
|
cfg
|
||||||
|
(fn [{:keys [::db/conn] :as cfg}]
|
||||||
|
(let [teams-array (db/create-array conn "uuid" teams)
|
||||||
|
teams-with-files (->> (db/exec! conn [sql:get-teams-files-counts teams-array])
|
||||||
|
(filter (fn [{:keys [total]}] (pos? total)))
|
||||||
|
(map :team-id)
|
||||||
|
(into #{}))
|
||||||
|
teams-to-keep (->> teams (filter teams-with-files) (into []))
|
||||||
|
teams-to-delete (->> teams (remove teams-with-files) (into []))]
|
||||||
|
|
||||||
|
;; Rename teams that have files in one go
|
||||||
|
(when (seq teams-to-keep)
|
||||||
|
(db/exec! conn [sql:prefix-teams-name-and-unset-default
|
||||||
|
org-prefix
|
||||||
|
(db/create-array conn "uuid" teams-to-keep)]))
|
||||||
|
|
||||||
|
;; Soft-delete empty teams in one go
|
||||||
|
(soft-delete-teams! cfg teams-to-delete)
|
||||||
|
|
||||||
|
(notifications/notify-organization-deletion cfg organization-name teams teams-to-delete)
|
||||||
|
nil)))))))
|
||||||
|
|
||||||
|
|
||||||
|
(sv/defmethod ::notify-organization-deletion
|
||||||
|
"For a list of teams, rename them with the name of the deleted org, and notify
|
||||||
|
of the deletion to the connected users"
|
||||||
|
{::doc/added "2.15"
|
||||||
|
::sm/params schema:notify-organization-deletion
|
||||||
|
::rpc/auth false}
|
||||||
|
[cfg {:keys [organization-id]}]
|
||||||
|
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||||
|
teams (->> (:teams org-summary)
|
||||||
|
(map :id))]
|
||||||
|
(manage-deleted-organization-teams cfg {:teams teams :organization-name (:name org-summary)})
|
||||||
|
nil))
|
||||||
|
|
||||||
|
;; ---- API: notify-user-organizations-deletion
|
||||||
|
|
||||||
|
(def ^:private schema:notify-user-organizations-deletion
|
||||||
|
[:map
|
||||||
|
[:profile-id ::sm/uuid]])
|
||||||
|
|
||||||
|
(sv/defmethod ::notify-user-organizations-deletion
|
||||||
|
"For a given user, find all owned organizations and rename or delete their teams."
|
||||||
|
{::doc/added "2.18"
|
||||||
|
::sm/params schema:notify-user-organizations-deletion}
|
||||||
|
[cfg {:keys [profile-id]}]
|
||||||
|
(let [owned-orgs (nitrate/call cfg :get-owned-orgs {:profile-id profile-id})]
|
||||||
|
(doseq [org owned-orgs]
|
||||||
|
(let [organization-name (:name org)
|
||||||
|
teams (map :id (:teams org))]
|
||||||
|
(manage-deleted-organization-teams cfg {:teams teams :organization-name organization-name}))))
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; ---- API: get-profile-by-email
|
||||||
|
|
||||||
|
(def ^:private sql:get-profile-by-email
|
||||||
|
"SELECT DISTINCT id, fullname, email, photo_id
|
||||||
|
FROM profile
|
||||||
|
WHERE email = ?
|
||||||
|
AND deleted_at IS NULL;")
|
||||||
|
|
||||||
|
(sv/defmethod ::get-profile-by-email
|
||||||
|
"Get profile by email"
|
||||||
|
{::doc/added "2.15"
|
||||||
|
::sm/params [:map [:email ::sm/email]]
|
||||||
|
::sm/result schema:profile}
|
||||||
|
[cfg {:keys [email]}]
|
||||||
|
(let [profile (db/exec-one! cfg [sql:get-profile-by-email email])]
|
||||||
|
(when-not profile
|
||||||
|
(ex/raise :type :not-found
|
||||||
|
:code :profile-not-found
|
||||||
|
:hint "profile does not exist"
|
||||||
|
:email email))
|
||||||
|
(profile-to-map profile)))
|
||||||
|
|
||||||
|
|
||||||
|
;; ---- API: get-profile-by-id
|
||||||
|
|
||||||
|
(def ^:private sql:get-profile-by-id
|
||||||
|
"SELECT DISTINCT id, fullname, email, photo_id
|
||||||
|
FROM profile
|
||||||
|
WHERE id = ?
|
||||||
|
AND deleted_at IS NULL;")
|
||||||
|
|
||||||
|
(sv/defmethod ::get-profile-by-id
|
||||||
|
"Get profile by email"
|
||||||
|
{::doc/added "2.15"
|
||||||
|
::sm/params [:map [:id ::sm/uuid]]
|
||||||
|
::sm/result schema:profile}
|
||||||
|
[cfg {:keys [id]}]
|
||||||
|
(let [profile (db/exec-one! cfg [sql:get-profile-by-id id])]
|
||||||
|
(when-not profile
|
||||||
|
(ex/raise :type :not-found
|
||||||
|
:code :profile-not-found
|
||||||
|
:hint "profile does not exist"
|
||||||
|
:id id))
|
||||||
|
(profile-to-map profile)))
|
||||||
|
|
||||||
|
|
||||||
|
;; ---- API: get-org-member-team-counts
|
||||||
|
|
||||||
|
(def ^:private sql:get-org-member-team-counts
|
||||||
|
"SELECT tpr.profile_id, COUNT(DISTINCT t.id) AS team_count
|
||||||
|
FROM team_profile_rel AS tpr
|
||||||
|
JOIN team AS t ON t.id = tpr.team_id
|
||||||
|
WHERE t.id = ANY(?)
|
||||||
|
AND t.deleted_at IS NULL
|
||||||
|
AND t.is_default IS FALSE
|
||||||
|
GROUP BY tpr.profile_id;")
|
||||||
|
|
||||||
|
(def ^:private schema:get-org-member-team-counts-params
|
||||||
|
[:map [:team-ids [:or ::sm/uuid [:vector ::sm/uuid]]]])
|
||||||
|
|
||||||
|
(def ^:private schema:get-org-member-team-counts-result
|
||||||
|
[:vector [:map
|
||||||
|
[:profile-id ::sm/uuid]
|
||||||
|
[:team-count ::sm/int]]])
|
||||||
|
|
||||||
|
(sv/defmethod ::get-org-member-team-counts
|
||||||
|
"Get the number of non-default teams each profile belongs to within a set of teams."
|
||||||
|
{::doc/added "2.15"
|
||||||
|
::sm/params schema:get-org-member-team-counts-params
|
||||||
|
::sm/result schema:get-org-member-team-counts-result
|
||||||
|
::rpc/auth false}
|
||||||
|
[cfg {:keys [team-ids]}]
|
||||||
|
(let [team-ids (cond
|
||||||
|
(uuid? team-ids)
|
||||||
|
[team-ids]
|
||||||
|
|
||||||
|
(and (vector? team-ids) (every? uuid? team-ids))
|
||||||
|
team-ids
|
||||||
|
|
||||||
|
:else
|
||||||
|
[])]
|
||||||
|
(if (empty? team-ids)
|
||||||
|
[]
|
||||||
|
(db/run! cfg (fn [{:keys [::db/conn]}]
|
||||||
|
(let [ids-array (db/create-array conn "uuid" team-ids)]
|
||||||
|
(db/exec! conn [sql:get-org-member-team-counts ids-array])))))))
|
||||||
|
|
||||||
|
|
||||||
|
;; API: invite-to-org
|
||||||
|
|
||||||
|
(sv/defmethod ::invite-to-org
|
||||||
|
"Invite to organization"
|
||||||
|
{::doc/added "2.15"
|
||||||
|
::sm/params [:map
|
||||||
|
[:email ::sm/email]
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:name ::sm/text]
|
||||||
|
[:initials [:maybe :string]]
|
||||||
|
[:logo ::sm/uri]]}
|
||||||
|
[cfg params]
|
||||||
|
(db/tx-run! cfg ti/create-org-invitation params)
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
;; API: get-org-invitations
|
||||||
|
|
||||||
|
(def ^:private sql:get-org-invitations
|
||||||
|
"SELECT DISTINCT ON (email_to)
|
||||||
|
ti.id,
|
||||||
|
ti.org_id AS organization_id,
|
||||||
|
ti.email_to AS email,
|
||||||
|
ti.created_at AS sent_at,
|
||||||
|
p.fullname AS name,
|
||||||
|
p.photo_id
|
||||||
|
FROM team_invitation AS ti
|
||||||
|
LEFT JOIN profile AS p
|
||||||
|
ON p.email = ti.email_to
|
||||||
|
AND p.deleted_at IS NULL
|
||||||
|
WHERE ti.valid_until >= now()
|
||||||
|
AND (ti.org_id = ? OR ti.team_id = ANY(?))
|
||||||
|
ORDER BY ti.email_to, ti.valid_until DESC, ti.created_at DESC;")
|
||||||
|
|
||||||
|
(def ^:private schema:get-org-invitations-params
|
||||||
|
[:map
|
||||||
|
[:organization-id ::sm/uuid]])
|
||||||
|
|
||||||
|
(def ^:private schema:get-org-invitations-result
|
||||||
|
[:vector
|
||||||
|
[:map
|
||||||
|
[:id ::sm/uuid]
|
||||||
|
[:organization-id {:optional true} [:maybe ::sm/uuid]]
|
||||||
|
[:email ::sm/email]
|
||||||
|
[:sent-at ::sm/inst]
|
||||||
|
[:name {:optional true} [:maybe ::sm/text]]
|
||||||
|
[:photo-url {:optional true} ::sm/uri]]])
|
||||||
|
|
||||||
|
(sv/defmethod ::get-org-invitations
|
||||||
|
"Get valid invitations for an organization, returning at most one invitation per email."
|
||||||
|
{::doc/added "2.16"
|
||||||
|
::sm/params schema:get-org-invitations-params
|
||||||
|
::sm/result schema:get-org-invitations-result}
|
||||||
|
[cfg {:keys [organization-id]}]
|
||||||
|
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||||
|
team-ids (->> (:teams org-summary)
|
||||||
|
(map :id)
|
||||||
|
(filter uuid?)
|
||||||
|
(into []))]
|
||||||
|
(db/run! cfg (fn [{:keys [::db/conn]}]
|
||||||
|
(let [ids-array (db/create-array conn "uuid" team-ids)]
|
||||||
|
(->> (db/exec! conn [sql:get-org-invitations organization-id ids-array])
|
||||||
|
(mapv (fn [{:keys [photo-id] :as invitation}]
|
||||||
|
(cond-> (dissoc invitation :photo-id)
|
||||||
|
photo-id
|
||||||
|
(assoc :photo-url (files/resolve-public-uri photo-id)))))))))))
|
||||||
|
|
||||||
|
|
||||||
|
;; API: delete-org-invitations
|
||||||
|
|
||||||
|
(def ^:private sql:delete-org-invitations
|
||||||
|
"DELETE FROM team_invitation AS ti
|
||||||
|
WHERE ti.email_to = ?
|
||||||
|
AND (ti.org_id = ? OR ti.team_id = ANY(?));")
|
||||||
|
|
||||||
|
(def ^:private schema:delete-org-invitations-params
|
||||||
|
[:map
|
||||||
|
[:organization-id ::sm/uuid]
|
||||||
|
[:email ::sm/email]])
|
||||||
|
|
||||||
|
(sv/defmethod ::delete-org-invitations
|
||||||
|
"Delete all invitations for one email in an organization scope (org + org teams)."
|
||||||
|
{::doc/added "2.16"
|
||||||
|
::sm/params schema:delete-org-invitations-params}
|
||||||
|
[cfg {:keys [organization-id email]}]
|
||||||
|
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||||
|
clean-email (profile/clean-email email)
|
||||||
|
team-ids (->> (:teams org-summary)
|
||||||
|
(map :id)
|
||||||
|
(filter uuid?)
|
||||||
|
(into []))]
|
||||||
|
(db/run! cfg (fn [{:keys [::db/conn]}]
|
||||||
|
(let [ids-array (db/create-array conn "uuid" team-ids)]
|
||||||
|
(db/exec! conn [sql:delete-org-invitations clean-email organization-id ids-array]))))
|
||||||
|
nil))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; API: remove-from-org
|
||||||
|
|
||||||
|
(def ^:private sql:get-reassign-to
|
||||||
|
"SELECT tpr.profile_id
|
||||||
|
FROM team_profile_rel AS tpr
|
||||||
|
WHERE tpr.team_id = ?
|
||||||
|
AND tpr.profile_id <> ?
|
||||||
|
AND tpr.is_owner IS NOT TRUE
|
||||||
|
ORDER BY CASE
|
||||||
|
WHEN tpr.is_admin IS TRUE THEN 1
|
||||||
|
ELSE 2
|
||||||
|
END,
|
||||||
|
tpr.created_at,
|
||||||
|
tpr.profile_id
|
||||||
|
LIMIT 1;")
|
||||||
|
|
||||||
|
(defn add-reassign-to [cfg profile-id team-to-transfer]
|
||||||
|
(let [reassign-to (-> (db/exec-one! cfg [sql:get-reassign-to (:id team-to-transfer) profile-id])
|
||||||
|
:profile-id)]
|
||||||
|
(when-not reassign-to
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :nobody-to-reassign-team))
|
||||||
|
|
||||||
|
(assoc team-to-transfer :reassign-to reassign-to)))
|
||||||
|
|
||||||
|
(sv/defmethod ::remove-from-org
|
||||||
|
"Remove an user from an organization"
|
||||||
|
{::doc/added "2.17"
|
||||||
|
::sm/params [:map
|
||||||
|
[:profile-id ::sm/uuid]
|
||||||
|
[:organization-id ::sm/uuid]
|
||||||
|
[:organization-name ::sm/text]
|
||||||
|
[:default-team-id ::sm/uuid]]
|
||||||
|
::db/transaction true}
|
||||||
|
[cfg {:keys [profile-id organization-id organization-name default-team-id] :as params}]
|
||||||
|
(let [{:keys [valid-teams-to-delete-ids
|
||||||
|
valid-teams-to-transfer
|
||||||
|
valid-teams-to-exit]} (cnit/get-valid-teams cfg organization-id profile-id default-team-id)
|
||||||
|
add-reassign-to (partial add-reassign-to cfg profile-id)
|
||||||
|
|
||||||
|
valid-teams-to-leave (into valid-teams-to-exit
|
||||||
|
(map add-reassign-to valid-teams-to-transfer))]
|
||||||
|
|
||||||
|
(cnit/leave-org cfg (assoc params
|
||||||
|
:id organization-id
|
||||||
|
:name organization-name
|
||||||
|
:teams-to-delete valid-teams-to-delete-ids
|
||||||
|
:teams-to-leave valid-teams-to-leave
|
||||||
|
:skip-validation true))
|
||||||
|
(notifications/notify-user-org-change cfg profile-id organization-id organization-name "dashboard.user-no-longer-belong-org")
|
||||||
|
nil))
|
||||||
|
|
||||||
|
;; API: get-remove-from-org-summary
|
||||||
|
|
||||||
|
(def ^:private schema:get-remove-from-org-summary-result
|
||||||
|
[:map
|
||||||
|
[:teams-to-delete ::sm/int]
|
||||||
|
[:teams-to-transfer ::sm/int]
|
||||||
|
[:teams-to-exit ::sm/int]])
|
||||||
|
|
||||||
|
(sv/defmethod ::get-remove-from-org-summary
|
||||||
|
"Get a summary of the teams that would be deleted, transferred, or exited
|
||||||
|
if the user were removed from the organization"
|
||||||
|
{::doc/added "2.17"
|
||||||
|
::sm/params [:map
|
||||||
|
[:profile-id ::sm/uuid]
|
||||||
|
[:organization-id ::sm/uuid]
|
||||||
|
[:default-team-id ::sm/uuid]]
|
||||||
|
::sm/result schema:get-remove-from-org-summary-result
|
||||||
|
::db/transaction true}
|
||||||
|
[cfg {:keys [profile-id organization-id default-team-id]}]
|
||||||
|
(let [{:keys [valid-teams-to-delete-ids
|
||||||
|
valid-teams-to-transfer
|
||||||
|
valid-teams-to-exit
|
||||||
|
valid-default-team]} (cnit/get-valid-teams cfg organization-id profile-id default-team-id)]
|
||||||
|
(when-not valid-default-team
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :not-valid-teams))
|
||||||
|
{:teams-to-delete (count valid-teams-to-delete-ids)
|
||||||
|
:teams-to-transfer (count valid-teams-to-transfer)
|
||||||
|
:teams-to-exit (count valid-teams-to-exit)}))
|
||||||
|
|
||||||
|
|||||||
44
backend/src/app/rpc/notifications.clj
Normal file
44
backend/src/app/rpc/notifications.clj
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.rpc.notifications
|
||||||
|
(:require
|
||||||
|
[app.common.uuid :as uuid]
|
||||||
|
[app.msgbus :as mbus]))
|
||||||
|
|
||||||
|
(defn notify-team-change
|
||||||
|
[cfg team notification]
|
||||||
|
(let [msgbus (::mbus/msgbus cfg)]
|
||||||
|
(mbus/pub! msgbus
|
||||||
|
;;TODO There is a bug on dashboard with teams notifications.
|
||||||
|
;;For now we send it to uuid/zero instead of team-id
|
||||||
|
:topic uuid/zero
|
||||||
|
:message {:type :team-org-change
|
||||||
|
:team team
|
||||||
|
:notification notification})))
|
||||||
|
|
||||||
|
|
||||||
|
(defn notify-user-org-change
|
||||||
|
[cfg profile-id organization-id organization-name notification]
|
||||||
|
(let [msgbus (::mbus/msgbus cfg)]
|
||||||
|
(mbus/pub! msgbus
|
||||||
|
:topic profile-id
|
||||||
|
:message {:type :user-org-change
|
||||||
|
:topic profile-id
|
||||||
|
:organization-id organization-id
|
||||||
|
:organization-name organization-name
|
||||||
|
:notification notification})))
|
||||||
|
|
||||||
|
|
||||||
|
(defn notify-organization-deletion
|
||||||
|
[cfg organization-name teams deleted-teams]
|
||||||
|
(let [msgbus (::mbus/msgbus cfg)]
|
||||||
|
(mbus/pub! msgbus
|
||||||
|
:topic uuid/zero
|
||||||
|
:message {:type :organization-deleted
|
||||||
|
:organization-name organization-name
|
||||||
|
:teams teams
|
||||||
|
:deleted-teams deleted-teams})))
|
||||||
@ -522,6 +522,30 @@
|
|||||||
(assoc ::count-sql [sql:get-team-access-requests-per-requester profile-id])
|
(assoc ::count-sql [sql:get-team-access-requests-per-requester profile-id])
|
||||||
(generic-check!)))
|
(generic-check!)))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; QUOTE: UPLOAD-SESSIONS-PER-PROFILE
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(def ^:private schema:upload-sessions-per-profile
|
||||||
|
[:map [::profile-id ::sm/uuid]])
|
||||||
|
|
||||||
|
(def ^:private valid-upload-sessions-per-profile-quote?
|
||||||
|
(sm/lazy-validator schema:upload-sessions-per-profile))
|
||||||
|
|
||||||
|
(def ^:private sql:get-upload-sessions-per-profile
|
||||||
|
"SELECT count(*) AS total
|
||||||
|
FROM upload_session
|
||||||
|
WHERE profile_id = ?")
|
||||||
|
|
||||||
|
(defmethod check-quote ::upload-sessions-per-profile
|
||||||
|
[{:keys [::profile-id ::target] :as quote}]
|
||||||
|
(assert (valid-upload-sessions-per-profile-quote? quote) "invalid quote parameters")
|
||||||
|
(-> quote
|
||||||
|
(assoc ::default (cf/get :quotes-upload-sessions-per-profile Integer/MAX_VALUE))
|
||||||
|
(assoc ::quote-sql [sql:get-quotes-1 target profile-id])
|
||||||
|
(assoc ::count-sql [sql:get-upload-sessions-per-profile profile-id])
|
||||||
|
(generic-check!)))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; QUOTE: DEFAULT
|
;; QUOTE: DEFAULT
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|||||||
@ -11,7 +11,9 @@
|
|||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
[app.loggers.audit :as audit]
|
||||||
[app.main :as-alias main]
|
[app.main :as-alias main]
|
||||||
[app.setup.keys :as keys]
|
[app.setup.keys :as keys]
|
||||||
[app.setup.templates]
|
[app.setup.templates]
|
||||||
@ -35,10 +37,9 @@
|
|||||||
(into {})))
|
(into {})))
|
||||||
|
|
||||||
(defn- handle-instance-id
|
(defn- handle-instance-id
|
||||||
[instance-id conn read-only?]
|
[instance-id conn]
|
||||||
(or instance-id
|
(or instance-id
|
||||||
(let [instance-id (uuid/random)]
|
(let [instance-id (uuid/random)]
|
||||||
(when-not read-only?
|
|
||||||
(try
|
(try
|
||||||
(db/insert! conn :server-prop
|
(db/insert! conn :server-prop
|
||||||
{:id "instance-id"
|
{:id "instance-id"
|
||||||
@ -47,10 +48,9 @@
|
|||||||
(catch Throwable cause
|
(catch Throwable cause
|
||||||
(l/warn :hint "unable to persist instance-id"
|
(l/warn :hint "unable to persist instance-id"
|
||||||
:instance-id instance-id
|
:instance-id instance-id
|
||||||
:cause cause))))
|
:cause cause)))
|
||||||
instance-id)))
|
instance-id)))
|
||||||
|
|
||||||
|
|
||||||
(def sql:add-prop
|
(def sql:add-prop
|
||||||
"INSERT INTO server_prop (id, content, preload)
|
"INSERT INTO server_prop (id, content, preload)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
@ -77,50 +77,47 @@
|
|||||||
(assert (db/pool? (::db/pool params)) "expected valid database pool"))
|
(assert (db/pool? (::db/pool params)) "expected valid database pool"))
|
||||||
|
|
||||||
(defmethod ig/init-key ::props
|
(defmethod ig/init-key ::props
|
||||||
[_ {:keys [::db/pool ::key] :as cfg}]
|
[_ {:keys [::key] :as cfg}]
|
||||||
|
(audit/submit cfg {:type "trigger"
|
||||||
|
:name "instance-start"
|
||||||
|
:props {:version (:full cf/version)
|
||||||
|
:flags (mapv name cf/flags)
|
||||||
|
:public-uri (str (cf/get :public-uri))}})
|
||||||
|
|
||||||
(db/tx-run! cfg (fn [{:keys [::db/conn]}]
|
(db/tx-run! cfg (fn [{:keys [::db/conn]}]
|
||||||
(db/xact-lock! conn 0)
|
(db/xact-lock! conn 0)
|
||||||
(when-not key
|
(when-not key
|
||||||
(l/warn :hint (str "using autogenerated secret-key, it will change on each restart and will invalidate "
|
(l/wrn :hint (str "using autogenerated secret-key, it will change "
|
||||||
"all sessions on each restart, it is highly recommended setting up the "
|
"on each restart and will invalidate "
|
||||||
|
"all sessions on each restart, it is highly "
|
||||||
|
"recommended setting up the "
|
||||||
"PENPOT_SECRET_KEY environment variable")))
|
"PENPOT_SECRET_KEY environment variable")))
|
||||||
(let [secret (or key (generate-random-key))]
|
(let [secret (or key (generate-random-key))]
|
||||||
(-> (get-all-props conn)
|
(-> (get-all-props conn)
|
||||||
(assoc :secret-key secret)
|
(assoc :secret-key secret)
|
||||||
(assoc :tokens-key (keys/derive secret :salt "tokens"))
|
(assoc :tokens-key (keys/derive secret :salt "tokens"))
|
||||||
(update :instance-id handle-instance-id conn (db/read-only? pool)))))))
|
(update :instance-id handle-instance-id conn))))))
|
||||||
|
|
||||||
(sm/register! ::props [:map-of :keyword ::sm/any])
|
|
||||||
|
|
||||||
|
|
||||||
(defmethod ig/init-key ::shared-keys
|
(defmethod ig/init-key ::shared-keys
|
||||||
[_ {:keys [::props] :as cfg}]
|
[_ {:keys [::props] :as cfg}]
|
||||||
(let [secret (get props :secret-key)]
|
(let [secret (get props :secret-key)]
|
||||||
(d/without-nils
|
(reduce (fn [keys id]
|
||||||
{:exporter
|
(let [key (or (get cfg id)
|
||||||
(let [key (or (get cfg :exporter)
|
(-> (keys/derive secret :salt (name id))
|
||||||
(-> (keys/derive secret :salt "exporter")
|
|
||||||
(bc/bytes->b64-str true)))]
|
(bc/bytes->b64-str true)))]
|
||||||
(if (or (str/empty? key)
|
(if (or (str/empty? key)
|
||||||
(str/blank? key))
|
(str/blank? key))
|
||||||
(do
|
(do
|
||||||
(l/wrn :hint "exporter key is disabled because empty string found")
|
(l/wrn :id (name id) :hint "key is disabled because empty string found")
|
||||||
nil)
|
keys)
|
||||||
(do
|
(do
|
||||||
(l/inf :hint "exporter key initialized" :key (d/obfuscate-string key))
|
(l/inf :id (name id) :hint "key initialized" :key (d/obfuscate-string key))
|
||||||
key)))
|
(assoc keys id key)))))
|
||||||
|
{}
|
||||||
|
[:exporter
|
||||||
:nitrate
|
:nitrate
|
||||||
(let [key (or (get cfg :nitrate)
|
:nexus])))
|
||||||
(-> (keys/derive secret :salt "nitrate")
|
|
||||||
(bc/bytes->b64-str true)))]
|
(sm/register! ::props [:map-of :keyword ::sm/any])
|
||||||
(if (or (str/empty? key)
|
(sm/register! ::shared-keys [:map-of :keyword ::sm/text])
|
||||||
(str/blank? key))
|
|
||||||
(do
|
|
||||||
(l/wrn :hint "nitrate key is disabled because empty string found")
|
|
||||||
nil)
|
|
||||||
(do
|
|
||||||
(l/inf :hint "nitrate key initialized" :key (d/obfuscate-string key))
|
|
||||||
key)))})))
|
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
(if (fs/exists? path)
|
(if (fs/exists? path)
|
||||||
(io/input-stream path)
|
(io/input-stream path)
|
||||||
(let [resp (http/req! cfg
|
(let [resp (http/req cfg
|
||||||
{:method :get :uri (:file-uri template)}
|
{:method :get :uri (:file-uri template)}
|
||||||
{:response-type :input-stream :sync? true})]
|
{:response-type :input-stream :sync? true})]
|
||||||
(when-not (= 200 (:status resp))
|
(when-not (= 200 (:status resp))
|
||||||
|
|||||||
@ -53,7 +53,7 @@
|
|||||||
:or {is-active true}}]
|
:or {is-active true}}]
|
||||||
(some-> (get-current-system)
|
(some-> (get-current-system)
|
||||||
(db/tx-run!
|
(db/tx-run!
|
||||||
(fn [{:keys [::db/conn] :as system}]
|
(fn [system]
|
||||||
(let [password (derive-password password)
|
(let [password (derive-password password)
|
||||||
params {:id (uuid/next)
|
params {:id (uuid/next)
|
||||||
:email email
|
:email email
|
||||||
@ -62,7 +62,7 @@
|
|||||||
:password password
|
:password password
|
||||||
:props {}}]
|
:props {}}]
|
||||||
(->> (cmd.auth/create-profile system params)
|
(->> (cmd.auth/create-profile system params)
|
||||||
(cmd.auth/create-profile-rels conn)))))))
|
(cmd.auth/create-profile-rels system)))))))
|
||||||
|
|
||||||
(defmethod exec-command "update-profile"
|
(defmethod exec-command "update-profile"
|
||||||
[{:keys [fullname email password is-active]}]
|
[{:keys [fullname email password is-active]}]
|
||||||
|
|||||||
@ -553,14 +553,13 @@
|
|||||||
(let [file-id (h/parse-uuid file-id)
|
(let [file-id (h/parse-uuid file-id)
|
||||||
tnow (ct/now)]
|
tnow (ct/now)]
|
||||||
|
|
||||||
(audit/insert! main/system
|
(audit/insert main/system
|
||||||
{::audit/name "delete-file"
|
{:name "delete-file"
|
||||||
::audit/type "action"
|
:type "action"
|
||||||
::audit/profile-id uuid/zero
|
:props {:id file-id}
|
||||||
::audit/props {:id file-id}
|
:context {:triggered-by "srepl"
|
||||||
::audit/context {:triggered-by "srepl"
|
|
||||||
:cause "explicit call to delete-file!"}
|
:cause "explicit call to delete-file!"}
|
||||||
::audit/tracked-at tnow})
|
:tracked-at tnow})
|
||||||
(wrk/invoke! (-> main/system
|
(wrk/invoke! (-> main/system
|
||||||
(assoc ::wrk/task :delete-object)
|
(assoc ::wrk/task :delete-object)
|
||||||
(assoc ::wrk/params {:object :file
|
(assoc ::wrk/params {:object :file
|
||||||
@ -578,17 +577,14 @@
|
|||||||
{:id file-id}
|
{:id file-id}
|
||||||
{::db/remove-deleted false
|
{::db/remove-deleted false
|
||||||
::sql/columns [:id :name]})]
|
::sql/columns [:id :name]})]
|
||||||
(audit/insert! system
|
(audit/insert system
|
||||||
{::audit/name "restore-file"
|
{:name "restore-file"
|
||||||
::audit/type "action"
|
:type "action"
|
||||||
::audit/profile-id uuid/zero
|
:props file
|
||||||
::audit/props file
|
:context {:triggered-by "srepl"
|
||||||
::audit/context {:triggered-by "srepl"
|
:cause "explicit call to restore-file!"}})
|
||||||
:cause "explicit call to restore-file!"}
|
|
||||||
::audit/tracked-at (ct/now)})
|
|
||||||
|
|
||||||
|
(#'files/restore-files conn [file-id]))
|
||||||
(#'files/restore-file conn file-id))
|
|
||||||
:restored))))
|
:restored))))
|
||||||
|
|
||||||
(defn delete-project!
|
(defn delete-project!
|
||||||
@ -597,14 +593,13 @@
|
|||||||
(let [project-id (h/parse-uuid project-id)
|
(let [project-id (h/parse-uuid project-id)
|
||||||
tnow (ct/now)]
|
tnow (ct/now)]
|
||||||
|
|
||||||
(audit/insert! main/system
|
(audit/insert main/system
|
||||||
{::audit/name "delete-project"
|
{:name "delete-project"
|
||||||
::audit/type "action"
|
:type "action"
|
||||||
::audit/profile-id uuid/zero
|
:props {:id project-id}
|
||||||
::audit/props {:id project-id}
|
:context {:triggered-by "srepl"
|
||||||
::audit/context {:triggered-by "srepl"
|
|
||||||
:cause "explicit call to delete-project!"}
|
:cause "explicit call to delete-project!"}
|
||||||
::audit/tracked-at tnow})
|
:tracked-at tnow})
|
||||||
|
|
||||||
(wrk/invoke! (-> main/system
|
(wrk/invoke! (-> main/system
|
||||||
(assoc ::wrk/task :delete-object)
|
(assoc ::wrk/task :delete-object)
|
||||||
@ -622,7 +617,7 @@
|
|||||||
(doseq [{:keys [id]} (db/query conn :file
|
(doseq [{:keys [id]} (db/query conn :file
|
||||||
{:project-id project-id}
|
{:project-id project-id}
|
||||||
{::sql/columns [:id]})]
|
{::sql/columns [:id]})]
|
||||||
(#'files/restore-file conn id))
|
(#'files/restore-files conn [id]))
|
||||||
|
|
||||||
:restored)
|
:restored)
|
||||||
|
|
||||||
@ -635,14 +630,12 @@
|
|||||||
(when-let [project (db/get* system :project
|
(when-let [project (db/get* system :project
|
||||||
{:id project-id}
|
{:id project-id}
|
||||||
{::db/remove-deleted false})]
|
{::db/remove-deleted false})]
|
||||||
(audit/insert! system
|
(audit/insert system
|
||||||
{::audit/name "restore-project"
|
{:name "restore-project"
|
||||||
::audit/type "action"
|
:type "action"
|
||||||
::audit/profile-id uuid/zero
|
:props project
|
||||||
::audit/props project
|
:context {:triggered-by "srepl"
|
||||||
::audit/context {:triggered-by "srepl"
|
:cause "explicit call to restore-team!"}})
|
||||||
:cause "explicit call to restore-team!"}
|
|
||||||
::audit/tracked-at (ct/now)})
|
|
||||||
|
|
||||||
(restore-project* system project-id))))))
|
(restore-project* system project-id))))))
|
||||||
|
|
||||||
@ -652,14 +645,13 @@
|
|||||||
(let [team-id (h/parse-uuid team-id)
|
(let [team-id (h/parse-uuid team-id)
|
||||||
tnow (ct/now)]
|
tnow (ct/now)]
|
||||||
|
|
||||||
(audit/insert! main/system
|
(audit/insert main/system
|
||||||
{::audit/name "delete-team"
|
{:name "delete-team"
|
||||||
::audit/type "action"
|
:type "action"
|
||||||
::audit/profile-id uuid/zero
|
:props {:id team-id}
|
||||||
::audit/props {:id team-id}
|
:context {:triggered-by "srepl"
|
||||||
::audit/context {:triggered-by "srepl"
|
|
||||||
:cause "explicit call to delete-profile!"}
|
:cause "explicit call to delete-profile!"}
|
||||||
::audit/tracked-at tnow})
|
:tracked-at tnow})
|
||||||
|
|
||||||
(wrk/invoke! (-> main/system
|
(wrk/invoke! (-> main/system
|
||||||
(assoc ::wrk/task :delete-object)
|
(assoc ::wrk/task :delete-object)
|
||||||
@ -695,14 +687,12 @@
|
|||||||
{:id team-id}
|
{:id team-id}
|
||||||
{::db/remove-deleted false})
|
{::db/remove-deleted false})
|
||||||
(teams/decode-row))]
|
(teams/decode-row))]
|
||||||
(audit/insert! system
|
(audit/insert system
|
||||||
{::audit/name "restore-team"
|
{:name "restore-team"
|
||||||
::audit/type "action"
|
:type "action"
|
||||||
::audit/profile-id uuid/zero
|
:props team
|
||||||
::audit/props team
|
:context {:triggered-by "srepl"
|
||||||
::audit/context {:triggered-by "srepl"
|
:cause "explicit call to restore-team!"}})
|
||||||
:cause "explicit call to restore-team!"}
|
|
||||||
::audit/tracked-at (ct/now)})
|
|
||||||
|
|
||||||
(restore-team* system team-id))))))
|
(restore-team* system team-id))))))
|
||||||
|
|
||||||
@ -712,13 +702,12 @@
|
|||||||
(let [profile-id (h/parse-uuid profile-id)
|
(let [profile-id (h/parse-uuid profile-id)
|
||||||
tnow (ct/now)]
|
tnow (ct/now)]
|
||||||
|
|
||||||
(audit/insert! main/system
|
(audit/insert main/system
|
||||||
{::audit/name "delete-profile"
|
{:name "delete-profile"
|
||||||
::audit/type "action"
|
:type "action"
|
||||||
::audit/profile-id uuid/zero
|
:context {:triggered-by "srepl"
|
||||||
::audit/context {:triggered-by "srepl"
|
|
||||||
:cause "explicit call to delete-profile!"}
|
:cause "explicit call to delete-profile!"}
|
||||||
::audit/tracked-at tnow})
|
:tracked-at tnow})
|
||||||
|
|
||||||
(wrk/invoke! (-> main/system
|
(wrk/invoke! (-> main/system
|
||||||
(assoc ::wrk/task :delete-object)
|
(assoc ::wrk/task :delete-object)
|
||||||
@ -737,14 +726,12 @@
|
|||||||
{:id profile-id}
|
{:id profile-id}
|
||||||
{::db/remove-deleted false})
|
{::db/remove-deleted false})
|
||||||
(profile/decode-row))]
|
(profile/decode-row))]
|
||||||
(audit/insert! system
|
(audit/insert system
|
||||||
{::audit/name "restore-profile"
|
{:name "restore-profile"
|
||||||
::audit/type "action"
|
:type "action"
|
||||||
::audit/profile-id uuid/zero
|
:props (audit/profile->props profile)
|
||||||
::audit/props (audit/profile->props profile)
|
:context {:triggered-by "srepl"
|
||||||
::audit/context {:triggered-by "srepl"
|
:cause "explicit call to restore-profile!"}})
|
||||||
:cause "explicit call to restore-profile!"}
|
|
||||||
::audit/tracked-at (ct/now)})
|
|
||||||
|
|
||||||
(db/update! system :profile
|
(db/update! system :profile
|
||||||
{:deleted-at nil}
|
{:deleted-at nil}
|
||||||
@ -768,13 +755,13 @@
|
|||||||
{::db/remove-deleted false})
|
{::db/remove-deleted false})
|
||||||
(profile/decode-row))]
|
(profile/decode-row))]
|
||||||
(do
|
(do
|
||||||
(audit/insert! system
|
(audit/insert system
|
||||||
{::audit/name "delete-profile"
|
{:name "delete-profile"
|
||||||
::audit/type "action"
|
:type "action"
|
||||||
::audit/profile-id (:id profile)
|
:profile-id (:id profile)
|
||||||
::audit/tracked-at deleted-at
|
:tracked-at deleted-at
|
||||||
::audit/props (audit/profile->props profile)
|
:props (audit/profile->props profile)
|
||||||
::audit/context {:triggered-by "srepl"
|
:context {:triggered-by "srepl"
|
||||||
:cause "explicit call to delete-profiles-in-bulk!"}})
|
:cause "explicit call to delete-profiles-in-bulk!"}})
|
||||||
(wrk/invoke! (-> system
|
(wrk/invoke! (-> system
|
||||||
(assoc ::wrk/task :delete-object)
|
(assoc ::wrk/task :delete-object)
|
||||||
@ -905,5 +892,4 @@
|
|||||||
(let [params (-> rel
|
(let [params (-> rel
|
||||||
(assoc :id (uuid/next))
|
(assoc :id (uuid/next))
|
||||||
(assoc :team-id (:id team)))]
|
(assoc :team-id (:id team)))]
|
||||||
(db/insert! conn :team-profile-rel params
|
(teams/add-profile-to-team! cfg params {::db/return-keys false}))))))))
|
||||||
{::db/return-keys false}))))))))
|
|
||||||
|
|||||||
@ -44,6 +44,7 @@
|
|||||||
"file-object-thumbnail"
|
"file-object-thumbnail"
|
||||||
"file-thumbnail"
|
"file-thumbnail"
|
||||||
"profile"
|
"profile"
|
||||||
|
"organization"
|
||||||
"tempfile"
|
"tempfile"
|
||||||
"file-data"
|
"file-data"
|
||||||
"file-data-fragment"
|
"file-data-fragment"
|
||||||
|
|||||||
@ -149,7 +149,7 @@
|
|||||||
:status "delete"
|
:status "delete"
|
||||||
:bucket bucket)
|
:bucket bucket)
|
||||||
(recur to-freeze (conj to-delete id) (rest objects))))
|
(recur to-freeze (conj to-delete id) (rest objects))))
|
||||||
(let [deletion-delay (if (= bucket "tempfile")
|
(let [deletion-delay (if (= "tempfile" bucket)
|
||||||
(ct/duration {:hours 2})
|
(ct/duration {:hours 2})
|
||||||
(cf/get-deletion-delay))]
|
(cf/get-deletion-delay))]
|
||||||
(some->> (seq to-freeze) (mark-freeze-in-bulk! conn))
|
(some->> (seq to-freeze) (mark-freeze-in-bulk! conn))
|
||||||
@ -166,6 +166,7 @@
|
|||||||
"profile" (process-objects! conn has-profile-refs? bucket objects)
|
"profile" (process-objects! conn has-profile-refs? bucket objects)
|
||||||
"file-data" (process-objects! conn has-file-data-refs? bucket objects)
|
"file-data" (process-objects! conn has-file-data-refs? bucket objects)
|
||||||
"tempfile" (process-objects! conn (constantly false) bucket objects)
|
"tempfile" (process-objects! conn (constantly false) bucket objects)
|
||||||
|
"organization" (process-objects! conn (constantly false) bucket objects)
|
||||||
(ex/raise :type :internal
|
(ex/raise :type :internal
|
||||||
:code :unexpected-unknown-reference
|
:code :unexpected-unknown-reference
|
||||||
:hint (dm/fmt "unknown reference '%'" bucket))))
|
:hint (dm/fmt "unknown reference '%'" bucket))))
|
||||||
@ -213,8 +214,13 @@
|
|||||||
[_ params]
|
[_ params]
|
||||||
(assert (db/pool? (::db/pool params)) "expect valid storage"))
|
(assert (db/pool? (::db/pool params)) "expect valid storage"))
|
||||||
|
|
||||||
(defmethod ig/init-key ::handler
|
(defmethod ig/expand-key ::handler
|
||||||
[_ cfg]
|
[k v]
|
||||||
(fn [_]
|
{k (merge {::min-age (ct/duration {:hours 2})} v)})
|
||||||
(process-touched! (assoc cfg ::timestamp (ct/now)))))
|
|
||||||
|
(defmethod ig/init-key ::handler
|
||||||
|
[_ {:keys [::min-age] :as cfg}]
|
||||||
|
(fn [_]
|
||||||
|
(let [threshold (ct/minus (ct/now) min-age)]
|
||||||
|
(process-touched! (assoc cfg ::timestamp threshold)))))
|
||||||
|
|
||||||
|
|||||||
@ -11,43 +11,27 @@
|
|||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.logging :as l]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.http.client :as http]
|
[app.http.client :as http]
|
||||||
[app.main :as-alias main]
|
[app.main :as-alias main]
|
||||||
[app.setup :as-alias setup]
|
[app.setup :as-alias setup]
|
||||||
|
[app.util.blob :as blob]
|
||||||
[app.util.json :as json]
|
[app.util.json :as json]
|
||||||
[integrant.core :as ig]
|
[integrant.core :as ig]
|
||||||
[promesa.exec :as px]))
|
[promesa.exec :as px]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
(defn- get-subscriptions
|
||||||
;; IMPL
|
[cfg]
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
(defn- send!
|
|
||||||
[cfg data]
|
|
||||||
(let [request {:method :post
|
|
||||||
:uri (cf/get :telemetry-uri)
|
|
||||||
:headers {"content-type" "application/json"}
|
|
||||||
:body (json/encode-str data)}
|
|
||||||
response (http/req! cfg request)]
|
|
||||||
(when (> (:status response) 206)
|
|
||||||
(ex/raise :type :internal
|
|
||||||
:code :invalid-response
|
|
||||||
:response-status (:status response)
|
|
||||||
:response-body (:body response)))))
|
|
||||||
|
|
||||||
(defn- get-subscriptions-newsletter-updates
|
|
||||||
[conn]
|
|
||||||
(let [sql "SELECT email FROM profile where props->>'~:newsletter-updates' = 'true'"]
|
(let [sql "SELECT email FROM profile where props->>'~:newsletter-updates' = 'true'"]
|
||||||
|
(db/run! cfg (fn [{:keys [::db/conn]}]
|
||||||
(->> (db/exec! conn [sql])
|
(->> (db/exec! conn [sql])
|
||||||
(mapv :email))))
|
(mapv :email))))))
|
||||||
|
|
||||||
(defn- get-subscriptions-newsletter-news
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
[conn]
|
;; LEGACY DATA COLLECTION
|
||||||
(let [sql "SELECT email FROM profile where props->>'~:newsletter-news' = 'true'"]
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(->> (db/exec! conn [sql])
|
|
||||||
(mapv :email))))
|
|
||||||
|
|
||||||
(defn- get-num-teams
|
(defn- get-num-teams
|
||||||
[conn]
|
[conn]
|
||||||
@ -161,8 +145,9 @@
|
|||||||
(def ^:private sql:get-counters
|
(def ^:private sql:get-counters
|
||||||
"SELECT name, count(*) AS count
|
"SELECT name, count(*) AS count
|
||||||
FROM audit_log
|
FROM audit_log
|
||||||
WHERE source = 'backend'
|
WHERE source LIKE 'telemetry:%'
|
||||||
AND tracked_at >= date_trunc('day', now())
|
AND created_at >= date_trunc('day', now())
|
||||||
|
AND created_at < date_trunc('day', now()) + interval '1 day'
|
||||||
GROUP BY 1
|
GROUP BY 1
|
||||||
ORDER BY 2 DESC")
|
ORDER BY 2 DESC")
|
||||||
|
|
||||||
@ -174,23 +159,13 @@
|
|||||||
{:total-accomulated-events total
|
{:total-accomulated-events total
|
||||||
:event-counters counters}))
|
:event-counters counters}))
|
||||||
|
|
||||||
(def ^:private sql:clean-counters
|
(defn- get-legacy-stats
|
||||||
"DELETE FROM audit_log
|
[{:keys [::db/conn]}]
|
||||||
WHERE ip_addr = '0.0.0.0'::inet -- we know this is from telemetry
|
|
||||||
AND tracked_at < (date_trunc('day', now()) - '1 day'::interval)")
|
|
||||||
|
|
||||||
(defn- clean-counters-data!
|
|
||||||
[conn]
|
|
||||||
(when-not (contains? cf/flags :audit-log)
|
|
||||||
(db/exec-one! conn [sql:clean-counters])))
|
|
||||||
|
|
||||||
(defn- get-stats
|
|
||||||
[conn]
|
|
||||||
(let [referer (if (cf/get :telemetry-with-taiga)
|
(let [referer (if (cf/get :telemetry-with-taiga)
|
||||||
"taiga"
|
"taiga"
|
||||||
(cf/get :telemetry-referer))]
|
(cf/get :telemetry-referer))]
|
||||||
(-> {:referer referer
|
(-> {:referer referer
|
||||||
:public-uri (cf/get :public-uri)
|
:public-uri (str (cf/get :public-uri))
|
||||||
:total-teams (get-num-teams conn)
|
:total-teams (get-num-teams conn)
|
||||||
:total-projects (get-num-projects conn)
|
:total-projects (get-num-projects conn)
|
||||||
:total-files (get-num-files conn)
|
:total-files (get-num-files conn)
|
||||||
@ -207,6 +182,124 @@
|
|||||||
(get-action-counters conn))
|
(get-action-counters conn))
|
||||||
(d/without-nils))))
|
(d/without-nils))))
|
||||||
|
|
||||||
|
(defn- make-legacy-request
|
||||||
|
[cfg data]
|
||||||
|
(let [request {:method :post
|
||||||
|
:uri (cf/get :telemetry-uri)
|
||||||
|
:headers {"content-type" "application/json"}
|
||||||
|
:body (json/encode-str data)}
|
||||||
|
response (http/req cfg request {:skip-ssrf-check? true})]
|
||||||
|
(when (> (:status response) 206)
|
||||||
|
(ex/raise :type :internal
|
||||||
|
:code :invalid-response
|
||||||
|
:response-status (:status response)
|
||||||
|
:response-body (:body response)))))
|
||||||
|
|
||||||
|
(defn- send-legacy-data
|
||||||
|
[{:keys [::setup/props] :as cfg} stats subs]
|
||||||
|
(let [data (cond-> {:type :telemetry-legacy-report
|
||||||
|
:version (:full cf/version)
|
||||||
|
:instance-id (:instance-id props)}
|
||||||
|
(some? stats)
|
||||||
|
(assoc :stats stats)
|
||||||
|
|
||||||
|
(seq subs)
|
||||||
|
(assoc :subscriptions subs))]
|
||||||
|
|
||||||
|
(make-legacy-request cfg data)))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; AUDIT-EVENT BATCH (TELEMETRY MODE)
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
;; Telemetry events older than this are purged by the GC step so the
|
||||||
|
;; buffer stays bounded.
|
||||||
|
(def ^:private batch-size 10000)
|
||||||
|
|
||||||
|
(def ^:private sql:gc-events
|
||||||
|
"DELETE FROM audit_log
|
||||||
|
WHERE source LIKE 'telemetry:%'
|
||||||
|
AND created_at < now() - interval '7 days'")
|
||||||
|
|
||||||
|
(defn- gc-events
|
||||||
|
"Delete telemetry-mode events older than `telemetry-retention-days`
|
||||||
|
so that the buffer stays bounded."
|
||||||
|
[{:keys [::db/conn]}]
|
||||||
|
(let [result (db/exec-one! conn [sql:gc-events])]
|
||||||
|
(when (pos? (:next.jdbc/update-count result))
|
||||||
|
(l/warn :hint "purged stale telemetry events"
|
||||||
|
:count (:next.jdbc/update-count result)))))
|
||||||
|
|
||||||
|
(def ^:private sql:fetch-telemetry-events
|
||||||
|
"SELECT id, name, type, source, tracked_at, profile_id, props, context
|
||||||
|
FROM audit_log
|
||||||
|
WHERE source LIKE 'telemetry:%'
|
||||||
|
ORDER BY created_at ASC
|
||||||
|
LIMIT ?")
|
||||||
|
|
||||||
|
(defn- row->event
|
||||||
|
[{:keys [name type source tracked-at profile-id props context]}]
|
||||||
|
(d/without-nils
|
||||||
|
{:name name
|
||||||
|
:type type
|
||||||
|
:source source
|
||||||
|
:tracked-at tracked-at
|
||||||
|
:profile-id profile-id
|
||||||
|
:props (or (some-> props db/decode-transit-pgobject) {})
|
||||||
|
:context (or (some-> context db/decode-transit-pgobject) {})}))
|
||||||
|
|
||||||
|
(defn- encode-batch
|
||||||
|
"Encode a sequence of event maps into a fressian+zstd base64 string
|
||||||
|
suitable for JSON transport."
|
||||||
|
^String [events]
|
||||||
|
(blob/encode-str events {:version 4}))
|
||||||
|
|
||||||
|
(defn send-event-batch
|
||||||
|
"Send a single batch of events to the telemetry endpoint. Returns
|
||||||
|
true on success."
|
||||||
|
[{:keys [::setup/props] :as cfg} batch]
|
||||||
|
(let [payload {:type :telemetry-events
|
||||||
|
:version (:full cf/version)
|
||||||
|
:instance-id (:instance-id props)
|
||||||
|
:events (encode-batch batch)}
|
||||||
|
request {:method :post
|
||||||
|
:uri (cf/get :telemetry-uri)
|
||||||
|
:headers {"content-type" "application/json"}
|
||||||
|
:body (json/encode-str payload)}
|
||||||
|
resp (http/req cfg request {:skip-ssrf-check? true})]
|
||||||
|
(if (<= (:status resp) 206)
|
||||||
|
true
|
||||||
|
(do
|
||||||
|
(l/warn :hint "telemetry event batch send failed"
|
||||||
|
:status (:status resp)
|
||||||
|
:body (:body resp))
|
||||||
|
false))))
|
||||||
|
|
||||||
|
(defn- delete-sent-events
|
||||||
|
"Delete rows by their ids after a successful send."
|
||||||
|
[conn ids]
|
||||||
|
(let [arr (db/create-array conn "uuid" ids)]
|
||||||
|
(db/exec-one! conn ["DELETE FROM audit_log WHERE id = ANY(?)" arr])))
|
||||||
|
|
||||||
|
(defn- collect-and-send-audit-events
|
||||||
|
"Collect anonymous telemetry-mode audit events and ship them to the
|
||||||
|
telemetry endpoint in a loop. Each iteration fetches one page of
|
||||||
|
`batch-size` rows, encodes and sends them, then deletes the rows on
|
||||||
|
success. The loop stops as soon as a send returns false, leaving
|
||||||
|
remaining rows intact for the next run."
|
||||||
|
[{:keys [::db/conn] :as cfg}]
|
||||||
|
(loop [counter 1]
|
||||||
|
(when-let [rows (-> (db/exec! conn [sql:fetch-telemetry-events batch-size])
|
||||||
|
(not-empty))]
|
||||||
|
(let [events (mapv row->event rows)
|
||||||
|
ids (mapv :id rows)]
|
||||||
|
(l/dbg :hint "shipping telemetry event batch"
|
||||||
|
:total (count events)
|
||||||
|
:batch counter)
|
||||||
|
(when (send-event-batch cfg events)
|
||||||
|
(delete-sent-events conn ids)
|
||||||
|
(recur (inc counter)))))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; TASK ENTRY POINT
|
;; TASK ENTRY POINT
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -218,46 +311,47 @@
|
|||||||
(assert (some? (::setup/props params)) "expected setup props to be available"))
|
(assert (some? (::setup/props params)) "expected setup props to be available"))
|
||||||
|
|
||||||
(defmethod ig/init-key ::handler
|
(defmethod ig/init-key ::handler
|
||||||
[_ {:keys [::db/pool ::setup/props] :as cfg}]
|
[_ cfg]
|
||||||
(fn [task]
|
(fn [task]
|
||||||
(let [params (:props task)
|
(let [params (:props task)
|
||||||
send? (get params :send? true)
|
send? (get params :send? true)
|
||||||
enabled? (or (get params :enabled? false)
|
enabled? (or (get params :enabled? false)
|
||||||
(contains? cf/flags :telemetry)
|
(contains? cf/flags :telemetry))
|
||||||
(cf/get :telemetry-enabled))
|
subs (get-subscriptions cfg)]
|
||||||
|
|
||||||
subs {:newsletter-updates (get-subscriptions-newsletter-updates pool)
|
|
||||||
:newsletter-news (get-subscriptions-newsletter-news pool)}
|
|
||||||
|
|
||||||
data {:subscriptions subs
|
|
||||||
:version (:full cf/version)
|
|
||||||
:instance-id (:instance-id props)}]
|
|
||||||
|
|
||||||
(when enabled?
|
|
||||||
(clean-counters-data! pool))
|
|
||||||
|
|
||||||
(cond
|
|
||||||
;; If we have telemetry enabled, then proceed the normal
|
;; If we have telemetry enabled, then proceed the normal
|
||||||
;; operation.
|
;; operation sending legacy report
|
||||||
enabled?
|
|
||||||
(let [data (merge data (get-stats pool))]
|
(if enabled?
|
||||||
(when send?
|
(when send?
|
||||||
|
(db/run! cfg gc-events)
|
||||||
|
;; Randomize start time to avoid thundering herd when multiple
|
||||||
|
;; instances restart at the same time.
|
||||||
(px/sleep (rand-int 10000))
|
(px/sleep (rand-int 10000))
|
||||||
(send! cfg data))
|
|
||||||
data)
|
(try
|
||||||
|
(let [stats (db/run! cfg get-legacy-stats)]
|
||||||
|
(send-legacy-data cfg stats subs))
|
||||||
|
(catch Exception cause
|
||||||
|
(l/wrn :hint "unable to send legacy report"
|
||||||
|
:cause cause)))
|
||||||
|
|
||||||
|
;; Ship any anonymous audit-log events accumulated in
|
||||||
|
;; telemetry mode (only when audit-log feature is off).
|
||||||
|
(when-not (contains? cf/flags :audit-log)
|
||||||
|
(try
|
||||||
|
(db/run! cfg collect-and-send-audit-events)
|
||||||
|
(catch Exception cause
|
||||||
|
(l/wrn :hint "unable to send events"
|
||||||
|
:cause cause)))))
|
||||||
|
|
||||||
;; If we have telemetry disabled, but there are users that are
|
;; If we have telemetry disabled, but there are users that are
|
||||||
;; explicitly checked the newsletter subscription on the
|
;; explicitly checked the newsletter subscription on the
|
||||||
;; onboarding dialog or the profile section, then proceed to
|
;; onboarding dialog or the profile section, then proceed to
|
||||||
;; send a limited telemetry data, that consists in the list of
|
;; send a limited telemetry data, that consists in the list of
|
||||||
;; subscribed emails and the running penpot version.
|
;; subscribed emails and the running penpot version.
|
||||||
(or (seq (:newsletter-updates subs))
|
(when (and send? (seq subs))
|
||||||
(seq (:newsletter-news subs)))
|
|
||||||
(do
|
|
||||||
(when send?
|
|
||||||
(px/sleep (rand-int 10000))
|
(px/sleep (rand-int 10000))
|
||||||
(send! cfg data))
|
(ex/ignoring
|
||||||
data)
|
(send-legacy-data cfg nil subs)))))))
|
||||||
|
|
||||||
:else
|
|
||||||
data))))
|
|
||||||
|
|||||||
41
backend/src/app/tasks/upload_session_gc.clj
Normal file
41
backend/src/app/tasks/upload_session_gc.clj
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.tasks.upload-session-gc
|
||||||
|
"A maintenance task that deletes stalled (incomplete) upload sessions.
|
||||||
|
|
||||||
|
An upload session is considered stalled when it was created more than
|
||||||
|
`max-age` ago without being completed (i.e. the session row still
|
||||||
|
exists because `assemble-chunks` was never called to clean it up).
|
||||||
|
The default max-age is 1 hour."
|
||||||
|
(:require
|
||||||
|
[app.common.logging :as l]
|
||||||
|
[app.common.time :as ct]
|
||||||
|
[app.db :as db]
|
||||||
|
[integrant.core :as ig]))
|
||||||
|
|
||||||
|
(def ^:private sql:delete-stalled-sessions
|
||||||
|
"DELETE FROM upload_session
|
||||||
|
WHERE created_at < ?::timestamptz")
|
||||||
|
|
||||||
|
(defmethod ig/assert-key ::handler
|
||||||
|
[_ params]
|
||||||
|
(assert (db/pool? (::db/pool params)) "expected a valid database pool"))
|
||||||
|
|
||||||
|
(defmethod ig/expand-key ::handler
|
||||||
|
[k v]
|
||||||
|
{k (merge {::max-age (ct/duration {:hours 1})} v)})
|
||||||
|
|
||||||
|
(defmethod ig/init-key ::handler
|
||||||
|
[_ {:keys [::max-age] :as cfg}]
|
||||||
|
(fn [_]
|
||||||
|
(db/tx-run! cfg
|
||||||
|
(fn [{:keys [::db/conn]}]
|
||||||
|
(let [threshold (ct/minus (ct/now) max-age)
|
||||||
|
result (-> (db/exec-one! conn [sql:delete-stalled-sessions threshold])
|
||||||
|
(db/get-update-count))]
|
||||||
|
(l/debug :hint "task finished" :deleted result)
|
||||||
|
{:deleted result})))))
|
||||||
@ -19,6 +19,7 @@
|
|||||||
java.io.DataOutputStream
|
java.io.DataOutputStream
|
||||||
java.io.InputStream
|
java.io.InputStream
|
||||||
java.io.OutputStream
|
java.io.OutputStream
|
||||||
|
java.util.Base64
|
||||||
net.jpountz.lz4.LZ4Compressor
|
net.jpountz.lz4.LZ4Compressor
|
||||||
net.jpountz.lz4.LZ4Factory
|
net.jpountz.lz4.LZ4Factory
|
||||||
net.jpountz.lz4.LZ4FastDecompressor
|
net.jpountz.lz4.LZ4FastDecompressor
|
||||||
@ -49,6 +50,13 @@
|
|||||||
5 (encode-v5 data)
|
5 (encode-v5 data)
|
||||||
(throw (ex-info "unsupported version" {:version version}))))))
|
(throw (ex-info "unsupported version" {:version version}))))))
|
||||||
|
|
||||||
|
(defn encode-str
|
||||||
|
"Encode data to a blob and return it as a URL-safe base64 string
|
||||||
|
(no padding). Accepts the same options as `encode`."
|
||||||
|
(^String [data] (encode-str data nil))
|
||||||
|
(^String [data opts]
|
||||||
|
(.encodeToString (.withoutPadding (Base64/getUrlEncoder)) ^bytes (encode data opts))))
|
||||||
|
|
||||||
(defn decode
|
(defn decode
|
||||||
"A function used for decode persisted blobs in the database."
|
"A function used for decode persisted blobs in the database."
|
||||||
[^bytes data]
|
[^bytes data]
|
||||||
@ -63,6 +71,11 @@
|
|||||||
5 (decode-v5 data)
|
5 (decode-v5 data)
|
||||||
(throw (ex-info "unsupported version" {:version version}))))))
|
(throw (ex-info "unsupported version" {:version version}))))))
|
||||||
|
|
||||||
|
(defn decode-str
|
||||||
|
"Decode a URL-safe base64 string produced by `encode-str` back to data."
|
||||||
|
[^String s]
|
||||||
|
(decode (.decode (Base64/getUrlDecoder) s)))
|
||||||
|
|
||||||
;; --- IMPL
|
;; --- IMPL
|
||||||
|
|
||||||
(defn- encode-v1
|
(defn- encode-v1
|
||||||
|
|||||||
91
backend/src/app/util/nio.clj
Normal file
91
backend/src/app/util/nio.clj
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.util.nio
|
||||||
|
"NIO helpers for working with files and byte arrays.
|
||||||
|
|
||||||
|
These are thin wrappers around java.nio that provide a
|
||||||
|
Clojure-idiomatic API. Candidates for porting to datoteka."
|
||||||
|
(:import
|
||||||
|
java.nio.ByteBuffer
|
||||||
|
java.nio.channels.FileChannel
|
||||||
|
java.nio.file.Files
|
||||||
|
java.nio.file.OpenOption
|
||||||
|
java.nio.file.Path
|
||||||
|
java.nio.file.StandardOpenOption))
|
||||||
|
|
||||||
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
|
;; ----------------------------------------------------------------
|
||||||
|
;; File operations (via java.nio.file.Files)
|
||||||
|
;; ----------------------------------------------------------------
|
||||||
|
|
||||||
|
(defn read-bytes
|
||||||
|
"Read all bytes from a file at `path`. Returns a byte array."
|
||||||
|
^bytes [^Path path]
|
||||||
|
(Files/readAllBytes path))
|
||||||
|
|
||||||
|
(defn write-bytes
|
||||||
|
"Write `data` (byte array) to a file at `path`, replacing existing
|
||||||
|
content. Returns `path`."
|
||||||
|
[^Path path ^bytes data]
|
||||||
|
(Files/write path data ^"[Ljava.nio.file.OpenOption;" (into-array OpenOption []))
|
||||||
|
path)
|
||||||
|
|
||||||
|
(defn append-bytes
|
||||||
|
"Append `data` (byte array) to the end of the file at `path`.
|
||||||
|
Creates the file if it does not exist. Returns `path`."
|
||||||
|
[^Path path ^bytes data]
|
||||||
|
(Files/write path data
|
||||||
|
^"[Ljava.nio.file.OpenOption;"
|
||||||
|
(into-array OpenOption
|
||||||
|
[StandardOpenOption/CREATE
|
||||||
|
StandardOpenOption/APPEND]))
|
||||||
|
path)
|
||||||
|
|
||||||
|
;; ----------------------------------------------------------------
|
||||||
|
;; FileChannel operations (internal API)
|
||||||
|
;; ----------------------------------------------------------------
|
||||||
|
|
||||||
|
(def ^:private read-write-opts
|
||||||
|
(into-array OpenOption
|
||||||
|
[StandardOpenOption/READ StandardOpenOption/WRITE]))
|
||||||
|
|
||||||
|
(defn open-channel
|
||||||
|
"Open a FileChannel for read/write on the given path."
|
||||||
|
^FileChannel [^Path path]
|
||||||
|
(FileChannel/open path read-write-opts))
|
||||||
|
|
||||||
|
(defn channel-size
|
||||||
|
"Return the size of the file backed by the channel."
|
||||||
|
^long [^FileChannel channel]
|
||||||
|
(.size channel))
|
||||||
|
|
||||||
|
(defn read-at
|
||||||
|
"Read `length` bytes from `channel` starting at `position` into a
|
||||||
|
new byte array. Returns the byte array.
|
||||||
|
Loops until the ByteBuffer is fully populated to guard against OS
|
||||||
|
partial reads, which would otherwise cause BufferUnderflowException
|
||||||
|
when copying from the buffer into the result array."
|
||||||
|
^bytes [^FileChannel channel ^long position ^long length]
|
||||||
|
(let [buf (ByteBuffer/allocate (int length))]
|
||||||
|
(.position channel position)
|
||||||
|
(loop []
|
||||||
|
(when (.hasRemaining buf)
|
||||||
|
(let [n (.read channel buf)]
|
||||||
|
(when (pos? n)
|
||||||
|
(recur)))))
|
||||||
|
(.flip buf)
|
||||||
|
(let [remaining (.remaining buf)
|
||||||
|
arr (byte-array remaining)]
|
||||||
|
(.get buf arr)
|
||||||
|
arr)))
|
||||||
|
|
||||||
|
(defn truncate
|
||||||
|
"Truncate the file to the given size. Returns the channel."
|
||||||
|
[^FileChannel channel ^long size]
|
||||||
|
(.truncate channel size)
|
||||||
|
channel)
|
||||||
229
backend/src/app/util/ssrf.clj
Normal file
229
backend/src/app/util/ssrf.clj
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.util.ssrf
|
||||||
|
"URL/host validation to prevent Server-Side Request Forgery."
|
||||||
|
(:require
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.logging :as l]
|
||||||
|
[app.config :as cf]
|
||||||
|
[cuerdas.core :as str])
|
||||||
|
(:import
|
||||||
|
com.google.common.net.InetAddresses
|
||||||
|
java.net.InetAddress
|
||||||
|
java.net.UnknownHostException
|
||||||
|
java.net.URI))
|
||||||
|
|
||||||
|
(def ^:private allowed-schemes
|
||||||
|
#{"http" "https"})
|
||||||
|
|
||||||
|
(def ^:private cloud-metadata-ips
|
||||||
|
"Exact IP addresses for cloud metadata services."
|
||||||
|
#{"169.254.169.254"
|
||||||
|
"fd00:ec2::254"})
|
||||||
|
|
||||||
|
(def ^:private extra-blocked-ranges
|
||||||
|
"CIDR ranges not covered by standard JDK InetAddress predicates.
|
||||||
|
Each entry is [base-address prefix-length]."
|
||||||
|
;; Carrier-grade NAT
|
||||||
|
[[100 64 0 0 10]
|
||||||
|
;; RFC 6890 / documentation / reserved
|
||||||
|
[192 0 0 0 24]
|
||||||
|
[192 0 2 0 24]
|
||||||
|
[198 18 0 0 15]
|
||||||
|
[198 51 100 0 24]
|
||||||
|
[203 0 113 0 24]
|
||||||
|
;; Reserved / future-use (broadcast and above)
|
||||||
|
[240 0 0 0 4]])
|
||||||
|
|
||||||
|
(defn- ip4-to-long
|
||||||
|
"Convert a 4-element byte array (IPv4) to a 32-bit long."
|
||||||
|
^long [^bytes bs]
|
||||||
|
(bit-or (bit-shift-left (bit-and (aget bs 0) 0xFF) 24)
|
||||||
|
(bit-shift-left (bit-and (aget bs 1) 0xFF) 16)
|
||||||
|
(bit-shift-left (bit-and (aget bs 2) 0xFF) 8)
|
||||||
|
(bit-and (aget bs 3) 0xFF)))
|
||||||
|
|
||||||
|
(defn- prefix-mask
|
||||||
|
"Return a 32-bit mask for the given prefix length."
|
||||||
|
^long [^long prefix-len]
|
||||||
|
(if (zero? prefix-len)
|
||||||
|
0
|
||||||
|
(bit-shift-left (unsigned-bit-shift-right 0xFFFFFFFF (- 32 prefix-len)) (- 32 prefix-len))))
|
||||||
|
|
||||||
|
(defn- in-cidr4?
|
||||||
|
"Check if an IPv4 address (as byte array) falls within a CIDR range
|
||||||
|
specified as [a b c d prefix-len]."
|
||||||
|
[^bytes addr [^long a ^long b ^long c ^long d ^long prefix-len]]
|
||||||
|
(let [base (bit-or (bit-shift-left (bit-and a 0xFF) 24)
|
||||||
|
(bit-shift-left (bit-and b 0xFF) 16)
|
||||||
|
(bit-shift-left (bit-and c 0xFF) 8)
|
||||||
|
(bit-and d 0xFF))
|
||||||
|
mask (prefix-mask prefix-len)
|
||||||
|
ip-val (ip4-to-long addr)]
|
||||||
|
(= (bit-and ip-val mask) (bit-and base mask))))
|
||||||
|
|
||||||
|
(defn- parse-cidr*
|
||||||
|
"Parse a CIDR string like '10.0.0.0/8' into [a b c d prefix-len]. Throws on invalid input."
|
||||||
|
[^String cidr]
|
||||||
|
(let [parts (str/split cidr #"/" 2)
|
||||||
|
prefix-len (when (= 2 (count parts))
|
||||||
|
(parse-long (nth parts 1)))]
|
||||||
|
(when-not prefix-len
|
||||||
|
(ex/raise :type :internal
|
||||||
|
:code :invalid-cidr
|
||||||
|
:hint (str "invalid CIDR notation: " cidr)))
|
||||||
|
(let [octets (str/split (first parts) #"\.")]
|
||||||
|
(when (not= 4 (count octets))
|
||||||
|
(ex/raise :type :internal
|
||||||
|
:code :invalid-cidr
|
||||||
|
:hint (str "invalid CIDR notation (expected IPv4): " cidr)))
|
||||||
|
(let [[a b c d] (map parse-long octets)]
|
||||||
|
(when (or (nil? a) (nil? b) (nil? c) (nil? d)
|
||||||
|
(not (<= 0 a 255)) (not (<= 0 b 255))
|
||||||
|
(not (<= 0 c 255)) (not (<= 0 d 255))
|
||||||
|
(not (<= 0 prefix-len 32)))
|
||||||
|
(ex/raise :type :internal
|
||||||
|
:code :invalid-cidr
|
||||||
|
:hint (str "invalid CIDR notation: " cidr)))
|
||||||
|
[a b c d prefix-len]))))
|
||||||
|
|
||||||
|
(defn parse-cidr
|
||||||
|
"Parse a CIDR string like '10.0.0.0/8' into [a b c d prefix-len].
|
||||||
|
Returns nil and logs a warning on invalid input."
|
||||||
|
[^String cidr]
|
||||||
|
(try
|
||||||
|
(parse-cidr* cidr)
|
||||||
|
(catch Exception _
|
||||||
|
(l/warn :hint "ignoring invalid CIDR" :cidr cidr)
|
||||||
|
nil)))
|
||||||
|
|
||||||
|
(defonce ^:dynamic extra-blocked-cidrs
|
||||||
|
(into #{} (keep parse-cidr) (cf/get :ssrf-extra-blocked-cidrs #{})))
|
||||||
|
|
||||||
|
(defn- ipv6-ula?
|
||||||
|
"Check if an IPv6 address is in the Unique Local Address range (fc00::/7)."
|
||||||
|
[^InetAddress addr]
|
||||||
|
(let [bs (.getAddress addr)]
|
||||||
|
(and (>= (alength bs) 16)
|
||||||
|
(= (bit-and (aget bs 0) 0xFE) 0xFC))))
|
||||||
|
|
||||||
|
(defn- ipv4-mapped-loopback?
|
||||||
|
"Check if an IPv4-mapped IPv6 address maps to loopback (::ffff:127.x.x.x)."
|
||||||
|
[^InetAddress addr]
|
||||||
|
(let [bs (.getAddress addr)]
|
||||||
|
(and (= (alength bs) 16)
|
||||||
|
;; Check it's an IPv4-mapped address: ::ffff:x.x.x.x
|
||||||
|
(= (aget bs 10) (byte -1)) ;; 0xFF
|
||||||
|
(= (aget bs 11) (byte -1)) ;; 0xFF
|
||||||
|
;; Check the embedded IPv4 is loopback (127.x.x.x)
|
||||||
|
(= (bit-and (aget bs 12) 0xFF) 127))))
|
||||||
|
|
||||||
|
(defn- blocked-address?
|
||||||
|
"Check if an InetAddress should be blocked. Returns true if blocked."
|
||||||
|
[^InetAddress addr]
|
||||||
|
(or
|
||||||
|
(.isAnyLocalAddress addr) ;; 0.0.0.0 or ::
|
||||||
|
(.isLoopbackAddress addr) ;; 127/8 or ::1
|
||||||
|
(.isLinkLocalAddress addr) ;; 169.254/16 or fe80::/10
|
||||||
|
(.isSiteLocalAddress addr) ;; 10/8, 172.16/12, 192.168/16
|
||||||
|
(.isMulticastAddress addr)
|
||||||
|
|
||||||
|
;; IPv6 ULA (fc00::/7)
|
||||||
|
(ipv6-ula? addr)
|
||||||
|
|
||||||
|
;; IPv4-mapped loopback
|
||||||
|
(ipv4-mapped-loopback? addr)
|
||||||
|
|
||||||
|
;; Cloud metadata IPs (exact match)
|
||||||
|
(contains? cloud-metadata-ips (.getHostAddress addr))
|
||||||
|
|
||||||
|
;; Extra blocked CIDRs (IPv4 only)
|
||||||
|
(let [bs (.getAddress addr)]
|
||||||
|
(if (= (alength bs) 4)
|
||||||
|
(or (some #(in-cidr4? bs %) extra-blocked-ranges)
|
||||||
|
(some #(in-cidr4? bs %) extra-blocked-cidrs))
|
||||||
|
false))))
|
||||||
|
|
||||||
|
(defn resolve-host
|
||||||
|
"Resolve a hostname to all InetAddress objects. Wraps InetAddress/getAllByName
|
||||||
|
so it can be stubbed in tests."
|
||||||
|
[^String hostname]
|
||||||
|
(try
|
||||||
|
(InetAddress/getAllByName hostname)
|
||||||
|
(catch UnknownHostException _
|
||||||
|
nil)))
|
||||||
|
|
||||||
|
(defn validate-uri
|
||||||
|
"Validates `uri-or-string`:
|
||||||
|
- scheme must be http or https,
|
||||||
|
- host must resolve to at least one address, and
|
||||||
|
- **every** resolved address must NOT be in the blocklist
|
||||||
|
(loopback, link-local, site-local, multicast, any-local,
|
||||||
|
cloud-metadata 169.254.169.254, IPv6 ULA fc00::/7, IPv4-mapped
|
||||||
|
IPv6 of any blocked IPv4, plus operator-supplied CIDRs).
|
||||||
|
When the host is an IP literal (decimal/octal/hex/IPv6) it is
|
||||||
|
normalized via `com.google.common.net.InetAddresses` before the
|
||||||
|
check.
|
||||||
|
Hosts in `:ssrf-allowed-hosts` (case-insensitive exact match) bypass
|
||||||
|
the IP check.
|
||||||
|
Throws `ex/raise :type :validation :code :ssrf-blocked-target` with
|
||||||
|
a hint that does NOT echo the resolved IP (avoid info leak)."
|
||||||
|
[uri-or-string]
|
||||||
|
(let [uri (if (instance? URI uri-or-string)
|
||||||
|
uri-or-string
|
||||||
|
(URI. (str uri-or-string)))
|
||||||
|
scheme (.getScheme uri)
|
||||||
|
host (.getHost uri)]
|
||||||
|
|
||||||
|
;; Validate scheme
|
||||||
|
(when (or (nil? scheme)
|
||||||
|
(not (contains? allowed-schemes (str/lower scheme))))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :ssrf-blocked-target
|
||||||
|
:hint "url scheme is not allowed"))
|
||||||
|
|
||||||
|
;; Validate host presence
|
||||||
|
(when (or (nil? host) (str/blank? host))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :ssrf-blocked-target
|
||||||
|
:hint "url host is missing"))
|
||||||
|
|
||||||
|
;; Check allowlist
|
||||||
|
(let [allowed-hosts (cf/get :ssrf-allowed-hosts #{})
|
||||||
|
host-lower (str/lower host)]
|
||||||
|
|
||||||
|
(when-not (contains? allowed-hosts host-lower)
|
||||||
|
;; Normalize the host: if it looks like an IP literal, normalize it
|
||||||
|
;; via Guava to catch decimal/octal/hex encodings
|
||||||
|
(let [normalized (if (InetAddresses/isInetAddress host)
|
||||||
|
(InetAddresses/forString host)
|
||||||
|
nil)
|
||||||
|
host-to-resolve (if normalized
|
||||||
|
(.getHostAddress ^InetAddress normalized)
|
||||||
|
host)
|
||||||
|
addresses (resolve-host host-to-resolve)]
|
||||||
|
|
||||||
|
(when (or (nil? addresses) (zero? (alength addresses)))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :ssrf-blocked-target
|
||||||
|
:hint "url host could not be resolved"))
|
||||||
|
|
||||||
|
;; All-or-nothing: if ANY resolved address is blocked, reject
|
||||||
|
(when (some blocked-address? (seq addresses))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :ssrf-blocked-target
|
||||||
|
:hint "url target is not allowed")))))
|
||||||
|
(str uri)))
|
||||||
|
|
||||||
|
(defn safe-url?
|
||||||
|
"Predicate version of `validate-uri`. Returns `true` if safe."
|
||||||
|
[uri-or-string]
|
||||||
|
(try
|
||||||
|
(validate-uri uri-or-string)
|
||||||
|
true
|
||||||
|
(catch Exception _
|
||||||
|
false)))
|
||||||
55
backend/test/backend_tests/auth_oidc_test.clj
Normal file
55
backend/test/backend_tests/auth_oidc_test.clj
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns backend-tests.auth-oidc-test
|
||||||
|
(:require
|
||||||
|
[app.auth.oidc :as oidc]
|
||||||
|
[clojure.test :as t]))
|
||||||
|
|
||||||
|
(def ^:private oidc-provider
|
||||||
|
{:id "oidc"
|
||||||
|
:type "oidc"})
|
||||||
|
|
||||||
|
(t/deftest parse-attr-path-supports-dot-and-double-underscore
|
||||||
|
(t/is
|
||||||
|
(= [:oidc/resource-access :penpot_roles :roles]
|
||||||
|
(#'oidc/parse-attr-path oidc-provider "resource_access__penpot_roles__roles")))
|
||||||
|
(t/is
|
||||||
|
(= [:oidc/ocs :data :email]
|
||||||
|
(#'oidc/parse-attr-path oidc-provider "ocs.data.email"))))
|
||||||
|
|
||||||
|
(t/deftest process-user-info-supports-dot-notation-nested-attrs
|
||||||
|
(let [provider (assoc oidc-provider
|
||||||
|
:email-attr "ocs.data.email"
|
||||||
|
:name-attr "ocs.data.display-name")
|
||||||
|
info (#'oidc/process-user-info provider
|
||||||
|
{}
|
||||||
|
{:email_verified true
|
||||||
|
:ocs {:data {:email "nextcloud@example.com"
|
||||||
|
:display-name "Nextcloud User"}}})]
|
||||||
|
(t/is (= "nextcloud@example.com" (:email info)))
|
||||||
|
(t/is (= "Nextcloud User" (:fullname info)))
|
||||||
|
(t/is (true? (:email-verified info)))))
|
||||||
|
|
||||||
|
;; The provider's `:user-info-source` value arrives as a string (enforced by
|
||||||
|
;; the malli schema in `app.config` and used as-is by the hard-coded Google /
|
||||||
|
;; GitHub provider maps), so the dispatch must interpret strings — not
|
||||||
|
;; keywords — to actually honour `PENPOT_OIDC_USER_INFO_SOURCE=userinfo`.
|
||||||
|
(t/deftest select-user-info-source-interprets-config-strings
|
||||||
|
(t/testing "explicit string values map to keyword dispatch tokens"
|
||||||
|
(t/is (= :token (#'oidc/select-user-info-source "token")))
|
||||||
|
(t/is (= :userinfo (#'oidc/select-user-info-source "userinfo"))))
|
||||||
|
|
||||||
|
(t/testing "missing or explicit \"auto\" falls back to auto dispatch"
|
||||||
|
(t/is (= :auto (#'oidc/select-user-info-source "auto")))
|
||||||
|
(t/is (= :auto (#'oidc/select-user-info-source nil))))
|
||||||
|
|
||||||
|
(t/testing "unknown values fall back to auto dispatch safely"
|
||||||
|
(t/is (= :auto (#'oidc/select-user-info-source "unknown")))
|
||||||
|
;; Guards against the reverse regression — a stray keyword value must
|
||||||
|
;; not silently slip through as if it were the matching string.
|
||||||
|
(t/is (= :auto (#'oidc/select-user-info-source :token)))
|
||||||
|
(t/is (= :auto (#'oidc/select-user-info-source :userinfo)))))
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user