Compare commits

...

74 Commits

Author SHA1 Message Date
d509ca1397 Remove RTE 2023-04-13 15:22:28 +02:00
1002f0c0e5 Working on detect type 2023-04-07 18:07:12 +02:00
04f0620ba4 Styled heading select 2023-04-07 14:01:46 +02:00
9cc34f16bb improve wrap into tag, improving text styles 2023-04-06 16:02:05 +02:00
63302fef71 Fix wrap in header 2023-04-05 16:20:30 +02:00
fc3052630a handle close Epic 2023-04-05 15:03:00 +02:00
a8ff5101be BitQue text 2023-04-04 17:14:31 +02:00
d78139c799 Fix avatar 2023-04-04 13:52:42 +02:00
35cf6ebaf9 Add cloud storage, fix upload and move to trunk 2023-04-03 16:08:53 +02:00
2aea60ecf2 Replace rusoto 2023-04-02 22:41:40 +02:00
5f1d9c1f4d Replace rusoto 2023-04-02 22:34:30 +02:00
23628d6f9b Replace rusoto 2023-04-02 22:34:12 +02:00
a192a1584e Upgrade and organize 2023-04-01 22:31:57 +02:00
cad12e7a76 Upgrade and organize 2023-03-31 23:25:20 +02:00
dependabot[bot]
427d386d39
Bump bumpalo from 3.7.1 to 3.12.0 (#7)
Bumps [bumpalo](https://github.com/fitzgen/bumpalo) from 3.7.1 to 3.12.0.
- [Release notes](https://github.com/fitzgen/bumpalo/releases)
- [Changelog](https://github.com/fitzgen/bumpalo/blob/main/CHANGELOG.md)
- [Commits](https://github.com/fitzgen/bumpalo/compare/3.7.1...3.12.0)

---
updated-dependencies:
- dependency-name: bumpalo
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-21 11:20:02 +01:00
8b1cbbc40c Reduce memory usage and prevent HashMap overflow 2021-10-17 13:06:36 +02:00
9cca951274 Reduce memory usage and prevent HashMap overflow 2021-10-17 13:05:23 +02:00
97f2023596 Reduce memory usage and prevent HashMap overflow 2021-10-16 11:16:58 +02:00
e390ce62b5 More modal solution 2021-10-16 10:53:01 +02:00
Adrian Woźniak
36bbaefb23
Fix email content type. Style lists 2021-10-15 15:58:15 +02:00
Adrian Woźniak
d49c92cd53
Reduce model memory usage 2021-10-15 14:40:51 +02:00
Adrian Woźniak
5abcfb99a6
Reduce issues memory usage 2021-10-15 13:36:24 +02:00
fd4e04647e Fix some compile errors 2021-10-14 22:42:42 +02:00
Adrian Woźniak
dc977891de
Broken start of issue cleanup 2021-10-14 17:03:36 +02:00
Adrian Woźniak
47674c1448
Refactor 2021-10-13 16:02:07 +02:00
Adrian Woźniak
e807dae81e
Refactor 2021-10-13 16:01:44 +02:00
a4c7f916be Reduce allocations 2021-10-12 22:45:37 +02:00
4e5f2101df Extract events from create issue 2021-10-12 22:39:05 +02:00
08375b5ee2 Extract events from project page 2021-10-12 22:25:11 +02:00
Adrian Woźniak
285ca9e97e
Fix blur 2021-10-12 17:54:55 +02:00
Adrian Woźniak
97325d72ef
Reduce memory footprint, fix alloc vec error 2021-10-11 17:08:00 +02:00
Adrian Woźniak
8478f5d112
Reduce memory footprint, fix alloc vec error 2021-10-11 16:56:15 +02:00
d8855bdfec TMP disable edit description. Reduce memory footprint 2021-10-10 17:17:44 +02:00
f22944664e Prevent spam all issues 2021-10-09 14:35:39 +02:00
Adrian Woźniak
f0c275120a
Fix drop create modal, add deploy info 2021-10-08 23:42:15 +02:00
Adrian Woźniak
fce3bb727f
Fix build release 2021-10-08 16:31:34 +02:00
Adrian Woźniak
d18e9ff6d6
Fix logo 2021-10-08 16:18:25 +02:00
Adrian Woźniak
1de72c59f5
Fix sign in 2021-10-08 15:39:38 +02:00
Adrian Woźniak
9ba3f112e6
Fix update avatar 2021-10-08 15:35:16 +02:00
Adrian Woźniak
980d263c87
Fix syntax highlight 2021-10-08 15:21:18 +02:00
Adrian Woźniak
25d5991ffb
Fix upload avatar 2021-10-08 15:21:18 +02:00
Adrian Woźniak
09e941ff8a
Fix small issues 2021-10-08 15:21:17 +02:00
Adrian Woźniak
a13678d98f
X 2021-10-05 14:34:20 +02:00
29fe2f8562 Refactor messages 2021-08-13 23:03:52 +02:00
Adrian Woźniak
02145de39f
Refactor messages 2021-08-13 17:11:25 +02:00
Adrian Woźniak
2d79c91087
Unify dependencies 2021-08-13 14:01:00 +02:00
Adrian Woźniak
4351483b2e
Unify dependencies 2021-08-13 13:11:51 +02:00
Adrian Woźniak
dc5164f779
Unify dependencies 2021-08-13 12:56:11 +02:00
Adrian Woźniak
477a888a12
Unify dependencies 2021-08-13 12:43:08 +02:00
Adrian Woźniak
7047a309d4
Unify dependencies 2021-08-13 12:42:29 +02:00
Adrian Woźniak
c8730485d0
Preallocations 2021-08-12 16:10:30 +02:00
146be0184b Fix redundant rebuild Project page 2021-04-30 23:08:39 +02:00
10bda7bb9c Some validations 2021-04-29 23:36:05 +02:00
a1d7e14984 Some issue information, better look, issues count 2021-04-29 23:21:48 +02:00
Adrian Woźniak
8ae4cc22ba Add epics page 2021-04-29 17:10:02 +02:00
Adrian Woźniak
c06c936118 Add simple JQL implementation 2021-04-29 15:09:41 +02:00
Adrian Woźniak
83ee058297 Clippy 2021-04-29 14:55:22 +02:00
Adrian Woźniak
98f9204fbd Add simple JQL implementation 2021-04-29 14:47:38 +02:00
f824694a05 Assignee field display 2021-04-28 23:46:42 +02:00
Adrian Woźniak
e6778db137 Add issues and filters 2021-04-28 16:57:56 +02:00
Adrian Woźniak
3ee08dea54 Upgrade and fix slow autoresize
Fix global handler

Fix initial content, fix settings status, restore partially working rte

Fmt

Implement keyup for rte

Save editor type, switch in mixed mode

Fix initial state for switch between editors

New logger, add handle multiple editors

Nicer editor switcher, fix change user mode in project settings

Epics starts and ends at. Fix DateTime Input month name
2021-04-27 23:57:15 +02:00
Adrian Woźniak
9994ab8165 Stop propagation 2021-04-20 14:25:24 +02:00
Adrian Woźniak
e5280618aa Small refactor 2021-04-19 22:31:18 +02:00
Adrian Woźniak
1117e878a8 Finish 3rd refactor step 2021-04-19 15:09:10 +02:00
Adrian Woźniak
1b5ac3c9c3 Simmplify 2021-04-19 10:21:20 +02:00
e3e55acd54 Rewrite some components to use render method 2021-04-18 23:24:20 +02:00
2d7ce5762a Rewrite some components to use render method 2021-04-18 15:37:45 +02:00
682066b561 Rewrite some components render 2021-04-18 13:55:42 +02:00
Adrian Woźniak
a5594f6844 Update packages 2021-04-16 16:52:16 +02:00
Adrian Woźniak
041078b7c9 Remove last in-use builder 2021-04-16 16:46:50 +02:00
Adrian Woźniak
2b40f9fd91 Better fmt, remove select builder 2021-04-16 15:20:25 +02:00
Adrian Woźniak
e6ef4d6b0e Remove some builders 2021-04-15 22:32:05 +02:00
520d2400be Optimizations 2021-04-11 22:10:18 +02:00
82971adb48 Optimizations 2021-04-11 22:09:42 +02:00
500 changed files with 22169 additions and 17090 deletions

View File

@ -82,9 +82,9 @@ fabric.properties
/tmp/
/jirs-client/target/
/jirs-client/tmp/
/jirs-client/build/
crates/web/target/
crates/web/tmp/
crates/web/build/
/jirs-server/target/
/jirs-server/tmp/
crates/bitque-server/target/
crates/bitque-server/tmp/

12
.env
View File

@ -1,7 +1,7 @@
DEBUG=true
RUST_LOG=debug
JIRS_CLIENT_PORT=7000
JIRS_CLIENT_BIND=0.0.0.0
DATABASE_URL=postgres://postgres@localhost:5432/jirs
JIRS_SERVER_PORT=5000
JIRS_SERVER_BIND=0.0.0.0
RUST_LOG=info
BITQUE_CLIENT_PORT=80
BITQUE_CLIENT_BIND=bitque.lvh.me
DATABASE_URL=postgres://postgres@localhost:5432/bitque
BITQUE_SERVER_PORT=5000
BITQUE_SERVER_BIND=0.0.0.0

33
.gitignore vendored
View File

@ -1,25 +1,12 @@
/target
mail.toml
mail.test.toml
web.toml
web.test.toml
db.toml
db.test.toml
fs.toml
fs.test.toml
highlight.toml
highlight.test.toml
pkg
jirs-client/pkg
jirs-client/tmp
jirs-client/build
/crates/bitque-client/pkg
/crates/bitque-client/tmp
/crates/bitque-client/build
/crates/bitque-server/target
/crates/bitque-cli/target
/crates/bitque-bat/bat
/crates/highlight/bitque-highlight/build
/crates/bitque-client/src/location.rs
/uploads
/config
tmp
jirs-server/target
jirs-cli/target
jirs-bat/bat
highlight/jirs-highlight/build
uploads
config

View File

@ -8,7 +8,7 @@ Use nothing other than standard rust tests.
## Submitting changes
Please send a [GitHub Pull Request to jirs](https://github.com/Eraden/hirs/pull/new/master) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). When you send a pull request, we will love you forever if you include RSpec examples. We can always use more test coverage. Please follow our coding conventions (below) and make sure all of your commits are atomic (one feature per commit).
Please send a [GitHub Pull Request to bitque](https://github.com/Eraden/hirs/pull/new/master) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). When you send a pull request, we will love you forever if you include RSpec examples. We can always use more test coverage. Please follow our coding conventions (below) and make sure all of your commits are atomic (one feature per commit).
Always write a clear log message for your commits. One-line messages are fine for small changes, but bigger changes should look like this:
@ -23,7 +23,7 @@ Start reading our code and you'll get the hang of it. We optimize for readabilit
* We ALWAYS run `cargo fmt` before commit
* We ALWAYS run `cargo clippy` before commit
* We avoid local variables and prefer functions in theirs place
* We prefer rust over JavaScript
* We prefer Rust over JavaScript
* We avoid putting logic in view
* This is open source software. Consider the people who will read your code, and make it look nice for them. It's sort of like driving a car: Perhaps you love doing donuts when you're alone, but with passengers the goal is to make the ride as smooth as possible.

4386
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +1,51 @@
#[package]
#name = "jirs"
#name = "bitque"
#version = "0.1.0"
#authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
#edition = "2018"
#description = "JIRS (Simplified JIRA in Rust)"
#repository = "https://gitlab.com/adrian.wozniak/jirs"
#repository = "https://gitlab.com/adrian.wozniak/bitque"
#license = "MPL-2.0"
#license-file = "./LICENSE"
[workspace]
members = [
"./jirs-cli",
"./jirs-server",
"./shared/jirs-config",
"./shared/jirs-data",
"./derive/derive_enum_iter",
"./derive/derive_enum_primitive",
"./derive/derive_enum_sql",
"./derive/derive_db_execute",
"./actors/highlight-actor",
"./actors/database-actor",
"./actors/web-actor",
"./actors/websocket-actor",
"./actors/mail-actor",
"./actors/amazon-actor",
"./actors/filesystem-actor",
"./crates/bitque-cli",
"./crates/bitque-server",
"./crates/bitque-config",
"./crates/bitque-data",
"./crates/derive_enum_iter",
"./crates/derive_enum_primitive",
"./crates/derive_enum_sql",
"./crates/derive_db_execute",
"./crates/highlight-actor",
"./crates/database-actor",
"./crates/web-actor",
"./crates/websocket-actor",
"./crates/mail-actor",
"./crates/cloud-storage-actor",
"./crates/filesystem-actor",
# Client
"./jirs-client"
"./crates/web"
]
exclude = [
"crates/bitque-cli",
"crates/web",
]
[workspace.dependencies]
bitque-cli = { path = "./crates/bitque-cli" }
bitque-server = { path = "./crates/bitque-server" }
bitque-config = { path = "./crates/bitque-config" }
bitque-data = { path = "./crates/bitque-data" }
derive_enum_iter = { path = "./crates/derive_enum_iter" }
derive_enum_primitive = { path = "./crates/derive_enum_primitive" }
derive_enum_sql = { path = "./crates/derive_enum_sql" }
derive_db_execute = { path = "./crates/derive_db_execute" }
highlight-actor = { path = "./crates/highlight-actor" }
database-actor = { path = "./crates/database-actor" }
web-actor = { path = "./crates/web-actor" }
websocket-actor = { path = "./crates/websocket-actor" }
mail-actor = { path = "./crates/mail-actor" }
cloud-storage-actor = { path = "./crates/cloud-storage-actor" }
filesystem-actor = { path = "./crates/filesystem-actor" }

View File

@ -1,15 +0,0 @@
FROM ubuntu:18.04
WORKDIR /app/
RUN apt-get update && apt-get install -y curl git openssl libpq-dev gcc openssl1.0 make cmake
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly -y
RUN . $HOME/.cargo/env && \
rustup toolchain install nightly && rustup default nightly
RUN ls -al /app
CMD . $HOME/.cargo/env && \
cd ./jirs-server && \
rm -Rf ./target/debug/jirs_server && \
cargo build --bin jirs_server --release --no-default-features --features local-storage && \
cp /app/target/release/jirs_server /app/build/

View File

@ -1,11 +1,13 @@
# A simplified Jira clone built with seed.rs and actix
![JIRS](https://raw.githubusercontent.com/Eraden/jirs/master/jirs-client/static/project-icon.svg)
![JIRS](https://raw.githubusercontent.com/Eraden/bitque/master/web/static/project-icon.svg)
Server: [![builds.sr.ht status](https://builds.sr.ht/~tsumanu/jirs/server.yml.svg)](https://builds.sr.ht/~tsumanu/jirs/server.yml?)
Client: [![builds.sr.ht status](https://builds.sr.ht/~tsumanu/jirs/client.yml.svg)](https://builds.sr.ht/~tsumanu/jirs/client.yml?)
Server: [![builds.sr.ht status](https://builds.sr.ht/~tsumanu/bitque/server.yml.svg)](https://builds.sr.ht/~tsumanu/bitque/server.yml?)
Client: [![builds.sr.ht status](https://builds.sr.ht/~tsumanu/bitque/client.yml.svg)](https://builds.sr.ht/~tsumanu/bitque/client.yml?)
https://git.sr.ht/~tsumanu/jirs
Main repo: https://git.sr.ht/~tsumanu/bitque
Demo: https://bitque.ita-prog.pl
## Features
@ -58,14 +60,14 @@ https://git.sr.ht/~tsumanu/jirs
* [X] Add Epic
* [X] Edit Epic
* [X] Delete Epic
* [ ] Epic `starts` and `ends` date
* [X] Epic `starts` and `ends` date
* [X] Grouping by Epic
* [ ] Basic Rich Text Editor
* [X] Basic Rich Text Editor
* [ ] Insert Code in Rich Text Editor
* [X] Code syntax
* [ ] Personal settings to choose MDE (Markdown Editor) or RTE
* [ ] Issues and filters view
* [ ] Issues and filters working filters
* [X] Personal settings to choose MDE (Markdown Editor) or RTE
* [X] Issues and filters view
* [X] Issues and filters working filters
## How to run it
@ -99,7 +101,7 @@ This requires additional configuration.
```toml
[filesystem]
store_path = "/var/jirs/uploads"
store_path = "/var/bitque/uploads"
client_path = "/img"
```
@ -126,7 +128,7 @@ region_name = "eu-central-1"
```toml
# db.toml
concurrency = 2
database_url = "postgres://postgres@localhost:5432/jirs"
database_url = "postgres://postgres@localhost:5432/bitque"
```
#### Mail Service
@ -139,15 +141,15 @@ concurrency = 2
user = "apikey"
pass = "YOUR-TOKEN"
host = "smtp.sendgrid.net"
from = "contact@jirs.pl"
from = "contact@bitque.pl"
```
### Local variables
Within `jirs` directory place `.env` file with following content
Within `bitque` directory place `.env` file with following content
```dotenv
DATABASE_URL=postgres://postgres@localhost:5432/jirs
DATABASE_URL=postgres://postgres@localhost:5432/bitque
RUST_LOG=actix_web=info,diesel=info
JIRS_CLIENT_PORT=7000
JIRS_CLIENT_BIND=0.0.0.0
@ -168,24 +170,23 @@ Requirements:
```bash
cargo install diesel_cli --no-default-features --features postgres
export DATABASE_URL=postgres://postgres@localhost/jirs
export DATABASE_URL=postgres://postgres@localhost/bitque
diesel setup
diesel migration run
cargo run --bin jirs_server
cargo run --bin bitque_server
```
### Frontend
```bash
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
cd jirs_client
yarn
./scripts/prod.sh
cd bitque_client
./web/scripts/prod.sh
```
```bash
sudo ln -s ./jirs.nginx /etc/nginx/sites-enabled/
sudo ln -s ./bitque.nginx /etc/nginx/sites-enabled/
sudo nginx -s reload
```
@ -203,10 +204,10 @@ Custom element glued with WASM
* `lang` does not have callback and it's used only on `connectedCallback`
```html
<jirs-code-view lang="Rust" file-path="/some/path.rs">
<bitque-code-view lang="Rust" file-path="/some/path.rs">
struct Foo {
}
</jirs-code-view>
</bitque-code-view>
```
### Supported languages
@ -348,3 +349,11 @@ struct Foo {
* lrc
* reStructuredText
* srt
## Utils
```bash
cargo install --locked --git https://github.com/dcchut/cargo-derivefmt --bin cargo-derivefmt
cargo install carto-sort
cargo install cargo-llvm-cov
```

View File

@ -1,51 +0,0 @@
[package]
name = "amazon-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "amazon_actor"
path = "./src/lib.rs"
[dependencies]
serde = "*"
actix = { version = "0.10.0" }
actix-service = { version = "*" }
actix-rt = "1"
actix-web-actors = "*"
bytes = { version = "0.5.6" }
futures = { version = "0.3.8" }
openssl-sys = { version = "*", features = ["vendored"] }
libc = { version = "0.2.0", default-features = false }
log = "0.4"
pretty_env_logger = "0.4"
env_logger = "0.7"
uuid = { version = "0.8.1", features = ["serde", "v4", "v5"] }
[dependencies.jirs-config]
path = "../../shared/jirs-config"
features = ["mail", "web", "local-storage"]
# Amazon S3
[dependencies.rusoto_s3]
version = "0.45.0"
[dependencies.rusoto_core]
version = "0.45.0"
[dependencies.rusoto_signature]
version = "0.45.0"
[dependencies.tokio]
version = "0.2.23"
features = ["tcp", "time", "rt-core", "fs"]

View File

@ -1,87 +0,0 @@
use {
actix,
rusoto_s3::{PutObjectRequest, S3Client, S3},
};
#[derive(Debug)]
pub enum AmazonError {
UploadFailed,
}
pub struct AmazonExecutor;
impl Default for AmazonExecutor {
fn default() -> Self {
Self {}
}
}
impl actix::Actor for AmazonExecutor {
type Context = actix::SyncContext<Self>;
}
#[derive(actix::Message)]
#[rtype(result = "Result<String, AmazonError>")]
pub struct S3PutObject {
pub source: tokio::sync::broadcast::Receiver<bytes::Bytes>,
pub file_name: String,
}
impl actix::Handler<S3PutObject> for AmazonExecutor {
type Result = Result<String, AmazonError>;
fn handle(&mut self, msg: S3PutObject, _ctx: &mut Self::Context) -> Self::Result {
let S3PutObject {
mut source,
file_name,
} = msg;
jirs_config::amazon::config().set_variables();
tokio::runtime::Runtime::new()
.expect("Failed to start amazon agent")
.block_on(async {
let s3 = jirs_config::amazon::config();
log::debug!("{:?}", s3);
// TODO: Unable to upload as stream because there is no size_hint
// use futures::stream::*;
// let stream = source
// .into_stream()
// .map_err(|_e| std::io::Error::from_raw_os_error(1));
let mut v: Vec<u8> = vec![];
use bytes::Buf;
while let Ok(b) = source.recv().await {
v.extend_from_slice(b.bytes())
}
let client = S3Client::new(s3.region());
let put_object = PutObjectRequest {
bucket: s3.bucket.clone(),
key: file_name.clone(),
// body: Some(rusoto_signature::ByteStream::new(stream)),
body: Some(v.into()),
..Default::default()
};
let id = match client.put_object(put_object).await {
Ok(obj) => obj,
Err(e) => {
log::error!("{}", e);
return Err(AmazonError::UploadFailed);
}
};
log::debug!("{:?}", id);
Ok(aws_s3_url(file_name.as_str()))
})
}
}
fn aws_s3_url(key: &str) -> String {
let config = jirs_config::amazon::config();
format!(
"https://{bucket}.s3.{region}.amazonaws.com/{key}",
bucket = config.bucket,
region = config.region_name,
key = key
)
}

View File

@ -1,62 +0,0 @@
[package]
name = "database-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "database_actor"
path = "./src/lib.rs"
[dependencies]
serde = "*"
bincode = "*"
toml = { version = "*" }
actix = { version = "0.10.0" }
actix-web = { version = "*" }
futures = { version = "0.3.8" }
openssl-sys = { version = "*", features = ["vendored"] }
libc = { version = "0.2.0", default-features = false }
pq-sys = { version = ">=0.3.0, <0.5.0" }
r2d2 = { version = ">= 0.8, < 0.9" }
dotenv = { version = "*" }
byteorder = "1.0"
chrono = { version = "0.4", features = ["serde"] }
time = { version = "0.1" }
url = { version = "2.1.0" }
percent-encoding = { version = "2.1.0" }
uuid = { version = "0.8.1", features = ["serde", "v4", "v5"] }
ipnetwork = { version = ">=0.12.2, <0.17.0" }
num-bigint = { version = ">=0.1.41, <0.3" }
num-traits = { version = "0.2" }
num-integer = { version = "0.1.32" }
bigdecimal = { version = ">= 0.0.10, <= 0.1.0" }
bitflags = { version = "1.0" }
log = "0.4"
pretty_env_logger = "0.4"
env_logger = "0.7"
[dependencies.jirs-config]
path = "../../shared/jirs-config"
features = ["database"]
[dependencies.jirs-data]
path = "../../shared/jirs-data"
features = ["backend"]
[dependencies.derive_db_execute]
path = "../../derive/derive_db_execute"
[dependencies.diesel]
version = "1.4.5"
features = ["unstable", "postgres", "numeric", "extras", "uuidv07"]

View File

@ -1,171 +0,0 @@
use {
crate::{
db_create, db_delete, db_find, db_load, db_pool, db_update,
tokens::CreateBindToken,
users::{LookupUser, Register},
DbExecutor, DbPooledConn, InvitationError,
},
actix::{Handler, Message},
diesel::prelude::*,
jirs_data::{
EmailString, Invitation, InvitationId, InvitationState, InvitationToken, ProjectId, Token,
User, UserId, UserRole, UsernameString,
},
};
db_find! {
FindByBindToken,
msg => invitations => invitations.filter(bind_token.eq(msg.token)),
Invitation,
token => InvitationToken
}
db_load! {
ListInvitation,
msg => invitations => invitations
.filter(invited_by_id.eq(msg.user_id))
.filter(state.ne(InvitationState::Accepted))
.order_by(state.asc())
.then_order_by(updated_at.desc()),
Invitation,
user_id => UserId
}
db_create! {
CreateInvitation,
msg => invitations => diesel::insert_into(invitations).values((
name.eq(msg.name),
email.eq(msg.email),
state.eq(InvitationState::Sent),
project_id.eq(msg.project_id),
invited_by_id.eq(msg.user_id),
role.eq(msg.role),
)),
Invitation,
user_id => UserId,
project_id => ProjectId,
email => EmailString,
name => UsernameString,
role => UserRole
}
db_delete! {
DeleteInvitation,
msg => invitations => diesel::delete(invitations).filter(id.eq(msg.id)),
Invitation,
id => InvitationId
}
db_update! {
UpdateInvitationState,
msg => invitations => diesel::update(invitations)
.set((
state.eq(msg.state),
updated_at.eq(chrono::Utc::now().naive_utc()),
))
.filter(id.eq(msg.id)),
Invitation,
id => InvitationId,
state => InvitationState
}
pub struct RevokeInvitation {
pub id: InvitationId,
}
impl Message for RevokeInvitation {
type Result = Result<(), crate::DatabaseError>;
}
impl Handler<RevokeInvitation> for DbExecutor {
type Result = Result<(), crate::DatabaseError>;
fn handle(&mut self, msg: RevokeInvitation, _ctx: &mut Self::Context) -> Self::Result {
let conn = db_pool!(self);
UpdateInvitationState {
id: msg.id,
state: InvitationState::Revoked,
}
.execute(conn)?;
Ok(())
}
}
pub struct AcceptInvitation {
pub invitation_token: InvitationToken,
}
impl AcceptInvitation {
pub fn execute(self, conn: &DbPooledConn) -> Result<Token, crate::DatabaseError> {
crate::Guard::new(conn)?.run::<Token, _>(|_guard| {
let invitation = crate::invitations::FindByBindToken {
token: self.invitation_token,
}
.execute(conn)?;
if invitation.state == InvitationState::Revoked {
return Err(crate::DatabaseError::Invitation(
InvitationError::InvitationRevoked,
));
}
crate::invitations::UpdateInvitationState {
id: invitation.id,
state: InvitationState::Accepted,
}
.execute(conn)?;
UpdateInvitationState {
id: invitation.id,
state: InvitationState::Accepted,
}
.execute(conn)?;
match {
Register {
name: invitation.name.clone(),
email: invitation.email.clone(),
project_id: Some(invitation.project_id),
role: UserRole::User,
}
.execute(conn)
} {
Ok(_) => (),
Err(crate::DatabaseError::User(crate::UserError::InvalidPair(..))) => (),
Err(e) => return Err(e),
};
let user: User = LookupUser {
name: invitation.name.clone(),
email: invitation.email.clone(),
}
.execute(conn)?;
CreateBindToken { user_id: user.id }.execute(conn)?;
crate::user_projects::CreateUserProject {
user_id: user.id,
project_id: invitation.project_id,
is_current: false,
is_default: false,
role: invitation.role,
}
.execute(conn)?;
crate::tokens::FindUserId { user_id: user.id }.execute(conn)
})
}
}
impl Message for AcceptInvitation {
type Result = Result<Token, crate::DatabaseError>;
}
impl Handler<AcceptInvitation> for DbExecutor {
type Result = Result<Token, crate::DatabaseError>;
fn handle(&mut self, msg: AcceptInvitation, _ctx: &mut Self::Context) -> Self::Result {
let conn = db_pool!(self);
msg.execute(conn)
}
}

View File

@ -1,109 +0,0 @@
#![recursion_limit = "256"]
#[macro_use]
extern crate diesel;
pub use errors::*;
use {
actix::{Actor, SyncContext},
diesel::pg::PgConnection,
diesel::r2d2::{self, ConnectionManager},
};
pub mod authorize_user;
pub mod comments;
pub mod epics;
pub mod errors;
pub mod invitations;
pub mod issue_assignees;
pub mod issue_statuses;
pub mod issues;
pub mod messages;
pub mod models;
pub mod prelude;
pub mod projects;
pub mod schema;
pub mod tokens;
pub mod user_projects;
pub mod users;
pub type DbPool = r2d2::Pool<ConnectionManager<PgConnection>>;
pub type DbPooledConn = r2d2::PooledConnection<ConnectionManager<PgConnection>>;
pub struct DbExecutor {
pub pool: DbPool,
pub config: jirs_config::database::Configuration,
}
impl Actor for DbExecutor {
type Context = SyncContext<Self>;
}
impl Default for DbExecutor {
fn default() -> Self {
Self {
pool: build_pool(),
config: jirs_config::database::Configuration::read(),
}
}
}
pub fn build_pool() -> DbPool {
dotenv::dotenv().ok();
let config = jirs_config::database::Configuration::read();
let manager = ConnectionManager::<PgConnection>::new(config.database_url);
r2d2::Pool::builder()
.max_size(config.concurrency as u32)
.build(manager)
.unwrap_or_else(|e| panic!("Failed to create pool. {}", e))
}
pub trait SyncQuery {
type Result;
fn handle(&self, pool: &DbPool) -> Self::Result;
}
pub struct Guard<'l> {
conn: &'l crate::DbPooledConn,
tm: &'l diesel::connection::AnsiTransactionManager,
}
impl<'l> Guard<'l> {
pub fn new(conn: &'l DbPooledConn) -> Result<Self, crate::DatabaseError> {
use diesel::{connection::TransactionManager, prelude::*};
let tm = conn.transaction_manager();
tm.begin_transaction(conn).map_err(|e| {
log::error!("{:?}", e);
crate::DatabaseError::DatabaseConnectionLost
})?;
Ok(Self { conn, tm })
}
pub fn run<R, F: FnOnce(&Guard) -> Result<R, crate::DatabaseError>>(
&self,
f: F,
) -> Result<R, crate::DatabaseError> {
use diesel::connection::TransactionManager;
let r = f(self);
match r {
Ok(r) => {
self.tm.commit_transaction(self.conn).map_err(|e| {
log::error!("{:?}", e);
crate::DatabaseError::DatabaseConnectionLost
})?;
Ok(r)
}
Err(e) => {
log::error!("{:?}", e);
self.tm.rollback_transaction(self.conn).map_err(|e| {
log::error!("{:?}", e);
crate::DatabaseError::DatabaseConnectionLost
})?;
Err(e)
}
}
}
}

View File

@ -1,699 +0,0 @@
#![allow(unused_imports, dead_code)]
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `comments` table.
///
/// (Automatically generated by Diesel.)
comments (id) {
/// The `id` column of the `comments` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `body` column of the `comments` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
body -> Text,
/// The `user_id` column of the `comments` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
user_id -> Int4,
/// The `issue_id` column of the `comments` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
issue_id -> Int4,
/// The `created_at` column of the `comments` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `comments` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `epics` table.
///
/// (Automatically generated by Diesel.)
epics (id) {
/// The `id` column of the `epics` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `name` column of the `epics` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
name -> Text,
/// The `user_id` column of the `epics` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
user_id -> Int4,
/// The `project_id` column of the `epics` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
project_id -> Int4,
/// The `created_at` column of the `epics` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `epics` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
/// The `starts_at` column of the `epics` table.
///
/// Its SQL type is `Nullable<Timestamp>`.
///
/// (Automatically generated by Diesel.)
starts_at -> Nullable<Timestamp>,
/// The `ends_at` column of the `epics` table.
///
/// Its SQL type is `Nullable<Timestamp>`.
///
/// (Automatically generated by Diesel.)
ends_at -> Nullable<Timestamp>,
/// The `description` column of the `epics` table.
///
/// Its SQL type is `Nullable<Text>`.
///
/// (Automatically generated by Diesel.)
description -> Nullable<Text>,
/// The `description_html` column of the `epics` table.
///
/// Its SQL type is `Nullable<Text>`.
///
/// (Automatically generated by Diesel.)
description_html -> Nullable<Text>,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `invitations` table.
///
/// (Automatically generated by Diesel.)
invitations (id) {
/// The `id` column of the `invitations` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `name` column of the `invitations` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
name -> Text,
/// The `email` column of the `invitations` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
email -> Text,
/// The `state` column of the `invitations` table.
///
/// Its SQL type is `InvitationStateType`.
///
/// (Automatically generated by Diesel.)
state -> InvitationStateType,
/// The `project_id` column of the `invitations` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
project_id -> Int4,
/// The `invited_by_id` column of the `invitations` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
invited_by_id -> Int4,
/// The `created_at` column of the `invitations` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `invitations` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
/// The `bind_token` column of the `invitations` table.
///
/// Its SQL type is `Uuid`.
///
/// (Automatically generated by Diesel.)
bind_token -> Uuid,
/// The `role` column of the `invitations` table.
///
/// Its SQL type is `UserRoleType`.
///
/// (Automatically generated by Diesel.)
role -> UserRoleType,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `issue_assignees` table.
///
/// (Automatically generated by Diesel.)
issue_assignees (id) {
/// The `id` column of the `issue_assignees` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `issue_id` column of the `issue_assignees` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
issue_id -> Int4,
/// The `user_id` column of the `issue_assignees` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
user_id -> Int4,
/// The `created_at` column of the `issue_assignees` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `issue_assignees` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `issue_statuses` table.
///
/// (Automatically generated by Diesel.)
issue_statuses (id) {
/// The `id` column of the `issue_statuses` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `name` column of the `issue_statuses` table.
///
/// Its SQL type is `Varchar`.
///
/// (Automatically generated by Diesel.)
name -> Varchar,
/// The `position` column of the `issue_statuses` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
position -> Int4,
/// The `project_id` column of the `issue_statuses` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
project_id -> Int4,
/// The `created_at` column of the `issue_statuses` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `issue_statuses` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `issues` table.
///
/// (Automatically generated by Diesel.)
issues (id) {
/// The `id` column of the `issues` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `title` column of the `issues` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
title -> Text,
/// The `issue_type` column of the `issues` table.
///
/// Its SQL type is `IssueTypeType`.
///
/// (Automatically generated by Diesel.)
issue_type -> IssueTypeType,
/// The `priority` column of the `issues` table.
///
/// Its SQL type is `IssuePriorityType`.
///
/// (Automatically generated by Diesel.)
priority -> IssuePriorityType,
/// The `list_position` column of the `issues` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
list_position -> Int4,
/// The `description` column of the `issues` table.
///
/// Its SQL type is `Nullable<Text>`.
///
/// (Automatically generated by Diesel.)
description -> Nullable<Text>,
/// The `description_text` column of the `issues` table.
///
/// Its SQL type is `Nullable<Text>`.
///
/// (Automatically generated by Diesel.)
description_text -> Nullable<Text>,
/// The `estimate` column of the `issues` table.
///
/// Its SQL type is `Nullable<Int4>`.
///
/// (Automatically generated by Diesel.)
estimate -> Nullable<Int4>,
/// The `time_spent` column of the `issues` table.
///
/// Its SQL type is `Nullable<Int4>`.
///
/// (Automatically generated by Diesel.)
time_spent -> Nullable<Int4>,
/// The `time_remaining` column of the `issues` table.
///
/// Its SQL type is `Nullable<Int4>`.
///
/// (Automatically generated by Diesel.)
time_remaining -> Nullable<Int4>,
/// The `reporter_id` column of the `issues` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
reporter_id -> Int4,
/// The `project_id` column of the `issues` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
project_id -> Int4,
/// The `created_at` column of the `issues` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `issues` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
/// The `issue_status_id` column of the `issues` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
issue_status_id -> Int4,
/// The `epic_id` column of the `issues` table.
///
/// Its SQL type is `Nullable<Int4>`.
///
/// (Automatically generated by Diesel.)
epic_id -> Nullable<Int4>,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `messages` table.
///
/// (Automatically generated by Diesel.)
messages (id) {
/// The `id` column of the `messages` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `receiver_id` column of the `messages` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
receiver_id -> Int4,
/// The `sender_id` column of the `messages` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
sender_id -> Int4,
/// The `summary` column of the `messages` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
summary -> Text,
/// The `description` column of the `messages` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
description -> Text,
/// The `message_type` column of the `messages` table.
///
/// Its SQL type is `MessageTypeType`.
///
/// (Automatically generated by Diesel.)
message_type -> MessageTypeType,
/// The `hyper_link` column of the `messages` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
hyper_link -> Text,
/// The `created_at` column of the `messages` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `messages` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `projects` table.
///
/// (Automatically generated by Diesel.)
projects (id) {
/// The `id` column of the `projects` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `name` column of the `projects` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
name -> Text,
/// The `url` column of the `projects` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
url -> Text,
/// The `description` column of the `projects` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
description -> Text,
/// The `category` column of the `projects` table.
///
/// Its SQL type is `ProjectCategoryType`.
///
/// (Automatically generated by Diesel.)
category -> ProjectCategoryType,
/// The `created_at` column of the `projects` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `projects` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
/// The `time_tracking` column of the `projects` table.
///
/// Its SQL type is `TimeTrackingType`.
///
/// (Automatically generated by Diesel.)
time_tracking -> TimeTrackingType,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `tokens` table.
///
/// (Automatically generated by Diesel.)
tokens (id) {
/// The `id` column of the `tokens` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `user_id` column of the `tokens` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
user_id -> Int4,
/// The `access_token` column of the `tokens` table.
///
/// Its SQL type is `Uuid`.
///
/// (Automatically generated by Diesel.)
access_token -> Uuid,
/// The `refresh_token` column of the `tokens` table.
///
/// Its SQL type is `Uuid`.
///
/// (Automatically generated by Diesel.)
refresh_token -> Uuid,
/// The `created_at` column of the `tokens` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `tokens` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
/// The `bind_token` column of the `tokens` table.
///
/// Its SQL type is `Nullable<Uuid>`.
///
/// (Automatically generated by Diesel.)
bind_token -> Nullable<Uuid>,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `user_projects` table.
///
/// (Automatically generated by Diesel.)
user_projects (id) {
/// The `id` column of the `user_projects` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `user_id` column of the `user_projects` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
user_id -> Int4,
/// The `project_id` column of the `user_projects` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
project_id -> Int4,
/// The `is_default` column of the `user_projects` table.
///
/// Its SQL type is `Bool`.
///
/// (Automatically generated by Diesel.)
is_default -> Bool,
/// The `is_current` column of the `user_projects` table.
///
/// Its SQL type is `Bool`.
///
/// (Automatically generated by Diesel.)
is_current -> Bool,
/// The `role` column of the `user_projects` table.
///
/// Its SQL type is `UserRoleType`.
///
/// (Automatically generated by Diesel.)
role -> UserRoleType,
/// The `created_at` column of the `user_projects` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `user_projects` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
}
}
table! {
use diesel::sql_types::*;
use jirs_data::*;
/// Representation of the `users` table.
///
/// (Automatically generated by Diesel.)
users (id) {
/// The `id` column of the `users` table.
///
/// Its SQL type is `Int4`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
/// The `name` column of the `users` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
name -> Text,
/// The `email` column of the `users` table.
///
/// Its SQL type is `Text`.
///
/// (Automatically generated by Diesel.)
email -> Text,
/// The `avatar_url` column of the `users` table.
///
/// Its SQL type is `Nullable<Text>`.
///
/// (Automatically generated by Diesel.)
avatar_url -> Nullable<Text>,
/// The `created_at` column of the `users` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
created_at -> Timestamp,
/// The `updated_at` column of the `users` table.
///
/// Its SQL type is `Timestamp`.
///
/// (Automatically generated by Diesel.)
updated_at -> Timestamp,
}
}
joinable!(comments -> issues (issue_id));
joinable!(comments -> users (user_id));
joinable!(epics -> projects (project_id));
joinable!(epics -> users (user_id));
joinable!(invitations -> projects (project_id));
joinable!(invitations -> users (invited_by_id));
joinable!(issue_assignees -> issues (issue_id));
joinable!(issue_assignees -> users (user_id));
joinable!(issue_statuses -> projects (project_id));
joinable!(issues -> epics (epic_id));
joinable!(issues -> issue_statuses (issue_status_id));
joinable!(issues -> projects (project_id));
joinable!(issues -> users (reporter_id));
joinable!(tokens -> users (user_id));
joinable!(user_projects -> projects (project_id));
joinable!(user_projects -> users (user_id));
allow_tables_to_appear_in_same_query!(
comments,
epics,
invitations,
issue_assignees,
issue_statuses,
issues,
messages,
projects,
tokens,
user_projects,
users,
);

View File

@ -1,36 +0,0 @@
[package]
name = "filesystem-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "filesystem_actor"
path = "./src/lib.rs"
[dependencies]
actix = { version = "0.10.0" }
futures = { version = "0.3.8" }
log = "0.4"
pretty_env_logger = "0.4"
env_logger = "0.7"
bytes = { version = "0.5.6" }
# Local storage
[dependencies.actix-files]
version = "*"
[dependencies.jirs-config]
path = "../../shared/jirs-config"
features = ["local-storage"]
[dependencies.tokio]
version = "0.2.23"
features = ["dns"]

View File

@ -1,37 +0,0 @@
[package]
name = "highlight-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "highlight_actor"
path = "./src/lib.rs"
[dependencies]
serde = "*"
bincode = "*"
toml = { version = "*" }
simsearch = { version = "0.2" }
actix = { version = "0.10.0" }
flate2 = { version = "*" }
syntect = { version = "*" }
lazy_static = { version = "*" }
log = "0.4"
pretty_env_logger = "0.4"
env_logger = "0.7"
[dependencies.jirs-config]
path = "../../shared/jirs-config"
features = ["hi"]
[dependencies.jirs-data]
path = "../../shared/jirs-data"
features = ["backend"]

View File

@ -1,25 +0,0 @@
use {
bincode::{deserialize_from, Result},
flate2::bufread::ZlibDecoder,
serde::de::DeserializeOwned,
std::io::BufRead,
};
fn from_reader<T: DeserializeOwned, R: BufRead>(input: R) -> Result<T> {
let mut decoder = ZlibDecoder::new(input);
deserialize_from(&mut decoder)
}
fn from_binary<T: DeserializeOwned>(v: &[u8]) -> T {
from_reader(v).unwrap()
}
#[inline(always)]
pub fn integrated_syntaxset() -> syntect::parsing::SyntaxSet {
from_binary(include_bytes!("./syntaxes.bin"))
}
#[inline(always)]
pub fn integrated_themeset() -> syntect::highlighting::ThemeSet {
from_binary(include_bytes!("./themes.bin"))
}

View File

@ -1,60 +0,0 @@
use {
crate::MailExecutor,
actix::{Handler, Message},
uuid::Uuid,
};
#[derive(Debug)]
pub struct Invite {
pub bind_token: Uuid,
pub email: String,
pub inviter_name: String,
}
impl Message for Invite {
type Result = Result<(), String>;
}
impl Handler<Invite> for MailExecutor {
type Result = Result<(), String>;
fn handle(&mut self, msg: Invite, _ctx: &mut Self::Context) -> Self::Result {
use lettre::Transport;
let transport = &mut self.transport;
let from = self.config.from.as_str();
let addr = jirs_config::web::Configuration::read().full_addr();
let html = format!(
r#"
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"></head>
<body>
<h1>You have been invited to project by {inviter_name}!</h1>
<p>
</p>
<p>
Please click this link: <a href="{addr}/invite?token={bind_token}">{addr}/invite?token={bind_token}</a>
</p>
</body>
</html>
"#,
bind_token = msg.bind_token,
inviter_name = msg.inviter_name,
addr = addr,
);
let email = lettre_email::Email::builder()
.from(from)
.to(msg.email.as_str())
.html(html.as_str())
.subject("Invitation to JIRS project")
.build()
.map_err(|_| "Email is not valid".to_string())?;
transport
.send(email.into())
.map(|_| ())
.map_err(|e| format!("Mailer: {}", e))
}
}

View File

@ -1,47 +0,0 @@
use actix::{Actor, SyncContext};
pub mod invite;
pub mod welcome;
pub type MailTransport = lettre::SmtpTransport;
pub struct MailExecutor {
pub transport: MailTransport,
pub config: jirs_config::mail::Configuration,
}
impl Actor for MailExecutor {
type Context = SyncContext<Self>;
}
impl Default for MailExecutor {
fn default() -> Self {
let config = jirs_config::mail::Configuration::read();
Self {
transport: mail_transport(&config),
config,
}
}
}
fn mail_client(config: &jirs_config::mail::Configuration) -> lettre::SmtpClient {
let jirs_config::mail::Configuration {
user: mail_user,
pass: mail_pass,
host: mail_host,
..
} = &config;
lettre::SmtpClient::new_simple(mail_host)
.expect("Failed to init SMTP client")
.credentials(lettre::smtp::authentication::Credentials::new(
mail_user.clone(),
mail_pass.clone(),
))
.connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited)
.smtp_utf8(true)
}
fn mail_transport(config: &jirs_config::mail::Configuration) -> MailTransport {
mail_client(config).transport()
}

View File

@ -1,59 +0,0 @@
use {
crate::MailExecutor,
actix::{Handler, Message},
uuid::Uuid,
};
#[derive(Debug)]
pub struct Welcome {
pub bind_token: Uuid,
pub email: String,
}
impl Message for Welcome {
type Result = Result<(), String>;
}
impl Handler<Welcome> for MailExecutor {
type Result = Result<(), String>;
fn handle(&mut self, msg: Welcome, _ctx: &mut Self::Context) -> Self::Result {
use lettre::Transport;
let transport = &mut self.transport;
let from = self.config.from.as_str();
let html = format!(
r#"
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"></head>
<body>
<h1>Welcome in JIRS!</h1>
<p>
</p>
<p>
Please copy this code to sign-in single use token field: <pre><code>{bind_token}</code</pre>
</p>
<p>
Notice: This token is single use and will be removed from system once you use it.
</p>
</body>
</html>
"#,
bind_token = msg.bind_token,
);
let email = lettre_email::Email::builder()
.from(from)
.to(msg.email.as_str())
.html(html.as_str())
.subject("Welcome to JIRS")
.build()
.map_err(|_| "Email is not valid".to_string())?;
transport
.send(email.into())
.map(|_| ())
.map_err(|e| format!("Mailer: {}", e))
}
}

View File

@ -1,72 +0,0 @@
[package]
name = "web-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "web_actor"
path = "./src/lib.rs"
[features]
local-storage = ["filesystem-actor"]
aws-s3 = ["amazon-actor"]
default = ["local-storage", "aws-s3"]
[dependencies]
serde = "*"
bincode = "*"
toml = { version = "*" }
actix = { version = "0.10.0" }
actix-web = { version = "*" }
actix-cors = { version = "*" }
actix-service = { version = "*" }
actix-rt = "1"
actix-web-actors = "*"
actix-multipart = "*"
bytes = { version = "0.5.6" }
futures = { version = "0.3.8" }
openssl-sys = { version = "*", features = ["vendored"] }
libc = { version = "0.2.0", default-features = false }
log = "0.4"
pretty_env_logger = "0.4"
env_logger = "0.7"
uuid = { version = "0.8.1", features = ["serde", "v4", "v5"] }
[dependencies.jirs-config]
path = "../../shared/jirs-config"
features = ["mail", "web", "local-storage"]
[dependencies.jirs-data]
path = "../../shared/jirs-data"
features = ["backend"]
[dependencies.database-actor]
path = "../database-actor"
[dependencies.mail-actor]
path = "../mail-actor"
[dependencies.websocket-actor]
path = "../websocket-actor"
[dependencies.filesystem-actor]
path = "../filesystem-actor"
optional = true
[dependencies.amazon-actor]
path = "../amazon-actor"
optional = true
[dependencies.tokio]
version = "0.2.23"
features = ["dns"]

View File

@ -1,129 +0,0 @@
use std::io::Write;
#[cfg(feature = "local-storage")]
use filesystem_actor;
use {
actix::Addr,
actix_multipart::{Field, Multipart},
actix_web::{http::header::ContentDisposition, post, web, web::Data, Error, HttpResponse},
database_actor::{
authorize_user::AuthorizeUser, user_projects::CurrentUserProject, users::UpdateAvatarUrl,
DbExecutor,
},
futures::{executor::block_on, StreamExt, TryStreamExt},
jirs_data::{User, UserId, WsMsg},
websocket_actor::server::{InnerMsg::BroadcastToChannel, WsServer},
};
#[post("/")]
pub async fn upload(
mut payload: Multipart,
db: Data<Addr<DbExecutor>>,
ws: Data<Addr<WsServer>>,
fs: Data<Addr<filesystem_actor::FileSystemExecutor>>,
amazon: Data<Addr<amazon_actor::AmazonExecutor>>,
) -> Result<HttpResponse, Error> {
let mut user_id: Option<UserId> = None;
let mut avatar_url: Option<String> = None;
while let Ok(Some(field)) = payload.try_next().await {
let disposition: ContentDisposition = match field.content_disposition() {
Some(d) => d,
_ => continue,
};
if !disposition.is_form_data() {
return Ok(HttpResponse::BadRequest().finish());
}
match disposition.get_name() {
Some("token") => {
user_id = Some(handle_token(field, db.clone()).await?);
}
Some("avatar") => {
let id = user_id.ok_or_else(|| HttpResponse::Unauthorized().finish())?;
avatar_url = Some(
crate::handlers::upload_avatar_image::handle_image(
id,
field,
disposition,
fs.clone(),
amazon.clone(),
)
.await?,
);
}
_ => continue,
};
}
let user_id = match user_id {
Some(id) => id,
_ => return Ok(HttpResponse::Unauthorized().finish()),
};
let project_id = match block_on(db.send(CurrentUserProject { user_id })) {
Ok(Ok(user_project)) => user_project.project_id,
_ => return Ok(HttpResponse::UnprocessableEntity().finish()),
};
match (user_id, avatar_url) {
(user_id, Some(avatar_url)) => {
let user = update_user_avatar(user_id, avatar_url.clone(), db).await?;
ws.send(BroadcastToChannel(
project_id,
WsMsg::AvatarUrlChanged(user.id, avatar_url),
))
.await
.map_err(|_| HttpResponse::UnprocessableEntity().finish())?;
Ok(HttpResponse::NoContent().finish())
}
_ => Ok(HttpResponse::UnprocessableEntity().finish()),
}
}
async fn update_user_avatar(
user_id: UserId,
new_url: String,
db: Data<Addr<DbExecutor>>,
) -> Result<User, Error> {
match db
.send(UpdateAvatarUrl {
user_id,
avatar_url: Some(new_url),
})
.await
{
Ok(Ok(user)) => Ok(user),
Ok(Err(e)) => {
error!("{:?}", e);
Err(HttpResponse::Unauthorized().finish().into())
}
Err(e) => {
error!("{:?}", e);
Err(HttpResponse::Unauthorized().finish().into())
}
}
}
async fn handle_token(mut field: Field, db: Data<Addr<DbExecutor>>) -> Result<UserId, Error> {
let mut f: Vec<u8> = vec![];
while let Some(chunk) = field.next().await {
let data = chunk.unwrap();
f = web::block(move || f.write_all(&data).map(|_| f)).await?;
}
let access_token = String::from_utf8(f)
.unwrap_or_default()
.parse::<uuid::Uuid>()
.map_err(|_| HttpResponse::Unauthorized().finish())?;
match db.send(AuthorizeUser { access_token }).await {
Ok(Ok(user)) => Ok(user.id),
Ok(Err(e)) => {
error!("{:?}", e);
Err(HttpResponse::Unauthorized().finish().into())
}
Err(e) => {
error!("{:?}", e);
Err(HttpResponse::Unauthorized().finish().into())
}
}
}

View File

@ -1,164 +0,0 @@
use {
actix::Addr,
actix_multipart::Field,
actix_web::{http::header::ContentDisposition, web::Data, Error},
futures::StreamExt,
jirs_data::UserId,
tokio::sync::broadcast::{Receiver, Sender},
};
#[cfg(all(feature = "local-storage", feature = "aws-s3"))]
pub(crate) async fn handle_image(
user_id: UserId,
mut field: Field,
disposition: ContentDisposition,
fs: Data<Addr<filesystem_actor::FileSystemExecutor>>,
amazon: Data<Addr<amazon_actor::AmazonExecutor>>,
) -> Result<String, Error> {
let filename = disposition.get_filename().unwrap();
let system_file_name = format!("{}-{}", user_id, filename);
let (sender, receiver) = tokio::sync::broadcast::channel(64);
let fs_fut = local_storage_write(system_file_name.clone(), fs, user_id, sender.subscribe());
let aws_fut = aws_s3(system_file_name, amazon, receiver);
let read_fut = read_form_data(&mut field, sender);
let fs_join = tokio::task::spawn(fs_fut);
let aws_join = tokio::task::spawn(aws_fut);
read_fut.await;
let mut new_link = None;
if let Ok(url) = fs_join.await {
new_link = url;
}
if let Ok(url) = aws_join.await {
new_link = url;
}
Ok(new_link.unwrap_or_default())
}
#[cfg(all(not(feature = "local-storage"), feature = "aws-s3"))]
pub(crate) async fn handle_image(
user_id: UserId,
mut field: Field,
disposition: ContentDisposition,
amazon: Data<Addr<amazon_actor::AmazonExecutor>>,
) -> Result<String, Error> {
let filename = disposition.get_filename().unwrap();
let system_file_name = format!("{}-{}", user_id, filename);
let (sender, receiver) = tokio::sync::broadcast::channel(64);
let aws_fut = aws_s3(system_file_name, amazon, receiver);
let read_fut = read_form_data(&mut field, sender);
let aws_join = tokio::task::spawn(aws_fut);
read_fut.await;
let mut new_link = None;
if let Ok(url) = aws_join.await {
new_link = url;
}
Ok(new_link.unwrap_or_default())
}
#[cfg(all(feature = "local-storage", not(feature = "aws-s3")))]
pub(crate) async fn handle_image(
user_id: UserId,
mut field: Field,
disposition: ContentDisposition,
fs: Data<Addr<filesystem_actor::FileSystemExecutor>>,
) -> Result<String, Error> {
let filename = disposition.get_filename().unwrap();
let system_file_name = format!("{}-{}", user_id, filename);
let (sender, receiver) = tokio::sync::broadcast::channel(64);
let fs_fut = local_storage_write(system_file_name, fs, user_id, sender.subscribe());
let read_fut = read_form_data(&mut field, sender);
let fs_join = tokio::task::spawn(fs_fut);
read_fut.await;
let mut new_link = None;
if let Ok(url) = fs_join.await {
new_link = url;
}
Ok(new_link.unwrap_or_default())
}
/// Read file from client
async fn read_form_data(field: &mut Field, sender: Sender<bytes::Bytes>) {
while let Some(chunk) = field.next().await {
let data = chunk.unwrap();
if let Err(err) = sender.send(data) {
log::error!("{:?}", err);
}
}
}
/// Stream bytes directly to AWS S3 Service
#[cfg(feature = "aws-s3")]
async fn aws_s3(
system_file_name: String,
amazon: Data<Addr<amazon_actor::AmazonExecutor>>,
receiver: Receiver<bytes::Bytes>,
) -> Option<String> {
let s3 = jirs_config::amazon::config();
if !s3.active {
return None;
}
match amazon
.send(amazon_actor::S3PutObject {
source: receiver,
file_name: system_file_name.to_string(),
})
.await
{
Ok(Ok(s)) => Some(s),
_ => None,
}
}
#[cfg(feature = "local-storage")]
async fn local_storage_write(
system_file_name: String,
fs: Data<Addr<filesystem_actor::FileSystemExecutor>>,
user_id: jirs_data::UserId,
receiver: Receiver<bytes::Bytes>,
) -> Option<String> {
let web_config = jirs_config::web::config();
let fs_config = jirs_config::fs::config();
match fs
.send(filesystem_actor::CreateFile {
source: receiver,
file_name: system_file_name.to_string(),
})
.await
{
Ok(Ok(_)) => Some(format!(
"{proto}://{bind}{port}{client_path}/{user_id}-{filename}",
proto = if web_config.ssl { "https" } else { "http" },
bind = web_config.bind,
port = match web_config.port.as_str() {
"80" | "443" => "".to_string(),
p => format!(":{}", p),
},
client_path = fs_config.client_path,
user_id = user_id,
filename = system_file_name
)),
Ok(_) => None,
_ => None,
}
}

View File

@ -1,117 +0,0 @@
use {
actix_service::{Service, Transform},
actix_web::{
dev::{ServiceRequest, ServiceResponse},
http::header::{self},
http::HeaderMap,
Error,
},
futures::future::{ok, FutureExt, LocalBoxFuture, Ready},
jirs_data::User,
std::task::{Context, Poll},
};
type Db = actix_web::web::Data<database_actor::DbPool>;
#[derive(Default)]
pub struct Authorize;
impl<S, B> Transform<S> for Authorize
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = Error;
type Transform = AuthorizeMiddleware<S>;
type InitError = ();
type Future = Ready<Result<Self::Transform, Self::InitError>>;
fn new_transform(&self, service: S) -> Self::Future {
ok(AuthorizeMiddleware { service })
}
}
pub struct AuthorizeMiddleware<S> {
service: S,
}
impl<S, B> Service for AuthorizeMiddleware<S>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = Error;
type Future = LocalBoxFuture<'static, Result<Self::Response, Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.service.poll_ready(cx)
}
fn call(&mut self, req: ServiceRequest) -> Self::Future {
let pool: &Db = match req.app_data::<Db>() {
Some(d) => d,
_ => {
return async move {
let res = crate::errors::ServiceError::DatabaseConnectionLost
.into_http_response()
.into_body();
Ok(req.into_response(res))
}
.boxed_local();
}
};
match check_token(req.headers(), pool.clone()) {
std::result::Result::Err(e) => {
return async move {
let res = e.into_http_response().into_body();
Ok(req.into_response(res))
}
.boxed_local();
}
Ok(_user) => {}
};
let fut = self.service.call(req);
async move { fut.await }.boxed_local()
}
}
pub fn token_from_headers(
headers: &HeaderMap,
) -> std::result::Result<uuid::Uuid, crate::errors::ServiceError> {
headers
.get(header::AUTHORIZATION)
.ok_or_else(|| crate::errors::ServiceError::Unauthorized)
.map(|h| h.to_str().unwrap_or_default())
.and_then(|s| parse_bearer(s))
}
fn check_token(
headers: &HeaderMap,
pool: Db,
) -> std::result::Result<User, crate::errors::ServiceError> {
token_from_headers(headers).and_then(|access_token| {
use database_actor::authorize_user::AuthorizeUser;
let conn = pool
.get()
.map_err(|_| crate::errors::ServiceError::DatabaseConnectionLost)?;
AuthorizeUser { access_token }
.execute(&conn)
.map_err(|_| crate::errors::ServiceError::Unauthorized)
})
}
fn parse_bearer(header: &str) -> Result<uuid::Uuid, crate::errors::ServiceError> {
if !header.starts_with("Bearer ") {
return Err(crate::errors::ServiceError::Unauthorized);
}
let (_bearer, token) = header.split_at(7);
uuid::Uuid::parse_str(token).map_err(|_e| crate::errors::ServiceError::Unauthorized)
}

View File

@ -1,59 +0,0 @@
[package]
name = "websocket-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "websocket_actor"
path = "./src/lib.rs"
[dependencies]
serde = "*"
bincode = "*"
toml = { version = "*" }
actix = { version = "0.10.0" }
actix-web = { version = "*" }
actix-web-actors = "*"
futures = { version = "0.3.8" }
openssl-sys = { version = "*", features = ["vendored"] }
libc = { version = "0.2.0", default-features = false }
flate2 = { version = "*" }
syntect = { version = "*" }
lazy_static = { version = "*" }
log = "0.4"
pretty_env_logger = "0.4"
env_logger = "0.7"
uuid = { version = "0.8.1", features = ["serde", "v4", "v5"] }
[dependencies.comrak]
version = "*"
[dependencies.pulldown-cmark]
version = "*"
[dependencies.jirs-config]
path = "../../shared/jirs-config"
features = ["websocket"]
[dependencies.jirs-data]
path = "../../shared/jirs-data"
features = ["backend"]
[dependencies.database-actor]
path = "../database-actor"
[dependencies.mail-actor]
path = "../mail-actor"
[dependencies.highlight-actor]
path = "../highlight-actor"

View File

@ -1,81 +0,0 @@
use {
crate::{
db_or_debug_and_return, mail_or_debug_and_return, WebSocketActor, WsHandler, WsResult,
},
actix::AsyncContext,
database_actor::{
authorize_user::AuthorizeUser,
tokens::{CreateBindToken, FindBindToken},
users::LookupUser,
},
futures::executor::block_on,
jirs_data::{Token, WsMsg},
mail_actor::welcome::Welcome,
};
pub struct Authenticate {
pub name: String,
pub email: String,
}
impl WsHandler<Authenticate> for WebSocketActor {
fn handle_msg(&mut self, msg: Authenticate, _ctx: &mut Self::Context) -> WsResult {
let Authenticate { name, email } = msg;
// TODO check attempt number, allow only 5 times per day
let user = db_or_debug_and_return!(self, LookupUser { name, email });
let token = db_or_debug_and_return!(self, CreateBindToken { user_id: user.id });
if let Some(bind_token) = token.bind_token.as_ref().cloned() {
let _ = mail_or_debug_and_return!(
self,
Welcome {
bind_token,
email: user.email,
}
);
}
Ok(Some(WsMsg::AuthenticateSuccess))
}
}
pub struct CheckAuthToken {
pub token: uuid::Uuid,
}
impl WsHandler<CheckAuthToken> for WebSocketActor {
fn handle_msg(&mut self, msg: CheckAuthToken, ctx: &mut Self::Context) -> WsResult {
let user: jirs_data::User = db_or_debug_and_return!(
self,
AuthorizeUser {
access_token: msg.token,
},
Ok(Some(WsMsg::AuthorizeLoaded(Err(
"Invalid auth token".to_string()
)))),
Ok(Some(WsMsg::AuthorizeExpired))
);
self.current_user = Some(user.clone());
self.current_user_project = self.load_user_project().ok();
self.current_project = self.load_project().ok();
block_on(self.join_channel(ctx.address().recipient()));
Ok(Some(WsMsg::AuthorizeLoaded(Ok(user))))
}
}
pub struct CheckBindToken {
pub bind_token: uuid::Uuid,
}
impl WsHandler<CheckBindToken> for WebSocketActor {
fn handle_msg(&mut self, msg: CheckBindToken, _ctx: &mut Self::Context) -> WsResult {
let token: Token = db_or_debug_and_return!(
self,
FindBindToken {
token: msg.bind_token,
},
Ok(Some(WsMsg::BindTokenBad)),
Ok(None)
);
Ok(Some(WsMsg::BindTokenOk(token.access_token)))
}
}

View File

@ -1,90 +0,0 @@
use {
crate::{db_or_debug_and_return, WebSocketActor, WsHandler, WsResult},
futures::executor::block_on,
jirs_data::{CommentId, CreateCommentPayload, IssueId, UpdateCommentPayload, WsMsg},
};
pub struct LoadIssueComments {
pub issue_id: IssueId,
}
impl WsHandler<LoadIssueComments> for WebSocketActor {
fn handle_msg(&mut self, msg: LoadIssueComments, _ctx: &mut Self::Context) -> WsResult {
self.require_user()?;
let comments = db_or_debug_and_return!(
self,
database_actor::comments::LoadIssueComments {
issue_id: msg.issue_id,
}
);
Ok(Some(WsMsg::IssueCommentsLoaded(comments)))
}
}
impl WsHandler<CreateCommentPayload> for WebSocketActor {
fn handle_msg(&mut self, mut msg: CreateCommentPayload, ctx: &mut Self::Context) -> WsResult {
use database_actor::comments::CreateComment;
let user_id = self.require_user()?.id;
if msg.user_id.is_none() {
msg.user_id = Some(user_id);
}
let issue_id = msg.issue_id;
let _ = db_or_debug_and_return!(
self,
CreateComment {
user_id,
issue_id,
body: msg.body,
}
);
self.handle_msg(LoadIssueComments { issue_id }, ctx)
}
}
impl WsHandler<UpdateCommentPayload> for WebSocketActor {
fn handle_msg(&mut self, msg: UpdateCommentPayload, _ctx: &mut Self::Context) -> WsResult {
use database_actor::comments::UpdateComment;
let user_id = self.require_user()?.id;
let UpdateCommentPayload {
id: comment_id,
body,
} = msg;
let comment = db_or_debug_and_return!(
self,
UpdateComment {
comment_id,
user_id,
body,
}
);
self.broadcast(&WsMsg::CommentUpdated(comment));
Ok(None)
}
}
pub struct DeleteComment {
pub comment_id: CommentId,
}
impl WsHandler<DeleteComment> for WebSocketActor {
fn handle_msg(&mut self, msg: DeleteComment, _ctx: &mut Self::Context) -> WsResult {
use database_actor::comments::DeleteComment;
let user_id = self.require_user()?.id;
let n = db_or_debug_and_return!(
self,
DeleteComment {
comment_id: msg.comment_id,
user_id,
}
);
Ok(Some(WsMsg::CommentDeleted(msg.comment_id, n)))
}
}

View File

@ -1,132 +0,0 @@
use jirs_data::IssueType;
use {
crate::{db_or_debug_and_return, WebSocketActor, WsHandler, WsResult},
futures::executor::block_on,
jirs_data::{DescriptionString, EpicId, NameString, UserProject, WsMsg},
};
pub struct LoadEpics;
impl WsHandler<LoadEpics> for WebSocketActor {
fn handle_msg(&mut self, _msg: LoadEpics, _ctx: &mut Self::Context) -> WsResult {
let project_id = self.require_user_project()?.project_id;
let epics = db_or_debug_and_return!(self, database_actor::epics::LoadEpics { project_id });
Ok(Some(WsMsg::EpicsLoaded(epics)))
}
}
pub struct CreateEpic {
pub name: NameString,
pub description: Option<DescriptionString>,
pub description_html: Option<DescriptionString>,
}
impl WsHandler<CreateEpic> for WebSocketActor {
fn handle_msg(&mut self, msg: CreateEpic, _ctx: &mut Self::Context) -> WsResult {
let CreateEpic {
name,
description,
description_html,
} = msg;
let UserProject {
user_id,
project_id,
..
} = self.require_user_project()?;
let epic = db_or_debug_and_return!(
self,
database_actor::epics::CreateEpic {
user_id: *user_id,
project_id: *project_id,
description,
description_html,
name,
}
);
Ok(Some(WsMsg::EpicCreated(epic)))
}
}
pub struct UpdateEpic {
pub epic_id: EpicId,
pub name: NameString,
}
impl WsHandler<UpdateEpic> for WebSocketActor {
fn handle_msg(&mut self, msg: UpdateEpic, _ctx: &mut Self::Context) -> WsResult {
let UpdateEpic { epic_id, name } = msg;
let UserProject { project_id, .. } = self.require_user_project()?;
let epic = db_or_debug_and_return!(
self,
database_actor::epics::UpdateEpic {
project_id: *project_id,
epic_id: epic_id,
name: name.clone(),
}
);
Ok(Some(WsMsg::EpicUpdated(epic)))
}
}
pub struct DeleteEpic {
pub epic_id: EpicId,
}
impl WsHandler<DeleteEpic> for WebSocketActor {
fn handle_msg(&mut self, msg: DeleteEpic, _ctx: &mut Self::Context) -> WsResult {
let DeleteEpic { epic_id } = msg;
let UserProject { user_id, .. } = self.require_user_project()?;
let n = db_or_debug_and_return!(
self,
database_actor::epics::DeleteEpic {
user_id: *user_id,
epic_id: epic_id,
}
);
Ok(Some(WsMsg::EpicDeleted(epic_id, n)))
}
}
pub struct TransformEpic {
pub epic_id: EpicId,
pub issue_type: IssueType,
}
impl WsHandler<TransformEpic> for WebSocketActor {
fn handle_msg(&mut self, msg: TransformEpic, _ctx: &mut Self::Context) -> WsResult {
let epic: jirs_data::Epic = db_or_debug_and_return!(
self,
database_actor::epics::FindEpic {
epic_id: msg.epic_id
}
);
let issue: database_actor::models::Issue = db_or_debug_and_return!(
self,
database_actor::issues::CreateIssue {
title: epic.name,
issue_type: msg.issue_type,
issue_status_id: 0,
priority: Default::default(),
description: epic.description_html,
description_text: epic.description,
estimate: None,
time_spent: None,
time_remaining: None,
project_id: epic.project_id,
reporter_id: epic.user_id,
user_ids: vec![epic.user_id],
epic_id: None
}
);
let n = db_or_debug_and_return!(
self,
database_actor::epics::DeleteEpic {
user_id: epic.user_id,
epic_id: epic.id
}
);
self.broadcast(&WsMsg::EpicDeleted(msg.epic_id, n));
self.broadcast(&WsMsg::IssueCreated(issue.into()));
Ok(None)
}
}

View File

@ -1,22 +0,0 @@
use {
crate::{actor_or_debug_and_return, WebSocketActor, WsHandler, WsResult},
futures::executor::block_on,
jirs_data::{Code, Lang, WsMsg},
};
pub struct HighlightCode(pub Lang, pub Code);
impl WsHandler<HighlightCode> for WebSocketActor {
fn handle_msg(&mut self, msg: HighlightCode, _ctx: &mut Self::Context) -> WsResult {
self.require_user()?.id;
let res = actor_or_debug_and_return!(
self,
hi,
highlight_actor::HighlightCode {
code: msg.1,
lang: msg.0,
}
);
Ok(Some(WsMsg::HighlightedCode(res)))
}
}

View File

@ -1,148 +0,0 @@
use {
crate::{
db_or_debug_and_return, mail_or_debug_and_return, server::InnerMsg, WebSocketActor,
WsHandler, WsMessageSender, WsResult,
},
database_actor::{invitations, messages::CreateMessageReceiver},
futures::executor::block_on,
jirs_data::{
EmailString, InvitationId, InvitationToken, MessageType, UserRole, UsernameString, WsMsg,
},
};
pub struct ListInvitation;
impl WsHandler<ListInvitation> for WebSocketActor {
fn handle_msg(&mut self, _msg: ListInvitation, _ctx: &mut Self::Context) -> WsResult {
let user_id = match self.current_user.as_ref().map(|u| u.id) {
Some(id) => id,
_ => return Ok(None),
};
let v = db_or_debug_and_return!(self, invitations::ListInvitation { user_id });
Ok(Some(WsMsg::InvitationListLoaded(v)))
}
}
pub struct CreateInvitation {
pub email: EmailString,
pub name: UsernameString,
pub role: UserRole,
}
impl WsHandler<CreateInvitation> for WebSocketActor {
fn handle_msg(&mut self, msg: CreateInvitation, _ctx: &mut Self::Context) -> WsResult {
let project_id = match self.current_user_project.as_ref() {
Some(up) => up.project_id,
_ => return Ok(None),
};
let (user_id, inviter_name) = self.require_user().map(|u| (u.id, u.name.clone()))?;
let CreateInvitation { email, name, role } = msg;
let invitation = db_or_debug_and_return!(
self,
database_actor::invitations::CreateInvitation {
user_id,
project_id,
email: email.clone(),
name: name.clone(),
role,
},
Ok(Some(WsMsg::InvitationSendFailure)),
Ok(Some(WsMsg::InvitationSendFailure))
);
let _ = mail_or_debug_and_return!(
self,
mail_actor::invite::Invite {
bind_token: invitation.bind_token,
email: invitation.email,
inviter_name,
},
Ok(Some(WsMsg::InvitationSendFailure)),
Ok(Some(WsMsg::InvitationSendFailure))
);
// If user exists then send message to him
if let Ok(Ok(message)) = block_on(self.db.send(database_actor::messages::CreateMessage {
receiver: CreateMessageReceiver::Lookup { name, email },
sender_id: user_id,
summary: "You have been invited to project".to_string(),
description: "You have been invited to project".to_string(),
message_type: MessageType::ReceivedInvitation,
hyper_link: format!("#{}", invitation.bind_token),
})) {
self.addr.do_send(InnerMsg::SendToUser(
message.receiver_id,
WsMsg::MessageUpdated(message),
));
}
Ok(Some(WsMsg::InvitationSendSuccess))
}
}
pub struct DeleteInvitation {
pub id: InvitationId,
}
impl WsHandler<DeleteInvitation> for WebSocketActor {
fn handle_msg(&mut self, msg: DeleteInvitation, _ctx: &mut Self::Context) -> WsResult {
self.require_user()?;
let DeleteInvitation { id } = msg;
let _ = db_or_debug_and_return!(self, invitations::DeleteInvitation { id });
Ok(None)
}
}
pub struct RevokeInvitation {
pub id: InvitationId,
}
impl WsHandler<RevokeInvitation> for WebSocketActor {
fn handle_msg(&mut self, msg: RevokeInvitation, _ctx: &mut Self::Context) -> WsResult {
self.require_user()?;
let RevokeInvitation { id } = msg;
let _ = db_or_debug_and_return!(self, invitations::RevokeInvitation { id });
Ok(Some(WsMsg::InvitationRevokeSuccess(id)))
}
}
pub struct AcceptInvitation {
pub invitation_token: InvitationToken,
}
impl WsHandler<AcceptInvitation> for WebSocketActor {
fn handle_msg(&mut self, msg: AcceptInvitation, ctx: &mut Self::Context) -> WsResult {
let AcceptInvitation { invitation_token } = msg;
let token = db_or_debug_and_return!(
self,
invitations::AcceptInvitation { invitation_token },
Ok(Some(WsMsg::InvitationAcceptFailure(invitation_token))),
Ok(Some(WsMsg::InvitationAcceptFailure(invitation_token)))
);
for message in crate::actor_or_debug_and_fallback!(
self,
db,
database_actor::messages::LookupMessagesByToken {
token: invitation_token,
user_id: token.user_id,
},
vec![],
vec![]
) {
crate::actor_or_debug_and_ignore!(
self,
db,
database_actor::messages::MarkMessageSeen {
user_id: token.user_id,
message_id: message.id,
},
|n| {
ctx.send_msg(&WsMsg::MessageMarkedSeen(message.id, n));
}
);
}
Ok(Some(WsMsg::InvitationAcceptSuccess(token.access_token)))
}
}

View File

@ -1,91 +0,0 @@
use {
crate::{db_or_debug_and_return, WebSocketActor, WsHandler, WsResult},
database_actor::issue_statuses,
futures::executor::block_on,
jirs_data::{IssueStatusId, Position, TitleString, WsMsg},
};
pub struct LoadIssueStatuses;
impl WsHandler<LoadIssueStatuses> for WebSocketActor {
fn handle_msg(&mut self, _msg: LoadIssueStatuses, _ctx: &mut Self::Context) -> WsResult {
let project_id = self.require_user_project()?.project_id;
let v = db_or_debug_and_return!(self, issue_statuses::LoadIssueStatuses { project_id });
Ok(Some(WsMsg::IssueStatusesLoaded(v)))
}
}
pub struct CreateIssueStatus {
pub position: i32,
pub name: TitleString,
}
impl WsHandler<CreateIssueStatus> for WebSocketActor {
fn handle_msg(&mut self, msg: CreateIssueStatus, _ctx: &mut Self::Context) -> WsResult {
let project_id = self.require_user_project()?.project_id;
let CreateIssueStatus { position, name } = msg;
let issue_status = db_or_debug_and_return!(
self,
issue_statuses::CreateIssueStatus {
project_id,
position,
name,
}
);
Ok(Some(WsMsg::IssueStatusCreated(issue_status)))
}
}
pub struct DeleteIssueStatus {
pub issue_status_id: IssueStatusId,
}
impl WsHandler<DeleteIssueStatus> for WebSocketActor {
fn handle_msg(&mut self, msg: DeleteIssueStatus, _ctx: &mut Self::Context) -> WsResult {
let project_id = self.require_user_project()?.project_id;
let DeleteIssueStatus { issue_status_id } = msg;
let n = db_or_debug_and_return!(
self,
issue_statuses::DeleteIssueStatus {
issue_status_id,
project_id,
}
);
Ok(Some(WsMsg::IssueStatusDeleted(msg.issue_status_id, n)))
}
}
pub struct UpdateIssueStatus {
pub issue_status_id: IssueStatusId,
pub position: Position,
pub name: TitleString,
}
impl WsHandler<UpdateIssueStatus> for WebSocketActor {
fn handle_msg(&mut self, msg: UpdateIssueStatus, _ctx: &mut Self::Context) -> WsResult {
let project_id = self.require_user_project()?.project_id;
let UpdateIssueStatus {
issue_status_id,
position,
name,
} = msg;
let issue_status = db_or_debug_and_return!(
self,
issue_statuses::UpdateIssueStatus {
issue_status_id,
position,
name,
project_id,
}
);
let msg = Some(WsMsg::IssueStatusUpdated(issue_status));
if let Some(ws_msg) = msg.as_ref() {
self.broadcast(ws_msg)
}
Ok(msg)
}
}

View File

@ -1,237 +0,0 @@
use {
crate::{db_or_debug_and_return, WebSocketActor, WsHandler, WsResult},
database_actor::{
issue_assignees::LoadAssignees,
issues::{LoadProjectIssues, UpdateIssue},
},
futures::executor::block_on,
jirs_data::{
CreateIssuePayload, IssueAssignee, IssueFieldId, IssueId, IssueStatusId, ListPosition,
PayloadVariant, WsMsg,
},
std::collections::HashMap,
};
pub struct UpdateIssueHandler {
pub id: i32,
pub field_id: IssueFieldId,
pub payload: PayloadVariant,
}
impl WsHandler<UpdateIssueHandler> for WebSocketActor {
fn handle_msg(&mut self, msg: UpdateIssueHandler, _ctx: &mut Self::Context) -> WsResult {
self.require_user()?;
let UpdateIssueHandler {
id,
field_id,
payload,
} = msg;
let mut msg = UpdateIssue {
issue_id: id,
..Default::default()
};
match (field_id, payload) {
(IssueFieldId::Type, PayloadVariant::IssueType(t)) => {
msg.issue_type = Some(t);
}
(IssueFieldId::Title, PayloadVariant::String(s)) => {
msg.title = Some(s);
}
(IssueFieldId::Description, PayloadVariant::String(s)) => {
let html: String = {
use pulldown_cmark::*;
let parser = pulldown_cmark::Parser::new(s.as_str());
enum ParseState {
Code(highlight_actor::TextHighlightCode),
Other,
}
let mut state = ParseState::Other;
let parser = parser.flat_map(|event| match event {
Event::Text(s) => {
if let ParseState::Code(h) = &mut state {
h.code.push_str(s.as_ref());
return vec![];
}
vec![Event::Text(s)]
}
Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(name))) => {
state = ParseState::Code(highlight_actor::TextHighlightCode {
lang: name.to_string(),
code: String::new(),
});
vec![Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(name)))]
}
Event::End(Tag::CodeBlock(CodeBlockKind::Fenced(lang))) => {
let ev = if let ParseState::Code(h) = &mut state {
let mut msg = highlight_actor::TextHighlightCode {
code: String::new(),
lang: String::new(),
};
std::mem::swap(h, &mut msg);
let highlighted =
match futures::executor::block_on(self.hi.send(msg)) {
Ok(Ok(res)) => res,
_ => s.to_string(),
};
vec![
Event::Html(highlighted.into()),
Event::End(Tag::CodeBlock(CodeBlockKind::Fenced(lang))),
]
} else {
vec![]
};
state = ParseState::Other;
ev
}
_ => vec![event],
});
let mut buff = String::new();
let _ = html::push_html(&mut buff, parser);
buff
};
msg.description = Some(html);
msg.description_text = Some(s);
}
(IssueFieldId::IssueStatusId, PayloadVariant::I32(s)) => {
msg.issue_status_id = Some(s);
}
(IssueFieldId::ListPosition, PayloadVariant::I32(i)) => {
msg.list_position = Some(i);
}
(IssueFieldId::Assignees, PayloadVariant::VecI32(v)) => {
msg.user_ids = Some(v);
}
(IssueFieldId::Reporter, PayloadVariant::I32(i)) => {
msg.reporter_id = Some(i);
}
(IssueFieldId::Priority, PayloadVariant::IssuePriority(p)) => {
msg.priority = Some(p);
}
(IssueFieldId::Estimate, PayloadVariant::OptionI32(o)) => {
msg.estimate = o;
}
(IssueFieldId::TimeSpent, PayloadVariant::OptionI32(o)) => {
msg.time_spent = o;
}
(IssueFieldId::TimeRemaining, PayloadVariant::OptionI32(o)) => {
msg.time_remaining = o;
}
(IssueFieldId::EpicName, PayloadVariant::OptionI32(o)) => {
msg.epic_id = Some(o);
}
_ => (),
};
let issue = db_or_debug_and_return!(self, msg);
let mut issue: jirs_data::Issue = issue.into();
let assignees: Vec<IssueAssignee> =
db_or_debug_and_return!(self, LoadAssignees { issue_id: issue.id });
for assignee in assignees {
issue.user_ids.push(assignee.user_id);
}
self.broadcast(&WsMsg::IssueUpdated(issue));
Ok(None)
}
}
impl WsHandler<CreateIssuePayload> for WebSocketActor {
fn handle_msg(&mut self, msg: CreateIssuePayload, _ctx: &mut Self::Context) -> WsResult {
self.require_user()?;
let msg = database_actor::issues::CreateIssue {
title: msg.title,
issue_type: msg.issue_type,
issue_status_id: msg.issue_status_id,
priority: msg.priority,
description: msg.description,
description_text: msg.description_text,
estimate: msg.estimate,
time_spent: msg.time_spent,
time_remaining: msg.time_remaining,
project_id: msg.project_id,
reporter_id: msg.reporter_id,
user_ids: msg.user_ids,
epic_id: msg.epic_id,
};
let issue = db_or_debug_and_return!(self, msg);
Ok(Some(WsMsg::IssueCreated(issue.into())))
}
}
pub struct DeleteIssue {
pub id: IssueId,
}
impl WsHandler<DeleteIssue> for WebSocketActor {
fn handle_msg(&mut self, msg: DeleteIssue, _ctx: &mut Self::Context) -> WsResult {
self.require_user()?;
let n = db_or_debug_and_return!(
self,
database_actor::issues::DeleteIssue { issue_id: msg.id }
);
Ok(Some(WsMsg::IssueDeleted(msg.id, n)))
}
}
pub struct LoadIssues;
impl WsHandler<LoadIssues> for WebSocketActor {
fn handle_msg(&mut self, _msg: LoadIssues, _ctx: &mut Self::Context) -> WsResult {
let project_id = self.require_user_project()?.project_id;
let v = db_or_debug_and_return!(self, LoadProjectIssues { project_id });
let issues: Vec<jirs_data::Issue> = v.into_iter().map(|i| i.into()).collect();
let mut issue_map = HashMap::new();
let mut queue = vec![];
for issue in issues {
let f = self.db.send(LoadAssignees { issue_id: issue.id });
queue.push(f);
issue_map.insert(issue.id, issue);
}
for f in queue {
if let Ok(Ok(assignees)) = block_on(f) {
for assignee in assignees {
if let Some(issue) = issue_map.get_mut(&assignee.issue_id) {
issue.user_ids.push(assignee.user_id);
}
}
};
}
let mut issues = vec![];
for (_, issue) in issue_map {
issues.push(issue);
}
issues.sort_by(|a, b| a.list_position.cmp(&b.list_position));
Ok(Some(WsMsg::ProjectIssuesLoaded(issues)))
}
}
pub struct SyncIssueListPosition(pub Vec<(IssueId, ListPosition, IssueStatusId, Option<IssueId>)>);
impl WsHandler<SyncIssueListPosition> for WebSocketActor {
fn handle_msg(&mut self, msg: SyncIssueListPosition, ctx: &mut Self::Context) -> WsResult {
let _project_id = self.require_user_project()?.project_id;
for (issue_id, list_position, status_id, epic_id) in msg.0 {
crate::actor_or_debug_and_ignore!(
self,
db,
database_actor::issues::UpdateIssue {
issue_id,
list_position: Some(list_position),
issue_status_id: Some(status_id),
epic_id: Some(epic_id),
..Default::default()
},
|_| {}
);
}
self.handle_msg(LoadIssues, ctx)
}
}

View File

@ -1,34 +0,0 @@
use {
crate::{db_or_debug_and_return, WebSocketActor, WsHandler, WsResult},
database_actor::messages,
futures::executor::block_on,
jirs_data::{MessageId, WsMsg},
};
pub struct LoadMessages;
impl WsHandler<LoadMessages> for WebSocketActor {
fn handle_msg(&mut self, _msg: LoadMessages, _ctx: &mut Self::Context) -> WsResult {
let user_id = self.require_user()?.id;
let v = db_or_debug_and_return!(self, messages::LoadMessages { user_id });
Ok(Some(WsMsg::MessagesLoaded(v)))
}
}
pub struct MarkMessageSeen {
pub id: MessageId,
}
impl WsHandler<MarkMessageSeen> for WebSocketActor {
fn handle_msg(&mut self, msg: MarkMessageSeen, _ctx: &mut Self::Context) -> WsResult {
let user_id = self.require_user()?.id;
let count = db_or_debug_and_return!(
self,
messages::MarkMessageSeen {
message_id: msg.id,
user_id,
}
);
Ok(Some(WsMsg::MessageMarkedSeen(msg.id, count)))
}
}

View File

@ -1,16 +0,0 @@
pub use {
auth::*, comments::*, epics::*, hi::*, invitations::*, issue_statuses::*, issues::*,
messages::*, projects::*, user_projects::*, users::*,
};
pub mod auth;
pub mod comments;
pub mod epics;
pub mod hi;
pub mod invitations;
pub mod issue_statuses;
pub mod issues;
pub mod messages;
pub mod projects;
pub mod user_projects;
pub mod users;

View File

@ -1,42 +0,0 @@
use {
crate::{db_or_debug_and_return, WebSocketActor, WsHandler, WsResult},
database_actor as db,
futures::executor::block_on,
jirs_data::{UpdateProjectPayload, UserProject, WsMsg},
};
impl WsHandler<UpdateProjectPayload> for WebSocketActor {
fn handle_msg(&mut self, msg: UpdateProjectPayload, _ctx: &mut Self::Context) -> WsResult {
let UserProject {
user_id,
project_id,
..
} = self.require_user_project()?;
let _ = db_or_debug_and_return!(
self,
database_actor::projects::UpdateProject {
project_id: *project_id,
name: msg.name,
url: msg.url,
description: msg.description,
category: msg.category,
time_tracking: msg.time_tracking,
}
);
let projects = db_or_debug_and_return!(
self,
database_actor::projects::LoadProjects { user_id: *user_id }
);
Ok(Some(WsMsg::ProjectsLoaded(projects)))
}
}
pub struct LoadProjects;
impl WsHandler<LoadProjects> for WebSocketActor {
fn handle_msg(&mut self, _msg: LoadProjects, _ctx: &mut Self::Context) -> WsResult {
let user_id = self.require_user()?.id;
let v = db_or_debug_and_return!(self, db::projects::LoadProjects { user_id });
Ok(Some(WsMsg::ProjectsLoaded(v)))
}
}

View File

@ -1,35 +0,0 @@
use {
crate::{db_or_debug_and_return, WebSocketActor, WsHandler, WsResult},
database_actor as db,
futures::executor::block_on,
jirs_data::{UserProjectId, WsMsg},
};
pub struct LoadUserProjects;
impl WsHandler<LoadUserProjects> for WebSocketActor {
fn handle_msg(&mut self, _msg: LoadUserProjects, _ctx: &mut Self::Context) -> WsResult {
let user_id = self.require_user()?.id;
let v = db_or_debug_and_return!(self, db::user_projects::LoadUserProjects { user_id });
Ok(Some(WsMsg::UserProjectsLoaded(v)))
}
}
pub struct SetCurrentUserProject {
pub id: UserProjectId,
}
impl WsHandler<SetCurrentUserProject> for WebSocketActor {
fn handle_msg(&mut self, msg: SetCurrentUserProject, _ctx: &mut Self::Context) -> WsResult {
let user_id = self.require_user()?.id;
let user_project = db_or_debug_and_return!(
self,
db::user_projects::ChangeCurrentUserProject {
user_id,
id: msg.id,
}
);
self.current_user_project = Some(user_project.clone());
Ok(Some(WsMsg::UserProjectCurrentChanged(user_project)))
}
}

View File

@ -1,111 +0,0 @@
use {
crate::{
db_or_debug_and_return, handlers::auth::Authenticate, WebSocketActor, WsHandler, WsResult,
},
database_actor::{self, users::Register as DbRegister},
futures::executor::block_on,
jirs_data::{UserId, UserProject, UserRole, WsMsg},
};
pub struct LoadProjectUsers;
impl WsHandler<LoadProjectUsers> for WebSocketActor {
fn handle_msg(&mut self, _msg: LoadProjectUsers, _ctx: &mut Self::Context) -> WsResult {
use database_actor::users::LoadProjectUsers as Msg;
let project_id = self.require_user_project()?.project_id;
let v = db_or_debug_and_return!(self, Msg { project_id });
Ok(Some(WsMsg::ProjectUsersLoaded(v)))
}
}
pub struct Register {
pub name: String,
pub email: String,
}
impl WsHandler<Register> for WebSocketActor {
fn handle_msg(&mut self, msg: Register, ctx: &mut Self::Context) -> WsResult {
let Register { name, email } = msg;
let _ = db_or_debug_and_return!(
self,
DbRegister {
name: name.clone(),
email: email.clone(),
project_id: None,
role: UserRole::Owner,
},
Ok(Some(WsMsg::SignUpPairTaken)),
Ok(None)
);
match self.handle_msg(Authenticate { name, email }, ctx) {
Ok(_) => (),
Err(e) => return Ok(Some(e)),
};
Ok(Some(WsMsg::SignUpSuccess))
}
}
pub struct LoadInvitedUsers;
impl WsHandler<LoadInvitedUsers> for WebSocketActor {
fn handle_msg(&mut self, _msg: LoadInvitedUsers, _ctx: &mut Self::Context) -> WsResult {
let user_id = self.require_user()?.id;
let users =
db_or_debug_and_return!(self, database_actor::users::LoadInvitedUsers { user_id });
Ok(Some(WsMsg::InvitedUsersLoaded(users)))
}
}
pub struct ProfileUpdate {
pub name: String,
pub email: String,
}
impl WsHandler<ProfileUpdate> for WebSocketActor {
fn handle_msg(&mut self, msg: ProfileUpdate, _ctx: &mut Self::Context) -> WsResult {
let user_id = self.require_user()?.id;
let ProfileUpdate { name, email } = msg;
let _ = db_or_debug_and_return!(
self,
database_actor::users::ProfileUpdate {
user_id,
name,
email,
}
);
Ok(Some(WsMsg::ProfileUpdated))
}
}
pub struct RemoveInvitedUser {
pub user_id: UserId,
}
impl WsHandler<RemoveInvitedUser> for WebSocketActor {
fn handle_msg(&mut self, msg: RemoveInvitedUser, _ctx: &mut Self::Context) -> WsResult {
let RemoveInvitedUser {
user_id: invited_id,
} = msg;
let UserProject {
user_id: inviter_id,
project_id,
..
} = self.require_user_project()?.clone();
let _ = db_or_debug_and_return!(
self,
database_actor::user_projects::RemoveInvitedUser {
invited_id,
inviter_id,
project_id,
}
);
Ok(Some(WsMsg::InvitedUserRemoveSuccess(invited_id)))
}
}

View File

@ -1,364 +0,0 @@
#[macro_use]
extern crate log;
use {
crate::{
handlers::*,
server::{InnerMsg, WsServer},
},
actix::{Actor, ActorContext, Addr, AsyncContext, Handler, Recipient, StreamHandler},
actix_web::{
get,
web::{self, Data},
Error, HttpRequest, HttpResponse,
},
actix_web_actors::ws,
database_actor::{projects::LoadCurrentProject, user_projects::CurrentUserProject, DbExecutor},
futures::executor::block_on,
jirs_data::{Project, User, UserProject, WsMsg},
log::*,
mail_actor::MailExecutor,
};
pub mod handlers;
pub mod prelude;
pub mod server;
pub type WsResult = std::result::Result<Option<WsMsg>, WsMsg>;
trait WsMessageSender {
fn send_msg(&mut self, msg: &jirs_data::WsMsg);
}
struct WebSocketActor {
db: Data<Addr<DbExecutor>>,
mail: Data<Addr<MailExecutor>>,
addr: Addr<WsServer>,
hi: Data<Addr<highlight_actor::HighlightActor>>,
current_user: Option<jirs_data::User>,
current_user_project: Option<jirs_data::UserProject>,
current_project: Option<jirs_data::Project>,
}
impl Actor for WebSocketActor {
type Context = ws::WebsocketContext<WebSocketActor>;
}
impl WsMessageSender for ws::WebsocketContext<WebSocketActor> {
fn send_msg(&mut self, msg: &WsMsg) {
self.binary(bincode::serialize(msg).unwrap())
}
}
impl Handler<InnerMsg> for WebSocketActor {
type Result = ();
fn handle(&mut self, msg: InnerMsg, ctx: &mut <Self as Actor>::Context) -> Self::Result {
if let InnerMsg::Transfer(msg) = msg {
ctx.send_msg(&msg)
};
}
}
impl WebSocketActor {
fn broadcast(&self, msg: &WsMsg) {
let project_id = match self.require_user_project() {
Ok(up) => up.project_id,
_ => return,
};
self.addr
.do_send(InnerMsg::BroadcastToChannel(project_id, msg.clone()));
}
fn handle_ws_msg(
&mut self,
msg: WsMsg,
ctx: &mut <WebSocketActor as Actor>::Context,
) -> WsResult {
if msg != WsMsg::Ping && msg != WsMsg::Pong {
debug!("incoming message: {:?}", msg);
}
let msg = match msg {
WsMsg::Ping => Some(WsMsg::Pong),
WsMsg::Pong => Some(WsMsg::Ping),
// issues
WsMsg::IssueUpdate(id, field_id, payload) => self.handle_msg(
UpdateIssueHandler {
id,
field_id,
payload,
},
ctx,
)?,
WsMsg::IssueCreate(payload) => self.handle_msg(payload, ctx)?,
WsMsg::IssueDelete(id) => self.handle_msg(DeleteIssue { id }, ctx)?,
WsMsg::IssueSyncListPosition(sync) => {
self.handle_msg(SyncIssueListPosition(sync), ctx)?
}
WsMsg::ProjectIssuesLoad => self.handle_msg(LoadIssues, ctx)?,
// issue statuses
WsMsg::IssueStatusesLoad => self.handle_msg(LoadIssueStatuses, ctx)?,
WsMsg::IssueStatusDelete(issue_status_id) => {
self.handle_msg(DeleteIssueStatus { issue_status_id }, ctx)?
}
WsMsg::IssueStatusUpdate(issue_status_id, name, position) => self.handle_msg(
UpdateIssueStatus {
issue_status_id,
name,
position,
},
ctx,
)?,
WsMsg::IssueStatusCreate(name, position) => {
self.handle_msg(CreateIssueStatus { name, position }, ctx)?
}
// projects
WsMsg::ProjectsLoad => self.handle_msg(LoadProjects, ctx)?,
WsMsg::ProjectUpdateLoad(payload) => self.handle_msg(payload, ctx)?,
// user projects
WsMsg::UserProjectsLoad => self.handle_msg(LoadUserProjects, ctx)?,
WsMsg::UserProjectSetCurrent(user_project_id) => self.handle_msg(
SetCurrentUserProject {
id: user_project_id,
},
ctx,
)?,
// auth
WsMsg::AuthorizeLoad(uuid) => self.handle_msg(CheckAuthToken { token: uuid }, ctx)?,
WsMsg::BindTokenCheck(uuid) => {
self.handle_msg(CheckBindToken { bind_token: uuid }, ctx)?
}
WsMsg::AuthenticateRequest(email, name) => {
self.handle_msg(Authenticate { name, email }, ctx)?
}
// register
WsMsg::SignUpRequest(email, username) => self.handle_msg(
Register {
name: username,
email,
},
ctx,
)?,
// users
WsMsg::ProjectUsersLoad => self.handle_msg(LoadProjectUsers, ctx)?,
WsMsg::InvitedUserRemoveRequest(user_id) => {
self.handle_msg(RemoveInvitedUser { user_id }, ctx)?
}
// comments
WsMsg::IssueCommentsLoad(issue_id) => {
self.handle_msg(LoadIssueComments { issue_id }, ctx)?
}
WsMsg::CommentCreate(payload) => self.handle_msg(payload, ctx)?,
WsMsg::CommentUpdate(payload) => self.handle_msg(payload, ctx)?,
WsMsg::CommentDelete(comment_id) => {
self.handle_msg(DeleteComment { comment_id }, ctx)?
}
// invitations
WsMsg::InvitationSendRequest { name, email, role } => {
self.handle_msg(CreateInvitation { name, email, role }, ctx)?
}
WsMsg::InvitationListLoad => self.handle_msg(ListInvitation, ctx)?,
WsMsg::InvitationAcceptRequest(invitation_token) => {
self.handle_msg(AcceptInvitation { invitation_token }, ctx)?
}
WsMsg::InvitationRevokeRequest(id) => self.handle_msg(RevokeInvitation { id }, ctx)?,
WsMsg::InvitedUsersLoad => self.handle_msg(LoadInvitedUsers, ctx)?,
// users
WsMsg::ProfileUpdate(email, name) => {
self.handle_msg(ProfileUpdate { email, name }, ctx)?
}
// messages
WsMsg::MessagesLoad => self.handle_msg(LoadMessages, ctx)?,
WsMsg::MessageMarkSeen(id) => self.handle_msg(MarkMessageSeen { id }, ctx)?,
// epics
WsMsg::EpicsLoad => self.handle_msg(epics::LoadEpics, ctx)?,
WsMsg::EpicCreate(name, description, description_html) => self.handle_msg(
epics::CreateEpic {
name,
description_html,
description,
},
ctx,
)?,
WsMsg::EpicUpdate(epic_id, name) => {
self.handle_msg(epics::UpdateEpic { epic_id, name }, ctx)?
}
WsMsg::EpicDelete(epic_id) => self.handle_msg(epics::DeleteEpic { epic_id }, ctx)?,
WsMsg::EpicTransform(epic_id, issue_type) => self.handle_msg(
epics::TransformEpic {
epic_id,
issue_type,
},
ctx,
)?,
// hi
WsMsg::HighlightCode(lang, code) => {
self.handle_msg(hi::HighlightCode(lang, code), ctx)?
}
// else fail
_ => {
error!("No handle for {:?} specified", msg);
None
}
};
if msg.is_some() && msg != Some(WsMsg::Pong) {
info!("sending message {:?}", msg);
}
Ok(msg)
}
async fn join_channel(&self, addr: Recipient<InnerMsg>) {
info!("joining channel...");
info!(" current user {:?}", self.current_user);
let user = match self.current_user.as_ref() {
None => return,
Some(u) => u,
};
let project_id = match self.require_user_project() {
Ok(user_project) => user_project.project_id,
_ => return,
};
match self
.addr
.send(InnerMsg::Join(project_id, user.id, addr))
.await
{
Err(e) => error!("{}", e),
_ => info!(" joined channel"),
};
}
fn require_user(&self) -> Result<&User, WsMsg> {
self.current_user
.as_ref()
.map(|u| u)
.ok_or_else(|| WsMsg::AuthorizeExpired)
}
fn require_user_project(&self) -> Result<&UserProject, WsMsg> {
self.current_user_project
.as_ref()
.map(|u| u)
.ok_or_else(|| WsMsg::AuthorizeExpired)
}
fn load_user_project(&self) -> Result<UserProject, WsMsg> {
let user_id = self.require_user()?.id;
match block_on(self.db.send(CurrentUserProject { user_id })) {
Ok(Ok(user_project)) => Ok(user_project),
Ok(Err(e)) => {
error!("load_user_project encounter service error {:?}", e);
Err(WsMsg::AuthorizeExpired)
}
Err(e) => {
error!("load_user_project encounter mailbox error {}", e);
Err(WsMsg::AuthorizeExpired)
}
}
}
fn load_project(&self) -> Result<Project, WsMsg> {
let project_id = self.require_user_project()?.project_id;
match block_on(self.db.send(LoadCurrentProject { project_id })) {
Ok(Ok(project)) => Ok(project),
Ok(Err(e)) => {
error!("{:?}", e);
Err(WsMsg::AuthorizeExpired)
}
Err(e) => {
error!("{}", e);
Err(WsMsg::AuthorizeExpired)
}
}
}
}
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WebSocketActor {
fn handle(
&mut self,
msg: Result<ws::Message, ws::ProtocolError>,
ctx: &mut <Self as Actor>::Context,
) {
match msg {
Ok(ws::Message::Ping(msg)) => ctx.pong(&msg),
Ok(ws::Message::Text(text)) => ctx.text(text),
Ok(ws::Message::Binary(bin)) => {
let ws_msg: bincode::Result<jirs_data::WsMsg> =
bincode::deserialize(bin.to_vec().as_slice());
let msg = match ws_msg {
Ok(m) => m,
_ => return,
};
match self.handle_ws_msg(msg, ctx) {
Ok(Some(msg)) => ctx.send_msg(&msg),
Err(e) => ctx.send_msg(&e),
_ => (),
};
}
_ => (),
}
}
fn finished(&mut self, ctx: &mut <Self as Actor>::Context) {
info!("Disconnected");
if let (Some(user), Some(up)) = (
self.current_user.as_ref(),
self.current_user_project.as_ref(),
) {
self.addr.do_send(InnerMsg::Leave(
up.project_id,
user.id,
ctx.address().recipient(),
));
}
ctx.stop()
}
}
pub trait WsHandler<Message>
where
Self: Actor,
{
fn handle_msg(&mut self, msg: Message, _ctx: &mut <Self as Actor>::Context) -> WsResult;
}
#[get("/ws/")]
pub async fn index(
req: HttpRequest,
stream: web::Payload,
db: Data<Addr<DbExecutor>>,
mail: Data<Addr<MailExecutor>>,
ws_server: Data<Addr<WsServer>>,
hi: Data<Addr<highlight_actor::HighlightActor>>,
) -> Result<HttpResponse, Error> {
ws::start(
WebSocketActor {
db,
mail,
hi,
current_user: None,
current_user_project: None,
current_project: None,
addr: ws_server.get_ref().clone(),
},
&req,
stream,
)
}

View File

@ -1,73 +0,0 @@
#[macro_export]
macro_rules! db_or_debug_and_return {
($s: ident, $msg: expr, $actor_err: expr, $mailbox_err: expr) => {
$crate::actor_or_debug_and_return!($s, db, $msg, $actor_err, $mailbox_err)
};
($s: ident, $msg: expr) => {
$crate::actor_or_debug_and_return!($s, db, $msg)
};
}
#[macro_export]
macro_rules! mail_or_debug_and_return {
($s: ident, $msg: expr, $actor_err: expr, $mailbox_err: expr) => {
$crate::actor_or_debug_and_return!($s, mail, $msg, $actor_err, $mailbox_err)
};
($s: ident, $msg: expr) => {
$crate::actor_or_debug_and_return!($s, mail, $msg)
};
}
#[macro_export]
macro_rules! actor_or_debug_and_return {
($s: ident, $actor: ident, $msg: expr, $actor_err: expr, $mailbox_err: expr) => {
match block_on($s.$actor.send($msg)) {
Ok(Ok(r)) => r,
Ok(Err(e)) => {
log::error!("{:?}", e);
return $actor_err;
}
Err(e) => {
log::error!("{:?}", e);
return $mailbox_err;
}
}
};
($s: ident, $actor: ident, $msg: expr) => {
crate::actor_or_debug_and_return!($s, $actor, $msg, Ok(None), Ok(None))
};
}
#[macro_export]
macro_rules! actor_or_debug_and_ignore {
($s: ident, $actor: ident, $msg: expr, $on_success: expr) => {
match block_on($s.$actor.send($msg)) {
Ok(Ok(r)) => {
$on_success(r);
}
Ok(Err(e)) => {
log::error!("{:?}", e);
}
Err(e) => {
log::error!("{:?}", e);
}
}
};
}
#[macro_export]
macro_rules! actor_or_debug_and_fallback {
($s: ident, $actor: ident, $msg: expr, $actor_err: expr, $mailbox_err: expr) => {
match block_on($s.$actor.send($msg)) {
Ok(Ok(r)) => r,
Ok(Err(e)) => {
log::error!("{:?}", e);
$actor_err
}
Err(e) => {
log::error!("{:?}", e);
$mailbox_err
}
}
};
}

View File

@ -0,0 +1,11 @@
[package]
name = "bitquec"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
[dependencies]
actix = { version = "0.13.0" }
clap = { version = "4.1.13" }
termion = { version = "*" }
tui = { version = "0.19.0", features = ["termion"] }

View File

@ -1,24 +1,19 @@
use {
std::{
error::Error,
io,
sync::{
atomic::{AtomicBool, Ordering},
mpsc, Arc,
},
time::Duration,
},
termion::{event::Key, input::MouseTerminal, raw::IntoRawMode, screen::AlternateScreen},
tui::{
backend::TermionBackend,
layout::{Constraint, Direction, Layout},
style::{Color, Style},
widgets::{Block, Borders, Tabs},
Terminal,
},
};
use std::error::Error;
use std::io;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{mpsc, Arc};
use std::time::Duration;
#[derive(Debug, Clone, Copy)]
use termion::event::Key;
use termion::screen::IntoAlternateScreen;
use tui::backend::TermionBackend;
use tui::layout::{Constraint, Direction, Layout};
use tui::style::{Color, Style};
use tui::text::{Span, Spans};
use tui::widgets::{Block, Borders, Tabs};
use tui::Terminal;
#[derive(Clone, Copy, Debug)]
pub struct Config {
pub exit_key: Key,
pub tick_rate: Duration,
@ -68,8 +63,8 @@ impl Events {
// eprintln!("{}", err);
// return;
// }
// if !ignore_exit_key.load(Ordering::Relaxed) && key == config.exit_key {
// return;
// if !ignore_exit_key.load(Ordering::Relaxed) && key ==
// config.exit_key { return;
// }
// }
// }
@ -84,8 +79,8 @@ impl Events {
Events {
rx,
ignore_exit_key,
// input_handle,
// tick_handle,
/* input_handle,
* tick_handle, */
}
}
@ -130,9 +125,7 @@ struct App<'a> {
fn main() -> Result<(), Box<dyn Error>> {
// Terminal initialization
let stdout = io::stdout().into_raw_mode()?;
let stdout = MouseTerminal::from(stdout);
let stdout = AlternateScreen::from(stdout);
let stdout = io::stdout().into_alternate_screen().unwrap();
let backend = TermionBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
terminal.hide_cursor()?;
@ -146,7 +139,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Main loop
loop {
terminal.draw(|mut f| {
terminal.draw(|f| {
let size = f.size();
let chunks = Layout::default()
.direction(Direction::Vertical)
@ -156,12 +149,17 @@ fn main() -> Result<(), Box<dyn Error>> {
let block = Block::default().style(Style::default().bg(Color::White));
f.render_widget(block, size);
let tabs = Tabs::default()
.block(Block::default().borders(Borders::ALL).title("Tabs"))
.titles(&app.tabs.titles)
.select(app.tabs.index)
.style(Style::default().fg(Color::Cyan))
.highlight_style(Style::default().fg(Color::Yellow));
let tabs = Tabs::new(
app.tabs
.titles
.iter()
.map(|s| Spans::from(vec![Span::styled(*s, Style::default())]))
.collect(),
)
.block(Block::default().borders(Borders::ALL).title("Tabs"))
.select(app.tabs.index)
.style(Style::default().fg(Color::Cyan))
.highlight_style(Style::default().fg(Color::Yellow));
f.render_widget(tabs, chunks[0]);
let inner = match app.tabs.index {
0 => Block::default().title("Inner 0").borders(Borders::ALL),

View File

@ -0,0 +1,29 @@
[package]
name = "bitque-config"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "bitque_config"
path = "./src/lib.rs"
[features]
cloud-storage = ["rust-s3"]
local-storage = []
database = []
hi = []
mail = []
web = ["cloud-storage", "local-storage"]
websocket = []
default = ["local-storage", "database", "hi", "mail", "web", "websocket"]
[dependencies]
serde = { version = "*" }
toml = { version = "*" }
rust-s3 = { version = "*", optional = true }
tracing = { version = "*" }

View File

@ -1,9 +1,10 @@
use {
rusoto_signature::Region,
serde::{Deserialize, Serialize},
};
use std::str::FromStr;
#[derive(Serialize, Deserialize, Debug)]
use s3::Region;
use serde::{Deserialize, Serialize};
use tracing::warn;
#[derive(Debug, Deserialize, Serialize)]
pub struct Configuration {
pub access_key_id: String,
pub secret_access_key: String,
@ -20,7 +21,11 @@ impl Default for Configuration {
access_key_id: "".to_string(),
secret_access_key: "".to_string(),
bucket: "".to_string(),
region_name: Region::default().name().to_string(),
region_name: Region::Custom {
region: "http://localhost:9000".to_string(),
endpoint: "http://localhost:9000".to_string(),
}
.to_string(),
active: true,
concurrency: 2,
}
@ -37,7 +42,10 @@ impl Configuration {
}
pub fn region(&self) -> Region {
self.region_name.parse::<Region>().unwrap_or_default()
self.region_name.parse::<Region>().unwrap_or_else(|e| {
warn!("{e}");
Region::from_str("http://localhost:9000").expect("Parse S3 Region is infallible")
})
}
pub fn set_variables(&self) {

View File

@ -1,4 +1,4 @@
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(serde::Deserialize, serde::Serialize)]
pub struct Configuration {
pub concurrency: usize,
pub database_url: String,
@ -7,10 +7,10 @@ pub struct Configuration {
impl Default for Configuration {
fn default() -> Self {
let database_url = if cfg!(test) {
"postgres://postgres@localhost:5432/jirs_test".to_string()
"postgres://postgres@localhost:5432/bitque_test".to_string()
} else {
std::env::var("DATABASE_URL")
.unwrap_or_else(|_| "postgres://postgres@localhost:5432/jirs".to_string())
.unwrap_or_else(|_| "postgres://postgres@localhost:5432/bitque".to_string())
};
Self {
concurrency: 2,

View File

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[derive(Deserialize, Serialize)]
pub struct Configuration {
pub store_path: String,
pub client_path: String,

View File

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[derive(Deserialize, Serialize)]
pub struct Configuration {
pub concurrency: usize,
#[serde(default = "Configuration::default_theme")]

View File

@ -1,5 +1,5 @@
#[cfg(feature = "aws-s3")]
pub mod amazon;
#[cfg(feature = "cloud-storage")]
pub mod cloud_storage;
#[cfg(feature = "database")]
pub mod database;

View File

@ -1,4 +1,4 @@
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(serde::Deserialize, serde::Serialize)]
pub struct Configuration {
pub concurrency: usize,
pub user: String,
@ -14,7 +14,7 @@ impl Default for Configuration {
user: "apikey".to_string(),
pass: "YOUR-TOKEN".to_string(),
host: "smtp.sendgrid.net".to_string(),
from: "contact@jirs.pl".to_string(),
from: "contact@bitque.pl".to_string(),
}
}
}

View File

@ -1,7 +1,8 @@
use {
serde::{de::DeserializeOwned, export::PhantomData, Serialize},
std::fs::{read_to_string, write},
};
use std::fs::{read_to_string, write};
use std::marker::PhantomData;
use serde::de::DeserializeOwned;
use serde::Serialize;
pub struct Reader<T: DeserializeOwned + Default + Serialize> {
__phantom: PhantomData<T>,

View File

@ -6,12 +6,13 @@ pub enum Protocol {
Https,
}
#[derive(Serialize, Deserialize)]
#[derive(Deserialize, Serialize)]
pub struct Configuration {
pub concurrency: usize,
pub port: String,
pub bind: String,
pub ssl: bool,
pub public_addr: Option<String>,
}
impl Default for Configuration {
@ -21,12 +22,20 @@ impl Default for Configuration {
port: "5000".to_string(),
bind: "0.0.0.0".to_string(),
ssl: false,
public_addr: None,
}
}
}
impl Configuration {
pub fn addr(&self) -> String {
match self.public_addr.as_deref() {
Some(s) => String::from(s),
_ => format!("{}:{}", self.bind, self.port),
}
}
pub fn bind_addr(&self) -> String {
format!("{}:{}", self.bind, self.port)
}

View File

@ -1,4 +1,4 @@
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(serde::Deserialize, serde::Serialize)]
pub struct Configuration {
pub concurrency: usize,
}

View File

@ -0,0 +1,30 @@
[package]
name = "bitque-data"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "bitque_data"
path = "./src/lib.rs"
[features]
backend = ["diesel", "actix", "diesel-derive-newtype"]
frontend = ['derive_enum_primitive']
[dependencies]
actix = { version = "0.13.0", optional = true }
chrono = { version = "*", features = ["serde"] }
diesel = { version = "2.0.3", features = ["postgres", "numeric", "uuid", "r2d2"], optional = true }
diesel-derive-enum = { version = "2.0.1", features = ["postgres"] }
derive_enum_primitive = { workspace = true, optional = true }
diesel-derive-more = { version = "1.1.3" }
diesel-derive-newtype = { version = "2.0.0-rc.0", optional = true }
serde = { version = "*" }
serde_json = { version = "*" }
strum = { version = "0.24.1", features = ['derive', 'strum_macros', 'std'] }
uuid = { version = "1.3.0", features = ["serde"] }

View File

@ -1,48 +1,50 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, PartialOrd, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
pub enum ProjectFieldId {
Name,
Url,
Description,
DescriptionMode,
Category,
TimeTracking,
IssueStatusName,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialOrd, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
pub enum SignInFieldId {
Username,
Email,
Token,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialOrd, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
pub enum SignUpFieldId {
Username,
Email,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialOrd, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
pub enum UsersFieldId {
Username,
Email,
UserRole,
Avatar,
CurrentProject,
TextEditorMode,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialOrd, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
pub enum InviteFieldId {
Token,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialOrd, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
pub enum CommentFieldId {
Body,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialOrd, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
pub enum IssueFieldId {
Type,
Title,
@ -60,7 +62,7 @@ pub enum IssueFieldId {
EpicEndsAt,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialOrd, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
pub enum EpicFieldId {
Name,
StartsAt,

View File

@ -1,18 +1,17 @@
use std::cmp::Ordering;
use chrono::NaiveDateTime;
use derive_enum_primitive::*;
#[cfg(feature = "backend")]
use diesel::*;
#[cfg(feature = "backend")]
use derive_enum_sql::EnumSql;
use {
chrono::NaiveDateTime,
derive_enum_iter::EnumIter,
derive_enum_primitive::EnumPrimitive,
serde::{Deserialize, Serialize},
std::cmp::Ordering,
std::str::FromStr,
uuid::Uuid,
};
pub use {fields::*, msg::WsMsg, payloads::*};
use diesel_derive_enum::DbEnum;
pub use fields::*;
pub use msg::WsMsg;
pub use payloads::*;
use serde::{Deserialize, Serialize};
use strum::*;
use uuid::Uuid;
pub mod fields;
pub mod msg;
@ -24,6 +23,7 @@ pub type ListPosition = i32;
pub type ProjectId = i32;
pub type ProjectName = String;
pub type UserId = i32;
pub type UserSettingId = i32;
pub type UserProjectId = i32;
pub type CommentId = i32;
pub type TokenId = i32;
@ -48,58 +48,89 @@ pub type Lang = String;
pub type BindToken = Uuid;
pub type InvitationToken = Uuid;
#[cfg_attr(feature = "backend", derive(FromSqlRow, AsExpression, EnumSql))]
#[cfg_attr(feature = "backend", sql_type = "IssueTypeType")]
pub type StartsAt = NaiveDateTime;
pub type EndsAt = NaiveDateTime;
#[cfg_attr(feature = "backend", derive(DbEnum))]
#[derive(
Clone, Copy, Deserialize, Serialize, Debug, PartialOrd, PartialEq, Hash, EnumIter, EnumPrimitive,
Clone,
Copy,
Debug,
Default,
Deserialize,
Display,
EnumAsStr,
EnumIter,
EnumLabel,
EnumString,
EnumU32,
Hash,
IntoStaticStr,
PartialEq,
PartialOrd,
Serialize,
)]
#[strum(serialize_all = "snake_case")]
#[cfg_attr(feature = "backend", PgType = "IssueTypeMapping")]
pub enum IssueType {
#[default]
Task,
Bug,
Story,
}
impl Default for IssueType {
fn default() -> Self {
IssueType::Task
}
}
impl std::fmt::Display for IssueType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_str())
}
}
#[cfg_attr(feature = "backend", derive(FromSqlRow, AsExpression, EnumSql))]
#[cfg_attr(feature = "backend", sql_type = "IssuePriorityType")]
#[cfg_attr(feature = "backend", derive(DbEnum))]
#[derive(
Clone, Copy, Deserialize, Serialize, Debug, PartialOrd, PartialEq, Hash, EnumIter, EnumPrimitive,
Clone,
Copy,
Debug,
Default,
Deserialize,
Display,
EnumAsStr,
EnumIter,
EnumLabel,
EnumString,
EnumU32,
Hash,
IntoStaticStr,
PartialEq,
PartialOrd,
Serialize,
)]
#[strum(serialize_all = "snake_case")]
#[cfg_attr(feature = "backend", PgType = "IssuePriorityMapping")]
pub enum IssuePriority {
Highest,
High,
#[default]
Medium,
Low,
Lowest,
}
impl Default for IssuePriority {
fn default() -> Self {
IssuePriority::Medium
}
}
impl std::fmt::Display for IssuePriority {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_str())
}
}
#[cfg_attr(feature = "backend", derive(FromSqlRow, AsExpression, EnumSql))]
#[cfg_attr(feature = "backend", sql_type = "UserRoleType")]
#[derive(Clone, Copy, Deserialize, Serialize, Debug, PartialEq, Hash, EnumIter, EnumPrimitive)]
#[cfg_attr(feature = "backend", derive(DbEnum))]
#[derive(
Clone,
Copy,
Debug,
Default,
Deserialize,
Display,
EnumAsStr,
EnumIter,
EnumLabel,
EnumString,
EnumU32,
Hash,
IntoStaticStr,
PartialEq,
Serialize,
)]
#[strum(serialize_all = "snake_case")]
#[cfg_attr(feature = "backend", PgType = "UserRoleMapping")]
pub enum UserRole {
#[default]
User,
Manager,
Owner,
@ -120,82 +151,93 @@ impl PartialOrd for UserRole {
}
}
impl Default for UserRole {
fn default() -> Self {
UserRole::User
}
}
impl std::fmt::Display for UserRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_str())
}
}
#[cfg_attr(feature = "backend", derive(FromSqlRow, AsExpression, EnumSql))]
#[cfg_attr(feature = "backend", sql_type = "ProjectCategoryType")]
#[cfg_attr(feature = "backend", derive(DbEnum))]
#[cfg_attr(feature = "backend", PgType = "ProjectCategoryMapping")]
#[derive(
Clone, Copy, Deserialize, Serialize, Debug, PartialOrd, PartialEq, Hash, EnumIter, EnumPrimitive,
Clone,
Copy,
Debug,
Default,
Deserialize,
Display,
EnumAsStr,
EnumIter,
EnumLabel,
EnumString,
EnumU32,
Hash,
IntoStaticStr,
PartialEq,
PartialOrd,
Serialize,
)]
#[strum(serialize_all = "snake_case")]
#[cfg_attr(feature = "backend", PgType = "ProjectCategoryMapping")]
pub enum ProjectCategory {
#[default]
Software,
Marketing,
Business,
}
impl Default for ProjectCategory {
fn default() -> Self {
ProjectCategory::Software
}
}
impl std::fmt::Display for ProjectCategory {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_str())
}
}
#[cfg_attr(feature = "backend", derive(FromSqlRow, AsExpression, EnumSql))]
#[cfg_attr(feature = "backend", sql_type = "InvitationStateType")]
#[cfg_attr(feature = "backend", derive(DbEnum))]
#[cfg_attr(feature = "backend", PgType = "InvitationStateMapping")]
#[derive(
Clone, Copy, Deserialize, Serialize, Debug, PartialOrd, PartialEq, Hash, EnumIter, EnumPrimitive,
Clone,
Copy,
Debug,
Default,
Deserialize,
Display,
EnumAsStr,
EnumIter,
EnumString,
EnumU32,
Hash,
IntoStaticStr,
PartialEq,
PartialOrd,
Serialize,
)]
#[strum(serialize_all = "snake_case")]
#[cfg_attr(feature = "backend", PgType = "InvitationStateMapping")]
pub enum InvitationState {
#[default]
Sent,
Accepted,
Revoked,
}
impl Default for InvitationState {
fn default() -> Self {
InvitationState::Sent
}
}
impl std::fmt::Display for InvitationState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_str())
}
}
#[cfg_attr(feature = "backend", derive(FromSqlRow, AsExpression, EnumSql))]
#[cfg_attr(feature = "backend", sql_type = "TimeTrackingType")]
#[cfg_attr(feature = "backend", derive(DbEnum))]
#[cfg_attr(feature = "backend", PgType = "TimeTrackingMapping")]
#[derive(
Clone, Copy, Deserialize, Serialize, Debug, PartialOrd, PartialEq, Hash, EnumIter, EnumPrimitive,
Clone,
Copy,
Debug,
Default,
Deserialize,
Display,
EnumAsStr,
EnumIter,
EnumLabel,
EnumString,
EnumU32,
Hash,
IntoStaticStr,
PartialEq,
PartialOrd,
Serialize,
)]
#[strum(serialize_all = "snake_case")]
#[cfg_attr(feature = "backend", PgType = "TimeTrackingMapping")]
pub enum TimeTracking {
#[default]
Untracked,
Fibonacci,
Hourly,
}
impl Default for TimeTracking {
fn default() -> Self {
Self::Untracked
}
}
#[derive(Clone, Serialize, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct ErrorResponse {
pub errors: Vec<String>,
}
@ -209,7 +251,7 @@ impl ErrorResponse {
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Project {
pub id: ProjectId,
pub name: String,
@ -221,7 +263,13 @@ pub struct Project {
pub time_tracking: TimeTracking,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
impl Project {
pub fn name(&self) -> &str {
&self.name
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Issue {
pub id: EpicId,
pub title: String,
@ -244,18 +292,18 @@ pub struct Issue {
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct IssueStatus {
pub id: IssueStatusId,
pub name: String,
pub position: ProjectId,
pub position: ListPosition,
pub project_id: ProjectId,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Invitation {
pub id: InvitationId,
pub name: String,
@ -270,7 +318,7 @@ pub struct Invitation {
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Comment {
pub id: CommentId,
pub body: String,
@ -281,7 +329,7 @@ pub struct Comment {
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct User {
pub id: UserId,
pub name: String,
@ -291,8 +339,14 @@ pub struct User {
pub updated_at: NaiveDateTime,
}
impl User {
pub fn name(&self) -> &str {
&self.name
}
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct UserProject {
pub id: UserProjectId,
pub user_id: UserId,
@ -305,7 +359,7 @@ pub struct UserProject {
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Token {
pub id: TokenId,
pub user_id: UserId,
@ -317,7 +371,7 @@ pub struct Token {
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct IssueAssignee {
pub id: i32,
pub issue_id: EpicId,
@ -326,31 +380,36 @@ pub struct IssueAssignee {
pub updated_at: NaiveDateTime,
}
#[cfg_attr(feature = "backend", derive(FromSqlRow, AsExpression, EnumSql))]
#[cfg_attr(feature = "backend", sql_type = "MessageTypeType")]
#[cfg_attr(feature = "backend", derive(DbEnum))]
#[cfg_attr(feature = "backend", PgType = "MessageTypeMapping")]
#[derive(
Clone, Copy, Deserialize, Serialize, Debug, PartialOrd, PartialEq, Hash, EnumPrimitive,
Clone,
Copy,
Debug,
Default,
Deserialize,
Display,
EnumAsStr,
EnumLabel,
EnumString,
EnumU32,
Hash,
IntoStaticStr,
PartialEq,
PartialOrd,
Serialize,
)]
#[strum(serialize_all = "snake_case")]
#[cfg_attr(feature = "backend", PgType = "MessageTypeMapping")]
pub enum MessageType {
ReceivedInvitation,
AssignedToIssue,
#[default]
Mention,
}
impl Default for MessageType {
fn default() -> Self {
Self::Mention
}
}
impl std::fmt::Display for MessageType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_label())
}
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Message {
pub id: MessageId,
pub receiver_id: UserId,
@ -364,7 +423,7 @@ pub struct Message {
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Epic {
pub id: EpicId,
pub name: NameString,
@ -372,8 +431,8 @@ pub struct Epic {
pub project_id: ProjectId,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
pub starts_at: Option<NaiveDateTime>,
pub ends_at: Option<NaiveDateTime>,
pub starts_at: Option<StartsAt>,
pub ends_at: Option<EndsAt>,
pub description: Option<DescriptionString>,
pub description_html: Option<DescriptionString>,
}
@ -384,7 +443,7 @@ pub static BOLD: FontStyle = 1;
pub static UNDERLINE: FontStyle = 2;
pub static ITALIC: FontStyle = 4;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Color {
/// Red component
pub r: u8,
@ -396,7 +455,7 @@ pub struct Color {
pub a: u8,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Style {
/// Foreground color
pub foreground: Color,
@ -406,7 +465,45 @@ pub struct Style {
pub font_style: FontStyle,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct HighlightedCode {
pub parts: Vec<(Style, String)>,
}
#[cfg_attr(feature = "backend", derive(DbEnum))]
#[derive(
Clone,
Copy,
Debug,
Default,
Deserialize,
Display,
EnumAsStr,
EnumIter,
EnumLabel,
EnumString,
EnumU32,
Hash,
IntoStaticStr,
PartialEq,
PartialOrd,
Serialize,
)]
#[strum(serialize_all = "snake_case")]
#[cfg_attr(feature = "backend", PgType = "TextEditorModeMapping")]
#[repr(C)]
#[cfg_attr(feature = "backend", PgType = "TextEditorModeMapping")]
pub enum TextEditorMode {
#[default]
MdOnly,
RteOnly,
Mixed,
}
#[cfg_attr(feature = "backend", derive(Queryable))]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct UserSetting {
pub id: UserSettingId,
pub user_id: UserId,
pub text_editor_mode: TextEditorMode,
}

View File

@ -1,18 +1,17 @@
use crate::DescriptionString;
use {
crate::{
AvatarUrl, BindToken, Code, Comment, CommentId, CreateCommentPayload, CreateIssuePayload,
EmailString, Epic, EpicId, HighlightedCode, Invitation, InvitationId, InvitationToken,
Issue, IssueFieldId, IssueId, IssueStatus, IssueStatusId, IssueType, Lang, ListPosition,
Message, MessageId, NameString, NumberOfDeleted, PayloadVariant, Position, Project,
TitleString, UpdateCommentPayload, UpdateProjectPayload, User, UserId, UserProject,
UserProjectId, UserRole, UsernameString,
},
serde::{Deserialize, Serialize},
uuid::Uuid,
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::{
AvatarUrl, BindToken, Code, Comment, CommentId, CreateCommentPayload, CreateIssuePayload,
DescriptionString, EmailString, EndsAt, Epic, EpicId, HighlightedCode, Invitation,
InvitationId, InvitationToken, Issue, IssueFieldId, IssueId, IssueStatus, IssueStatusId,
IssueType, Lang, ListPosition, Message, MessageId, NameString, NumberOfDeleted, PayloadVariant,
Position, Project, StartsAt, TextEditorMode, TitleString, UpdateCommentPayload,
UpdateProjectPayload, User, UserId, UserProject, UserProjectId, UserRole, UserSetting,
UsernameString,
};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[repr(C)]
pub enum WsError {
InvalidLoginPair,
@ -120,28 +119,70 @@ impl WsError {
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum WsMsg {
Ping,
Pong,
Die,
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct IssueSync {
pub id: IssueId,
pub list_position: ListPosition,
pub issue_status_id: IssueStatusId,
pub epic_id: Option<IssueId>,
}
// auth
AuthorizeLoad(Uuid),
AuthorizeLoaded(Result<User, String>),
AuthorizeExpired,
AuthenticateRequest(EmailString, UsernameString),
AuthenticateSuccess,
BindTokenCheck(Uuid),
BindTokenBad,
BindTokenOk(Uuid),
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsgIssue {
IssueUpdate(IssueId, IssueFieldId, PayloadVariant),
IssueUpdated(Issue),
IssueDelete(IssueId),
IssueDeleted(IssueId, NumberOfDeleted),
IssueCreate(CreateIssuePayload),
IssueCreated(Issue),
IssueSyncListPosition(Vec<IssueSync>),
IssueSyncedListPosition(Vec<IssueSync>),
}
// Sign up
SignUpRequest(EmailString, UsernameString),
SignUpSuccess,
SignUpPairTaken,
impl From<WsMsgIssue> for WsMsg {
fn from(msg: WsMsgIssue) -> Self {
WsMsg::Issue(msg)
}
}
// invitations
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsgIssueStatus {
IssueStatusesLoad,
IssueStatusesLoaded(Vec<IssueStatus>),
IssueStatusUpdate(IssueStatusId, TitleString, Position),
IssueStatusUpdated(IssueStatus),
IssueStatusCreate(TitleString, Position),
IssueStatusCreated(IssueStatus),
IssueStatusDelete(IssueStatusId),
IssueStatusDeleted(IssueStatusId, NumberOfDeleted),
}
impl From<WsMsgIssueStatus> for WsMsg {
fn from(msg: WsMsgIssueStatus) -> Self {
WsMsg::IssueStatus(msg)
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsgComment {
IssueCommentsLoad(IssueId),
IssueCommentsLoaded(Vec<Comment>),
CommentCreate(CreateCommentPayload),
CommentCreated(Comment),
CommentUpdate(UpdateCommentPayload),
CommentUpdated(Comment),
CommentDelete(CommentId),
CommentDeleted(CommentId, NumberOfDeleted),
}
impl From<WsMsgComment> for WsMsg {
fn from(msg: WsMsgComment) -> Self {
WsMsg::Comment(msg)
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsgInvitation {
InvitationListLoad,
InvitationListLoaded(Vec<Invitation>),
//
@ -169,65 +210,16 @@ pub enum WsMsg {
//
InvitedUserRemoveRequest(UserId),
InvitedUserRemoveSuccess(UserId),
}
// project page
ProjectsLoad,
ProjectsLoaded(Vec<Project>),
impl From<WsMsgInvitation> for WsMsg {
fn from(msg: WsMsgInvitation) -> Self {
WsMsg::Invitation(msg)
}
}
ProjectIssuesLoad,
ProjectIssuesLoaded(Vec<Issue>),
ProjectUsersLoad,
ProjectUsersLoaded(Vec<User>),
ProjectUpdateLoad(UpdateProjectPayload),
// issue
IssueUpdate(IssueId, IssueFieldId, PayloadVariant),
IssueUpdated(Issue),
IssueDelete(IssueId),
IssueDeleted(IssueId, NumberOfDeleted),
IssueCreate(CreateIssuePayload),
IssueCreated(Issue),
IssueSyncListPosition(Vec<(IssueId, ListPosition, IssueStatusId, Option<IssueId>)>),
// issue status
IssueStatusesLoad,
IssueStatusesLoaded(Vec<IssueStatus>),
IssueStatusUpdate(IssueStatusId, TitleString, Position),
IssueStatusUpdated(IssueStatus),
IssueStatusCreate(TitleString, Position),
IssueStatusCreated(IssueStatus),
IssueStatusDelete(IssueStatusId),
IssueStatusDeleted(IssueStatusId, NumberOfDeleted),
// comments
IssueCommentsLoad(IssueId),
IssueCommentsLoaded(Vec<Comment>),
CommentCreate(CreateCommentPayload),
CommentCreated(Comment),
CommentUpdate(UpdateCommentPayload),
CommentUpdated(Comment),
CommentDelete(CommentId),
CommentDeleted(CommentId, NumberOfDeleted),
// users
AvatarUrlChanged(UserId, AvatarUrl),
ProfileUpdate(EmailString, UsernameString),
ProfileUpdated,
// user projects
UserProjectsLoad,
UserProjectsLoaded(Vec<UserProject>),
UserProjectSetCurrent(UserProjectId),
UserProjectCurrentChanged(UserProject),
// messages
MessageUpdated(Message),
MessagesLoad,
MessagesLoaded(Vec<Message>),
MessageMarkSeen(MessageId),
MessageMarkedSeen(MessageId, NumberOfDeleted),
// epics
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsgEpic {
EpicsLoad,
EpicsLoaded(Vec<Epic>),
EpicCreate(
@ -236,11 +228,112 @@ pub enum WsMsg {
Option<DescriptionString>,
),
EpicCreated(Epic),
EpicUpdate(EpicId, NameString),
EpicUpdateName(EpicId, NameString),
EpicUpdateStartsAt(EpicId, Option<StartsAt>),
EpicUpdateEndsAt(EpicId, Option<EndsAt>),
EpicUpdated(Epic),
EpicDelete(EpicId),
EpicDeleted(EpicId, NumberOfDeleted),
EpicTransform(EpicId, IssueType),
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsgProject {
ProjectsLoad,
ProjectsLoaded(Vec<Project>),
ProjectIssuesLoad,
ProjectIssuesLoaded(Vec<Issue>),
ProjectUsersLoad,
ProjectUsersLoaded(Vec<User>),
ProjectUpdateLoad(UpdateProjectPayload),
}
impl From<WsMsgProject> for WsMsg {
fn from(msg: WsMsgProject) -> Self {
WsMsg::Project(msg)
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsgSession {
// auth
AuthorizeLoad(Uuid),
AuthorizeLoaded(Result<(User, UserSetting), String>),
AuthorizeExpired,
AuthenticateRequest(EmailString, UsernameString),
AuthenticateSuccess,
BindTokenCheck(Uuid),
BindTokenBad,
BindTokenOk(Uuid),
// Sign up
SignUpRequest(EmailString, UsernameString),
SignUpSuccess,
SignUpPairTaken,
}
impl From<WsMsgSession> for WsMsg {
fn from(msg: WsMsgSession) -> WsMsg {
WsMsg::Session(msg)
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsgUser {
// users
AvatarUrlChanged(UserId, AvatarUrl),
ProfileUpdate(EmailString, UsernameString),
ProfileUpdated,
// user settings
UserSettingUpdated(UserSetting),
UserSettingSetEditorMode(TextEditorMode),
}
impl From<WsMsgUser> for WsMsg {
fn from(msg: WsMsgUser) -> WsMsg {
WsMsg::User(msg)
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsgMessage {
// messages
MessageUpdated(Message),
MessagesLoad,
MessagesLoaded(Vec<Message>),
MessageMarkSeen(MessageId),
MessageMarkedSeen(MessageId, NumberOfDeleted),
}
impl From<WsMsgMessage> for WsMsg {
fn from(msg: WsMsgMessage) -> WsMsg {
WsMsg::Message(msg)
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum WsMsg {
Ping,
Pong,
Die,
Session(WsMsgSession),
Invitation(WsMsgInvitation),
Project(WsMsgProject),
Issue(WsMsgIssue),
IssueStatus(WsMsgIssueStatus),
Comment(WsMsgComment),
User(WsMsgUser),
Message(WsMsgMessage),
Epic(WsMsgEpic),
// user projects
UserProjectsLoad,
UserProjectsLoaded(Vec<UserProject>),
UserProjectSetCurrent(UserProjectId),
UserProjectCurrentChanged(UserProject),
// highlight
HighlightCode(Lang, Code),

View File

@ -1,25 +1,24 @@
use {
crate::{
CommentId, EpicId, Issue, IssueId, IssuePriority, IssueStatusId, IssueType,
ProjectCategory, ProjectId, TimeTracking, UserId,
},
serde::{Deserialize, Serialize},
use serde::{Deserialize, Serialize};
use crate::{
CommentId, EpicId, Issue, IssueId, IssuePriority, IssueStatusId, IssueType, ProjectCategory,
ProjectId, TimeTracking, UserId,
};
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CreateCommentPayload {
pub user_id: Option<UserId>,
pub issue_id: IssueId,
pub body: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct UpdateCommentPayload {
pub id: CommentId,
pub body: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CreateIssuePayload {
pub title: String,
pub issue_type: IssueType,
@ -36,7 +35,7 @@ pub struct CreateIssuePayload {
pub epic_id: Option<EpicId>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct UpdateProjectPayload {
pub id: ProjectId,
pub name: Option<String>,
@ -46,7 +45,7 @@ pub struct UpdateProjectPayload {
pub time_tracking: Option<TimeTracking>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum PayloadVariant {
OptionI32(Option<i32>),
VecI32(Vec<i32>),
@ -57,7 +56,7 @@ pub enum PayloadVariant {
ProjectCategory(ProjectCategory),
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, PartialOrd)]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct UpdateIssuePayload {
pub title: String,
pub issue_type: IssueType,

View File

@ -0,0 +1,38 @@
[package]
name = "bitque"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "BITQUE (Simplified JIRA in Rust) Actix server"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"
[features]
cloud-storage = ["cloud-storage-actor"]
local-storage = ["filesystem-actor"]
default = ["local-storage"]
[dependencies]
actix = { version = "0" }
actix-rt = { version = "2" }
actix-web = { version = "4" }
cloud-storage-actor = { workspace = true, optional = true }
bitque-config = { workspace = true, features = ["web", "websocket", "local-storage", "hi", "database"] }
bitque-data = { workspace = true, features = ["backend"] }
database-actor = { workspace = true }
dotenv = { version = "*" }
filesystem-actor = { workspace = true, optional = true }
futures = { version = "*" }
highlight-actor = { workspace = true }
libc = { version = "0.2.0", default-features = false }
mail-actor = { workspace = true }
openssl-sys = { version = "*", features = ["vendored"] }
serde = { version = "*", features = ["derive"] }
serde_json = { version = ">=0.8.0, <2.0" }
tokio = { version = "1", features = ["full"] }
toml = { version = "0.7.3" }
tracing = { version = "0" }
tracing-subscriber = { version = "0", features = ['env-filter', 'thread_local', 'serde_json'] }
web-actor = { workspace = true, features = ["local-storage"] }
websocket-actor = { workspace = true }

View File

@ -8,12 +8,12 @@ RUN rustup toolchain install nightly && \
RUN cargo install diesel_cli --no-default-features --features postgres
ADD jirs-server /app/jirs-server
ADD jirs-data /app/jirs-data
ADD bitque-server /app/bitque-server
ADD bitque-data /app/bitque-data
RUN pacman -Sy openssl openssh pkgconf --noconfirm
RUN pkg-config --libs openssl
CMD cd /app/jirs-server && \
CMD cd /app/bitque-server && \
$HOME/.cargo/bin/diesel setup --database-url=$DATABASE_URL && \
cargo run --bin jirs_server
cargo run --bin bitque_server

View File

@ -1,6 +1,6 @@
use actix_web::HttpResponse;
use jirs_data::{msg::WsError, ErrorResponse};
use bitque_data::msg::WsError;
use bitque_data::ErrorResponse;
const TOKEN_NOT_FOUND: &str = "Token not found";
const DATABASE_CONNECTION_FAILED: &str = "Database connection failed";

View File

@ -0,0 +1,84 @@
#![feature(async_closure)]
#![recursion_limit = "256"]
use actix::Actor;
use actix_web::web::Data;
use actix_web::{App, HttpServer};
use tracing::info;
use tracing_subscriber::util::SubscriberInitExt;
pub mod errors;
macro_rules! featured {
($app: ident, $feature: expr, $connect: expr) => {
#[cfg(feature = $feature)]
let $app = $connect;
};
}
#[actix_rt::main]
async fn main() -> Result<(), String> {
dotenv::dotenv().ok();
tracing_subscriber::fmt::fmt()
.with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env())
.finish()
.init();
let web_config = bitque_config::web::Configuration::read();
let db_addr = actix::SyncArbiter::start(
bitque_config::database::Configuration::read().concurrency,
database_actor::DbExecutor::default,
);
let mail_addr = actix::SyncArbiter::start(
bitque_config::mail::Configuration::read().concurrency,
mail_actor::MailExecutor::default,
);
let hi_addr = actix::SyncArbiter::start(
bitque_config::hi::Configuration::read().concurrency,
highlight_actor::HighlightActor::default,
);
#[cfg(feature = "local-storage")]
let fs_addr = actix::SyncArbiter::start(
bitque_config::fs::Configuration::read().concurrency,
filesystem_actor::LocalStorageExecutor::default,
);
#[cfg(feature = "cloud-storage")]
let cloud_storage_addr = actix::SyncArbiter::start(
bitque_config::web::Configuration::read().concurrency,
cloud_storage_actor::CloudStorageExecutor::default,
);
let ws_server = websocket_actor::server::WsServer::start_default();
info!("Listen at {}", web_config.bind_addr());
HttpServer::new(move || {
let app = App::new().wrap(actix_web::middleware::Logger::default());
// data step
let app = app
.app_data(Data::new(ws_server.clone()))
.app_data(Data::new(db_addr.clone()))
.app_data(Data::new(mail_addr.clone()))
.app_data(Data::new(hi_addr.clone()))
.app_data(Data::new(database_actor::build_pool()));
featured! { app, "local-storage", app.app_data(Data::new(fs_addr.clone())) };
featured! { app, "cloud-storage", app.app_data(Data::new(cloud_storage_addr.clone())) };
// services step
let app = app
.service(websocket_actor::index)
.service(actix_web::web::scope("/avatar").service(web_actor::avatar::upload));
featured! { app, "local-storage", app.service(filesystem_actor::service()) };
app
})
.workers(web_config.concurrency)
.bind(web_config.bind_addr())
.map_err(|e| format!("{}", e))?
.run()
.await
.expect("Server internal error");
Ok(())
}

View File

@ -0,0 +1,19 @@
[package]
name = "cloud-storage-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"
[dependencies]
actix = { version = "0.13.0" }
bitque-config = { workspace = true, features = ["mail", "web", "local-storage"] }
bytes = { version = "1" }
tokio = { version = "1", features = ["full"] }
tracing = { version = "0.1.37" }
rust-s3 = { version = "*" }
aws-creds = { version = "=0.30.0", features = ['attohttpc'] }
thiserror = { version = "*" }

View File

@ -0,0 +1,96 @@
use std::str::FromStr;
use awscreds::Credentials;
use s3::Region;
use tracing::warn;
#[derive(Debug, thiserror::Error)]
pub enum AmazonError {
#[error("File upload to external storage failed")]
UploadFailed,
#[error("Failed to connect to bucket")]
ConnectBucket,
#[error("Malformed external storage credentials")]
Credentials,
}
pub struct CloudStorageExecutor;
impl Default for CloudStorageExecutor {
fn default() -> Self {
Self {}
}
}
impl actix::Actor for CloudStorageExecutor {
type Context = actix::SyncContext<Self>;
}
#[derive(actix::Message)]
#[rtype(result = "Result<String, AmazonError>")]
pub struct PutObject {
pub source: tokio::sync::broadcast::Receiver<bytes::Bytes>,
pub file_name: String,
pub dir: String,
}
impl actix::Handler<PutObject> for CloudStorageExecutor {
type Result = Result<String, AmazonError>;
fn handle(&mut self, msg: PutObject, _ctx: &mut Self::Context) -> Self::Result {
let PutObject {
// source,
mut source,
file_name,
dir,
} = msg;
bitque_config::cloud_storage::config().set_variables();
tokio::runtime::Runtime::new()
.expect("Failed to start amazon agent")
.block_on(async {
let s3 = bitque_config::cloud_storage::config();
tracing::debug!("{:?}", s3);
let mut v: Vec<u8> = Vec::with_capacity(1024 * 1024 * 16);
while let Ok(b) = source.recv().await {
v.extend_from_slice(&b)
}
let config = bitque_config::cloud_storage::config();
let bucket = s3::Bucket::new(
config.bucket.as_str(),
Region::from_str(config.region_name.as_str()).unwrap(),
Credentials::new(
Some(config.access_key_id.as_str()),
Some(config.secret_access_key.as_str()),
None,
None,
None,
)
.map_err(|e| {
warn!("{e}");
AmazonError::Credentials
})?,
)
.map_err(|e| {
warn!("{e}");
AmazonError::ConnectBucket
})?
.with_path_style();
let put = bucket
.put_object(format!("{dir}/{file_name}").as_str(), &v)
.await
.map_err(|e| {
warn!("{e}");
AmazonError::UploadFailed
})?;
if put.status_code() >= 300 {
// Error
Err(AmazonError::UploadFailed)
} else {
Ok(format!("{}/{}", bucket.url(), file_name))
}
})
}
}

View File

@ -0,0 +1,42 @@
[package]
name = "database-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "database_actor"
path = "./src/lib.rs"
[dependencies]
actix = { version = "0.13.0" }
bigdecimal = { version = "0.3.0" }
bincode = { version = "*" }
bitflags = { version = "2.0.2" }
bitque-config = { workspace = true, features = ["database"] }
bitque-data = { workspace = true, features = ["backend"] }
byteorder = { version = "1.0" }
chrono = { version = "0.4", features = ["serde"] }
derive_db_execute = { workspace = true }
diesel = { version = "2.0.3", features = ["postgres", "numeric", "uuid", "r2d2", "chrono"] }
dotenv = { version = "*" }
futures = { version = "0.3.8" }
ipnetwork = { version = "0.20.0" }
libc = { version = "0.2.0", default-features = false }
num-bigint = { version = "0.4.3" }
num-integer = { version = "0.1.32" }
num-traits = { version = "0.2" }
openssl-sys = { version = "*", features = ["vendored"] }
percent-encoding = { version = "2.1.0" }
pq-sys = { version = ">=0.3.0, <0.5.0" }
r2d2 = { version = ">= 0.8, < 0.9" }
serde = { version = "*" }
time = { version = "0.3.20" }
toml = { version = "*" }
tracing = { version = "0.1.37" }
url = { version = "2.1.0" }
uuid = { version = "1.3.0", features = ["serde", "v4", "v5"] }

View File

@ -0,0 +1,141 @@
diff --git a/crates/database-actor/src/schema.rs b/crates/database-actor/src/schema.rs
index 34a35365..a8f775b2 100644
--- a/crates/database-actor/src/schema.rs
+++ b/crates/database-actor/src/schema.rs
@@ -37,19 +37,19 @@ diesel::table! {
use bitque_data::*;
invitations (id) {
id -> Int4,
name -> Text,
email -> Text,
- state -> InvitationState,
+ state -> InvitationStateMapping,
project_id -> Int4,
invited_by_id -> Int4,
created_at -> Timestamp,
updated_at -> Timestamp,
bind_token -> Uuid,
- role -> UserRole,
+ role -> UserRoleMapping,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
@@ -81,14 +81,14 @@ diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
issues (id) {
id -> Int4,
title -> Text,
- issue_type -> IssueType,
- priority -> IssuePriority,
+ issue_type -> IssueTypeMapping,
+ priority -> IssuePriorityMapping,
list_position -> Int4,
description -> Nullable<Text>,
description_text -> Nullable<Text>,
estimate -> Nullable<Int4>,
time_spent -> Nullable<Int4>,
time_remaining -> Nullable<Int4>,
@@ -108,13 +108,13 @@ diesel::table! {
messages (id) {
id -> Int4,
receiver_id -> Int4,
sender_id -> Int4,
summary -> Text,
description -> Text,
- message_type -> MessageType,
+ message_type -> MessageTypeMapping,
hyper_link -> Text,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}
@@ -124,16 +124,16 @@ diesel::table! {
projects (id) {
id -> Int4,
name -> Text,
url -> Text,
description -> Text,
- category -> ProjectCategory,
+ category -> ProjectCategoryMapping,
created_at -> Timestamp,
updated_at -> Timestamp,
- time_tracking -> TimeTracking,
+ time_tracking -> TimeTrackingMapping,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
@@ -156,26 +156,26 @@ diesel::table! {
user_projects (id) {
id -> Int4,
user_id -> Int4,
project_id -> Int4,
is_default -> Bool,
is_current -> Bool,
- role -> UserRole,
+ role -> UserRoleMapping,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
user_settings (id) {
id -> Int4,
user_id -> Int4,
- text_editor_mode -> TextEditorMode,
+ text_editor_mode -> TextEditorModeMapping,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
@@ -205,20 +205,20 @@ diesel::joinable!(issues -> projects (project_id));
diesel::joinable!(issues -> users (reporter_id));
diesel::joinable!(tokens -> users (user_id));
diesel::joinable!(user_projects -> projects (project_id));
diesel::joinable!(user_projects -> users (user_id));
diesel::joinable!(user_settings -> users (user_id));
-diesel::allow_tables_to_appear_in_same_query!(
- comments,
- epics,
- invitations,
- issue_assignees,
- issue_statuses,
- issues,
- messages,
- projects,
- tokens,
- user_projects,
- user_settings,
- users,
-);
+// diesel::allow_tables_to_appear_in_same_query!(
+// comments,
+// epics,
+// invitations,
+// issue_assignees,
+// issue_statuses,
+// issues,
+// messages,
+// projects,
+// tokens,
+// user_projects,
+// user_settings,
+// users,
+// );

View File

@ -1,8 +1,8 @@
use {
crate::{db_find, tokens::FindAccessToken},
diesel::prelude::*,
jirs_data::User,
};
use bitque_data::User;
use diesel::prelude::*;
use crate::db_find;
use crate::tokens::FindAccessToken;
db_find! {
AuthorizeUser,

View File

@ -1,8 +1,7 @@
use {
crate::{db_create, db_delete, db_load, db_update},
diesel::prelude::*,
jirs_data::{Comment, CommentId, IssueId, UserId},
};
use bitque_data::{Comment, CommentId, IssueId, UserId};
use diesel::prelude::*;
use crate::{db_create, db_delete, db_load, db_update};
db_load! {
LoadIssueComments,

View File

@ -1,11 +1,9 @@
use {
crate::{db_create, db_delete, db_load, db_update},
derive_db_execute::Execute,
diesel::prelude::*,
jirs_data::{DescriptionString, Epic, EpicId, ProjectId},
};
use bitque_data::{DescriptionString, EndsAt, Epic, EpicId, ProjectId, StartsAt};
use diesel::prelude::*;
#[derive(Execute)]
use crate::{db_create, db_delete, db_load, db_update};
#[derive(derive_db_execute::Execute)]
#[db_exec(schema = "epics", result = "Epic", find = "epics.find(msg.epic_id)")]
pub struct FindEpic {
pub epic_id: EpicId,
@ -36,7 +34,7 @@ db_create! {
}
db_update! {
UpdateEpic,
UpdateEpicName,
msg => epics => diesel::update(
epics
.filter(project_id.eq(msg.project_id))
@ -48,6 +46,32 @@ db_update! {
name => String
}
db_update! {
UpdateEpicStartsAt,
msg => epics => diesel::update(
epics
.filter(project_id.eq(msg.project_id))
.find(msg.epic_id),
).set(starts_at.eq(msg.starts_at)),
Epic,
epic_id => i32,
project_id => i32,
starts_at => Option<StartsAt>
}
db_update! {
UpdateEpicEndsAt,
msg => epics => diesel::update(
epics
.filter(project_id.eq(msg.project_id))
.find(msg.epic_id),
).set(ends_at.eq(msg.ends_at)),
Epic,
epic_id => i32,
project_id => i32,
ends_at => Option<EndsAt>
}
db_delete! {
DeleteEpic,
msg => epics => diesel::delete(

View File

@ -1,4 +1,4 @@
use jirs_data::{EmailString, UsernameString};
use bitque_data::{EmailString, UsernameString};
#[derive(Debug)]
pub enum OperationError {
@ -20,6 +20,7 @@ pub enum ResourceKind {
Project,
Token,
UserProject,
UserSetting,
User,
Comment,
}

View File

@ -0,0 +1,182 @@
use actix::{Handler, Message};
use bitque_data::{
EmailString, Invitation, InvitationId, InvitationState, InvitationToken, ProjectId, Token,
User, UserId, UserRole, UsernameString,
};
use diesel::prelude::*;
use crate::tokens::CreateBindToken;
use crate::users::{LookupUser, Register};
use crate::{
db_create, db_delete, db_find, db_load, db_pool, db_update, DatabaseError, DbExecutor,
DbPooledConn, InvitationError,
};
db_find! {
FindByBindToken,
msg => invitations => invitations.filter(bind_token.eq(msg.token)),
Invitation,
token => InvitationToken
}
db_load! {
ListInvitation,
msg => invitations => invitations
.filter(invited_by_id.eq(msg.user_id))
.filter(state.ne(InvitationState::Accepted))
.order_by(state.asc())
.then_order_by(updated_at.desc()),
Invitation,
user_id => UserId
}
db_create! {
CreateInvitation,
msg => invitations => diesel::insert_into(invitations).values((
name.eq(msg.name),
email.eq(msg.email),
state.eq(InvitationState::Sent),
project_id.eq(msg.project_id),
invited_by_id.eq(msg.user_id),
role.eq(msg.role),
)),
Invitation,
user_id => UserId,
project_id => ProjectId,
email => EmailString,
name => UsernameString,
role => UserRole
}
db_delete! {
DeleteInvitation,
msg => invitations => diesel::delete(invitations).filter(id.eq(msg.id)),
Invitation,
id => InvitationId
}
db_update! {
UpdateInvitationState,
msg => invitations => diesel::update(invitations)
.set((
state.eq(msg.state),
updated_at.eq(chrono::Utc::now().naive_utc()),
))
.filter(id.eq(msg.id)),
Invitation,
id => InvitationId,
state => InvitationState
}
pub struct RevokeInvitation {
pub id: InvitationId,
}
impl Message for RevokeInvitation {
type Result = Result<(), crate::DatabaseError>;
}
impl Handler<RevokeInvitation> for DbExecutor {
type Result = Result<(), crate::DatabaseError>;
fn handle(&mut self, msg: RevokeInvitation, _ctx: &mut Self::Context) -> Self::Result {
let mut conn = db_pool!(self);
UpdateInvitationState {
id: msg.id,
state: InvitationState::Revoked,
}
.execute(&mut conn)?;
Ok(())
}
}
pub struct AcceptInvitation {
pub invitation_token: InvitationToken,
}
impl AcceptInvitation {
pub fn execute(self, conn: &mut DbPooledConn) -> Result<Token, crate::DatabaseError> {
let mut res = Err(DatabaseError::DatabaseConnectionLost);
conn.transaction(|conn| {
res = self.exec_in_transaction(conn);
if res.is_err() {
Err(diesel::NotFound)
} else {
Ok(())
}
})
.ok();
res
}
fn exec_in_transaction(self, conn: &mut DbPooledConn) -> Result<Token, crate::DatabaseError> {
let invitation = FindByBindToken {
token: self.invitation_token,
}
.execute(conn)?;
if invitation.state == InvitationState::Revoked {
return Err(crate::DatabaseError::Invitation(
InvitationError::InvitationRevoked,
));
}
UpdateInvitationState {
id: invitation.id,
state: InvitationState::Accepted,
}
.execute(conn)?;
UpdateInvitationState {
id: invitation.id,
state: InvitationState::Accepted,
}
.execute(conn)?;
match {
Register {
name: invitation.name.clone(),
email: invitation.email.clone(),
project_id: Some(invitation.project_id),
role: UserRole::User,
}
.execute(conn)
} {
Ok(_) => (),
Err(crate::DatabaseError::User(crate::UserError::InvalidPair(..))) => (),
Err(e) => return Err(e),
};
let user: User = LookupUser {
name: invitation.name.clone(),
email: invitation.email.clone(),
}
.execute(conn)?;
CreateBindToken { user_id: user.id }.execute(conn)?;
crate::user_projects::CreateUserProject {
user_id: user.id,
project_id: invitation.project_id,
is_current: false,
is_default: false,
role: invitation.role,
}
.execute(conn)?;
crate::tokens::FindUserId { user_id: user.id }.execute(conn)
}
}
impl Message for AcceptInvitation {
type Result = Result<Token, crate::DatabaseError>;
}
impl Handler<AcceptInvitation> for DbExecutor {
type Result = Result<Token, crate::DatabaseError>;
fn handle(&mut self, msg: AcceptInvitation, _ctx: &mut Self::Context) -> Self::Result {
let mut conn = db_pool!(self);
msg.execute(&mut conn)
}
}

View File

@ -1,8 +1,8 @@
use {
crate::{db_create, db_delete, db_load, db_load_field},
diesel::{expression::dsl::not, prelude::*},
jirs_data::{IssueAssignee, IssueId, UserId},
};
use bitque_data::{IssueAssignee, IssueId, UserId};
use diesel::dsl::not;
use diesel::prelude::*;
use crate::{db_create, db_delete, db_load, db_load_field};
db_create! {
AsignMultiple,

View File

@ -1,8 +1,7 @@
use {
crate::{db_create, db_delete, db_load, db_update},
diesel::prelude::*,
jirs_data::{IssueStatus, IssueStatusId, Position, ProjectId, TitleString},
};
use bitque_data::{IssueStatus, IssueStatusId, Position, ProjectId, TitleString};
use diesel::prelude::*;
use crate::{db_create, db_delete, db_load, db_update};
db_load! {
LoadIssueStatuses,

View File

@ -1,11 +1,10 @@
use {
crate::models::Issue,
derive_db_execute::Execute,
diesel::{expression::sql_literal::sql, prelude::*},
jirs_data::{IssueId, IssuePriority, IssueStatusId, IssueType, ProjectId, UserId},
};
use bitque_data::{IssueId, IssuePriority, IssueStatusId, IssueType, ProjectId, UserId};
use diesel::dsl::sql;
use diesel::prelude::*;
#[derive(Default, Execute)]
use crate::models::Issue;
#[derive(Default, derive_db_execute::Execute)]
#[db_exec(
result = "Issue",
schema = "issues",
@ -15,7 +14,7 @@ pub struct LoadIssue {
pub issue_id: IssueId,
}
#[derive(Execute)]
#[derive(derive_db_execute::Execute)]
#[db_exec(
result = "Issue",
schema = "issues",
@ -25,28 +24,28 @@ pub struct LoadProjectIssues {
pub project_id: ProjectId,
}
#[derive(Default, Execute)]
#[derive(Default, derive_db_execute::Execute)]
#[db_exec(result = "Issue", schema = "issues")]
pub struct UpdateIssue {
pub issue_id: jirs_data::IssueId,
pub issue_id: bitque_data::IssueId,
pub title: Option<String>,
pub issue_type: Option<IssueType>,
pub priority: Option<IssuePriority>,
pub list_position: Option<jirs_data::ListPosition>,
pub list_position: Option<bitque_data::ListPosition>,
pub description: Option<String>,
pub description_text: Option<String>,
pub estimate: Option<i32>,
pub time_spent: Option<i32>,
pub time_remaining: Option<i32>,
pub project_id: Option<jirs_data::ProjectId>,
pub user_ids: Option<Vec<jirs_data::UserId>>,
pub reporter_id: Option<jirs_data::UserId>,
pub issue_status_id: Option<jirs_data::IssueStatusId>,
pub epic_id: Option<Option<jirs_data::EpicId>>,
pub project_id: Option<bitque_data::ProjectId>,
pub user_ids: Option<Vec<bitque_data::UserId>>,
pub reporter_id: Option<bitque_data::UserId>,
pub issue_status_id: Option<bitque_data::IssueStatusId>,
pub epic_id: Option<Option<bitque_data::EpicId>>,
}
impl UpdateIssue {
fn execute(self, conn: &crate::DbPooledConn) -> Result<Issue, crate::DatabaseError> {
fn execute(self, conn: &mut crate::DbPooledConn) -> Result<Issue, crate::DatabaseError> {
let msg = self;
use crate::schema::issues::dsl::*;
if let Some(user_ids) = msg.user_ids {
@ -88,7 +87,7 @@ impl UpdateIssue {
))
.get_result(conn)
.map_err(|e| {
log::debug!("{:?}", e);
::tracing::debug!("{:?}", e);
crate::DatabaseError::GenericFailure(
crate::OperationError::Create,
crate::ResourceKind::Issue,
@ -97,7 +96,7 @@ impl UpdateIssue {
}
}
#[derive(Execute)]
#[derive(derive_db_execute::Execute)]
#[db_exec(
result = "Issue",
schema = "issues",
@ -112,12 +111,11 @@ pub struct DeleteIssue {
}
mod inner {
use {
crate::models::Issue,
derive_db_execute::Execute,
diesel::prelude::*,
jirs_data::{IssuePriority, IssueStatusId, IssueType},
};
use bitque_data::{IssuePriority, IssueStatusId, IssueType};
use derive_db_execute::Execute;
use diesel::prelude::*;
use crate::models::Issue;
#[derive(Default, Execute)]
#[db_exec(
@ -154,13 +152,13 @@ mod inner {
pub estimate: Option<i32>,
pub time_spent: Option<i32>,
pub time_remaining: Option<i32>,
pub project_id: jirs_data::ProjectId,
pub reporter_id: jirs_data::UserId,
pub epic_id: Option<jirs_data::EpicId>,
pub project_id: bitque_data::ProjectId,
pub reporter_id: bitque_data::UserId,
pub epic_id: Option<bitque_data::EpicId>,
}
}
#[derive(Execute)]
#[derive(derive_db_execute::Execute)]
#[db_exec(result = "Issue", schema = "issues")]
pub struct CreateIssue {
pub title: String,
@ -172,31 +170,39 @@ pub struct CreateIssue {
pub estimate: Option<i32>,
pub time_spent: Option<i32>,
pub time_remaining: Option<i32>,
pub project_id: jirs_data::ProjectId,
pub reporter_id: jirs_data::UserId,
pub user_ids: Vec<jirs_data::UserId>,
pub epic_id: Option<jirs_data::EpicId>,
pub project_id: ProjectId,
pub reporter_id: UserId,
pub user_ids: Vec<UserId>,
pub epic_id: Option<bitque_data::EpicId>,
}
impl CreateIssue {
fn execute(self, conn: &crate::DbPooledConn) -> Result<Issue, crate::DatabaseError> {
fn execute(self, conn: &mut crate::DbPooledConn) -> Result<Issue, crate::DatabaseError> {
use crate::schema::issues::dsl::*;
let msg = self;
let pos = issues
.select(sql("COALESCE(max(list_position), 0) + 1"))
.select(sql::<diesel::sql_types::Integer>(
"COALESCE(max(list_position), 0) + 1",
))
.get_result::<i32>(conn)
.map_err(|e| {
log::error!("resolve new issue position failed {}", e);
::tracing::error!("resolve new issue position failed {}", e);
crate::DatabaseError::Issue(crate::IssueError::BadListPosition)
})?;
let i_s_id: IssueStatusId = if msg.issue_status_id == 0 {
crate::issue_statuses::LoadIssueStatuses {
project_id: msg.project_id,
}
.execute(conn)?
.execute(conn)
.map_err(|e| {
::tracing::error!("Failed to find issue status. {:?}", e);
e
})?
.first()
.ok_or_else(|| crate::DatabaseError::Issue(crate::IssueError::NoIssueStatuses))?
.ok_or(crate::DatabaseError::Issue(
crate::IssueError::NoIssueStatuses,
))?
.id
} else {
msg.issue_status_id
@ -222,13 +228,24 @@ impl CreateIssue {
reporter_id: msg.reporter_id,
epic_id: msg.epic_id,
}
.execute(conn)?;
crate::issue_assignees::AsignMultiple {
issue_id: issue.id,
user_ids: assign_users,
};
.execute(conn)
.map_err(|e| {
::tracing::error!("Failed to insert issue. {:?}", e);
e
})?;
if !assign_users.is_empty() {
crate::issue_assignees::AsignMultiple {
issue_id: issue.id,
user_ids: assign_users,
}
.execute(conn)
.map_err(|e| {
::tracing::error!("Failed to apply multiple assignee to issue. {:?}", e);
e
})?;
}
issues.find(issue.id).get_result(conn).map_err(|e| {
log::error!("{:?}", e);
::tracing::error!("{:?}", e);
crate::DatabaseError::GenericFailure(
crate::OperationError::Create,
crate::ResourceKind::Issue,

View File

@ -0,0 +1,65 @@
#![recursion_limit = "256"]
#[macro_use]
extern crate diesel;
use actix::{Actor, SyncContext};
use diesel::pg::PgConnection;
use diesel::r2d2::{self, ConnectionManager};
pub use errors::*;
pub mod authorize_user;
pub mod comments;
pub mod epics;
pub mod errors;
pub mod invitations;
pub mod issue_assignees;
pub mod issue_statuses;
pub mod issues;
pub mod messages;
pub mod models;
pub mod prelude;
pub mod projects;
pub mod schema;
pub mod tokens;
pub mod user_projects;
pub mod user_settings;
pub mod users;
pub type DbPool = r2d2::Pool<ConnectionManager<PgConnection>>;
pub type DbPooledConn = r2d2::PooledConnection<ConnectionManager<PgConnection>>;
pub struct DbExecutor {
pub pool: DbPool,
pub config: bitque_config::database::Configuration,
}
impl Actor for DbExecutor {
type Context = SyncContext<Self>;
}
impl Default for DbExecutor {
fn default() -> Self {
Self {
pool: build_pool(),
config: bitque_config::database::Configuration::read(),
}
}
}
pub fn build_pool() -> DbPool {
dotenv::dotenv().ok();
let config = bitque_config::database::Configuration::read();
let manager = ConnectionManager::<PgConnection>::new(&config.database_url);
r2d2::Pool::builder()
.max_size(config.concurrency as u32)
.build(manager)
.unwrap_or_else(|e| panic!("Failed to create pool. {}", e))
}
pub trait SyncQuery {
type Result;
fn handle(&self, pool: &DbPool) -> Self::Result;
}

View File

@ -1,11 +1,8 @@
use {
crate::{
db_create, db_delete, db_load,
users::{FindUser, LookupUser},
},
diesel::prelude::*,
jirs_data::{BindToken, Message, MessageId, MessageType, User, UserId},
};
use bitque_data::{BindToken, Message, MessageId, MessageType, User, UserId};
use diesel::prelude::*;
use crate::users::{FindUser, LookupUser};
use crate::{db_create, db_delete, db_load};
db_load! {
LoadMessages,

View File

@ -1,15 +1,13 @@
use {
crate::schema::*,
chrono::NaiveDateTime,
jirs_data::{
EpicId, InvitationState, IssuePriority, IssueStatusId, IssueType, ProjectCategory,
ProjectId, TimeTracking, UserId,
},
serde::{Deserialize, Serialize},
uuid::Uuid,
use bitque_data::{
EpicId, InvitationState, IssuePriority, IssueStatusId, IssueType, ProjectCategory, ProjectId,
TimeTracking, UserId,
};
use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Debug, Deserialize, Queryable)]
use crate::schema::*;
#[derive(Debug, Deserialize, Queryable, Serialize)]
pub struct Issue {
pub id: i32,
pub title: String,
@ -29,9 +27,9 @@ pub struct Issue {
pub epic_id: Option<EpicId>,
}
impl Into<jirs_data::Issue> for Issue {
fn into(self) -> jirs_data::Issue {
jirs_data::Issue {
impl Into<bitque_data::Issue> for Issue {
fn into(self) -> bitque_data::Issue {
bitque_data::Issue {
id: self.id,
title: self.title,
issue_type: self.issue_type,
@ -54,8 +52,8 @@ impl Into<jirs_data::Issue> for Issue {
}
}
#[derive(Debug, Serialize, Deserialize, Insertable)]
#[table_name = "issues"]
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[diesel(table_name = issues)]
pub struct CreateIssueForm {
pub title: String,
pub issue_type: IssueType,
@ -72,15 +70,15 @@ pub struct CreateIssueForm {
pub epic_id: Option<EpicId>,
}
#[derive(Debug, Serialize, Deserialize, Insertable)]
#[table_name = "issue_assignees"]
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[diesel(table_name = issue_assignees)]
pub struct CreateIssueAssigneeForm {
pub issue_id: i32,
pub user_id: i32,
}
#[derive(Debug, Serialize, Deserialize, Insertable)]
#[table_name = "projects"]
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[diesel(table_name = projects)]
pub struct UpdateProjectForm {
pub name: Option<String>,
pub url: Option<String>,
@ -89,8 +87,8 @@ pub struct UpdateProjectForm {
pub time_tracking: Option<TimeTracking>,
}
#[derive(Debug, Serialize, Deserialize, Insertable)]
#[table_name = "projects"]
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[diesel(table_name = projects)]
pub struct CreateProjectForm {
pub name: String,
pub url: String,
@ -98,25 +96,16 @@ pub struct CreateProjectForm {
pub category: ProjectCategory,
}
#[derive(Debug, Serialize, Deserialize, Insertable)]
#[table_name = "users"]
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[diesel(table_name = users)]
pub struct UserForm {
pub name: String,
pub email: String,
pub avatar_url: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Insertable)]
#[table_name = "tokens"]
pub struct TokenForm {
pub user_id: i32,
pub access_token: Uuid,
pub refresh_token: Uuid,
pub bind_token: Option<Uuid>,
}
#[derive(Debug, Serialize, Deserialize, Insertable)]
#[table_name = "invitations"]
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[diesel(table_name = invitations)]
pub struct InvitationForm {
pub name: String,
pub email: String,

View File

@ -1,14 +1,14 @@
#[macro_export]
macro_rules! db_pool {
($self: expr) => {
&$self.pool.get().map_err(|e| {
log::error!("{:?}", e);
$self.pool.get().map_err(|e| {
::tracing::error!("{:?}", e);
$crate::DatabaseError::DatabaseConnectionLost
})?
};
($self: expr, $pool: expr) => {
&$pool.get().map_err(|e| {
log::error!("{:?}", e);
$pool.get().map_err(|e| {
::tracing::error!("{:?}", e);
$crate::DatabaseError::DatabaseConnectionLost
})?
};
@ -18,7 +18,7 @@ macro_rules! db_pool {
macro_rules! q {
($q: expr) => {{
let q = $q;
log::debug!(
::tracing::debug!(
"{}",
diesel::debug_query::<diesel::pg::Pg, _>(&q).to_string()
);
@ -34,13 +34,13 @@ macro_rules! db_find {
}
impl $action {
pub fn execute(self, $conn: &$crate::DbPooledConn) -> Result<$resource, crate::DatabaseError> {
pub fn execute(self, $conn: &mut $crate::DbPooledConn) -> Result<$resource, crate::DatabaseError> {
use crate::schema:: $schema ::dsl::*;
let $self = self;
$crate::q!($q)
.first($conn)
.map_err(|e| {
log::error!("{:?}", e);
::tracing::error!("{:?}", e);
$crate::DatabaseError::GenericFailure(
$crate::OperationError::LoadCollection,
$crate::ResourceKind::$resource,
@ -57,8 +57,8 @@ macro_rules! db_find {
type Result = Result<$resource, $crate::DatabaseError>;
fn handle(&mut self, msg: $action, _ctx: &mut Self::Context) -> Self::Result {
let $conn = $crate::db_pool!(self);
msg.execute($conn)
let mut $conn = $crate::db_pool!(self);
msg.execute(&mut $conn)
}
}
};
@ -75,13 +75,13 @@ macro_rules! db_load {
}
impl $action {
pub fn execute(self, conn: &$crate::DbPooledConn) -> Result<Vec<$resource>, $crate::DatabaseError> {
pub fn execute(self, conn: &mut $crate::DbPooledConn) -> Result<Vec<$resource>, $crate::DatabaseError> {
use crate::schema:: $schema ::dsl::*;
let $self = self;
$crate::q!($q)
.load(conn)
.map_err(|e| {
log::error!("{:?}", e);
::tracing::error!("{:?}", e);
$crate::DatabaseError::GenericFailure(
$crate::OperationError::LoadCollection,
$crate::ResourceKind::$resource,
@ -98,9 +98,9 @@ macro_rules! db_load {
type Result = Result<Vec<$resource>, $crate::DatabaseError>;
fn handle(&mut self, msg: $action, _ctx: &mut Self::Context) -> Self::Result {
let conn = $crate::db_pool!(self);
let mut conn = $crate::db_pool!(self);
msg.execute(conn)
msg.execute(&mut conn)
}
}
};
@ -114,13 +114,13 @@ macro_rules! db_load_field {
}
impl $action {
pub fn execute(self, conn: &$crate::DbPooledConn) -> Result<Vec<$return_type>, $crate::DatabaseError> {
pub fn execute(self, conn: &mut $crate::DbPooledConn) -> Result<Vec<$return_type>, $crate::DatabaseError> {
use crate::schema:: $schema ::dsl::*;
let $self = self;
$crate::q!($q)
.load(conn)
.map_err(|e| {
log::error!("{:?}", e);
::tracing::error!("{:?}", e);
$crate::DatabaseError::GenericFailure(
$crate::OperationError::LoadCollection,
$crate::ResourceKind::$resource,
@ -137,9 +137,9 @@ macro_rules! db_load_field {
type Result = Result<Vec<$return_type>, $crate::DatabaseError>;
fn handle(&mut self, msg: $action, _ctx: &mut Self::Context) -> Self::Result {
let conn = $crate::db_pool!(self);
let mut conn = $crate::db_pool!(self);
msg.execute(conn)
msg.execute(&mut conn)
}
}
};
@ -151,25 +151,34 @@ macro_rules! db_create {
};
($action: ident, $self: ident => $conn: ident => $schema: ident => $q: expr, $resource: ident, $($field: ident => $ty: ty),+) => {
pub struct $action {
$(pub $field : $ty),+
$(pub $field : $ty),+
}
impl $action {
pub fn execute(self, $conn: &$crate::DbPooledConn) -> Result<$resource, crate::DatabaseError> {
crate::Guard::new($conn)?.run(|_guard| {
use crate::schema:: $schema ::dsl::*;
let $self = self;
$crate::q!($q)
.get_result::<$resource>($conn)
.map_err(|e| {
log::error!("{:?}", e);
pub fn execute(self, conn: &mut $crate::DbPooledConn) -> Result<$resource, crate::DatabaseError> {
let mut res = Err(crate::DatabaseError::DatabaseConnectionLost);
conn.transaction(|conn| {
res = self.exec_with_transaction(conn);
if res.is_err() {
Err(diesel::NotFound)
} else {
Ok(())
}
}).ok();
res
}
fn exec_with_transaction(self, $conn: &mut $crate::DbPooledConn) -> Result<$resource, crate::DatabaseError> {
use crate::schema:: $schema ::dsl::*;
let $self = self;
$crate::q!($q).get_result::<$resource>($conn).map_err(|e| {
::tracing::error!("{:?}", e);
$crate::DatabaseError::GenericFailure(
$crate::OperationError::Create,
$crate::ResourceKind::$resource,
)
})
})
}
}
}
impl actix::Message for $action {
@ -180,9 +189,9 @@ macro_rules! db_create {
type Result = Result<$resource, $crate::DatabaseError>;
fn handle(&mut self, msg: $action, _ctx: &mut Self::Context) -> Self::Result {
let $conn = $crate::db_pool!(self);
let mut $conn = $crate::db_pool!(self);
msg.execute($conn)
msg.execute(&mut $conn)
}
}
};
@ -199,13 +208,13 @@ macro_rules! db_update {
}
impl $action {
pub fn execute(self, $conn: &$crate::DbPooledConn) -> Result<$resource, crate::DatabaseError> {
pub fn execute(self, $conn: &mut $crate::DbPooledConn) -> Result<$resource, crate::DatabaseError> {
use crate::schema:: $schema ::dsl::*;
let $self = self;
$crate::q!($q)
.get_result::<$resource>($conn)
.map_err(|e| {
log::error!("{:?}", e);
::tracing::error!("{:?}", e);
$crate::DatabaseError::GenericFailure(
$crate::OperationError::Update,
$crate::ResourceKind::$resource,
@ -222,9 +231,9 @@ macro_rules! db_update {
type Result = Result<$resource, $crate::DatabaseError>;
fn handle(&mut self, msg: $action, _ctx: &mut Self::Context) -> Self::Result {
let $conn = $crate::db_pool!(self);
let mut $conn = $crate::db_pool!(self);
msg.execute ( $conn )
msg.execute ( &mut $conn )
}
}
};
@ -241,13 +250,13 @@ macro_rules! db_delete {
}
impl $action {
pub fn execute(self, $conn: &$crate::DbPooledConn) -> Result<usize, $crate::DatabaseError> {
pub fn execute(self, $conn: &mut $crate::DbPooledConn) -> Result<usize, $crate::DatabaseError> {
use $crate::schema:: $schema ::dsl::*;
let $self = self;
$crate::q!($q)
.execute($conn)
.map_err(|e| {
log::error!("{:?}", e);
::tracing::error!("{:?}", e);
$crate::DatabaseError::GenericFailure(
$crate::OperationError::Delete,
$crate::ResourceKind::$resource,
@ -264,9 +273,9 @@ macro_rules! db_delete {
type Result = Result<usize, $crate::DatabaseError>;
fn handle(&mut self, msg: $action, _ctx: &mut Self::Context) -> Self::Result {
let $conn = $crate::db_pool!(self);
let mut $conn = $crate::db_pool!(self);
msg.execute($conn)
msg.execute(&mut $conn)
}
}
};

View File

@ -1,8 +1,7 @@
use {
crate::{db_create, db_find, db_load, db_update},
diesel::prelude::*,
jirs_data::{NameString, Project, ProjectCategory, ProjectId, TimeTracking, UserId},
};
use bitque_data::{NameString, Project, ProjectCategory, ProjectId, TimeTracking, UserId};
use diesel::prelude::*;
use crate::{db_create, db_find, db_load, db_update};
db_find! {
LoadCurrentProject,
@ -12,11 +11,10 @@ db_find! {
}
mod inner {
use {
crate::db_create,
diesel::prelude::*,
jirs_data::{NameString, Project, ProjectCategory, TimeTracking},
};
use bitque_data::{NameString, Project, ProjectCategory, TimeTracking};
use diesel::prelude::*;
use crate::db_create;
db_create! {
CreateProject,

View File

@ -1,13 +1,13 @@
diff --git a/jirs-server/src/schema.rs b/jirs-server/src/schema.rs
diff --git a/bitque-server/src/schema.rs b/bitque-server/src/schema.rs
index 00d1c0b..5b82ccf 100644
--- a/jirs-server/src/schema.rs
+++ b/jirs-server/src/schema.rs
--- a/bitque-server/src/schema.rs
+++ b/bitque-server/src/schema.rs
@@ -1,6 +1,8 @@
+#![allow(unused_imports, dead_code)]
+
table! {
use diesel::sql_types::*;
use jirs_data::*;
use bitque_data::*;
/// Representation of the `comments` table.
///

View File

@ -0,0 +1,224 @@
// @generated automatically by Diesel CLI.
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
comments (id) {
id -> Int4,
body -> Text,
user_id -> Int4,
issue_id -> Int4,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
epics (id) {
id -> Int4,
name -> Text,
user_id -> Int4,
project_id -> Int4,
created_at -> Timestamp,
updated_at -> Timestamp,
starts_at -> Nullable<Timestamp>,
ends_at -> Nullable<Timestamp>,
description -> Nullable<Text>,
description_html -> Nullable<Text>,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
invitations (id) {
id -> Int4,
name -> Text,
email -> Text,
state -> InvitationStateMapping,
project_id -> Int4,
invited_by_id -> Int4,
created_at -> Timestamp,
updated_at -> Timestamp,
bind_token -> Uuid,
role -> UserRoleMapping,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
issue_assignees (id) {
id -> Int4,
issue_id -> Int4,
user_id -> Int4,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
issue_statuses (id) {
id -> Int4,
name -> Varchar,
position -> Int4,
project_id -> Int4,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
issues (id) {
id -> Int4,
title -> Text,
issue_type -> IssueTypeMapping,
priority -> IssuePriorityMapping,
list_position -> Int4,
description -> Nullable<Text>,
description_text -> Nullable<Text>,
estimate -> Nullable<Int4>,
time_spent -> Nullable<Int4>,
time_remaining -> Nullable<Int4>,
reporter_id -> Int4,
project_id -> Int4,
created_at -> Timestamp,
updated_at -> Timestamp,
issue_status_id -> Int4,
epic_id -> Nullable<Int4>,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
messages (id) {
id -> Int4,
receiver_id -> Int4,
sender_id -> Int4,
summary -> Text,
description -> Text,
message_type -> MessageTypeMapping,
hyper_link -> Text,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
projects (id) {
id -> Int4,
name -> Text,
url -> Text,
description -> Text,
category -> ProjectCategoryMapping,
created_at -> Timestamp,
updated_at -> Timestamp,
time_tracking -> TimeTrackingMapping,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
tokens (id) {
id -> Int4,
user_id -> Int4,
access_token -> Uuid,
refresh_token -> Uuid,
created_at -> Timestamp,
updated_at -> Timestamp,
bind_token -> Nullable<Uuid>,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
user_projects (id) {
id -> Int4,
user_id -> Int4,
project_id -> Int4,
is_default -> Bool,
is_current -> Bool,
role -> UserRoleMapping,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
user_settings (id) {
id -> Int4,
user_id -> Int4,
text_editor_mode -> TextEditorModeMapping,
}
}
diesel::table! {
use diesel::sql_types::*;
use bitque_data::*;
users (id) {
id -> Int4,
name -> Text,
email -> Text,
avatar_url -> Nullable<Text>,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}
diesel::joinable!(comments -> issues (issue_id));
diesel::joinable!(comments -> users (user_id));
diesel::joinable!(epics -> projects (project_id));
diesel::joinable!(epics -> users (user_id));
diesel::joinable!(invitations -> projects (project_id));
diesel::joinable!(invitations -> users (invited_by_id));
diesel::joinable!(issue_assignees -> issues (issue_id));
diesel::joinable!(issue_assignees -> users (user_id));
diesel::joinable!(issue_statuses -> projects (project_id));
diesel::joinable!(issues -> epics (epic_id));
diesel::joinable!(issues -> issue_statuses (issue_status_id));
diesel::joinable!(issues -> projects (project_id));
diesel::joinable!(issues -> users (reporter_id));
diesel::joinable!(tokens -> users (user_id));
diesel::joinable!(user_projects -> projects (project_id));
diesel::joinable!(user_projects -> users (user_id));
diesel::joinable!(user_settings -> users (user_id));
diesel::allow_tables_to_appear_in_same_query!(
comments,
epics,
invitations,
issue_assignees,
issue_statuses,
issues,
messages,
projects,
tokens,
user_projects,
user_settings,
users,
);

View File

@ -1,8 +1,7 @@
use {
crate::{db_create, db_find, db_update},
diesel::prelude::*,
jirs_data::{Token, UserId},
};
use bitque_data::{Token, UserId};
use diesel::prelude::*;
use crate::{db_create, db_find, db_update};
db_find! {
FindUserId,

View File

@ -1,8 +1,7 @@
use {
crate::{db_create, db_delete, db_find, db_load, db_update},
diesel::prelude::*,
jirs_data::{ProjectId, UserId, UserProject, UserProjectId, UserRole},
};
use bitque_data::{ProjectId, UserId, UserProject, UserProjectId, UserRole};
use diesel::prelude::*;
use crate::{db_create, db_delete, db_find, db_load, db_update};
db_find! {
CurrentUserProject,
@ -27,11 +26,10 @@ db_load! {
}
mod inner {
use {
crate::db_update,
diesel::prelude::*,
jirs_data::{UserId, UserProject, UserProjectId},
};
use bitque_data::{UserId, UserProject, UserProjectId};
use diesel::prelude::*;
use crate::db_update;
db_update! {
ChangeProjectIsCurrent,

View File

@ -0,0 +1,57 @@
use bitque_data::{TextEditorMode, UserId, UserSetting};
use diesel::prelude::*;
use crate::{db_find, db_update};
db_find! {
FindUserSetting,
msg => user_settings => user_settings
.distinct_on(id)
.filter(user_id.eq(msg.user_id))
.limit(1),
UserSetting,
user_id => UserId
}
db_update! {
UpdateUserSetting,
msg => conn => user_settings => {
inner::Update { user_id: msg.user_id, mode: msg.mode }
.execute(conn).or_else(|_|
inner::Create { user_id: msg.user_id, mode: msg.mode }
.execute(conn)
)?;
user_settings.filter(user_id.eq(msg.user_id))
},
UserSetting,
user_id => UserId,
mode => TextEditorMode
}
mod inner {
use bitque_data::{TextEditorMode, UserId, UserSetting};
use diesel::prelude::*;
use crate::{db_create, db_update};
db_update! {
Update,
msg => user_settings => {
diesel::update(user_settings.filter(user_id.eq(msg.user_id))).set(text_editor_mode.eq(msg.mode))
},
UserSetting,
user_id => UserId,
mode => TextEditorMode
}
db_create! {
Create,
msg => user_settings => diesel::insert_into(user_settings).values((
user_id.eq(msg.user_id),
text_editor_mode.eq(msg.mode)
)),
UserSetting,
user_id => UserId,
mode => TextEditorMode
}
}

View File

@ -1,11 +1,9 @@
use {
crate::{
db_create, db_find, db_load, db_update, projects::CreateProject, q,
user_projects::CreateUserProject, DbPooledConn,
},
diesel::prelude::*,
jirs_data::{EmailString, IssueId, ProjectId, User, UserId, UserRole, UsernameString},
};
use bitque_data::{EmailString, IssueId, ProjectId, User, UserId, UserRole, UsernameString};
use diesel::prelude::*;
use crate::projects::CreateProject;
use crate::user_projects::CreateUserProject;
use crate::{db_create, db_find, db_load, db_update, q, DbPooledConn};
db_find! {
FindUser,
@ -122,7 +120,7 @@ db_load! {
user_id => UserId
}
fn count_matching_users(name: &str, email: &str, conn: &DbPooledConn) -> i64 {
fn count_matching_users(name: &str, email: &str, conn: &mut DbPooledConn) -> i64 {
use crate::schema::users::dsl;
q!(dsl::users
@ -155,13 +153,13 @@ db_update! {
#[cfg(test)]
mod tests {
use diesel::connection::TransactionManager;
use jirs_data::{Project, ProjectCategory};
use crate::build_pool;
use bitque_data::{Project, ProjectCategory};
use super::*;
use crate::build_pool;
use crate::schema::issues::dsl::issues;
use crate::schema::tokens::dsl::tokens;
use crate::schema::user_settings::dsl::user_settings;
#[test]
fn check_collision() {
@ -170,13 +168,14 @@ mod tests {
use crate::schema::users::dsl::users;
let pool = build_pool();
let conn = &pool.get().unwrap();
let tm = conn.transaction_manager();
tm.begin_transaction(conn).unwrap();
let mut conn = pool.get().unwrap();
let conn = &mut conn;
conn.begin_test_transaction().unwrap();
diesel::delete(user_settings).execute(conn).unwrap();
diesel::delete(user_projects).execute(conn).unwrap();
diesel::delete(tokens).execute(conn).unwrap();
diesel::delete(issues).execute(conn).unwrap();
diesel::delete(users).execute(conn).unwrap();
diesel::delete(projects).execute(conn).unwrap();
@ -222,8 +221,6 @@ mod tests {
let res2 = count_matching_users("Bar", "foo@example.com", conn);
let res3 = count_matching_users("Foo", "foo@example.com", conn);
tm.rollback_transaction(conn).unwrap();
assert_eq!(res1, 1);
assert_eq!(res2, 1);
assert_eq!(res3, 1);

View File

@ -3,8 +3,8 @@ name = "derive_db_execute"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"
@ -13,4 +13,5 @@ name = "derive_db_execute"
path = "./src/lib.rs"
proc-macro = true
[dependencies]
[dev-dependencies]
diesel = { version = "2", features = ['postgres'] }

View File

@ -3,11 +3,15 @@ mod utils;
extern crate proc_macro;
use {
crate::parse_attr::Attributes,
proc_macro::{token_stream::IntoIter, TokenStream, TokenTree},
std::iter::Peekable,
};
use std::iter::Peekable;
use proc_macro::token_stream::IntoIter;
use proc_macro::{TokenStream, TokenTree};
use crate::parse_attr::Attributes;
#[cfg(test)]
pub mod schema;
fn parse_meta(mut it: Peekable<IntoIter>) -> (Peekable<IntoIter>, Option<Attributes>) {
let mut attrs: Option<Attributes> = None;
@ -34,43 +38,45 @@ fn parse_meta(mut it: Peekable<IntoIter>) -> (Peekable<IntoIter>, Option<Attribu
///
///
///
/// Example:
/// ## Example:
///
/// ```
/// pub struct Issue {
/// pub id: i32,
/// pub name: String,
/// }
/// use derive_db_execute::Execute;
///
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "Issue", find = "issues.find(msg.id)")]
/// pub struct FindOne {
/// pub id: i32,
/// }
/// pub struct Issue {
/// pub id: i32,
/// pub name: String,
/// }
///
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "Issue", load = "issues")]
/// pub struct LoadAll;
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "Issue", find = "issues.find(msg.id)")]
/// pub struct FindOne {
/// pub id: i32,
/// }
///
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "usize", destroy = "diesel::delete(issues.find(msg.id)")]
/// pub struct DeleteOne {
/// pub id: i32
/// }
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "Issue", load = "issues")]
/// pub struct LoadAll;
///
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "Issue", destroy = "diesel::insert_into(issues).values(name.eq(msg.name))")]
/// pub struct CreateOne {
/// pub name: String
/// }
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "usize", destroy = "diesel::delete(issues.find(msg.id))")]
/// pub struct DeleteOne {
/// pub id: i32
/// }
///
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "Issue", destroy = "diesel::update(issues.find(msg.id)).set(name.eq(msg.name))")]
/// pub struct UpdateOne {
/// pub id: i32,
/// pub name: String
/// }
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "Issue", destroy = "diesel::insert_into(issues).values(name.eq(msg.name))")]
/// pub struct CreateOne {
/// pub name: String
/// }
///
/// #[derive(Execute)]
/// #[db_exec(schema = "issues", result = "Issue", destroy = "diesel::update(issues.find(msg.id)).set(name.eq(msg.name))")]
/// pub struct UpdateOne {
/// pub id: i32,
/// pub name: String
/// }
/// ```
///
#[proc_macro_derive(Execute, attributes(db_exec))]
pub fn derive_enum_iter(item: TokenStream) -> TokenStream {
let mut it = item.into_iter().peekable();
@ -124,9 +130,9 @@ pub fn derive_enum_iter(item: TokenStream) -> TokenStream {
type Result = Result<{action_result}, crate::DatabaseError>;
fn handle(&mut self, msg: {name}, _ctx: &mut Self::Context) -> Self::Result {{
let conn = crate::db_pool!(self);
let mut conn = crate::db_pool!(self);
msg.execute(conn)
msg.execute(&mut conn)
}}
}}
@ -151,18 +157,18 @@ fn build_create_exec(
impl {name} {{
pub fn execute(
self,
conn: &crate::DbPooledConn,
conn: &mut crate::DbPooledConn,
) -> Result<{action_result}, crate::DatabaseError> {{
crate::Guard::new(conn)?.run(|_guard| {{
conn.transaction(|conn| {{
use crate::schema::{schema}::dsl::*;
let msg = self;
crate::q!({query}).get_result(conn).map_err(|e| {{
log::error!("{{:?}}", e);
crate::DatabaseError::GenericFailure(
crate::OperationError::Create,
crate::ResourceKind::{resource},
)
}})
crate::q!({query}).get_result(conn)
}}).map_err(|e| {{
::tracing::error!("{{:?}}", e);
crate::DatabaseError::GenericFailure(
crate::OperationError::Create,
crate::ResourceKind::{resource},
)
}})
}}
}}
@ -187,12 +193,12 @@ fn build_find_exec(
impl {name} {{
pub fn execute(
self,
conn: &crate::DbPooledConn,
conn: &mut crate::DbPooledConn,
) -> Result<{action_result}, crate::DatabaseError> {{
use crate::schema::{schema}::dsl::*;
let msg = self;
crate::q!({query}).first(conn).map_err(|e| {{
log::error!("{{:?}}", e);
::tracing::error!("{{:?}}", e);
crate::DatabaseError::GenericFailure(
crate::OperationError::LoadSingle,
crate::ResourceKind::{resource},
@ -221,12 +227,12 @@ fn build_load_exec(
impl {name} {{
pub fn execute(
self,
conn: &crate::DbPooledConn,
conn: &mut crate::DbPooledConn,
) -> Result<{action_result}, crate::DatabaseError> {{
use crate::schema::{schema}::dsl::*;
let msg = self;
crate::q!({query}).load(conn).map_err(|e| {{
log::error!("{{:?}}", e);
::tracing::error!("{{:?}}", e);
crate::DatabaseError::GenericFailure(
crate::OperationError::LoadCollection,
crate::ResourceKind::{resource},
@ -255,12 +261,12 @@ fn build_update_exec(
impl {name} {{
pub fn execute(
self,
conn: &crate::DbPooledConn,
conn: &mut crate::DbPooledConn,
) -> Result<{action_result}, crate::DatabaseError> {{
use crate::schema::{schema}::dsl::*;
let msg = self;
crate::q!({query}).get_result(conn).map_err(|e| {{
log::error!("{{:?}}", e);
::tracing::error!("{{:?}}", e);
crate::DatabaseError::GenericFailure(
crate::OperationError::Update,
crate::ResourceKind::{resource},
@ -289,12 +295,12 @@ fn build_destroy_exec(
impl {name} {{
pub fn execute(
self,
conn: &crate::DbPooledConn,
conn: &mut crate::DbPooledConn,
) -> Result<{action_result}, crate::DatabaseError> {{
use crate::schema::{schema}::dsl::*;
let msg = self;
crate::q!({query}).execute(conn).map_err(|e| {{
log::error!("{{:?}}", e);
::tracing::error!("{{:?}}", e);
crate::DatabaseError::GenericFailure(
crate::OperationError::Delete,
crate::ResourceKind::{resource},

View File

@ -1,7 +1,9 @@
use proc_macro::{token_stream::IntoIter, TokenTree};
use std::iter::Peekable;
#[derive(Default, Debug)]
use proc_macro::token_stream::IntoIter;
use proc_macro::TokenTree;
#[derive(Debug, Default)]
pub struct Attributes {
pub result: Option<String>,
pub schema: Option<String>,

View File

@ -0,0 +1,9 @@
use diesel::prelude::*;
table! {
use diesel::sql_types::*;
issues (id) {
id -> Int4,
title -> Text,
}
}

View File

@ -1,6 +1,8 @@
use proc_macro::{token_stream::IntoIter, TokenTree};
use std::iter::Peekable;
use proc_macro::token_stream::IntoIter;
use proc_macro::TokenTree;
pub fn skip_pub(mut it: Peekable<IntoIter>) -> Peekable<IntoIter> {
if let Some(TokenTree::Ident(ident)) = it.next() {
if ident.to_string().as_str() != "pub" {

View File

@ -3,8 +3,8 @@ name = "derive_enum_iter"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"

View File

@ -1,9 +1,9 @@
extern crate proc_macro;
use {
proc_macro::{token_stream::IntoIter, TokenStream, TokenTree},
std::iter::Peekable,
};
use std::iter::Peekable;
use proc_macro::token_stream::IntoIter;
use proc_macro::{TokenStream, TokenTree};
fn skip_meta(mut it: Peekable<IntoIter>) -> Peekable<IntoIter> {
while let Some(token) = it.peek() {
@ -27,7 +27,7 @@ fn consume_ident(mut it: Peekable<IntoIter>, name: &str) -> Peekable<IntoIter> {
it
}
pub(in crate) fn codegen(mut it: Peekable<IntoIter>) -> Result<String, String> {
pub(crate) fn codegen(mut it: Peekable<IntoIter>) -> Result<String, String> {
let name = it
.next()
.expect("Expect to struct name but nothing was found");

View File

@ -3,8 +3,8 @@ name = "derive_enum_primitive"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"

View File

@ -0,0 +1,354 @@
extern crate proc_macro;
use proc_macro::{TokenStream, TokenTree};
fn as_str(name: &str, variants: &[String]) -> String {
let mut code = format!(
r#"
impl {name} {{
pub fn as_str(&self) -> &'static str {{
match self {{
"#,
name = name,
);
for variant in variants {
let lower = variant.to_lowercase();
code.push_str(
format!(
" {name}::{variant} => \"{lower}\",\n",
variant = variant,
name = name,
lower = lower
)
.as_str(),
);
}
code.push_str(" }\n }\n}");
code
}
fn from_str(name: &str, variants: &[String]) -> String {
let mut code = format!(
r#"
impl std::str::FromStr for {name} {{
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {{
match s {{
"#,
name = name,
);
for variant in variants {
let lower = variant.to_lowercase();
code.push_str(
format!(
" \"{lower}\" => Ok({name}::{variant}),\n",
variant = variant,
name = name,
lower = lower
)
.as_str(),
);
}
code.push_str(
format!(
" _ => Err(format!(\"Unknown {name} {{}}\", s)),",
name = name
)
.as_str(),
);
code.push_str(" }\n }\n}");
code
}
fn into_label(name: &str, variants: &[String]) -> String {
let mut code = format!(
r#"
impl {name} {{
pub fn to_label(&self) -> &'static str {{
match self {{
"#,
name = name,
);
for variant in variants {
code.push_str(
format!(
" {name}::{variant} => \"{variant}\",\n",
variant = variant,
name = name,
)
.as_str(),
);
}
code.push_str(" }\n }\n}");
code
}
fn into_u32(name: &str, variants: &[String]) -> String {
let mut code = format!(
r#"
impl Into<u32> for {name} {{
fn into(self) -> u32 {{
match self {{
"#,
name = name
);
for (idx, variant) in variants.iter().enumerate() {
code.push_str(
format!(
" {name}::{variant} => {idx},\n",
variant = variant,
name = name,
idx = idx
)
.as_str(),
);
}
code.push_str(" }\n }\n}");
code
}
fn from_u32(name: &str, variants: &[String]) -> String {
let mut code = format!(
r#"
impl Into<{name}> for u32 {{
fn into(self) -> {name} {{
match self {{
"#,
name = name
);
for (idx, variant) in variants.iter().enumerate() {
code.push_str(
format!(
" {idx} => {name}::{variant},\n",
variant = variant,
name = name,
idx = idx
)
.as_str(),
);
}
code.push_str(format!(" _ => {name}::default(),\n", name = name,).as_str());
code.push_str(" }\n }\n}");
code
}
#[proc_macro_derive(EnumU32)]
pub fn derive_enum_u32(item: TokenStream) -> TokenStream {
let mut it = item.into_iter().peekable();
while let Some(token) = it.peek() {
match token {
TokenTree::Ident(_) => {
break;
}
_ => {
it.next();
}
}
}
if let Some(TokenTree::Ident(ident)) = it.next() {
if ident.to_string().as_str() != "pub" {
panic!("Expect to find keyword pub but was found {:?}", ident)
}
} else {
panic!("Expect to find keyword pub but nothing was found")
}
if let Some(TokenTree::Ident(ident)) = it.next() {
if ident.to_string().as_str() != "enum" {
panic!("Expect to find keyword struct but was found {:?}", ident)
}
} else {
panic!("Expect to find keyword struct but nothing was found")
}
let name = it
.next()
.expect("Expect to struct name but nothing was found")
.to_string();
let mut variants = vec![];
if let Some(TokenTree::Group(group)) = it.next() {
for token in group.stream() {
if let TokenTree::Ident(ident) = token {
variants.push(ident.to_string())
}
}
} else {
panic!("Enum variants group expected");
}
if variants.is_empty() {
panic!("Enum cannot be empty")
}
let mut code = String::new();
code.push_str(into_u32(&name, &variants).as_str());
code.push_str(from_u32(&name, &variants).as_str());
code.parse().unwrap()
}
#[proc_macro_derive(EnumLabel)]
pub fn derive_enum_label(item: TokenStream) -> TokenStream {
let mut it = item.into_iter().peekable();
while let Some(token) = it.peek() {
match token {
TokenTree::Ident(_) => {
break;
}
_ => {
it.next();
}
}
}
if let Some(TokenTree::Ident(ident)) = it.next() {
if ident.to_string().as_str() != "pub" {
panic!("Expect to find keyword pub but was found {:?}", ident)
}
} else {
panic!("Expect to find keyword pub but nothing was found")
}
if let Some(TokenTree::Ident(ident)) = it.next() {
if ident.to_string().as_str() != "enum" {
panic!("Expect to find keyword struct but was found {:?}", ident)
}
} else {
panic!("Expect to find keyword struct but nothing was found")
}
let name = it
.next()
.expect("Expect to struct name but nothing was found")
.to_string();
let mut variants = vec![];
if let Some(TokenTree::Group(group)) = it.next() {
for token in group.stream() {
if let TokenTree::Ident(ident) = token {
variants.push(ident.to_string())
}
}
} else {
panic!("Enum variants group expected");
}
if variants.is_empty() {
panic!("Enum cannot be empty")
}
let mut code = String::new();
code.push_str(into_label(&name, &variants).as_str());
code.parse().unwrap()
}
#[proc_macro_derive(EnumStr)]
pub fn derive_enum_str(item: TokenStream) -> TokenStream {
let mut it = item.into_iter().peekable();
while let Some(token) = it.peek() {
match token {
TokenTree::Ident(_) => {
break;
}
_ => {
it.next();
}
}
}
if let Some(TokenTree::Ident(ident)) = it.next() {
if ident.to_string().as_str() != "pub" {
panic!("Expect to find keyword pub but was found {:?}", ident)
}
} else {
panic!("Expect to find keyword pub but nothing was found")
}
if let Some(TokenTree::Ident(ident)) = it.next() {
if ident.to_string().as_str() != "enum" {
panic!("Expect to find keyword struct but was found {:?}", ident)
}
} else {
panic!("Expect to find keyword struct but nothing was found")
}
let name = it
.next()
.expect("Expect to struct name but nothing was found")
.to_string();
let mut variants = vec![];
if let Some(TokenTree::Group(group)) = it.next() {
for token in group.stream() {
if let TokenTree::Ident(ident) = token {
variants.push(ident.to_string())
}
}
} else {
panic!("Enum variants group expected");
}
if variants.is_empty() {
panic!("Enum cannot be empty")
}
let mut code = String::new();
code.push_str(from_str(&name, &variants).as_str());
code.parse().unwrap()
}
#[proc_macro_derive(EnumAsStr)]
pub fn derive_enum_as_str(item: TokenStream) -> TokenStream {
let mut it = item.into_iter().peekable();
while let Some(token) = it.peek() {
match token {
TokenTree::Ident(_) => {
break;
}
_ => {
it.next();
}
}
}
if let Some(TokenTree::Ident(ident)) = it.next() {
if ident.to_string().as_str() != "pub" {
panic!("Expect to find keyword pub but was found {:?}", ident)
}
} else {
panic!("Expect to find keyword pub but nothing was found")
}
if let Some(TokenTree::Ident(ident)) = it.next() {
if ident.to_string().as_str() != "enum" {
panic!("Expect to find keyword struct but was found {:?}", ident)
}
} else {
panic!("Expect to find keyword struct but nothing was found")
}
let name = it
.next()
.expect("Expect to struct name but nothing was found")
.to_string();
let mut variants = vec![];
if let Some(TokenTree::Group(group)) = it.next() {
for token in group.stream() {
if let TokenTree::Ident(ident) = token {
variants.push(ident.to_string())
}
}
} else {
panic!("Enum variants group expected");
}
if variants.is_empty() {
panic!("Enum cannot be empty")
}
let mut code = String::new();
code.push_str(as_str(&name, &variants).as_str());
code.parse().unwrap()
}

View File

@ -0,0 +1,26 @@
[package]
name = "diesel-derive-enum"
version = "2.0.1"
description = "Derive diesel boilerplate for using enums in databases"
authors = ["Alex Whitney <adwhit@fastmail.com>"]
repository = "http://github.com/adwhit/diesel-derive-enum"
homepage = "http://github.com/adwhit/diesel-derive-enum"
keywords = ["diesel", "postgres", "sqlite", "mysql", "sql"]
license = "MIT OR Apache-2.0"
readme = "README.md"
edition = "2021"
[dependencies]
quote = "1"
syn = "1"
heck = "0.4.0"
proc-macro2 = "1"
[features]
postgres = []
sqlite = []
mysql = []
[lib]
name = "diesel_derive_enum"
proc-macro = true

View File

@ -0,0 +1,500 @@
#![recursion_limit = "1024"]
extern crate proc_macro;
use heck::{ToKebabCase, ToLowerCamelCase, ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase};
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span};
use quote::quote;
use syn::*;
/// Implement the traits necessary for inserting the enum directly into a
/// database
///
/// # Attributes
///
/// ## Type attributes
///
/// * `#[ExistingTypePath = "crate::schema::sql_types::NewEnum"]` specifies the
/// path to a corresponding diesel type that was already created by the diesel
/// CLI. If omitted, the type will be generated by this macro. *Note*: Only
/// applies to `postgres`, will error if specified for other databases
/// * `#[DieselType = "NewEnumMapping"]` specifies the name for the diesel type
/// to create. If omitted, uses `<enum name>Mapping`. *Note*: Cannot be
/// specified alongside `ExistingTypePath`
/// * `#[DbValueStyle = "snake_case"]` specifies a renaming style from each of
/// the rust enum variants to each of the database variants. Either
/// `camelCase`, `kebab-case`, `PascalCase`, `SCREAMING_SNAKE_CASE`,
/// `snake_case`, `verbatim`. If omitted, uses `snake_case`.
///
/// ## Variant attributes
///
/// * `#[db_rename = "variant"]` specifies the db name for a specific variant.
#[proc_macro_derive(
DbEnum,
attributes(PgType, DieselType, ExistingTypePath, DbValueStyle, db_rename)
)]
pub fn derive(input: TokenStream) -> TokenStream {
let input: DeriveInput = parse_macro_input!(input as DeriveInput);
let existing_mapping_path = val_from_attrs(&input.attrs, "ExistingTypePath");
if !cfg!(feature = "postgres") && existing_mapping_path.is_some() {
panic!("ExistingTypePath attribute only applies when the 'postgres' feature is enabled");
}
// we could allow a default value here but... I'm not very keen
// let existing_mapping_path = existing_mapping_path
// .unwrap_or_else(|| format!("crate::schema::sql_types::{}", input.ident));
let pg_internal_type = val_from_attrs(&input.attrs, "PgType");
if existing_mapping_path.is_some() && pg_internal_type.is_some() {
panic!("Cannot specify both `ExistingTypePath` and `PgType` attributes");
}
let pg_internal_type = pg_internal_type.unwrap_or(input.ident.to_string().to_snake_case());
let new_diesel_mapping = val_from_attrs(&input.attrs, "DieselType");
if existing_mapping_path.is_some() && new_diesel_mapping.is_some() {
panic!("Cannot specify both `ExistingTypePath` and `DieselType` attributes");
}
let new_diesel_mapping = new_diesel_mapping.unwrap_or_else(|| format!("{}Type", input.ident));
// Maintain backwards compatibility by defaulting to snake case.
let case_style =
val_from_attrs(&input.attrs, "DbValueStyle").unwrap_or_else(|| "snake_case".to_string());
let case_style = CaseStyle::from_string(&case_style);
let existing_mapping_path = existing_mapping_path.map(|v| {
v.parse::<proc_macro2::TokenStream>()
.expect("ExistingTypePath is not a valid token")
});
let new_diesel_mapping = Ident::new(new_diesel_mapping.as_ref(), Span::call_site());
if let Data::Enum(syn::DataEnum {
variants: data_variants,
..
}) = input.data
{
generate_derive_enum_impls(
&existing_mapping_path,
&new_diesel_mapping,
&pg_internal_type,
case_style,
&input.ident,
&data_variants,
)
} else {
syn::Error::new(
Span::call_site(),
"derive(DbEnum) can only be applied to enums",
)
.to_compile_error()
.into()
}
}
fn val_from_attrs(attrs: &[Attribute], attr_name: &str) -> Option<String> {
for attr in attrs {
if attr.path.is_ident(attr_name) {
match attr.parse_meta().ok()? {
Meta::NameValue(MetaNameValue {
lit: Lit::Str(lit_str),
..
}) => return Some(lit_str.value()),
_ => panic!(
"Attribute '{}' must have form: {} = \"value\"",
attr_name, attr_name
),
}
}
}
None
}
/// Defines the casing for the database representation. Follows serde naming
/// convention.
#[derive(Clone, Copy, Debug, PartialEq)]
enum CaseStyle {
Camel,
Kebab,
Pascal,
Upper,
ScreamingSnake,
Snake,
Verbatim,
}
impl CaseStyle {
fn from_string(name: &str) -> Self {
match name {
"camelCase" => CaseStyle::Camel,
"kebab-case" => CaseStyle::Kebab,
"PascalCase" => CaseStyle::Pascal,
"SCREAMING_SNAKE_CASE" => CaseStyle::ScreamingSnake,
"UPPERCASE" => CaseStyle::Upper,
"snake_case" => CaseStyle::Snake,
"verbatim" | "verbatimcase" => CaseStyle::Verbatim,
s => panic!("unsupported casing: `{}`", s),
}
}
}
fn generate_derive_enum_impls(
existing_mapping_path: &Option<proc_macro2::TokenStream>,
new_diesel_mapping: &Ident,
pg_internal_type: &str,
case_style: CaseStyle,
enum_ty: &Ident,
variants: &syn::punctuated::Punctuated<Variant, syn::token::Comma>,
) -> TokenStream {
let modname = Ident::new(&format!("db_enum_impl_{}", enum_ty), Span::call_site());
let variant_ids: Vec<proc_macro2::TokenStream> = variants
.iter()
.map(|variant| {
if let Fields::Unit = variant.fields {
let id = &variant.ident;
quote! {
#enum_ty::#id
}
} else {
panic!("Variants must be fieldless")
}
})
.collect();
let variants_db: Vec<String> = variants
.iter()
.map(|variant| {
val_from_attrs(&variant.attrs, "db_rename")
.unwrap_or_else(|| stylize_value(&variant.ident.to_string(), case_style))
})
.collect();
let variants_db_bytes: Vec<LitByteStr> = variants_db
.iter()
.map(|variant_str| LitByteStr::new(variant_str.as_bytes(), Span::call_site()))
.collect();
let common = generate_common(enum_ty, &variant_ids, &variants_db, &variants_db_bytes);
let (diesel_mapping_def, diesel_mapping_use) =
// Skip this part if we already have an existing mapping
if existing_mapping_path.is_some() {
(None, None)
} else {
let new_diesel_mapping_def = generate_new_diesel_mapping(new_diesel_mapping, pg_internal_type);
let common_impls_on_new_diesel_mapping =
generate_common_impls(&quote! { #new_diesel_mapping }, enum_ty);
(
Some(quote! {
#new_diesel_mapping_def
#common_impls_on_new_diesel_mapping
}),
Some(quote! {
pub use self::#modname::#new_diesel_mapping;
}),
)
};
let pg_impl = if cfg!(feature = "postgres") {
match existing_mapping_path {
Some(path) => {
let common_impls_on_existing_diesel_mapping = generate_common_impls(path, enum_ty);
let postgres_impl = generate_postgres_impl(path, enum_ty, true);
Some(quote! {
#common_impls_on_existing_diesel_mapping
#postgres_impl
})
}
None => Some(generate_postgres_impl(
&quote! { #new_diesel_mapping },
enum_ty,
false,
)),
}
} else {
None
};
let mysql_impl = if cfg!(feature = "mysql") {
Some(generate_mysql_impl(new_diesel_mapping, enum_ty))
} else {
None
};
let sqlite_impl = if cfg!(feature = "sqlite") {
Some(generate_sqlite_impl(new_diesel_mapping, enum_ty))
} else {
None
};
let imports = quote! {
use super::*;
use diesel::{
backend::{self, Backend},
deserialize::{self, FromSql},
expression::AsExpression,
internal::derives::as_expression::Bound,
query_builder::{bind_collector::RawBytesBindCollector, QueryId},
row::Row,
serialize::{self, IsNull, Output, ToSql},
sql_types::*,
Queryable,
};
use std::io::Write;
};
let quoted = quote! {
#diesel_mapping_use
#[allow(non_snake_case)]
mod #modname {
#imports
#common
#diesel_mapping_def
#pg_impl
#mysql_impl
#sqlite_impl
}
};
quoted.into()
}
fn stylize_value(value: &str, style: CaseStyle) -> String {
match style {
CaseStyle::Camel => value.to_lower_camel_case(),
CaseStyle::Kebab => value.to_kebab_case(),
CaseStyle::Pascal => value.to_upper_camel_case(),
CaseStyle::Upper => value.to_uppercase(),
CaseStyle::ScreamingSnake => value.to_shouty_snake_case(),
CaseStyle::Snake => value.to_snake_case(),
CaseStyle::Verbatim => value.to_string(),
}
}
fn generate_common(
enum_ty: &Ident,
variants_rs: &[proc_macro2::TokenStream],
variants_db: &[String],
variants_db_bytes: &[LitByteStr],
) -> proc_macro2::TokenStream {
quote! {
fn db_str_representation(e: &#enum_ty) -> &'static str {
match *e {
#(#variants_rs => #variants_db,)*
}
}
fn from_db_binary_representation(bytes: &[u8]) -> deserialize::Result<#enum_ty> {
match bytes {
#(#variants_db_bytes => Ok(#variants_rs),)*
v => Err(format!("Unrecognized enum variant: '{}'",
String::from_utf8_lossy(v)).into()),
}
}
}
}
fn generate_new_diesel_mapping(
new_diesel_mapping: &Ident,
pg_internal_type: &str,
) -> proc_macro2::TokenStream {
// Note - we only generate a new mapping for mysql and sqlite, postgres
// should already have one
quote! {
#[derive(SqlType, Clone)]
#[diesel(mysql_type(name = "Enum"))]
#[diesel(sqlite_type(name = "Text"))]
#[diesel(postgres_type(name = #pg_internal_type))]
pub struct #new_diesel_mapping;
}
}
fn generate_common_impls(
diesel_mapping: &proc_macro2::TokenStream,
enum_ty: &Ident,
) -> proc_macro2::TokenStream {
quote! {
// NOTE: at some point this impl will no longer be necessary
// for diesel-cli schemas
// See https://github.com/adwhit/diesel-derive-enum/issues/10
// and https://github.com/adwhit/diesel-derive-enum/pull/79
impl QueryId for #diesel_mapping {
type QueryId = #diesel_mapping;
const HAS_STATIC_QUERY_ID: bool = true;
}
impl AsExpression<#diesel_mapping> for #enum_ty {
type Expression = Bound<#diesel_mapping, Self>;
fn as_expression(self) -> Self::Expression {
Bound::new(self)
}
}
impl AsExpression<Nullable<#diesel_mapping>> for #enum_ty {
type Expression = Bound<Nullable<#diesel_mapping>, Self>;
fn as_expression(self) -> Self::Expression {
Bound::new(self)
}
}
impl<'a> AsExpression<#diesel_mapping> for &'a #enum_ty {
type Expression = Bound<#diesel_mapping, Self>;
fn as_expression(self) -> Self::Expression {
Bound::new(self)
}
}
impl<'a> AsExpression<Nullable<#diesel_mapping>> for &'a #enum_ty {
type Expression = Bound<Nullable<#diesel_mapping>, Self>;
fn as_expression(self) -> Self::Expression {
Bound::new(self)
}
}
impl<'a, 'b> AsExpression<#diesel_mapping> for &'a &'b #enum_ty {
type Expression = Bound<#diesel_mapping, Self>;
fn as_expression(self) -> Self::Expression {
Bound::new(self)
}
}
impl<'a, 'b> AsExpression<Nullable<#diesel_mapping>> for &'a &'b #enum_ty {
type Expression = Bound<Nullable<#diesel_mapping>, Self>;
fn as_expression(self) -> Self::Expression {
Bound::new(self)
}
}
impl<DB> ToSql<Nullable<#diesel_mapping>, DB> for #enum_ty
where
DB: Backend,
Self: ToSql<#diesel_mapping, DB>,
{
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, DB>) -> serialize::Result {
ToSql::<#diesel_mapping, DB>::to_sql(self, out)
}
}
}
}
fn generate_postgres_impl(
diesel_mapping: &proc_macro2::TokenStream,
enum_ty: &Ident,
with_clone: bool,
) -> proc_macro2::TokenStream {
// If the type was generated by postgres, we have to manually add a clone impl,
// if generated by 'us' it has already been done
let clone_impl = if with_clone {
Some(quote! {
impl Clone for #diesel_mapping {
fn clone(&self) -> Self {
#diesel_mapping
}
}
})
} else {
None
};
quote! {
mod pg_impl {
use super::*;
use diesel::pg::{Pg, PgValue};
#clone_impl
impl FromSql<#diesel_mapping, Pg> for #enum_ty {
fn from_sql(raw: PgValue) -> deserialize::Result<Self> {
from_db_binary_representation(raw.as_bytes())
}
}
impl ToSql<#diesel_mapping, Pg> for #enum_ty
{
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result {
out.write_all(db_str_representation(self).as_bytes())?;
Ok(IsNull::No)
}
}
impl Queryable<#diesel_mapping, Pg> for #enum_ty {
type Row = Self;
fn build(row: Self::Row) -> deserialize::Result<Self> {
Ok(row)
}
}
}
}
}
fn generate_mysql_impl(diesel_mapping: &Ident, enum_ty: &Ident) -> proc_macro2::TokenStream {
quote! {
mod mysql_impl {
use super::*;
use diesel;
use diesel::mysql::{Mysql, MysqlValue};
impl FromSql<#diesel_mapping, Mysql> for #enum_ty {
fn from_sql(raw: MysqlValue) -> deserialize::Result<Self> {
from_db_binary_representation(raw.as_bytes())
}
}
impl ToSql<#diesel_mapping, Mysql> for #enum_ty
{
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Mysql>) -> serialize::Result {
out.write_all(db_str_representation(self).as_bytes())?;
Ok(IsNull::No)
}
}
impl Queryable<#diesel_mapping, Mysql> for #enum_ty {
type Row = Self;
fn build(row: Self::Row) -> deserialize::Result<Self> {
Ok(row)
}
}
}
}
}
fn generate_sqlite_impl(diesel_mapping: &Ident, enum_ty: &Ident) -> proc_macro2::TokenStream {
quote! {
mod sqlite_impl {
use super::*;
use diesel;
use diesel::sql_types;
use diesel::sqlite::Sqlite;
impl FromSql<#diesel_mapping, Sqlite> for #enum_ty {
fn from_sql(value: backend::RawValue<Sqlite>) -> deserialize::Result<Self> {
let bytes = <Vec<u8> as FromSql<sql_types::Binary, Sqlite>>::from_sql(value)?;
from_db_binary_representation(bytes.as_slice())
}
}
impl ToSql<#diesel_mapping, Sqlite> for #enum_ty {
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Sqlite>) -> serialize::Result {
<str as ToSql<sql_types::Text, Sqlite>>::to_sql(db_str_representation(self), out)
}
}
impl Queryable<#diesel_mapping, Sqlite> for #enum_ty {
type Row = Self;
fn build(row: Self::Row) -> deserialize::Result<Self> {
Ok(row)
}
}
}
}
}

View File

@ -3,8 +3,8 @@ name = "derive_utils"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "JIRS (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/jirs"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"

View File

@ -0,0 +1,21 @@
[package]
name = "filesystem-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "filesystem_actor"
path = "./src/lib.rs"
[dependencies]
actix = { version = "0.13.0" }
actix-files = { version = "0.6.2" }
bitque-config = { workspace = true, features = ["local-storage"] }
bytes = { version = "1.4.0" }
futures = { version = "0.3.8" }
tokio = { version = "1", features = ["full"] }

View File

@ -1,9 +1,9 @@
use {
actix::SyncContext,
actix_files::{self, Files},
jirs_config::fs::Configuration,
std::{io::Write, path::PathBuf},
};
use std::io::Write;
use std::path::PathBuf;
use actix::SyncContext;
use actix_files::{self, Files};
use bitque_config::fs::Configuration;
#[derive(Debug)]
pub enum FsError {
@ -13,11 +13,11 @@ pub enum FsError {
WriteFile,
}
pub struct FileSystemExecutor {
pub struct LocalStorageExecutor {
config: Configuration,
}
impl FileSystemExecutor {
impl LocalStorageExecutor {
pub fn client_path(&self) -> &str {
self.config.client_path.as_str()
}
@ -27,7 +27,7 @@ impl FileSystemExecutor {
}
}
impl Default for FileSystemExecutor {
impl Default for LocalStorageExecutor {
fn default() -> Self {
Self {
config: Configuration::read(),
@ -35,7 +35,7 @@ impl Default for FileSystemExecutor {
}
}
impl actix::Actor for FileSystemExecutor {
impl actix::Actor for LocalStorageExecutor {
type Context = SyncContext<Self>;
}
@ -46,11 +46,14 @@ pub struct CreateFile {
pub file_name: String,
}
impl actix::Handler<CreateFile> for FileSystemExecutor {
impl actix::Handler<CreateFile> for LocalStorageExecutor {
type Result = Result<usize, FsError>;
fn handle(&mut self, msg: CreateFile, _ctx: &mut Self::Context) -> Self::Result {
let Configuration { store_path, .. } = &self.config;
if std::fs::metadata(&store_path).is_err() {
let _ = std::fs::create_dir_all(&store_path);
}
let CreateFile {
mut source,
file_name,

View File

@ -0,0 +1,25 @@
[package]
name = "highlight-actor"
version = "0.1.0"
authors = ["Adrian Wozniak <adrian.wozniak@ita-prog.pl>"]
edition = "2018"
description = "BITQUE (Simplified JIRA in Rust) shared data types"
repository = "https://gitlab.com/adrian.wozniak/bitque"
license = "MPL-2.0"
#license-file = "../LICENSE"
[lib]
name = "highlight_actor"
path = "./src/lib.rs"
[dependencies]
actix = { version = "0.13.0" }
bincode = { version = "*" }
bitque-config = { workspace = true, features = ["hi"] }
bitque-data = { workspace = true, features = ["backend"] }
flate2 = { version = "*" }
lazy_static = { version = "*" }
serde = { version = "*" }
simsearch = { version = "0.2" }
syntect = { version = "*" }
toml = { version = "*" }

Some files were not shown because too many files have changed in this diff Show More