Skip to content

Commit 1c04825

Browse files
Update Cozy integration doc (#3905)
1 parent a9b2d6f commit 1c04825

File tree

3 files changed

+224
-3
lines changed

3 files changed

+224
-3
lines changed

docs/adr/0061-cozy-integration-set-up.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,46 @@ cozy-stack instances add tmail.localhost:8080 --passphrase cozy --apps home,stor
5757
1. On the cozy-twakemail side
5858
- Clone `https://github.com/cozy/cozy-twakemail`
5959
- `yarn install`
60-
- In `src/components/AppLayout.jsx`, replace `flag('mail.embedded-app-url')` with `http://localhost:2023`
6160
- `yarn build`
6261
- `cozy-stack serve --appdir tmail:build/ --disable-csp`
62+
- Open another terminal while cozy-stack is running
63+
- `cozy-stack apps install dataproxy --domain tmail.localhost:8080`
64+
- `cozy-stack feature flags --domain tmail.localhost:8080 '{"cozy.search.enabled": true}'`
65+
- `cozy-stack feature flags --domain tmail.localhost:8080 '{"mail.embedded-app-url": "http://localhost:2023"}'`
6366

6467
2. On the tmail side
65-
- Config tmail to run on basic auth
68+
- Apply patchs/cozy-dev-config.patch
69+
- Edit session url in jmap-dart-client to /jmap/session
6670
- isInsideCozy will be `false` if run on localhost, so in cozy_config_web.dart, return true on isInsideCozy
6771
- in `env.file`, COZY_INTEGRATION=true
6872
- `flutter run -d chrome --web-port 2023 --web-browser-flag "--disable-web-security" --profile`
6973

7074
3. Access Cozy
7175
- tmail cozy: http://tmail.localhost:8080/
72-
- The password is `cozy`
76+
- The password is `cozy`
77+
78+
### Run Cozy locally with modified Cozy libs
79+
If there is a need of modifying Cozy libs
80+
1. On cozy-libs side
81+
- Clone `https://github.com/cozy/cozy-libs`
82+
- `yarn install`
83+
- `yarn build`
84+
For example, if you want to use locally modified `cozy-external-bridge`
85+
- `cd packages/cozy-external-bridge`
86+
- `yarn link`
87+
- `yarn build`
88+
89+
2. On cozy-twakemail side
90+
- Look for rlink.sh file in /scripts, move the file to ~/Downloads
91+
- `mv ~/Downloads/rlink.sh ~/bin/rlink`
92+
- `chmod +x ~/bin/rlink`
93+
- Reset the terminal
94+
- Repeat part 1 of `Run Cozy locally`
95+
- While cozy-stack is running, open another terminal in the same directory
96+
- `rlink {library-you-modified-and-linked}` for example `rlink cozy-external-bridge`
97+
- While rlink is running, run `yarn build`
98+
99+
3. On tmail side
100+
- Repeat part 2 of `Run Cozy locally`
101+
102+
Note: You can leave the cozy-stack and rlink running if you plan to further modify Cozy libs. After each modification, run `yarn build` in cozy-libs packages side then run `yarn build` in cozy-twakemail side, then refresh the browser.

patchs/cozy-dev-config.patch

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
diff --git a/cozy/lib/cozy_config_manager/cozy_config_manager_web.dart b/cozy/lib/cozy_config_manager/cozy_config_manager_web.dart
2+
index 03da73f1e..b518b19ef 100644
3+
--- a/cozy/lib/cozy_config_manager/cozy_config_manager_web.dart
4+
+++ b/cozy/lib/cozy_config_manager/cozy_config_manager_web.dart
5+
@@ -14,6 +14,7 @@ class CozyConfigManager {
6+
}
7+
8+
Future<bool> get isInsideCozy async {
9+
+ return true;
10+
return _isInsideCozy ??= await _checkCozyEnvironment();
11+
}
12+
13+
diff --git a/env.file b/env.file
14+
index 77b662611..2c60bb1a1 100644
15+
--- a/env.file
16+
+++ b/env.file
17+
@@ -1,6 +1,6 @@
18+
-SERVER_URL=http://localhost/
19+
-DOMAIN_REDIRECT_URL=http://localhost:3000
20+
-WEB_OIDC_CLIENT_ID=teammail-web
21+
+SERVER_URL=https://jmap.lin-saas.dev
22+
+DOMAIN_REDIRECT_URL=http://localhost:2023
23+
+WEB_OIDC_CLIENT_ID=teammail-web-dev
24+
OIDC_SCOPES=openid,profile,email,offline_access
25+
APP_GRID_AVAILABLE=supported
26+
FCM_AVAILABLE=supported
27+
@@ -8,4 +8,4 @@ IOS_FCM=supported
28+
FORWARD_WARNING_MESSAGE=
29+
PLATFORM=other
30+
WS_ECHO_PING=
31+
-COZY_INTEGRATION=
32+
\ No newline at end of file
33+
+COZY_INTEGRATION=true
34+
\ No newline at end of file
35+
diff --git a/lib/features/home/presentation/extensions/handle_web_finger_to_get_token_extension.dart b/lib/features/home/presentation/extensions/handle_web_finger_to_get_token_extension.dart
36+
index a51b1a9d2..7d8734e0c 100644
37+
--- a/lib/features/home/presentation/extensions/handle_web_finger_to_get_token_extension.dart
38+
+++ b/lib/features/home/presentation/extensions/handle_web_finger_to_get_token_extension.dart
39+
@@ -2,11 +2,11 @@ import 'package:core/presentation/state/failure.dart';
40+
import 'package:core/utils/platform_info.dart';
41+
import 'package:dartz/dartz.dart';
42+
import 'package:model/oidc/oidc_configuration.dart';
43+
-import 'package:model/oidc/request/oidc_request.dart';
44+
import 'package:model/oidc/response/oidc_response.dart';
45+
import 'package:tmail_ui_user/features/home/presentation/home_controller.dart';
46+
+import 'package:tmail_ui_user/features/login/data/network/oidc_error.dart';
47+
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
48+
-import 'package:tmail_ui_user/features/login/domain/model/base_url_oidc_response.dart';
49+
+import 'package:tmail_ui_user/features/login/domain/state/check_oidc_is_available_state.dart';
50+
import 'package:tmail_ui_user/features/login/domain/state/get_oidc_configuration_state.dart';
51+
import 'package:tmail_ui_user/features/login/domain/state/get_token_oidc_state.dart';
52+
import 'package:tmail_ui_user/main/utils/app_config.dart';
53+
@@ -21,9 +21,7 @@ extension HandleWebFingerToGetTokenExtension on HomeController {
54+
if (baseUri == null) {
55+
goToLogin();
56+
} else {
57+
- consumeState(
58+
- checkOIDCIsAvailableInteractor.execute(OIDCRequest.fromUri(baseUri)),
59+
- );
60+
+ handleFailureViewState(CheckOIDCIsAvailableFailure(CanNotFoundOIDCLinks()));
61+
}
62+
}
63+
64+
@@ -58,7 +56,7 @@ extension HandleWebFingerToGetTokenExtension on HomeController {
65+
}
66+
67+
void tryGetOIDCConfigurationFromBaseUri(Uri baseUri) {
68+
- getOIDCConfiguration(BaseUrlOidcResponse(baseUri));
69+
+ handleFailureViewState(GetOIDCConfigurationFromBaseUrlFailure(null));
70+
}
71+
72+
bool isGetTokenOIDCFailure(Failure? failure) {
73+
diff --git a/lib/features/login/presentation/extensions/handle_openid_configuration.dart b/lib/features/login/presentation/extensions/handle_openid_configuration.dart
74+
index d8b35fd1b..f1c4ca3c4 100644
75+
--- a/lib/features/login/presentation/extensions/handle_openid_configuration.dart
76+
+++ b/lib/features/login/presentation/extensions/handle_openid_configuration.dart
77+
@@ -1,11 +1,11 @@
78+
79+
-import 'package:tmail_ui_user/features/login/domain/model/base_url_oidc_response.dart';
80+
+import 'package:tmail_ui_user/features/login/domain/state/get_oidc_configuration_state.dart';
81+
import 'package:tmail_ui_user/features/login/presentation/login_controller.dart';
82+
83+
extension HandleOpenidConfiguration on LoginController {
84+
85+
void tryGetOIDCConfigurationFromBaseUrl(Uri baseUri) {
86+
- getOIDCConfiguration(BaseUrlOidcResponse(baseUri));
87+
+ handleFailureViewState(GetOIDCConfigurationFromBaseUrlFailure(null));
88+
}
89+
90+
void handleGetOIDCConfigurationFromBaseUrlFailure() {
91+
diff --git a/lib/features/login/presentation/login_controller.dart b/lib/features/login/presentation/login_controller.dart
92+
index ec41a9e7a..15b4864c6 100644
93+
--- a/lib/features/login/presentation/login_controller.dart
94+
+++ b/lib/features/login/presentation/login_controller.dart
95+
@@ -15,7 +15,6 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
96+
import 'package:jmap_dart_client/jmap/core/user_name.dart';
97+
import 'package:model/account/password.dart';
98+
import 'package:model/oidc/oidc_configuration.dart';
99+
-import 'package:model/oidc/request/oidc_request.dart';
100+
import 'package:model/oidc/response/oidc_response.dart';
101+
import 'package:tmail_ui_user/features/base/reloadable/reloadable_controller.dart';
102+
import 'package:tmail_ui_user/features/home/domain/state/auto_sign_in_via_deep_link_state.dart';
103+
@@ -340,16 +339,7 @@ class LoginController extends ReloadableController {
104+
}
105+
106+
void _checkOIDCIsAvailable() {
107+
- if (_currentBaseUrl == null) {
108+
- dispatchState(Left(CheckOIDCIsAvailableFailure(CanNotFoundBaseUrl())));
109+
- } else {
110+
- consumeState(_checkOIDCIsAvailableInteractor.execute(
111+
- OIDCRequest(
112+
- baseUrl: _currentBaseUrl!.toString(),
113+
- resourceUrl: _currentBaseUrl!.origin
114+
- )
115+
- ));
116+
- }
117+
+ handleFailureViewState(CheckOIDCIsAvailableFailure(CanNotFoundOIDCLinks()));
118+
}
119+
120+
void handleBackButtonAction(BuildContext context) {

scripts/rlink.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
# rlink is useful when you are working in packages used in other packages/apps. Normally you
4+
# would use yarn link but it can cause problems since node_modules are resolved inside the
5+
# linked directory instead of the host directory. Here, the "link" is done the hard way with
6+
# nodemon and rsync, ensuring that the node_modules/<package> corresponds to the linked package.
7+
# Location of the linked packages is found by using the directory where yarn stores its symbolic
8+
# links.
9+
#
10+
# ## Installation
11+
#
12+
# Assuming ~/bin is in your PATH
13+
# $ wget https://gist.githubusercontent.com/ptbrowne/add609bdcf4396d32072acc4674fff23/raw -O ~/bin/rlink
14+
# $ chmod +x ~/bin/rlink
15+
#
16+
# ## Usage
17+
#
18+
# `rlink cozy-client`
19+
20+
21+
realpath=$(which realpath)
22+
if [[ $realpath == "" ]]; then
23+
realpath=$(which grealpath)
24+
fi
25+
if [[ $realpath == "" ]]; then
26+
echo "You must have realpath (or grealpath) installed. `brew install coreutils` on mac osx."
27+
exit 1
28+
fi
29+
30+
which nodemon > /dev/null
31+
if [[ $? != 0 ]]; then
32+
echo "You must have nodemon installed globally"
33+
exit 1
34+
fi
35+
36+
set -e
37+
38+
package=$1
39+
40+
if [[ $package == "" ]]; then
41+
echo "Usage: rlink <package>"
42+
exit 1
43+
fi
44+
45+
set -u
46+
47+
package_link_dir=$($realpath ~/.config/yarn/link/$package)
48+
49+
50+
if [[ -e $package_link_dir ]]; then
51+
echo "$package is available in yarn links, resolved path is $package_link_dir"
52+
else
53+
echo "$package is not available in yarn links, please \`yarn link\` there first."
54+
exit 1
55+
fi
56+
57+
package_node_module_dir=$(pwd)/node_modules/$package
58+
59+
if [[ -e $package_node_module_dir ]]; then
60+
echo "$package is installed node_modules, resolved path is $package_node_module_dir"
61+
else
62+
echo "$package is not installed node_modules. Bailing out, please install the package first."
63+
exit 1
64+
fi
65+
66+
extensions="js,json,md,jsx,kt,java,m,mm,h,swift"
67+
68+
echo "Will monitor extensions $extensions"
69+
cmd="rsync -aP $package_link_dir/ --exclude .git --exclude node_modules $package_node_module_dir/"
70+
71+
nodemon -w $package_link_dir -x "$cmd" -e $extensions

0 commit comments

Comments
 (0)