Skip to content

Commit

Permalink
bayanat v1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
sjacgit committed May 19, 2023
1 parent 643c717 commit 14caa37
Show file tree
Hide file tree
Showing 47 changed files with 5,128 additions and 641 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/pip-audit.yml
@@ -0,0 +1,28 @@
on:
pull_request: {}
push:
branches:
- main
paths:
- requirements.txt
schedule:
- cron: 19 20 * * *
name: pip-audit
jobs:
selftest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install
run: |
sudo apt install libimage-exiftool-perl
python -m venv env/
source env/bin/activate
python -m pip install -r requirements.txt
- uses: pypa/gh-action-pip-audit@v1.0.6
with:
inputs: requirements.txt
virtual-environment: env/
local: true
ignore-vulns: |
PYSEC-2021-13
22 changes: 22 additions & 0 deletions .github/workflows/semgrep.yml
@@ -0,0 +1,22 @@
on:
pull_request: {}
push:
branches:
- main
paths:
- .github/workflows/semgrep.yml
schedule:
# random HH:MM to avoid a load spike on GitHub Actions at 00:00
- cron: 18 16 * * *
name: Semgrep
jobs:
semgrep:
name: Scan
runs-on: ubuntu-20.04
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
container:
image: returntocorp/semgrep
steps:
- uses: actions/checkout@v3
- run: semgrep ci
23 changes: 19 additions & 4 deletions enferno/admin/models.py
Expand Up @@ -5,21 +5,20 @@
from functools import wraps
from pathlib import Path
from tempfile import NamedTemporaryFile

import pandas as pd
from flask_babel import gettext
from flask_login import current_user
from geoalchemy2 import Geometry
from geoalchemy2.shape import to_shape
from sqlalchemy import JSON, ARRAY, text
from sqlalchemy.dialects.postgresql import TSVECTOR, JSONB
from sqlalchemy.orm.attributes import flag_modified
from werkzeug.utils import secure_filename
from flask_babel import gettext

from enferno.extensions import db
from enferno.settings import ProdConfig, DevConfig
from enferno.utils.base import BaseMixin
from enferno.utils.date_helper import DateHelper
from geoalchemy2 import Geometry
from geoalchemy2.shape import to_shape

# Load configurations based on environment settings
if os.getenv("FLASK_DEBUG") == '0':
Expand Down Expand Up @@ -1346,6 +1345,19 @@ def create_revision(self, user_id=None, created=None):
def bulletin_relations(self):
return self.bulletins_to + self.bulletins_from

@property
def bulletin_relations_dict(self):
return [relation.to_dict(exclude=self) for relation in self.bulletin_relations]

@property
def actor_relations_dict(self):
return [relation.to_dict() for relation in self.actor_relations]

@property
def incident_relations_dict(self):
return [relation.to_dict() for relation in self.incident_relations]


# helper property returns all actor relations
@property
def actor_relations(self):
Expand Down Expand Up @@ -3756,6 +3768,8 @@ class Activity(db.Model, BaseMixin):
ACTION_DELETE = 'DELETE'
ACTION_CREATE = 'CREATE-REVISION'
ACTION_BULK_UPDATE = "BULK-UPDATE"
ACTION_APPROVE_EXPORT = "APPROVE-EXPORT"
ACTION_REJECT_EXPORT = "REJECT-EXPORT"
ACTION_LOGIN = 'LOGIN'
ACTION_LOGOUT = 'LOGOUT'

Expand Down Expand Up @@ -3907,3 +3921,4 @@ def to_dict(self):

def __repr__(self):
return '<{} - {}>'.format(self.id, self.name)

181 changes: 119 additions & 62 deletions enferno/admin/templates/admin/bulletins.html
Expand Up @@ -10,6 +10,9 @@
{% include 'nav-drawer.html' %} {% include 'nav-bar.html' %} {% include
'admin/partials/bulletin_drawer.html' %} {% include
'admin/partials/bulk_bulletin_drawer.html' %}

{% include
'admin/partials/export_drawer.html' %}
<v-main>
{% include 'admin/partials/bulletin_advsearch.html' %}
<v-container class="container--fluid">
Expand Down Expand Up @@ -95,70 +98,77 @@
'admin/partials/review_dialog.html' %}
</v-toolbar>

<v-toolbar v-if="bulkAllowed() || exportAllowed()" dense color="white" flat>
<template v-if="bulkIcons">

<v-btn @click="selected=[]" x-small fab
class="mr-3" elevation="0" color="white">
<v-icon>mdi-checkbox-blank-outline</v-icon>
</v-btn>

<v-btn
@click="bulkBulletinDrawer=true"
small
color="primary"
class="mx-2"
depressed
v-if="bulkAllowed()"
>
<v-icon small left
>mdi-circle-edit-outline
</v-icon>
{{ _('Bulk update') }}
</v-btn>
{% if config.EXPORT_TOOL %}
<v-btn
@click="exportDrawer=true"
small
color="primary"
class="mx-2"
depressed
v-if="exportAllowed()"
>
<v-icon small left
>mdi-file-export-outline
</v-icon>
{{ _('Export') }}
</v-btn>
{% endif %}
</template>
<template>
<v-progress-circular v-for="job in jobs"
size="20" small
:indeterminate="job.status!='SUCCESS'"

:color="job.status=='SUCCESS' ? 'success': 'amber'"
:value="job.status=='SUCCESS'?100:null"
class="mx-1"
stroke="1"
></v-progress-circular>
</template>
<v-spacer></v-spacer>

<div>

<v-tooltip top>
<template v-slot:activator="{ on, attrs }">
<v-chip v-on="on" label small close color="yellow lighten-4"
class="grey--text text--darken-2"
@click:close="allBulletins"
>{{ _('About') }} ${itemsLength} {{ _('results') }}
(${searchTime} {{ _('seconds') }})
</v-chip>
</template>
<span>${search}</span>
</v-tooltip>
</div>

{% if current_user.has_role('Admin') or current_user.has_role('Mod') %}
<v-toolbar dense color="grey lighten-4" flat>
<template v-if="bulkIcons">

<v-btn @click="selected=[]" x-small fab
class="mr-3" elevation="0" color="white">
<v-icon>mdi-checkbox-blank-outline</v-icon>
</v-btn>


<v-btn
@click="bulkBulletinDrawer=true"
small
color="fifth"
depressed
>
<v-icon small left
>mdi-circle-edit-outline
</v-icon
>
{{ _('Bulk update') }}
</v-btn
>
</template>
<template>
<v-progress-circular v-for="job in jobs"
size="20" small
:indeterminate="job.status!='SUCCESS'"

:color="job.status=='SUCCESS' ? 'success': 'amber'"
:value="job.status=='SUCCESS'?100:null"
class="mx-1"
stroke="1"
></v-progress-circular>
</template>
<v-spacer></v-spacer>

<div>

<v-tooltip top>
<template v-slot:activator="{ on, attrs }">
<v-chip v-on="on" label small close color="yellow lighten-4"
class="grey--text text--darken-2"
@click:close="allBulletins"
>{{ _('About') }} ${itemsLength} {{ _('results') }}
(${searchTime} {{ _('seconds') }})
</v-chip>
</template>
<span>${search}</span>
</v-tooltip>
</div>


<v-spacer></v-spacer>
<v-chip small color="accent" v-if="selected.length"
>${selected.length} {{ _('Selected items') }}</v-chip
>
</v-toolbar>
{% endif %}

<v-spacer></v-spacer>
<v-chip small color="accent" v-if="selected.length"
>${selected.length} {{ _('Selected items') }}</v-chip
>
</v-toolbar>

</template>

Expand All @@ -180,7 +190,7 @@
<v-chip
x-small
v-if="item.review_action"
color="grey lighten-4"
v-if=" color="grey lighten-4"
class="secondary--text"
>${item.review_action}
</v-chip
Expand Down Expand Up @@ -336,6 +346,7 @@

<script>
window.__GOOGLE_MAPS_API_KEY__ = '{{ config.GOOGLE_MAPS_API_KEY }}';
window.__EXPORT_TOOL__ = ('{{ config.EXPORT_TOOL }}' === 'True');

let app = new Vue({
el: "#app",
Expand Down Expand Up @@ -438,7 +449,8 @@
bulletinDrawer: false,
bulkBulletinDrawer: false,


exportDrawer: false,
exportConfig: {},
sources: [],
locations: [],
labels: [],
Expand Down Expand Up @@ -734,6 +746,28 @@

methods: {

exportRequest(){

let ids = this.selected.map(x => x.id);
this.loading = true;
axios.post(`/export/api/bulletin/export`, {
items: ids,
config: this.exportConfig
})
.then(response => {
this.showSnack(response.data);
}).catch(error=>{
console.error(error.response?.data);
this.showSnack(error.response?.data)
}).finally(()=>{
this.loading = false;
this.exportDrawer = false;
this.selected = [];
this.exportConfig = {};

});
},


selectAllRestrict(props) {
if (props.value === false) {
Expand All @@ -743,7 +777,7 @@
})
}

console.log(props.items);

this.selected = this.selected.concat(props.items.filter(x => !x.restricted))
},

Expand Down Expand Up @@ -1074,6 +1108,7 @@
this.snackMessage = message;
this.snackbar = true;
},

has_role(user, role) {
for (const r of user.roles) {
if (r.name === role) {
Expand All @@ -1083,6 +1118,28 @@
return false;
},

bulkAllowed() {
if (this.has_role(this.currentUser, 'Admin')) {
return true;
}
if (this.has_role(this.currentUser, 'Mod')) {
return true;
}
return false;
},

exportAllowed() {
if(__EXPORT_TOOL__){
if (this.has_role(this.currentUser, 'Admin')) {
return true;
}
if (this.currentUser.can_export) {
return true;
}
}
return false;
},

editAllowed(bulletin) {

if(bulletin.restricted){
Expand Down
4 changes: 2 additions & 2 deletions enferno/admin/templates/admin/locations.html
Expand Up @@ -262,9 +262,9 @@
watch: {

locationDrawer: function (val) {
if (val == false) {
if (val === false) {

if (this.$route.path != '/admin/locations/')
if (this.$route.path !== '/admin/locations/')
this.$router.push('/admin/locations/')
}
},
Expand Down

0 comments on commit 14caa37

Please sign in to comment.