Skip to content

Commit

Permalink
Merge pull request #49 from EyeSeeTea/feature/user_authority_monitoring
Browse files Browse the repository at this point in the history
Monitor users authority changes
  • Loading branch information
ifoche authored Jun 17, 2024
2 parents 82852d7 + 2e4ceb4 commit 70ebd5d
Show file tree
Hide file tree
Showing 38 changed files with 2,746 additions and 44 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Application testing
on:
push:
workflow_dispatch:
jobs:
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install apt libraries
run: sudo apt install gettext -y

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "16"

- name: Install yarn
run: npm install -g yarn

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Cache yarn dependencies
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile --silent

- name: Run vitest tests
run: yarn test

- name: Build typescript
run: npx tsc
97 changes: 92 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ yarn start users migrate \

## User monitoring

### Execution:
### Users Permissions Fixer and 2FA Reporter

#### Execution:

```
yarn install
Expand All @@ -413,7 +415,7 @@ or
yarn start usermonitoring run-2fa-reporter --config-file config.json
```

### Debug:
#### Debug:

```
yarn install
Expand All @@ -424,7 +426,7 @@ LOG_LEVEL=debug node --inspect-brk dist/index.js usermonitoring run-users-monito
LOG_LEVEL=debug node --inspect-brk dist/index.js usermonitoring run-2fa-reporter --config-file config.json
```

### Requirements:
#### Requirements:

Use node 16:

Expand All @@ -444,7 +446,7 @@ A config json file to get the user/password and server:
}
```

### run-2fa-reporter Datastore:
#### run-2fa-reporter Datastore:

d2-tools -> two-factor-monitoring:

Expand All @@ -467,7 +469,7 @@ The datastore must contain:
}
```

### run-users-monitoring Datastore:
#### run-users-monitoring Datastore:

d2-tools -> permission-fixer:

Expand Down Expand Up @@ -587,6 +589,91 @@ Note: the names are used only to make easy understand and debug the keys.
}
```

### Users Authorities Monitoring

#### Execution:

```bash
yarn install

yarn build

yarn start usermonitoring run-authorities-monitoring --config-file config.json

# To get the debug logs and store them in a file use:
LOG_LEVEL=debug yarn start usermonitoring run-authorities-monitoring --config-file config.json &> authorities-monitoring.log
```

#### Parameters:

- `--config-file`: Connection and webhook config file.
- `-s` | `--set-datastore`: Write users data to datastore, use in script setup. It assumes there is a monitoring config in d2-tools/authorities-monitor.

#### Requirements:

A config file with the access info of the server and the message webhook details:

```JSON
{
"URL": {
"username": "user",
"password": "passwd",
"server": "https://dhis.url/"
},
"WEBHOOK": {
"ms_url": "http://webhook.url/",
"proxy": "http://proxy.url/",
"server_name": "INSTANCE_NAME"
}
}
```

This reports stores data into the `d2-tools.authorities-monitor` datastore. This key needs to be setup before the first run to get a correct report.
Its possible to leave `usersByAuthority` empty and use the `-s` flag to populate it.

A sample:

```JSON
{
"usersByAuthority": {
"AUTH1": [
{
"id": "lJf6FW6vtDD",
"name": "fake user 1",
"userRoles": [
{
"id": "So7ZSqi9ovy",
"name": "Role 1"
}
]
},
{
"id": "wXGwwP53ngu",
"name": "fake user 2",
"userRoles": [
{
"id": "So7ZSqi9ovy",
"name": "Role 1"
}
]
}
],
"AUTH2": [
{
"id": "wXGwwP53ngu",
"name": "fake user 2",
"userRoles": [
{
"id": "So7ZSqi9ovy",
"name": "Role 1"
}
]
}
]
}
}
```

## Move Attributes from a Program

Get all the TEIS in the program and move the value from the attribute in the argument `--from-attribute-id` to the attribute `--to-attribute-id`. Then delete the value in `--from-attribute-id`.
Expand Down
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"service": "nodemon",
"start": "node dist/index.js",
"start:dev": "ts-node src/index.ts",
"test": "yarn test-unit",
"test-unit": "vitest run --reporter=basic",
"test-unit-watch": "vitest watch",
"prettify": "prettier \"./**/*.{js,jsx,json,css,ts,tsx}\" --write",
"release": "standard-version"
},
Expand Down Expand Up @@ -45,6 +48,7 @@
"@types/random-seed": "^0.3.3",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"core-js": "2.6.9",
"dotenv": "^16.0.1",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -53,14 +57,25 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"fake-indexeddb": "4.0.2",
"flow-remove-types": "2.182.0",
"jsdom": "^22.1.0",
"nodemon": "^2.0.15",
"prettier": "^2.6.0",
"react-html-parser-ultimate": "^1.0.7",
"ts-loader": "^9.2.8",
"ts-mockito": "^2.6.1",
"ts-node": "^10.7.0",
"tsconfig-paths": "^3.14.0",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"typescript": "^4.6.2",
"vite": "^4.2.0",
"vite-bundle-visualizer": "^0.6.0",
"vite-plugin-checker": "^0.6.2",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-node-stdlib-browser": "^0.2.1",
"vite-tsconfig-paths": "4.0.0",
"vitest": "^0.32.2",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2",
"webpack-node-externals": "^3.0.0"
Expand Down
146 changes: 146 additions & 0 deletions reviewpad.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# This file is used to configure Reviewpad.
# The configuration is a proposal to help you get started.
# You can use it as a starting point and customize it to your needs.
# For more details see https://docs.reviewpad.com/guides/syntax.

# Define the list of labels to be used by Reviewpad.
# For more details see https://docs.reviewpad.com/guides/syntax#label.
labels:
small:
description: Pull request is small
color: "#76dbbe"
medium:
description: Pull request is medium
color: "#2986cc"
large:
description: Pull request is large
color: "#c90076"

# Define the list of workflows to be run by Reviewpad.
# A workflow is a list of actions that will be executed based on the defined rules.
# For more details see https://docs.reviewpad.com/guides/syntax#workflow.
workflows:
# This workflow calls Reviewpad AI agent to summarize the pull request.
- name: summarize
description: Summarize the pull request
always-run: true
if:
# Summarize the pull requests when pull requests are opened or synchronized.
- rule: ($eventType() == "synchronize" || $eventType() == "opened") && $state() == "open"
extra-actions:
- $summarize()

# This workflow assigns the most relevant reviewer to pull requests.
# This helps guarantee that pull requests are reviewed by at least one person.
- name: reviewer-assignment
description: Assign the most relevant reviewer to pull requests
always-run: true
if:
# Automatically assign reviewer when the pull request is ready for review.
- rule: $isDraft() == false
extra-actions:
- $assignCodeAuthorReviewers()

# This workflow praises contributors on their pull request contributions.
# This helps contributors feel appreciated.
- name: praise-contributors-on-milestones
description: Praise contributors based on their contributions
always-run: true
if:
# Praise contributors on their first pull request.
- rule: $pullRequestCountBy($author()) == 1
extra-actions:
- $commentOnce($sprintf("Thank you @%s for this first contribution!", [$author()]))

# This workflow validates that pull requests follow the conventional commits specification.
# This helps developers automatically generate changelogs.
# For more details, see https://www.conventionalcommits.org/en/v1.0.0/.
- name: check-conventional-commits
description: Validate that pull requests follow the conventional commits
always-run: true
if:
- rule: $isDraft() == false
then:
# Check commits messages against the conventional commits specification
- $commitLint()
# Check pull request title against the conventional commits specification.
- $titleLint()

# This workflow validates best practices for pull request management.
# This helps developers follow best practices.
- name: best-practices
description: Validate best practices for pull request management
always-run: true
if:
# Warn pull requests that do not have an associated GitHub issue.
#- rule: $hasLinkedIssues() == false
# extra-actions:
# - $warn("Please link an issue to the pull request")
# Warn pull requests if their description is empty.
- rule: $description() == ""
extra-actions:
- $warn("Please provide a description for the pull request")
# Warn pull request do not have a clean linear history.
#- rule: $hasLinearHistory() == false
# extra-actions:
# - $warn("Please rebase your pull request on the latest changes")

# This workflow labels pull requests based on the total number of lines changed.
# This helps pick pull requests based on their size and to incentivize small pull requests.
- name: size-labeling
description: Label pull request based on the number of lines changed
always-run: true
if:
- rule: $size() < 100
extra-actions:
- $removeLabels(["medium", "large"])
- $addLabel("small")
- rule: $size() >= 100 && $size() < 300
extra-actions:
- $removeLabels(["small", "large"])
- $addLabel("medium")
- rule: $size() >= 300
extra-actions:
- $removeLabels(["small", "medium"])
- $addLabel("large")

# This workflow signals pull requests waiting for reviews.
# This helps guarantee that pull requests are reviewed and approved by at least one person.
- name: check-approvals
description: Check that pull requests have the required number of approvals
always-run: true
if:
# Label pull requests with `waiting-for-review` if there are no approvals;
- rule: $isDraft() == false && $approvalsCount() < 1
extra-actions:
- $addLabel("waiting-for-review")

# This workflow labels pull requests based on the pull request change type.
# This helps pick pull requests based on their change type.
- name: change-type-labelling
description: Label pull requests based on the type of changes
always-run: true
if:
# Label pull requests with `docs` if they only modify Markdown or txt files.
- rule: $hasFileExtensions([".md", ".txt"])
extra-actions:
- $addLabel("docs")
# Label pull requests with `infra` if they modify Terraform files.
- rule: $hasFileExtensions([".tf"])
extra-actions:
- $addLabel("infra")
# Label pull requests with `dependencies` if they only modify `package.json` and `package.lock` files.
- rule: $hasFileExtensions(["package.json", "package-lock.json"])
extra-actions:
- $addLabel("dependencies")

# This workflow validates that pull requests do not contain changes to the license.
# This helps avoid unwanted license modifications.
- name: license-validation
description: Validate that licenses are not modified
always-run: true
if:
# Fail Reviewpad check on pull requests that modify any LICENSE;
- rule: $hasFilePattern("**/LICENSE*")
extra-actions:
- $fail("License files cannot be modified")
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect, it, beforeEach, afterEach } from "vitest";

import { DomLocalStorageAdapter } from "../DomLocalStorageAdapter";

const storeName = "testStore";
const options = { name: "testDB", version: 1, keyPath: "id", objectStores: [storeName] };
DomLocalStorageAdapter.localStorage = localStorage;

let testCnt = 0;
beforeEach(() => {
Expand Down
Loading

0 comments on commit 70ebd5d

Please sign in to comment.