mirror of
https://github.com/lldap/lldap.git
synced 2026-07-25 17:58:44 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c052c091e | |||
| 278fb1630d |
@@ -1,9 +1,7 @@
|
|||||||
FROM rust:1.85
|
FROM rust:1.66
|
||||||
|
|
||||||
ARG USERNAME=lldapdev
|
ARG USERNAME=lldapdev
|
||||||
# We need to keep the user as 1001 to match the GitHub runner's UID.
|
ARG USER_UID=1000
|
||||||
# See https://github.com/actions/checkout/issues/956.
|
|
||||||
ARG USER_UID=1001
|
|
||||||
ARG USER_GID=$USER_UID
|
ARG USER_GID=$USER_UID
|
||||||
|
|
||||||
# Create the user
|
# Create the user
|
||||||
@@ -23,4 +21,4 @@ RUN RUSTFLAGS=-Ctarget-feature=-crt-static cargo install wasm-pack \
|
|||||||
|
|
||||||
USER $USERNAME
|
USER $USERNAME
|
||||||
ENV CARGO_HOME=/home/$USERNAME/.cargo
|
ENV CARGO_HOME=/home/$USERNAME/.cargo
|
||||||
ENV SHELL=/bin/bash
|
ENV SHELL=/bin/bash
|
||||||
+1
-9
@@ -34,20 +34,12 @@ package.json
|
|||||||
.vscode
|
.vscode
|
||||||
.devcontainer
|
.devcontainer
|
||||||
|
|
||||||
# Created databases
|
|
||||||
*.db
|
|
||||||
*.db-shm
|
|
||||||
*.db-wal
|
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
|
||||||
**/*.rs.bk
|
|
||||||
|
|
||||||
# Various config files that shouldn't be tracked
|
# Various config files that shouldn't be tracked
|
||||||
.env
|
.env
|
||||||
lldap_config.toml
|
lldap_config.toml
|
||||||
server_key
|
server_key
|
||||||
|
users.db*
|
||||||
screenshot.png
|
screenshot.png
|
||||||
recipe.json
|
recipe.json
|
||||||
lldap_config.toml
|
|
||||||
cert.pem
|
cert.pem
|
||||||
key.pem
|
key.pem
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
example_configs/** linguist-documentation
|
example-configs/** linguist-documentation
|
||||||
docs/** linguist-documentation
|
docs/** linguist-documentation
|
||||||
*.md linguist-documentation
|
*.md linguist-documentation
|
||||||
lldap_config.docker_template.toml linguist-documentation
|
lldap_config.docker_template.toml linguist-documentation
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
# These are supported funding model platforms
|
|
||||||
|
|
||||||
github: [lldap]
|
|
||||||
|
|
||||||
custom: ['https://bmc.link/nitnelave']
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
title: "[BUG]"
|
|
||||||
labels: bug
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
1. Go to '...'
|
|
||||||
2. Click on '....'
|
|
||||||
3. Scroll down to '....'
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Logs**
|
|
||||||
If applicable, add logs to explain the problem.
|
|
||||||
LLDAP should be started in verbose mode (`LLDAP_VERBOSE=true` env variable, or `verbose = true` in the config). Include the logs in triple-backtick "```"
|
|
||||||
If integrating with another service, please add its configuration (paste it or screenshot it) as well as any useful logs or screenshots (showing the error, for instance).
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here.
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: "[FEATURE REQUEST]"
|
|
||||||
labels: enhancement
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Motivation**
|
|
||||||
Why do you want the feature? What problem do you have, what use cases would it enable?
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've considered. You can include workarounds that are currently possible.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
---
|
|
||||||
name: Integration request
|
|
||||||
about: Request for integration with a service
|
|
||||||
title: "[INTEGRATION]"
|
|
||||||
labels: integration
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Checklist**
|
|
||||||
- [ ] Check if there is already an [example config](https://github.com/lldap/lldap/tree/main/example_configs) for it.
|
|
||||||
- [ ] Try to figure out the configuration values for the new service yourself.
|
|
||||||
- You can use other example configs for inspiration.
|
|
||||||
- If you're having trouble, you can ask on [Discord](https://discord.gg/h5PEdRMNyP) or create an issue.
|
|
||||||
- If you succeed, make sure to contribute an example configuration, or a configuration guide.
|
|
||||||
- If you hit a block because of an unimplemented feature, create an issue.
|
|
||||||
|
|
||||||
**Description of the service**
|
|
||||||
Quick summary of what the service is and how it's using LDAP. Link to the service's documentation on configuring LDAP.
|
|
||||||
|
|
||||||
**What you've tried**
|
|
||||||
A sample configuration that you've tried.
|
|
||||||
|
|
||||||
**What's not working**
|
|
||||||
Error logs, error screenshots, features that are not working, missing features.
|
|
||||||
+1
-12
@@ -1,23 +1,12 @@
|
|||||||
codecov:
|
codecov:
|
||||||
require_ci_to_pass: yes
|
require_ci_to_pass: yes
|
||||||
comment:
|
comment:
|
||||||
layout: "header,diff,files"
|
layout: "diff,flags"
|
||||||
require_changes: true
|
require_changes: true
|
||||||
require_base: true
|
require_base: true
|
||||||
require_head: true
|
require_head: true
|
||||||
coverage:
|
|
||||||
status:
|
|
||||||
project:
|
|
||||||
default:
|
|
||||||
target: "75%"
|
|
||||||
threshold: "0.1%"
|
|
||||||
removed_code_behavior: adjust_base
|
|
||||||
github_checks:
|
|
||||||
annotations: true
|
|
||||||
ignore:
|
ignore:
|
||||||
- "app"
|
- "app"
|
||||||
- "docs"
|
- "docs"
|
||||||
- "example_configs"
|
- "example_configs"
|
||||||
- "migration-tool"
|
- "migration-tool"
|
||||||
- "scripts"
|
|
||||||
- "set-password"
|
|
||||||
|
|||||||
@@ -1,6 +1,72 @@
|
|||||||
FROM localhost:5000/lldap/lldap:alpine-base
|
FROM debian:bullseye AS lldap
|
||||||
# Taken directly from https://github.com/tianon/gosu/blob/master/INSTALL.md
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
ENV GOSU_VERSION=1.17
|
ARG TARGETPLATFORM
|
||||||
|
RUN apt update && apt install -y wget
|
||||||
|
WORKDIR /dim
|
||||||
|
COPY bin/ bin/
|
||||||
|
COPY web/ web/
|
||||||
|
|
||||||
|
RUN mkdir -p target/
|
||||||
|
RUN mkdir -p /lldap/app
|
||||||
|
|
||||||
|
RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
|
||||||
|
mv bin/x86_64-unknown-linux-musl-lldap-bin/lldap target/lldap && \
|
||||||
|
mv bin/x86_64-unknown-linux-musl-migration-tool-bin/migration-tool target/migration-tool && \
|
||||||
|
mv bin/x86_64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
||||||
|
chmod +x target/lldap && \
|
||||||
|
chmod +x target/migration-tool && \
|
||||||
|
chmod +x target/lldap_set_password && \
|
||||||
|
ls -la target/ . && \
|
||||||
|
pwd \
|
||||||
|
; fi
|
||||||
|
|
||||||
|
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
||||||
|
mv bin/aarch64-unknown-linux-musl-lldap-bin/lldap target/lldap && \
|
||||||
|
mv bin/aarch64-unknown-linux-musl-migration-tool-bin/migration-tool target/migration-tool && \
|
||||||
|
mv bin/aarch64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
||||||
|
chmod +x target/lldap && \
|
||||||
|
chmod +x target/migration-tool && \
|
||||||
|
chmod +x target/lldap_set_password && \
|
||||||
|
ls -la target/ . && \
|
||||||
|
pwd \
|
||||||
|
; fi
|
||||||
|
|
||||||
|
RUN if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
|
||||||
|
mv bin/armv7-unknown-linux-gnueabihf-lldap-bin/lldap target/lldap && \
|
||||||
|
mv bin/armv7-unknown-linux-gnueabihf-migration-tool-bin/migration-tool target/migration-tool && \
|
||||||
|
mv bin/armv7-unknown-linux-gnueabihf-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
||||||
|
chmod +x target/lldap && \
|
||||||
|
chmod +x target/migration-tool && \
|
||||||
|
chmod +x target/lldap_set_password && \
|
||||||
|
ls -la target/ . && \
|
||||||
|
pwd \
|
||||||
|
; fi
|
||||||
|
|
||||||
|
# Web and App dir
|
||||||
|
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
COPY lldap_config.docker_template.toml /lldap/
|
||||||
|
COPY web/index_local.html web/index.html
|
||||||
|
RUN cp target/lldap /lldap/ && \
|
||||||
|
cp target/migration-tool /lldap/ && \
|
||||||
|
cp target/lldap_set_password /lldap/ && \
|
||||||
|
cp -R web/index.html \
|
||||||
|
web/pkg \
|
||||||
|
web/static \
|
||||||
|
/lldap/app/
|
||||||
|
|
||||||
|
WORKDIR /lldap
|
||||||
|
RUN set -x \
|
||||||
|
&& for file in $(cat /lldap/app/static/libraries.txt); do wget -P app/static "$file"; done \
|
||||||
|
&& for file in $(cat /lldap/app/static/fonts/fonts.txt); do wget -P app/static/fonts "$file"; done \
|
||||||
|
&& chmod a+r -R .
|
||||||
|
|
||||||
|
FROM alpine:3.16
|
||||||
|
WORKDIR /app
|
||||||
|
ENV UID=1000
|
||||||
|
ENV GID=1000
|
||||||
|
ENV USER=lldap
|
||||||
|
ENV GOSU_VERSION 1.14
|
||||||
|
# Fetch gosu from git
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
\
|
\
|
||||||
apk add --no-cache --virtual .gosu-deps \
|
apk add --no-cache --virtual .gosu-deps \
|
||||||
@@ -15,20 +81,9 @@ RUN set -eux; \
|
|||||||
\
|
\
|
||||||
# verify the signature
|
# verify the signature
|
||||||
export GNUPGHOME="$(mktemp -d)"; \
|
export GNUPGHOME="$(mktemp -d)"; \
|
||||||
for server in \
|
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
|
||||||
hkps://keys.openpgp.org \
|
|
||||||
ha.pool.sks-keyservers.net \
|
|
||||||
hkp://p80.pool.sks-keyservers.net:80 \
|
|
||||||
keyserver.ubuntu.com \
|
|
||||||
hkp://keyserver.ubuntu.com:80 \
|
|
||||||
pgp.mit.edu \
|
|
||||||
; do \
|
|
||||||
if gpg --batch --keyserver "$server" --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; then \
|
|
||||||
break; \
|
|
||||||
fi; \
|
|
||||||
done; \
|
|
||||||
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
|
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
|
||||||
gpgconf --kill all; \
|
command -v gpgconf && gpgconf --kill all || :; \
|
||||||
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
|
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
|
||||||
\
|
\
|
||||||
# clean up fetch dependencies
|
# clean up fetch dependencies
|
||||||
@@ -38,4 +93,22 @@ RUN set -eux; \
|
|||||||
# verify that the binary works
|
# verify that the binary works
|
||||||
gosu --version; \
|
gosu --version; \
|
||||||
gosu nobody true
|
gosu nobody true
|
||||||
COPY --chown=$USER:$USER docker-entrypoint.sh /docker-entrypoint.sh
|
RUN apk add --no-cache tini ca-certificates bash tzdata && \
|
||||||
|
addgroup -g $GID $USER && \
|
||||||
|
adduser \
|
||||||
|
--disabled-password \
|
||||||
|
--gecos "" \
|
||||||
|
--home "$(pwd)" \
|
||||||
|
--ingroup "$USER" \
|
||||||
|
--no-create-home \
|
||||||
|
--uid "$UID" \
|
||||||
|
"$USER" && \
|
||||||
|
mkdir -p /data && \
|
||||||
|
chown $USER:$USER /data
|
||||||
|
COPY --from=lldap --chown=$USER:$USER /lldap /app
|
||||||
|
COPY --from=lldap --chown=$USER:$USER /docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
VOLUME ["/data"]
|
||||||
|
WORKDIR /app
|
||||||
|
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
|
||||||
|
CMD ["run", "--config-file", "/data/lldap_config.toml"]
|
||||||
|
HEALTHCHECK CMD ["/app/lldap", "healthcheck", "--config-file", "/data/lldap_config.toml"]
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
FROM debian:bullseye AS lldap
|
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
|
||||||
ARG TARGETPLATFORM
|
|
||||||
RUN apt update && apt install -y wget
|
|
||||||
WORKDIR /dim
|
|
||||||
COPY bin/ bin/
|
|
||||||
COPY web/ web/
|
|
||||||
|
|
||||||
RUN mkdir -p target/
|
|
||||||
RUN mkdir -p /lldap/app
|
|
||||||
|
|
||||||
RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
|
|
||||||
mv bin/x86_64-unknown-linux-musl-lldap-bin/lldap target/lldap && \
|
|
||||||
mv bin/x86_64-unknown-linux-musl-lldap_migration_tool-bin/lldap_migration_tool target/lldap_migration_tool && \
|
|
||||||
mv bin/x86_64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
|
||||||
chmod +x target/lldap && \
|
|
||||||
chmod +x target/lldap_migration_tool && \
|
|
||||||
chmod +x target/lldap_set_password && \
|
|
||||||
ls -la target/ . && \
|
|
||||||
pwd \
|
|
||||||
; fi
|
|
||||||
|
|
||||||
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
|
||||||
mv bin/aarch64-unknown-linux-musl-lldap-bin/lldap target/lldap && \
|
|
||||||
mv bin/aarch64-unknown-linux-musl-lldap_migration_tool-bin/lldap_migration_tool target/lldap_migration_tool && \
|
|
||||||
mv bin/aarch64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
|
||||||
chmod +x target/lldap && \
|
|
||||||
chmod +x target/lldap_migration_tool && \
|
|
||||||
chmod +x target/lldap_set_password && \
|
|
||||||
ls -la target/ . && \
|
|
||||||
pwd \
|
|
||||||
; fi
|
|
||||||
|
|
||||||
RUN if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
|
|
||||||
mv bin/armv7-unknown-linux-musleabihf-lldap-bin/lldap target/lldap && \
|
|
||||||
mv bin/armv7-unknown-linux-musleabihf-lldap_migration_tool-bin/lldap_migration_tool target/lldap_migration_tool && \
|
|
||||||
mv bin/armv7-unknown-linux-musleabihf-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
|
||||||
chmod +x target/lldap && \
|
|
||||||
chmod +x target/lldap_migration_tool && \
|
|
||||||
chmod +x target/lldap_set_password && \
|
|
||||||
ls -la target/ . && \
|
|
||||||
pwd \
|
|
||||||
; fi
|
|
||||||
|
|
||||||
# Web and App dir
|
|
||||||
COPY lldap_config.docker_template.toml /lldap/
|
|
||||||
COPY web/index_local.html web/index.html
|
|
||||||
RUN cp target/lldap /lldap/ && \
|
|
||||||
cp target/lldap_migration_tool /lldap/ && \
|
|
||||||
cp target/lldap_set_password /lldap/ && \
|
|
||||||
cp -R web/index.html \
|
|
||||||
web/pkg \
|
|
||||||
web/static \
|
|
||||||
/lldap/app/
|
|
||||||
|
|
||||||
WORKDIR /lldap
|
|
||||||
RUN set -x \
|
|
||||||
&& for file in $(cat /lldap/app/static/libraries.txt); do wget -P app/static "$file"; done \
|
|
||||||
&& for file in $(cat /lldap/app/static/fonts/fonts.txt); do wget -P app/static/fonts "$file"; done \
|
|
||||||
&& chmod a+r -R .
|
|
||||||
|
|
||||||
FROM alpine:3.19
|
|
||||||
WORKDIR /app
|
|
||||||
ENV UID=1000
|
|
||||||
ENV GID=1000
|
|
||||||
ENV USER=lldap
|
|
||||||
RUN apk add --no-cache tini ca-certificates bash tzdata jq curl jo && \
|
|
||||||
addgroup -g $GID $USER && \
|
|
||||||
adduser \
|
|
||||||
--disabled-password \
|
|
||||||
--gecos "" \
|
|
||||||
--home "$(pwd)" \
|
|
||||||
--ingroup "$USER" \
|
|
||||||
--no-create-home \
|
|
||||||
--uid "$UID" \
|
|
||||||
"$USER" && \
|
|
||||||
mkdir -p /data && \
|
|
||||||
chown $USER:$USER /data
|
|
||||||
COPY --from=lldap --chown=$USER:$USER /lldap /app
|
|
||||||
VOLUME ["/data"]
|
|
||||||
HEALTHCHECK CMD ["/app/lldap", "healthcheck", "--config-file", "/data/lldap_config.toml"]
|
|
||||||
WORKDIR /app
|
|
||||||
COPY scripts/bootstrap.sh ./
|
|
||||||
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
|
|
||||||
CMD ["run", "--config-file", "/data/lldap_config.toml"]
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
FROM localhost:5000/lldap/lldap:alpine-base
|
|
||||||
COPY --chown=$USER:$USER docker-entrypoint-rootless.sh /docker-entrypoint.sh
|
|
||||||
USER $USER
|
|
||||||
@@ -1,45 +1,79 @@
|
|||||||
FROM localhost:5000/lldap/lldap:debian-base
|
FROM debian:bullseye AS lldap
|
||||||
# Taken directly from https://github.com/tianon/gosu/blob/master/INSTALL.md
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
ENV GOSU_VERSION=1.17
|
ARG TARGETPLATFORM
|
||||||
RUN set -eux; \
|
RUN apt update && apt install -y wget
|
||||||
# save list of currently installed packages for later so we can clean up
|
WORKDIR /dim
|
||||||
savedAptMark="$(apt-mark showmanual)"; \
|
COPY bin/ bin/
|
||||||
for i in 1 2 3; do \
|
COPY web/ web/
|
||||||
apt-get update && \
|
|
||||||
apt-get install -y --no-install-recommends wget ca-certificates gnupg && \
|
RUN mkdir -p target/
|
||||||
apt-get clean && \
|
RUN mkdir -p /lldap/app
|
||||||
rm -rf /var/lib/apt/lists/* && break || sleep 5; \
|
|
||||||
done; \
|
RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
|
||||||
\
|
mv bin/x86_64-unknown-linux-musl-lldap-bin/lldap target/lldap && \
|
||||||
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
|
mv bin/x86_64-unknown-linux-musl-migration-tool-bin/migration-tool target/migration-tool && \
|
||||||
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
|
mv bin/x86_64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
||||||
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
|
chmod +x target/lldap && \
|
||||||
\
|
chmod +x target/migration-tool && \
|
||||||
# verify the signature
|
chmod +x target/lldap_set_password && \
|
||||||
export GNUPGHOME="$(mktemp -d)"; \
|
ls -la target/ . && \
|
||||||
for server in \
|
pwd \
|
||||||
hkps://keys.openpgp.org \
|
; fi
|
||||||
ha.pool.sks-keyservers.net \
|
|
||||||
hkp://p80.pool.sks-keyservers.net:80 \
|
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
||||||
keyserver.ubuntu.com \
|
mv bin/aarch64-unknown-linux-musl-lldap-bin/lldap target/lldap && \
|
||||||
hkp://keyserver.ubuntu.com:80 \
|
mv bin/aarch64-unknown-linux-musl-migration-tool-bin/migration-tool target/migration-tool && \
|
||||||
pgp.mit.edu \
|
mv bin/aarch64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
||||||
; do \
|
chmod +x target/lldap && \
|
||||||
if gpg --batch --keyserver "$server" --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; then \
|
chmod +x target/migration-tool && \
|
||||||
break; \
|
chmod +x target/lldap_set_password && \
|
||||||
fi; \
|
ls -la target/ . && \
|
||||||
done; \
|
pwd \
|
||||||
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
|
; fi
|
||||||
gpgconf --kill all; \
|
|
||||||
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
|
RUN if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
|
||||||
\
|
mv bin/armv7-unknown-linux-gnueabihf-lldap-bin/lldap target/lldap && \
|
||||||
# clean up fetch dependencies
|
mv bin/armv7-unknown-linux-gnueabihf-migration-tool-bin/migration-tool target/migration-tool && \
|
||||||
apt-mark auto '.*' > /dev/null; \
|
mv bin/armv7-unknown-linux-gnueabihf-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
||||||
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
|
chmod +x target/lldap && \
|
||||||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
|
chmod +x target/migration-tool && \
|
||||||
\
|
chmod +x target/lldap_set_password && \
|
||||||
chmod +x /usr/local/bin/gosu; \
|
ls -la target/ . && \
|
||||||
# verify that the binary works
|
pwd \
|
||||||
gosu --version; \
|
; fi
|
||||||
gosu nobody true
|
|
||||||
COPY --chown=$USER:$USER docker-entrypoint.sh /docker-entrypoint.sh
|
# Web and App dir
|
||||||
|
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
COPY lldap_config.docker_template.toml /lldap/
|
||||||
|
COPY web/index_local.html web/index.html
|
||||||
|
RUN cp target/lldap /lldap/ && \
|
||||||
|
cp target/migration-tool /lldap/ && \
|
||||||
|
cp target/lldap_set_password /lldap/ && \
|
||||||
|
cp -R web/index.html \
|
||||||
|
web/pkg \
|
||||||
|
web/static \
|
||||||
|
/lldap/app/
|
||||||
|
|
||||||
|
WORKDIR /lldap
|
||||||
|
RUN set -x \
|
||||||
|
&& for file in $(cat /lldap/app/static/libraries.txt); do wget -P app/static "$file"; done \
|
||||||
|
&& for file in $(cat /lldap/app/static/fonts/fonts.txt); do wget -P app/static/fonts "$file"; done \
|
||||||
|
&& chmod a+r -R .
|
||||||
|
|
||||||
|
FROM debian:bullseye-slim
|
||||||
|
ENV UID=1000
|
||||||
|
ENV GID=1000
|
||||||
|
ENV USER=lldap
|
||||||
|
RUN apt update && \
|
||||||
|
apt install -y --no-install-recommends tini openssl ca-certificates gosu tzdata && \
|
||||||
|
apt clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
groupadd -g $GID $USER && useradd --system -m -g $USER --uid $UID $USER && \
|
||||||
|
mkdir -p /data && chown $USER:$USER /data
|
||||||
|
COPY --from=lldap --chown=$USER:$USER /lldap /app
|
||||||
|
COPY --from=lldap --chown=$USER:$USER /docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
VOLUME ["/data"]
|
||||||
|
WORKDIR /app
|
||||||
|
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
|
||||||
|
CMD ["run", "--config-file", "/data/lldap_config.toml"]
|
||||||
|
HEALTHCHECK CMD ["/app/lldap", "healthcheck", "--config-file", "/data/lldap_config.toml"]
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
FROM debian:bullseye AS lldap
|
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
|
||||||
ARG TARGETPLATFORM
|
|
||||||
RUN apt update && apt install -y wget
|
|
||||||
WORKDIR /dim
|
|
||||||
COPY bin/ bin/
|
|
||||||
COPY web/ web/
|
|
||||||
|
|
||||||
RUN mkdir -p target/
|
|
||||||
RUN mkdir -p /lldap/app
|
|
||||||
|
|
||||||
RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
|
|
||||||
mv bin/x86_64-unknown-linux-musl-lldap-bin/lldap target/lldap && \
|
|
||||||
mv bin/x86_64-unknown-linux-musl-lldap_migration_tool-bin/lldap_migration_tool target/lldap_migration_tool && \
|
|
||||||
mv bin/x86_64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
|
||||||
chmod +x target/lldap && \
|
|
||||||
chmod +x target/lldap_migration_tool && \
|
|
||||||
chmod +x target/lldap_set_password && \
|
|
||||||
ls -la target/ . && \
|
|
||||||
pwd \
|
|
||||||
; fi
|
|
||||||
|
|
||||||
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
|
||||||
mv bin/aarch64-unknown-linux-musl-lldap-bin/lldap target/lldap && \
|
|
||||||
mv bin/aarch64-unknown-linux-musl-lldap_migration_tool-bin/lldap_migration_tool target/lldap_migration_tool && \
|
|
||||||
mv bin/aarch64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
|
||||||
chmod +x target/lldap && \
|
|
||||||
chmod +x target/lldap_migration_tool && \
|
|
||||||
chmod +x target/lldap_set_password && \
|
|
||||||
ls -la target/ . && \
|
|
||||||
pwd \
|
|
||||||
; fi
|
|
||||||
|
|
||||||
RUN if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
|
|
||||||
mv bin/armv7-unknown-linux-musleabihf-lldap-bin/lldap target/lldap && \
|
|
||||||
mv bin/armv7-unknown-linux-musleabihf-lldap_migration_tool-bin/lldap_migration_tool target/lldap_migration_tool && \
|
|
||||||
mv bin/armv7-unknown-linux-musleabihf-lldap_set_password-bin/lldap_set_password target/lldap_set_password && \
|
|
||||||
chmod +x target/lldap && \
|
|
||||||
chmod +x target/lldap_migration_tool && \
|
|
||||||
chmod +x target/lldap_set_password && \
|
|
||||||
ls -la target/ . && \
|
|
||||||
pwd \
|
|
||||||
; fi
|
|
||||||
|
|
||||||
# Web and App dir
|
|
||||||
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
|
||||||
COPY lldap_config.docker_template.toml /lldap/
|
|
||||||
COPY web/index_local.html web/index.html
|
|
||||||
RUN cp target/lldap /lldap/ && \
|
|
||||||
cp target/lldap_migration_tool /lldap/ && \
|
|
||||||
cp target/lldap_set_password /lldap/ && \
|
|
||||||
cp -R web/index.html \
|
|
||||||
web/pkg \
|
|
||||||
web/static \
|
|
||||||
/lldap/app/
|
|
||||||
|
|
||||||
WORKDIR /lldap
|
|
||||||
RUN set -x \
|
|
||||||
&& for file in $(cat /lldap/app/static/libraries.txt); do wget -P app/static "$file"; done \
|
|
||||||
&& for file in $(cat /lldap/app/static/fonts/fonts.txt); do wget -P app/static/fonts "$file"; done \
|
|
||||||
&& chmod a+r -R .
|
|
||||||
|
|
||||||
FROM debian:bullseye-slim
|
|
||||||
ENV UID=1000
|
|
||||||
ENV GID=1000
|
|
||||||
ENV USER=lldap
|
|
||||||
RUN apt update && \
|
|
||||||
apt install -y --no-install-recommends tini openssl ca-certificates tzdata jq curl jo && \
|
|
||||||
apt clean && \
|
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
|
||||||
groupadd -g $GID $USER && useradd --system -m -g $USER --uid $UID $USER && \
|
|
||||||
mkdir -p /data && chown $USER:$USER /data
|
|
||||||
COPY --from=lldap --chown=$USER:$USER /lldap /app
|
|
||||||
COPY --from=lldap --chown=$USER:$USER /docker-entrypoint.sh /docker-entrypoint.sh
|
|
||||||
VOLUME ["/data"]
|
|
||||||
WORKDIR /app
|
|
||||||
COPY scripts/bootstrap.sh ./
|
|
||||||
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
|
|
||||||
CMD ["run", "--config-file", "/data/lldap_config.toml"]
|
|
||||||
HEALTHCHECK CMD ["/app/lldap", "healthcheck", "--config-file", "/data/lldap_config.toml"]
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
FROM localhost:5000/lldap/lldap:debian-base
|
|
||||||
COPY --chown=$USER:$USER docker-entrypoint-rootless.sh /docker-entrypoint.sh
|
|
||||||
USER $USER
|
|
||||||
@@ -1,41 +1,45 @@
|
|||||||
# Keep tracking base image
|
# Keep tracking base image
|
||||||
FROM rust:1.85-slim-bookworm
|
FROM rust:1.66-slim-bullseye
|
||||||
|
|
||||||
# Set needed env path
|
# Set needed env path
|
||||||
ENV PATH="/opt/armv7l-linux-musleabihf-cross/:/opt/armv7l-linux-musleabihf-cross/bin/:/opt/aarch64-linux-musl-cross/:/opt/aarch64-linux-musl-cross/bin/:/opt/x86_64-linux-musl-cross/:/opt/x86_64-linux-musl-cross/bin/:$PATH"
|
ENV PATH="/opt/aarch64-linux-musl-cross/:/opt/aarch64-linux-musl-cross/bin/:/opt/x86_64-linux-musl-cross/:/opt/x86_64-linux-musl-cross/bin/:$PATH"
|
||||||
|
|
||||||
# Set building env
|
### Install build deps x86_64
|
||||||
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse \
|
|
||||||
CARGO_NET_GIT_FETCH_WITH_CLI=true \
|
|
||||||
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=armv7l-linux-musleabihf-gcc \
|
|
||||||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc \
|
|
||||||
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-linux-musl-gcc \
|
|
||||||
CC_armv7_unknown_linux_musleabihf=armv7l-linux-musleabihf-gcc \
|
|
||||||
CC_x86_64_unknown_linux_musl=x86_64-linux-musl-gcc \
|
|
||||||
CC_aarch64_unknown_linux_musl=aarch64-linux-musl-gcc
|
|
||||||
|
|
||||||
### Install Additional Build Tools
|
|
||||||
RUN apt update && \
|
RUN apt update && \
|
||||||
apt install -y --no-install-recommends curl git wget make perl pkg-config tar jq gzip && \
|
apt install -y --no-install-recommends curl git wget build-essential make perl pkg-config curl tar jq musl-tools gzip && \
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
|
||||||
|
apt update && \
|
||||||
|
apt install -y --no-install-recommends nodejs && \
|
||||||
apt clean && \
|
apt clean && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
### Add musl-gcc aarch64, x86_64 and armv7l
|
### Install build deps aarch64 build
|
||||||
|
RUN dpkg --add-architecture arm64 && \
|
||||||
|
apt update && \
|
||||||
|
apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross gzip && \
|
||||||
|
apt clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
rustup target add aarch64-unknown-linux-gnu
|
||||||
|
|
||||||
|
### armhf deps
|
||||||
|
RUN dpkg --add-architecture armhf && \
|
||||||
|
apt update && \
|
||||||
|
apt install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-armhf-cross libc6-dev-armhf-cross gzip && \
|
||||||
|
apt clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
rustup target add armv7-unknown-linux-gnueabihf
|
||||||
|
|
||||||
|
### Add musl-gcc aarch64 and x86_64
|
||||||
RUN wget -c https://musl.cc/x86_64-linux-musl-cross.tgz && \
|
RUN wget -c https://musl.cc/x86_64-linux-musl-cross.tgz && \
|
||||||
tar zxf ./x86_64-linux-musl-cross.tgz -C /opt && \
|
tar zxf ./x86_64-linux-musl-cross.tgz -C /opt && \
|
||||||
wget -c https://musl.cc/aarch64-linux-musl-cross.tgz && \
|
wget -c https://musl.cc/aarch64-linux-musl-cross.tgz && \
|
||||||
tar zxf ./aarch64-linux-musl-cross.tgz -C /opt && \
|
tar zxf ./aarch64-linux-musl-cross.tgz -C /opt && \
|
||||||
wget -c http://musl.cc/armv7l-linux-musleabihf-cross.tgz && \
|
|
||||||
tar zxf ./armv7l-linux-musleabihf-cross.tgz -C /opt && \
|
|
||||||
rm ./x86_64-linux-musl-cross.tgz && \
|
rm ./x86_64-linux-musl-cross.tgz && \
|
||||||
rm ./aarch64-linux-musl-cross.tgz && \
|
rm ./aarch64-linux-musl-cross.tgz
|
||||||
rm ./armv7l-linux-musleabihf-cross.tgz
|
|
||||||
|
|
||||||
### Add musl target
|
### Add musl target
|
||||||
RUN rustup target add x86_64-unknown-linux-musl && \
|
RUN rustup target add x86_64-unknown-linux-musl && \
|
||||||
rustup target add aarch64-unknown-linux-musl && \
|
rustup target add aarch64-unknown-linux-musl
|
||||||
rustup target add armv7-unknown-linux-musleabihf && \
|
|
||||||
rustup target add x86_64-unknown-freebsd
|
|
||||||
|
|
||||||
|
|
||||||
CMD ["bash"]
|
CMD ["bash"]
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ env:
|
|||||||
|
|
||||||
# build-ui , create/compile the web
|
# build-ui , create/compile the web
|
||||||
### install wasm
|
### install wasm
|
||||||
|
### install rollup
|
||||||
### run app/build.sh
|
### run app/build.sh
|
||||||
### upload artifacts
|
### upload artifacts
|
||||||
|
|
||||||
@@ -39,10 +40,10 @@ env:
|
|||||||
# GitHub actions randomly timeout when downloading musl-gcc, using custom dev image #
|
# GitHub actions randomly timeout when downloading musl-gcc, using custom dev image #
|
||||||
# Look into .github/workflows/Dockerfile.dev for development image details #
|
# Look into .github/workflows/Dockerfile.dev for development image details #
|
||||||
# Using lldap dev image based on https://hub.docker.com/_/rust and musl-gcc bundled #
|
# Using lldap dev image based on https://hub.docker.com/_/rust and musl-gcc bundled #
|
||||||
# lldap/rust-dev #
|
|
||||||
#######################################################################################
|
#######################################################################################
|
||||||
# Cargo build
|
### Cargo build
|
||||||
### armv7, aarch64 and amd64 is musl based
|
### aarch64 and amd64 is musl based
|
||||||
|
### armv7 is glibc based, musl had issue with time_t when cross compile https://github.com/rust-lang/libc/issues/1848
|
||||||
|
|
||||||
# build-ui,builds-armhf, build-aarch64, build-amd64 will upload artifacts will be used next job
|
# build-ui,builds-armhf, build-aarch64, build-amd64 will upload artifacts will be used next job
|
||||||
|
|
||||||
@@ -50,11 +51,12 @@ env:
|
|||||||
### will run lldap with postgres, mariadb and sqlite backend, do selfcheck command.
|
### will run lldap with postgres, mariadb and sqlite backend, do selfcheck command.
|
||||||
|
|
||||||
# Build docker image
|
# Build docker image
|
||||||
### Triplet docker image arch with debian and alpine base
|
### Triplet docker image arch with debian base
|
||||||
|
### amd64 & aarch64 with alpine base
|
||||||
# build-docker-image job will fetch artifacts and run Dockerfile.ci then push the image.
|
# build-docker-image job will fetch artifacts and run Dockerfile.ci then push the image.
|
||||||
### Look into .github/workflows/Dockerfile.ci.debian or .github/workflowds/Dockerfile.ci.alpine
|
### Look into .github/workflows/Dockerfile.ci.debian or .github/workflowds/Dockerfile.ci.alpine
|
||||||
|
|
||||||
# Create release artifacts
|
# create release artifacts
|
||||||
### Fetch artifacts
|
### Fetch artifacts
|
||||||
### Clean up web artifact
|
### Clean up web artifact
|
||||||
### Setup folder structure
|
### Setup folder structure
|
||||||
@@ -82,13 +84,13 @@ jobs:
|
|||||||
build-ui:
|
build-ui:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: pre_job
|
needs: pre_job
|
||||||
if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.event_name == 'release' }}
|
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
|
||||||
container:
|
container:
|
||||||
image: lldap/rust-dev:latest
|
image: nitnelave/rust-dev:latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v5.0.0
|
uses: actions/checkout@v3.5.0
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
/usr/local/cargo/bin
|
/usr/local/cargo/bin
|
||||||
@@ -99,6 +101,8 @@ jobs:
|
|||||||
key: lldap-ui-${{ hashFiles('**/Cargo.lock') }}
|
key: lldap-ui-${{ hashFiles('**/Cargo.lock') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
lldap-ui-
|
lldap-ui-
|
||||||
|
- name: Install rollup (nodejs)
|
||||||
|
run: npm install -g rollup
|
||||||
- name: Add wasm target (rust)
|
- name: Add wasm target (rust)
|
||||||
run: rustup target add wasm32-unknown-unknown
|
run: rustup target add wasm32-unknown-unknown
|
||||||
- name: Install wasm-pack with cargo
|
- name: Install wasm-pack with cargo
|
||||||
@@ -110,7 +114,7 @@ jobs:
|
|||||||
- name: Check build path
|
- name: Check build path
|
||||||
run: ls -al app/
|
run: ls -al app/
|
||||||
- name: Upload ui artifacts
|
- name: Upload ui artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ui
|
name: ui
|
||||||
path: app/
|
path: app/
|
||||||
@@ -119,21 +123,23 @@ jobs:
|
|||||||
build-bin:
|
build-bin:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: pre_job
|
needs: pre_job
|
||||||
if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.event_name == 'release' }}
|
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
matrix:
|
||||||
target: [armv7-unknown-linux-musleabihf, aarch64-unknown-linux-musl, x86_64-unknown-linux-musl]
|
target: [armv7-unknown-linux-gnueabihf, aarch64-unknown-linux-musl, x86_64-unknown-linux-musl]
|
||||||
container:
|
container:
|
||||||
image: lldap/rust-dev:latest
|
image: nitnelave/rust-dev:latest
|
||||||
env:
|
env:
|
||||||
|
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
|
||||||
|
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-musl-gcc
|
||||||
|
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: x86_64-linux-musl-gcc
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
RUSTFLAGS: -Ctarget-feature=+crt-static
|
RUSTFLAGS: -Ctarget-feature=+crt-static
|
||||||
CARGO_HOME: ${GITHUB_WORKSPACE}/.cargo
|
CARGO_HOME: ${GITHUB_WORKSPACE}/.cargo
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v5.0.0
|
uses: actions/checkout@v3.5.0
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
.cargo/bin
|
.cargo/bin
|
||||||
@@ -145,21 +151,21 @@ jobs:
|
|||||||
restore-keys: |
|
restore-keys: |
|
||||||
lldap-bin-${{ matrix.target }}-
|
lldap-bin-${{ matrix.target }}-
|
||||||
- name: Compile ${{ matrix.target }} lldap and tools
|
- name: Compile ${{ matrix.target }} lldap and tools
|
||||||
run: cargo build --target=${{ matrix.target }} --release -p lldap -p lldap_migration_tool -p lldap_set_password
|
run: cargo build --target=${{ matrix.target }} --release -p lldap -p migration-tool -p lldap_set_password
|
||||||
- name: Check path
|
- name: Check path
|
||||||
run: ls -al target/release
|
run: ls -al target/release
|
||||||
- name: Upload ${{ matrix.target}} lldap artifacts
|
- name: Upload ${{ matrix.target}} lldap artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.target}}-lldap-bin
|
name: ${{ matrix.target}}-lldap-bin
|
||||||
path: target/${{ matrix.target }}/release/lldap
|
path: target/${{ matrix.target }}/release/lldap
|
||||||
- name: Upload ${{ matrix.target }} migration tool artifacts
|
- name: Upload ${{ matrix.target }} migration tool artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.target }}-lldap_migration_tool-bin
|
name: ${{ matrix.target }}-migration-tool-bin
|
||||||
path: target/${{ matrix.target }}/release/lldap_migration_tool
|
path: target/${{ matrix.target }}/release/migration-tool
|
||||||
- name: Upload ${{ matrix.target }} password tool artifacts
|
- name: Upload ${{ matrix.target }} password tool artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.target }}-lldap_set_password-bin
|
name: ${{ matrix.target }}-lldap_set_password-bin
|
||||||
path: target/${{ matrix.target }}/release/lldap_set_password
|
path: target/${{ matrix.target }}/release/lldap_set_password
|
||||||
@@ -174,13 +180,11 @@ jobs:
|
|||||||
ports:
|
ports:
|
||||||
- 3306:3306
|
- 3306:3306
|
||||||
env:
|
env:
|
||||||
MARIADB_USER: lldapuser
|
MYSQL_USER: lldapuser
|
||||||
MARIADB_PASSWORD: lldappass
|
MYSQL_PASSWORD: lldappass
|
||||||
MARIADB_DATABASE: lldap
|
MYSQL_DATABASE: lldap
|
||||||
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
|
MYSQL_ROOT_PASSWORD: rootpass
|
||||||
options: >-
|
options: --name mariadb
|
||||||
--name mariadb
|
|
||||||
--health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3
|
|
||||||
|
|
||||||
postgresql:
|
postgresql:
|
||||||
image: postgres:latest
|
image: postgres:latest
|
||||||
@@ -190,16 +194,11 @@ jobs:
|
|||||||
POSTGRES_USER: lldapuser
|
POSTGRES_USER: lldapuser
|
||||||
POSTGRES_PASSWORD: lldappass
|
POSTGRES_PASSWORD: lldappass
|
||||||
POSTGRES_DB: lldap
|
POSTGRES_DB: lldap
|
||||||
options: >-
|
options: --name postgresql
|
||||||
--health-cmd pg_isready
|
|
||||||
--health-interval 10s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 5
|
|
||||||
--name postgresql
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: x86_64-unknown-linux-musl-lldap-bin
|
name: x86_64-unknown-linux-musl-lldap-bin
|
||||||
path: bin/
|
path: bin/
|
||||||
@@ -216,8 +215,6 @@ jobs:
|
|||||||
LLDAP_database_url: postgres://lldapuser:lldappass@localhost/lldap
|
LLDAP_database_url: postgres://lldapuser:lldappass@localhost/lldap
|
||||||
LLDAP_ldap_port: 3890
|
LLDAP_ldap_port: 3890
|
||||||
LLDAP_http_port: 17170
|
LLDAP_http_port: 17170
|
||||||
LLDAP_JWT_SECRET: verysecret
|
|
||||||
LLDAP_LDAP_USER_PASS: password
|
|
||||||
|
|
||||||
|
|
||||||
- name: Run lldap with mariadb DB (MySQL Compatible) and healthcheck
|
- name: Run lldap with mariadb DB (MySQL Compatible) and healthcheck
|
||||||
@@ -229,8 +226,6 @@ jobs:
|
|||||||
LLDAP_database_url: mysql://lldapuser:lldappass@localhost/lldap
|
LLDAP_database_url: mysql://lldapuser:lldappass@localhost/lldap
|
||||||
LLDAP_ldap_port: 3891
|
LLDAP_ldap_port: 3891
|
||||||
LLDAP_http_port: 17171
|
LLDAP_http_port: 17171
|
||||||
LLDAP_JWT_SECRET: verysecret
|
|
||||||
LLDAP_LDAP_USER_PASS: password
|
|
||||||
|
|
||||||
|
|
||||||
- name: Run lldap with sqlite DB and healthcheck
|
- name: Run lldap with sqlite DB and healthcheck
|
||||||
@@ -242,8 +237,6 @@ jobs:
|
|||||||
LLDAP_database_url: sqlite://users.db?mode=rwc
|
LLDAP_database_url: sqlite://users.db?mode=rwc
|
||||||
LLDAP_ldap_port: 3892
|
LLDAP_ldap_port: 3892
|
||||||
LLDAP_http_port: 17172
|
LLDAP_http_port: 17172
|
||||||
LLDAP_JWT_SECRET: verysecret
|
|
||||||
LLDAP_LDAP_USER_PASS: password
|
|
||||||
|
|
||||||
- name: Check DB container logs
|
- name: Check DB container logs
|
||||||
run: |
|
run: |
|
||||||
@@ -263,27 +256,17 @@ jobs:
|
|||||||
POSTGRES_USER: lldapuser
|
POSTGRES_USER: lldapuser
|
||||||
POSTGRES_PASSWORD: lldappass
|
POSTGRES_PASSWORD: lldappass
|
||||||
POSTGRES_DB: lldap
|
POSTGRES_DB: lldap
|
||||||
options: >-
|
options: --name postgresql
|
||||||
--health-cmd pg_isready
|
|
||||||
--health-interval 10s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 5
|
|
||||||
--name postgresql
|
|
||||||
|
|
||||||
mariadb:
|
mariadb:
|
||||||
image: mariadb:latest
|
image: mariadb:latest
|
||||||
ports:
|
ports:
|
||||||
- 3306:3306
|
- 3306:3306
|
||||||
env:
|
env:
|
||||||
MARIADB_USER: lldapuser
|
MYSQL_USER: lldapuser
|
||||||
MARIADB_PASSWORD: lldappass
|
MYSQL_PASSWORD: lldappass
|
||||||
MARIADB_DATABASE: lldap
|
MYSQL_DATABASE: lldap
|
||||||
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
|
MYSQL_ROOT_PASSWORD: rootpass
|
||||||
options: >-
|
options: --name mariadb
|
||||||
--name mariadb
|
|
||||||
--health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3
|
|
||||||
|
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
image: mysql:latest
|
image: mysql:latest
|
||||||
ports:
|
ports:
|
||||||
@@ -292,26 +275,19 @@ jobs:
|
|||||||
MYSQL_USER: lldapuser
|
MYSQL_USER: lldapuser
|
||||||
MYSQL_PASSWORD: lldappass
|
MYSQL_PASSWORD: lldappass
|
||||||
MYSQL_DATABASE: lldap
|
MYSQL_DATABASE: lldap
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: 1
|
MYSQL_ROOT_PASSWORD: rootpass
|
||||||
options: >-
|
options: --name mysql
|
||||||
--name mysql
|
|
||||||
--health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
|
|
||||||
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout scripts
|
|
||||||
uses: actions/checkout@v5.0.0
|
|
||||||
with:
|
|
||||||
sparse-checkout: 'scripts'
|
|
||||||
|
|
||||||
- name: Download LLDAP artifacts
|
- name: Download LLDAP artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: x86_64-unknown-linux-musl-lldap-bin
|
name: x86_64-unknown-linux-musl-lldap-bin
|
||||||
path: bin/
|
path: bin/
|
||||||
|
|
||||||
- name: Download LLDAP set password
|
- name: Download LLDAP set password
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: x86_64-unknown-linux-musl-lldap_set_password-bin
|
name: x86_64-unknown-linux-musl-lldap_set_password-bin
|
||||||
path: bin/
|
path: bin/
|
||||||
@@ -330,15 +306,15 @@ jobs:
|
|||||||
sleep 10s
|
sleep 10s
|
||||||
bin/lldap healthcheck
|
bin/lldap healthcheck
|
||||||
env:
|
env:
|
||||||
LLDAP_DATABASE_URL: sqlite://users.db?mode=rwc
|
LLDAP_database_url: sqlite://users.db?mode=rwc
|
||||||
LLDAP_LDAP_PORT: 3890
|
LLDAP_ldap_port: 3890
|
||||||
LLDAP_HTTP_PORT: 17170
|
LLDAP_http_port: 17170
|
||||||
LLDAP_LDAP_USER_PASS: ldappass
|
LLDAP_LDAP_USER_PASS: ldappass
|
||||||
LLDAP_JWT_SECRET: somejwtsecret
|
LLDAP_JWT_SECRET: somejwtsecret
|
||||||
|
|
||||||
- name: Create dummy user
|
- name: Create dummy user
|
||||||
run: |
|
run: |
|
||||||
TOKEN=$(curl -X POST -H "Content-Type: application/json" -d '{"username": "admin", "password": "ldappass"}' http://localhost:17170/auth/simple/login | jq -r .token)
|
TOKEN=$(curl -X POST -H "Content-Type: application/json" -d '{"username": "admin", "password": "ldappass"}' http://localhost:17170/auth/simple/login | cut -c 11-277)
|
||||||
echo "$TOKEN"
|
echo "$TOKEN"
|
||||||
curl 'http://localhost:17170/api/graphql' -H 'Content-Type: application/json' -H "Authorization: Bearer ${TOKEN//[$'\t\r\n ']}" --data-binary '{"query":"mutation{\n createUser(user:\n {\n id: \"dummyuser\",\n email: \"dummyuser@example.com\"\n }\n )\n {\n id\n email\n }\n}\n\n\n"}' --compressed
|
curl 'http://localhost:17170/api/graphql' -H 'Content-Type: application/json' -H "Authorization: Bearer ${TOKEN//[$'\t\r\n ']}" --data-binary '{"query":"mutation{\n createUser(user:\n {\n id: \"dummyuser\",\n email: \"dummyuser@example.com\"\n }\n )\n {\n id\n email\n }\n}\n\n\n"}' --compressed
|
||||||
bin/lldap_set_password --base-url http://localhost:17170 --admin-username admin --admin-password ldappass --token $TOKEN --username dummyuser --password dummypassword
|
bin/lldap_set_password --base-url http://localhost:17170 --admin-username admin --admin-password ldappass --token $TOKEN --username dummyuser --password dummypassword
|
||||||
@@ -352,61 +328,58 @@ jobs:
|
|||||||
|
|
||||||
- name: Export and Converting to Postgress
|
- name: Export and Converting to Postgress
|
||||||
run: |
|
run: |
|
||||||
bash ./scripts/sqlite_dump_commands.sh | sqlite3 ./users.db > ./dump.sql
|
curl -L https://raw.githubusercontent.com/nitnelave/lldap/main/scripts/sqlite_dump_commands.sh -o helper.sh
|
||||||
sed -i -r -e "s/X'([[:xdigit:]]+'[^'])/'\\\x\\1/g" -e ":a; s/(INSERT INTO (user_attribute_schema|jwt_storage)\(.*\) VALUES\(.*),1([^']*\);)$/\1,true\3/; s/(INSERT INTO (user_attribute_schema|jwt_storage)\(.*\) VALUES\(.*),0([^']*\);)$/\1,false\3/; ta" -e '1s/^/BEGIN;\n/' -e '$aCOMMIT;' ./dump.sql
|
chmod +x ./helper.sh
|
||||||
|
./helper.sh | sqlite3 ./users.db > ./dump.sql
|
||||||
|
sed -i -r -e "s/X'([[:xdigit:]]+'[^'])/'\\\x\\1/g" -e '1s/^/BEGIN;\n/' -e '$aCOMMIT;' ./dump.sql
|
||||||
|
|
||||||
- name: Create schema on postgres
|
- name: Create schema on postgres
|
||||||
env:
|
|
||||||
LLDAP_DATABASE_URL: postgres://lldapuser:lldappass@localhost:5432/lldap
|
|
||||||
LLDAP_JWT_SECRET: somejwtsecret
|
|
||||||
run: |
|
run: |
|
||||||
bin/lldap create_schema
|
bin/lldap create_schema -d postgres://lldapuser:lldappass@localhost:5432/lldap
|
||||||
|
|
||||||
- name: Copy converted db to postgress and import
|
- name: Copy converted db to postgress and import
|
||||||
run: |
|
run: |
|
||||||
|
docker ps -a
|
||||||
docker cp ./dump.sql postgresql:/tmp/dump.sql
|
docker cp ./dump.sql postgresql:/tmp/dump.sql
|
||||||
docker exec postgresql bash -c "psql -U lldapuser -d lldap < /tmp/dump.sql" | tee import.log
|
docker exec postgresql bash -c "psql -U lldapuser -d lldap < /tmp/dump.sql"
|
||||||
rm ./dump.sql
|
rm ./dump.sql
|
||||||
! grep ERROR import.log > /dev/null
|
|
||||||
|
|
||||||
- name: Export and Converting to mariadb
|
- name: Export and Converting to mariadb
|
||||||
run: |
|
run: |
|
||||||
bash ./scripts/sqlite_dump_commands.sh | sqlite3 ./users.db > ./dump.sql
|
curl -L https://raw.githubusercontent.com/nitnelave/lldap/main/scripts/sqlite_dump_commands.sh -o helper.sh
|
||||||
|
chmod +x ./helper.sh
|
||||||
|
./helper.sh | sqlite3 ./users.db > ./dump.sql
|
||||||
cp ./dump.sql ./dump-no-sed.sql
|
cp ./dump.sql ./dump-no-sed.sql
|
||||||
sed -i -r -e "s/([^']'[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{9})\+00:00'([^'])/\1'\2/g" \-e 's/^INSERT INTO "?([a-zA-Z0-9_]+)"?/INSERT INTO `\1`/' -e '1s/^/START TRANSACTION;\n/' -e '$aCOMMIT;' ./dump.sql
|
sed -i -r -e "s/([^']'[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{9})\+00:00'([^'])/\1'\2/g" \-e 's/^INSERT INTO "?([a-zA-Z0-9_]+)"?/INSERT INTO `\1`/' -e '1s/^/START TRANSACTION;\n/' -e '$aCOMMIT;' ./dump.sql
|
||||||
sed -i '1 i\SET FOREIGN_KEY_CHECKS = 0;' ./dump.sql
|
sed -i '1 i\SET FOREIGN_KEY_CHECKS = 0;' ./dump.sql
|
||||||
|
|
||||||
- name: Create schema on mariadb
|
- name: Create schema on mariadb
|
||||||
env:
|
run: bin/lldap create_schema -d mysql://lldapuser:lldappass@localhost:3306/lldap
|
||||||
LLDAP_DATABASE_URL: mysql://lldapuser:lldappass@localhost:3306/lldap
|
|
||||||
LLDAP_JWT_SECRET: somejwtsecret
|
|
||||||
run: bin/lldap create_schema
|
|
||||||
|
|
||||||
- name: Copy converted db to mariadb and import
|
- name: Copy converted db to mariadb and import
|
||||||
run: |
|
run: |
|
||||||
|
docker ps -a
|
||||||
docker cp ./dump.sql mariadb:/tmp/dump.sql
|
docker cp ./dump.sql mariadb:/tmp/dump.sql
|
||||||
docker exec mariadb bash -c "mariadb -ulldapuser -plldappass -f lldap < /tmp/dump.sql" | tee import.log
|
docker exec mariadb bash -c "mariadb -ulldapuser -plldappass -f lldap < /tmp/dump.sql"
|
||||||
rm ./dump.sql
|
rm ./dump.sql
|
||||||
! grep ERROR import.log > /dev/null
|
|
||||||
|
|
||||||
- name: Export and Converting to mysql
|
- name: Export and Converting to mysql
|
||||||
run: |
|
run: |
|
||||||
bash ./scripts/sqlite_dump_commands.sh | sqlite3 ./users.db > ./dump.sql
|
curl -L https://raw.githubusercontent.com/nitnelave/lldap/main/scripts/sqlite_dump_commands.sh -o helper.sh
|
||||||
|
chmod +x ./helper.sh
|
||||||
|
./helper.sh | sqlite3 ./users.db > ./dump.sql
|
||||||
sed -i -r -e 's/^INSERT INTO "?([a-zA-Z0-9_]+)"?/INSERT INTO `\1`/' -e '1s/^/START TRANSACTION;\n/' -e '$aCOMMIT;' ./dump.sql
|
sed -i -r -e 's/^INSERT INTO "?([a-zA-Z0-9_]+)"?/INSERT INTO `\1`/' -e '1s/^/START TRANSACTION;\n/' -e '$aCOMMIT;' ./dump.sql
|
||||||
sed -i '1 i\SET FOREIGN_KEY_CHECKS = 0;' ./dump.sql
|
sed -i '1 i\SET FOREIGN_KEY_CHECKS = 0;' ./dump.sql
|
||||||
|
|
||||||
- name: Create schema on mysql
|
- name: Create schema on mysql
|
||||||
env:
|
run: bin/lldap create_schema -d mysql://lldapuser:lldappass@localhost:3307/lldap
|
||||||
LLDAP_DATABASE_URL: mysql://lldapuser:lldappass@localhost:3307/lldap
|
|
||||||
LLDAP_JWT_SECRET: somejwtsecret
|
|
||||||
run: bin/lldap create_schema
|
|
||||||
|
|
||||||
- name: Copy converted db to mysql and import
|
- name: Copy converted db to mysql and import
|
||||||
run: |
|
run: |
|
||||||
|
docker ps -a
|
||||||
docker cp ./dump.sql mysql:/tmp/dump.sql
|
docker cp ./dump.sql mysql:/tmp/dump.sql
|
||||||
docker exec mysql bash -c "mysql -ulldapuser -plldappass -f lldap < /tmp/dump.sql" | tee import.log
|
docker exec mysql bash -c "mysql -ulldapuser -plldappass -f lldap < /tmp/dump.sql"
|
||||||
rm ./dump.sql
|
rm ./dump.sql
|
||||||
! grep ERROR import.log > /dev/null
|
|
||||||
|
|
||||||
- name: Run lldap with postgres DB and healthcheck again
|
- name: Run lldap with postgres DB and healthcheck again
|
||||||
run: |
|
run: |
|
||||||
@@ -414,9 +387,10 @@ jobs:
|
|||||||
sleep 10s
|
sleep 10s
|
||||||
bin/lldap healthcheck
|
bin/lldap healthcheck
|
||||||
env:
|
env:
|
||||||
LLDAP_DATABASE_URL: postgres://lldapuser:lldappass@localhost:5432/lldap
|
LLDAP_database_url: postgres://lldapuser:lldappass@localhost:5432/lldap
|
||||||
LLDAP_LDAP_PORT: 3891
|
LLDAP_ldap_port: 3891
|
||||||
LLDAP_HTTP_PORT: 17171
|
LLDAP_http_port: 17171
|
||||||
|
LLDAP_LDAP_USER_PASS: ldappass
|
||||||
LLDAP_JWT_SECRET: somejwtsecret
|
LLDAP_JWT_SECRET: somejwtsecret
|
||||||
|
|
||||||
- name: Run lldap with mariaDB and healthcheck again
|
- name: Run lldap with mariaDB and healthcheck again
|
||||||
@@ -425,9 +399,9 @@ jobs:
|
|||||||
sleep 10s
|
sleep 10s
|
||||||
bin/lldap healthcheck
|
bin/lldap healthcheck
|
||||||
env:
|
env:
|
||||||
LLDAP_DATABASE_URL: mysql://lldapuser:lldappass@localhost:3306/lldap
|
LLDAP_database_url: mysql://lldapuser:lldappass@localhost:3306/lldap
|
||||||
LLDAP_LDAP_PORT: 3892
|
LLDAP_ldap_port: 3892
|
||||||
LLDAP_HTTP_PORT: 17172
|
LLDAP_http_port: 17172
|
||||||
LLDAP_JWT_SECRET: somejwtsecret
|
LLDAP_JWT_SECRET: somejwtsecret
|
||||||
|
|
||||||
- name: Run lldap with mysql and healthcheck again
|
- name: Run lldap with mysql and healthcheck again
|
||||||
@@ -436,239 +410,133 @@ jobs:
|
|||||||
sleep 10s
|
sleep 10s
|
||||||
bin/lldap healthcheck
|
bin/lldap healthcheck
|
||||||
env:
|
env:
|
||||||
LLDAP_DATABASE_URL: mysql://lldapuser:lldappass@localhost:3307/lldap
|
LLDAP_database_url: mysql://lldapuser:lldappass@localhost:3307/lldap
|
||||||
LLDAP_LDAP_PORT: 3893
|
LLDAP_ldap_port: 3893
|
||||||
LLDAP_HTTP_PORT: 17173
|
LLDAP_http_port: 17173
|
||||||
LLDAP_JWT_SECRET: somejwtsecret
|
LLDAP_JWT_SECRET: somejwtsecret
|
||||||
|
|
||||||
- name: Test Dummy User Postgres
|
- name: Test Dummy User
|
||||||
run: ldapsearch -H ldap://localhost:3891 -LLL -D "uid=dummyuser,ou=people,dc=example,dc=com" -w 'dummypassword' -s "One" -b "ou=people,dc=example,dc=com"
|
run: |
|
||||||
- name: Test Dummy User MariaDB
|
ldapsearch -H ldap://localhost:3891 -LLL -D "uid=dummyuser,ou=people,dc=example,dc=com" -w 'dummypassword' -s "One" -b "ou=people,dc=example,dc=com"
|
||||||
run: ldapsearch -H ldap://localhost:3892 -LLL -D "uid=dummyuser,ou=people,dc=example,dc=com" -w 'dummypassword' -s "One" -b "ou=people,dc=example,dc=com"
|
ldapsearch -H ldap://localhost:3892 -LLL -D "uid=dummyuser,ou=people,dc=example,dc=com" -w 'dummypassword' -s "One" -b "ou=people,dc=example,dc=com"
|
||||||
- name: Test Dummy User MySQL
|
ldapsearch -H ldap://localhost:3893 -LLL -D "uid=dummyuser,ou=people,dc=example,dc=com" -w 'dummypassword' -s "One" -b "ou=people,dc=example,dc=com"
|
||||||
run: ldapsearch -H ldap://localhost:3893 -LLL -D "uid=dummyuser,ou=people,dc=example,dc=com" -w 'dummypassword' -s "One" -b "ou=people,dc=example,dc=com"
|
|
||||||
|
|
||||||
########################################
|
|
||||||
#### BUILD BASE IMAGE ##################
|
|
||||||
########################################
|
|
||||||
build-docker-image:
|
build-docker-image:
|
||||||
needs: [build-ui, build-bin]
|
needs: [build-ui, build-bin]
|
||||||
name: Build Docker image
|
name: Build Docker image
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
container: ["debian","alpine"]
|
|
||||||
include:
|
|
||||||
- container: alpine
|
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
||||||
tags: |
|
|
||||||
type=ref,event=pr
|
|
||||||
type=semver,pattern=v{{version}}
|
|
||||||
type=semver,pattern=v{{major}}
|
|
||||||
type=semver,pattern=v{{major}}.{{minor}}
|
|
||||||
type=semver,pattern=v{{version}},suffix=
|
|
||||||
type=semver,pattern=v{{major}},suffix=
|
|
||||||
type=semver,pattern=v{{major}}.{{minor}},suffix=
|
|
||||||
type=raw,value=latest,enable={{ is_default_branch }}
|
|
||||||
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
||||||
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/v') }},suffix=
|
|
||||||
type=raw,value=latest,enable={{ is_default_branch }},suffix=
|
|
||||||
type=raw,value={{ date 'YYYY-MM-DD' }},enable={{ is_default_branch }}
|
|
||||||
type=raw,value={{ date 'YYYY-MM-DD' }},enable={{ is_default_branch }},suffix=
|
|
||||||
- container: debian
|
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
||||||
tags: |
|
|
||||||
type=ref,event=pr
|
|
||||||
type=semver,pattern=v{{version}}
|
|
||||||
type=semver,pattern=v{{major}}
|
|
||||||
type=semver,pattern=v{{major}}.{{minor}}
|
|
||||||
type=raw,value=latest,enable={{ is_default_branch }}
|
|
||||||
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
||||||
type=raw,value={{ date 'YYYY-MM-DD' }},enable={{ is_default_branch }}
|
|
||||||
services:
|
|
||||||
registry:
|
|
||||||
image: registry:2
|
|
||||||
ports:
|
|
||||||
- 5000:5000
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v5.0.0
|
uses: actions/checkout@v3.5.0
|
||||||
|
|
||||||
- name: Download all artifacts
|
- name: Download all artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
path: bin
|
path: bin
|
||||||
|
|
||||||
- name: Download llap ui artifacts
|
- name: Download llap ui artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ui
|
name: ui
|
||||||
path: web
|
path: web
|
||||||
|
|
||||||
- name: Setup QEMU
|
- name: Setup QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v2
|
||||||
- name: Setup buildx
|
- uses: docker/setup-buildx-action@v2
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
driver-opts: network=host
|
|
||||||
|
|
||||||
- name: Docker ${{ matrix.container }} Base meta
|
- name: Docker meta
|
||||||
id: meta-base
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
# list of Docker images to use as base name for tags
|
# list of Docker images to use as base name for tags
|
||||||
images: |
|
images: |
|
||||||
localhost:5000/lldap/lldap
|
nitnelave/lldap
|
||||||
tags: ${{ matrix.container }}-base
|
# generate Docker tags based on the following events/attributes
|
||||||
|
|
||||||
- name: Build ${{ matrix.container }} Base Docker Image
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
# On PR will fail, force fully uncomment push: true, or docker image will fail for next steps
|
|
||||||
#push: ${{ github.event_name != 'pull_request' }}
|
|
||||||
push: true
|
|
||||||
platforms: ${{ matrix.platforms }}
|
|
||||||
file: ./.github/workflows/Dockerfile.ci.${{ matrix.container }}-base
|
|
||||||
tags: |
|
tags: |
|
||||||
${{ steps.meta-base.outputs.tags }}
|
type=ref,event=branch
|
||||||
labels: ${{ steps.meta-base.outputs.labels }}
|
type=ref,event=pr
|
||||||
cache-from: type=gha,mode=max
|
type=semver,pattern={{version}}
|
||||||
cache-to: type=gha,mode=max
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}
|
||||||
|
type=sha
|
||||||
|
|
||||||
#####################################
|
- name: parse tag
|
||||||
#### build variants docker image ####
|
uses: gacts/github-slug@v1
|
||||||
#####################################
|
id: slug
|
||||||
|
|
||||||
- name: Docker ${{ matrix.container }}-rootless meta
|
- name: Login to Docker Hub
|
||||||
id: meta-rootless
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
# list of Docker images to use as base name for tags
|
|
||||||
images: |
|
|
||||||
nitnelave/lldap
|
|
||||||
lldap/lldap
|
|
||||||
ghcr.io/lldap/lldap
|
|
||||||
# Wanted Docker tags
|
|
||||||
# vX-alpine
|
|
||||||
# vX.Y-alpine
|
|
||||||
# vX.Y.Z-alpine
|
|
||||||
# latest
|
|
||||||
# latest-alpine
|
|
||||||
# stable
|
|
||||||
# stable-alpine
|
|
||||||
# YYYY-MM-DD
|
|
||||||
# YYYY-MM-DD-alpine
|
|
||||||
#################
|
|
||||||
# vX-debian
|
|
||||||
# vX.Y-debian
|
|
||||||
# vX.Y.Z-debian
|
|
||||||
# latest-debian
|
|
||||||
# stable-debian
|
|
||||||
# YYYY-MM-DD-debian
|
|
||||||
#################
|
|
||||||
# Check matrix for tag list definition
|
|
||||||
flavor: |
|
|
||||||
latest=false
|
|
||||||
suffix=-${{ matrix.container }}-rootless
|
|
||||||
tags: ${{ matrix.tags }}
|
|
||||||
|
|
||||||
- name: Docker ${{ matrix.container }} meta
|
|
||||||
id: meta-standard
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
# list of Docker images to use as base name for tags
|
|
||||||
images: |
|
|
||||||
nitnelave/lldap
|
|
||||||
lldap/lldap
|
|
||||||
ghcr.io/lldap/lldap
|
|
||||||
# Wanted Docker tags
|
|
||||||
# vX-alpine
|
|
||||||
# vX.Y-alpine
|
|
||||||
# vX.Y.Z-alpine
|
|
||||||
# latest
|
|
||||||
# latest-alpine
|
|
||||||
# stable
|
|
||||||
# stable-alpine
|
|
||||||
# YYYY-MM-DD
|
|
||||||
# YYYY-MM-DD-alpine
|
|
||||||
#################
|
|
||||||
# vX-debian
|
|
||||||
# vX.Y-debian
|
|
||||||
# vX.Y.Z-debian
|
|
||||||
# latest-debian
|
|
||||||
# stable-debian
|
|
||||||
# YYYY-MM-DD-debian
|
|
||||||
#################
|
|
||||||
# Check matrix for tag list definition
|
|
||||||
flavor: |
|
|
||||||
latest=false
|
|
||||||
suffix=-${{ matrix.container }}
|
|
||||||
tags: ${{ matrix.tags }}
|
|
||||||
|
|
||||||
# Docker login to nitnelave/lldap and lldap/lldap
|
|
||||||
- name: Login to Nitnelave/LLDAP Docker Hub
|
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
########################################
|
||||||
if: github.event_name != 'pull_request'
|
#### docker image :latest tag build ####
|
||||||
uses: docker/login-action@v3
|
########################################
|
||||||
with:
|
- name: Build and push latest alpine
|
||||||
registry: ghcr.io
|
if: github.event_name != 'release'
|
||||||
username: nitnelave
|
uses: docker/build-push-action@v4
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build ${{ matrix.container }}-rootless Docker Image
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
platforms: ${{ matrix.platforms }}
|
platforms: linux/amd64,linux/arm64
|
||||||
file: ./.github/workflows/Dockerfile.ci.${{ matrix.container }}-rootless
|
file: ./.github/workflows/Dockerfile.ci.alpine
|
||||||
tags: |
|
tags: nitnelave/lldap:latest, nitnelave/lldap:latest-alpine
|
||||||
${{ steps.meta-rootless.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta-rootless.outputs.labels }}
|
|
||||||
cache-from: type=gha,mode=max
|
cache-from: type=gha,mode=max
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
### This docker build always the last, due :latest tag pushed multiple times, for whatever variants may added in future add docker build above this
|
- name: Build and push latest debian
|
||||||
- name: Build ${{ matrix.container }} Docker Image
|
if: github.event_name != 'release'
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
platforms: ${{ matrix.platforms }}
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
file: ./.github/workflows/Dockerfile.ci.${{ matrix.container }}
|
file: ./.github/workflows/Dockerfile.ci.debian
|
||||||
tags: |
|
tags: nitnelave/lldap:latest-debian
|
||||||
${{ steps.meta-standard.outputs.tags }}
|
cache-from: type=gha,mode=max
|
||||||
labels: ${{ steps.meta-standard.outputs.labels }}
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
########################################
|
||||||
|
#### docker image :semver tag build ####
|
||||||
|
########################################
|
||||||
|
- name: Build and push release alpine
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
# Tag as latest, stable, semver, major, major.minor and major.minor.patch.
|
||||||
|
file: ./.github/workflows/Dockerfile.ci.alpine
|
||||||
|
tags: nitnelave/lldap:stable, nitnelave/lldap:stable-alpine, nitnelave/lldap:v${{ steps.slug.outputs.version-semantic }}, nitnelave/lldap:v${{ steps.slug.outputs.version-major }}, nitnelave/lldap:v${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}, nitnelave/lldap:v${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}.${{ steps.slug.outputs.version-patch }}, nitnelave/lldap:v${{ steps.slug.outputs.version-semantic }}-alpine, nitnelave/lldap:v${{ steps.slug.outputs.version-major }}-alpine, nitnelave/lldap:v${{ steps.slug.outputs.version-major }}-alpine.${{ steps.slug.outputs.version-minor }}-alpine, nitnelave/lldap:v${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}.${{ steps.slug.outputs.version-patch }}-alpine
|
||||||
|
cache-from: type=gha,mode=max
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Build and push release debian
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
push: true
|
||||||
|
# Tag as latest, stable, semver, major, major.minor and major.minor.patch.
|
||||||
|
file: ./.github/workflows/Dockerfile.ci.debian
|
||||||
|
tags: nitnelave/lldap:stable-debian, nitnelave/lldap:v${{ steps.slug.outputs.version-semantic }}-debian, nitnelave/lldap:v${{ steps.slug.outputs.version-major }}-debian, nitnelave/lldap:v${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}-debian, nitnelave/lldap:v${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}.${{ steps.slug.outputs.version-patch }}-debian
|
||||||
cache-from: type=gha,mode=max
|
cache-from: type=gha,mode=max
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
- name: Update repo description
|
- name: Update repo description
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: peter-evans/dockerhub-description@v4
|
uses: peter-evans/dockerhub-description@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
repository: nitnelave/lldap
|
repository: nitnelave/lldap
|
||||||
|
|
||||||
- name: Update lldap repo description
|
|
||||||
if: github.event_name != 'pull_request'
|
|
||||||
uses: peter-evans/dockerhub-description@v4
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
|
||||||
repository: lldap/lldap
|
|
||||||
|
|
||||||
###############################################################
|
###############################################################
|
||||||
### Download artifacts, clean up ui, upload to release page ###
|
### Download artifacts, clean up ui, upload to release page ###
|
||||||
###############################################################
|
###############################################################
|
||||||
@@ -681,7 +549,7 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- name: Download all artifacts
|
- name: Download all artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
path: bin/
|
path: bin/
|
||||||
- name: Check file
|
- name: Check file
|
||||||
@@ -690,19 +558,19 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mv bin/aarch64-unknown-linux-musl-lldap-bin/lldap bin/aarch64-lldap
|
mv bin/aarch64-unknown-linux-musl-lldap-bin/lldap bin/aarch64-lldap
|
||||||
mv bin/x86_64-unknown-linux-musl-lldap-bin/lldap bin/amd64-lldap
|
mv bin/x86_64-unknown-linux-musl-lldap-bin/lldap bin/amd64-lldap
|
||||||
mv bin/armv7-unknown-linux-musleabihf-lldap-bin/lldap bin/armhf-lldap
|
mv bin/armv7-unknown-linux-gnueabihf-lldap-bin/lldap bin/armhf-lldap
|
||||||
mv bin/aarch64-unknown-linux-musl-lldap_migration_tool-bin/lldap_migration_tool bin/aarch64-lldap_migration_tool
|
mv bin/aarch64-unknown-linux-musl-migration-tool-bin/migration-tool bin/aarch64-migration-tool
|
||||||
mv bin/x86_64-unknown-linux-musl-lldap_migration_tool-bin/lldap_migration_tool bin/amd64-lldap_migration_tool
|
mv bin/x86_64-unknown-linux-musl-migration-tool-bin/migration-tool bin/amd64-migration-tool
|
||||||
mv bin/armv7-unknown-linux-musleabihf-lldap_migration_tool-bin/lldap_migration_tool bin/armhf-lldap_migration_tool
|
mv bin/armv7-unknown-linux-gnueabihf-migration-tool-bin/migration-tool bin/armhf-migration-tool
|
||||||
mv bin/aarch64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password bin/aarch64-lldap_set_password
|
mv bin/aarch64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password bin/aarch64-lldap_set_password
|
||||||
mv bin/x86_64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password bin/amd64-lldap_set_password
|
mv bin/x86_64-unknown-linux-musl-lldap_set_password-bin/lldap_set_password bin/amd64-lldap_set_password
|
||||||
mv bin/armv7-unknown-linux-musleabihf-lldap_set_password-bin/lldap_set_password bin/armhf-lldap_set_password
|
mv bin/armv7-unknown-linux-gnueabihf-lldap_set_password-bin/lldap_set_password bin/armhf-lldap_set_password
|
||||||
chmod +x bin/*-lldap
|
chmod +x bin/*-lldap
|
||||||
chmod +x bin/*-lldap_migration_tool
|
chmod +x bin/*-migration-tool
|
||||||
chmod +x bin/*-lldap_set_password
|
chmod +x bin/*-lldap_set_password
|
||||||
|
|
||||||
- name: Download llap ui artifacts
|
- name: Download llap ui artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ui
|
name: ui
|
||||||
path: web
|
path: web
|
||||||
@@ -724,9 +592,9 @@ jobs:
|
|||||||
mv bin/aarch64-lldap aarch64-lldap/lldap
|
mv bin/aarch64-lldap aarch64-lldap/lldap
|
||||||
mv bin/amd64-lldap amd64-lldap/lldap
|
mv bin/amd64-lldap amd64-lldap/lldap
|
||||||
mv bin/armhf-lldap armhf-lldap/lldap
|
mv bin/armhf-lldap armhf-lldap/lldap
|
||||||
mv bin/aarch64-lldap_migration_tool aarch64-lldap/lldap_migration_tool
|
mv bin/aarch64-migration-tool aarch64-lldap/migration-tool
|
||||||
mv bin/amd64-lldap_migration_tool amd64-lldap/lldap_migration_tool
|
mv bin/amd64-migration-tool amd64-lldap/migration-tool
|
||||||
mv bin/armhf-lldap_migration_tool armhf-lldap/lldap_migration_tool
|
mv bin/armhf-migration-tool armhf-lldap/migration-tool
|
||||||
mv bin/aarch64-lldap_set_password aarch64-lldap/lldap_set_password
|
mv bin/aarch64-lldap_set_password aarch64-lldap/lldap_set_password
|
||||||
mv bin/amd64-lldap_set_password amd64-lldap/lldap_set_password
|
mv bin/amd64-lldap_set_password amd64-lldap/lldap_set_password
|
||||||
mv bin/armhf-lldap_set_password armhf-lldap/lldap_set_password
|
mv bin/armhf-lldap_set_password armhf-lldap/lldap_set_password
|
||||||
@@ -752,9 +620,5 @@ jobs:
|
|||||||
artifacts: aarch64-lldap.tar.gz,
|
artifacts: aarch64-lldap.tar.gz,
|
||||||
amd64-lldap.tar.gz,
|
amd64-lldap.tar.gz,
|
||||||
armhf-lldap.tar.gz
|
armhf-lldap.tar.gz
|
||||||
draft: true
|
|
||||||
omitBodyDuringUpdate: true
|
|
||||||
omitDraftDuringUpdate: true
|
|
||||||
omitNameDuringUpdate: true
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v5.0.0
|
uses: actions/checkout@v3.5.0
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --verbose --workspace
|
run: cargo build --verbose --workspace
|
||||||
@@ -52,7 +52,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v5.0.0
|
uses: actions/checkout@v3.5.0
|
||||||
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v5.0.0
|
uses: actions/checkout@v3.5.0
|
||||||
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
@@ -81,14 +81,12 @@ jobs:
|
|||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
name: Code coverage
|
name: Code coverage
|
||||||
needs:
|
needs: pre_job
|
||||||
- pre_job
|
|
||||||
- test
|
|
||||||
if: ${{ needs.pre_job.outputs.should_skip != 'true' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
|
if: ${{ needs.pre_job.outputs.should_skip != 'true' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v5.0.0
|
uses: actions/checkout@v3.5.0
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
run: rustup toolchain install nightly --component llvm-tools-preview && rustup component add llvm-tools-preview --toolchain stable-x86_64-unknown-linux-gnu
|
run: rustup toolchain install nightly --component llvm-tools-preview && rustup component add llvm-tools-preview --toolchain stable-x86_64-unknown-linux-gnu
|
||||||
@@ -101,10 +99,9 @@ jobs:
|
|||||||
run: cargo llvm-cov --workspace --no-report
|
run: cargo llvm-cov --workspace --no-report
|
||||||
- name: Aggregate reports
|
- name: Aggregate reports
|
||||||
run: cargo llvm-cov --no-run --lcov --output-path lcov.info
|
run: cargo llvm-cov --no-run --lcov --output-path lcov.info
|
||||||
- name: Upload coverage to Codecov (main)
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@v4
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
files: lcov.info
|
files: lcov.info
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: true
|
||||||
codecov_yml_path: .github/codecov.yml
|
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|||||||
-248
@@ -5,254 +5,6 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [0.6.2] 2025-07-21
|
|
||||||
|
|
||||||
Small release, focused on LDAP improvements and ongoing maintenance.
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- LDAP
|
|
||||||
- Support for searching groups by their `groupid`
|
|
||||||
- Support for `whoamiOID`
|
|
||||||
- Support for creating groups
|
|
||||||
- Support for subschema entry
|
|
||||||
- Custom assets path.
|
|
||||||
- New endpoint for requesting client settings
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- A missing JWT secret now prevents startup.
|
|
||||||
- Attributes with invalid characters (such as underscores) cannot be created anymore.
|
|
||||||
- Searching custom (string) attributes is now case insensitive.
|
|
||||||
- Using the top-level `firstName`, `lastName` and `avatar` GraphQL fields for users is now deprecated. Use the `attributes` field instead.
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- `lldap_set_password` now uses the system's SSL certificates.
|
|
||||||
|
|
||||||
### Cleanups
|
|
||||||
|
|
||||||
- Split the main `lldap` crate into many sub-crates
|
|
||||||
- Various dependency version bumps
|
|
||||||
- Upgraded to 2024 Rust edition
|
|
||||||
- Docs/FAQ improvements
|
|
||||||
|
|
||||||
### Bootstrap script
|
|
||||||
|
|
||||||
- Custom attributes support
|
|
||||||
- Read the paswsord from a file
|
|
||||||
- Resilient to no user or group files
|
|
||||||
|
|
||||||
### New services
|
|
||||||
|
|
||||||
- Discord integration (Discord role to LLDAP user)
|
|
||||||
- HashiCorp
|
|
||||||
- Jellyfin 2FA with Duo
|
|
||||||
- Kimai
|
|
||||||
- Mailcow
|
|
||||||
- Peertube
|
|
||||||
- Penpot
|
|
||||||
- PgAdmin
|
|
||||||
- Project Quay
|
|
||||||
- Quadlet
|
|
||||||
- Snipe-IT
|
|
||||||
- SSSD
|
|
||||||
- Stalwart
|
|
||||||
- UnifiOS
|
|
||||||
|
|
||||||
## [0.6.1] 2024-11-22
|
|
||||||
|
|
||||||
Small release, mainly to fix a migration issue with Sqlite and Postgresql.
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Added a link to a community terraform provider (#1035)
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- The opaque dependency now points to the official crate rather than a fork (#1040)
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Migration of the DB schema from 7 to 8 is now automatic for sqlite, and fixed for postgres (#1045)
|
|
||||||
- The startup warning about `key_seed` applying instead of `key_file` now has instructions on how to silence it (#1032)
|
|
||||||
|
|
||||||
### New services
|
|
||||||
|
|
||||||
- OneDev
|
|
||||||
|
|
||||||
## [0.6.0] 2024-11-09
|
|
||||||
|
|
||||||
### Breaking
|
|
||||||
|
|
||||||
- The endpoint `/auth/reset/step1` is now `POST` instead of `GET` (#704)
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Custom attributes are now supported (#67) ! You can add new fields (string, integers, JPEG or dates) to users and query them. That unlocks many integrations with other services, and allows for a deeper/more customized integration. Special thanks to @pixelrazor and @bojidar-bg for their help with the UI.
|
|
||||||
- Custom object classes (for all users/groups) can now be added (#833)
|
|
||||||
- Barebones support for Paged Results Control (no paging, no respect for windows, but a correct response with all the results) (#698)
|
|
||||||
- A daily docker image is tagged and released. (#613)
|
|
||||||
- A bootstrap script allows reading the list of users/groups from a file and making sure the server contains exactly the same thing. (#654)
|
|
||||||
- Make it possible to serve lldap behind a sub-path in (#752)
|
|
||||||
- LLDAP can now be found on a custom package repository for opensuse, fedora, ubuntu, debian and centos ([Repository link](https://software.opensuse.org//download.html?project=home%3AMasgalor%3ALLDAP&package=lldap)). Thanks @Masgalor for setting it up and maintaining it.
|
|
||||||
- There's now an option to force reset the admin password (#748) optionally on every restart (#959)
|
|
||||||
- There's a rootless docker container (#755)
|
|
||||||
- entryDN is now supported (#780)
|
|
||||||
- Unknown LDAP controls are now detected and ignored (#787, #799)
|
|
||||||
- A community-developed CLI for scripting (#793)
|
|
||||||
- Added a way to print raw logs to debug long-running sessions (#992)
|
|
||||||
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- The official docker repository is now `lldap/lldap`
|
|
||||||
- Removed password length limitation in lldap_set_password tool
|
|
||||||
- Group names and emails are now case insensitive, but keep their casing (#666)
|
|
||||||
- Better error messages (and exit code (#745)) when changing the private key (#778, #1008), using the wrong SMTP port (#970), using the wrong env variables (#972)
|
|
||||||
- Allow `member=` filters with plain user names (not full DNs) (#949)
|
|
||||||
- Correctly detect and refuse anonymous binds (#974)
|
|
||||||
- Clearer logging (#971, #981, #982)
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Logging out applies globally, not just in the local browser. (#721)
|
|
||||||
- It's no longer possible to create the same user twice (#745)
|
|
||||||
- Fix wide substring filters (#738)
|
|
||||||
- Don't log the database password if provided in the connection URL (#735)
|
|
||||||
- Fix a panic when postgres uses a different collation (#821)
|
|
||||||
- The UI now defaults to the user ID for users with no display names (#843)
|
|
||||||
- Fix searching for users with more than one `memberOf` filter (#872)
|
|
||||||
- Fix compilation on Windows (#932) and Illumos (#964)
|
|
||||||
- The UI now correctly detects whether password resets are enabled. (#753)
|
|
||||||
- Fix a missing lowercasing of username when changing passwords through LDAP (#1012)
|
|
||||||
- Fix SQLite writers erroring when racing (#1021)
|
|
||||||
- LDAP sessions no longer buffer their logs until unbind, causing memory leaks (#1025)
|
|
||||||
|
|
||||||
### Performance
|
|
||||||
|
|
||||||
- Only expand attributes once per query, not per result (#687)
|
|
||||||
|
|
||||||
### Security
|
|
||||||
|
|
||||||
- When asked to send a password reset to an unknown email, sleep for 3 seconds and don't print the email in the error (#887)
|
|
||||||
|
|
||||||
### New services
|
|
||||||
|
|
||||||
Linux user accounts can now be managed by LLDAP, using PAM and nslcd.
|
|
||||||
|
|
||||||
- Apereo CAS server
|
|
||||||
- Carpal
|
|
||||||
- Gitlab
|
|
||||||
- Grocy
|
|
||||||
- Harbor
|
|
||||||
- Home Assistant
|
|
||||||
- Jenkins
|
|
||||||
- Kasm
|
|
||||||
- Maddy
|
|
||||||
- Mastodon
|
|
||||||
- Metabase
|
|
||||||
- MegaRAC-BMC
|
|
||||||
- Netbox
|
|
||||||
- OCIS
|
|
||||||
- Prosody
|
|
||||||
- Radicale
|
|
||||||
- SonarQube
|
|
||||||
- Traccar
|
|
||||||
- Zitadel
|
|
||||||
|
|
||||||
## [0.5.0] 2023-09-14
|
|
||||||
|
|
||||||
### Breaking
|
|
||||||
|
|
||||||
- Emails and UUIDs are now enforced to be unique.
|
|
||||||
- If you have several users with the same email, you'll have to disambiguate
|
|
||||||
them. You can do that by either issuing SQL commands directly
|
|
||||||
(`UPDATE users SET email = 'x@x' WHERE user_id = 'bob';`), or by reverting
|
|
||||||
to a 0.4.x version of LLDAP and editing the user through the web UI.
|
|
||||||
An error will prevent LLDAP 0.5+ from starting otherwise.
|
|
||||||
- This was done to prevent account takeover for systems that allow to
|
|
||||||
login via email.
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- The server private key can be set as a seed from an env variable (#504).
|
|
||||||
- This is especially useful when you have multiple containers, they don't
|
|
||||||
need to share a writeable folder.
|
|
||||||
- Added support for changing the password through a plain LDAP Modify
|
|
||||||
operation (as opposed to an extended operation), to allow Jellyfin
|
|
||||||
to change password (#620).
|
|
||||||
- Allow creating a user with multiple objectClass (#612).
|
|
||||||
- Emails now have a message ID (#608).
|
|
||||||
- Added a warning for browsers that have WASM/JS disabled (#639).
|
|
||||||
- Added support for querying OUs in LDAP (#669).
|
|
||||||
- Added a button to clear the avatar in the UI (#358).
|
|
||||||
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- Groups are now sorted by name in the web UI (#623).
|
|
||||||
- ARM build now uses musl (#584).
|
|
||||||
- Improved logging.
|
|
||||||
- Default admin user is only created if there are no admins (#563).
|
|
||||||
- That allows you to remove the default admin, making it harder to
|
|
||||||
bruteforce.
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Fixed URL parsing with a trailing slash in the password setting utility
|
|
||||||
(#597).
|
|
||||||
|
|
||||||
In addition to all that, there was significant progress towards #67,
|
|
||||||
user-defined attributes. That complex feature will unblock integration with many
|
|
||||||
systems, including PAM authentication.
|
|
||||||
|
|
||||||
### New services
|
|
||||||
|
|
||||||
- Ejabberd
|
|
||||||
- Ergo
|
|
||||||
- LibreNMS
|
|
||||||
- Mealie
|
|
||||||
- MinIO
|
|
||||||
- OpnSense
|
|
||||||
- PfSense
|
|
||||||
- PowerDnsAdmin
|
|
||||||
- Proxmox
|
|
||||||
- Squid
|
|
||||||
- Tandoor recipes
|
|
||||||
- TheLounge
|
|
||||||
- Zabbix-web
|
|
||||||
- Zulip
|
|
||||||
|
|
||||||
## [0.4.3] 2023-04-11
|
|
||||||
|
|
||||||
The repository has changed from `nitnelave/lldap` to `lldap/lldap`, both on GitHub
|
|
||||||
and on DockerHub (although we will keep publishing the images to
|
|
||||||
`nitnelave/lldap` for the foreseeable future). All data on GitHub has been
|
|
||||||
migrated, and the new docker images are available both on DockerHub and on the
|
|
||||||
GHCR under `lldap/lldap`.
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- EC private keys are not supported for LDAPS.
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- SMTP user no longer has a default value (and instead defaults to unauthenticated).
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- WASM payload is now delivered uncompressed to Safari due to a Safari bug.
|
|
||||||
- Password reset no longer redirects to login page.
|
|
||||||
- NextCloud config should add the "mail" attribute.
|
|
||||||
- GraphQL parameters are now urldecoded, to support special characters in usernames.
|
|
||||||
- Healthcheck correctly checks the server certificate.
|
|
||||||
|
|
||||||
### New services
|
|
||||||
|
|
||||||
- Home Assistant
|
|
||||||
- Shaarli
|
|
||||||
|
|
||||||
## [0.4.2] - 2023-03-27
|
## [0.4.2] - 2023-03-27
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
# How to contribute to LLDAP
|
|
||||||
|
|
||||||
## Did you find a bug?
|
|
||||||
|
|
||||||
- Make sure there isn't already an [issue](https://github.com/lldap/lldap/issues?q=is%3Aissue+is%3Aopen) for it.
|
|
||||||
- Check if the bug still happens with the `latest` docker image, or the `main` branch if you compile it yourself.
|
|
||||||
- [Create an issue](https://github.com/lldap/lldap/issues/new) on GitHub. What makes a great issue:
|
|
||||||
- A quick summary of the bug.
|
|
||||||
- Steps to reproduce.
|
|
||||||
- LLDAP _verbose_ logs when reproducing the bug. Verbose mode can be set through environment variables (`LLDAP_VERBOSE=true`) or in the config (`verbose = true`).
|
|
||||||
- What you expected to happen.
|
|
||||||
- What actually happened.
|
|
||||||
- Other notes (what you tried, why you think it's happening, ...).
|
|
||||||
|
|
||||||
## Are you requesting integration with a new service?
|
|
||||||
|
|
||||||
- Check if there is already an [example config](https://github.com/lldap/lldap/tree/main/example_configs) for it.
|
|
||||||
- Try to figure out the configuration values for the new service yourself.
|
|
||||||
- You can use other example configs for inspiration.
|
|
||||||
- If you're having trouble, you can ask on [Discord](https://discord.gg/h5PEdRMNyP)
|
|
||||||
- If you succeed, make sure to contribute an example configuration, or a configuration guide.
|
|
||||||
- If you hit a block because of an unimplemented feature, go to the next section.
|
|
||||||
|
|
||||||
## Are you asking for a new feature?
|
|
||||||
|
|
||||||
- Make sure there isn't already an [issue](https://github.com/lldap/lldap/issues?q=is%3Aissue+is%3Aopen) for it.
|
|
||||||
- [Create an issue](https://github.com/lldap/lldap/issues/new) on GitHub. What makes a great feature request:
|
|
||||||
- A quick summary of the feature.
|
|
||||||
- Motivation: what problem does the feature solve?
|
|
||||||
- Workarounds: what are the currently possible solutions to the problem, however bad?
|
|
||||||
|
|
||||||
## Do you want to work on a PR?
|
|
||||||
|
|
||||||
That's great! There are 2 main ways to contribute to the project: documentation and code.
|
|
||||||
|
|
||||||
### Documentation
|
|
||||||
|
|
||||||
The simplest way to contribute is to submit a configuration guide for a new
|
|
||||||
service: it can be an example configuration file, or a markdown guide
|
|
||||||
explaining the steps necessary to configure the service.
|
|
||||||
|
|
||||||
We also have some
|
|
||||||
[documentation](https://github.com/lldap/lldap/tree/main/docs) with more
|
|
||||||
advanced guides (scripting, migrations, ...) you can contribute to.
|
|
||||||
|
|
||||||
### Code
|
|
||||||
|
|
||||||
If you don't know what to start with, check out the
|
|
||||||
[good first issues](https://github.com/lldap/lldap/labels/good%20first%20issue).
|
|
||||||
|
|
||||||
Otherwise, if you want to fix a specific bug or implement a feature, make sure
|
|
||||||
to start by creating an issue for it (if it doesn't already exist). There, we
|
|
||||||
can discuss whether it would be likely to be accepted and consider design
|
|
||||||
issues. That will save you from going down a wrong path, creating an entire PR
|
|
||||||
before getting told that it doesn't align with the project or the design is
|
|
||||||
flawed!
|
|
||||||
|
|
||||||
Once we agree on what to do in the issue, you can start working on the PR. A good quality PR has:
|
|
||||||
- A description of the change.
|
|
||||||
- The format we use for both commit titles and PRs is:
|
|
||||||
`tag: Do the thing`
|
|
||||||
The tag can be: server, app, docker, example_configs, ... It's a broad category.
|
|
||||||
The rest of the title should be an imperative sentence (see for instance [Commit Message
|
|
||||||
Guidelines](https://gist.github.com/robertpainsi/b632364184e70900af4ab688decf6f53)).
|
|
||||||
- The PR should refer to the issue it's addressing (e.g. "Fix #123").
|
|
||||||
- Explain the _why_ of the change.
|
|
||||||
- But also the _how_.
|
|
||||||
- Highlight any potential flaw or limitation.
|
|
||||||
- The code change should be as small as possible while solving the problem.
|
|
||||||
- Don't try to code-golf to change fewer characters, but keep logically separate changes in
|
|
||||||
different PRs.
|
|
||||||
- Add tests if possible.
|
|
||||||
- The tests should highlight the original issue in case of a bug.
|
|
||||||
- Ideally, we can apply the tests without the rest of the change and they would fail. With the
|
|
||||||
change, they pass.
|
|
||||||
- In some areas, there is no test infrastructure in place (e.g. for frontend changes). In that
|
|
||||||
case, do some manual testing and include the results (logs for backend changes, screenshot of a
|
|
||||||
successful service integration, screenshot of the frontend change).
|
|
||||||
- For backend changes, the tests should cover a significant portion of the new code paths, or
|
|
||||||
everything if possible. You can also add more tests to cover existing code.
|
|
||||||
- Of course, make sure all the existing tests pass. This will be checked anyway in the GitHub CI.
|
|
||||||
|
|
||||||
### Workflow
|
|
||||||
|
|
||||||
We use [GitHub Flow](https://docs.github.com/en/get-started/quickstart/github-flow):
|
|
||||||
- Fork the repository.
|
|
||||||
- (Optional) Create a new branch, or just use `main` in your fork.
|
|
||||||
- Make your change.
|
|
||||||
- Create a PR.
|
|
||||||
- Address the comments by adding more commits to your branch (or to `main`).
|
|
||||||
- The PR gets merged (the commits get squashed to a single one).
|
|
||||||
- (Optional) You can delete your branch/fork.
|
|
||||||
|
|
||||||
## Reminder
|
|
||||||
|
|
||||||
We're all volunteers, so be kind to each other! And since we're doing that in our free time, some
|
|
||||||
things can take a longer than expected.
|
|
||||||
Generated
+1281
-2178
File diff suppressed because it is too large
Load Diff
+10
-21
@@ -1,21 +1,13 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"server",
|
"server",
|
||||||
"app",
|
"auth",
|
||||||
"migration-tool",
|
"app",
|
||||||
"set-password",
|
"migration-tool",
|
||||||
"crates/*",
|
"set-password",
|
||||||
]
|
]
|
||||||
default-members = ["server"]
|
|
||||||
resolver = "2"
|
|
||||||
|
|
||||||
[workspace.package]
|
default-members = ["server"]
|
||||||
authors = ["Valentin Tolmer <valentin@tolmer.fr>"]
|
|
||||||
documentation = "https://github.com/lldap/lldap"
|
|
||||||
edition = "2024"
|
|
||||||
homepage = "https://github.com/lldap/lldap"
|
|
||||||
license = "GPL-3.0-only"
|
|
||||||
repository = "https://github.com/lldap/lldap"
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
@@ -23,12 +15,9 @@ lto = true
|
|||||||
[profile.release.package.lldap_app]
|
[profile.release.package.lldap_app]
|
||||||
opt-level = 's'
|
opt-level = 's'
|
||||||
|
|
||||||
|
[patch.crates-io.opaque-ke]
|
||||||
|
git = 'https://github.com/nitnelave/opaque-ke/'
|
||||||
|
branch = 'zeroize_1.5'
|
||||||
|
|
||||||
[patch.crates-io.lber]
|
[patch.crates-io.lber]
|
||||||
git = 'https://github.com/inejge/ldap3/'
|
git = 'https://github.com/inejge/ldap3/'
|
||||||
|
|
||||||
[workspace.dependencies.sea-orm]
|
|
||||||
version = "1.1.8"
|
|
||||||
default-features = false
|
|
||||||
|
|
||||||
[workspace.dependencies.serde]
|
|
||||||
version = "1"
|
|
||||||
|
|||||||
+6
-7
@@ -1,5 +1,5 @@
|
|||||||
# Build image
|
# Build image
|
||||||
FROM rust:alpine3.21 AS chef
|
FROM rust:alpine3.16 AS chef
|
||||||
|
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
# Add user
|
# Add user
|
||||||
@@ -31,19 +31,19 @@ FROM chef AS builder
|
|||||||
COPY --from=planner /tmp/recipe.json recipe.json
|
COPY --from=planner /tmp/recipe.json recipe.json
|
||||||
RUN cargo chef cook --release -p lldap_app --target wasm32-unknown-unknown \
|
RUN cargo chef cook --release -p lldap_app --target wasm32-unknown-unknown \
|
||||||
&& cargo chef cook --release -p lldap \
|
&& cargo chef cook --release -p lldap \
|
||||||
&& cargo chef cook --release -p lldap_migration_tool \
|
&& cargo chef cook --release -p migration-tool \
|
||||||
&& cargo chef cook --release -p lldap_set_password
|
&& cargo chef cook --release -p lldap_set_password
|
||||||
|
|
||||||
# Copy the source and build the app and server.
|
# Copy the source and build the app and server.
|
||||||
COPY --chown=app:app . .
|
COPY --chown=app:app . .
|
||||||
RUN cargo build --release -p lldap -p lldap_migration_tool -p lldap_set_password \
|
RUN cargo build --release -p lldap -p migration-tool -p lldap_set_password \
|
||||||
# Build the frontend.
|
# Build the frontend.
|
||||||
&& ./app/build.sh
|
&& ./app/build.sh
|
||||||
|
|
||||||
# Final image
|
# Final image
|
||||||
FROM alpine:3.21
|
FROM alpine:3.16
|
||||||
|
|
||||||
ENV GOSU_VERSION=1.14
|
ENV GOSU_VERSION 1.14
|
||||||
# Fetch gosu from git
|
# Fetch gosu from git
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
\
|
\
|
||||||
@@ -78,9 +78,8 @@ WORKDIR /app
|
|||||||
COPY --from=builder /app/app/index_local.html app/index.html
|
COPY --from=builder /app/app/index_local.html app/index.html
|
||||||
COPY --from=builder /app/app/static app/static
|
COPY --from=builder /app/app/static app/static
|
||||||
COPY --from=builder /app/app/pkg app/pkg
|
COPY --from=builder /app/app/pkg app/pkg
|
||||||
COPY --from=builder /app/target/release/lldap /app/target/release/lldap_migration_tool /app/target/release/lldap_set_password ./
|
COPY --from=builder /app/target/release/lldap /app/target/release/migration-tool /app/target/release/lldap_set_password ./
|
||||||
COPY docker-entrypoint.sh lldap_config.docker_template.toml ./
|
COPY docker-entrypoint.sh lldap_config.docker_template.toml ./
|
||||||
COPY scripts/bootstrap.sh ./
|
|
||||||
|
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& apk add --no-cache bash tzdata \
|
&& apk add --no-cache bash tzdata \
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
build-dev-container:
|
|
||||||
docker buildx build --tag lldap/rust-dev --file .github/workflows/Dockerfile.dev --push .github/workflows
|
|
||||||
|
|
||||||
prepare-release:
|
|
||||||
./prepare-release.sh
|
|
||||||
@@ -5,15 +5,14 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/lldap/lldap/actions/workflows/rust.yml?query=branch%3Amain">
|
<a href="https://github.com/nitnelave/lldap/actions/workflows/rust.yml?query=branch%3Amain">
|
||||||
<img
|
<img
|
||||||
src="https://github.com/lldap/lldap/actions/workflows/rust.yml/badge.svg"
|
src="https://github.com/nitnelave/lldap/actions/workflows/rust.yml/badge.svg"
|
||||||
alt="Build"/>
|
alt="Build"/>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://discord.gg/h5PEdRMNyP">
|
<a href="https://discord.gg/h5PEdRMNyP">
|
||||||
<img alt="Discord" src="https://img.shields.io/discord/898492935446876200?label=discord&logo=discord" />
|
<img alt="Discord" src="https://img.shields.io/discord/898492935446876200?label=discord&logo=discord" />
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="https://twitter.com/nitnelave1?ref_src=twsrc%5Etfw">
|
<a href="https://twitter.com/nitnelave1?ref_src=twsrc%5Etfw">
|
||||||
<img
|
<img
|
||||||
src="https://img.shields.io/twitter/follow/nitnelave1?style=social"
|
src="https://img.shields.io/twitter/follow/nitnelave1?style=social"
|
||||||
@@ -24,24 +23,24 @@
|
|||||||
src="https://img.shields.io/badge/unsafe-forbidden-success.svg"
|
src="https://img.shields.io/badge/unsafe-forbidden-success.svg"
|
||||||
alt="Unsafe forbidden"/>
|
alt="Unsafe forbidden"/>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://app.codecov.io/gh/lldap/lldap">
|
<a href="https://app.codecov.io/gh/nitnelave/lldap">
|
||||||
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/lldap/lldap" />
|
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/nitnelave/lldap" />
|
||||||
</a>
|
|
||||||
<br/>
|
|
||||||
<a href="https://www.buymeacoffee.com/nitnelave" target="_blank">
|
|
||||||
<img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" >
|
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
- [About](#about)
|
- [About](#about)
|
||||||
- [Installation](docs/install.md)
|
- [Installation](#installation)
|
||||||
- [Usage](#usage)
|
- [With Docker](#with-docker)
|
||||||
- [Recommended architecture](#recommended-architecture)
|
- [From source](#from-source)
|
||||||
|
- [Cross-compilation](#cross-compilation)
|
||||||
- [Client configuration](#client-configuration)
|
- [Client configuration](#client-configuration)
|
||||||
- [Known compatible services](#known-compatible-services)
|
- [Compatible services](#compatible-services)
|
||||||
- [General configuration guide](#general-configuration-guide)
|
- [General configuration guide](#general-configuration-guide)
|
||||||
- [Incompatible services](#incompatible-services)
|
- [Sample client configurations](#sample-client-configurations)
|
||||||
- [Frequently Asked Questions](#frequently-asked-questions)
|
- [Comparisons with other services](#comparisons-with-other-services)
|
||||||
|
- [vs OpenLDAP](#vs-openldap)
|
||||||
|
- [vs FreeIPA](#vs-freeipa)
|
||||||
|
- [I can't log in!](#i-cant-log-in)
|
||||||
- [Contributions](#contributions)
|
- [Contributions](#contributions)
|
||||||
|
|
||||||
## About
|
## About
|
||||||
@@ -52,7 +51,7 @@ many backends, from KeyCloak to Authelia to Nextcloud and
|
|||||||
[more](#compatible-services)!
|
[more](#compatible-services)!
|
||||||
|
|
||||||
<img
|
<img
|
||||||
src="https://raw.githubusercontent.com/lldap/lldap/master/screenshot.png"
|
src="https://raw.githubusercontent.com/nitnelave/lldap/master/screenshot.png"
|
||||||
alt="Screenshot of the user list page"
|
alt="Screenshot of the user list page"
|
||||||
width="50%"
|
width="50%"
|
||||||
align="right"
|
align="right"
|
||||||
@@ -83,60 +82,137 @@ MySQL/MariaDB or PostgreSQL.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
It's possible to install lldap from OCI images ([docker](docs/install.md#with-docker)/[podman](docs/install.md#with-podman)), from [Kubernetes](docs/install.md#with-kubernetes), or from [a regular distribution package manager](docs/install.md/#from-a-package-repository) (Archlinux, Debian, CentOS, Fedora, OpenSuse, Ubuntu, FreeBSD).
|
### With Docker
|
||||||
|
|
||||||
Building [from source](docs/install.md#from-source) and [cross-compiling](docs/install.md#cross-compilation) to a different hardware architecture is also supported.
|
The image is available at `nitnelave/lldap`. You should persist the `/data`
|
||||||
|
folder, which contains your configuration, the database and the private key
|
||||||
|
file.
|
||||||
|
|
||||||
## Usage
|
Configure the server by copying the `lldap_config.docker_template.toml` to
|
||||||
|
`/data/lldap_config.toml` and updating the configuration values (especially the
|
||||||
|
`jwt_secret` and `ldap_user_pass`, unless you override them with env variables).
|
||||||
|
Environment variables should be prefixed with `LLDAP_` to override the
|
||||||
|
configuration.
|
||||||
|
|
||||||
The simplest way to use LLDAP is through the web front-end. There you can
|
If the `lldap_config.toml` doesn't exist when starting up, LLDAP will use default one. The default admin password is `password`, you can change the password later using the web interface.
|
||||||
create users, set passwords, add them to groups and so on. Users can also
|
|
||||||
connect to the web UI and change their information, or request a password reset
|
|
||||||
link (if you configured the SMTP client).
|
|
||||||
|
|
||||||
You can create and manage custom attributes through the Web UI, or through the
|
Secrets can also be set through a file. The filename should be specified by the
|
||||||
community-contributed CLI frontend (
|
variables `LLDAP_JWT_SECRET_FILE` or `LLDAP_LDAP_USER_PASS_FILE`, and the file
|
||||||
[Zepmann/lldap-cli](https://github.com/Zepmann/lldap-cli)). This is necessary
|
contents are loaded into the respective configuration parameters. Note that
|
||||||
for some service integrations.
|
`_FILE` variables take precedence.
|
||||||
|
|
||||||
The [bootstrap.sh](scripts/bootstrap.sh) script can enforce a list of
|
Example for docker compose:
|
||||||
users/groups/attributes from a given file, reflecting it on the server.
|
|
||||||
|
|
||||||
To manage the user, group and membership lifecycle in an infrastructure-as-code
|
- You can use either the `:latest` tag image or `:stable` as used in this example.
|
||||||
scenario you can use the unofficial [LLDAP terraform provider in the terraform registry](https://registry.terraform.io/providers/tasansga/lldap/latest).
|
- `:latest` tag image contains recently pushed code or feature tests, in which some instability can be expected.
|
||||||
|
- If `UID` and `GID` no defined LLDAP will use default `UID` and `GID` number `1000`.
|
||||||
|
- If no `TZ` is set, default `UTC` timezone will be used.
|
||||||
|
|
||||||
LLDAP is also very scriptable, through its GraphQL API. See the
|
```yaml
|
||||||
[Scripting](docs/scripting.md) docs for more info.
|
version: "3"
|
||||||
|
|
||||||
### Recommended architecture
|
volumes:
|
||||||
|
lldap_data:
|
||||||
|
driver: local
|
||||||
|
|
||||||
If you are using containers, a sample architecture could look like this:
|
services:
|
||||||
|
lldap:
|
||||||
|
image: nitnelave/lldap:stable
|
||||||
|
ports:
|
||||||
|
# For LDAP
|
||||||
|
- "3890:3890"
|
||||||
|
# For the web front-end
|
||||||
|
- "17170:17170"
|
||||||
|
volumes:
|
||||||
|
- "lldap_data:/data"
|
||||||
|
# Alternatively, you can mount a local folder
|
||||||
|
# - "./lldap_data:/data"
|
||||||
|
environment:
|
||||||
|
- UID=####
|
||||||
|
- GID=####
|
||||||
|
- TZ=####/####
|
||||||
|
- LLDAP_JWT_SECRET=REPLACE_WITH_RANDOM
|
||||||
|
- LLDAP_LDAP_USER_PASS=REPLACE_WITH_PASSWORD
|
||||||
|
- LLDAP_LDAP_BASE_DN=dc=example,dc=com
|
||||||
|
# You can also set a different database:
|
||||||
|
# - LLDAP_DATABASE_URL=mysql://mysql-user:password@mysql-server/my-database
|
||||||
|
# - LLDAP_DATABASE_URL=postgres://postgres-user:password@postgres-server/my-database
|
||||||
|
```
|
||||||
|
|
||||||
- A reverse proxy (e.g. nginx or Traefik)
|
Then the service will listen on two ports, one for LDAP and one for the web
|
||||||
- An authentication service (e.g. Authelia, Authentik or KeyCloak) connected to
|
front-end.
|
||||||
LLDAP to provide authentication for non-authenticated services, or to provide
|
|
||||||
SSO with compatible ones.
|
### With Kubernetes
|
||||||
- The LLDAP service, with the web port exposed to Traefik.
|
|
||||||
- The LDAP port doesn't need to be exposed, since only the other containers
|
See https://github.com/Evantage-WS/lldap-kubernetes for a LLDAP deployment for Kubernetes
|
||||||
will access it.
|
|
||||||
- You can also set up LDAPS if you want to expose the LDAP port to the
|
### From source
|
||||||
internet (not recommended) or for an extra layer of security in the
|
|
||||||
inter-container communication (though it's very much optional).
|
#### Backend
|
||||||
- The default LLDAP container starts up as root to fix up some files'
|
|
||||||
permissions before downgrading the privilege to the given user. However,
|
To compile the project, you'll need:
|
||||||
you can (should?) use the `*-rootless` version of the images to be able to
|
|
||||||
start directly as that user, once you got the permissions right. Just don't
|
- curl and gzip: `sudo apt install curl gzip`
|
||||||
forget to change from the `UID/GID` env vars to the `uid` docker-compose
|
- Rust/Cargo: [rustup.rs](https://rustup.rs/)
|
||||||
field.
|
|
||||||
- Any other service that needs to connect to LLDAP for authentication (e.g.
|
Then you can compile the server (and the migration tool if you want):
|
||||||
NextCloud) can be added to a shared network with LLDAP. The finest
|
|
||||||
granularity is a network for each pair of LLDAP-service, but there are often
|
```shell
|
||||||
coarser granularities that make sense (e.g. a network for the \*arr stack and
|
cargo build --release -p lldap -p migration-tool
|
||||||
LLDAP).
|
```
|
||||||
|
|
||||||
|
The resulting binaries will be in `./target/release/`. Alternatively, you can
|
||||||
|
just run `cargo run -- run` to run the server.
|
||||||
|
|
||||||
|
#### Frontend
|
||||||
|
|
||||||
|
To bring up the server, you'll need to compile the frontend. In addition to
|
||||||
|
`cargo`, you'll need:
|
||||||
|
|
||||||
|
- WASM-pack: `cargo install wasm-pack`
|
||||||
|
|
||||||
|
Then you can build the frontend files with
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./app/build.sh
|
||||||
|
````
|
||||||
|
|
||||||
|
(you'll need to run this after every front-end change to update the WASM
|
||||||
|
package served).
|
||||||
|
|
||||||
|
The default config is in `src/infra/configuration.rs`, but you can override it
|
||||||
|
by creating an `lldap_config.toml`, setting environment variables or passing
|
||||||
|
arguments to `cargo run`. Have a look at the docker template:
|
||||||
|
`lldap_config.docker_template.toml`.
|
||||||
|
|
||||||
|
You can also install it as a systemd service, see
|
||||||
|
[lldap.service](example_configs/lldap.service).
|
||||||
|
|
||||||
|
### Cross-compilation
|
||||||
|
|
||||||
|
Docker images are provided for AMD64, ARM64 and ARM/V7.
|
||||||
|
|
||||||
|
If you want to cross-compile yourself, you can do so by installing
|
||||||
|
[`cross`](https://github.com/rust-embedded/cross):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo install cross
|
||||||
|
cross build --target=armv7-unknown-linux-musleabihf -p lldap --release
|
||||||
|
./app/build.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
(Replace `armv7-unknown-linux-musleabihf` with the correct Rust target for your
|
||||||
|
device.)
|
||||||
|
|
||||||
|
You can then get the compiled server binary in
|
||||||
|
`target/armv7-unknown-linux-musleabihf/release/lldap` and the various needed files
|
||||||
|
(`index.html`, `main.js`, `pkg` folder) in the `app` folder. Copy them to the
|
||||||
|
Raspberry Pi (or other target), with the folder structure maintained (`app`
|
||||||
|
files in an `app` folder next to the binary).
|
||||||
|
|
||||||
## Client configuration
|
## Client configuration
|
||||||
|
|
||||||
### Known compatible services
|
### Compatible services
|
||||||
|
|
||||||
Most services that can use LDAP as an authentication provider should work out
|
Most services that can use LDAP as an authentication provider should work out
|
||||||
of the box. For new services, it's possible that they require a bit of tweaking
|
of the box. For new services, it's possible that they require a bit of tweaking
|
||||||
@@ -144,13 +220,6 @@ on LLDAP's side to make things work. In that case, just create an issue with
|
|||||||
the relevant details (logs of the service, LLDAP logs with `verbose=true` in
|
the relevant details (logs of the service, LLDAP logs with `verbose=true` in
|
||||||
the config).
|
the config).
|
||||||
|
|
||||||
Some specific clients have been tested to work and come with sample
|
|
||||||
configuration files, or guides. See the [`example_configs`](example_configs)
|
|
||||||
folder for example configs for integration with specific services.
|
|
||||||
|
|
||||||
Integration with Linux accounts is possible, through PAM and nslcd. See [PAM
|
|
||||||
configuration guide](example_configs/pam/README.md). Integration with Windows (e.g. Samba) is WIP.
|
|
||||||
|
|
||||||
### General configuration guide
|
### General configuration guide
|
||||||
|
|
||||||
To configure the services that will talk to LLDAP, here are the values:
|
To configure the services that will talk to LLDAP, here are the values:
|
||||||
@@ -170,41 +239,117 @@ filter like: `(memberOf=cn=admins,ou=groups,dc=example,dc=com)`.
|
|||||||
The administrator group for LLDAP is `lldap_admin`: anyone in this group has
|
The administrator group for LLDAP is `lldap_admin`: anyone in this group has
|
||||||
admin rights in the Web UI. Most LDAP integrations should instead use a user in
|
admin rights in the Web UI. Most LDAP integrations should instead use a user in
|
||||||
the `lldap_strict_readonly` or `lldap_password_manager` group, to avoid granting full
|
the `lldap_strict_readonly` or `lldap_password_manager` group, to avoid granting full
|
||||||
administration access to many services. To prevent privilege escalation users in the
|
administration access to many services.
|
||||||
`lldap_password_manager` group are not allowed to change passwords of admins in the
|
|
||||||
`lldap_admin` group.
|
|
||||||
|
|
||||||
### Incompatible services
|
### Sample client configurations
|
||||||
|
|
||||||
Though we try to be maximally compatible, not every feature is supported; LLDAP
|
Some specific clients have been tested to work and come with sample
|
||||||
is not a fully-featured LDAP server, intentionally so.
|
configuration files, or guides. See the [`example_configs`](example_configs)
|
||||||
|
folder for help with:
|
||||||
|
|
||||||
LDAP browsing tools are generally not supported, though they could be. If you
|
- [Airsonic Advanced](example_configs/airsonic-advanced.md)
|
||||||
need to use one but it behaves weirdly, please file a bug.
|
- [Apache Guacamole](example_configs/apacheguacamole.md)
|
||||||
|
- [Authelia](example_configs/authelia_config.yml)
|
||||||
|
- [Authentik](example_configs/authentik.md)
|
||||||
|
- [Bookstack](example_configs/bookstack.env.example)
|
||||||
|
- [Calibre-Web](example_configs/calibre_web.md)
|
||||||
|
- [Dell iDRAC](example_configs/dell_idrac.md)
|
||||||
|
- [Dex](example_configs/dex_config.yml)
|
||||||
|
- [Dokuwiki](example_configs/dokuwiki.md)
|
||||||
|
- [Dolibarr](example_configs/dolibarr.md)
|
||||||
|
- [Emby](example_configs/emby.md)
|
||||||
|
- [Gitea](example_configs/gitea.md)
|
||||||
|
- [Grafana](example_configs/grafana_ldap_config.toml)
|
||||||
|
- [Hedgedoc](example_configs/hedgedoc.md)
|
||||||
|
- [Jellyfin](example_configs/jellyfin.md)
|
||||||
|
- [Jitsi Meet](example_configs/jitsi_meet.conf)
|
||||||
|
- [KeyCloak](example_configs/keycloak.md)
|
||||||
|
- [Matrix](example_configs/matrix_synapse.yml)
|
||||||
|
- [Nextcloud](example_configs/nextcloud.md)
|
||||||
|
- [Nexus](example_configs/nexus.md)
|
||||||
|
- [Organizr](example_configs/Organizr.md)
|
||||||
|
- [Portainer](example_configs/portainer.md)
|
||||||
|
- [Rancher](example_configs/rancher.md)
|
||||||
|
- [Seafile](example_configs/seafile.md)
|
||||||
|
- [Shaarli](example_configs/shaarli.md)
|
||||||
|
- [Syncthing](example_configs/syncthing.md)
|
||||||
|
- [Vaultwarden](example_configs/vaultwarden.md)
|
||||||
|
- [WeKan](example_configs/wekan.md)
|
||||||
|
- [WG Portal](example_configs/wg_portal.env.example)
|
||||||
|
- [WikiJS](example_configs/wikijs.md)
|
||||||
|
- [XBackBone](example_configs/xbackbone_config.php)
|
||||||
|
- [Zendto](example_configs/zendto.md)
|
||||||
|
|
||||||
Some services use features that are not implemented, or require specific
|
## Migrating from SQLite
|
||||||
attributes. You can try to create those attributes (see custom attributes in
|
|
||||||
the [Usage](#usage) section).
|
|
||||||
|
|
||||||
Finally, some services require password hashes so they can validate themselves
|
If you started with an SQLite database and would like to migrate to
|
||||||
the user's password without contacting LLDAP. This is not and will not be
|
MySQL/MariaDB or PostgreSQL, check out the [DB
|
||||||
supported, it's incompatible with our password hashing scheme (a zero-knowledge
|
migration docs](/docs/database_migration.md).
|
||||||
proof). Furthermore, it's generally not recommended in terms of security, since
|
|
||||||
it duplicates the places from which a password hash could leak.
|
|
||||||
|
|
||||||
In that category, the most prominent is Synology. It is, to date, the only
|
## Comparisons with other services
|
||||||
service that seems definitely incompatible with LLDAP.
|
|
||||||
|
|
||||||
## Frequently Asked Questions
|
### vs OpenLDAP
|
||||||
|
|
||||||
- [I can't login](docs/faq.md#i-cant-log-in)
|
[OpenLDAP](https://www.openldap.org) is a monster of a service that implements
|
||||||
- [Discord Integration](docs/faq.md#discord-integration)
|
all of LDAP and all of its extensions, plus some of its own. That said, if you
|
||||||
- [Migrating from SQLite](docs/faq.md#migrating-from-sqlite)
|
need all that flexibility, it might be what you need! Note that installation
|
||||||
- How does lldap compare [with OpenLDAP](docs/faq.md#how-does-lldap-compare-with-openldap)? [With FreeIPA](docs/faq.md#how-does-lldap-compare-with-freeipa)? [With Kanidm](docs/faq.md#how-does-lldap-compare-with-kanidm)?
|
can be a bit painful (figuring out how to use `slapd`) and people have mixed
|
||||||
- [Does lldap support vhosts?](docs/faq.md#does-lldap-support-vhosts)
|
experiences following tutorials online. If you don't configure it properly, you
|
||||||
- [Does lldap provide commercial support contracts?](docs/faq.md#does-lldap-provide-commercial-support-contracts)
|
might end up storing passwords in clear, so a breach of your server would
|
||||||
- [Can I make a donation to fund development?](docs/faq.md#can-i-make-a-donation-to-fund-development)
|
reveal all the stored passwords!
|
||||||
- [Is lldap sustainable? Can we depend on it for our infrastructure?](docs/faq.md#is-lldap-sustainable-can-we-depend-on-it-for-our-infrastructure)
|
|
||||||
|
OpenLDAP doesn't come with a UI: if you want a web interface, you'll have to
|
||||||
|
install one (not that many look nice) and configure it.
|
||||||
|
|
||||||
|
LLDAP is much simpler to setup, has a much smaller image (10x smaller, 20x if
|
||||||
|
you add PhpLdapAdmin), and comes packed with its own purpose-built web UI.
|
||||||
|
However, it's not as flexible as OpenLDAP.
|
||||||
|
|
||||||
|
### vs FreeIPA
|
||||||
|
|
||||||
|
[FreeIPA](http://www.freeipa.org) is the one-stop shop for identity management:
|
||||||
|
LDAP, Kerberos, NTP, DNS, Samba, you name it, it has it. In addition to user
|
||||||
|
management, it also does security policies, single sign-on, certificate
|
||||||
|
management, linux account management and so on.
|
||||||
|
|
||||||
|
If you need all of that, go for it! Keep in mind that a more complex system is
|
||||||
|
more complex to maintain, though.
|
||||||
|
|
||||||
|
LLDAP is much lighter to run (<10 MB RAM including the DB), easier to
|
||||||
|
configure (no messing around with DNS or security policies) and simpler to
|
||||||
|
use. It also comes conveniently packed in a docker container.
|
||||||
|
|
||||||
|
### vs Kanidm
|
||||||
|
|
||||||
|
[Kanidm](https://kanidm.com) is an up-and-coming Rust identity management
|
||||||
|
platform, covering all your bases: OAuth, Linux accounts, SSH keys, Radius,
|
||||||
|
WebAuthn. It comes with a (read-only) LDAPS server.
|
||||||
|
|
||||||
|
It's fairly easy to install and does much more; but their LDAP server is
|
||||||
|
read-only, and by having more moving parts it is inherently more complex. If
|
||||||
|
you don't need to modify the users through LDAP and you're planning on
|
||||||
|
installing something like [KeyCloak](https://www.keycloak.org) to provide
|
||||||
|
modern identity protocols, check out Kanidm.
|
||||||
|
|
||||||
|
## I can't log in!
|
||||||
|
|
||||||
|
If you just set up the server, can get to the login page but the password you
|
||||||
|
set isn't working, try the following:
|
||||||
|
|
||||||
|
- (For docker): Make sure that the `/data` folder is persistent, either to a
|
||||||
|
docker volume or mounted from the host filesystem.
|
||||||
|
- Check if there is a `lldap_config.toml` file (either in `/data` for docker
|
||||||
|
or in the current directory). If there isn't, copy
|
||||||
|
`lldap_config.docker_template.toml` there, and fill in the various values
|
||||||
|
(passwords, secrets, ...).
|
||||||
|
- Check if there is a `users.db` file (either in `/data` for docker or where
|
||||||
|
you specified the DB URL, which defaults to the current directory). If
|
||||||
|
there isn't, check that the user running the command (user with ID 10001
|
||||||
|
for docker) has the rights to write to the `/data` folder. If in doubt, you
|
||||||
|
can `chmod 777 /data` (or whatever the folder) to make it world-writeable.
|
||||||
|
- Make sure you restart the server.
|
||||||
|
- If it's still not working, join the
|
||||||
|
[Discord server](https://discord.gg/h5PEdRMNyP) to ask for help.
|
||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
|
|
||||||
|
|||||||
+10
-45
@@ -1,13 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lldap_app"
|
name = "lldap_app"
|
||||||
version = "0.6.2"
|
version = "0.4.3-alpha"
|
||||||
description = "Frontend for LLDAP"
|
authors = ["Valentin Tolmer <valentin@tolmer.fr>"]
|
||||||
edition.workspace = true
|
edition = "2021"
|
||||||
include = ["src/**/*", "queries/**/*", "Cargo.toml", "../schema.graphql"]
|
include = ["src/**/*", "queries/**/*", "Cargo.toml", "../schema.graphql"]
|
||||||
authors.workspace = true
|
|
||||||
homepage.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
repository.workspace = true
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
@@ -19,33 +15,32 @@ graphql_client = "0.10"
|
|||||||
http = "0.2"
|
http = "0.2"
|
||||||
jwt = "0.13"
|
jwt = "0.13"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
serde = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
url-escape = "0.1.1"
|
url-escape = "0.1.1"
|
||||||
validator = "0.14"
|
validator = "=0.14"
|
||||||
validator_derive = "0.14"
|
sha1 = "*"
|
||||||
wasm-bindgen = "0.2.100"
|
validator_derive = "*"
|
||||||
|
wasm-bindgen = "0.2"
|
||||||
wasm-bindgen-futures = "*"
|
wasm-bindgen-futures = "*"
|
||||||
yew = "0.19.3"
|
yew = "0.19.3"
|
||||||
yew-router = "0.16"
|
yew-router = "0.16"
|
||||||
|
|
||||||
# Needed because of https://github.com/tkaitchuck/aHash/issues/95
|
# Needed because of https://github.com/tkaitchuck/aHash/issues/95
|
||||||
indexmap = "=1.6.2"
|
indexmap = "=1.6.2"
|
||||||
|
gloo-timers = "0.2.6"
|
||||||
|
|
||||||
[dependencies.web-sys]
|
[dependencies.web-sys]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
features = [
|
features = [
|
||||||
"Document",
|
"Document",
|
||||||
"Element",
|
"Element",
|
||||||
"Event",
|
|
||||||
"FileReader",
|
"FileReader",
|
||||||
"FormData",
|
|
||||||
"HtmlDocument",
|
"HtmlDocument",
|
||||||
"HtmlFormElement",
|
|
||||||
"HtmlInputElement",
|
"HtmlInputElement",
|
||||||
"HtmlOptionElement",
|
"HtmlOptionElement",
|
||||||
"HtmlOptionsCollection",
|
"HtmlOptionsCollection",
|
||||||
"HtmlSelectElement",
|
"HtmlSelectElement",
|
||||||
"SubmitEvent",
|
|
||||||
"console",
|
"console",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -55,33 +50,15 @@ features = [
|
|||||||
"wasmbind"
|
"wasmbind"
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies.derive_more]
|
|
||||||
features = ["debug", "display", "from", "from_str"]
|
|
||||||
default-features = false
|
|
||||||
version = "1"
|
|
||||||
|
|
||||||
[dependencies.lldap_auth]
|
[dependencies.lldap_auth]
|
||||||
path = "../crates/auth"
|
path = "../auth"
|
||||||
features = [ "opaque_client" ]
|
features = [ "opaque_client" ]
|
||||||
|
|
||||||
[dependencies.lldap_frontend_options]
|
|
||||||
path = "../crates/frontend-options"
|
|
||||||
|
|
||||||
[dependencies.lldap_validation]
|
|
||||||
path = "../crates/validation"
|
|
||||||
|
|
||||||
[dependencies.image]
|
[dependencies.image]
|
||||||
features = ["jpeg"]
|
features = ["jpeg"]
|
||||||
default-features = false
|
default-features = false
|
||||||
version = "0.24"
|
version = "0.24"
|
||||||
|
|
||||||
[dependencies.serde]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
[dependencies.strum]
|
|
||||||
features = ["derive"]
|
|
||||||
version = "0.25"
|
|
||||||
|
|
||||||
[dependencies.yew_form]
|
[dependencies.yew_form]
|
||||||
git = "https://github.com/jfbilodeau/yew_form"
|
git = "https://github.com/jfbilodeau/yew_form"
|
||||||
rev = "4b9fabffb63393ec7626a4477fd36de12a07fac9"
|
rev = "4b9fabffb63393ec7626a4477fd36de12a07fac9"
|
||||||
@@ -92,15 +69,3 @@ rev = "4b9fabffb63393ec7626a4477fd36de12a07fac9"
|
|||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[lints.rust]
|
|
||||||
unexpected_cfgs = { level = "warn", check-cfg = [
|
|
||||||
'cfg(wasm_bindgen_unstable_test_coverage)',
|
|
||||||
] }
|
|
||||||
|
|
||||||
[package.metadata.wasm-pack.profile.dev]
|
|
||||||
wasm-opt = ['--enable-bulk-memory']
|
|
||||||
[package.metadata.wasm-pack.profile.profiling]
|
|
||||||
wasm-opt = ['--enable-bulk-memory']
|
|
||||||
[package.metadata.wasm-pack.profile.release]
|
|
||||||
wasm-opt = ['--enable-bulk-memory']
|
|
||||||
|
|||||||
+4
-22
@@ -4,8 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>LLDAP Administration</title>
|
<title>LLDAP Administration</title>
|
||||||
<base href="/">
|
<script src="/static/main.js" type="module" defer></script>
|
||||||
<script src="static/main.js" type="module" defer></script>
|
|
||||||
<link
|
<link
|
||||||
href="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/css/bootstrap-nightshade.min.css"
|
href="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/css/bootstrap-nightshade.min.css"
|
||||||
rel="preload stylesheet"
|
rel="preload stylesheet"
|
||||||
@@ -16,8 +15,8 @@
|
|||||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"
|
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"
|
||||||
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"
|
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
<script
|
<script
|
||||||
src="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/js/darkmode.min.js"
|
src="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/js/darkmode.min.js"
|
||||||
integrity="sha384-A4SLs39X/aUfwRclRaXvNeXNBTLZdnZdHhhteqbYFS2jZTRD79tKeFeBn7SGXNpi"
|
integrity="sha384-A4SLs39X/aUfwRclRaXvNeXNBTLZdnZdHhhteqbYFS2jZTRD79tKeFeBn7SGXNpi"
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
<link
|
<link
|
||||||
@@ -34,7 +33,7 @@
|
|||||||
href="https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap" />
|
href="https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap" />
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="static/style.css" />
|
href="/static/style.css" />
|
||||||
<script>
|
<script>
|
||||||
function inDarkMode(){
|
function inDarkMode(){
|
||||||
return darkmode.inDarkMode;
|
return darkmode.inDarkMode;
|
||||||
@@ -44,23 +43,6 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
|
||||||
<!-- This will be displayed if the user doesn't have JavaScript enabled. -->
|
|
||||||
LLDAP requires JavaScript, please switch to a compatible browser or
|
|
||||||
enable it.
|
|
||||||
</noscript>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
/* Detect if the user has WASM support. */
|
|
||||||
if (typeof WebAssembly === 'undefined') {
|
|
||||||
const pWASMMsg = document.createElement("p")
|
|
||||||
pWASMMsg.innerHTML = `
|
|
||||||
LLDAP requires WASM and JIT for JavaScript, please switch to a
|
|
||||||
compatible browser or enable it.
|
|
||||||
`
|
|
||||||
document.body.appendChild(pWASMMsg)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+2
-19
@@ -13,8 +13,8 @@
|
|||||||
<script
|
<script
|
||||||
src="/static/bootstrap.bundle.min.js"
|
src="/static/bootstrap.bundle.min.js"
|
||||||
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"></script>
|
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"></script>
|
||||||
<script
|
<script
|
||||||
src="/static/darkmode.min.js"
|
src="/static/darkmode.min.js"
|
||||||
integrity="sha384-A4SLs39X/aUfwRclRaXvNeXNBTLZdnZdHhhteqbYFS2jZTRD79tKeFeBn7SGXNpi"></script>
|
integrity="sha384-A4SLs39X/aUfwRclRaXvNeXNBTLZdnZdHhhteqbYFS2jZTRD79tKeFeBn7SGXNpi"></script>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
@@ -40,23 +40,6 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
|
||||||
<!-- This will be displayed if the user doesn't have JavaScript enabled. -->
|
|
||||||
LLDAP requires JavaScript, please switch to a compatible browser or
|
|
||||||
enable it.
|
|
||||||
</noscript>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
/* Detect if the user has WASM support. */
|
|
||||||
if (typeof WebAssembly === 'undefined') {
|
|
||||||
const pWASMMsg = document.createElement("p")
|
|
||||||
pWASMMsg.innerHTML = `
|
|
||||||
LLDAP requires WASM and JIT for JavaScript, please switch to a
|
|
||||||
compatible browser or enable it.
|
|
||||||
`
|
|
||||||
document.body.appendChild(pWASMMsg)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
mutation CreateGroup($group: CreateGroupInput!) {
|
mutation CreateGroup($name: String!) {
|
||||||
createGroupWithDetails(request: $group) {
|
createGroup(name: $name) {
|
||||||
id
|
id
|
||||||
displayName
|
displayName
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
mutation CreateGroupAttribute($name: String!, $attributeType: AttributeType!, $isList: Boolean!, $isVisible: Boolean!) {
|
|
||||||
addGroupAttribute(name: $name, attributeType: $attributeType, isList: $isList, isVisible: $isVisible, isEditable: false) {
|
|
||||||
ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
mutation CreateUserAttribute($name: String!, $attributeType: AttributeType!, $isList: Boolean!, $isVisible: Boolean!, $isEditable: Boolean!) {
|
|
||||||
addUserAttribute(name: $name, attributeType: $attributeType, isList: $isList, isVisible: $isVisible, isEditable: $isEditable) {
|
|
||||||
ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
mutation DeleteGroupAttributeQuery($name: String!) {
|
|
||||||
deleteGroupAttribute(name: $name) {
|
|
||||||
ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
mutation DeleteUserAttributeQuery($name: String!) {
|
|
||||||
deleteUserAttribute(name: $name) {
|
|
||||||
ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
query GetGroupAttributesSchema {
|
|
||||||
schema {
|
|
||||||
groupSchema {
|
|
||||||
attributes {
|
|
||||||
name
|
|
||||||
attributeType
|
|
||||||
isList
|
|
||||||
isVisible
|
|
||||||
isHardcoded
|
|
||||||
isReadonly
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,22 +8,5 @@ query GetGroupDetails($id: Int!) {
|
|||||||
id
|
id
|
||||||
displayName
|
displayName
|
||||||
}
|
}
|
||||||
attributes {
|
|
||||||
name
|
|
||||||
value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
schema {
|
|
||||||
groupSchema {
|
|
||||||
attributes {
|
|
||||||
name
|
|
||||||
attributeType
|
|
||||||
isList
|
|
||||||
isVisible
|
|
||||||
isEditable
|
|
||||||
isHardcoded
|
|
||||||
isReadonly
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
query GetUserAttributesSchema {
|
|
||||||
schema {
|
|
||||||
userSchema {
|
|
||||||
attributes {
|
|
||||||
name
|
|
||||||
attributeType
|
|
||||||
isList
|
|
||||||
isVisible
|
|
||||||
isEditable
|
|
||||||
isHardcoded
|
|
||||||
isReadonly
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,30 +2,15 @@ query GetUserDetails($id: String!) {
|
|||||||
user(userId: $id) {
|
user(userId: $id) {
|
||||||
id
|
id
|
||||||
email
|
email
|
||||||
avatar
|
|
||||||
displayName
|
displayName
|
||||||
|
firstName
|
||||||
|
lastName
|
||||||
|
avatar
|
||||||
creationDate
|
creationDate
|
||||||
uuid
|
uuid
|
||||||
groups {
|
groups {
|
||||||
id
|
id
|
||||||
displayName
|
displayName
|
||||||
}
|
}
|
||||||
attributes {
|
|
||||||
name
|
|
||||||
value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
schema {
|
|
||||||
userSchema {
|
|
||||||
attributes {
|
|
||||||
name
|
|
||||||
attributeType
|
|
||||||
isList
|
|
||||||
isVisible
|
|
||||||
isEditable
|
|
||||||
isHardcoded
|
|
||||||
isReadonly
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
mutation UpdateGroup($group: UpdateGroupInput!) {
|
|
||||||
updateGroup(group: $group) {
|
|
||||||
ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -155,13 +155,8 @@ impl Component for AddGroupMemberComponent {
|
|||||||
let to_add_user_list = self.get_selectable_user_list(ctx, user_list);
|
let to_add_user_list = self.get_selectable_user_list(ctx, user_list);
|
||||||
#[allow(unused_braces)]
|
#[allow(unused_braces)]
|
||||||
let make_select_option = |user: User| {
|
let make_select_option = |user: User| {
|
||||||
let name = if user.display_name.is_empty() {
|
|
||||||
user.id.clone()
|
|
||||||
} else {
|
|
||||||
user.display_name.clone()
|
|
||||||
};
|
|
||||||
html_nested! {
|
html_nested! {
|
||||||
<SelectOption value={user.id.clone()} text={name} key={user.id} />
|
<SelectOption value={user.id.clone()} text={user.display_name.clone()} key={user.id} />
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
html! {
|
html! {
|
||||||
|
|||||||
+135
-57
@@ -1,38 +1,54 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::{
|
||||||
banner::Banner,
|
|
||||||
change_password::ChangePasswordForm,
|
change_password::ChangePasswordForm,
|
||||||
create_group::CreateGroupForm,
|
create_group::CreateGroupForm,
|
||||||
create_group_attribute::CreateGroupAttributeForm,
|
|
||||||
create_user::CreateUserForm,
|
create_user::CreateUserForm,
|
||||||
create_user_attribute::CreateUserAttributeForm,
|
|
||||||
group_details::GroupDetails,
|
group_details::GroupDetails,
|
||||||
group_schema_table::ListGroupSchema,
|
|
||||||
group_table::GroupTable,
|
group_table::GroupTable,
|
||||||
login::LoginForm,
|
login::LoginForm,
|
||||||
|
logout::LogoutButton,
|
||||||
reset_password_step1::ResetPasswordStep1Form,
|
reset_password_step1::ResetPasswordStep1Form,
|
||||||
reset_password_step2::ResetPasswordStep2Form,
|
reset_password_step2::ResetPasswordStep2Form,
|
||||||
router::{AppRoute, Link, Redirect},
|
router::{AppRoute, Link, Redirect},
|
||||||
user_details::UserDetails,
|
user_details::UserDetails,
|
||||||
user_schema_table::ListUserSchema,
|
|
||||||
user_table::UserTable,
|
user_table::UserTable,
|
||||||
},
|
},
|
||||||
infra::{api::HostService, cookies::get_cookie},
|
infra::{api::HostService, cookies::get_cookie},
|
||||||
};
|
};
|
||||||
|
|
||||||
use gloo_console::error;
|
use gloo_console::error;
|
||||||
use lldap_frontend_options::Options;
|
use wasm_bindgen::prelude::*;
|
||||||
use yew::{
|
use yew::{
|
||||||
Context, function_component,
|
function_component,
|
||||||
html::Scope,
|
html::Scope,
|
||||||
prelude::{Component, Html, html},
|
prelude::{html, Component, Html},
|
||||||
|
Context,
|
||||||
};
|
};
|
||||||
use yew_router::{
|
use yew_router::{
|
||||||
BrowserRouter, Switch,
|
|
||||||
prelude::{History, Location},
|
prelude::{History, Location},
|
||||||
scope_ext::RouterScopeExt,
|
scope_ext::RouterScopeExt,
|
||||||
|
BrowserRouter, Switch,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
#[wasm_bindgen(js_namespace = darkmode)]
|
||||||
|
fn toggleDarkMode(doSave: bool);
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
fn inDarkMode() -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[function_component(DarkModeToggle)]
|
||||||
|
pub fn dark_mode_toggle() -> Html {
|
||||||
|
html! {
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input class="form-check-input" onclick={|_| toggleDarkMode(true)} type="checkbox" id="darkModeToggle" checked={inDarkMode()}/>
|
||||||
|
<label class="form-check-label" for="darkModeToggle">{"Dark mode"}</label>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[function_component(AppContainer)]
|
#[function_component(AppContainer)]
|
||||||
pub fn app_container() -> Html {
|
pub fn app_container() -> Html {
|
||||||
html! {
|
html! {
|
||||||
@@ -51,7 +67,7 @@ pub struct App {
|
|||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
Login((String, bool)),
|
Login((String, bool)),
|
||||||
Logout,
|
Logout,
|
||||||
SettingsReceived(anyhow::Result<Options>),
|
PasswordResetProbeFinished(anyhow::Result<bool>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for App {
|
impl Component for App {
|
||||||
@@ -76,8 +92,9 @@ impl Component for App {
|
|||||||
redirect_to: Self::get_redirect_route(ctx),
|
redirect_to: Self::get_redirect_route(ctx),
|
||||||
password_reset_enabled: None,
|
password_reset_enabled: None,
|
||||||
};
|
};
|
||||||
ctx.link()
|
ctx.link().send_future(async move {
|
||||||
.send_future(async move { Msg::SettingsReceived(HostService::get_settings().await) });
|
Msg::PasswordResetProbeFinished(HostService::probe_password_reset().await)
|
||||||
|
});
|
||||||
app.apply_initial_redirections(ctx);
|
app.apply_initial_redirections(ctx);
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
@@ -102,11 +119,14 @@ impl Component for App {
|
|||||||
self.redirect_to = None;
|
self.redirect_to = None;
|
||||||
history.push(AppRoute::Login);
|
history.push(AppRoute::Login);
|
||||||
}
|
}
|
||||||
Msg::SettingsReceived(Ok(settings)) => {
|
Msg::PasswordResetProbeFinished(Ok(enabled)) => {
|
||||||
self.password_reset_enabled = Some(settings.password_reset_enabled);
|
self.password_reset_enabled = Some(enabled);
|
||||||
}
|
}
|
||||||
Msg::SettingsReceived(Err(err)) => {
|
Msg::PasswordResetProbeFinished(Err(err)) => {
|
||||||
error!(err.to_string());
|
self.password_reset_enabled = Some(false);
|
||||||
|
error!(&format!(
|
||||||
|
"Could not probe for password reset support: {err:#}"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -115,14 +135,13 @@ impl Component for App {
|
|||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
fn view(&self, ctx: &Context<Self>) -> Html {
|
||||||
let link = ctx.link().clone();
|
let link = ctx.link().clone();
|
||||||
let is_admin = self.is_admin();
|
let is_admin = self.is_admin();
|
||||||
let username = self.user_info.clone().map(|(username, _)| username);
|
|
||||||
let password_reset_enabled = self.password_reset_enabled;
|
let password_reset_enabled = self.password_reset_enabled;
|
||||||
html! {
|
html! {
|
||||||
<div>
|
<div>
|
||||||
<Banner is_admin={is_admin} username={username} on_logged_out={link.callback(|_| Msg::Logout)} />
|
{self.view_banner(ctx)}
|
||||||
<div class="container py-3 bg-kug">
|
<div class="container py-3 bg-kug">
|
||||||
<div class="row justify-content-center" style="padding-bottom: 80px;">
|
<div class="row justify-content-center" style="padding-bottom: 80px;">
|
||||||
<main class="py-3">
|
<main class="py-3" style="max-width: 1000px">
|
||||||
<Switch<AppRoute>
|
<Switch<AppRoute>
|
||||||
render={Switch::render(move |routes| Self::dispatch_route(routes, &link, is_admin, password_reset_enabled))}
|
render={Switch::render(move |routes| Self::dispatch_route(routes, &link, is_admin, password_reset_enabled))}
|
||||||
/>
|
/>
|
||||||
@@ -196,55 +215,29 @@ impl App {
|
|||||||
AppRoute::CreateUser => html! {
|
AppRoute::CreateUser => html! {
|
||||||
<CreateUserForm/>
|
<CreateUserForm/>
|
||||||
},
|
},
|
||||||
AppRoute::Index | AppRoute::ListUsers => {
|
AppRoute::Index | AppRoute::ListUsers => html! {
|
||||||
let user_button = html! {
|
<div>
|
||||||
|
<UserTable />
|
||||||
<Link classes="btn btn-primary" to={AppRoute::CreateUser}>
|
<Link classes="btn btn-primary" to={AppRoute::CreateUser}>
|
||||||
<i class="bi-person-plus me-2"></i>
|
<i class="bi-person-plus me-2"></i>
|
||||||
{"Create a user"}
|
{"Create a user"}
|
||||||
</Link>
|
</Link>
|
||||||
};
|
</div>
|
||||||
html! {
|
},
|
||||||
<div>
|
|
||||||
{ user_button.clone() }
|
|
||||||
<UserTable />
|
|
||||||
{ user_button }
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AppRoute::CreateGroup => html! {
|
AppRoute::CreateGroup => html! {
|
||||||
<CreateGroupForm/>
|
<CreateGroupForm/>
|
||||||
},
|
},
|
||||||
AppRoute::CreateUserAttribute => html! {
|
AppRoute::ListGroups => html! {
|
||||||
<CreateUserAttributeForm/>
|
<div>
|
||||||
},
|
<GroupTable />
|
||||||
AppRoute::CreateGroupAttribute => html! {
|
|
||||||
<CreateGroupAttributeForm/>
|
|
||||||
},
|
|
||||||
AppRoute::ListGroups => {
|
|
||||||
let group_button = html! {
|
|
||||||
<Link classes="btn btn-primary" to={AppRoute::CreateGroup}>
|
<Link classes="btn btn-primary" to={AppRoute::CreateGroup}>
|
||||||
<i class="bi-plus-circle me-2"></i>
|
<i class="bi-plus-circle me-2"></i>
|
||||||
{"Create a group"}
|
{"Create a group"}
|
||||||
</Link>
|
</Link>
|
||||||
};
|
</div>
|
||||||
// Note: There's a weird bug when switching from the users page to the groups page
|
|
||||||
// where the two groups buttons are at the bottom. I don't know why.
|
|
||||||
html! {
|
|
||||||
<div>
|
|
||||||
{ group_button.clone() }
|
|
||||||
<GroupTable />
|
|
||||||
{ group_button }
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AppRoute::ListUserSchema => html! {
|
|
||||||
<ListUserSchema />
|
|
||||||
},
|
|
||||||
AppRoute::ListGroupSchema => html! {
|
|
||||||
<ListGroupSchema />
|
|
||||||
},
|
},
|
||||||
AppRoute::GroupDetails { group_id } => html! {
|
AppRoute::GroupDetails { group_id } => html! {
|
||||||
<GroupDetails group_id={*group_id} is_admin={is_admin} />
|
<GroupDetails group_id={*group_id} />
|
||||||
},
|
},
|
||||||
AppRoute::UserDetails { user_id } => html! {
|
AppRoute::UserDetails { user_id } => html! {
|
||||||
<UserDetails username={user_id.clone()} is_admin={is_admin} />
|
<UserDetails username={user_id.clone()} is_admin={is_admin} />
|
||||||
@@ -270,6 +263,91 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn view_banner(&self, ctx: &Context<Self>) -> Html {
|
||||||
|
html! {
|
||||||
|
<header class="p-2 mb-3 border-bottom">
|
||||||
|
<div class="container">
|
||||||
|
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
|
||||||
|
<a href="/" class="d-flex align-items-center mt-2 mb-lg-0 me-md-5 text-decoration-none">
|
||||||
|
<h2>{"LLDAP"}</h2>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
||||||
|
{if self.is_admin() { html! {
|
||||||
|
<>
|
||||||
|
<li>
|
||||||
|
<Link
|
||||||
|
classes="nav-link px-2 h6"
|
||||||
|
to={AppRoute::ListUsers}>
|
||||||
|
<i class="bi-people me-2"></i>
|
||||||
|
{"Users"}
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<Link
|
||||||
|
classes="nav-link px-2 h6"
|
||||||
|
to={AppRoute::ListGroups}>
|
||||||
|
<i class="bi-collection me-2"></i>
|
||||||
|
{"Groups"}
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
</>
|
||||||
|
} } else { html!{} } }
|
||||||
|
</ul>
|
||||||
|
{ self.view_user_menu(ctx) }
|
||||||
|
<DarkModeToggle />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view_user_menu(&self, ctx: &Context<Self>) -> Html {
|
||||||
|
if let Some((user_id, _)) = &self.user_info {
|
||||||
|
let link = ctx.link();
|
||||||
|
html! {
|
||||||
|
<div class="dropdown text-end">
|
||||||
|
<a href="#"
|
||||||
|
class="d-block nav-link text-decoration-none dropdown-toggle"
|
||||||
|
id="dropdownUser"
|
||||||
|
data-bs-toggle="dropdown"
|
||||||
|
aria-expanded="false">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="32"
|
||||||
|
height="32"
|
||||||
|
fill="currentColor"
|
||||||
|
class="bi bi-person-circle"
|
||||||
|
viewBox="0 0 16 16">
|
||||||
|
<path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z"/>
|
||||||
|
<path fill-rule="evenodd" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z"/>
|
||||||
|
</svg>
|
||||||
|
<span class="ms-2">
|
||||||
|
{user_id}
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<ul
|
||||||
|
class="dropdown-menu text-small dropdown-menu-lg-end"
|
||||||
|
aria-labelledby="dropdownUser1"
|
||||||
|
style="">
|
||||||
|
<li>
|
||||||
|
<Link
|
||||||
|
classes="dropdown-item"
|
||||||
|
to={AppRoute::UserDetails{ user_id: user_id.clone() }}>
|
||||||
|
{"View details"}
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li><hr class="dropdown-divider" /></li>
|
||||||
|
<li>
|
||||||
|
<LogoutButton on_logged_out={link.callback(|_| Msg::Logout)} />
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
html! {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn view_footer(&self) -> Html {
|
fn view_footer(&self) -> Html {
|
||||||
html! {
|
html! {
|
||||||
<footer class="text-center fixed-bottom text-muted bg-light py-2">
|
<footer class="text-center fixed-bottom text-muted bg-light py-2">
|
||||||
@@ -277,7 +355,7 @@ impl App {
|
|||||||
<span>{format!("LLDAP version {}", env!("CARGO_PKG_VERSION"))}</span>
|
<span>{format!("LLDAP version {}", env!("CARGO_PKG_VERSION"))}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<a href="https://github.com/lldap/lldap" class="me-4 text-reset">
|
<a href="https://github.com/nitnelave/lldap" class="me-4 text-reset">
|
||||||
<i class="bi-github"></i>
|
<i class="bi-github"></i>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://discord.gg/h5PEdRMNyP" class="me-4 text-reset">
|
<a href="https://discord.gg/h5PEdRMNyP" class="me-4 text-reset">
|
||||||
@@ -288,7 +366,7 @@ impl App {
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span>{"License "}<a href="https://github.com/lldap/lldap/blob/main/LICENSE" class="link-secondary">{"GNU GPL"}</a></span>
|
<span>{"License "}<a href="https://github.com/nitnelave/lldap/blob/main/LICENSE" class="link-secondary">{"GNU GPL"}</a></span>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
use crate::infra::functional::{LoadableResult, use_graphql_call};
|
|
||||||
use graphql_client::GraphQLQuery;
|
|
||||||
use yew::{Properties, function_component, html, virtual_dom::AttrValue};
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/get_user_details.graphql",
|
|
||||||
variables_derives = "Clone,PartialEq,Eq",
|
|
||||||
response_derives = "Debug, Hash, PartialEq, Eq, Clone",
|
|
||||||
custom_scalars_module = "crate::infra::graphql"
|
|
||||||
)]
|
|
||||||
pub struct GetUserDetails;
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct Props {
|
|
||||||
pub user: AttrValue,
|
|
||||||
#[prop_or(32)]
|
|
||||||
pub width: i32,
|
|
||||||
#[prop_or(32)]
|
|
||||||
pub height: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(Avatar)]
|
|
||||||
pub fn avatar(props: &Props) -> Html {
|
|
||||||
let user_details = use_graphql_call::<GetUserDetails>(get_user_details::Variables {
|
|
||||||
id: props.user.to_string(),
|
|
||||||
});
|
|
||||||
|
|
||||||
match &(*user_details) {
|
|
||||||
LoadableResult::Loaded(Ok(response)) => {
|
|
||||||
let avatar = response.user.avatar.clone();
|
|
||||||
match &avatar {
|
|
||||||
Some(data) => html! {
|
|
||||||
<img
|
|
||||||
id="avatarDisplay"
|
|
||||||
src={format!("data:image/jpeg;base64, {}", data)}
|
|
||||||
style={format!("max-height:{}px;max-width:{}px;height:auto;width:auto;", props.height, props.width)}
|
|
||||||
alt="Avatar" />
|
|
||||||
},
|
|
||||||
None => html! {
|
|
||||||
<BlankAvatarDisplay
|
|
||||||
width={props.width}
|
|
||||||
height={props.height} />
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LoadableResult::Loaded(Err(error)) => html! {
|
|
||||||
<BlankAvatarDisplay
|
|
||||||
error={error.to_string()}
|
|
||||||
width={props.width}
|
|
||||||
height={props.height} />
|
|
||||||
},
|
|
||||||
LoadableResult::Loading => html! {
|
|
||||||
<BlankAvatarDisplay
|
|
||||||
width={props.width}
|
|
||||||
height={props.height} />
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
struct BlankAvatarDisplayProps {
|
|
||||||
#[prop_or(None)]
|
|
||||||
pub error: Option<AttrValue>,
|
|
||||||
pub width: i32,
|
|
||||||
pub height: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(BlankAvatarDisplay)]
|
|
||||||
fn blank_avatar_display(props: &BlankAvatarDisplayProps) -> Html {
|
|
||||||
let fill = match &props.error {
|
|
||||||
Some(_) => "red",
|
|
||||||
None => "currentColor",
|
|
||||||
};
|
|
||||||
html! {
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width={props.width.to_string()}
|
|
||||||
height={props.height.to_string()}
|
|
||||||
fill={fill}
|
|
||||||
class="bi bi-person-circle"
|
|
||||||
viewBox="0 0 16 16">
|
|
||||||
<title>{props.error.clone().unwrap_or(AttrValue::Static("Avatar"))}</title>
|
|
||||||
<path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z"/>
|
|
||||||
<path fill-rule="evenodd" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z"/>
|
|
||||||
</svg>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
use crate::components::{
|
|
||||||
avatar::Avatar,
|
|
||||||
logout::LogoutButton,
|
|
||||||
router::{AppRoute, Link},
|
|
||||||
};
|
|
||||||
use wasm_bindgen::prelude::wasm_bindgen;
|
|
||||||
use yew::{Callback, Properties, function_component, html};
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct Props {
|
|
||||||
pub is_admin: bool,
|
|
||||||
pub username: Option<String>,
|
|
||||||
pub on_logged_out: Callback<()>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(Banner)]
|
|
||||||
pub fn banner(props: &Props) -> Html {
|
|
||||||
html! {
|
|
||||||
<header class="p-2 mb-3 border-bottom">
|
|
||||||
<div class="container">
|
|
||||||
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
|
|
||||||
<a href={yew_router::utils::base_url().unwrap_or("/".to_string())} class="d-flex align-items-center mt-2 mb-lg-0 me-md-5 text-decoration-none">
|
|
||||||
<h2>{"LLDAP"}</h2>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
|
|
||||||
{if props.is_admin { html! {
|
|
||||||
<>
|
|
||||||
<li>
|
|
||||||
<Link
|
|
||||||
classes="nav-link px-2 h6"
|
|
||||||
to={AppRoute::ListUsers}>
|
|
||||||
<i class="bi-people me-2"></i>
|
|
||||||
{"Users"}
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<Link
|
|
||||||
classes="nav-link px-2 h6"
|
|
||||||
to={AppRoute::ListGroups}>
|
|
||||||
<i class="bi-collection me-2"></i>
|
|
||||||
{"Groups"}
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<Link
|
|
||||||
classes="nav-link px-2 h6"
|
|
||||||
to={AppRoute::ListUserSchema}>
|
|
||||||
<i class="bi-list-ul me-2"></i>
|
|
||||||
{"User schema"}
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<Link
|
|
||||||
classes="nav-link px-2 h6"
|
|
||||||
to={AppRoute::ListGroupSchema}>
|
|
||||||
<i class="bi-list-ul me-2"></i>
|
|
||||||
{"Group schema"}
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
</>
|
|
||||||
} } else { html!{} } }
|
|
||||||
</ul>
|
|
||||||
<UserMenu username={props.username.clone()} on_logged_out={props.on_logged_out.clone()}/>
|
|
||||||
<DarkModeToggle />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
struct UserMenuProps {
|
|
||||||
pub username: Option<String>,
|
|
||||||
pub on_logged_out: Callback<()>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(UserMenu)]
|
|
||||||
fn user_menu(props: &UserMenuProps) -> Html {
|
|
||||||
match &props.username {
|
|
||||||
Some(username) => html! {
|
|
||||||
<div class="dropdown text-end">
|
|
||||||
<a href="#"
|
|
||||||
class="d-block nav-link text-decoration-none dropdown-toggle"
|
|
||||||
id="dropdownUser"
|
|
||||||
data-bs-toggle="dropdown"
|
|
||||||
aria-expanded="false">
|
|
||||||
<Avatar user={username.clone()} />
|
|
||||||
<span class="ms-2">
|
|
||||||
{username}
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
<ul
|
|
||||||
class="dropdown-menu text-small dropdown-menu-lg-end"
|
|
||||||
aria-labelledby="dropdownUser1"
|
|
||||||
style="">
|
|
||||||
<li>
|
|
||||||
<Link
|
|
||||||
classes="dropdown-item"
|
|
||||||
to={AppRoute::UserDetails{ user_id: username.to_string() }}>
|
|
||||||
{"View details"}
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
<li><hr class="dropdown-divider" /></li>
|
|
||||||
<li>
|
|
||||||
<LogoutButton on_logged_out={props.on_logged_out.clone()} />
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
},
|
|
||||||
_ => html! {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
extern "C" {
|
|
||||||
#[wasm_bindgen(js_namespace = darkmode)]
|
|
||||||
fn toggleDarkMode(doSave: bool);
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
fn inDarkMode() -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(DarkModeToggle)]
|
|
||||||
fn dark_mode_toggle() -> Html {
|
|
||||||
html! {
|
|
||||||
<div class="form-check form-switch">
|
|
||||||
<input class="form-check-input" onclick={|_| toggleDarkMode(true)} type="checkbox" id="darkModeToggle" checked={inDarkMode()}/>
|
|
||||||
<label class="form-check-label" for="darkModeToggle">{"Dark mode"}</label>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::password_field::PasswordField,
|
||||||
form::{field::Field, submit::Submit},
|
components::router::{AppRoute, Link},
|
||||||
router::{AppRoute, Link},
|
|
||||||
},
|
|
||||||
infra::{
|
infra::{
|
||||||
api::HostService,
|
api::HostService,
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
common_component::{CommonComponent, CommonComponentParts},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{Result, anyhow, bail};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use gloo_console::error;
|
use gloo_console::error;
|
||||||
use lldap_auth::*;
|
use lldap_auth::*;
|
||||||
use validator_derive::Validate;
|
use validator_derive::Validate;
|
||||||
@@ -100,7 +98,7 @@ impl CommonComponent<ChangePasswordForm> for ChangePasswordForm {
|
|||||||
.context("Could not initialize login")?;
|
.context("Could not initialize login")?;
|
||||||
self.opaque_data = OpaqueData::Login(login_start_request.state);
|
self.opaque_data = OpaqueData::Login(login_start_request.state);
|
||||||
let req = login::ClientLoginStartRequest {
|
let req = login::ClientLoginStartRequest {
|
||||||
username: ctx.props().username.clone().into(),
|
username: ctx.props().username.clone(),
|
||||||
login_start_request: login_start_request.message,
|
login_start_request: login_start_request.message,
|
||||||
};
|
};
|
||||||
self.common.call_backend(
|
self.common.call_backend(
|
||||||
@@ -131,13 +129,11 @@ impl CommonComponent<ChangePasswordForm> for ChangePasswordForm {
|
|||||||
Msg::SubmitNewPassword => {
|
Msg::SubmitNewPassword => {
|
||||||
let mut rng = rand::rngs::OsRng;
|
let mut rng = rand::rngs::OsRng;
|
||||||
let new_password = self.form.model().password;
|
let new_password = self.form.model().password;
|
||||||
let registration_start_request = opaque::client::registration::start_registration(
|
let registration_start_request =
|
||||||
new_password.as_bytes(),
|
opaque::client::registration::start_registration(&new_password, &mut rng)
|
||||||
&mut rng,
|
.context("Could not initiate password change")?;
|
||||||
)
|
|
||||||
.context("Could not initiate password change")?;
|
|
||||||
let req = registration::ClientRegistrationStartRequest {
|
let req = registration::ClientRegistrationStartRequest {
|
||||||
username: ctx.props().username.clone().into(),
|
username: ctx.props().username.clone(),
|
||||||
registration_start_request: registration_start_request.message,
|
registration_start_request: registration_start_request.message,
|
||||||
};
|
};
|
||||||
self.opaque_data = OpaqueData::Registration(registration_start_request.state);
|
self.opaque_data = OpaqueData::Registration(registration_start_request.state);
|
||||||
@@ -210,6 +206,7 @@ impl Component for ChangePasswordForm {
|
|||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
fn view(&self, ctx: &Context<Self>) -> Html {
|
||||||
let is_admin = ctx.props().is_admin;
|
let is_admin = ctx.props().is_admin;
|
||||||
let link = ctx.link();
|
let link = ctx.link();
|
||||||
|
type Field = yew_form::Field<FormModel>;
|
||||||
html! {
|
html! {
|
||||||
<>
|
<>
|
||||||
<div class="mb-2 mt-2">
|
<div class="mb-2 mt-2">
|
||||||
@@ -226,44 +223,88 @@ impl Component for ChangePasswordForm {
|
|||||||
}
|
}
|
||||||
} else { html! {} }
|
} else { html! {} }
|
||||||
}
|
}
|
||||||
<form class="form">
|
<form
|
||||||
|
class="form">
|
||||||
{if !is_admin { html! {
|
{if !is_admin { html! {
|
||||||
<Field<FormModel>
|
<div class="form-group row">
|
||||||
form={&self.form}
|
<label for="old_password"
|
||||||
required=true
|
class="form-label col-sm-2 col-form-label">
|
||||||
label="Current password"
|
{"Current password*:"}
|
||||||
field_name="old_password"
|
</label>
|
||||||
input_type="password"
|
<div class="col-sm-10">
|
||||||
autocomplete="current-password"
|
<Field
|
||||||
oninput={link.callback(|_| Msg::FormUpdate)} />
|
form={&self.form}
|
||||||
|
field_name="old_password"
|
||||||
|
input_type="password"
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
autocomplete="current-password"
|
||||||
|
oninput={link.callback(|_| Msg::FormUpdate)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("old_password")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
}} else { html! {} }}
|
}} else { html! {} }}
|
||||||
<Field<FormModel>
|
<div class="form-group row mb-3">
|
||||||
form={&self.form}
|
<label for="new_password"
|
||||||
required=true
|
class="form-label col-sm-2 col-form-label">
|
||||||
label="New password"
|
{"New Password"}
|
||||||
field_name="password"
|
<span class="text-danger">{"*"}</span>
|
||||||
input_type="password"
|
{":"}
|
||||||
autocomplete="new-password"
|
</label>
|
||||||
oninput={link.callback(|_| Msg::FormUpdate)} />
|
<div class="col-sm-10">
|
||||||
<Field<FormModel>
|
<PasswordField<FormModel>
|
||||||
form={&self.form}
|
form={&self.form}
|
||||||
required=true
|
field_name="password"
|
||||||
label="Confirm password"
|
class="form-control"
|
||||||
field_name="confirm_password"
|
class_invalid="is-invalid has-error"
|
||||||
input_type="password"
|
class_valid="has-success"
|
||||||
autocomplete="new-password"
|
oninput={link.callback(|_| Msg::FormUpdate)} />
|
||||||
oninput={link.callback(|_| Msg::FormUpdate)} />
|
<div class="invalid-feedback">
|
||||||
<Submit
|
{&self.form.field_message("password")}
|
||||||
disabled={self.common.is_task_running()}
|
</div>
|
||||||
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::Submit})}
|
</div>
|
||||||
text="Save changes" >
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="confirm_password"
|
||||||
|
class="form-label col-sm-2 col-form-label">
|
||||||
|
{"Confirm Password"}
|
||||||
|
<span class="text-danger">{"*"}</span>
|
||||||
|
{":"}
|
||||||
|
</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<Field
|
||||||
|
form={&self.form}
|
||||||
|
field_name="confirm_password"
|
||||||
|
input_type="password"
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
autocomplete="new-password"
|
||||||
|
oninput={link.callback(|_| Msg::FormUpdate)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("confirm_password")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<button
|
||||||
|
class="btn btn-primary col-auto col-form-label"
|
||||||
|
type="submit"
|
||||||
|
disabled={self.common.is_task_running()}
|
||||||
|
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::Submit})}>
|
||||||
|
<i class="bi-save me-2"></i>
|
||||||
|
{"Save changes"}
|
||||||
|
</button>
|
||||||
<Link
|
<Link
|
||||||
classes="btn btn-secondary ms-2 col-auto col-form-label"
|
classes="btn btn-secondary ms-2 col-auto col-form-label"
|
||||||
to={AppRoute::UserDetails{user_id: ctx.props().username.clone()}}>
|
to={AppRoute::UserDetails{user_id: ctx.props().username.clone()}}>
|
||||||
<i class="bi-arrow-return-left me-2"></i>
|
<i class="bi-arrow-return-left me-2"></i>
|
||||||
{"Back"}
|
{"Back"}
|
||||||
</Link>
|
</Link>
|
||||||
</Submit>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::router::AppRoute,
|
||||||
form::{
|
infra::common_component::{CommonComponent, CommonComponentParts},
|
||||||
attribute_input::{ListAttributeInput, SingleAttributeInput},
|
|
||||||
field::Field,
|
|
||||||
submit::Submit,
|
|
||||||
},
|
|
||||||
router::AppRoute,
|
|
||||||
},
|
|
||||||
infra::{
|
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
form_utils::{
|
|
||||||
AttributeValue, EmailIsRequired, GraphQlAttributeSchema, IsAdmin,
|
|
||||||
read_all_form_attributes,
|
|
||||||
},
|
|
||||||
schema::AttributeType,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use anyhow::{Result, ensure};
|
use anyhow::{bail, Result};
|
||||||
use gloo_console::log;
|
use gloo_console::log;
|
||||||
use graphql_client::GraphQLQuery;
|
use graphql_client::GraphQLQuery;
|
||||||
use validator_derive::Validate;
|
use validator_derive::Validate;
|
||||||
@@ -24,32 +10,6 @@ use yew::prelude::*;
|
|||||||
use yew_form_derive::Model;
|
use yew_form_derive::Model;
|
||||||
use yew_router::{prelude::History, scope_ext::RouterScopeExt};
|
use yew_router::{prelude::History, scope_ext::RouterScopeExt};
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/get_group_attributes_schema.graphql",
|
|
||||||
response_derives = "Debug,Clone,PartialEq,Eq",
|
|
||||||
custom_scalars_module = "crate::infra::graphql",
|
|
||||||
extern_enums("AttributeType")
|
|
||||||
)]
|
|
||||||
pub struct GetGroupAttributesSchema;
|
|
||||||
|
|
||||||
use get_group_attributes_schema::ResponseData;
|
|
||||||
|
|
||||||
pub type Attribute =
|
|
||||||
get_group_attributes_schema::GetGroupAttributesSchemaSchemaGroupSchemaAttributes;
|
|
||||||
|
|
||||||
impl From<&Attribute> for GraphQlAttributeSchema {
|
|
||||||
fn from(attr: &Attribute) -> Self {
|
|
||||||
Self {
|
|
||||||
name: attr.name.clone(),
|
|
||||||
is_list: attr.is_list,
|
|
||||||
is_readonly: attr.is_readonly,
|
|
||||||
is_editable: false, // Need to be admin to edit it.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
#[derive(GraphQLQuery)]
|
||||||
#[graphql(
|
#[graphql(
|
||||||
schema_path = "../schema.graphql",
|
schema_path = "../schema.graphql",
|
||||||
@@ -62,8 +22,6 @@ pub struct CreateGroup;
|
|||||||
pub struct CreateGroupForm {
|
pub struct CreateGroupForm {
|
||||||
common: CommonComponentParts<Self>,
|
common: CommonComponentParts<Self>,
|
||||||
form: yew_form::Form<CreateGroupModel>,
|
form: yew_form::Form<CreateGroupModel>,
|
||||||
attributes_schema: Option<Vec<Attribute>>,
|
|
||||||
form_ref: NodeRef,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Model, Validate, PartialEq, Eq, Clone, Default)]
|
#[derive(Model, Validate, PartialEq, Eq, Clone, Default)]
|
||||||
@@ -74,7 +32,6 @@ pub struct CreateGroupModel {
|
|||||||
|
|
||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
Update,
|
Update,
|
||||||
ListAttributesResponse(Result<ResponseData>),
|
|
||||||
SubmitForm,
|
SubmitForm,
|
||||||
CreateGroupResponse(Result<create_group::ResponseData>),
|
CreateGroupResponse(Result<create_group::ResponseData>),
|
||||||
}
|
}
|
||||||
@@ -88,33 +45,12 @@ impl CommonComponent<CreateGroupForm> for CreateGroupForm {
|
|||||||
match msg {
|
match msg {
|
||||||
Msg::Update => Ok(true),
|
Msg::Update => Ok(true),
|
||||||
Msg::SubmitForm => {
|
Msg::SubmitForm => {
|
||||||
ensure!(self.form.validate(), "Check the form for errors");
|
if !self.form.validate() {
|
||||||
|
bail!("Check the form for errors");
|
||||||
let all_values = read_all_form_attributes(
|
}
|
||||||
self.attributes_schema.iter().flatten(),
|
|
||||||
&self.form_ref,
|
|
||||||
IsAdmin(true),
|
|
||||||
EmailIsRequired(false),
|
|
||||||
)?;
|
|
||||||
let attributes = Some(
|
|
||||||
all_values
|
|
||||||
.into_iter()
|
|
||||||
.filter(|a| !a.values.is_empty())
|
|
||||||
.map(
|
|
||||||
|AttributeValue { name, values }| create_group::AttributeValueInput {
|
|
||||||
name,
|
|
||||||
value: values,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let model = self.form.model();
|
let model = self.form.model();
|
||||||
let req = create_group::Variables {
|
let req = create_group::Variables {
|
||||||
group: create_group::CreateGroupInput {
|
name: model.groupname,
|
||||||
displayName: model.groupname,
|
|
||||||
attributes,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
self.common.call_graphql::<CreateGroup, _>(
|
self.common.call_graphql::<CreateGroup, _>(
|
||||||
ctx,
|
ctx,
|
||||||
@@ -127,16 +63,11 @@ impl CommonComponent<CreateGroupForm> for CreateGroupForm {
|
|||||||
Msg::CreateGroupResponse(response) => {
|
Msg::CreateGroupResponse(response) => {
|
||||||
log!(&format!(
|
log!(&format!(
|
||||||
"Created group '{}'",
|
"Created group '{}'",
|
||||||
&response?.create_group_with_details.display_name
|
&response?.create_group.display_name
|
||||||
));
|
));
|
||||||
ctx.link().history().unwrap().push(AppRoute::ListGroups);
|
ctx.link().history().unwrap().push(AppRoute::ListGroups);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
Msg::ListAttributesResponse(schema) => {
|
|
||||||
self.attributes_schema =
|
|
||||||
Some(schema?.schema.group_schema.attributes.into_iter().collect());
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,22 +80,11 @@ impl Component for CreateGroupForm {
|
|||||||
type Message = Msg;
|
type Message = Msg;
|
||||||
type Properties = ();
|
type Properties = ();
|
||||||
|
|
||||||
fn create(ctx: &Context<Self>) -> Self {
|
fn create(_: &Context<Self>) -> Self {
|
||||||
let mut component = Self {
|
Self {
|
||||||
common: CommonComponentParts::<Self>::create(),
|
common: CommonComponentParts::<Self>::create(),
|
||||||
form: yew_form::Form::<CreateGroupModel>::new(CreateGroupModel::default()),
|
form: yew_form::Form::<CreateGroupModel>::new(CreateGroupModel::default()),
|
||||||
attributes_schema: None,
|
}
|
||||||
form_ref: NodeRef::default(),
|
|
||||||
};
|
|
||||||
component
|
|
||||||
.common
|
|
||||||
.call_graphql::<GetGroupAttributesSchema, _>(
|
|
||||||
ctx,
|
|
||||||
get_group_attributes_schema::Variables {},
|
|
||||||
Msg::ListAttributesResponse,
|
|
||||||
"Error trying to fetch group schema",
|
|
||||||
);
|
|
||||||
component
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
||||||
@@ -173,30 +93,44 @@ impl Component for CreateGroupForm {
|
|||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
fn view(&self, ctx: &Context<Self>) -> Html {
|
||||||
let link = ctx.link();
|
let link = ctx.link();
|
||||||
|
type Field = yew_form::Field<CreateGroupModel>;
|
||||||
html! {
|
html! {
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<form class="form py-3" style="max-width: 636px"
|
<form class="form py-3" style="max-width: 636px">
|
||||||
ref={self.form_ref.clone()}>
|
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<h5 class="fw-bold">{"Create a group"}</h5>
|
<h5 class="fw-bold">{"Create a group"}</h5>
|
||||||
</div>
|
</div>
|
||||||
<Field<CreateGroupModel>
|
<div class="form-group row mb-3">
|
||||||
form={&self.form}
|
<label for="groupname"
|
||||||
required=true
|
class="form-label col-4 col-form-label">
|
||||||
label="Group name"
|
{"Group name"}
|
||||||
field_name="groupname"
|
<span class="text-danger">{"*"}</span>
|
||||||
oninput={link.callback(|_| Msg::Update)} />
|
{":"}
|
||||||
{
|
</label>
|
||||||
self.attributes_schema
|
<div class="col-8">
|
||||||
.iter()
|
<Field
|
||||||
.flatten()
|
form={&self.form}
|
||||||
.filter(|a| !a.is_readonly && a.name != "display_name")
|
field_name="groupname"
|
||||||
.map(get_custom_attribute_input)
|
class="form-control"
|
||||||
.collect::<Vec<_>>()
|
class_invalid="is-invalid has-error"
|
||||||
}
|
class_valid="has-success"
|
||||||
<Submit
|
autocomplete="groupname"
|
||||||
disabled={self.common.is_task_running()}
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::SubmitForm})} />
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("groupname")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<button
|
||||||
|
class="btn btn-primary col-auto col-form-label"
|
||||||
|
type="submit"
|
||||||
|
disabled={self.common.is_task_running()}
|
||||||
|
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::SubmitForm})}>
|
||||||
|
<i class="bi-save me-2"></i>
|
||||||
|
{"Submit"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{ if let Some(e) = &self.common.error {
|
{ if let Some(e) = &self.common.error {
|
||||||
html! {
|
html! {
|
||||||
@@ -210,21 +144,3 @@ impl Component for CreateGroupForm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_custom_attribute_input(attribute_schema: &Attribute) -> Html {
|
|
||||||
if attribute_schema.is_list {
|
|
||||||
html! {
|
|
||||||
<ListAttributeInput
|
|
||||||
name={attribute_schema.name.clone()}
|
|
||||||
attribute_type={attribute_schema.attribute_type}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
html! {
|
|
||||||
<SingleAttributeInput
|
|
||||||
name={attribute_schema.name.clone()}
|
|
||||||
attribute_type={attribute_schema.attribute_type}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,175 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
components::{
|
|
||||||
form::{checkbox::CheckBox, field::Field, select::Select, submit::Submit},
|
|
||||||
router::AppRoute,
|
|
||||||
},
|
|
||||||
infra::{
|
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
schema::{AttributeType, validate_attribute_type},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use anyhow::{Result, bail};
|
|
||||||
use gloo_console::log;
|
|
||||||
use graphql_client::GraphQLQuery;
|
|
||||||
use lldap_validation::attributes::validate_attribute_name;
|
|
||||||
use validator_derive::Validate;
|
|
||||||
use yew::prelude::*;
|
|
||||||
use yew_form_derive::Model;
|
|
||||||
use yew_router::{prelude::History, scope_ext::RouterScopeExt};
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/create_group_attribute.graphql",
|
|
||||||
response_derives = "Debug",
|
|
||||||
custom_scalars_module = "crate::infra::graphql",
|
|
||||||
extern_enums("AttributeType")
|
|
||||||
)]
|
|
||||||
pub struct CreateGroupAttribute;
|
|
||||||
|
|
||||||
pub struct CreateGroupAttributeForm {
|
|
||||||
common: CommonComponentParts<Self>,
|
|
||||||
form: yew_form::Form<CreateGroupAttributeModel>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Model, Validate, PartialEq, Eq, Clone, Default, Debug)]
|
|
||||||
pub struct CreateGroupAttributeModel {
|
|
||||||
#[validate(length(min = 1, message = "attribute_name is required"))]
|
|
||||||
attribute_name: String,
|
|
||||||
#[validate(custom = "validate_attribute_type")]
|
|
||||||
attribute_type: String,
|
|
||||||
is_list: bool,
|
|
||||||
is_visible: bool, // remove when backend doesn't return group attributes for normal users
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Msg {
|
|
||||||
Update,
|
|
||||||
SubmitForm,
|
|
||||||
CreateGroupAttributeResponse(Result<create_group_attribute::ResponseData>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommonComponent<CreateGroupAttributeForm> for CreateGroupAttributeForm {
|
|
||||||
fn handle_msg(
|
|
||||||
&mut self,
|
|
||||||
ctx: &Context<Self>,
|
|
||||||
msg: <Self as Component>::Message,
|
|
||||||
) -> Result<bool> {
|
|
||||||
match msg {
|
|
||||||
Msg::Update => Ok(true),
|
|
||||||
Msg::SubmitForm => {
|
|
||||||
if !self.form.validate() {
|
|
||||||
bail!("Check the form for errors");
|
|
||||||
}
|
|
||||||
let model = self.form.model();
|
|
||||||
validate_attribute_name(&model.attribute_name).or_else(|invalid_chars| {
|
|
||||||
let invalid = String::from_iter(invalid_chars);
|
|
||||||
bail!(
|
|
||||||
"Attribute name contains one or more invalid characters: {}",
|
|
||||||
invalid
|
|
||||||
);
|
|
||||||
})?;
|
|
||||||
let attribute_type =
|
|
||||||
AttributeType::try_from(model.attribute_type.as_str()).unwrap();
|
|
||||||
let req = create_group_attribute::Variables {
|
|
||||||
name: model.attribute_name,
|
|
||||||
attribute_type,
|
|
||||||
is_list: model.is_list,
|
|
||||||
is_visible: model.is_visible,
|
|
||||||
};
|
|
||||||
self.common.call_graphql::<CreateGroupAttribute, _>(
|
|
||||||
ctx,
|
|
||||||
req,
|
|
||||||
Msg::CreateGroupAttributeResponse,
|
|
||||||
"Error trying to create group attribute",
|
|
||||||
);
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
Msg::CreateGroupAttributeResponse(response) => {
|
|
||||||
response?;
|
|
||||||
let model = self.form.model();
|
|
||||||
log!(&format!(
|
|
||||||
"Created group attribute '{}'",
|
|
||||||
model.attribute_name
|
|
||||||
));
|
|
||||||
ctx.link()
|
|
||||||
.history()
|
|
||||||
.unwrap()
|
|
||||||
.push(AppRoute::ListGroupSchema);
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mut_common(&mut self) -> &mut CommonComponentParts<Self> {
|
|
||||||
&mut self.common
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for CreateGroupAttributeForm {
|
|
||||||
type Message = Msg;
|
|
||||||
type Properties = ();
|
|
||||||
|
|
||||||
fn create(_: &Context<Self>) -> Self {
|
|
||||||
let model = CreateGroupAttributeModel {
|
|
||||||
attribute_type: AttributeType::String.to_string(),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
Self {
|
|
||||||
common: CommonComponentParts::<Self>::create(),
|
|
||||||
form: yew_form::Form::<CreateGroupAttributeModel>::new(model),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
||||||
CommonComponentParts::<Self>::update(self, ctx, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let link = ctx.link();
|
|
||||||
html! {
|
|
||||||
<div class="row justify-content-center">
|
|
||||||
<form class="form py-3" style="max-width: 636px">
|
|
||||||
<h5 class="fw-bold">{"Create a group attribute"}</h5>
|
|
||||||
<Field<CreateGroupAttributeModel>
|
|
||||||
label="Name"
|
|
||||||
required={true}
|
|
||||||
form={&self.form}
|
|
||||||
field_name="attribute_name"
|
|
||||||
oninput={link.callback(|_| Msg::Update)} />
|
|
||||||
<Select<CreateGroupAttributeModel>
|
|
||||||
label="Type"
|
|
||||||
required={true}
|
|
||||||
form={&self.form}
|
|
||||||
field_name="attribute_type"
|
|
||||||
oninput={link.callback(|_| Msg::Update)}>
|
|
||||||
<option selected=true value="String">{"String"}</option>
|
|
||||||
<option value="Integer">{"Integer"}</option>
|
|
||||||
<option value="JpegPhoto">{"Jpeg"}</option>
|
|
||||||
<option value="DateTime">{"DateTime"}</option>
|
|
||||||
</Select<CreateGroupAttributeModel>>
|
|
||||||
<CheckBox<CreateGroupAttributeModel>
|
|
||||||
label="Multiple values"
|
|
||||||
form={&self.form}
|
|
||||||
field_name="is_list"
|
|
||||||
ontoggle={link.callback(|_| Msg::Update)} />
|
|
||||||
<CheckBox<CreateGroupAttributeModel>
|
|
||||||
label="Visible to users"
|
|
||||||
form={&self.form}
|
|
||||||
field_name="is_visible"
|
|
||||||
ontoggle={link.callback(|_| Msg::Update)} />
|
|
||||||
<Submit
|
|
||||||
disabled={self.common.is_task_running()}
|
|
||||||
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::SubmitForm})}/>
|
|
||||||
</form>
|
|
||||||
{ if let Some(e) = &self.common.error {
|
|
||||||
html! {
|
|
||||||
<div class="alert alert-danger">
|
|
||||||
{e.to_string() }
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
} else { html! {} }
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+175
-141
@@ -1,23 +1,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::router::AppRoute,
|
||||||
form::{
|
|
||||||
attribute_input::{ListAttributeInput, SingleAttributeInput},
|
|
||||||
field::Field,
|
|
||||||
submit::Submit,
|
|
||||||
},
|
|
||||||
router::AppRoute,
|
|
||||||
},
|
|
||||||
infra::{
|
infra::{
|
||||||
api::HostService,
|
api::HostService,
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
common_component::{CommonComponent, CommonComponentParts},
|
||||||
form_utils::{
|
|
||||||
AttributeValue, EmailIsRequired, GraphQlAttributeSchema, IsAdmin,
|
|
||||||
read_all_form_attributes,
|
|
||||||
},
|
|
||||||
schema::AttributeType,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{Result, ensure};
|
use anyhow::{bail, Result};
|
||||||
use gloo_console::log;
|
use gloo_console::log;
|
||||||
use graphql_client::GraphQLQuery;
|
use graphql_client::GraphQLQuery;
|
||||||
use lldap_auth::{opaque, registration};
|
use lldap_auth::{opaque, registration};
|
||||||
@@ -26,31 +14,6 @@ use yew::prelude::*;
|
|||||||
use yew_form_derive::Model;
|
use yew_form_derive::Model;
|
||||||
use yew_router::{prelude::History, scope_ext::RouterScopeExt};
|
use yew_router::{prelude::History, scope_ext::RouterScopeExt};
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/get_user_attributes_schema.graphql",
|
|
||||||
response_derives = "Debug,Clone,PartialEq,Eq",
|
|
||||||
custom_scalars_module = "crate::infra::graphql",
|
|
||||||
extern_enums("AttributeType")
|
|
||||||
)]
|
|
||||||
pub struct GetUserAttributesSchema;
|
|
||||||
|
|
||||||
use get_user_attributes_schema::ResponseData;
|
|
||||||
|
|
||||||
pub type Attribute = get_user_attributes_schema::GetUserAttributesSchemaSchemaUserSchemaAttributes;
|
|
||||||
|
|
||||||
impl From<&Attribute> for GraphQlAttributeSchema {
|
|
||||||
fn from(attr: &Attribute) -> Self {
|
|
||||||
Self {
|
|
||||||
name: attr.name.clone(),
|
|
||||||
is_list: attr.is_list,
|
|
||||||
is_readonly: attr.is_readonly,
|
|
||||||
is_editable: attr.is_editable,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
#[derive(GraphQLQuery)]
|
||||||
#[graphql(
|
#[graphql(
|
||||||
schema_path = "../schema.graphql",
|
schema_path = "../schema.graphql",
|
||||||
@@ -63,14 +26,17 @@ pub struct CreateUser;
|
|||||||
pub struct CreateUserForm {
|
pub struct CreateUserForm {
|
||||||
common: CommonComponentParts<Self>,
|
common: CommonComponentParts<Self>,
|
||||||
form: yew_form::Form<CreateUserModel>,
|
form: yew_form::Form<CreateUserModel>,
|
||||||
attributes_schema: Option<Vec<Attribute>>,
|
|
||||||
form_ref: NodeRef,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Model, Validate, PartialEq, Eq, Clone, Default)]
|
#[derive(Model, Validate, PartialEq, Eq, Clone, Default)]
|
||||||
pub struct CreateUserModel {
|
pub struct CreateUserModel {
|
||||||
#[validate(length(min = 1, message = "Username is required"))]
|
#[validate(length(min = 1, message = "Username is required"))]
|
||||||
username: String,
|
username: String,
|
||||||
|
#[validate(email(message = "A valid email is required"))]
|
||||||
|
email: String,
|
||||||
|
display_name: String,
|
||||||
|
first_name: String,
|
||||||
|
last_name: String,
|
||||||
#[validate(custom(
|
#[validate(custom(
|
||||||
function = "empty_or_long",
|
function = "empty_or_long",
|
||||||
message = "Password should be longer than 8 characters (or left empty)"
|
message = "Password should be longer than 8 characters (or left empty)"
|
||||||
@@ -90,7 +56,6 @@ fn empty_or_long(value: &str) -> Result<(), validator::ValidationError> {
|
|||||||
|
|
||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
Update,
|
Update,
|
||||||
ListAttributesResponse(Result<ResponseData>),
|
|
||||||
SubmitForm,
|
SubmitForm,
|
||||||
CreateUserResponse(Result<create_user::ResponseData>),
|
CreateUserResponse(Result<create_user::ResponseData>),
|
||||||
SuccessfulCreation,
|
SuccessfulCreation,
|
||||||
@@ -111,43 +76,20 @@ impl CommonComponent<CreateUserForm> for CreateUserForm {
|
|||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
match msg {
|
match msg {
|
||||||
Msg::Update => Ok(true),
|
Msg::Update => Ok(true),
|
||||||
Msg::ListAttributesResponse(schema) => {
|
|
||||||
self.attributes_schema =
|
|
||||||
Some(schema?.schema.user_schema.attributes.into_iter().collect());
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
Msg::SubmitForm => {
|
Msg::SubmitForm => {
|
||||||
ensure!(self.form.validate(), "Check the form for errors");
|
if !self.form.validate() {
|
||||||
|
bail!("Check the form for errors");
|
||||||
let all_values = read_all_form_attributes(
|
}
|
||||||
self.attributes_schema.iter().flatten(),
|
|
||||||
&self.form_ref,
|
|
||||||
IsAdmin(true),
|
|
||||||
EmailIsRequired(true),
|
|
||||||
)?;
|
|
||||||
let attributes = Some(
|
|
||||||
all_values
|
|
||||||
.into_iter()
|
|
||||||
.filter(|a| !a.values.is_empty())
|
|
||||||
.map(
|
|
||||||
|AttributeValue { name, values }| create_user::AttributeValueInput {
|
|
||||||
name,
|
|
||||||
value: values,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let model = self.form.model();
|
let model = self.form.model();
|
||||||
|
let to_option = |s: String| if s.is_empty() { None } else { Some(s) };
|
||||||
let req = create_user::Variables {
|
let req = create_user::Variables {
|
||||||
user: create_user::CreateUserInput {
|
user: create_user::CreateUserInput {
|
||||||
id: model.username,
|
id: model.username,
|
||||||
email: None,
|
email: model.email,
|
||||||
displayName: None,
|
displayName: to_option(model.display_name),
|
||||||
firstName: None,
|
firstName: to_option(model.first_name),
|
||||||
lastName: None,
|
lastName: to_option(model.last_name),
|
||||||
avatar: None,
|
avatar: None,
|
||||||
attributes,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
self.common.call_graphql::<CreateUser, _>(
|
self.common.call_graphql::<CreateUser, _>(
|
||||||
@@ -175,12 +117,9 @@ impl CommonComponent<CreateUserForm> for CreateUserForm {
|
|||||||
let opaque::client::registration::ClientRegistrationStartResult {
|
let opaque::client::registration::ClientRegistrationStartResult {
|
||||||
state,
|
state,
|
||||||
message,
|
message,
|
||||||
} = opaque::client::registration::start_registration(
|
} = opaque::client::registration::start_registration(&password, &mut rng)?;
|
||||||
password.as_bytes(),
|
|
||||||
&mut rng,
|
|
||||||
)?;
|
|
||||||
let req = registration::ClientRegistrationStartRequest {
|
let req = registration::ClientRegistrationStartRequest {
|
||||||
username: user_id.into(),
|
username: user_id,
|
||||||
registration_start_request: message,
|
registration_start_request: message,
|
||||||
};
|
};
|
||||||
self.common
|
self.common
|
||||||
@@ -231,20 +170,11 @@ impl Component for CreateUserForm {
|
|||||||
type Message = Msg;
|
type Message = Msg;
|
||||||
type Properties = ();
|
type Properties = ();
|
||||||
|
|
||||||
fn create(ctx: &Context<Self>) -> Self {
|
fn create(_: &Context<Self>) -> Self {
|
||||||
let mut component = Self {
|
Self {
|
||||||
common: CommonComponentParts::<Self>::create(),
|
common: CommonComponentParts::<Self>::create(),
|
||||||
form: yew_form::Form::<CreateUserModel>::new(CreateUserModel::default()),
|
form: yew_form::Form::<CreateUserModel>::new(CreateUserModel::default()),
|
||||||
attributes_schema: None,
|
}
|
||||||
form_ref: NodeRef::default(),
|
|
||||||
};
|
|
||||||
component.common.call_graphql::<GetUserAttributesSchema, _>(
|
|
||||||
ctx,
|
|
||||||
get_user_attributes_schema::Variables {},
|
|
||||||
Msg::ListAttributesResponse,
|
|
||||||
"Error trying to fetch user schema",
|
|
||||||
);
|
|
||||||
component
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
||||||
@@ -253,41 +183,163 @@ impl Component for CreateUserForm {
|
|||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
fn view(&self, ctx: &Context<Self>) -> Html {
|
||||||
let link = &ctx.link();
|
let link = &ctx.link();
|
||||||
|
type Field = yew_form::Field<CreateUserModel>;
|
||||||
html! {
|
html! {
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<form class="form py-3"
|
<form class="form py-3" style="max-width: 636px">
|
||||||
ref={self.form_ref.clone()}>
|
<div class="row mb-3">
|
||||||
<Field<CreateUserModel>
|
<h5 class="fw-bold">{"Create a user"}</h5>
|
||||||
form={&self.form}
|
</div>
|
||||||
required=true
|
<div class="form-group row mb-3">
|
||||||
label="User name"
|
<label for="username"
|
||||||
field_name="username"
|
class="form-label col-4 col-form-label">
|
||||||
oninput={link.callback(|_| Msg::Update)} />
|
{"User name"}
|
||||||
{
|
<span class="text-danger">{"*"}</span>
|
||||||
self.attributes_schema
|
{":"}
|
||||||
.iter()
|
</label>
|
||||||
.flatten()
|
<div class="col-8">
|
||||||
.filter(|a| !a.is_readonly)
|
<Field
|
||||||
.map(get_custom_attribute_input)
|
form={&self.form}
|
||||||
.collect::<Vec<_>>()
|
field_name="username"
|
||||||
}
|
class="form-control"
|
||||||
<Field<CreateUserModel>
|
class_invalid="is-invalid has-error"
|
||||||
form={&self.form}
|
class_valid="has-success"
|
||||||
label="Password"
|
autocomplete="username"
|
||||||
field_name="password"
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
input_type="password"
|
<div class="invalid-feedback">
|
||||||
autocomplete="new-password"
|
{&self.form.field_message("username")}
|
||||||
oninput={link.callback(|_| Msg::Update)} />
|
</div>
|
||||||
<Field<CreateUserModel>
|
</div>
|
||||||
form={&self.form}
|
</div>
|
||||||
label="Confirm password"
|
<div class="form-group row mb-3">
|
||||||
field_name="confirm_password"
|
<label for="email"
|
||||||
input_type="password"
|
class="form-label col-4 col-form-label">
|
||||||
autocomplete="new-password"
|
{"Email"}
|
||||||
oninput={link.callback(|_| Msg::Update)} />
|
<span class="text-danger">{"*"}</span>
|
||||||
<Submit
|
{":"}
|
||||||
disabled={self.common.is_task_running()}
|
</label>
|
||||||
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::SubmitForm})} />
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
form={&self.form}
|
||||||
|
input_type="email"
|
||||||
|
field_name="email"
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
autocomplete="email"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("email")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="display-name"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"Display name:"}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
form={&self.form}
|
||||||
|
autocomplete="name"
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
field_name="display_name"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("display_name")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="first-name"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"First name:"}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
form={&self.form}
|
||||||
|
autocomplete="given-name"
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
field_name="first_name"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("first_name")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="last-name"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"Last name:"}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
form={&self.form}
|
||||||
|
autocomplete="family-name"
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
field_name="last_name"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("last_name")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="password"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"Password:"}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
form={&self.form}
|
||||||
|
input_type="password"
|
||||||
|
field_name="password"
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
autocomplete="new-password"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("password")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="confirm_password"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"Confirm password:"}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
form={&self.form}
|
||||||
|
input_type="password"
|
||||||
|
field_name="confirm_password"
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
autocomplete="new-password"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("confirm_password")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<button
|
||||||
|
class="btn btn-primary col-auto col-form-label mt-4"
|
||||||
|
disabled={self.common.is_task_running()}
|
||||||
|
type="submit"
|
||||||
|
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::SubmitForm})}>
|
||||||
|
<i class="bi-save me-2"></i>
|
||||||
|
{"Submit"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{
|
{
|
||||||
if let Some(e) = &self.common.error {
|
if let Some(e) = &self.common.error {
|
||||||
@@ -302,21 +354,3 @@ impl Component for CreateUserForm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_custom_attribute_input(attribute_schema: &Attribute) -> Html {
|
|
||||||
if attribute_schema.is_list {
|
|
||||||
html! {
|
|
||||||
<ListAttributeInput
|
|
||||||
name={attribute_schema.name.clone()}
|
|
||||||
attribute_type={attribute_schema.attribute_type}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
html! {
|
|
||||||
<SingleAttributeInput
|
|
||||||
name={attribute_schema.name.clone()}
|
|
||||||
attribute_type={attribute_schema.attribute_type}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,182 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
components::{
|
|
||||||
form::{checkbox::CheckBox, field::Field, select::Select, submit::Submit},
|
|
||||||
router::AppRoute,
|
|
||||||
},
|
|
||||||
infra::{
|
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
schema::{AttributeType, validate_attribute_type},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use anyhow::{Result, bail};
|
|
||||||
use gloo_console::log;
|
|
||||||
use graphql_client::GraphQLQuery;
|
|
||||||
use lldap_validation::attributes::validate_attribute_name;
|
|
||||||
use validator_derive::Validate;
|
|
||||||
use yew::prelude::*;
|
|
||||||
use yew_form_derive::Model;
|
|
||||||
use yew_router::{prelude::History, scope_ext::RouterScopeExt};
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/create_user_attribute.graphql",
|
|
||||||
response_derives = "Debug",
|
|
||||||
custom_scalars_module = "crate::infra::graphql",
|
|
||||||
extern_enums("AttributeType")
|
|
||||||
)]
|
|
||||||
pub struct CreateUserAttribute;
|
|
||||||
|
|
||||||
pub struct CreateUserAttributeForm {
|
|
||||||
common: CommonComponentParts<Self>,
|
|
||||||
form: yew_form::Form<CreateUserAttributeModel>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Model, Validate, PartialEq, Eq, Clone, Default, Debug)]
|
|
||||||
pub struct CreateUserAttributeModel {
|
|
||||||
#[validate(length(min = 1, message = "attribute_name is required"))]
|
|
||||||
attribute_name: String,
|
|
||||||
#[validate(custom = "validate_attribute_type")]
|
|
||||||
attribute_type: String,
|
|
||||||
is_editable: bool,
|
|
||||||
is_list: bool,
|
|
||||||
is_visible: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Msg {
|
|
||||||
Update,
|
|
||||||
SubmitForm,
|
|
||||||
CreateUserAttributeResponse(Result<create_user_attribute::ResponseData>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommonComponent<CreateUserAttributeForm> for CreateUserAttributeForm {
|
|
||||||
fn handle_msg(
|
|
||||||
&mut self,
|
|
||||||
ctx: &Context<Self>,
|
|
||||||
msg: <Self as Component>::Message,
|
|
||||||
) -> Result<bool> {
|
|
||||||
match msg {
|
|
||||||
Msg::Update => Ok(true),
|
|
||||||
Msg::SubmitForm => {
|
|
||||||
if !self.form.validate() {
|
|
||||||
bail!("Check the form for errors");
|
|
||||||
}
|
|
||||||
let model = self.form.model();
|
|
||||||
if model.is_editable && !model.is_visible {
|
|
||||||
bail!("Editable attributes must also be visible");
|
|
||||||
}
|
|
||||||
validate_attribute_name(&model.attribute_name).or_else(|invalid_chars| {
|
|
||||||
let invalid = String::from_iter(invalid_chars);
|
|
||||||
bail!(
|
|
||||||
"Attribute name contains one or more invalid characters: {}",
|
|
||||||
invalid
|
|
||||||
);
|
|
||||||
})?;
|
|
||||||
let attribute_type =
|
|
||||||
AttributeType::try_from(model.attribute_type.as_str()).unwrap();
|
|
||||||
let req = create_user_attribute::Variables {
|
|
||||||
name: model.attribute_name,
|
|
||||||
attribute_type,
|
|
||||||
is_editable: model.is_editable,
|
|
||||||
is_list: model.is_list,
|
|
||||||
is_visible: model.is_visible,
|
|
||||||
};
|
|
||||||
self.common.call_graphql::<CreateUserAttribute, _>(
|
|
||||||
ctx,
|
|
||||||
req,
|
|
||||||
Msg::CreateUserAttributeResponse,
|
|
||||||
"Error trying to create user attribute",
|
|
||||||
);
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
Msg::CreateUserAttributeResponse(response) => {
|
|
||||||
response?;
|
|
||||||
let model = self.form.model();
|
|
||||||
log!(&format!(
|
|
||||||
"Created user attribute '{}'",
|
|
||||||
model.attribute_name
|
|
||||||
));
|
|
||||||
ctx.link().history().unwrap().push(AppRoute::ListUserSchema);
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mut_common(&mut self) -> &mut CommonComponentParts<Self> {
|
|
||||||
&mut self.common
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for CreateUserAttributeForm {
|
|
||||||
type Message = Msg;
|
|
||||||
type Properties = ();
|
|
||||||
|
|
||||||
fn create(_: &Context<Self>) -> Self {
|
|
||||||
let model = CreateUserAttributeModel {
|
|
||||||
attribute_type: AttributeType::String.to_string(),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
Self {
|
|
||||||
common: CommonComponentParts::<Self>::create(),
|
|
||||||
form: yew_form::Form::<CreateUserAttributeModel>::new(model),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
||||||
CommonComponentParts::<Self>::update(self, ctx, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let link = ctx.link();
|
|
||||||
html! {
|
|
||||||
<div class="row justify-content-center">
|
|
||||||
<form class="form py-3" style="max-width: 636px">
|
|
||||||
<h5 class="fw-bold">{"Create a user attribute"}</h5>
|
|
||||||
<Field<CreateUserAttributeModel>
|
|
||||||
label="Name"
|
|
||||||
required={true}
|
|
||||||
form={&self.form}
|
|
||||||
field_name="attribute_name"
|
|
||||||
oninput={link.callback(|_| Msg::Update)} />
|
|
||||||
<Select<CreateUserAttributeModel>
|
|
||||||
label="Type"
|
|
||||||
required={true}
|
|
||||||
form={&self.form}
|
|
||||||
field_name="attribute_type"
|
|
||||||
oninput={link.callback(|_| Msg::Update)}>
|
|
||||||
<option selected=true value="String">{"String"}</option>
|
|
||||||
<option value="Integer">{"Integer"}</option>
|
|
||||||
<option value="JpegPhoto">{"Jpeg"}</option>
|
|
||||||
<option value="DateTime">{"DateTime"}</option>
|
|
||||||
</Select<CreateUserAttributeModel>>
|
|
||||||
<CheckBox<CreateUserAttributeModel>
|
|
||||||
label="Multiple values"
|
|
||||||
form={&self.form}
|
|
||||||
field_name="is_list"
|
|
||||||
ontoggle={link.callback(|_| Msg::Update)} />
|
|
||||||
<CheckBox<CreateUserAttributeModel>
|
|
||||||
label="Visible to users"
|
|
||||||
form={&self.form}
|
|
||||||
field_name="is_visible"
|
|
||||||
ontoggle={link.callback(|_| Msg::Update)} />
|
|
||||||
<CheckBox<CreateUserAttributeModel>
|
|
||||||
label="Editable by users"
|
|
||||||
form={&self.form}
|
|
||||||
field_name="is_editable"
|
|
||||||
ontoggle={link.callback(|_| Msg::Update)} />
|
|
||||||
<Submit
|
|
||||||
disabled={self.common.is_task_running()}
|
|
||||||
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::SubmitForm})}/>
|
|
||||||
</form>
|
|
||||||
{ if let Some(e) = &self.common.error {
|
|
||||||
html! {
|
|
||||||
<div class="alert alert-danger">
|
|
||||||
{e.to_string() }
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
} else { html! {} }
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
use crate::infra::{
|
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
modal::Modal,
|
|
||||||
};
|
|
||||||
use anyhow::{Error, Result};
|
|
||||||
use graphql_client::GraphQLQuery;
|
|
||||||
use yew::prelude::*;
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/delete_group_attribute.graphql",
|
|
||||||
response_derives = "Debug",
|
|
||||||
custom_scalars_module = "crate::infra::graphql"
|
|
||||||
)]
|
|
||||||
pub struct DeleteGroupAttributeQuery;
|
|
||||||
|
|
||||||
pub struct DeleteGroupAttribute {
|
|
||||||
common: CommonComponentParts<Self>,
|
|
||||||
node_ref: NodeRef,
|
|
||||||
modal: Option<Modal>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(yew::Properties, Clone, PartialEq, Debug)]
|
|
||||||
pub struct DeleteGroupAttributeProps {
|
|
||||||
pub attribute_name: String,
|
|
||||||
pub on_attribute_deleted: Callback<String>,
|
|
||||||
pub on_error: Callback<Error>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Msg {
|
|
||||||
ClickedDeleteGroupAttribute,
|
|
||||||
ConfirmDeleteGroupAttribute,
|
|
||||||
DismissModal,
|
|
||||||
DeleteGroupAttributeResponse(Result<delete_group_attribute_query::ResponseData>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommonComponent<DeleteGroupAttribute> for DeleteGroupAttribute {
|
|
||||||
fn handle_msg(
|
|
||||||
&mut self,
|
|
||||||
ctx: &Context<Self>,
|
|
||||||
msg: <Self as Component>::Message,
|
|
||||||
) -> Result<bool> {
|
|
||||||
match msg {
|
|
||||||
Msg::ClickedDeleteGroupAttribute => {
|
|
||||||
self.modal.as_ref().expect("modal not initialized").show();
|
|
||||||
}
|
|
||||||
Msg::ConfirmDeleteGroupAttribute => {
|
|
||||||
self.update(ctx, Msg::DismissModal);
|
|
||||||
self.common.call_graphql::<DeleteGroupAttributeQuery, _>(
|
|
||||||
ctx,
|
|
||||||
delete_group_attribute_query::Variables {
|
|
||||||
name: ctx.props().attribute_name.clone(),
|
|
||||||
},
|
|
||||||
Msg::DeleteGroupAttributeResponse,
|
|
||||||
"Error trying to delete group attribute",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Msg::DismissModal => {
|
|
||||||
self.modal.as_ref().expect("modal not initialized").hide();
|
|
||||||
}
|
|
||||||
Msg::DeleteGroupAttributeResponse(response) => {
|
|
||||||
response?;
|
|
||||||
ctx.props()
|
|
||||||
.on_attribute_deleted
|
|
||||||
.emit(ctx.props().attribute_name.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mut_common(&mut self) -> &mut CommonComponentParts<Self> {
|
|
||||||
&mut self.common
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for DeleteGroupAttribute {
|
|
||||||
type Message = Msg;
|
|
||||||
type Properties = DeleteGroupAttributeProps;
|
|
||||||
|
|
||||||
fn create(_: &Context<Self>) -> Self {
|
|
||||||
Self {
|
|
||||||
common: CommonComponentParts::<Self>::create(),
|
|
||||||
node_ref: NodeRef::default(),
|
|
||||||
modal: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rendered(&mut self, _: &Context<Self>, first_render: bool) {
|
|
||||||
if first_render {
|
|
||||||
self.modal = Some(Modal::new(
|
|
||||||
self.node_ref
|
|
||||||
.cast::<web_sys::Element>()
|
|
||||||
.expect("Modal node is not an element"),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
||||||
CommonComponentParts::<Self>::update_and_report_error(
|
|
||||||
self,
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
ctx.props().on_error.clone(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let link = &ctx.link();
|
|
||||||
html! {
|
|
||||||
<>
|
|
||||||
<button
|
|
||||||
class="btn btn-danger"
|
|
||||||
disabled={self.common.is_task_running()}
|
|
||||||
onclick={link.callback(|_| Msg::ClickedDeleteGroupAttribute)}>
|
|
||||||
<i class="bi-x-circle-fill" aria-label="Delete attribute" />
|
|
||||||
</button>
|
|
||||||
{self.show_modal(ctx)}
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DeleteGroupAttribute {
|
|
||||||
fn show_modal(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let link = &ctx.link();
|
|
||||||
html! {
|
|
||||||
<div
|
|
||||||
class="modal fade"
|
|
||||||
id={"deleteGroupAttributeModal".to_string() + &ctx.props().attribute_name}
|
|
||||||
tabindex="-1"
|
|
||||||
aria-labelledby="deleteGroupAttributeModalLabel"
|
|
||||||
aria-hidden="true"
|
|
||||||
ref={self.node_ref.clone()}>
|
|
||||||
<div class="modal-dialog">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title" id="deleteGroupAttributeModalLabel">{"Delete group attribute?"}</h5>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn-close"
|
|
||||||
aria-label="Close"
|
|
||||||
onclick={link.callback(|_| Msg::DismissModal)} />
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<span>
|
|
||||||
{"Are you sure you want to delete group attribute "}
|
|
||||||
<b>{&ctx.props().attribute_name}</b>{"?"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn btn-secondary"
|
|
||||||
onclick={link.callback(|_| Msg::DismissModal)}>
|
|
||||||
<i class="bi-x-circle me-2"></i>
|
|
||||||
{"Cancel"}
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onclick={link.callback(|_| Msg::ConfirmDeleteGroupAttribute)}
|
|
||||||
class="btn btn-danger">
|
|
||||||
<i class="bi-check-circle me-2"></i>
|
|
||||||
{"Yes, I'm sure"}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
use crate::infra::{
|
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
modal::Modal,
|
|
||||||
};
|
|
||||||
use anyhow::{Error, Result};
|
|
||||||
use graphql_client::GraphQLQuery;
|
|
||||||
use yew::prelude::*;
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/delete_user_attribute.graphql",
|
|
||||||
response_derives = "Debug",
|
|
||||||
custom_scalars_module = "crate::infra::graphql"
|
|
||||||
)]
|
|
||||||
pub struct DeleteUserAttributeQuery;
|
|
||||||
|
|
||||||
pub struct DeleteUserAttribute {
|
|
||||||
common: CommonComponentParts<Self>,
|
|
||||||
node_ref: NodeRef,
|
|
||||||
modal: Option<Modal>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(yew::Properties, Clone, PartialEq, Debug)]
|
|
||||||
pub struct DeleteUserAttributeProps {
|
|
||||||
pub attribute_name: String,
|
|
||||||
pub on_attribute_deleted: Callback<String>,
|
|
||||||
pub on_error: Callback<Error>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Msg {
|
|
||||||
ClickedDeleteUserAttribute,
|
|
||||||
ConfirmDeleteUserAttribute,
|
|
||||||
DismissModal,
|
|
||||||
DeleteUserAttributeResponse(Result<delete_user_attribute_query::ResponseData>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommonComponent<DeleteUserAttribute> for DeleteUserAttribute {
|
|
||||||
fn handle_msg(
|
|
||||||
&mut self,
|
|
||||||
ctx: &Context<Self>,
|
|
||||||
msg: <Self as Component>::Message,
|
|
||||||
) -> Result<bool> {
|
|
||||||
match msg {
|
|
||||||
Msg::ClickedDeleteUserAttribute => {
|
|
||||||
self.modal.as_ref().expect("modal not initialized").show();
|
|
||||||
}
|
|
||||||
Msg::ConfirmDeleteUserAttribute => {
|
|
||||||
self.update(ctx, Msg::DismissModal);
|
|
||||||
self.common.call_graphql::<DeleteUserAttributeQuery, _>(
|
|
||||||
ctx,
|
|
||||||
delete_user_attribute_query::Variables {
|
|
||||||
name: ctx.props().attribute_name.clone(),
|
|
||||||
},
|
|
||||||
Msg::DeleteUserAttributeResponse,
|
|
||||||
"Error trying to delete user attribute",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Msg::DismissModal => {
|
|
||||||
self.modal.as_ref().expect("modal not initialized").hide();
|
|
||||||
}
|
|
||||||
Msg::DeleteUserAttributeResponse(response) => {
|
|
||||||
response?;
|
|
||||||
ctx.props()
|
|
||||||
.on_attribute_deleted
|
|
||||||
.emit(ctx.props().attribute_name.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mut_common(&mut self) -> &mut CommonComponentParts<Self> {
|
|
||||||
&mut self.common
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for DeleteUserAttribute {
|
|
||||||
type Message = Msg;
|
|
||||||
type Properties = DeleteUserAttributeProps;
|
|
||||||
|
|
||||||
fn create(_: &Context<Self>) -> Self {
|
|
||||||
Self {
|
|
||||||
common: CommonComponentParts::<Self>::create(),
|
|
||||||
node_ref: NodeRef::default(),
|
|
||||||
modal: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rendered(&mut self, _: &Context<Self>, first_render: bool) {
|
|
||||||
if first_render {
|
|
||||||
self.modal = Some(Modal::new(
|
|
||||||
self.node_ref
|
|
||||||
.cast::<web_sys::Element>()
|
|
||||||
.expect("Modal node is not an element"),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
||||||
CommonComponentParts::<Self>::update_and_report_error(
|
|
||||||
self,
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
ctx.props().on_error.clone(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let link = &ctx.link();
|
|
||||||
html! {
|
|
||||||
<>
|
|
||||||
<button
|
|
||||||
class="btn btn-danger"
|
|
||||||
disabled={self.common.is_task_running()}
|
|
||||||
onclick={link.callback(|_| Msg::ClickedDeleteUserAttribute)}>
|
|
||||||
<i class="bi-x-circle-fill" aria-label="Delete attribute" />
|
|
||||||
</button>
|
|
||||||
{self.show_modal(ctx)}
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DeleteUserAttribute {
|
|
||||||
fn show_modal(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let link = &ctx.link();
|
|
||||||
html! {
|
|
||||||
<div
|
|
||||||
class="modal fade"
|
|
||||||
id={"deleteUserAttributeModal".to_string() + &ctx.props().attribute_name}
|
|
||||||
tabindex="-1"
|
|
||||||
aria-labelledby="deleteUserAttributeModalLabel"
|
|
||||||
aria-hidden="true"
|
|
||||||
ref={self.node_ref.clone()}>
|
|
||||||
<div class="modal-dialog">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title" id="deleteUserAttributeModalLabel">{"Delete user attribute?"}</h5>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn-close"
|
|
||||||
aria-label="Close"
|
|
||||||
onclick={link.callback(|_| Msg::DismissModal)} />
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<span>
|
|
||||||
{"Are you sure you want to delete user attribute "}
|
|
||||||
<b>{&ctx.props().attribute_name}</b>{"?"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn btn-secondary"
|
|
||||||
onclick={link.callback(|_| Msg::DismissModal)}>
|
|
||||||
<i class="bi-x-circle me-2"></i>
|
|
||||||
{"Cancel"}
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onclick={link.callback(|_| Msg::ConfirmDeleteUserAttribute)}
|
|
||||||
class="btn btn-danger">
|
|
||||||
<i class="bi-check-circle me-2"></i>
|
|
||||||
{"Yes, I'm sure"}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
components::form::{date_input::DateTimeInput, file_input::JpegFileInput},
|
|
||||||
infra::{schema::AttributeType, tooltip::Tooltip},
|
|
||||||
};
|
|
||||||
use web_sys::Element;
|
|
||||||
use yew::{
|
|
||||||
Component, Context, Html, Properties, function_component, html, use_effect_with_deps,
|
|
||||||
use_node_ref, virtual_dom::AttrValue,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
struct AttributeInputProps {
|
|
||||||
name: AttrValue,
|
|
||||||
attribute_type: AttributeType,
|
|
||||||
#[prop_or(None)]
|
|
||||||
value: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(AttributeInput)]
|
|
||||||
fn attribute_input(props: &AttributeInputProps) -> Html {
|
|
||||||
let input_type = match props.attribute_type {
|
|
||||||
AttributeType::String => "text",
|
|
||||||
AttributeType::Integer => "number",
|
|
||||||
AttributeType::DateTime => {
|
|
||||||
return html! {
|
|
||||||
<DateTimeInput name={props.name.clone()} value={props.value.clone()} />
|
|
||||||
};
|
|
||||||
}
|
|
||||||
AttributeType::JpegPhoto => {
|
|
||||||
return html! {
|
|
||||||
<JpegFileInput name={props.name.clone()} value={props.value.clone()} />
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
html! {
|
|
||||||
<input
|
|
||||||
type={input_type}
|
|
||||||
name={props.name.clone()}
|
|
||||||
class="form-control"
|
|
||||||
value={props.value.clone()} />
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
struct AttributeLabelProps {
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
#[function_component(AttributeLabel)]
|
|
||||||
fn attribute_label(props: &AttributeLabelProps) -> Html {
|
|
||||||
let tooltip_ref = use_node_ref();
|
|
||||||
|
|
||||||
use_effect_with_deps(
|
|
||||||
move |tooltip_ref| {
|
|
||||||
Tooltip::new(
|
|
||||||
tooltip_ref
|
|
||||||
.cast::<Element>()
|
|
||||||
.expect("Tooltip element should exist"),
|
|
||||||
);
|
|
||||||
|| {}
|
|
||||||
},
|
|
||||||
tooltip_ref.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
html! {
|
|
||||||
<label for={props.name.clone()}
|
|
||||||
class="form-label col-4 col-form-label"
|
|
||||||
>
|
|
||||||
{props.name[0..1].to_uppercase() + &props.name[1..].replace('_', " ")}{":"}
|
|
||||||
<button
|
|
||||||
class="btn btn-sm btn-link"
|
|
||||||
type="button"
|
|
||||||
data-bs-placement="right"
|
|
||||||
title={props.name.clone()}
|
|
||||||
ref={tooltip_ref}>
|
|
||||||
<i class="bi bi-info-circle" aria-label="Info" />
|
|
||||||
</button>
|
|
||||||
</label>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct SingleAttributeInputProps {
|
|
||||||
pub name: String,
|
|
||||||
pub(crate) attribute_type: AttributeType,
|
|
||||||
#[prop_or(None)]
|
|
||||||
pub value: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(SingleAttributeInput)]
|
|
||||||
pub fn single_attribute_input(props: &SingleAttributeInputProps) -> Html {
|
|
||||||
html! {
|
|
||||||
<div class="row mb-3">
|
|
||||||
<AttributeLabel name={props.name.clone()} />
|
|
||||||
<div class="col-8">
|
|
||||||
<AttributeInput
|
|
||||||
attribute_type={props.attribute_type}
|
|
||||||
name={props.name.clone()}
|
|
||||||
value={props.value.clone()} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct ListAttributeInputProps {
|
|
||||||
pub name: String,
|
|
||||||
pub(crate) attribute_type: AttributeType,
|
|
||||||
#[prop_or(vec!())]
|
|
||||||
pub values: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum ListAttributeInputMsg {
|
|
||||||
Remove(usize),
|
|
||||||
Append,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ListAttributeInput {
|
|
||||||
indices: Vec<usize>,
|
|
||||||
next_index: usize,
|
|
||||||
values: Vec<String>,
|
|
||||||
}
|
|
||||||
impl Component for ListAttributeInput {
|
|
||||||
type Message = ListAttributeInputMsg;
|
|
||||||
type Properties = ListAttributeInputProps;
|
|
||||||
|
|
||||||
fn create(ctx: &Context<Self>) -> Self {
|
|
||||||
let values = ctx.props().values.clone();
|
|
||||||
Self {
|
|
||||||
indices: (0..values.len()).collect(),
|
|
||||||
next_index: values.len(),
|
|
||||||
values,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
||||||
match msg {
|
|
||||||
ListAttributeInputMsg::Remove(removed) => {
|
|
||||||
self.indices.retain_mut(|x| *x != removed);
|
|
||||||
}
|
|
||||||
ListAttributeInputMsg::Append => {
|
|
||||||
self.indices.push(self.next_index);
|
|
||||||
self.next_index += 1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn changed(&mut self, ctx: &Context<Self>) -> bool {
|
|
||||||
if ctx.props().values != self.values {
|
|
||||||
self.values.clone_from(&ctx.props().values);
|
|
||||||
self.indices = (0..self.values.len()).collect();
|
|
||||||
self.next_index = self.values.len();
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let props = &ctx.props();
|
|
||||||
let link = &ctx.link();
|
|
||||||
html! {
|
|
||||||
<div class="row mb-3">
|
|
||||||
<AttributeLabel name={props.name.clone()} />
|
|
||||||
<div class="col-8">
|
|
||||||
{self.indices.iter().map(|&i| html! {
|
|
||||||
<div class="input-group mb-2" key={i}>
|
|
||||||
<AttributeInput
|
|
||||||
attribute_type={props.attribute_type}
|
|
||||||
name={props.name.clone()}
|
|
||||||
value={props.values.get(i).cloned().unwrap_or_default()} />
|
|
||||||
<button
|
|
||||||
class="btn btn-danger"
|
|
||||||
type="button"
|
|
||||||
onclick={link.callback(move |_| ListAttributeInputMsg::Remove(i))}>
|
|
||||||
<i class="bi-x-circle-fill" aria-label="Remove value" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
}).collect::<Html>()}
|
|
||||||
<button
|
|
||||||
class="btn btn-secondary"
|
|
||||||
type="button"
|
|
||||||
onclick={link.callback(|_| ListAttributeInputMsg::Append)}>
|
|
||||||
<i class="bi-plus-circle me-2"></i>
|
|
||||||
{"Add value"}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
use yew::{Callback, Properties, function_component, html, virtual_dom::AttrValue};
|
|
||||||
use yew_form::{Form, Model};
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct Props<T: Model> {
|
|
||||||
pub label: AttrValue,
|
|
||||||
pub field_name: String,
|
|
||||||
pub form: Form<T>,
|
|
||||||
#[prop_or(false)]
|
|
||||||
pub required: bool,
|
|
||||||
#[prop_or_else(Callback::noop)]
|
|
||||||
pub ontoggle: Callback<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(CheckBox)]
|
|
||||||
pub fn checkbox<T: Model>(props: &Props<T>) -> Html {
|
|
||||||
html! {
|
|
||||||
<div class="form-group row mb-3">
|
|
||||||
<label for={props.field_name.clone()}
|
|
||||||
class="form-label col-4 col-form-label">
|
|
||||||
{&props.label}
|
|
||||||
{if props.required {
|
|
||||||
html!{<span class="text-danger">{"*"}</span>}
|
|
||||||
} else {html!{}}}
|
|
||||||
{":"}
|
|
||||||
</label>
|
|
||||||
<div class="col-8">
|
|
||||||
<yew_form::CheckBox<T>
|
|
||||||
form={&props.form}
|
|
||||||
field_name={props.field_name.clone()}
|
|
||||||
ontoggle={props.ontoggle.clone()} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
use web_sys::HtmlInputElement;
|
|
||||||
use yew::{Event, Properties, function_component, html, use_state, virtual_dom::AttrValue};
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct DateTimeInputProps {
|
|
||||||
pub name: AttrValue,
|
|
||||||
pub value: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(DateTimeInput)]
|
|
||||||
pub fn date_time_input(props: &DateTimeInputProps) -> Html {
|
|
||||||
let value = use_state(|| {
|
|
||||||
props
|
|
||||||
.value
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|x| DateTime::<Utc>::from_str(x).ok())
|
|
||||||
});
|
|
||||||
|
|
||||||
html! {
|
|
||||||
<div class="input-group">
|
|
||||||
<input
|
|
||||||
type="hidden"
|
|
||||||
name={props.name.clone()}
|
|
||||||
value={value.as_ref().map(|v: &DateTime<Utc>| v.to_rfc3339())} />
|
|
||||||
<input
|
|
||||||
type="datetime-local"
|
|
||||||
step="1"
|
|
||||||
class="form-control"
|
|
||||||
value={value.as_ref().map(|v: &DateTime<Utc>| v.naive_utc().to_string())}
|
|
||||||
onchange={move |e: Event| {
|
|
||||||
let string_val =
|
|
||||||
e.target()
|
|
||||||
.expect("Event should have target")
|
|
||||||
.unchecked_into::<HtmlInputElement>()
|
|
||||||
.value();
|
|
||||||
value.set(
|
|
||||||
NaiveDateTime::from_str(&string_val)
|
|
||||||
.ok()
|
|
||||||
.map(|x| DateTime::from_naive_utc_and_offset(x, Utc))
|
|
||||||
)
|
|
||||||
}} />
|
|
||||||
<span class="input-group-text">{"UTC"}</span>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
use yew::{Callback, InputEvent, Properties, function_component, html, virtual_dom::AttrValue};
|
|
||||||
use yew_form::{Form, Model};
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct Props<T: Model> {
|
|
||||||
pub label: AttrValue,
|
|
||||||
pub field_name: String,
|
|
||||||
pub form: Form<T>,
|
|
||||||
#[prop_or(false)]
|
|
||||||
pub required: bool,
|
|
||||||
#[prop_or(String::from("text"))]
|
|
||||||
pub input_type: String,
|
|
||||||
// If not present, will default to field_name
|
|
||||||
#[prop_or(None)]
|
|
||||||
pub autocomplete: Option<String>,
|
|
||||||
#[prop_or_else(Callback::noop)]
|
|
||||||
pub oninput: Callback<InputEvent>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(Field)]
|
|
||||||
pub fn field<T: Model>(props: &Props<T>) -> Html {
|
|
||||||
html! {
|
|
||||||
<div class="row mb-3">
|
|
||||||
<label for={props.field_name.clone()}
|
|
||||||
class="form-label col-4 col-form-label">
|
|
||||||
{&props.label}
|
|
||||||
{if props.required {
|
|
||||||
html!{<span class="text-danger">{"*"}</span>}
|
|
||||||
} else {html!{}}}
|
|
||||||
{":"}
|
|
||||||
</label>
|
|
||||||
<div class="col-8">
|
|
||||||
<yew_form::Field<T>
|
|
||||||
form={&props.form}
|
|
||||||
field_name={props.field_name.clone()}
|
|
||||||
input_type={props.input_type.clone()}
|
|
||||||
class="form-control"
|
|
||||||
class_invalid="is-invalid has-error"
|
|
||||||
class_valid="has-success"
|
|
||||||
autocomplete={props.autocomplete.clone().unwrap_or(props.field_name.clone())}
|
|
||||||
oninput={&props.oninput} />
|
|
||||||
<div class="invalid-feedback">
|
|
||||||
{&props.form.field_message(&props.field_name)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,238 +0,0 @@
|
|||||||
use std::{fmt::Display, str::FromStr};
|
|
||||||
|
|
||||||
use anyhow::{Error, Ok, Result, bail};
|
|
||||||
use gloo_file::{
|
|
||||||
File,
|
|
||||||
callbacks::{FileReader, read_as_bytes},
|
|
||||||
};
|
|
||||||
use web_sys::{FileList, HtmlInputElement, InputEvent};
|
|
||||||
use yew::Properties;
|
|
||||||
use yew::{prelude::*, virtual_dom::AttrValue};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct JsFile {
|
|
||||||
file: Option<File>,
|
|
||||||
contents: Option<Vec<u8>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for JsFile {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{}",
|
|
||||||
self.file.as_ref().map(File::name).unwrap_or_default()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for JsFile {
|
|
||||||
type Err = Error;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self> {
|
|
||||||
if s.is_empty() {
|
|
||||||
Ok(JsFile::default())
|
|
||||||
} else {
|
|
||||||
bail!("Building file from non-empty string")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_base64(file: &JsFile) -> Result<String> {
|
|
||||||
match file {
|
|
||||||
JsFile {
|
|
||||||
file: None,
|
|
||||||
contents: None,
|
|
||||||
} => Ok(String::new()),
|
|
||||||
JsFile {
|
|
||||||
file: Some(_),
|
|
||||||
contents: None,
|
|
||||||
} => bail!("Image file hasn't finished loading, try again"),
|
|
||||||
JsFile {
|
|
||||||
file: Some(_),
|
|
||||||
contents: Some(data),
|
|
||||||
} => {
|
|
||||||
if !is_valid_jpeg(data.as_slice()) {
|
|
||||||
bail!("Chosen image is not a valid JPEG");
|
|
||||||
}
|
|
||||||
Ok(base64::encode(data))
|
|
||||||
}
|
|
||||||
JsFile {
|
|
||||||
file: None,
|
|
||||||
contents: Some(data),
|
|
||||||
} => Ok(base64::encode(data)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A [yew::Component] to display the user details, with a form allowing to edit them.
|
|
||||||
pub struct JpegFileInput {
|
|
||||||
// None means that the avatar hasn't changed.
|
|
||||||
avatar: Option<JsFile>,
|
|
||||||
reader: Option<FileReader>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Msg {
|
|
||||||
Update,
|
|
||||||
/// A new file was selected.
|
|
||||||
FileSelected(File),
|
|
||||||
/// The "Clear" button for the avatar was clicked.
|
|
||||||
ClearClicked,
|
|
||||||
/// A picked file finished loading.
|
|
||||||
FileLoaded(String, Result<Vec<u8>>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, Clone, PartialEq, Eq)]
|
|
||||||
pub struct Props {
|
|
||||||
pub name: AttrValue,
|
|
||||||
pub value: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for JpegFileInput {
|
|
||||||
type Message = Msg;
|
|
||||||
type Properties = Props;
|
|
||||||
|
|
||||||
fn create(ctx: &Context<Self>) -> Self {
|
|
||||||
Self {
|
|
||||||
avatar: Some(JsFile {
|
|
||||||
file: None,
|
|
||||||
contents: ctx
|
|
||||||
.props()
|
|
||||||
.value
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|x| base64::decode(x).ok()),
|
|
||||||
}),
|
|
||||||
reader: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn changed(&mut self, ctx: &Context<Self>) -> bool {
|
|
||||||
self.avatar = Some(JsFile {
|
|
||||||
file: None,
|
|
||||||
contents: ctx
|
|
||||||
.props()
|
|
||||||
.value
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|x| base64::decode(x).ok()),
|
|
||||||
});
|
|
||||||
self.reader = None;
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
||||||
match msg {
|
|
||||||
Msg::Update => true,
|
|
||||||
Msg::FileSelected(new_avatar) => {
|
|
||||||
if self
|
|
||||||
.avatar
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|f| f.file.as_ref().map(|f| f.name()))
|
|
||||||
!= Some(new_avatar.name())
|
|
||||||
{
|
|
||||||
let file_name = new_avatar.name();
|
|
||||||
let link = ctx.link().clone();
|
|
||||||
self.reader = Some(read_as_bytes(&new_avatar, move |res| {
|
|
||||||
link.send_message(Msg::FileLoaded(
|
|
||||||
file_name,
|
|
||||||
res.map_err(|e| anyhow::anyhow!("{:#}", e)),
|
|
||||||
))
|
|
||||||
}));
|
|
||||||
self.avatar = Some(JsFile {
|
|
||||||
file: Some(new_avatar),
|
|
||||||
contents: None,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
Msg::ClearClicked => {
|
|
||||||
self.avatar = Some(JsFile::default());
|
|
||||||
true
|
|
||||||
}
|
|
||||||
Msg::FileLoaded(file_name, data) => {
|
|
||||||
if let Some(avatar) = &mut self.avatar {
|
|
||||||
if let Some(file) = &avatar.file {
|
|
||||||
if file.name() == file_name {
|
|
||||||
if let Result::Ok(data) = data {
|
|
||||||
if !is_valid_jpeg(data.as_slice()) {
|
|
||||||
// Clear the selection.
|
|
||||||
self.avatar = Some(JsFile::default());
|
|
||||||
// TODO: bail!("Chosen image is not a valid JPEG");
|
|
||||||
} else {
|
|
||||||
avatar.contents = Some(data);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.reader = None;
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let link = &ctx.link();
|
|
||||||
|
|
||||||
let avatar_string = match &self.avatar {
|
|
||||||
Some(avatar) => {
|
|
||||||
let avatar_base64 = to_base64(avatar);
|
|
||||||
avatar_base64.as_deref().unwrap_or("").to_owned()
|
|
||||||
}
|
|
||||||
None => String::new(),
|
|
||||||
};
|
|
||||||
html! {
|
|
||||||
<div class="row align-items-center">
|
|
||||||
<div class="col-5">
|
|
||||||
<input type="hidden" name={ctx.props().name.clone()} value={avatar_string.clone()} />
|
|
||||||
<input
|
|
||||||
class="form-control"
|
|
||||||
id="avatarInput"
|
|
||||||
type="file"
|
|
||||||
accept="image/jpeg"
|
|
||||||
oninput={link.callback(|e: InputEvent| {
|
|
||||||
let input: HtmlInputElement = e.target_unchecked_into();
|
|
||||||
Self::upload_files(input.files())
|
|
||||||
})} />
|
|
||||||
</div>
|
|
||||||
<div class="col-3">
|
|
||||||
<button
|
|
||||||
class="btn btn-secondary col-auto"
|
|
||||||
id="avatarClear"
|
|
||||||
type="button"
|
|
||||||
onclick={link.callback(|_| {Msg::ClearClicked})}>
|
|
||||||
{"Clear"}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="col-4">
|
|
||||||
{
|
|
||||||
if !avatar_string.is_empty() {
|
|
||||||
html!{
|
|
||||||
<img
|
|
||||||
id="avatarDisplay"
|
|
||||||
src={format!("data:image/jpeg;base64, {}", avatar_string)}
|
|
||||||
style="max-height:128px;max-width:128px;height:auto;width:auto;"
|
|
||||||
alt="Avatar" />
|
|
||||||
}
|
|
||||||
} else { html! {} }
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JpegFileInput {
|
|
||||||
fn upload_files(files: Option<FileList>) -> Msg {
|
|
||||||
match files {
|
|
||||||
Some(files) if files.length() > 0 => {
|
|
||||||
Msg::FileSelected(File::from(files.item(0).unwrap()))
|
|
||||||
}
|
|
||||||
Some(_) | None => Msg::Update,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_valid_jpeg(bytes: &[u8]) -> bool {
|
|
||||||
image::io::Reader::with_format(std::io::Cursor::new(bytes), image::ImageFormat::Jpeg)
|
|
||||||
.decode()
|
|
||||||
.is_ok()
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
pub mod attribute_input;
|
|
||||||
pub mod checkbox;
|
|
||||||
pub mod date_input;
|
|
||||||
pub mod field;
|
|
||||||
pub mod file_input;
|
|
||||||
pub mod select;
|
|
||||||
pub mod static_value;
|
|
||||||
pub mod submit;
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
use yew::{
|
|
||||||
Callback, Children, InputEvent, Properties, function_component, html, virtual_dom::AttrValue,
|
|
||||||
};
|
|
||||||
use yew_form::{Form, Model};
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct Props<T: Model> {
|
|
||||||
pub label: AttrValue,
|
|
||||||
pub field_name: String,
|
|
||||||
pub form: Form<T>,
|
|
||||||
#[prop_or(false)]
|
|
||||||
pub required: bool,
|
|
||||||
#[prop_or_else(Callback::noop)]
|
|
||||||
pub oninput: Callback<InputEvent>,
|
|
||||||
pub children: Children,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(Select)]
|
|
||||||
pub fn select<T: Model>(props: &Props<T>) -> Html {
|
|
||||||
html! {
|
|
||||||
<div class="row mb-3">
|
|
||||||
<label for={props.field_name.clone()}
|
|
||||||
class="form-label col-4 col-form-label">
|
|
||||||
{&props.label}
|
|
||||||
{if props.required {
|
|
||||||
html!{<span class="text-danger">{"*"}</span>}
|
|
||||||
} else {html!{}}}
|
|
||||||
{":"}
|
|
||||||
</label>
|
|
||||||
<div class="col-8">
|
|
||||||
<yew_form::Select<T>
|
|
||||||
form={&props.form}
|
|
||||||
class="form-control"
|
|
||||||
class_invalid="is-invalid has-error"
|
|
||||||
class_valid="has-success"
|
|
||||||
field_name={props.field_name.clone()}
|
|
||||||
oninput={&props.oninput} >
|
|
||||||
{for props.children.iter()}
|
|
||||||
</yew_form::Select<T>>
|
|
||||||
<div class="invalid-feedback">
|
|
||||||
{&props.form.field_message(&props.field_name)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
use yew::{Children, Properties, function_component, html, virtual_dom::AttrValue};
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct Props {
|
|
||||||
pub label: AttrValue,
|
|
||||||
pub id: AttrValue,
|
|
||||||
pub children: Children,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(StaticValue)]
|
|
||||||
pub fn static_value(props: &Props) -> Html {
|
|
||||||
html! {
|
|
||||||
<div class="row mb-3">
|
|
||||||
<label for={props.id.clone()}
|
|
||||||
class="form-label col-4 col-form-label">
|
|
||||||
{&props.label}
|
|
||||||
{":"}
|
|
||||||
</label>
|
|
||||||
<div class="col-8">
|
|
||||||
<span id={props.id.clone()} class="form-control-static">
|
|
||||||
{for props.children.iter()}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
use web_sys::MouseEvent;
|
|
||||||
use yew::{Callback, Children, Properties, function_component, html, virtual_dom::AttrValue};
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct Props {
|
|
||||||
pub disabled: bool,
|
|
||||||
pub onclick: Callback<MouseEvent>,
|
|
||||||
// Additional elements to insert after the button, in the same div
|
|
||||||
#[prop_or_default]
|
|
||||||
pub children: Children,
|
|
||||||
#[prop_or(AttrValue::from("Submit"))]
|
|
||||||
pub text: AttrValue,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(Submit)]
|
|
||||||
pub fn submit(props: &Props) -> Html {
|
|
||||||
html! {
|
|
||||||
<div class="form-group row justify-content-center">
|
|
||||||
<button
|
|
||||||
class="btn btn-primary col-auto col-form-label"
|
|
||||||
type="submit"
|
|
||||||
disabled={props.disabled}
|
|
||||||
onclick={&props.onclick}>
|
|
||||||
<i class="bi-save me-2"></i>
|
|
||||||
{props.text.clone()}
|
|
||||||
</button>
|
|
||||||
{for props.children.iter()}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
use crate::infra::attributes::AttributeDescription;
|
|
||||||
use lldap_validation::attributes::{ALLOWED_CHARACTERS_DESCRIPTION, validate_attribute_name};
|
|
||||||
use yew::{Html, html};
|
|
||||||
|
|
||||||
fn render_attribute_aliases(attribute_description: &AttributeDescription) -> Html {
|
|
||||||
if attribute_description.aliases.is_empty() {
|
|
||||||
html! {}
|
|
||||||
} else {
|
|
||||||
html! {
|
|
||||||
<>
|
|
||||||
<br/>
|
|
||||||
<small class="text-muted">
|
|
||||||
{"Aliases: "}
|
|
||||||
{attribute_description.aliases.join(", ")}
|
|
||||||
</small>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_attribute_validation_warnings(attribute_name: &str) -> Html {
|
|
||||||
match validate_attribute_name(attribute_name) {
|
|
||||||
Ok(()) => {
|
|
||||||
html! {}
|
|
||||||
}
|
|
||||||
Err(_invalid_chars) => {
|
|
||||||
html! {
|
|
||||||
<>
|
|
||||||
<br/>
|
|
||||||
<small class="text-warning">
|
|
||||||
{"Warning: This attribute uses one or more invalid characters "}
|
|
||||||
{"("}{ALLOWED_CHARACTERS_DESCRIPTION}{"). "}
|
|
||||||
{"Some clients may not support it."}
|
|
||||||
</small>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn render_attribute_name(
|
|
||||||
hardcoded: bool,
|
|
||||||
attribute_description: &AttributeDescription,
|
|
||||||
) -> Html {
|
|
||||||
html! {
|
|
||||||
<>
|
|
||||||
{&attribute_description.attribute_name}
|
|
||||||
{if hardcoded {render_attribute_aliases(attribute_description)} else {html!{}}}
|
|
||||||
{render_attribute_validation_warnings(attribute_description.attribute_name)}
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub mod attribute_schema;
|
|
||||||
@@ -1,17 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::{
|
||||||
add_group_member::{self, AddGroupMemberComponent},
|
add_group_member::{self, AddGroupMemberComponent},
|
||||||
group_details_form::GroupDetailsForm,
|
|
||||||
remove_user_from_group::RemoveUserFromGroupComponent,
|
remove_user_from_group::RemoveUserFromGroupComponent,
|
||||||
router::{AppRoute, Link},
|
router::{AppRoute, Link},
|
||||||
},
|
},
|
||||||
infra::{
|
infra::common_component::{CommonComponent, CommonComponentParts},
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
form_utils::GraphQlAttributeSchema,
|
|
||||||
schema::AttributeType,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use anyhow::{Error, Result, bail};
|
use anyhow::{bail, Error, Result};
|
||||||
use graphql_client::GraphQLQuery;
|
use graphql_client::GraphQLQuery;
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
|
||||||
@@ -20,33 +15,19 @@ use yew::prelude::*;
|
|||||||
schema_path = "../schema.graphql",
|
schema_path = "../schema.graphql",
|
||||||
query_path = "queries/get_group_details.graphql",
|
query_path = "queries/get_group_details.graphql",
|
||||||
response_derives = "Debug, Hash, PartialEq, Eq, Clone",
|
response_derives = "Debug, Hash, PartialEq, Eq, Clone",
|
||||||
custom_scalars_module = "crate::infra::graphql",
|
custom_scalars_module = "crate::infra::graphql"
|
||||||
extern_enums("AttributeType")
|
|
||||||
)]
|
)]
|
||||||
pub struct GetGroupDetails;
|
pub struct GetGroupDetails;
|
||||||
|
|
||||||
pub type Group = get_group_details::GetGroupDetailsGroup;
|
pub type Group = get_group_details::GetGroupDetailsGroup;
|
||||||
pub type User = get_group_details::GetGroupDetailsGroupUsers;
|
pub type User = get_group_details::GetGroupDetailsGroupUsers;
|
||||||
pub type AddGroupMemberUser = add_group_member::User;
|
pub type AddGroupMemberUser = add_group_member::User;
|
||||||
pub type Attribute = get_group_details::GetGroupDetailsGroupAttributes;
|
|
||||||
pub type AttributeSchema = get_group_details::GetGroupDetailsSchemaGroupSchemaAttributes;
|
|
||||||
|
|
||||||
impl From<&AttributeSchema> for GraphQlAttributeSchema {
|
|
||||||
fn from(attr: &AttributeSchema) -> Self {
|
|
||||||
Self {
|
|
||||||
name: attr.name.clone(),
|
|
||||||
is_list: attr.is_list,
|
|
||||||
is_readonly: attr.is_readonly,
|
|
||||||
is_editable: attr.is_editable,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GroupDetails {
|
pub struct GroupDetails {
|
||||||
common: CommonComponentParts<Self>,
|
common: CommonComponentParts<Self>,
|
||||||
/// The group info. If none, the error is in `error`. If `error` is None, then we haven't
|
/// The group info. If none, the error is in `error`. If `error` is None, then we haven't
|
||||||
/// received the server response yet.
|
/// received the server response yet.
|
||||||
group_and_schema: Option<(Group, Vec<AttributeSchema>)>,
|
group: Option<Group>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// State machine describing the possible transitions of the component state.
|
/// State machine describing the possible transitions of the component state.
|
||||||
@@ -57,13 +38,11 @@ pub enum Msg {
|
|||||||
OnError(Error),
|
OnError(Error),
|
||||||
OnUserAddedToGroup(AddGroupMemberUser),
|
OnUserAddedToGroup(AddGroupMemberUser),
|
||||||
OnUserRemovedFromGroup((String, i64)),
|
OnUserRemovedFromGroup((String, i64)),
|
||||||
DisplayNameUpdated,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(yew::Properties, Clone, PartialEq, Eq)]
|
#[derive(yew::Properties, Clone, PartialEq, Eq)]
|
||||||
pub struct Props {
|
pub struct Props {
|
||||||
pub group_id: i64,
|
pub group_id: i64,
|
||||||
pub is_admin: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GroupDetails {
|
impl GroupDetails {
|
||||||
@@ -90,16 +69,41 @@ impl GroupDetails {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_details(&self, ctx: &Context<Self>, g: &Group, schema: Vec<AttributeSchema>) -> Html {
|
fn view_details(&self, g: &Group) -> Html {
|
||||||
html! {
|
html! {
|
||||||
<>
|
<>
|
||||||
<h3>{g.display_name.to_string()}</h3>
|
<h3>{g.display_name.to_string()}</h3>
|
||||||
<GroupDetailsForm
|
<div class="py-3">
|
||||||
group={g.clone()}
|
<form class="form">
|
||||||
group_attributes_schema={schema}
|
<div class="form-group row mb-3">
|
||||||
is_admin={ctx.props().is_admin}
|
<label for="displayName"
|
||||||
on_display_name_updated={ctx.link().callback(|_| Msg::DisplayNameUpdated)}
|
class="form-label col-4 col-form-label">
|
||||||
/>
|
{"Group: "}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<span id="groupId" class="form-constrol-static">{g.display_name.to_string()}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="creationDate"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"Creation date: "}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<span id="creationDate" class="form-constrol-static">{g.creation_date.naive_local().date()}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="uuid"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"UUID: "}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<span id="uuid" class="form-constrol-static">{g.uuid.to_string()}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,38 +182,29 @@ impl GroupDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CommonComponent<GroupDetails> for GroupDetails {
|
impl CommonComponent<GroupDetails> for GroupDetails {
|
||||||
fn handle_msg(
|
fn handle_msg(&mut self, _: &Context<Self>, msg: <Self as Component>::Message) -> Result<bool> {
|
||||||
&mut self,
|
|
||||||
ctx: &Context<Self>,
|
|
||||||
msg: <Self as Component>::Message,
|
|
||||||
) -> Result<bool> {
|
|
||||||
match msg {
|
match msg {
|
||||||
Msg::GroupDetailsResponse(response) => match response {
|
Msg::GroupDetailsResponse(response) => match response {
|
||||||
Ok(group) => {
|
Ok(group) => self.group = Some(group.group),
|
||||||
self.group_and_schema =
|
|
||||||
Some((group.group, group.schema.group_schema.attributes))
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.group_and_schema = None;
|
self.group = None;
|
||||||
bail!("Error getting user details: {}", e);
|
bail!("Error getting user details: {}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Msg::OnError(e) => return Err(e),
|
Msg::OnError(e) => return Err(e),
|
||||||
Msg::OnUserAddedToGroup(user) => {
|
Msg::OnUserAddedToGroup(user) => {
|
||||||
self.group_and_schema.as_mut().unwrap().0.users.push(User {
|
self.group.as_mut().unwrap().users.push(User {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
display_name: user.display_name,
|
display_name: user.display_name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Msg::OnUserRemovedFromGroup((user_id, _)) => {
|
Msg::OnUserRemovedFromGroup((user_id, _)) => {
|
||||||
self.group_and_schema
|
self.group
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
|
||||||
.users
|
.users
|
||||||
.retain(|u| u.id != user_id);
|
.retain(|u| u.id != user_id);
|
||||||
}
|
}
|
||||||
Msg::DisplayNameUpdated => self.get_group_details(ctx),
|
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
@@ -226,7 +221,7 @@ impl Component for GroupDetails {
|
|||||||
fn create(ctx: &Context<Self>) -> Self {
|
fn create(ctx: &Context<Self>) -> Self {
|
||||||
let mut table = Self {
|
let mut table = Self {
|
||||||
common: CommonComponentParts::<Self>::create(),
|
common: CommonComponentParts::<Self>::create(),
|
||||||
group_and_schema: None,
|
group: None,
|
||||||
};
|
};
|
||||||
table.get_group_details(ctx);
|
table.get_group_details(ctx);
|
||||||
table
|
table
|
||||||
@@ -237,15 +232,15 @@ impl Component for GroupDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
fn view(&self, ctx: &Context<Self>) -> Html {
|
||||||
match (&self.group_and_schema, &self.common.error) {
|
match (&self.group, &self.common.error) {
|
||||||
(None, None) => html! {{"Loading..."}},
|
(None, None) => html! {{"Loading..."}},
|
||||||
(None, Some(e)) => html! {<div>{"Error: "}{e.to_string()}</div>},
|
(None, Some(e)) => html! {<div>{"Error: "}{e.to_string()}</div>},
|
||||||
(Some((group, schema)), error) => {
|
(Some(u), error) => {
|
||||||
html! {
|
html! {
|
||||||
<div>
|
<div>
|
||||||
{self.view_details(ctx, group, schema.clone())}
|
{self.view_details(u)}
|
||||||
{self.view_user_list(ctx, group)}
|
{self.view_user_list(ctx, u)}
|
||||||
{self.view_add_user_button(ctx, group)}
|
{self.view_add_user_button(ctx, u)}
|
||||||
{self.view_messages(error)}
|
{self.view_messages(error)}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,271 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
components::{
|
|
||||||
form::{
|
|
||||||
attribute_input::{ListAttributeInput, SingleAttributeInput},
|
|
||||||
static_value::StaticValue,
|
|
||||||
submit::Submit,
|
|
||||||
},
|
|
||||||
group_details::{Attribute, AttributeSchema, Group},
|
|
||||||
},
|
|
||||||
infra::{
|
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
form_utils::{AttributeValue, EmailIsRequired, IsAdmin, read_all_form_attributes},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use anyhow::{Ok, Result};
|
|
||||||
use graphql_client::GraphQLQuery;
|
|
||||||
use yew::prelude::*;
|
|
||||||
|
|
||||||
/// The GraphQL query sent to the server to update the group details.
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/update_group.graphql",
|
|
||||||
response_derives = "Debug",
|
|
||||||
variables_derives = "Clone,PartialEq,Eq",
|
|
||||||
custom_scalars_module = "crate::infra::graphql"
|
|
||||||
)]
|
|
||||||
pub struct UpdateGroup;
|
|
||||||
|
|
||||||
/// A [yew::Component] to display the group details, with a form allowing to edit them.
|
|
||||||
pub struct GroupDetailsForm {
|
|
||||||
common: CommonComponentParts<Self>,
|
|
||||||
/// True if we just successfully updated the group, to display a success message.
|
|
||||||
just_updated: bool,
|
|
||||||
updated_group_name: bool,
|
|
||||||
group: Group,
|
|
||||||
form_ref: NodeRef,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Msg {
|
|
||||||
/// A form field changed.
|
|
||||||
Update,
|
|
||||||
/// The "Submit" button was clicked.
|
|
||||||
SubmitClicked,
|
|
||||||
/// We got the response from the server about our update message.
|
|
||||||
GroupUpdated(Result<update_group::ResponseData>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(yew::Properties, Clone, PartialEq)]
|
|
||||||
pub struct Props {
|
|
||||||
/// The current group details.
|
|
||||||
pub group: Group,
|
|
||||||
pub group_attributes_schema: Vec<AttributeSchema>,
|
|
||||||
pub is_admin: bool,
|
|
||||||
pub on_display_name_updated: Callback<()>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommonComponent<GroupDetailsForm> for GroupDetailsForm {
|
|
||||||
fn handle_msg(
|
|
||||||
&mut self,
|
|
||||||
ctx: &Context<Self>,
|
|
||||||
msg: <Self as Component>::Message,
|
|
||||||
) -> Result<bool> {
|
|
||||||
match msg {
|
|
||||||
Msg::Update => Ok(true),
|
|
||||||
Msg::SubmitClicked => self.submit_group_update_form(ctx),
|
|
||||||
Msg::GroupUpdated(Err(e)) => Err(e),
|
|
||||||
Msg::GroupUpdated(Result::Ok(_)) => {
|
|
||||||
self.just_updated = true;
|
|
||||||
if self.updated_group_name {
|
|
||||||
self.updated_group_name = false;
|
|
||||||
ctx.props().on_display_name_updated.emit(());
|
|
||||||
}
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mut_common(&mut self) -> &mut CommonComponentParts<Self> {
|
|
||||||
&mut self.common
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for GroupDetailsForm {
|
|
||||||
type Message = Msg;
|
|
||||||
type Properties = Props;
|
|
||||||
|
|
||||||
fn create(ctx: &Context<Self>) -> Self {
|
|
||||||
Self {
|
|
||||||
common: CommonComponentParts::<Self>::create(),
|
|
||||||
just_updated: false,
|
|
||||||
updated_group_name: false,
|
|
||||||
group: ctx.props().group.clone(),
|
|
||||||
form_ref: NodeRef::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
||||||
self.just_updated = false;
|
|
||||||
CommonComponentParts::<Self>::update(self, ctx, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let link = &ctx.link();
|
|
||||||
|
|
||||||
let can_edit =
|
|
||||||
|a: &AttributeSchema| (ctx.props().is_admin || a.is_editable) && !a.is_readonly;
|
|
||||||
let display_field = |a: &AttributeSchema| {
|
|
||||||
if can_edit(a) {
|
|
||||||
get_custom_attribute_input(a, &self.group.attributes)
|
|
||||||
} else {
|
|
||||||
get_custom_attribute_static(a, &self.group.attributes)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
html! {
|
|
||||||
<div class="py-3">
|
|
||||||
<form
|
|
||||||
class="form"
|
|
||||||
ref={self.form_ref.clone()}>
|
|
||||||
<StaticValue label="Group ID" id="groupId">
|
|
||||||
<i>{&self.group.id}</i>
|
|
||||||
</StaticValue>
|
|
||||||
{
|
|
||||||
ctx
|
|
||||||
.props()
|
|
||||||
.group_attributes_schema
|
|
||||||
.iter()
|
|
||||||
.filter(|a| a.is_hardcoded && a.name != "group_id")
|
|
||||||
.map(display_field)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
{
|
|
||||||
ctx
|
|
||||||
.props()
|
|
||||||
.group_attributes_schema
|
|
||||||
.iter()
|
|
||||||
.filter(|a| !a.is_hardcoded)
|
|
||||||
.map(display_field)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
<Submit
|
|
||||||
text="Save changes"
|
|
||||||
disabled={self.common.is_task_running()}
|
|
||||||
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::SubmitClicked})} />
|
|
||||||
</form>
|
|
||||||
{
|
|
||||||
if let Some(e) = &self.common.error {
|
|
||||||
html! {
|
|
||||||
<div class="alert alert-danger">
|
|
||||||
{e.to_string() }
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
} else { html! {} }
|
|
||||||
}
|
|
||||||
<div hidden={!self.just_updated}>
|
|
||||||
<div class="alert alert-success mt-4">{"Group successfully updated!"}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_custom_attribute_input(
|
|
||||||
attribute_schema: &AttributeSchema,
|
|
||||||
group_attributes: &[Attribute],
|
|
||||||
) -> Html {
|
|
||||||
let values = group_attributes
|
|
||||||
.iter()
|
|
||||||
.find(|a| a.name == attribute_schema.name)
|
|
||||||
.map(|attribute| attribute.value.clone())
|
|
||||||
.unwrap_or_default();
|
|
||||||
if attribute_schema.is_list {
|
|
||||||
html! {
|
|
||||||
<ListAttributeInput
|
|
||||||
name={attribute_schema.name.clone()}
|
|
||||||
attribute_type={attribute_schema.attribute_type}
|
|
||||||
values={values}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
html! {
|
|
||||||
<SingleAttributeInput
|
|
||||||
name={attribute_schema.name.clone()}
|
|
||||||
attribute_type={attribute_schema.attribute_type}
|
|
||||||
value={values.first().cloned().unwrap_or_default()}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_custom_attribute_static(
|
|
||||||
attribute_schema: &AttributeSchema,
|
|
||||||
group_attributes: &[Attribute],
|
|
||||||
) -> Html {
|
|
||||||
let values = group_attributes
|
|
||||||
.iter()
|
|
||||||
.find(|a| a.name == attribute_schema.name)
|
|
||||||
.map(|attribute| attribute.value.clone())
|
|
||||||
.unwrap_or_default();
|
|
||||||
html! {
|
|
||||||
<StaticValue label={attribute_schema.name.clone()} id={attribute_schema.name.clone()}>
|
|
||||||
{values.into_iter().map(|x| html!{<div>{x}</div>}).collect::<Vec<_>>()}
|
|
||||||
</StaticValue>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GroupDetailsForm {
|
|
||||||
fn submit_group_update_form(&mut self, ctx: &Context<Self>) -> Result<bool> {
|
|
||||||
let mut all_values = read_all_form_attributes(
|
|
||||||
ctx.props().group_attributes_schema.iter(),
|
|
||||||
&self.form_ref,
|
|
||||||
IsAdmin(ctx.props().is_admin),
|
|
||||||
EmailIsRequired(false),
|
|
||||||
)?;
|
|
||||||
let base_attributes = &self.group.attributes;
|
|
||||||
all_values.retain(|a| {
|
|
||||||
let base_val = base_attributes
|
|
||||||
.iter()
|
|
||||||
.find(|base_val| base_val.name == a.name);
|
|
||||||
base_val
|
|
||||||
.map(|v| v.value != a.values)
|
|
||||||
.unwrap_or(!a.values.is_empty())
|
|
||||||
});
|
|
||||||
if all_values.iter().any(|a| a.name == "display_name") {
|
|
||||||
self.updated_group_name = true;
|
|
||||||
}
|
|
||||||
let remove_attributes: Option<Vec<String>> = if all_values.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(all_values.iter().map(|a| a.name.clone()).collect())
|
|
||||||
};
|
|
||||||
let insert_attributes: Option<Vec<update_group::AttributeValueInput>> =
|
|
||||||
if remove_attributes.is_none() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(
|
|
||||||
all_values
|
|
||||||
.into_iter()
|
|
||||||
.filter(|a| !a.values.is_empty())
|
|
||||||
.map(
|
|
||||||
|AttributeValue { name, values }| update_group::AttributeValueInput {
|
|
||||||
name,
|
|
||||||
value: values,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
let mut group_input = update_group::UpdateGroupInput {
|
|
||||||
id: self.group.id,
|
|
||||||
displayName: None,
|
|
||||||
removeAttributes: None,
|
|
||||||
insertAttributes: None,
|
|
||||||
};
|
|
||||||
let default_group_input = group_input.clone();
|
|
||||||
group_input.removeAttributes = remove_attributes;
|
|
||||||
group_input.insertAttributes = insert_attributes;
|
|
||||||
// Nothing changed.
|
|
||||||
if group_input == default_group_input {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
let req = update_group::Variables { group: group_input };
|
|
||||||
self.common.call_graphql::<UpdateGroup, _>(
|
|
||||||
ctx,
|
|
||||||
req,
|
|
||||||
Msg::GroupUpdated,
|
|
||||||
"Error trying to update group",
|
|
||||||
);
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,199 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
components::{
|
|
||||||
delete_group_attribute::DeleteGroupAttribute,
|
|
||||||
fragments::attribute_schema::render_attribute_name,
|
|
||||||
router::{AppRoute, Link},
|
|
||||||
},
|
|
||||||
infra::{
|
|
||||||
attributes::group,
|
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
schema::AttributeType,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use anyhow::{Error, Result, anyhow};
|
|
||||||
use gloo_console::log;
|
|
||||||
use graphql_client::GraphQLQuery;
|
|
||||||
use yew::prelude::*;
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/get_group_attributes_schema.graphql",
|
|
||||||
response_derives = "Debug,Clone,PartialEq,Eq",
|
|
||||||
custom_scalars_module = "crate::infra::graphql",
|
|
||||||
extern_enums("AttributeType")
|
|
||||||
)]
|
|
||||||
pub struct GetGroupAttributesSchema;
|
|
||||||
|
|
||||||
use get_group_attributes_schema::ResponseData;
|
|
||||||
|
|
||||||
pub type Attribute =
|
|
||||||
get_group_attributes_schema::GetGroupAttributesSchemaSchemaGroupSchemaAttributes;
|
|
||||||
|
|
||||||
#[derive(yew::Properties, Clone, PartialEq, Eq)]
|
|
||||||
pub struct Props {
|
|
||||||
pub hardcoded: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GroupSchemaTable {
|
|
||||||
common: CommonComponentParts<Self>,
|
|
||||||
attributes: Option<Vec<Attribute>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Msg {
|
|
||||||
ListAttributesResponse(Result<ResponseData>),
|
|
||||||
OnAttributeDeleted(String),
|
|
||||||
OnError(Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommonComponent<GroupSchemaTable> for GroupSchemaTable {
|
|
||||||
fn handle_msg(&mut self, _: &Context<Self>, msg: <Self as Component>::Message) -> Result<bool> {
|
|
||||||
match msg {
|
|
||||||
Msg::ListAttributesResponse(schema) => {
|
|
||||||
self.attributes =
|
|
||||||
Some(schema?.schema.group_schema.attributes.into_iter().collect());
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
Msg::OnError(e) => Err(e),
|
|
||||||
Msg::OnAttributeDeleted(attribute_name) => match self.attributes {
|
|
||||||
None => {
|
|
||||||
log!(format!(
|
|
||||||
"Attribute {attribute_name} was deleted but component has no attributes"
|
|
||||||
));
|
|
||||||
Err(anyhow!("invalid state"))
|
|
||||||
}
|
|
||||||
Some(_) => {
|
|
||||||
self.attributes
|
|
||||||
.as_mut()
|
|
||||||
.unwrap()
|
|
||||||
.retain(|a| a.name != attribute_name);
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mut_common(&mut self) -> &mut CommonComponentParts<Self> {
|
|
||||||
&mut self.common
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for GroupSchemaTable {
|
|
||||||
type Message = Msg;
|
|
||||||
type Properties = Props;
|
|
||||||
|
|
||||||
fn create(ctx: &Context<Self>) -> Self {
|
|
||||||
let mut table = GroupSchemaTable {
|
|
||||||
common: CommonComponentParts::<Self>::create(),
|
|
||||||
attributes: None,
|
|
||||||
};
|
|
||||||
table.common.call_graphql::<GetGroupAttributesSchema, _>(
|
|
||||||
ctx,
|
|
||||||
get_group_attributes_schema::Variables {},
|
|
||||||
Msg::ListAttributesResponse,
|
|
||||||
"Error trying to fetch group schema",
|
|
||||||
);
|
|
||||||
table
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
||||||
CommonComponentParts::<Self>::update(self, ctx, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
html! {
|
|
||||||
<div>
|
|
||||||
{self.view_attributes(ctx)}
|
|
||||||
{self.view_errors()}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GroupSchemaTable {
|
|
||||||
fn view_attributes(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let hardcoded = ctx.props().hardcoded;
|
|
||||||
let make_table = |attributes: &Vec<Attribute>| {
|
|
||||||
html! {
|
|
||||||
<div class="table-responsive">
|
|
||||||
<h3>{if hardcoded {"Hardcoded"} else {"User-defined"}}{" attributes"}</h3>
|
|
||||||
<table class="table table-hover">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>{"Attribute name"}</th>
|
|
||||||
<th>{"Type"}</th>
|
|
||||||
<th>{"Visible"}</th>
|
|
||||||
{if hardcoded {html!{}} else {html!{<th>{"Delete"}</th>}}}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{attributes.iter().map(|u| self.view_attribute(ctx, u)).collect::<Vec<_>>()}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
};
|
|
||||||
match &self.attributes {
|
|
||||||
None => html! {{"Loading..."}},
|
|
||||||
Some(attributes) => {
|
|
||||||
let mut attributes = attributes.clone();
|
|
||||||
attributes.retain(|attribute| attribute.is_hardcoded == ctx.props().hardcoded);
|
|
||||||
make_table(&attributes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_attribute(&self, ctx: &Context<Self>, attribute: &Attribute) -> Html {
|
|
||||||
let link = ctx.link();
|
|
||||||
let attribute_type = attribute.attribute_type;
|
|
||||||
let checkmark = html! {
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check" viewBox="0 0 16 16">
|
|
||||||
<path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425z"></path>
|
|
||||||
</svg>
|
|
||||||
};
|
|
||||||
let hardcoded = ctx.props().hardcoded;
|
|
||||||
let desc = group::resolve_group_attribute_description_or_default(&attribute.name);
|
|
||||||
html! {
|
|
||||||
<tr key={attribute.name.clone()}>
|
|
||||||
<td>{render_attribute_name(hardcoded, &desc)}</td>
|
|
||||||
<td>{if attribute.is_list { format!("List<{attribute_type}>")} else {attribute_type.to_string()}}</td>
|
|
||||||
<td>{if attribute.is_visible {checkmark.clone()} else {html!{}}}</td>
|
|
||||||
{
|
|
||||||
if hardcoded {
|
|
||||||
html!{}
|
|
||||||
} else {
|
|
||||||
html!{
|
|
||||||
<td>
|
|
||||||
<DeleteGroupAttribute
|
|
||||||
attribute_name={attribute.name.clone()}
|
|
||||||
on_attribute_deleted={link.callback(Msg::OnAttributeDeleted)}
|
|
||||||
on_error={link.callback(Msg::OnError)}/>
|
|
||||||
</td>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_errors(&self) -> Html {
|
|
||||||
match &self.common.error {
|
|
||||||
None => html! {},
|
|
||||||
Some(e) => html! {<div>{"Error: "}{e.to_string()}</div>},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(ListGroupSchema)]
|
|
||||||
pub fn list_group_schema() -> Html {
|
|
||||||
html! {
|
|
||||||
<div>
|
|
||||||
<GroupSchemaTable hardcoded={true} />
|
|
||||||
<GroupSchemaTable hardcoded={false} />
|
|
||||||
<Link classes="btn btn-primary" to={AppRoute::CreateGroupAttribute}>
|
|
||||||
<i class="bi-plus-circle me-2"></i>
|
|
||||||
{"Create an attribute"}
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+66
-63
@@ -1,14 +1,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::router::{AppRoute, Link},
|
||||||
form::submit::Submit,
|
|
||||||
router::{AppRoute, Link},
|
|
||||||
},
|
|
||||||
infra::{
|
infra::{
|
||||||
api::HostService,
|
api::HostService,
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
common_component::{CommonComponent, CommonComponentParts},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{Result, anyhow, bail};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use gloo_console::error;
|
use gloo_console::error;
|
||||||
use lldap_auth::*;
|
use lldap_auth::*;
|
||||||
use validator_derive::Validate;
|
use validator_derive::Validate;
|
||||||
@@ -69,7 +66,7 @@ impl CommonComponent<LoginForm> for LoginForm {
|
|||||||
opaque::client::login::start_login(&password, &mut rng)
|
opaque::client::login::start_login(&password, &mut rng)
|
||||||
.context("Could not initialize login")?;
|
.context("Could not initialize login")?;
|
||||||
let req = login::ClientLoginStartRequest {
|
let req = login::ClientLoginStartRequest {
|
||||||
username: username.into(),
|
username,
|
||||||
login_start_request: message,
|
login_start_request: message,
|
||||||
};
|
};
|
||||||
self.common
|
self.common
|
||||||
@@ -152,68 +149,74 @@ impl Component for LoginForm {
|
|||||||
let link = &ctx.link();
|
let link = &ctx.link();
|
||||||
if self.refreshing {
|
if self.refreshing {
|
||||||
html! {
|
html! {
|
||||||
<div>
|
<div class="spinner-border" role="status">
|
||||||
<img src={"spinner.gif"} alt={"Loading"} />
|
<span class="sr-only">{"Loading..."}</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
html! {
|
html! {
|
||||||
<form class="form center-block col-sm-4 col-offset-4">
|
<form
|
||||||
<div class="input-group">
|
class="form center-block col-sm-4 col-offset-4">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group">
|
||||||
<span class="input-group-text">
|
<div class="input-group-prepend">
|
||||||
<i class="bi-person-fill"/>
|
<span class="input-group-text">
|
||||||
</span>
|
<i class="bi-person-fill"/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Field
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
form={&self.form}
|
||||||
|
field_name="username"
|
||||||
|
placeholder="Username"
|
||||||
|
autocomplete="username"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
</div>
|
</div>
|
||||||
<Field
|
<div class="input-group">
|
||||||
class="form-control"
|
<div class="input-group-prepend">
|
||||||
class_invalid="is-invalid has-error"
|
<span class="input-group-text">
|
||||||
class_valid="has-success"
|
<i class="bi-lock-fill"/>
|
||||||
form={&self.form}
|
</span>
|
||||||
field_name="username"
|
</div>
|
||||||
placeholder="Username"
|
<Field
|
||||||
autocomplete="username"
|
class="form-control"
|
||||||
oninput={link.callback(|_| Msg::Update)} />
|
class_invalid="is-invalid has-error"
|
||||||
</div>
|
class_valid="has-success"
|
||||||
<div class="input-group">
|
form={&self.form}
|
||||||
<div class="input-group-prepend">
|
field_name="password"
|
||||||
<span class="input-group-text">
|
input_type="password"
|
||||||
<i class="bi-lock-fill"/>
|
placeholder="Password"
|
||||||
</span>
|
autocomplete="current-password" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mt-3">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="btn btn-primary"
|
||||||
|
disabled={self.common.is_task_running()}
|
||||||
|
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::Submit})}>
|
||||||
|
<i class="bi-box-arrow-in-right me-2"/>
|
||||||
|
{"Login"}
|
||||||
|
</button>
|
||||||
|
{ if password_reset_enabled {
|
||||||
|
html! {
|
||||||
|
<Link
|
||||||
|
classes="btn-link btn"
|
||||||
|
disabled={self.common.is_task_running()}
|
||||||
|
to={AppRoute::StartResetPassword}>
|
||||||
|
{"Forgot your password?"}
|
||||||
|
</Link>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
html!{}
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
{ if let Some(e) = &self.common.error {
|
||||||
|
html! { e.to_string() }
|
||||||
|
} else { html! {} }
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<Field
|
|
||||||
class="form-control"
|
|
||||||
class_invalid="is-invalid has-error"
|
|
||||||
class_valid="has-success"
|
|
||||||
form={&self.form}
|
|
||||||
field_name="password"
|
|
||||||
input_type="password"
|
|
||||||
placeholder="Password"
|
|
||||||
autocomplete="current-password" />
|
|
||||||
</div>
|
|
||||||
<Submit
|
|
||||||
text="Login"
|
|
||||||
disabled={self.common.is_task_running()}
|
|
||||||
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::Submit})}>
|
|
||||||
{ if password_reset_enabled {
|
|
||||||
html! {
|
|
||||||
<Link
|
|
||||||
classes="btn-link btn"
|
|
||||||
disabled={self.common.is_task_running()}
|
|
||||||
to={AppRoute::StartResetPassword}>
|
|
||||||
{"Forgot your password?"}
|
|
||||||
</Link>
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
html!{}
|
|
||||||
}}
|
|
||||||
</Submit>
|
|
||||||
<div class="form-group">
|
|
||||||
{ if let Some(e) = &self.common.error {
|
|
||||||
html! { e.to_string() }
|
|
||||||
} else { html! {} }
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,16 @@
|
|||||||
pub mod add_group_member;
|
pub mod add_group_member;
|
||||||
pub mod add_user_to_group;
|
pub mod add_user_to_group;
|
||||||
pub mod app;
|
pub mod app;
|
||||||
pub mod avatar;
|
|
||||||
pub mod banner;
|
|
||||||
pub mod change_password;
|
pub mod change_password;
|
||||||
pub mod create_group;
|
pub mod create_group;
|
||||||
pub mod create_group_attribute;
|
|
||||||
pub mod create_user;
|
pub mod create_user;
|
||||||
pub mod create_user_attribute;
|
|
||||||
pub mod delete_group;
|
pub mod delete_group;
|
||||||
pub mod delete_group_attribute;
|
|
||||||
pub mod delete_user;
|
pub mod delete_user;
|
||||||
pub mod delete_user_attribute;
|
|
||||||
pub mod form;
|
|
||||||
pub mod fragments;
|
|
||||||
pub mod group_details;
|
pub mod group_details;
|
||||||
pub mod group_details_form;
|
|
||||||
pub mod group_schema_table;
|
|
||||||
pub mod group_table;
|
pub mod group_table;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod logout;
|
pub mod logout;
|
||||||
|
pub mod password_field;
|
||||||
pub mod remove_user_from_group;
|
pub mod remove_user_from_group;
|
||||||
pub mod reset_password_step1;
|
pub mod reset_password_step1;
|
||||||
pub mod reset_password_step2;
|
pub mod reset_password_step2;
|
||||||
@@ -27,5 +18,4 @@ pub mod router;
|
|||||||
pub mod select;
|
pub mod select;
|
||||||
pub mod user_details;
|
pub mod user_details;
|
||||||
pub mod user_details_form;
|
pub mod user_details_form;
|
||||||
pub mod user_schema_table;
|
|
||||||
pub mod user_table;
|
pub mod user_table;
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
use crate::infra::{
|
||||||
|
api::{hash_password, HostService, PasswordHash, PasswordWasLeaked},
|
||||||
|
common_component::{CommonComponent, CommonComponentParts},
|
||||||
|
};
|
||||||
|
use anyhow::Result;
|
||||||
|
use gloo_timers::callback::Timeout;
|
||||||
|
use web_sys::{HtmlInputElement, InputEvent};
|
||||||
|
use yew::{html, Callback, Classes, Component, Context, Properties};
|
||||||
|
use yew_form::{Field, Form, Model};
|
||||||
|
|
||||||
|
pub enum PasswordFieldMsg {
|
||||||
|
OnInput(String),
|
||||||
|
OnInputIdle,
|
||||||
|
PasswordCheckResult(Result<(Option<PasswordWasLeaked>, PasswordHash)>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
pub enum PasswordState {
|
||||||
|
// Whether the password was found in a leak.
|
||||||
|
Checked(PasswordWasLeaked),
|
||||||
|
// Server doesn't support checking passwords (TODO: move to config).
|
||||||
|
NotSupported,
|
||||||
|
// Requested a check, no response yet from the server.
|
||||||
|
Loading,
|
||||||
|
// User is still actively typing.
|
||||||
|
Typing,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PasswordField<FormModel: Model> {
|
||||||
|
common: CommonComponentParts<Self>,
|
||||||
|
timeout_task: Option<Timeout>,
|
||||||
|
password: String,
|
||||||
|
password_check_state: PasswordState,
|
||||||
|
_marker: std::marker::PhantomData<FormModel>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<FormModel: Model> CommonComponent<PasswordField<FormModel>> for PasswordField<FormModel> {
|
||||||
|
fn handle_msg(
|
||||||
|
&mut self,
|
||||||
|
ctx: &Context<Self>,
|
||||||
|
msg: <Self as Component>::Message,
|
||||||
|
) -> anyhow::Result<bool> {
|
||||||
|
match msg {
|
||||||
|
PasswordFieldMsg::OnInput(password) => {
|
||||||
|
self.password = password;
|
||||||
|
if self.password_check_state != PasswordState::NotSupported {
|
||||||
|
self.password_check_state = PasswordState::Typing;
|
||||||
|
if self.password.len() >= 8 {
|
||||||
|
let link = ctx.link().clone();
|
||||||
|
self.timeout_task = Some(Timeout::new(500, move || {
|
||||||
|
link.send_message(PasswordFieldMsg::OnInputIdle)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PasswordFieldMsg::PasswordCheckResult(result) => {
|
||||||
|
self.timeout_task = None;
|
||||||
|
// If there's an error from the backend, don't retry.
|
||||||
|
self.password_check_state = PasswordState::NotSupported;
|
||||||
|
if let (Some(check), hash) = result? {
|
||||||
|
if hash == hash_password(&self.password) {
|
||||||
|
self.password_check_state = PasswordState::Checked(check)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PasswordFieldMsg::OnInputIdle => {
|
||||||
|
self.timeout_task = None;
|
||||||
|
if self.password_check_state != PasswordState::NotSupported {
|
||||||
|
self.password_check_state = PasswordState::Loading;
|
||||||
|
self.common.call_backend(
|
||||||
|
ctx,
|
||||||
|
HostService::check_password_haveibeenpwned(hash_password(&self.password)),
|
||||||
|
PasswordFieldMsg::PasswordCheckResult,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mut_common(&mut self) -> &mut CommonComponentParts<PasswordField<FormModel>> {
|
||||||
|
&mut self.common
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Properties, PartialEq, Clone)]
|
||||||
|
pub struct PasswordFieldProperties<FormModel: Model> {
|
||||||
|
pub field_name: String,
|
||||||
|
pub form: Form<FormModel>,
|
||||||
|
#[prop_or_else(|| { "form-control".into() })]
|
||||||
|
pub class: Classes,
|
||||||
|
#[prop_or_else(|| { "is-invalid".into() })]
|
||||||
|
pub class_invalid: Classes,
|
||||||
|
#[prop_or_else(|| { "is-valid".into() })]
|
||||||
|
pub class_valid: Classes,
|
||||||
|
#[prop_or_else(Callback::noop)]
|
||||||
|
pub oninput: Callback<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<FormModel: Model> Component for PasswordField<FormModel> {
|
||||||
|
type Message = PasswordFieldMsg;
|
||||||
|
type Properties = PasswordFieldProperties<FormModel>;
|
||||||
|
|
||||||
|
fn create(_: &Context<Self>) -> Self {
|
||||||
|
Self {
|
||||||
|
common: CommonComponentParts::<Self>::create(),
|
||||||
|
timeout_task: None,
|
||||||
|
password: String::new(),
|
||||||
|
password_check_state: PasswordState::Typing,
|
||||||
|
_marker: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
||||||
|
CommonComponentParts::<Self>::update(self, ctx, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self, ctx: &Context<Self>) -> yew::Html {
|
||||||
|
let link = &ctx.link();
|
||||||
|
html! {
|
||||||
|
<div>
|
||||||
|
<Field<FormModel>
|
||||||
|
autocomplete={"new-password"}
|
||||||
|
input_type={"password"}
|
||||||
|
field_name={ctx.props().field_name.clone()}
|
||||||
|
form={ctx.props().form.clone()}
|
||||||
|
class={ctx.props().class.clone()}
|
||||||
|
class_invalid={ctx.props().class_invalid.clone()}
|
||||||
|
class_valid={ctx.props().class_valid.clone()}
|
||||||
|
oninput={link.callback(|e: InputEvent| {
|
||||||
|
use wasm_bindgen::JsCast;
|
||||||
|
let target = e.target().unwrap();
|
||||||
|
let input = target.dyn_into::<HtmlInputElement>().unwrap();
|
||||||
|
PasswordFieldMsg::OnInput(input.value())
|
||||||
|
})} />
|
||||||
|
{
|
||||||
|
match self.password_check_state {
|
||||||
|
PasswordState::Checked(PasswordWasLeaked(true)) => html! { <i class="bi bi-x"></i> },
|
||||||
|
PasswordState::Checked(PasswordWasLeaked(false)) => html! { <i class="bi bi-check"></i> },
|
||||||
|
PasswordState::NotSupported | PasswordState::Typing => html!{},
|
||||||
|
PasswordState::Loading =>
|
||||||
|
html! {
|
||||||
|
<div class="spinner-border spinner-border-sm" role="status">
|
||||||
|
<span class="sr-only">{"Loading..."}</span>
|
||||||
|
</div>
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ use crate::{
|
|||||||
common_component::{CommonComponent, CommonComponentParts},
|
common_component::{CommonComponent, CommonComponentParts},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{bail, Result};
|
||||||
use validator_derive::Validate;
|
use validator_derive::Validate;
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
use yew_form::Form;
|
use yew_form::Form;
|
||||||
@@ -104,11 +104,7 @@ impl Component for ResetPasswordStep1Form {
|
|||||||
</div>
|
</div>
|
||||||
{ if self.just_succeeded {
|
{ if self.just_succeeded {
|
||||||
html! {
|
html! {
|
||||||
{"If a user with this username or email exists, a password reset email will \
|
{"A reset token has been sent to your email."}
|
||||||
be sent to the associated email address. Please check your email and \
|
|
||||||
follow the instructions. If you don't receive an email, please check \
|
|
||||||
your spam folder. If you still don't receive an email, please contact \
|
|
||||||
your administrator."}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
html! {
|
html! {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::{
|
||||||
form::{field::Field, submit::Submit},
|
password_field::PasswordField,
|
||||||
router::{AppRoute, Link},
|
router::{AppRoute, Link},
|
||||||
},
|
},
|
||||||
infra::{
|
infra::{
|
||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
common_component::{CommonComponent, CommonComponentParts},
|
common_component::{CommonComponent, CommonComponentParts},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{bail, Result};
|
||||||
use lldap_auth::{
|
use lldap_auth::{
|
||||||
opaque::client::registration as opaque_registration,
|
opaque::client::registration as opaque_registration,
|
||||||
password_reset::ServerPasswordResetResponse, registration,
|
password_reset::ServerPasswordResetResponse, registration,
|
||||||
@@ -68,10 +68,10 @@ impl CommonComponent<ResetPasswordStep2Form> for ResetPasswordStep2Form {
|
|||||||
let mut rng = rand::rngs::OsRng;
|
let mut rng = rand::rngs::OsRng;
|
||||||
let new_password = self.form.model().password;
|
let new_password = self.form.model().password;
|
||||||
let registration_start_request =
|
let registration_start_request =
|
||||||
opaque_registration::start_registration(new_password.as_bytes(), &mut rng)
|
opaque_registration::start_registration(&new_password, &mut rng)
|
||||||
.context("Could not initiate password change")?;
|
.context("Could not initiate password change")?;
|
||||||
let req = registration::ClientRegistrationStartRequest {
|
let req = registration::ClientRegistrationStartRequest {
|
||||||
username: self.username.as_ref().unwrap().into(),
|
username: self.username.clone().unwrap(),
|
||||||
registration_start_request: registration_start_request.message,
|
registration_start_request: registration_start_request.message,
|
||||||
};
|
};
|
||||||
self.opaque_data = Some(registration_start_request.state);
|
self.opaque_data = Some(registration_start_request.state);
|
||||||
@@ -148,7 +148,7 @@ impl Component for ResetPasswordStep2Form {
|
|||||||
(None, None) => {
|
(None, None) => {
|
||||||
return html! {
|
return html! {
|
||||||
{"Validating token"}
|
{"Validating token"}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
(None, Some(e)) => {
|
(None, Some(e)) => {
|
||||||
return html! {
|
return html! {
|
||||||
@@ -163,33 +163,63 @@ impl Component for ResetPasswordStep2Form {
|
|||||||
{"Back"}
|
{"Back"}
|
||||||
</Link>
|
</Link>
|
||||||
</>
|
</>
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
|
type Field = yew_form::Field<FormModel>;
|
||||||
html! {
|
html! {
|
||||||
<>
|
<>
|
||||||
<h2>{"Reset your password"}</h2>
|
<h2>{"Reset your password"}</h2>
|
||||||
<form class="form">
|
<form
|
||||||
<Field<FormModel>
|
class="form">
|
||||||
label="New password"
|
<div class="form-group row">
|
||||||
required=true
|
<label for="new_password"
|
||||||
form={&self.form}
|
class="form-label col-sm-2 col-form-label">
|
||||||
field_name="password"
|
{"New password*:"}
|
||||||
autocomplete="new-password"
|
</label>
|
||||||
input_type="password"
|
<div class="col-sm-10">
|
||||||
oninput={link.callback(|_| Msg::FormUpdate)} />
|
<PasswordField<FormModel>
|
||||||
<Field<FormModel>
|
form={&self.form}
|
||||||
label="Confirm password"
|
field_name="password"
|
||||||
required=true
|
class="form-control"
|
||||||
form={&self.form}
|
class_invalid="is-invalid has-error"
|
||||||
field_name="confirm_password"
|
class_valid="has-success"
|
||||||
autocomplete="new-password"
|
oninput={link.callback(|_| Msg::FormUpdate)} />
|
||||||
input_type="password"
|
<div class="invalid-feedback">
|
||||||
oninput={link.callback(|_| Msg::FormUpdate)} />
|
{&self.form.field_message("password")}
|
||||||
<Submit
|
</div>
|
||||||
disabled={self.common.is_task_running()}
|
</div>
|
||||||
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::Submit})} />
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="confirm_password"
|
||||||
|
class="form-label col-sm-2 col-form-label">
|
||||||
|
{"Confirm password*:"}
|
||||||
|
</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<Field
|
||||||
|
form={&self.form}
|
||||||
|
field_name="confirm_password"
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
autocomplete="new-password"
|
||||||
|
input_type="password"
|
||||||
|
oninput={link.callback(|_| Msg::FormUpdate)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("confirm_password")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mt-2">
|
||||||
|
<button
|
||||||
|
class="btn btn-primary col-sm-1 col-form-label"
|
||||||
|
type="submit"
|
||||||
|
disabled={self.common.is_task_running()}
|
||||||
|
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::Submit})}>
|
||||||
|
{"Submit"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{ if let Some(e) = &self.common.error {
|
{ if let Some(e) = &self.common.error {
|
||||||
html! {
|
html! {
|
||||||
|
|||||||
@@ -22,14 +22,6 @@ pub enum AppRoute {
|
|||||||
ListGroups,
|
ListGroups,
|
||||||
#[at("/group/:group_id")]
|
#[at("/group/:group_id")]
|
||||||
GroupDetails { group_id: i64 },
|
GroupDetails { group_id: i64 },
|
||||||
#[at("/user-attributes")]
|
|
||||||
ListUserSchema,
|
|
||||||
#[at("/user-attributes/create")]
|
|
||||||
CreateUserAttribute,
|
|
||||||
#[at("/group-attributes")]
|
|
||||||
ListGroupSchema,
|
|
||||||
#[at("/group-attributes/create")]
|
|
||||||
CreateGroupAttribute,
|
|
||||||
#[at("/")]
|
#[at("/")]
|
||||||
Index,
|
Index,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,9 @@ use crate::{
|
|||||||
router::{AppRoute, Link},
|
router::{AppRoute, Link},
|
||||||
user_details_form::UserDetailsForm,
|
user_details_form::UserDetailsForm,
|
||||||
},
|
},
|
||||||
infra::{
|
infra::common_component::{CommonComponent, CommonComponentParts},
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
form_utils::GraphQlAttributeSchema,
|
|
||||||
schema::AttributeType,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use anyhow::{Error, Result, bail};
|
use anyhow::{bail, Error, Result};
|
||||||
use graphql_client::GraphQLQuery;
|
use graphql_client::GraphQLQuery;
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
|
||||||
@@ -20,38 +16,18 @@ use yew::prelude::*;
|
|||||||
schema_path = "../schema.graphql",
|
schema_path = "../schema.graphql",
|
||||||
query_path = "queries/get_user_details.graphql",
|
query_path = "queries/get_user_details.graphql",
|
||||||
response_derives = "Debug, Hash, PartialEq, Eq, Clone",
|
response_derives = "Debug, Hash, PartialEq, Eq, Clone",
|
||||||
custom_scalars_module = "crate::infra::graphql",
|
custom_scalars_module = "crate::infra::graphql"
|
||||||
extern_enums("AttributeType")
|
|
||||||
)]
|
)]
|
||||||
pub struct GetUserDetails;
|
pub struct GetUserDetails;
|
||||||
|
|
||||||
pub type User = get_user_details::GetUserDetailsUser;
|
pub type User = get_user_details::GetUserDetailsUser;
|
||||||
pub type Group = get_user_details::GetUserDetailsUserGroups;
|
pub type Group = get_user_details::GetUserDetailsUserGroups;
|
||||||
pub type Attribute = get_user_details::GetUserDetailsUserAttributes;
|
|
||||||
pub type AttributeSchema = get_user_details::GetUserDetailsSchemaUserSchemaAttributes;
|
|
||||||
|
|
||||||
impl From<&AttributeSchema> for GraphQlAttributeSchema {
|
|
||||||
fn from(attr: &AttributeSchema) -> Self {
|
|
||||||
Self {
|
|
||||||
name: attr.name.clone(),
|
|
||||||
is_list: attr.is_list,
|
|
||||||
is_readonly: attr.is_readonly,
|
|
||||||
is_editable: attr.is_editable,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct UserDetails {
|
pub struct UserDetails {
|
||||||
common: CommonComponentParts<Self>,
|
common: CommonComponentParts<Self>,
|
||||||
/// The user info. If none, the error is in `error`. If `error` is None, then we haven't
|
/// The user info. If none, the error is in `error`. If `error` is None, then we haven't
|
||||||
/// received the server response yet.
|
/// received the server response yet.
|
||||||
user_and_schema: Option<(User, Vec<AttributeSchema>)>,
|
user: Option<User>,
|
||||||
}
|
|
||||||
|
|
||||||
impl UserDetails {
|
|
||||||
fn mut_groups(&mut self) -> &mut Vec<Group> {
|
|
||||||
&mut self.user_and_schema.as_mut().unwrap().0.groups
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// State machine describing the possible transitions of the component state.
|
/// State machine describing the possible transitions of the component state.
|
||||||
@@ -74,20 +50,22 @@ impl CommonComponent<UserDetails> for UserDetails {
|
|||||||
fn handle_msg(&mut self, _: &Context<Self>, msg: <Self as Component>::Message) -> Result<bool> {
|
fn handle_msg(&mut self, _: &Context<Self>, msg: <Self as Component>::Message) -> Result<bool> {
|
||||||
match msg {
|
match msg {
|
||||||
Msg::UserDetailsResponse(response) => match response {
|
Msg::UserDetailsResponse(response) => match response {
|
||||||
Ok(user) => {
|
Ok(user) => self.user = Some(user.user),
|
||||||
self.user_and_schema = Some((user.user, user.schema.user_schema.attributes))
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.user_and_schema = None;
|
self.user = None;
|
||||||
bail!("Error getting user details: {}", e);
|
bail!("Error getting user details: {}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Msg::OnError(e) => return Err(e),
|
Msg::OnError(e) => return Err(e),
|
||||||
Msg::OnUserAddedToGroup(group) => {
|
Msg::OnUserAddedToGroup(group) => {
|
||||||
self.mut_groups().push(group);
|
self.user.as_mut().unwrap().groups.push(group);
|
||||||
}
|
}
|
||||||
Msg::OnUserRemovedFromGroup((_, group_id)) => {
|
Msg::OnUserRemovedFromGroup((_, group_id)) => {
|
||||||
self.mut_groups().retain(|g| g.id != group_id);
|
self.user
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.groups
|
||||||
|
.retain(|g| g.id != group_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
@@ -200,7 +178,7 @@ impl Component for UserDetails {
|
|||||||
fn create(ctx: &Context<Self>) -> Self {
|
fn create(ctx: &Context<Self>) -> Self {
|
||||||
let mut table = Self {
|
let mut table = Self {
|
||||||
common: CommonComponentParts::<Self>::create(),
|
common: CommonComponentParts::<Self>::create(),
|
||||||
user_and_schema: None,
|
user: None,
|
||||||
};
|
};
|
||||||
table.get_user_details(ctx);
|
table.get_user_details(ctx);
|
||||||
table
|
table
|
||||||
@@ -211,8 +189,10 @@ impl Component for UserDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
fn view(&self, ctx: &Context<Self>) -> Html {
|
||||||
match (&self.user_and_schema, &self.common.error) {
|
match (&self.user, &self.common.error) {
|
||||||
(Some((u, schema)), error) => {
|
(None, None) => html! {{"Loading..."}},
|
||||||
|
(None, Some(e)) => html! {<div>{"Error: "}{e.to_string()}</div>},
|
||||||
|
(Some(u), error) => {
|
||||||
html! {
|
html! {
|
||||||
<>
|
<>
|
||||||
<h3>{u.id.to_string()}</h3>
|
<h3>{u.id.to_string()}</h3>
|
||||||
@@ -227,20 +207,13 @@ impl Component for UserDetails {
|
|||||||
<div>
|
<div>
|
||||||
<h5 class="row m-3 fw-bold">{"User details"}</h5>
|
<h5 class="row m-3 fw-bold">{"User details"}</h5>
|
||||||
</div>
|
</div>
|
||||||
<UserDetailsForm
|
<UserDetailsForm user={u.clone()} />
|
||||||
user={u.clone()}
|
|
||||||
user_attributes_schema={schema.clone()}
|
|
||||||
is_admin={ctx.props().is_admin}
|
|
||||||
is_edited_user_admin={u.groups.iter().any(|g| g.display_name == "lldap_admin")}
|
|
||||||
/>
|
|
||||||
{self.view_group_memberships(ctx, u)}
|
{self.view_group_memberships(ctx, u)}
|
||||||
{self.view_add_group_button(ctx, u)}
|
{self.view_add_group_button(ctx, u)}
|
||||||
{self.view_messages(error)}
|
{self.view_messages(error)}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, None) => html! {{"Loading..."}},
|
|
||||||
(None, Some(e)) => html! {<div>{"Error: "}{e.to_string()}</div>},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,56 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::user_details::User,
|
||||||
form::{
|
infra::common_component::{CommonComponent, CommonComponentParts},
|
||||||
attribute_input::{ListAttributeInput, SingleAttributeInput},
|
};
|
||||||
static_value::StaticValue,
|
use anyhow::{bail, Error, Result};
|
||||||
submit::Submit,
|
use gloo_file::{
|
||||||
},
|
callbacks::{read_as_bytes, FileReader},
|
||||||
user_details::{Attribute, AttributeSchema, User},
|
File,
|
||||||
},
|
|
||||||
infra::{
|
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
form_utils::{AttributeValue, EmailIsRequired, IsAdmin, read_all_form_attributes},
|
|
||||||
schema::AttributeType,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use anyhow::{Ok, Result};
|
|
||||||
use gloo_console::console;
|
|
||||||
use graphql_client::GraphQLQuery;
|
use graphql_client::GraphQLQuery;
|
||||||
|
use validator_derive::Validate;
|
||||||
|
use web_sys::{FileList, HtmlInputElement, InputEvent};
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
use yew_form_derive::Model;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct JsFile {
|
||||||
|
file: Option<File>,
|
||||||
|
contents: Option<Vec<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToString for JsFile {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
self.file
|
||||||
|
.as_ref()
|
||||||
|
.map(File::name)
|
||||||
|
.unwrap_or_else(String::new)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for JsFile {
|
||||||
|
type Err = Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self> {
|
||||||
|
if s.is_empty() {
|
||||||
|
Ok(JsFile::default())
|
||||||
|
} else {
|
||||||
|
bail!("Building file from non-empty string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The fields of the form, with the editable details and the constraints.
|
||||||
|
#[derive(Model, Validate, PartialEq, Eq, Clone)]
|
||||||
|
pub struct UserModel {
|
||||||
|
#[validate(email)]
|
||||||
|
email: String,
|
||||||
|
display_name: String,
|
||||||
|
first_name: String,
|
||||||
|
last_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
/// The GraphQL query sent to the server to update the user details.
|
/// The GraphQL query sent to the server to update the user details.
|
||||||
#[derive(GraphQLQuery)]
|
#[derive(GraphQLQuery)]
|
||||||
@@ -32,17 +66,23 @@ pub struct UpdateUser;
|
|||||||
/// A [yew::Component] to display the user details, with a form allowing to edit them.
|
/// A [yew::Component] to display the user details, with a form allowing to edit them.
|
||||||
pub struct UserDetailsForm {
|
pub struct UserDetailsForm {
|
||||||
common: CommonComponentParts<Self>,
|
common: CommonComponentParts<Self>,
|
||||||
|
form: yew_form::Form<UserModel>,
|
||||||
|
avatar: JsFile,
|
||||||
|
reader: Option<FileReader>,
|
||||||
/// True if we just successfully updated the user, to display a success message.
|
/// True if we just successfully updated the user, to display a success message.
|
||||||
just_updated: bool,
|
just_updated: bool,
|
||||||
user: User,
|
user: User,
|
||||||
form_ref: NodeRef,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
/// A form field changed.
|
/// A form field changed.
|
||||||
Update,
|
Update,
|
||||||
|
/// A new file was selected.
|
||||||
|
FileSelected(File),
|
||||||
/// The "Submit" button was clicked.
|
/// The "Submit" button was clicked.
|
||||||
SubmitClicked,
|
SubmitClicked,
|
||||||
|
/// A picked file finished loading.
|
||||||
|
FileLoaded(String, Result<Vec<u8>>),
|
||||||
/// We got the response from the server about our update message.
|
/// We got the response from the server about our update message.
|
||||||
UserUpdated(Result<update_user::ResponseData>),
|
UserUpdated(Result<update_user::ResponseData>),
|
||||||
}
|
}
|
||||||
@@ -51,9 +91,6 @@ pub enum Msg {
|
|||||||
pub struct Props {
|
pub struct Props {
|
||||||
/// The current user details.
|
/// The current user details.
|
||||||
pub user: User,
|
pub user: User,
|
||||||
pub user_attributes_schema: Vec<AttributeSchema>,
|
|
||||||
pub is_admin: bool,
|
|
||||||
pub is_edited_user_admin: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommonComponent<UserDetailsForm> for UserDetailsForm {
|
impl CommonComponent<UserDetailsForm> for UserDetailsForm {
|
||||||
@@ -64,12 +101,42 @@ impl CommonComponent<UserDetailsForm> for UserDetailsForm {
|
|||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
match msg {
|
match msg {
|
||||||
Msg::Update => Ok(true),
|
Msg::Update => Ok(true),
|
||||||
Msg::SubmitClicked => self.submit_user_update_form(ctx),
|
Msg::FileSelected(new_avatar) => {
|
||||||
Msg::UserUpdated(Err(e)) => Err(e),
|
if self.avatar.file.as_ref().map(|f| f.name()) != Some(new_avatar.name()) {
|
||||||
Msg::UserUpdated(Result::Ok(_)) => {
|
let file_name = new_avatar.name();
|
||||||
self.just_updated = true;
|
let link = ctx.link().clone();
|
||||||
|
self.reader = Some(read_as_bytes(&new_avatar, move |res| {
|
||||||
|
link.send_message(Msg::FileLoaded(
|
||||||
|
file_name,
|
||||||
|
res.map_err(|e| anyhow::anyhow!("{:#}", e)),
|
||||||
|
))
|
||||||
|
}));
|
||||||
|
self.avatar = JsFile {
|
||||||
|
file: Some(new_avatar),
|
||||||
|
contents: None,
|
||||||
|
};
|
||||||
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
Msg::SubmitClicked => self.submit_user_update_form(ctx),
|
||||||
|
Msg::UserUpdated(response) => self.user_update_finished(response),
|
||||||
|
Msg::FileLoaded(file_name, data) => {
|
||||||
|
if let Some(file) = &self.avatar.file {
|
||||||
|
if file.name() == file_name {
|
||||||
|
let data = data?;
|
||||||
|
if !is_valid_jpeg(data.as_slice()) {
|
||||||
|
// Clear the selection.
|
||||||
|
self.avatar = JsFile::default();
|
||||||
|
bail!("Chosen image is not a valid JPEG");
|
||||||
|
} else {
|
||||||
|
self.avatar.contents = Some(data);
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.reader = None;
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,11 +150,19 @@ impl Component for UserDetailsForm {
|
|||||||
type Properties = Props;
|
type Properties = Props;
|
||||||
|
|
||||||
fn create(ctx: &Context<Self>) -> Self {
|
fn create(ctx: &Context<Self>) -> Self {
|
||||||
|
let model = UserModel {
|
||||||
|
email: ctx.props().user.email.clone(),
|
||||||
|
display_name: ctx.props().user.display_name.clone(),
|
||||||
|
first_name: ctx.props().user.first_name.clone(),
|
||||||
|
last_name: ctx.props().user.last_name.clone(),
|
||||||
|
};
|
||||||
Self {
|
Self {
|
||||||
common: CommonComponentParts::<Self>::create(),
|
common: CommonComponentParts::<Self>::create(),
|
||||||
|
form: yew_form::Form::new(model),
|
||||||
|
avatar: JsFile::default(),
|
||||||
just_updated: false,
|
just_updated: false,
|
||||||
|
reader: None,
|
||||||
user: ctx.props().user.clone(),
|
user: ctx.props().user.clone(),
|
||||||
form_ref: NodeRef::default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,47 +172,156 @@ impl Component for UserDetailsForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
fn view(&self, ctx: &Context<Self>) -> Html {
|
||||||
|
type Field = yew_form::Field<UserModel>;
|
||||||
let link = &ctx.link();
|
let link = &ctx.link();
|
||||||
|
|
||||||
let can_edit =
|
let avatar_base64 = maybe_to_base64(&self.avatar).unwrap_or_default();
|
||||||
|a: &AttributeSchema| (ctx.props().is_admin || a.is_editable) && !a.is_readonly;
|
let avatar_string = avatar_base64
|
||||||
let display_field = |a: &AttributeSchema| {
|
.as_deref()
|
||||||
if can_edit(a) {
|
.or(self.user.avatar.as_deref())
|
||||||
get_custom_attribute_input(a, &self.user.attributes)
|
.unwrap_or("");
|
||||||
} else {
|
|
||||||
get_custom_attribute_static(a, &self.user.attributes)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
html! {
|
html! {
|
||||||
<div class="py-3">
|
<div class="py-3">
|
||||||
<form
|
<form class="form">
|
||||||
class="form"
|
<div class="form-group row mb-3">
|
||||||
ref={self.form_ref.clone()}>
|
<label for="userId"
|
||||||
<StaticValue label="User ID" id="userId">
|
class="form-label col-4 col-form-label">
|
||||||
<i>{&self.user.id}</i>
|
{"User ID: "}
|
||||||
</StaticValue>
|
</label>
|
||||||
{
|
<div class="col-8">
|
||||||
ctx
|
<span id="userId" class="form-control-static"><i>{&self.user.id}</i></span>
|
||||||
.props()
|
</div>
|
||||||
.user_attributes_schema
|
</div>
|
||||||
.iter()
|
<div class="form-group row mb-3">
|
||||||
.filter(|a| a.is_hardcoded && a.name != "user_id")
|
<label for="creationDate"
|
||||||
.map(display_field)
|
class="form-label col-4 col-form-label">
|
||||||
.collect::<Vec<_>>()
|
{"Creation date: "}
|
||||||
}
|
</label>
|
||||||
{
|
<div class="col-8">
|
||||||
ctx
|
<span id="creationDate" class="form-control-static">{&self.user.creation_date.naive_local().date()}</span>
|
||||||
.props()
|
</div>
|
||||||
.user_attributes_schema
|
</div>
|
||||||
.iter()
|
<div class="form-group row mb-3">
|
||||||
.filter(|a| !a.is_hardcoded)
|
<label for="uuid"
|
||||||
.map(display_field)
|
class="form-label col-4 col-form-label">
|
||||||
.collect::<Vec<_>>()
|
{"UUID: "}
|
||||||
}
|
</label>
|
||||||
<Submit
|
<div class="col-8">
|
||||||
text="Save changes"
|
<span id="creationDate" class="form-control-static">{&self.user.uuid}</span>
|
||||||
disabled={self.common.is_task_running()}
|
</div>
|
||||||
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::SubmitClicked})} />
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="email"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"Email"}
|
||||||
|
<span class="text-danger">{"*"}</span>
|
||||||
|
{":"}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
form={&self.form}
|
||||||
|
field_name="email"
|
||||||
|
autocomplete="email"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("email")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="display_name"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"Display Name: "}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
class="form-control"
|
||||||
|
class_invalid="is-invalid has-error"
|
||||||
|
class_valid="has-success"
|
||||||
|
form={&self.form}
|
||||||
|
field_name="display_name"
|
||||||
|
autocomplete="name"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("display_name")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="first_name"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"First Name: "}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
class="form-control"
|
||||||
|
form={&self.form}
|
||||||
|
field_name="first_name"
|
||||||
|
autocomplete="given-name"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("first_name")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mb-3">
|
||||||
|
<label for="last_name"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"Last Name: "}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<Field
|
||||||
|
class="form-control"
|
||||||
|
form={&self.form}
|
||||||
|
field_name="last_name"
|
||||||
|
autocomplete="family-name"
|
||||||
|
oninput={link.callback(|_| Msg::Update)} />
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{&self.form.field_message("last_name")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row align-items-center mb-3">
|
||||||
|
<label for="avatar"
|
||||||
|
class="form-label col-4 col-form-label">
|
||||||
|
{"Avatar: "}
|
||||||
|
</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-8">
|
||||||
|
<input
|
||||||
|
class="form-control"
|
||||||
|
id="avatarInput"
|
||||||
|
type="file"
|
||||||
|
accept="image/jpeg"
|
||||||
|
oninput={link.callback(|e: InputEvent| {
|
||||||
|
let input: HtmlInputElement = e.target_unchecked_into();
|
||||||
|
Self::upload_files(input.files())
|
||||||
|
})} />
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<img
|
||||||
|
id="avatarDisplay"
|
||||||
|
src={format!("data:image/jpeg;base64, {}", avatar_string)}
|
||||||
|
style="max-height:128px;max-width:128px;height:auto;width:auto;"
|
||||||
|
alt="Avatar" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-center mt-3">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="btn btn-primary col-auto col-form-label"
|
||||||
|
disabled={self.common.is_task_running()}
|
||||||
|
onclick={link.callback(|e: MouseEvent| {e.prevent_default(); Msg::SubmitClicked})}>
|
||||||
|
<i class="bi-save me-2"></i>
|
||||||
|
{"Save changes"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{
|
{
|
||||||
if let Some(e) = &self.common.error {
|
if let Some(e) = &self.common.error {
|
||||||
@@ -156,107 +340,19 @@ impl Component for UserDetailsForm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_custom_attribute_input(
|
|
||||||
attribute_schema: &AttributeSchema,
|
|
||||||
user_attributes: &[Attribute],
|
|
||||||
) -> Html {
|
|
||||||
let values = user_attributes
|
|
||||||
.iter()
|
|
||||||
.find(|a| a.name == attribute_schema.name)
|
|
||||||
.map(|attribute| attribute.value.clone())
|
|
||||||
.unwrap_or_default();
|
|
||||||
if attribute_schema.is_list {
|
|
||||||
html! {
|
|
||||||
<ListAttributeInput
|
|
||||||
name={attribute_schema.name.clone()}
|
|
||||||
attribute_type={attribute_schema.attribute_type}
|
|
||||||
values={values}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
html! {
|
|
||||||
<SingleAttributeInput
|
|
||||||
name={attribute_schema.name.clone()}
|
|
||||||
attribute_type={attribute_schema.attribute_type}
|
|
||||||
value={values.first().cloned().unwrap_or_default()}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_custom_attribute_static(
|
|
||||||
attribute_schema: &AttributeSchema,
|
|
||||||
user_attributes: &[Attribute],
|
|
||||||
) -> Html {
|
|
||||||
let values = user_attributes
|
|
||||||
.iter()
|
|
||||||
.find(|a| a.name == attribute_schema.name)
|
|
||||||
.map(|attribute| attribute.value.clone())
|
|
||||||
.unwrap_or_default();
|
|
||||||
let value_to_str = match attribute_schema.attribute_type {
|
|
||||||
AttributeType::String | AttributeType::Integer => |v: String| v,
|
|
||||||
AttributeType::DateTime => |v: String| {
|
|
||||||
console!(format!("Parsing date: {}", &v));
|
|
||||||
chrono::DateTime::parse_from_rfc3339(&v)
|
|
||||||
.map(|dt| dt.naive_utc().to_string())
|
|
||||||
.unwrap_or_else(|_| "Invalid date".to_string())
|
|
||||||
},
|
|
||||||
AttributeType::JpegPhoto => |_: String| "Unimplemented JPEG display".to_string(),
|
|
||||||
};
|
|
||||||
html! {
|
|
||||||
<StaticValue label={attribute_schema.name.clone()} id={attribute_schema.name.clone()}>
|
|
||||||
{values.into_iter().map(|x| html!{<div>{value_to_str(x)}</div>}).collect::<Vec<_>>()}
|
|
||||||
</StaticValue>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserDetailsForm {
|
impl UserDetailsForm {
|
||||||
fn submit_user_update_form(&mut self, ctx: &Context<Self>) -> Result<bool> {
|
fn submit_user_update_form(&mut self, ctx: &Context<Self>) -> Result<bool> {
|
||||||
// TODO: Handle unloaded files.
|
if !self.form.validate() {
|
||||||
// if let Some(JsFile {
|
bail!("Invalid inputs");
|
||||||
// file: Some(_),
|
}
|
||||||
// contents: None,
|
if let JsFile {
|
||||||
// }) = &self.avatar
|
file: Some(_),
|
||||||
// {
|
contents: None,
|
||||||
// bail!("Image file hasn't finished loading, try again");
|
} = &self.avatar
|
||||||
// }
|
{
|
||||||
let mut all_values = read_all_form_attributes(
|
bail!("Image file hasn't finished loading, try again");
|
||||||
ctx.props().user_attributes_schema.iter(),
|
}
|
||||||
&self.form_ref,
|
let base_user = &self.user;
|
||||||
IsAdmin(ctx.props().is_admin),
|
|
||||||
EmailIsRequired(!ctx.props().is_edited_user_admin),
|
|
||||||
)?;
|
|
||||||
let base_attributes = &self.user.attributes;
|
|
||||||
all_values.retain(|a| {
|
|
||||||
let base_val = base_attributes
|
|
||||||
.iter()
|
|
||||||
.find(|base_val| base_val.name == a.name);
|
|
||||||
base_val
|
|
||||||
.map(|v| v.value != a.values)
|
|
||||||
.unwrap_or(!a.values.is_empty())
|
|
||||||
});
|
|
||||||
let remove_attributes: Option<Vec<String>> = if all_values.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(all_values.iter().map(|a| a.name.clone()).collect())
|
|
||||||
};
|
|
||||||
let insert_attributes: Option<Vec<update_user::AttributeValueInput>> =
|
|
||||||
if remove_attributes.is_none() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(
|
|
||||||
all_values
|
|
||||||
.into_iter()
|
|
||||||
.filter(|a| !a.values.is_empty())
|
|
||||||
.map(
|
|
||||||
|AttributeValue { name, values }| update_user::AttributeValueInput {
|
|
||||||
name,
|
|
||||||
value: values,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
let mut user_input = update_user::UpdateUserInput {
|
let mut user_input = update_user::UpdateUserInput {
|
||||||
id: self.user.id.clone(),
|
id: self.user.id.clone(),
|
||||||
email: None,
|
email: None,
|
||||||
@@ -264,12 +360,23 @@ impl UserDetailsForm {
|
|||||||
firstName: None,
|
firstName: None,
|
||||||
lastName: None,
|
lastName: None,
|
||||||
avatar: None,
|
avatar: None,
|
||||||
removeAttributes: None,
|
|
||||||
insertAttributes: None,
|
|
||||||
};
|
};
|
||||||
let default_user_input = user_input.clone();
|
let default_user_input = user_input.clone();
|
||||||
user_input.removeAttributes = remove_attributes;
|
let model = self.form.model();
|
||||||
user_input.insertAttributes = insert_attributes;
|
let email = model.email;
|
||||||
|
if base_user.email != email {
|
||||||
|
user_input.email = Some(email);
|
||||||
|
}
|
||||||
|
if base_user.display_name != model.display_name {
|
||||||
|
user_input.displayName = Some(model.display_name);
|
||||||
|
}
|
||||||
|
if base_user.first_name != model.first_name {
|
||||||
|
user_input.firstName = Some(model.first_name);
|
||||||
|
}
|
||||||
|
if base_user.last_name != model.last_name {
|
||||||
|
user_input.lastName = Some(model.last_name);
|
||||||
|
}
|
||||||
|
user_input.avatar = maybe_to_base64(&self.avatar)?;
|
||||||
// Nothing changed.
|
// Nothing changed.
|
||||||
if user_input == default_user_input {
|
if user_input == default_user_input {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
@@ -283,4 +390,58 @@ impl UserDetailsForm {
|
|||||||
);
|
);
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn user_update_finished(&mut self, r: Result<update_user::ResponseData>) -> Result<bool> {
|
||||||
|
r?;
|
||||||
|
let model = self.form.model();
|
||||||
|
self.user.email = model.email;
|
||||||
|
self.user.display_name = model.display_name;
|
||||||
|
self.user.first_name = model.first_name;
|
||||||
|
self.user.last_name = model.last_name;
|
||||||
|
if let Some(avatar) = maybe_to_base64(&self.avatar)? {
|
||||||
|
self.user.avatar = Some(avatar);
|
||||||
|
}
|
||||||
|
self.just_updated = true;
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn upload_files(files: Option<FileList>) -> Msg {
|
||||||
|
if let Some(files) = files {
|
||||||
|
if files.length() > 0 {
|
||||||
|
Msg::FileSelected(File::from(files.item(0).unwrap()))
|
||||||
|
} else {
|
||||||
|
Msg::Update
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Msg::Update
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_valid_jpeg(bytes: &[u8]) -> bool {
|
||||||
|
image::io::Reader::with_format(std::io::Cursor::new(bytes), image::ImageFormat::Jpeg)
|
||||||
|
.decode()
|
||||||
|
.is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn maybe_to_base64(file: &JsFile) -> Result<Option<String>> {
|
||||||
|
match file {
|
||||||
|
JsFile {
|
||||||
|
file: None,
|
||||||
|
contents: _,
|
||||||
|
} => Ok(None),
|
||||||
|
JsFile {
|
||||||
|
file: Some(_),
|
||||||
|
contents: None,
|
||||||
|
} => bail!("Image file hasn't finished loading, try again"),
|
||||||
|
JsFile {
|
||||||
|
file: Some(_),
|
||||||
|
contents: Some(data),
|
||||||
|
} => {
|
||||||
|
if !is_valid_jpeg(data.as_slice()) {
|
||||||
|
bail!("Chosen image is not a valid JPEG");
|
||||||
|
}
|
||||||
|
Ok(Some(base64::encode(data)))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,199 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
components::{
|
|
||||||
delete_user_attribute::DeleteUserAttribute,
|
|
||||||
fragments::attribute_schema::render_attribute_name,
|
|
||||||
router::{AppRoute, Link},
|
|
||||||
},
|
|
||||||
infra::{
|
|
||||||
attributes::user,
|
|
||||||
common_component::{CommonComponent, CommonComponentParts},
|
|
||||||
schema::AttributeType,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use anyhow::{Error, Result, anyhow};
|
|
||||||
use gloo_console::log;
|
|
||||||
use graphql_client::GraphQLQuery;
|
|
||||||
use yew::prelude::*;
|
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
|
||||||
#[graphql(
|
|
||||||
schema_path = "../schema.graphql",
|
|
||||||
query_path = "queries/get_user_attributes_schema.graphql",
|
|
||||||
response_derives = "Debug,Clone,PartialEq,Eq",
|
|
||||||
custom_scalars_module = "crate::infra::graphql",
|
|
||||||
extern_enums("AttributeType")
|
|
||||||
)]
|
|
||||||
pub struct GetUserAttributesSchema;
|
|
||||||
|
|
||||||
use get_user_attributes_schema::ResponseData;
|
|
||||||
|
|
||||||
pub type Attribute = get_user_attributes_schema::GetUserAttributesSchemaSchemaUserSchemaAttributes;
|
|
||||||
|
|
||||||
#[derive(yew::Properties, Clone, PartialEq, Eq)]
|
|
||||||
pub struct Props {
|
|
||||||
pub hardcoded: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct UserSchemaTable {
|
|
||||||
common: CommonComponentParts<Self>,
|
|
||||||
attributes: Option<Vec<Attribute>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Msg {
|
|
||||||
ListAttributesResponse(Result<ResponseData>),
|
|
||||||
OnAttributeDeleted(String),
|
|
||||||
OnError(Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommonComponent<UserSchemaTable> for UserSchemaTable {
|
|
||||||
fn handle_msg(&mut self, _: &Context<Self>, msg: <Self as Component>::Message) -> Result<bool> {
|
|
||||||
match msg {
|
|
||||||
Msg::ListAttributesResponse(schema) => {
|
|
||||||
self.attributes = Some(schema?.schema.user_schema.attributes.into_iter().collect());
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
Msg::OnError(e) => Err(e),
|
|
||||||
Msg::OnAttributeDeleted(attribute_name) => match self.attributes {
|
|
||||||
None => {
|
|
||||||
log!(format!(
|
|
||||||
"Attribute {attribute_name} was deleted but component has no attributes"
|
|
||||||
));
|
|
||||||
Err(anyhow!("invalid state"))
|
|
||||||
}
|
|
||||||
Some(_) => {
|
|
||||||
self.attributes
|
|
||||||
.as_mut()
|
|
||||||
.unwrap()
|
|
||||||
.retain(|a| a.name != attribute_name);
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mut_common(&mut self) -> &mut CommonComponentParts<Self> {
|
|
||||||
&mut self.common
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for UserSchemaTable {
|
|
||||||
type Message = Msg;
|
|
||||||
type Properties = Props;
|
|
||||||
|
|
||||||
fn create(ctx: &Context<Self>) -> Self {
|
|
||||||
let mut table = UserSchemaTable {
|
|
||||||
common: CommonComponentParts::<Self>::create(),
|
|
||||||
attributes: None,
|
|
||||||
};
|
|
||||||
table.common.call_graphql::<GetUserAttributesSchema, _>(
|
|
||||||
ctx,
|
|
||||||
get_user_attributes_schema::Variables {},
|
|
||||||
Msg::ListAttributesResponse,
|
|
||||||
"Error trying to fetch user schema",
|
|
||||||
);
|
|
||||||
table
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
||||||
CommonComponentParts::<Self>::update(self, ctx, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
html! {
|
|
||||||
<div>
|
|
||||||
{self.view_attributes(ctx)}
|
|
||||||
{self.view_errors()}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserSchemaTable {
|
|
||||||
fn view_attributes(&self, ctx: &Context<Self>) -> Html {
|
|
||||||
let hardcoded = ctx.props().hardcoded;
|
|
||||||
let make_table = |attributes: &Vec<Attribute>| {
|
|
||||||
html! {
|
|
||||||
<div class="table-responsive">
|
|
||||||
<h3>{if hardcoded {"Hardcoded"} else {"User-defined"}}{" attributes"}</h3>
|
|
||||||
<table class="table table-hover">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>{"Attribute name"}</th>
|
|
||||||
<th>{"Type"}</th>
|
|
||||||
<th>{"Editable"}</th>
|
|
||||||
<th>{"Visible"}</th>
|
|
||||||
{if hardcoded {html!{}} else {html!{<th>{"Delete"}</th>}}}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{attributes.iter().map(|u| self.view_attribute(ctx, u)).collect::<Vec<_>>()}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
};
|
|
||||||
match &self.attributes {
|
|
||||||
None => html! {{"Loading..."}},
|
|
||||||
Some(attributes) => {
|
|
||||||
let mut attributes = attributes.clone();
|
|
||||||
attributes.retain(|attribute| attribute.is_hardcoded == ctx.props().hardcoded);
|
|
||||||
make_table(&attributes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_attribute(&self, ctx: &Context<Self>, attribute: &Attribute) -> Html {
|
|
||||||
let link = ctx.link();
|
|
||||||
let attribute_type = attribute.attribute_type;
|
|
||||||
let checkmark = html! {
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check" viewBox="0 0 16 16">
|
|
||||||
<path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425z"></path>
|
|
||||||
</svg>
|
|
||||||
};
|
|
||||||
let hardcoded = ctx.props().hardcoded;
|
|
||||||
let desc = user::resolve_user_attribute_description_or_default(&attribute.name);
|
|
||||||
html! {
|
|
||||||
<tr key={attribute.name.clone()}>
|
|
||||||
<td>{render_attribute_name(hardcoded, &desc)}</td>
|
|
||||||
<td>{if attribute.is_list { format!("List<{attribute_type}>")} else {attribute_type.to_string()}}</td>
|
|
||||||
<td>{if attribute.is_editable {checkmark.clone()} else {html!{}}}</td>
|
|
||||||
<td>{if attribute.is_visible {checkmark.clone()} else {html!{}}}</td>
|
|
||||||
{
|
|
||||||
if hardcoded {
|
|
||||||
html!{}
|
|
||||||
} else {
|
|
||||||
html!{
|
|
||||||
<td>
|
|
||||||
<DeleteUserAttribute
|
|
||||||
attribute_name={attribute.name.clone()}
|
|
||||||
on_attribute_deleted={link.callback(Msg::OnAttributeDeleted)}
|
|
||||||
on_error={link.callback(Msg::OnError)}/>
|
|
||||||
</td>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_errors(&self) -> Html {
|
|
||||||
match &self.common.error {
|
|
||||||
None => html! {},
|
|
||||||
Some(e) => html! {<div>{"Error: "}{e.to_string()}</div>},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(ListUserSchema)]
|
|
||||||
pub fn list_user_schema() -> Html {
|
|
||||||
html! {
|
|
||||||
<div>
|
|
||||||
<UserSchemaTable hardcoded={true} />
|
|
||||||
<UserSchemaTable hardcoded={false} />
|
|
||||||
<Link classes="btn btn-primary" to={AppRoute::CreateUserAttribute}>
|
|
||||||
<i class="bi-plus-circle me-2"></i>
|
|
||||||
{"Create an attribute"}
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+89
-63
@@ -1,11 +1,10 @@
|
|||||||
use super::cookies::set_cookie;
|
use crate::infra::cookies::set_cookie;
|
||||||
use anyhow::{Context, Result, anyhow};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use gloo_net::http::{Method, RequestBuilder};
|
use gloo_net::http::{Method, Request};
|
||||||
use graphql_client::GraphQLQuery;
|
use graphql_client::GraphQLQuery;
|
||||||
use lldap_auth::{JWTClaims, login, registration};
|
use lldap_auth::{login, registration, JWTClaims};
|
||||||
|
|
||||||
use lldap_frontend_options::Options;
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use serde::{Serialize, de::DeserializeOwned};
|
|
||||||
use web_sys::RequestCredentials;
|
use web_sys::RequestCredentials;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -17,32 +16,21 @@ fn get_claims_from_jwt(jwt: &str) -> Result<JWTClaims> {
|
|||||||
Ok(token.claims().clone())
|
Ok(token.claims().clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RequestType<Body: Serialize> {
|
const NO_BODY: Option<()> = None;
|
||||||
Get,
|
|
||||||
Post(Body),
|
|
||||||
}
|
|
||||||
|
|
||||||
const GET_REQUEST: RequestType<()> = RequestType::Get;
|
async fn call_server(
|
||||||
|
|
||||||
fn base_url() -> String {
|
|
||||||
yew_router::utils::base_url().unwrap_or_default()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn call_server<Body: Serialize>(
|
|
||||||
url: &str,
|
url: &str,
|
||||||
body: RequestType<Body>,
|
body: Option<impl Serialize>,
|
||||||
error_message: &'static str,
|
error_message: &'static str,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
let request_builder = RequestBuilder::new(url)
|
let mut request = Request::new(url)
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.credentials(RequestCredentials::SameOrigin);
|
.credentials(RequestCredentials::SameOrigin);
|
||||||
let request = if let RequestType::Post(b) = body {
|
if let Some(b) = body {
|
||||||
request_builder
|
request = request
|
||||||
.method(Method::POST)
|
.body(serde_json::to_string(&b)?)
|
||||||
.body(serde_json::to_string(&b)?)?
|
.method(Method::POST);
|
||||||
} else {
|
}
|
||||||
request_builder.build()?
|
|
||||||
};
|
|
||||||
let response = request.send().await?;
|
let response = request.send().await?;
|
||||||
if response.ok() {
|
if response.ok() {
|
||||||
Ok(response.text().await?)
|
Ok(response.text().await?)
|
||||||
@@ -59,7 +47,7 @@ async fn call_server<Body: Serialize>(
|
|||||||
|
|
||||||
async fn call_server_json_with_error_message<CallbackResult, Body: Serialize>(
|
async fn call_server_json_with_error_message<CallbackResult, Body: Serialize>(
|
||||||
url: &str,
|
url: &str,
|
||||||
request: RequestType<Body>,
|
request: Option<Body>,
|
||||||
error_message: &'static str,
|
error_message: &'static str,
|
||||||
) -> Result<CallbackResult>
|
) -> Result<CallbackResult>
|
||||||
where
|
where
|
||||||
@@ -71,7 +59,7 @@ where
|
|||||||
|
|
||||||
async fn call_server_empty_response_with_error_message<Body: Serialize>(
|
async fn call_server_empty_response_with_error_message<Body: Serialize>(
|
||||||
url: &str,
|
url: &str,
|
||||||
request: RequestType<Body>,
|
request: Option<Body>,
|
||||||
error_message: &'static str,
|
error_message: &'static str,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
call_server(url, request, error_message).await.map(|_| ())
|
call_server(url, request, error_message).await.map(|_| ())
|
||||||
@@ -86,6 +74,19 @@ fn set_cookies_from_jwt(response: login::ServerLoginResponse) -> Result<(String,
|
|||||||
.context("Error setting cookie")
|
.context("Error setting cookie")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
pub struct PasswordHash(String);
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
pub struct PasswordWasLeaked(pub bool);
|
||||||
|
|
||||||
|
pub fn hash_password(password: &str) -> PasswordHash {
|
||||||
|
use sha1::{Digest, Sha1};
|
||||||
|
let mut hasher = Sha1::new();
|
||||||
|
hasher.update(password);
|
||||||
|
PasswordHash(format!("{:X}", hasher.finalize()))
|
||||||
|
}
|
||||||
|
|
||||||
impl HostService {
|
impl HostService {
|
||||||
pub async fn graphql_query<QueryType>(
|
pub async fn graphql_query<QueryType>(
|
||||||
variables: QueryType::Variables,
|
variables: QueryType::Variables,
|
||||||
@@ -109,8 +110,8 @@ impl HostService {
|
|||||||
};
|
};
|
||||||
let request_body = QueryType::build_query(variables);
|
let request_body = QueryType::build_query(variables);
|
||||||
call_server_json_with_error_message::<graphql_client::Response<_>, _>(
|
call_server_json_with_error_message::<graphql_client::Response<_>, _>(
|
||||||
&(base_url() + "/api/graphql"),
|
"/api/graphql",
|
||||||
RequestType::Post(request_body),
|
Some(request_body),
|
||||||
error_message,
|
error_message,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -121,8 +122,8 @@ impl HostService {
|
|||||||
request: login::ClientLoginStartRequest,
|
request: login::ClientLoginStartRequest,
|
||||||
) -> Result<Box<login::ServerLoginStartResponse>> {
|
) -> Result<Box<login::ServerLoginStartResponse>> {
|
||||||
call_server_json_with_error_message(
|
call_server_json_with_error_message(
|
||||||
&(base_url() + "/auth/opaque/login/start"),
|
"/auth/opaque/login/start",
|
||||||
RequestType::Post(request),
|
Some(request),
|
||||||
"Could not start authentication: ",
|
"Could not start authentication: ",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -130,29 +131,20 @@ impl HostService {
|
|||||||
|
|
||||||
pub async fn login_finish(request: login::ClientLoginFinishRequest) -> Result<(String, bool)> {
|
pub async fn login_finish(request: login::ClientLoginFinishRequest) -> Result<(String, bool)> {
|
||||||
call_server_json_with_error_message::<login::ServerLoginResponse, _>(
|
call_server_json_with_error_message::<login::ServerLoginResponse, _>(
|
||||||
&(base_url() + "/auth/opaque/login/finish"),
|
"/auth/opaque/login/finish",
|
||||||
RequestType::Post(request),
|
Some(request),
|
||||||
"Could not finish authentication",
|
"Could not finish authentication",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.and_then(set_cookies_from_jwt)
|
.and_then(set_cookies_from_jwt)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_settings() -> Result<Options> {
|
|
||||||
call_server_json_with_error_message::<Options, _>(
|
|
||||||
&(base_url() + "/settings"),
|
|
||||||
GET_REQUEST,
|
|
||||||
"Could not fetch settings: ",
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn register_start(
|
pub async fn register_start(
|
||||||
request: registration::ClientRegistrationStartRequest,
|
request: registration::ClientRegistrationStartRequest,
|
||||||
) -> Result<Box<registration::ServerRegistrationStartResponse>> {
|
) -> Result<Box<registration::ServerRegistrationStartResponse>> {
|
||||||
call_server_json_with_error_message(
|
call_server_json_with_error_message(
|
||||||
&(base_url() + "/auth/opaque/register/start"),
|
"/auth/opaque/register/start",
|
||||||
RequestType::Post(request),
|
Some(request),
|
||||||
"Could not start registration: ",
|
"Could not start registration: ",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -162,8 +154,8 @@ impl HostService {
|
|||||||
request: registration::ClientRegistrationFinishRequest,
|
request: registration::ClientRegistrationFinishRequest,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
call_server_empty_response_with_error_message(
|
call_server_empty_response_with_error_message(
|
||||||
&(base_url() + "/auth/opaque/register/finish"),
|
"/auth/opaque/register/finish",
|
||||||
RequestType::Post(request),
|
Some(request),
|
||||||
"Could not finish registration",
|
"Could not finish registration",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -171,8 +163,8 @@ impl HostService {
|
|||||||
|
|
||||||
pub async fn refresh() -> Result<(String, bool)> {
|
pub async fn refresh() -> Result<(String, bool)> {
|
||||||
call_server_json_with_error_message::<login::ServerLoginResponse, _>(
|
call_server_json_with_error_message::<login::ServerLoginResponse, _>(
|
||||||
&(base_url() + "/auth/refresh"),
|
"/auth/refresh",
|
||||||
GET_REQUEST,
|
NO_BODY,
|
||||||
"Could not start authentication: ",
|
"Could not start authentication: ",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -181,22 +173,14 @@ impl HostService {
|
|||||||
|
|
||||||
// The `_request` parameter is to make it the same shape as the other functions.
|
// The `_request` parameter is to make it the same shape as the other functions.
|
||||||
pub async fn logout() -> Result<()> {
|
pub async fn logout() -> Result<()> {
|
||||||
call_server_empty_response_with_error_message(
|
call_server_empty_response_with_error_message("/auth/logout", NO_BODY, "Could not logout")
|
||||||
&(base_url() + "/auth/logout"),
|
.await
|
||||||
GET_REQUEST,
|
|
||||||
"Could not logout",
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn reset_password_step1(username: String) -> Result<()> {
|
pub async fn reset_password_step1(username: String) -> Result<()> {
|
||||||
call_server_empty_response_with_error_message(
|
call_server_empty_response_with_error_message(
|
||||||
&format!(
|
&format!("/auth/reset/step1/{}", url_escape::encode_query(&username)),
|
||||||
"{}/auth/reset/step1/{}",
|
NO_BODY,
|
||||||
base_url(),
|
|
||||||
url_escape::encode_query(&username)
|
|
||||||
),
|
|
||||||
RequestType::Post(""),
|
|
||||||
"Could not initiate password reset",
|
"Could not initiate password reset",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -206,10 +190,52 @@ impl HostService {
|
|||||||
token: String,
|
token: String,
|
||||||
) -> Result<lldap_auth::password_reset::ServerPasswordResetResponse> {
|
) -> Result<lldap_auth::password_reset::ServerPasswordResetResponse> {
|
||||||
call_server_json_with_error_message(
|
call_server_json_with_error_message(
|
||||||
&format!("{}/auth/reset/step2/{}", base_url(), token),
|
&format!("/auth/reset/step2/{}", token),
|
||||||
GET_REQUEST,
|
NO_BODY,
|
||||||
"Could not validate token",
|
"Could not validate token",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn probe_password_reset() -> Result<bool> {
|
||||||
|
Ok(
|
||||||
|
gloo_net::http::Request::get("/auth/reset/step1/lldap_unlikely_very_long_user_name")
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.status()
|
||||||
|
!= http::StatusCode::NOT_FOUND,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn check_password_haveibeenpwned(
|
||||||
|
password_hash: PasswordHash,
|
||||||
|
) -> Result<(Option<PasswordWasLeaked>, PasswordHash)> {
|
||||||
|
use lldap_auth::password_reset::*;
|
||||||
|
let hash_prefix = &password_hash.0[0..5];
|
||||||
|
match call_server_json_with_error_message::<PasswordHashList, _>(
|
||||||
|
&format!("/auth/password/check/{}", hash_prefix),
|
||||||
|
NO_BODY,
|
||||||
|
"Could not validate token",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(r) => {
|
||||||
|
for PasswordHashCount { hash, count } in r.hashes {
|
||||||
|
if password_hash.0[5..] == hash && count != 0 {
|
||||||
|
return Ok((Some(PasswordWasLeaked(true)), password_hash));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok((Some(PasswordWasLeaked(false)), password_hash))
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
if e.to_string().contains("[501]:") {
|
||||||
|
// Unimplemented, no API key.
|
||||||
|
Ok((None, password_hash))
|
||||||
|
} else {
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
pub struct AttributeDescription<'a> {
|
|
||||||
pub attribute_identifier: &'a str,
|
|
||||||
pub attribute_name: &'a str,
|
|
||||||
pub aliases: Vec<&'a str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod group {
|
|
||||||
|
|
||||||
use super::AttributeDescription;
|
|
||||||
|
|
||||||
pub fn resolve_group_attribute_description(name: &str) -> Option<AttributeDescription> {
|
|
||||||
match name {
|
|
||||||
"creation_date" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: "creationdate",
|
|
||||||
aliases: vec![name, "createtimestamp", "modifytimestamp"],
|
|
||||||
}),
|
|
||||||
"display_name" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: "displayname",
|
|
||||||
aliases: vec![name, "cn", "uid", "id"],
|
|
||||||
}),
|
|
||||||
"group_id" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: "groupid",
|
|
||||||
aliases: vec![name],
|
|
||||||
}),
|
|
||||||
"uuid" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: name,
|
|
||||||
aliases: vec!["entryuuid"],
|
|
||||||
}),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn resolve_group_attribute_description_or_default(name: &str) -> AttributeDescription {
|
|
||||||
match resolve_group_attribute_description(name) {
|
|
||||||
Some(d) => d,
|
|
||||||
None => AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: name,
|
|
||||||
aliases: vec![],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod user {
|
|
||||||
|
|
||||||
use super::AttributeDescription;
|
|
||||||
|
|
||||||
pub fn resolve_user_attribute_description(name: &str) -> Option<AttributeDescription> {
|
|
||||||
match name {
|
|
||||||
"avatar" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: name,
|
|
||||||
aliases: vec!["jpegphoto"],
|
|
||||||
}),
|
|
||||||
"creation_date" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: "creationdate",
|
|
||||||
aliases: vec![name, "createtimestamp", "modifytimestamp"],
|
|
||||||
}),
|
|
||||||
"display_name" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: "displayname",
|
|
||||||
aliases: vec![name, "cn"],
|
|
||||||
}),
|
|
||||||
"first_name" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: "firstname",
|
|
||||||
aliases: vec![name, "givenname"],
|
|
||||||
}),
|
|
||||||
"last_name" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: "lastname",
|
|
||||||
aliases: vec![name, "sn"],
|
|
||||||
}),
|
|
||||||
"mail" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: name,
|
|
||||||
aliases: vec!["email"],
|
|
||||||
}),
|
|
||||||
"user_id" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: "uid",
|
|
||||||
aliases: vec![name, "id"],
|
|
||||||
}),
|
|
||||||
"uuid" => Some(AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: name,
|
|
||||||
aliases: vec!["entryuuid"],
|
|
||||||
}),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn resolve_user_attribute_description_or_default(name: &str) -> AttributeDescription {
|
|
||||||
match resolve_user_attribute_description(name) {
|
|
||||||
Some(d) => d,
|
|
||||||
None => AttributeDescription {
|
|
||||||
attribute_identifier: name,
|
|
||||||
attribute_name: name,
|
|
||||||
aliases: vec![],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{Result, anyhow};
|
use anyhow::{anyhow, Result};
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
use web_sys::HtmlDocument;
|
use web_sys::HtmlDocument;
|
||||||
@@ -22,11 +22,10 @@ pub fn set_cookie(cookie_name: &str, value: &str, expiration: &DateTime<Utc>) ->
|
|||||||
.map_err(|_| anyhow!("Document is not an HTMLDocument"))
|
.map_err(|_| anyhow!("Document is not an HTMLDocument"))
|
||||||
})?;
|
})?;
|
||||||
let cookie_string = format!(
|
let cookie_string = format!(
|
||||||
"{}={}; expires={}; sameSite=Strict; path={}/",
|
"{}={}; expires={}; sameSite=Strict; path=/",
|
||||||
cookie_name,
|
cookie_name,
|
||||||
value,
|
value,
|
||||||
expiration.to_rfc2822(),
|
expiration.to_rfc2822()
|
||||||
yew_router::utils::base_url().unwrap_or_default()
|
|
||||||
);
|
);
|
||||||
doc.set_cookie(&cookie_string)
|
doc.set_cookie(&cookie_string)
|
||||||
.map_err(|_| anyhow!("Could not set cookie"))
|
.map_err(|_| anyhow!("Could not set cookie"))
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
use anyhow::{Result, anyhow, ensure};
|
|
||||||
use validator::validate_email;
|
|
||||||
use web_sys::{FormData, HtmlFormElement};
|
|
||||||
use yew::NodeRef;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AttributeValue {
|
|
||||||
pub name: String,
|
|
||||||
pub values: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GraphQlAttributeSchema {
|
|
||||||
pub name: String,
|
|
||||||
pub is_list: bool,
|
|
||||||
pub is_readonly: bool,
|
|
||||||
pub is_editable: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn validate_email_attributes(all_values: &[AttributeValue]) -> Result<()> {
|
|
||||||
let maybe_email_values = all_values.iter().find(|a| a.name == "mail");
|
|
||||||
let email_values = &maybe_email_values
|
|
||||||
.ok_or_else(|| anyhow!("Email is required"))?
|
|
||||||
.values;
|
|
||||||
ensure!(!email_values.is_empty(), "Email is required");
|
|
||||||
ensure!(email_values.len() == 1, "Multiple emails are not supported");
|
|
||||||
ensure!(validate_email(&email_values[0]), "Email is not valid");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct IsAdmin(pub bool);
|
|
||||||
pub struct EmailIsRequired(pub bool);
|
|
||||||
|
|
||||||
pub fn read_all_form_attributes(
|
|
||||||
schema: impl IntoIterator<Item = impl Into<GraphQlAttributeSchema>>,
|
|
||||||
form_ref: &NodeRef,
|
|
||||||
is_admin: IsAdmin,
|
|
||||||
email_is_required: EmailIsRequired,
|
|
||||||
) -> Result<Vec<AttributeValue>> {
|
|
||||||
let form = form_ref.cast::<HtmlFormElement>().unwrap();
|
|
||||||
let form_data = FormData::new_with_form(&form)
|
|
||||||
.map_err(|e| anyhow!("Failed to get FormData: {:#?}", e.as_string()))?;
|
|
||||||
let all_values = schema
|
|
||||||
.into_iter()
|
|
||||||
.map(Into::<GraphQlAttributeSchema>::into)
|
|
||||||
.filter(|attr| !attr.is_readonly && (is_admin.0 || attr.is_editable))
|
|
||||||
.map(|attr| -> Result<AttributeValue> {
|
|
||||||
let val = form_data
|
|
||||||
.get_all(attr.name.as_str())
|
|
||||||
.iter()
|
|
||||||
.map(|js_val| js_val.as_string().unwrap_or_default())
|
|
||||||
.filter(|val| !val.is_empty())
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
ensure!(
|
|
||||||
val.len() <= 1 || attr.is_list,
|
|
||||||
"Multiple values supplied for non-list attribute {}",
|
|
||||||
attr.name
|
|
||||||
);
|
|
||||||
Ok(AttributeValue {
|
|
||||||
name: attr.name.clone(),
|
|
||||||
values: val,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<_>>>()?;
|
|
||||||
if email_is_required.0 {
|
|
||||||
validate_email_attributes(&all_values)?;
|
|
||||||
}
|
|
||||||
Ok(all_values)
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
use crate::infra::api::HostService;
|
|
||||||
use anyhow::Result;
|
|
||||||
use graphql_client::GraphQLQuery;
|
|
||||||
use wasm_bindgen_futures::spawn_local;
|
|
||||||
use yew::{UseStateHandle, use_effect_with_deps, use_state_eq};
|
|
||||||
|
|
||||||
// Enum to represent a result that is fetched asynchronously.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum LoadableResult<T> {
|
|
||||||
// The result is still being fetched
|
|
||||||
Loading,
|
|
||||||
// The async call is completed
|
|
||||||
Loaded(Result<T>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: PartialEq> PartialEq for LoadableResult<T> {
|
|
||||||
fn eq(&self, other: &Self) -> bool {
|
|
||||||
match (self, other) {
|
|
||||||
(LoadableResult::Loading, LoadableResult::Loading) => true,
|
|
||||||
(LoadableResult::Loaded(Ok(d1)), LoadableResult::Loaded(Ok(d2))) => d1.eq(d2),
|
|
||||||
(LoadableResult::Loaded(Err(e1)), LoadableResult::Loaded(Err(e2))) => {
|
|
||||||
e1.to_string().eq(&e2.to_string())
|
|
||||||
}
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn use_graphql_call<QueryType>(
|
|
||||||
variables: QueryType::Variables,
|
|
||||||
) -> UseStateHandle<LoadableResult<QueryType::ResponseData>>
|
|
||||||
where
|
|
||||||
QueryType: GraphQLQuery + 'static,
|
|
||||||
<QueryType as graphql_client::GraphQLQuery>::Variables: std::cmp::PartialEq + Clone,
|
|
||||||
<QueryType as graphql_client::GraphQLQuery>::ResponseData: std::cmp::PartialEq,
|
|
||||||
{
|
|
||||||
let loadable_result: UseStateHandle<LoadableResult<QueryType::ResponseData>> =
|
|
||||||
use_state_eq(|| LoadableResult::Loading);
|
|
||||||
{
|
|
||||||
let loadable_result = loadable_result.clone();
|
|
||||||
use_effect_with_deps(
|
|
||||||
move |variables| {
|
|
||||||
let task = HostService::graphql_query::<QueryType>(
|
|
||||||
variables.clone(),
|
|
||||||
"Failed graphql query",
|
|
||||||
);
|
|
||||||
|
|
||||||
spawn_local(async move {
|
|
||||||
let response = task.await;
|
|
||||||
loadable_result.set(LoadableResult::Loaded(response));
|
|
||||||
});
|
|
||||||
|
|
||||||
|| ()
|
|
||||||
},
|
|
||||||
variables,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
loadable_result.clone()
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,5 @@
|
|||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod attributes;
|
|
||||||
pub mod common_component;
|
pub mod common_component;
|
||||||
pub mod cookies;
|
pub mod cookies;
|
||||||
pub mod form_utils;
|
|
||||||
pub mod functional;
|
|
||||||
pub mod graphql;
|
pub mod graphql;
|
||||||
pub mod modal;
|
pub mod modal;
|
||||||
pub mod schema;
|
|
||||||
pub mod tooltip;
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#![allow(clippy::empty_docs)]
|
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
use derive_more::Display;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use strum::EnumString;
|
|
||||||
use validator::ValidationError;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash, EnumString, Display)]
|
|
||||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
|
||||||
#[strum(ascii_case_insensitive)]
|
|
||||||
pub(crate) enum AttributeType {
|
|
||||||
String,
|
|
||||||
Integer,
|
|
||||||
#[strum(serialize = "DATE_TIME", serialize = "DATETIME")]
|
|
||||||
DateTime,
|
|
||||||
#[strum(serialize = "JPEG_PHOTO", serialize = "JPEGPHOTO")]
|
|
||||||
JpegPhoto,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn validate_attribute_type(attribute_type: &str) -> Result<(), ValidationError> {
|
|
||||||
AttributeType::try_from(attribute_type)
|
|
||||||
.map_err(|_| ValidationError::new("Invalid attribute type"))?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_deserialize_attribute_type() {
|
|
||||||
let attr_type: AttributeType = "STRING".try_into().unwrap();
|
|
||||||
assert_eq!(attr_type, AttributeType::String);
|
|
||||||
|
|
||||||
let attr_type: AttributeType = "Integer".try_into().unwrap();
|
|
||||||
assert_eq!(attr_type, AttributeType::Integer);
|
|
||||||
|
|
||||||
let attr_type: AttributeType = "DATE_TIME".try_into().unwrap();
|
|
||||||
assert_eq!(attr_type, AttributeType::DateTime);
|
|
||||||
|
|
||||||
let attr_type: AttributeType = "JpegPhoto".try_into().unwrap();
|
|
||||||
assert_eq!(attr_type, AttributeType::JpegPhoto);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#![allow(clippy::empty_docs)]
|
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
extern "C" {
|
|
||||||
#[wasm_bindgen(js_namespace = bootstrap)]
|
|
||||||
pub type Tooltip;
|
|
||||||
|
|
||||||
#[wasm_bindgen(constructor, js_namespace = bootstrap)]
|
|
||||||
pub fn new(e: web_sys::Element) -> Tooltip;
|
|
||||||
}
|
|
||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
pub mod components;
|
pub mod components;
|
||||||
pub mod infra;
|
pub mod infra;
|
||||||
|
|
||||||
use wasm_bindgen::prelude::{JsValue, wasm_bindgen};
|
use wasm_bindgen::prelude::{wasm_bindgen, JsValue};
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn run_app() -> Result<(), JsValue> {
|
pub fn run_app() -> Result<(), JsValue> {
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 44 KiB |
@@ -0,0 +1,36 @@
|
|||||||
|
[package]
|
||||||
|
name = "lldap_auth"
|
||||||
|
version = "0.3.0"
|
||||||
|
authors = ["Valentin Tolmer <valentin@tolmer.fr>"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["opaque_server", "opaque_client"]
|
||||||
|
opaque_server = []
|
||||||
|
opaque_client = []
|
||||||
|
js = []
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rust-argon2 = "0.8"
|
||||||
|
curve25519-dalek = "3"
|
||||||
|
digest = "0.9"
|
||||||
|
generic-array = "*"
|
||||||
|
rand = "0.8"
|
||||||
|
serde = "*"
|
||||||
|
sha2 = "0.9"
|
||||||
|
thiserror = "*"
|
||||||
|
|
||||||
|
[dependencies.opaque-ke]
|
||||||
|
version = "0.6"
|
||||||
|
|
||||||
|
[dependencies.chrono]
|
||||||
|
version = "*"
|
||||||
|
features = [ "serde" ]
|
||||||
|
|
||||||
|
# For WASM targets, use the JS getrandom.
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.getrandom]
|
||||||
|
version = "0.2"
|
||||||
|
features = ["js"]
|
||||||
|
|
||||||
|
[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom]
|
||||||
|
version = "0.2"
|
||||||
@@ -5,22 +5,21 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
pub mod access_control;
|
|
||||||
pub mod opaque;
|
pub mod opaque;
|
||||||
|
|
||||||
/// The messages for the 3-step OPAQUE and simple login process.
|
/// The messages for the 3-step OPAQUE and simple login process.
|
||||||
pub mod login {
|
pub mod login {
|
||||||
use super::{types::UserId, *};
|
use super::*;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct ServerData {
|
pub struct ServerData {
|
||||||
pub username: UserId,
|
pub username: String,
|
||||||
pub server_login: opaque::server::login::ServerLogin,
|
pub server_login: opaque::server::login::ServerLogin,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct ClientLoginStartRequest {
|
pub struct ClientLoginStartRequest {
|
||||||
pub username: UserId,
|
pub username: String,
|
||||||
pub login_start_request: opaque::server::login::CredentialRequest,
|
pub login_start_request: opaque::server::login::CredentialRequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,14 +39,14 @@ pub mod login {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct ClientSimpleLoginRequest {
|
pub struct ClientSimpleLoginRequest {
|
||||||
pub username: UserId,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ClientSimpleLoginRequest {
|
impl fmt::Debug for ClientSimpleLoginRequest {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("ClientSimpleLoginRequest")
|
f.debug_struct("ClientSimpleLoginRequest")
|
||||||
.field("username", &self.username.as_str())
|
.field("username", &self.username)
|
||||||
.field("password", &"***********")
|
.field("password", &"***********")
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
@@ -64,16 +63,16 @@ pub mod login {
|
|||||||
/// The messages for the 3-step OPAQUE registration process.
|
/// The messages for the 3-step OPAQUE registration process.
|
||||||
/// It is used to reset a user's password.
|
/// It is used to reset a user's password.
|
||||||
pub mod registration {
|
pub mod registration {
|
||||||
use super::{types::UserId, *};
|
use super::*;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct ServerData {
|
pub struct ServerData {
|
||||||
pub username: UserId,
|
pub username: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct ClientRegistrationStartRequest {
|
pub struct ClientRegistrationStartRequest {
|
||||||
pub username: UserId,
|
pub username: String,
|
||||||
pub registration_start_request: opaque::server::registration::RegistrationRequest,
|
pub registration_start_request: opaque::server::registration::RegistrationRequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,106 +102,16 @@ pub mod password_reset {
|
|||||||
pub user_id: String,
|
pub user_id: String,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub mod types {
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
use serde::{Deserialize, Serialize};
|
pub struct PasswordHashCount {
|
||||||
|
pub hash: String,
|
||||||
#[cfg(feature = "sea_orm")]
|
pub count: u64,
|
||||||
use sea_orm::{DbErr, DeriveValueType, TryFromU64, Value};
|
|
||||||
|
|
||||||
#[derive(
|
|
||||||
PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default, Hash, Serialize, Deserialize,
|
|
||||||
)]
|
|
||||||
#[cfg_attr(feature = "sea_orm", derive(DeriveValueType))]
|
|
||||||
#[serde(from = "String")]
|
|
||||||
pub struct CaseInsensitiveString(String);
|
|
||||||
|
|
||||||
impl CaseInsensitiveString {
|
|
||||||
pub fn new(s: &str) -> Self {
|
|
||||||
Self(s.to_ascii_lowercase())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_str(&self) -> &str {
|
|
||||||
self.0.as_str()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn into_string(self) -> String {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for CaseInsensitiveString {
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
fn from(mut s: String) -> Self {
|
pub struct PasswordHashList {
|
||||||
s.make_ascii_lowercase();
|
pub hashes: Vec<PasswordHashCount>,
|
||||||
Self(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&String> for CaseInsensitiveString {
|
|
||||||
fn from(s: &String) -> Self {
|
|
||||||
Self::new(s.as_str())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&str> for CaseInsensitiveString {
|
|
||||||
fn from(s: &str) -> Self {
|
|
||||||
Self::new(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(
|
|
||||||
PartialEq,
|
|
||||||
Eq,
|
|
||||||
PartialOrd,
|
|
||||||
Ord,
|
|
||||||
Clone,
|
|
||||||
Default,
|
|
||||||
Hash,
|
|
||||||
Serialize,
|
|
||||||
Deserialize,
|
|
||||||
derive_more::Debug,
|
|
||||||
derive_more::Display,
|
|
||||||
)]
|
|
||||||
#[cfg_attr(feature = "sea_orm", derive(DeriveValueType))]
|
|
||||||
#[serde(from = "CaseInsensitiveString")]
|
|
||||||
#[debug(r#""{}""#, _0.as_str())]
|
|
||||||
#[display("{}", _0.as_str())]
|
|
||||||
pub struct UserId(CaseInsensitiveString);
|
|
||||||
|
|
||||||
impl UserId {
|
|
||||||
pub fn new(s: &str) -> Self {
|
|
||||||
s.into()
|
|
||||||
}
|
|
||||||
pub fn as_str(&self) -> &str {
|
|
||||||
self.0.as_str()
|
|
||||||
}
|
|
||||||
pub fn into_string(self) -> String {
|
|
||||||
self.0.into_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<T> From<T> for UserId
|
|
||||||
where
|
|
||||||
T: Into<CaseInsensitiveString>,
|
|
||||||
{
|
|
||||||
fn from(s: T) -> Self {
|
|
||||||
Self(s.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "sea_orm")]
|
|
||||||
impl From<&UserId> for Value {
|
|
||||||
fn from(user_id: &UserId) -> Self {
|
|
||||||
user_id.as_str().into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(feature = "sea_orm")]
|
|
||||||
impl TryFromU64 for UserId {
|
|
||||||
fn try_from_u64(_n: u64) -> Result<Self, DbErr> {
|
|
||||||
Err(DbErr::ConvertFromU64(
|
|
||||||
"UserId cannot be constructed from u64",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
use crate::types::UserId;
|
|
||||||
use opaque_ke::ciphersuite::CipherSuite;
|
use opaque_ke::ciphersuite::CipherSuite;
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
|
|
||||||
@@ -32,6 +31,7 @@ impl ArgonHasher {
|
|||||||
lanes: 1,
|
lanes: 1,
|
||||||
mem_cost: 50 * 1024, // 50 MB, in KB
|
mem_cost: 50 * 1024, // 50 MB, in KB
|
||||||
secret: &[],
|
secret: &[],
|
||||||
|
thread_mode: argon2::ThreadMode::Sequential,
|
||||||
time_cost: 1,
|
time_cost: 1,
|
||||||
variant: argon2::Variant::Argon2id,
|
variant: argon2::Variant::Argon2id,
|
||||||
version: argon2::Version::Version13,
|
version: argon2::Version::Version13,
|
||||||
@@ -77,10 +77,10 @@ pub mod client {
|
|||||||
pub use opaque_ke::ClientRegistrationFinishParameters;
|
pub use opaque_ke::ClientRegistrationFinishParameters;
|
||||||
/// Initiate the registration negotiation.
|
/// Initiate the registration negotiation.
|
||||||
pub fn start_registration<R: RngCore + CryptoRng>(
|
pub fn start_registration<R: RngCore + CryptoRng>(
|
||||||
password: &[u8],
|
password: &str,
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
) -> AuthenticationResult<ClientRegistrationStartResult> {
|
) -> AuthenticationResult<ClientRegistrationStartResult> {
|
||||||
Ok(ClientRegistration::start(rng, password)?)
|
Ok(ClientRegistration::start(rng, password.as_bytes())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finalize the registration negotiation.
|
/// Finalize the registration negotiation.
|
||||||
@@ -132,12 +132,6 @@ pub mod server {
|
|||||||
pub use super::*;
|
pub use super::*;
|
||||||
pub type ServerRegistration = opaque_ke::ServerRegistration<DefaultSuite>;
|
pub type ServerRegistration = opaque_ke::ServerRegistration<DefaultSuite>;
|
||||||
pub type ServerSetup = opaque_ke::ServerSetup<DefaultSuite>;
|
pub type ServerSetup = opaque_ke::ServerSetup<DefaultSuite>;
|
||||||
|
|
||||||
pub fn generate_random_private_key() -> ServerSetup {
|
|
||||||
let mut rng = rand::rngs::OsRng;
|
|
||||||
ServerSetup::new(&mut rng)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Methods to register a new user, from the server side.
|
/// Methods to register a new user, from the server side.
|
||||||
pub mod registration {
|
pub mod registration {
|
||||||
pub use super::*;
|
pub use super::*;
|
||||||
@@ -151,12 +145,12 @@ pub mod server {
|
|||||||
pub fn start_registration(
|
pub fn start_registration(
|
||||||
server_setup: &ServerSetup,
|
server_setup: &ServerSetup,
|
||||||
registration_request: RegistrationRequest,
|
registration_request: RegistrationRequest,
|
||||||
username: &UserId,
|
username: &str,
|
||||||
) -> AuthenticationResult<ServerRegistrationStartResult> {
|
) -> AuthenticationResult<ServerRegistrationStartResult> {
|
||||||
Ok(ServerRegistration::start(
|
Ok(ServerRegistration::start(
|
||||||
server_setup,
|
server_setup,
|
||||||
registration_request,
|
registration_request,
|
||||||
username.as_str().as_bytes(),
|
username.as_bytes(),
|
||||||
)?)
|
)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,14 +178,14 @@ pub mod server {
|
|||||||
server_setup: &ServerSetup,
|
server_setup: &ServerSetup,
|
||||||
password_file: Option<ServerRegistration>,
|
password_file: Option<ServerRegistration>,
|
||||||
credential_request: CredentialRequest,
|
credential_request: CredentialRequest,
|
||||||
username: &UserId,
|
username: &str,
|
||||||
) -> AuthenticationResult<ServerLoginStartResult> {
|
) -> AuthenticationResult<ServerLoginStartResult> {
|
||||||
Ok(ServerLogin::start(
|
Ok(ServerLogin::start(
|
||||||
rng,
|
rng,
|
||||||
server_setup,
|
server_setup,
|
||||||
password_file,
|
password_file,
|
||||||
credential_request,
|
credential_request,
|
||||||
username.as_str().as_bytes(),
|
username.as_bytes(),
|
||||||
ServerLoginStartParameters::default(),
|
ServerLoginStartParameters::default(),
|
||||||
)?)
|
)?)
|
||||||
}
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "lldap_access_control"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "Access control wrappers for LLDAP"
|
|
||||||
authors.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
homepage.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
repository.workspace = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
tracing = "*"
|
|
||||||
async-trait = "0.1"
|
|
||||||
|
|
||||||
[dependencies.lldap_auth]
|
|
||||||
path = "../auth"
|
|
||||||
features = ["opaque_server", "opaque_client", "sea_orm"]
|
|
||||||
|
|
||||||
[dependencies.lldap_domain]
|
|
||||||
path = "../domain"
|
|
||||||
|
|
||||||
[dependencies.lldap_domain_handlers]
|
|
||||||
path = "../domain-handlers"
|
|
||||||
|
|
||||||
[dependencies.lldap_domain_model]
|
|
||||||
path = "../domain-model"
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "lldap_auth"
|
|
||||||
version = "0.6.0"
|
|
||||||
description = "Authentication protocol for LLDAP"
|
|
||||||
edition.workspace = true
|
|
||||||
authors.workspace = true
|
|
||||||
homepage.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
repository.workspace = true
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["opaque_server", "opaque_client"]
|
|
||||||
opaque_server = []
|
|
||||||
opaque_client = []
|
|
||||||
js = []
|
|
||||||
sea_orm = ["dep:sea-orm"]
|
|
||||||
test = []
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
rust-argon2 = "2"
|
|
||||||
curve25519-dalek = "3"
|
|
||||||
digest = "0.9"
|
|
||||||
generic-array = "0.14"
|
|
||||||
rand = "0.8"
|
|
||||||
sha2 = "0.9"
|
|
||||||
thiserror = "2"
|
|
||||||
|
|
||||||
[dependencies.derive_more]
|
|
||||||
features = ["debug", "display"]
|
|
||||||
default-features = false
|
|
||||||
version = "1"
|
|
||||||
|
|
||||||
[dependencies.opaque-ke]
|
|
||||||
version = "0.7"
|
|
||||||
|
|
||||||
[dependencies.chrono]
|
|
||||||
version = "*"
|
|
||||||
features = ["serde"]
|
|
||||||
|
|
||||||
[dependencies.sea-orm]
|
|
||||||
workspace = true
|
|
||||||
features = ["macros"]
|
|
||||||
optional = true
|
|
||||||
|
|
||||||
[dependencies.serde]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
# For WASM targets, use the JS getrandom.
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.getrandom]
|
|
||||||
version = "0.2"
|
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom]
|
|
||||||
version = "0.2"
|
|
||||||
features = ["js"]
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
use crate::types::UserId;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
|
||||||
pub enum Permission {
|
|
||||||
Admin,
|
|
||||||
PasswordManager,
|
|
||||||
Readonly,
|
|
||||||
Regular,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub struct ValidationResults {
|
|
||||||
pub user: UserId,
|
|
||||||
pub permission: Permission,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ValidationResults {
|
|
||||||
#[cfg(feature = "test")]
|
|
||||||
pub fn admin() -> Self {
|
|
||||||
Self {
|
|
||||||
user: UserId::new("admin"),
|
|
||||||
permission: Permission::Admin,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn is_admin(&self) -> bool {
|
|
||||||
self.permission == Permission::Admin
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn can_read_all(&self) -> bool {
|
|
||||||
self.permission == Permission::Admin
|
|
||||||
|| self.permission == Permission::Readonly
|
|
||||||
|| self.permission == Permission::PasswordManager
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn can_read(&self, user: &UserId) -> bool {
|
|
||||||
self.permission == Permission::Admin
|
|
||||||
|| self.permission == Permission::PasswordManager
|
|
||||||
|| self.permission == Permission::Readonly
|
|
||||||
|| &self.user == user
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn can_change_password(&self, user: &UserId, user_is_admin: bool) -> bool {
|
|
||||||
self.permission == Permission::Admin
|
|
||||||
|| (self.permission == Permission::PasswordManager && !user_is_admin)
|
|
||||||
|| &self.user == user
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn can_write(&self, user: &UserId) -> bool {
|
|
||||||
self.permission == Permission::Admin || &self.user == user
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "lldap_domain_handlers"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition.workspace = true
|
|
||||||
authors.workspace = true
|
|
||||||
homepage.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
repository.workspace = true
|
|
||||||
|
|
||||||
[features]
|
|
||||||
test = []
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
async-trait = "0.1"
|
|
||||||
base64 = "0.21"
|
|
||||||
ldap3_proto = "0.6.0"
|
|
||||||
serde_bytes = "0.11"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
pretty_assertions = "1"
|
|
||||||
|
|
||||||
[dependencies.chrono]
|
|
||||||
features = ["serde"]
|
|
||||||
version = "0.4"
|
|
||||||
|
|
||||||
[dependencies.derive_more]
|
|
||||||
features = ["debug", "display", "from", "from_str"]
|
|
||||||
default-features = false
|
|
||||||
version = "1"
|
|
||||||
|
|
||||||
[dependencies.lldap_auth]
|
|
||||||
path = "../auth"
|
|
||||||
features = ["opaque_server", "opaque_client", "sea_orm"]
|
|
||||||
|
|
||||||
[dependencies.lldap_domain]
|
|
||||||
path = "../domain"
|
|
||||||
|
|
||||||
[dependencies.lldap_domain_model]
|
|
||||||
path = "../domain-model"
|
|
||||||
|
|
||||||
[dependencies.serde]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
[dependencies.uuid]
|
|
||||||
features = ["v1", "v3"]
|
|
||||||
version = "1"
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub mod handler;
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "lldap_domain_model"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition.workspace = true
|
|
||||||
authors.workspace = true
|
|
||||||
homepage.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
repository.workspace = true
|
|
||||||
|
|
||||||
[features]
|
|
||||||
test = []
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
base64 = "0.21"
|
|
||||||
bincode = "1.3"
|
|
||||||
orion = "0.17"
|
|
||||||
serde_bytes = "0.11"
|
|
||||||
thiserror = "2"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
pretty_assertions = "1"
|
|
||||||
|
|
||||||
[dependencies.chrono]
|
|
||||||
features = ["serde"]
|
|
||||||
version = "0.4"
|
|
||||||
|
|
||||||
[dependencies.derive_more]
|
|
||||||
features = ["debug", "display", "from", "from_str"]
|
|
||||||
default-features = false
|
|
||||||
version = "1"
|
|
||||||
|
|
||||||
[dependencies.lldap_auth]
|
|
||||||
path = "../auth"
|
|
||||||
features = ["opaque_server", "opaque_client", "sea_orm"]
|
|
||||||
|
|
||||||
[dependencies.lldap_domain]
|
|
||||||
path = "../domain"
|
|
||||||
|
|
||||||
[dependencies.sea-orm]
|
|
||||||
workspace = true
|
|
||||||
features = ["macros"]
|
|
||||||
|
|
||||||
[dependencies.serde]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
[dependencies.uuid]
|
|
||||||
features = ["v1", "v3"]
|
|
||||||
version = "1"
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
pub mod error;
|
|
||||||
pub mod model;
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
use crate::error::DomainError;
|
|
||||||
use lldap_domain::{
|
|
||||||
schema::AttributeList,
|
|
||||||
types::{Attribute, AttributeName, AttributeType, AttributeValue, Cardinality, Serialized},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Value must be a serialized attribute value of the type denoted by typ,
|
|
||||||
// and either a singleton or unbounded list, depending on is_list.
|
|
||||||
pub fn deserialize_attribute_value(
|
|
||||||
value: &Serialized,
|
|
||||||
typ: AttributeType,
|
|
||||||
is_list: bool,
|
|
||||||
) -> AttributeValue {
|
|
||||||
match (typ, is_list) {
|
|
||||||
(AttributeType::String, false) => {
|
|
||||||
AttributeValue::String(Cardinality::Singleton(value.unwrap()))
|
|
||||||
}
|
|
||||||
(AttributeType::String, true) => {
|
|
||||||
AttributeValue::String(Cardinality::Unbounded(value.unwrap()))
|
|
||||||
}
|
|
||||||
(AttributeType::Integer, false) => {
|
|
||||||
AttributeValue::Integer(Cardinality::Singleton(value.unwrap::<i64>()))
|
|
||||||
}
|
|
||||||
(AttributeType::Integer, true) => {
|
|
||||||
AttributeValue::Integer(Cardinality::Unbounded(value.unwrap()))
|
|
||||||
}
|
|
||||||
(AttributeType::DateTime, false) => {
|
|
||||||
AttributeValue::DateTime(Cardinality::Singleton(value.unwrap()))
|
|
||||||
}
|
|
||||||
(AttributeType::DateTime, true) => {
|
|
||||||
AttributeValue::DateTime(Cardinality::Unbounded(value.unwrap()))
|
|
||||||
}
|
|
||||||
(AttributeType::JpegPhoto, false) => {
|
|
||||||
AttributeValue::JpegPhoto(Cardinality::Singleton(value.unwrap()))
|
|
||||||
}
|
|
||||||
(AttributeType::JpegPhoto, true) => {
|
|
||||||
AttributeValue::JpegPhoto(Cardinality::Unbounded(value.unwrap()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deserialize_attribute(
|
|
||||||
name: AttributeName,
|
|
||||||
value: &Serialized,
|
|
||||||
schema: &AttributeList,
|
|
||||||
) -> Result<Attribute, DomainError> {
|
|
||||||
match schema.get_attribute_type(&name) {
|
|
||||||
Some((typ, is_list)) => Ok(Attribute {
|
|
||||||
name,
|
|
||||||
value: deserialize_attribute_value(value, typ, is_list),
|
|
||||||
}),
|
|
||||||
None => Err(DomainError::InternalError(format!(
|
|
||||||
"Unable to find schema for attribute named '{}'",
|
|
||||||
name.into_string()
|
|
||||||
))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
use sea_orm::entity::prelude::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use lldap_domain::{
|
|
||||||
schema::AttributeSchema,
|
|
||||||
types::{AttributeName, AttributeType},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
|
||||||
#[sea_orm(table_name = "group_attribute_schema")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(
|
|
||||||
primary_key,
|
|
||||||
auto_increment = false,
|
|
||||||
column_name = "group_attribute_schema_name"
|
|
||||||
)]
|
|
||||||
pub attribute_name: AttributeName,
|
|
||||||
#[sea_orm(column_name = "group_attribute_schema_type")]
|
|
||||||
pub attribute_type: AttributeType,
|
|
||||||
#[sea_orm(column_name = "group_attribute_schema_is_list")]
|
|
||||||
pub is_list: bool,
|
|
||||||
#[sea_orm(column_name = "group_attribute_schema_is_group_visible")]
|
|
||||||
pub is_group_visible: bool,
|
|
||||||
#[sea_orm(column_name = "group_attribute_schema_is_group_editable")]
|
|
||||||
pub is_group_editable: bool,
|
|
||||||
#[sea_orm(column_name = "group_attribute_schema_is_hardcoded")]
|
|
||||||
pub is_hardcoded: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
#[sea_orm(has_many = "super::group_attributes::Entity")]
|
|
||||||
GroupAttributes,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::GroupAttributes> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::GroupAttributes.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
impl From<Model> for AttributeSchema {
|
|
||||||
fn from(value: Model) -> Self {
|
|
||||||
Self {
|
|
||||||
name: value.attribute_name,
|
|
||||||
attribute_type: value.attribute_type,
|
|
||||||
is_list: value.is_list,
|
|
||||||
is_visible: value.is_group_visible,
|
|
||||||
is_editable: value.is_group_editable,
|
|
||||||
is_hardcoded: value.is_hardcoded,
|
|
||||||
is_readonly: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
use sea_orm::entity::prelude::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use lldap_domain::types::{AttributeName, GroupId, Serialized};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
|
||||||
#[sea_orm(table_name = "group_attributes")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(
|
|
||||||
primary_key,
|
|
||||||
auto_increment = false,
|
|
||||||
column_name = "group_attribute_group_id"
|
|
||||||
)]
|
|
||||||
pub group_id: GroupId,
|
|
||||||
#[sea_orm(
|
|
||||||
primary_key,
|
|
||||||
auto_increment = false,
|
|
||||||
column_name = "group_attribute_name"
|
|
||||||
)]
|
|
||||||
pub attribute_name: AttributeName,
|
|
||||||
#[sea_orm(column_name = "group_attribute_value")]
|
|
||||||
pub value: Serialized,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::groups::Entity",
|
|
||||||
from = "Column::GroupId",
|
|
||||||
to = "super::groups::Column::GroupId",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Groups,
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::group_attribute_schema::Entity",
|
|
||||||
from = "Column::AttributeName",
|
|
||||||
to = "super::group_attribute_schema::Column::AttributeName",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
GroupAttributeSchema,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::Group> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Groups.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::GroupAttributeSchema> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::GroupAttributeSchema.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
use sea_orm::entity::prelude::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use lldap_domain::types::LdapObjectClass;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
|
||||||
#[sea_orm(table_name = "group_object_classes")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub lower_object_class: String,
|
|
||||||
pub object_class: LdapObjectClass,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
impl From<Model> for LdapObjectClass {
|
|
||||||
fn from(value: Model) -> Self {
|
|
||||||
value.object_class
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
pub mod prelude;
|
|
||||||
|
|
||||||
pub mod deserialize;
|
|
||||||
pub mod groups;
|
|
||||||
pub mod jwt_refresh_storage;
|
|
||||||
pub mod jwt_storage;
|
|
||||||
pub mod memberships;
|
|
||||||
pub mod password_reset_tokens;
|
|
||||||
pub mod users;
|
|
||||||
|
|
||||||
pub mod user_attribute_schema;
|
|
||||||
pub mod user_attributes;
|
|
||||||
pub mod user_object_classes;
|
|
||||||
|
|
||||||
pub mod group_attribute_schema;
|
|
||||||
pub mod group_attributes;
|
|
||||||
pub mod group_object_classes;
|
|
||||||
|
|
||||||
pub use prelude::*;
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.3
|
|
||||||
|
|
||||||
pub use super::group_attribute_schema::Column as GroupAttributeSchemaColumn;
|
|
||||||
pub use super::group_attribute_schema::Entity as GroupAttributeSchema;
|
|
||||||
pub use super::group_attributes::Column as GroupAttributesColumn;
|
|
||||||
pub use super::group_attributes::Entity as GroupAttributes;
|
|
||||||
pub use super::group_object_classes::Column as GroupObjectClassesColumn;
|
|
||||||
pub use super::group_object_classes::Entity as GroupObjectClasses;
|
|
||||||
pub use super::groups::Column as GroupColumn;
|
|
||||||
pub use super::groups::Entity as Group;
|
|
||||||
pub use super::jwt_refresh_storage::Column as JwtRefreshStorageColumn;
|
|
||||||
pub use super::jwt_refresh_storage::Entity as JwtRefreshStorage;
|
|
||||||
pub use super::jwt_storage::Column as JwtStorageColumn;
|
|
||||||
pub use super::jwt_storage::Entity as JwtStorage;
|
|
||||||
pub use super::memberships::Column as MembershipColumn;
|
|
||||||
pub use super::memberships::Entity as Membership;
|
|
||||||
pub use super::password_reset_tokens::Column as PasswordResetTokensColumn;
|
|
||||||
pub use super::password_reset_tokens::Entity as PasswordResetTokens;
|
|
||||||
pub use super::user_attribute_schema::Column as UserAttributeSchemaColumn;
|
|
||||||
pub use super::user_attribute_schema::Entity as UserAttributeSchema;
|
|
||||||
pub use super::user_attributes::Column as UserAttributesColumn;
|
|
||||||
pub use super::user_attributes::Entity as UserAttributes;
|
|
||||||
pub use super::user_object_classes::Column as UserObjectClassesColumn;
|
|
||||||
pub use super::user_object_classes::Entity as UserObjectClasses;
|
|
||||||
pub use super::users::Column as UserColumn;
|
|
||||||
pub use super::users::Entity as User;
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
use sea_orm::entity::prelude::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use lldap_domain::{
|
|
||||||
schema::AttributeSchema,
|
|
||||||
types::{AttributeName, AttributeType},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
|
||||||
#[sea_orm(table_name = "user_attribute_schema")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(
|
|
||||||
primary_key,
|
|
||||||
auto_increment = false,
|
|
||||||
column_name = "user_attribute_schema_name"
|
|
||||||
)]
|
|
||||||
pub attribute_name: AttributeName,
|
|
||||||
#[sea_orm(column_name = "user_attribute_schema_type")]
|
|
||||||
pub attribute_type: AttributeType,
|
|
||||||
#[sea_orm(column_name = "user_attribute_schema_is_list")]
|
|
||||||
pub is_list: bool,
|
|
||||||
#[sea_orm(column_name = "user_attribute_schema_is_user_visible")]
|
|
||||||
pub is_user_visible: bool,
|
|
||||||
#[sea_orm(column_name = "user_attribute_schema_is_user_editable")]
|
|
||||||
pub is_user_editable: bool,
|
|
||||||
#[sea_orm(column_name = "user_attribute_schema_is_hardcoded")]
|
|
||||||
pub is_hardcoded: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
#[sea_orm(has_many = "super::user_attributes::Entity")]
|
|
||||||
UserAttributes,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::UserAttributes> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::UserAttributes.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
impl From<Model> for AttributeSchema {
|
|
||||||
fn from(value: Model) -> Self {
|
|
||||||
Self {
|
|
||||||
name: value.attribute_name,
|
|
||||||
attribute_type: value.attribute_type,
|
|
||||||
is_list: value.is_list,
|
|
||||||
is_visible: value.is_user_visible,
|
|
||||||
is_editable: value.is_user_editable,
|
|
||||||
is_hardcoded: value.is_hardcoded,
|
|
||||||
is_readonly: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
use sea_orm::entity::prelude::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use lldap_domain::types::{AttributeName, Serialized, UserId};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
|
||||||
#[sea_orm(table_name = "user_attributes")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(
|
|
||||||
primary_key,
|
|
||||||
auto_increment = false,
|
|
||||||
column_name = "user_attribute_user_id"
|
|
||||||
)]
|
|
||||||
pub user_id: UserId,
|
|
||||||
#[sea_orm(
|
|
||||||
primary_key,
|
|
||||||
auto_increment = false,
|
|
||||||
column_name = "user_attribute_name"
|
|
||||||
)]
|
|
||||||
pub attribute_name: AttributeName,
|
|
||||||
#[sea_orm(column_name = "user_attribute_value")]
|
|
||||||
pub value: Serialized,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::users::Entity",
|
|
||||||
from = "Column::UserId",
|
|
||||||
to = "super::users::Column::UserId",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Users,
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::user_attribute_schema::Entity",
|
|
||||||
from = "Column::AttributeName",
|
|
||||||
to = "super::user_attribute_schema::Column::AttributeName",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
UserAttributeSchema,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::User> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Users.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::UserAttributeSchema> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::UserAttributeSchema.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user