@synopackageland/templates 0.9.9 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -29
- package/package.json +2 -2
- package/templates/_shared/AGENTS.md +53 -15
- package/templates/native-go/backend/THIRD_PARTY_NOTICES.txt +1 -1
- package/templates/native-go/backend/cmd/app/main.go +15 -1
- package/templates/native-go/backend/cmd/app/main_test.go +33 -0
- package/templates/native-go/backend/go.mod +1 -1
- package/templates/native-go/backend/go.sum +2 -2
- package/templates/native-go/i18n/messages/de.json +4 -0
- package/templates/native-go/i18n/messages/en.json +4 -0
- package/templates/native-go/i18n/messages/es.json +4 -0
- package/templates/native-go/i18n/messages/fr.json +4 -0
- package/templates/native-go/i18n/messages/it.json +4 -0
- package/templates/native-go/i18n/messages/ja.json +4 -0
- package/templates/native-go/i18n/messages/ko.json +4 -0
- package/templates/native-go/i18n/messages/zh-CN.json +4 -0
- package/templates/native-go/i18n/messages/zh-TW.json +4 -0
- package/templates/native-go/ui/app.js +2 -1
- package/templates/native-go-delegate/frontend/test/capability-panels.test.ts +24 -3
- package/templates/native-go-jobs/frontend/test/background-page.test.ts +4 -4
- package/templates/native-go-root-ops/backend/internal/app/executor.go +2 -65
- package/templates/native-go-root-ops/backend/internal/app/executor_test.go +10 -82
- package/templates/native-go-root-ops/frontend/src/ExecutorGate.vue +16 -0
- package/templates/native-go-root-ops/frontend/test/executor-gate.test.ts +60 -0
- package/templates/native-go-vue/README.md +24 -8
- package/templates/native-go-vue/frontend/package-lock.json +9 -9
- package/templates/native-go-vue/frontend/package.json +2 -2
- package/templates/native-go-vue/frontend/src/App.vue +36 -36
- package/templates/native-go-vue/frontend/src/ExecutorGate.vue +10 -0
- package/templates/native-go-vue/frontend/test/apps.test.ts +65 -12
- package/templates/native-go-vue/frontend/test/context.ts +8 -0
- package/templates/native-go-vue/frontend/test/native-controls.test.ts +3 -4
- package/templates/native-go-vue/frontend/test/shell-i18n.test.ts +2 -2
- package/templates/native-node/README.md +153 -0
- package/templates/native-node/backend/app/package.json +4 -0
- package/templates/native-node/backend/app/permissions.json +5 -0
- package/templates/native-node/backend/package-lock.json +59 -0
- package/templates/native-node/backend/package.json +17 -0
- package/templates/native-node/backend/src/delegate.ts +5 -0
- package/templates/native-node/backend/src/jobs.ts +5 -0
- package/templates/native-node/backend/src/main.ts +4 -0
- package/templates/native-node/backend/src/params.ts +11 -0
- package/templates/native-node/backend/src/root-ops.ts +5 -0
- package/templates/native-node/backend/src/routes.ts +97 -0
- package/templates/native-node/backend/src/service.ts +22 -0
- package/templates/native-node/backend/test/routes.test.ts +75 -0
- package/templates/native-node/backend/test/support.ts +67 -0
- package/templates/native-node/backend/tsconfig.build.json +8 -0
- package/templates/native-node/backend/tsconfig.json +18 -0
- package/templates/native-node/dsm-package.yaml +80 -0
- package/templates/native-node/gitignore +4 -0
- package/templates/native-node-delegate/backend/src/delegate.ts +35 -0
- package/templates/native-node-delegate/backend/test/delegate.test.ts +51 -0
- package/templates/native-node-jobs/backend/src/jobs.ts +38 -0
- package/templates/native-node-jobs/backend/test/jobs.test.ts +73 -0
- package/templates/native-node-root-ops/backend/src/root-ops.ts +16 -0
- package/templates/native-node-root-ops/backend/test/root-ops.test.ts +23 -0
- package/templates/native-node-vue/README.md +56 -0
- package/templates/native-node-vue/gitignore +4 -0
- package/templates/native-python/README.md +150 -0
- package/templates/native-python/backend/app/delegate.py +5 -0
- package/templates/native-python/backend/app/jobs.py +5 -0
- package/templates/native-python/backend/app/main.py +5 -0
- package/templates/native-python/backend/app/params.py +10 -0
- package/templates/native-python/backend/app/permissions.json +5 -0
- package/templates/native-python/backend/app/root_ops.py +5 -0
- package/templates/native-python/backend/app/routes.py +107 -0
- package/templates/native-python/backend/tests/support.py +72 -0
- package/templates/native-python/backend/tests/test_routes.py +73 -0
- package/templates/native-python/dsm-package.yaml +77 -0
- package/templates/native-python/gitignore +2 -0
- package/templates/native-python-delegate/backend/app/delegate.py +42 -0
- package/templates/native-python-delegate/backend/tests/test_delegate.py +58 -0
- package/templates/native-python-jobs/backend/app/jobs.py +40 -0
- package/templates/native-python-jobs/backend/tests/test_jobs.py +72 -0
- package/templates/native-python-root-ops/backend/app/root_ops.py +18 -0
- package/templates/native-python-root-ops/backend/tests/test_root_ops.py +34 -0
- package/templates/native-python-vue/README.md +56 -0
- package/templates/native-python-vue/gitignore +3 -0
- package/templates/native-rust/README.md +74 -296
- package/templates/native-rust/backend/Cargo.lock +6 -6
- package/templates/native-rust/backend/Cargo.toml +2 -10
- package/templates/native-rust/backend/src/delegate.rs +6 -0
- package/templates/native-rust/backend/src/jobs.rs +6 -0
- package/templates/native-rust/backend/src/main.rs +12 -0
- package/templates/native-rust/backend/src/root_ops.rs +6 -0
- package/templates/native-rust/backend/src/routes.rs +352 -0
- package/templates/native-rust/backend/src/test_support.rs +91 -0
- package/templates/native-rust/dsm-package.yaml +10 -21
- package/templates/native-rust-delegate/backend/src/delegate.rs +171 -0
- package/templates/native-rust-jobs/backend/src/jobs.rs +240 -0
- package/templates/native-rust-root-ops/backend/src/root_ops.rs +83 -0
- package/templates/native-rust-vue/README.md +35 -34
- package/templates/native-rust/backend/THIRD_PARTY_NOTICES.txt +0 -207
- package/templates/native-rust/backend/src/app/background/mod.rs +0 -424
- package/templates/native-rust/backend/src/app/background/owner.rs +0 -77
- package/templates/native-rust/backend/src/app/background/owner_tests.rs +0 -174
- package/templates/native-rust/backend/src/app/background/schedule.rs +0 -126
- package/templates/native-rust/backend/src/app/background/schedule_tests.rs +0 -108
- package/templates/native-rust/backend/src/app/background/tests.rs +0 -505
- package/templates/native-rust/backend/src/app/background/work.rs +0 -78
- package/templates/native-rust/backend/src/app/background/work_tests.rs +0 -123
- package/templates/native-rust/backend/src/app/background_routes.rs +0 -22
- package/templates/native-rust/backend/src/app/delegate_config.rs +0 -188
- package/templates/native-rust/backend/src/app/delegate_routes.rs +0 -22
- package/templates/native-rust/backend/src/app/identity.rs +0 -56
- package/templates/native-rust/backend/src/app/migrations.rs +0 -79
- package/templates/native-rust/backend/src/app/mod.rs +0 -30
- package/templates/native-rust/backend/src/app/portal.rs +0 -317
- package/templates/native-rust/backend/src/app/root_routes.rs +0 -23
- package/templates/native-rust/backend/src/app/routes.rs +0 -315
- package/templates/native-rust/backend/src/app/session_files.rs +0 -19
- package/templates/native-rust/backend/src/app/shared_folder.rs +0 -383
- package/templates/native-rust/backend/src/app/test_support.rs +0 -202
- package/templates/native-rust/backend/src/app/uninstall.rs +0 -38
- package/templates/native-rust/backend/src/bin/api.rs +0 -72
- package/templates/native-rust/backend/src/bin/background-worker.rs +0 -37
- package/templates/native-rust/backend/src/build_env.rs +0 -155
- package/templates/native-rust/backend/src/lib.rs +0 -6
- package/templates/native-rust/backend/src/permissions.rs +0 -54
- package/templates/native-rust/backend/src/process.rs +0 -91
- package/templates/native-rust/i18n/glossary.json +0 -665
- package/templates/native-rust/i18n/messages/de.json +0 -32
- package/templates/native-rust/i18n/messages/en.json +0 -32
- package/templates/native-rust/i18n/messages/es.json +0 -32
- package/templates/native-rust/i18n/messages/fr.json +0 -32
- package/templates/native-rust/i18n/messages/it.json +0 -32
- package/templates/native-rust/i18n/messages/ja.json +0 -32
- package/templates/native-rust/i18n/messages/ko.json +0 -32
- package/templates/native-rust/i18n/messages/zh-CN.json +0 -32
- package/templates/native-rust/i18n/messages/zh-TW.json +0 -32
- package/templates/native-rust/ui/app.css +0 -45
- package/templates/native-rust/ui/app.js +0 -111
- package/templates/native-rust-delegate/backend/src/app/delegate_routes.rs +0 -92
- package/templates/native-rust-delegate/backend/src/bin/background-worker.rs +0 -52
- package/templates/native-rust-jobs/backend/src/app/background_routes.rs +0 -109
- package/templates/native-rust-root-ops/backend/src/app/root_routes.rs +0 -475
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
//! Recurring copies of an imported job: owners manage their own, an
|
|
2
|
-
//! administrator re-approves them.
|
|
3
|
-
|
|
4
|
-
use serde::Deserialize;
|
|
5
|
-
use serde_json::{Value, json};
|
|
6
|
-
use syno_pkg_land_sdk::api::{self, Caller};
|
|
7
|
-
use syno_pkg_land_sdk::background::{Access, ScheduleRequest};
|
|
8
|
-
use syno_pkg_land_sdk::ctx::Context;
|
|
9
|
-
use syno_pkg_land_sdk::http::Request;
|
|
10
|
-
use syno_pkg_land_sdk::{BoxError, jsonx};
|
|
11
|
-
|
|
12
|
-
use super::{BackgroundApi, background_error, decode_id, identity_unavailable};
|
|
13
|
-
use crate::app::routes::decode_params;
|
|
14
|
-
|
|
15
|
-
impl BackgroundApi {
|
|
16
|
-
pub(super) fn schedules(
|
|
17
|
-
&self,
|
|
18
|
-
ctx: &Context,
|
|
19
|
-
_: &Caller,
|
|
20
|
-
_: &Request,
|
|
21
|
-
access: &Access,
|
|
22
|
-
params: &[u8],
|
|
23
|
-
) -> Result<Value, BoxError> {
|
|
24
|
-
decode_params::<jsonx::Empty>(params)?;
|
|
25
|
-
let list = self
|
|
26
|
-
.store
|
|
27
|
-
.schedules(ctx, access)
|
|
28
|
-
.map_err(background_error)?;
|
|
29
|
-
Ok(json!({"schedules": list}))
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
pub(super) fn create_schedule(
|
|
33
|
-
&self,
|
|
34
|
-
ctx: &Context,
|
|
35
|
-
_: &Caller,
|
|
36
|
-
_: &Request,
|
|
37
|
-
access: &Access,
|
|
38
|
-
params: &[u8],
|
|
39
|
-
) -> Result<Value, BoxError> {
|
|
40
|
-
#[derive(Default, Deserialize)]
|
|
41
|
-
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
|
42
|
-
struct Params {
|
|
43
|
-
#[serde(default)]
|
|
44
|
-
key: String,
|
|
45
|
-
#[serde(default)]
|
|
46
|
-
job_id: String,
|
|
47
|
-
#[serde(default)]
|
|
48
|
-
interval_seconds: i64,
|
|
49
|
-
#[serde(default)]
|
|
50
|
-
consent: bool,
|
|
51
|
-
}
|
|
52
|
-
let params: Params = decode_params(params)?;
|
|
53
|
-
if !access.owner.valid() {
|
|
54
|
-
return Err(identity_unavailable().into());
|
|
55
|
-
}
|
|
56
|
-
let request = ScheduleRequest {
|
|
57
|
-
key: params.key,
|
|
58
|
-
job_id: params.job_id,
|
|
59
|
-
interval_seconds: params.interval_seconds,
|
|
60
|
-
consent: params.consent,
|
|
61
|
-
};
|
|
62
|
-
let (schedule, duplicate) = self
|
|
63
|
-
.store
|
|
64
|
-
.create_schedule(ctx, &request, access)
|
|
65
|
-
.map_err(background_error)?;
|
|
66
|
-
Ok(json!({"schedule": schedule, "duplicate": duplicate}))
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
pub(super) fn disable_schedule(
|
|
70
|
-
&self,
|
|
71
|
-
ctx: &Context,
|
|
72
|
-
_: &Caller,
|
|
73
|
-
_: &Request,
|
|
74
|
-
access: &Access,
|
|
75
|
-
params: &[u8],
|
|
76
|
-
) -> Result<Value, BoxError> {
|
|
77
|
-
let id = decode_id(params)?;
|
|
78
|
-
let schedule = self
|
|
79
|
-
.store
|
|
80
|
-
.set_schedule(ctx, &id, false, access)
|
|
81
|
-
.map_err(background_error)?;
|
|
82
|
-
Ok(json!({"schedule": schedule}))
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
pub(super) fn enable_schedule(
|
|
86
|
-
&self,
|
|
87
|
-
ctx: &Context,
|
|
88
|
-
_: &Caller,
|
|
89
|
-
_: &Request,
|
|
90
|
-
access: &Access,
|
|
91
|
-
params: &[u8],
|
|
92
|
-
) -> Result<Value, BoxError> {
|
|
93
|
-
#[derive(Default, Deserialize)]
|
|
94
|
-
#[serde(deny_unknown_fields)]
|
|
95
|
-
struct Params {
|
|
96
|
-
#[serde(default)]
|
|
97
|
-
id: String,
|
|
98
|
-
#[serde(default)]
|
|
99
|
-
consent: bool,
|
|
100
|
-
}
|
|
101
|
-
let params = match decode_params::<Params>(params) {
|
|
102
|
-
Ok(p) if p.consent => p,
|
|
103
|
-
_ => return Err(api::Error::bad_request("explicit consent is required").into()),
|
|
104
|
-
};
|
|
105
|
-
let schedule = self
|
|
106
|
-
.store
|
|
107
|
-
.set_schedule(ctx, ¶ms.id, true, access)
|
|
108
|
-
.map_err(background_error)?;
|
|
109
|
-
Ok(json!({"schedule": schedule}))
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
pub(super) fn delete_schedule(
|
|
113
|
-
&self,
|
|
114
|
-
ctx: &Context,
|
|
115
|
-
_: &Caller,
|
|
116
|
-
_: &Request,
|
|
117
|
-
access: &Access,
|
|
118
|
-
params: &[u8],
|
|
119
|
-
) -> Result<Value, BoxError> {
|
|
120
|
-
let id = decode_id(params)?;
|
|
121
|
-
self.store
|
|
122
|
-
.delete_schedule(ctx, &id, access)
|
|
123
|
-
.map_err(background_error)?;
|
|
124
|
-
Ok(json!({"deleted": true}))
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
use syno_pkg_land_sdk::background::{JobResult, Outcome, State};
|
|
2
|
-
use syno_pkg_land_sdk::ctx::Context;
|
|
3
|
-
|
|
4
|
-
use super::tests::{Env, data, id_params};
|
|
5
|
-
use crate::app::test_support::{Stub, alice, bob, carol};
|
|
6
|
-
|
|
7
|
-
fn ordinary_env() -> Env {
|
|
8
|
-
let env = Env::new();
|
|
9
|
-
env.set_uid(|name| match name {
|
|
10
|
-
"alice" => "1024".into(),
|
|
11
|
-
"bob" => "1025".into(),
|
|
12
|
-
"carol" => "1026".into(),
|
|
13
|
-
_ => String::new(),
|
|
14
|
-
});
|
|
15
|
-
env
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
fn submit_and_finish(env: &Env, auth: &Stub) -> String {
|
|
19
|
-
let (code, out) = env.call(
|
|
20
|
-
auth,
|
|
21
|
-
"bg.jobs.submit",
|
|
22
|
-
r#"{"key":"copy","folder":"/share","relative":"a.txt"}"#,
|
|
23
|
-
);
|
|
24
|
-
assert_eq!(code, "", "{out}");
|
|
25
|
-
let id: String = data(&out)["job"]["id"].as_str().unwrap().into();
|
|
26
|
-
let ctx = Context::background();
|
|
27
|
-
env.store.claim(&ctx).unwrap();
|
|
28
|
-
env.store
|
|
29
|
-
.finish(
|
|
30
|
-
&ctx,
|
|
31
|
-
&id,
|
|
32
|
-
Outcome {
|
|
33
|
-
state: State::Succeeded,
|
|
34
|
-
result: Some(JobResult {
|
|
35
|
-
bytes: 5,
|
|
36
|
-
..JobResult::default()
|
|
37
|
-
}),
|
|
38
|
-
..Outcome::default()
|
|
39
|
-
},
|
|
40
|
-
)
|
|
41
|
-
.unwrap();
|
|
42
|
-
id
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
fn schedule_count(env: &Env, auth: &Stub) -> usize {
|
|
46
|
-
let (_, out) = env.call(auth, "bg.schedules.list", "{}");
|
|
47
|
-
data(&out)["schedules"].as_array().unwrap().len()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
#[test]
|
|
51
|
-
fn schedule_routes_consent_owner_and_admin() {
|
|
52
|
-
let env = ordinary_env();
|
|
53
|
-
let id = submit_and_finish(&env, &bob());
|
|
54
|
-
let params = format!(r#"{{"key":"s","jobId":"{id}","intervalSeconds":3600,"consent":true}}"#);
|
|
55
|
-
assert_eq!(
|
|
56
|
-
env.call(&carol(), "bg.schedules.create", ¶ms).0,
|
|
57
|
-
"not_found"
|
|
58
|
-
);
|
|
59
|
-
for bad in [
|
|
60
|
-
format!(r#"{{"key":"s","jobId":"{id}","intervalSeconds":3600}}"#),
|
|
61
|
-
format!(
|
|
62
|
-
r#"{{"key":"s","jobId":"{id}","intervalSeconds":3600,"consent":true,"owner":"carol"}}"#
|
|
63
|
-
),
|
|
64
|
-
] {
|
|
65
|
-
assert_eq!(
|
|
66
|
-
env.call(&bob(), "bg.schedules.create", &bad).0,
|
|
67
|
-
"bad_request",
|
|
68
|
-
"{bad}"
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
let (code, out) = env.call(&bob(), "bg.schedules.create", ¶ms);
|
|
72
|
-
assert_eq!(code, "", "create: {out}");
|
|
73
|
-
let sid = data(&out)["schedule"]["id"].as_str().unwrap().to_string();
|
|
74
|
-
assert_eq!(schedule_count(&env, &carol()), 0, "list leak");
|
|
75
|
-
assert_eq!(schedule_count(&env, &alice()), 1, "admin list");
|
|
76
|
-
for method in ["bg.schedules.disable", "bg.schedules.delete"] {
|
|
77
|
-
assert_eq!(
|
|
78
|
-
env.call(&carol(), method, &id_params(&sid)).0,
|
|
79
|
-
"not_found",
|
|
80
|
-
"{method}"
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
let enable = format!(r#"{{"id":"{sid}","consent":true}}"#);
|
|
84
|
-
assert_eq!(
|
|
85
|
-
env.call(&bob(), "bg.schedules.enable", &enable).0,
|
|
86
|
-
"admin_required"
|
|
87
|
-
);
|
|
88
|
-
assert_eq!(
|
|
89
|
-
env.call(&alice(), "bg.schedules.disable", &id_params(&sid))
|
|
90
|
-
.0,
|
|
91
|
-
""
|
|
92
|
-
);
|
|
93
|
-
assert_eq!(
|
|
94
|
-
env.call(&alice(), "bg.schedules.enable", &id_params(&sid))
|
|
95
|
-
.0,
|
|
96
|
-
"bad_request"
|
|
97
|
-
);
|
|
98
|
-
assert_eq!(env.call(&alice(), "bg.schedules.enable", &enable).0, "");
|
|
99
|
-
assert_eq!(
|
|
100
|
-
env.call(&bob(), "bg.schedules.delete", &id_params(&sid)).0,
|
|
101
|
-
""
|
|
102
|
-
);
|
|
103
|
-
assert_eq!(
|
|
104
|
-
env.files.calls(),
|
|
105
|
-
1,
|
|
106
|
-
"no scheduling route calls File Station, uses a root grant or stores a session"
|
|
107
|
-
);
|
|
108
|
-
}
|