Skip to content

Commit

Permalink
Updated permissions and gui
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafamat committed Oct 22, 2023
1 parent 672a9f4 commit bf20c83
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 57 deletions.
24 changes: 16 additions & 8 deletions backend/api/_template/_permission.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,58 @@
"required": true,
"collection": true
},
"per_is_active": {
"bsonType": "bool",
"title": "Is Active",
"description": "Permission is active",
"default": true,
"trueText": "Yes",
"falseText": "No"
},
"per_read": {
"bsonType": "bool",
"title": "Read",
"description": "Read Permission",
"description": "Read permission",
"default": false,
"trueText": "Yes",
"falseText": "No"
},
"per_insert": {
"bsonType": "bool",
"title": "Insert",
"description": "Insert Permission",
"description": "Insert permission",
"default": false,
"trueText": "Yes",
"falseText": "No"
},
"per_update": {
"bsonType": "bool",
"title": "Update",
"description": "Update Permission",
"description": "Update permission",
"default": false,
"trueText": "Yes",
"falseText": "No"
},
"per_delete": {
"bsonType": "bool",
"title": "Delete",
"description": "Delete Permission",
"description": "Delete permission",
"default": false,
"trueText": "Yes",
"falseText": "No"
},
"per_action": {
"bsonType": "bool",
"title": "Action",
"description": "Action Run Permission",
"description": "Action run permission",
"default": false,
"trueText": "Yes",
"falseText": "No"
},
"per_query": {
"bsonType": "bool",
"title": "Query",
"description": "Query Run Permission",
"description": "Query run permission",
"default": false,
"trueText": "Yes",
"falseText": "No"
Expand Down Expand Up @@ -112,8 +120,8 @@
"index": [
["per_tag"],
["per_collection_id"],
["per_collection_id", "per_tag", "per_query"],
["per_collection_id", "per_tag", "per_read", "per_insert", "per_update", "per_delete", "per_query"]
["per_collection_id", "per_is_active", "per_tag", "per_query"],
["per_collection_id", "per_is_active", "per_tag", "per_read", "per_insert", "per_update", "per_delete", "per_query"]
],
"sort": {
"_modified_at": -1
Expand Down
36 changes: 20 additions & 16 deletions backend/api/_template/_token.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,42 @@
"tkn_is_active": {
"bsonType": "bool",
"title": "Is Active",
"description": "Token Accesibility",
"default": true
"description": "Token accesibility",
"default": true,
"trueText": "Yes",
"falseText": "No"
},
"tkn_grant_read": {
"bsonType": "bool",
"title": "Grant Read",
"description": "Grant Read",
"default": false
"description": "Grant for reading",
"default": false,
"trueText": "Yes",
"falseText": "No"
},
"tkn_grant_insert": {
"bsonType": "bool",
"title": "Grant Insert",
"description": "Grant Insert",
"default": false
"description": "Grant for inserting",
"default": false,
"trueText": "Yes",
"falseText": "No"
},
"tkn_grant_update": {
"bsonType": "bool",
"title": "Grant Update",
"description": "Grant Update",
"default": false
},
"tkn_grant_upsert": {
"bsonType": "bool",
"title": "Grant Upsert",
"description": "Grant Upsert",
"default": false
"description": "Grant for updating",
"default": false,
"trueText": "Yes",
"falseText": "No"
},
"tkn_grant_delete": {
"bsonType": "bool",
"title": "Grant Delete",
"description": "Grant Delete",
"default": false
"description": "Grant for deleting",
"default": false,
"trueText": "Yes",
"falseText": "No"
},
"tkn_allowed_ips": {
"bsonType": "array",
Expand Down
23 changes: 14 additions & 9 deletions backend/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2187,17 +2187,17 @@ def collections_f(self, obj):
data__ = []
for coll_ in collections_:
for usr_tag_ in usr_tags_:
filter_ = {
permission_ = Mongo().db_["_permission"].find_one({
"per_collection_id": coll_["col_id"],
"per_is_active": True,
"per_tag": usr_tag_,
"$or": [
{"per_read": True},
{"per_insert": True},
{"per_update": True},
{"per_delete": True}
]
}
permission_ = Mongo().db_["_permission"].find_one(filter_)
})
if permission_:
data__.append(coll_)
break
Expand Down Expand Up @@ -2231,6 +2231,7 @@ def collection_f(self, obj):
for usr_tag_ in usr_tags_:
permissions_ = Mongo().db_["_permission"].find_one({
"per_collection_id": col_id_,
"per_is_active": True,
"per_tag": usr_tag_,
"$or": [
{"per_insert": True},
Expand Down Expand Up @@ -2688,9 +2689,10 @@ def savequery_f(self, obj_):
raise AuthError("user not found")
usr_tags_ = user_["_tags"] if "_tags" in user_ and len(user_["_tags"]) > 0 else []

permission_ = Mongo().db_["_permission"].find_one({"per_collection_id": que_collection_id_, "per_tag": {"$in": usr_tags_}, "per_query": True})
if not permission_:
raise AuthError("no permission to save query")
if not (Auth().is_manager_f(user_) or Auth().is_admin_f(user_)):
permission_ = Mongo().db_["_permission"].find_one({"per_collection_id": que_collection_id_, "per_is_active": True, "per_tag": {"$in": usr_tags_}, "per_query": True})
if not permission_:
raise AuthError("no permission to save query")

doc_ = {
"que_aggregate": aggregate_,
Expand Down Expand Up @@ -3762,8 +3764,11 @@ def access_validate_by_api_token_f(self, bearer_, operation_, qid_):
if qid_ not in find_["tkn_allowed_queries"]:
raise AuthError(f"token is not allowed to read {qid_}")

if not ("tkn_allowed_ips" in find_ and len(find_["tkn_allowed_ips"]) > 0 and
(ip_ in find_["tkn_allowed_ips"] or "0.0.0.0" in find_["tkn_allowed_ips"])):
if not (
"tkn_allowed_ips" in find_ and
len(find_["tkn_allowed_ips"]) > 0 and
(ip_ in find_["tkn_allowed_ips"] or "0.0.0.0" in find_["tkn_allowed_ips"])
):
raise AuthError(f"IP is not allowed to do {operation_}")

return {"result": True}
Expand Down Expand Up @@ -3954,7 +3959,7 @@ def permission_f(self, input_):

permit_ = False
for usr_tag_ in usr_tags_:
permission_ = Mongo().db_["_permission"].find_one({"per_collection_id": collection_id_, "per_tag": usr_tag_})
permission_ = Mongo().db_["_permission"].find_one({"per_collection_id": collection_id_, "per_is_active": True, "per_is_active": True, "per_tag": usr_tag_})
if permission_:
per_insert_ = "per_insert" in permission_ and permission_["per_insert"] is True
per_read_ = "per_read" in permission_ and permission_["per_read"] is True
Expand Down
2 changes: 1 addition & 1 deletion pwa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "technoplatz-bi-pwa",
"version": "4.4.8",
"version": "4.4.9",
"author": "Mustafa Mat, Technoplatz IT Solutions GmbH",
"homepage": "https://bi.technoplatz.com",
"scripts": {
Expand Down
15 changes: 8 additions & 7 deletions pwa/src/app/pages/collection/collection.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,15 @@ <h3>{{ subheader | titlecase | translate }}&nbsp;</h3>
mode="md">
</ion-checkbox>
</th>

<!-- DATA LIST HEADER -->
<th *ngFor="let item of properties_ | keyvalue : orderByIndex">
<div>
{{ item.value.title }}
<span *ngIf="searched && searched[item.key]?.f" class="danger">[F]</span><br />
<ion-button size="small" fill="clear" class="ion-no-padding" (click)="set_search(item.key)">{{
item.key }}<ion-icon name="filter-sharp" class="filter-icon"></ion-icon></ion-button>
{{ item.value.title }}<br />
<ion-button size="small"
[class]="searched && searched[item.key]?.f ? 'filtered-btn' : 'unfiltered-btn'"
(click)="set_search(item.key)">{{
item.key }}<ion-icon name="filter-sharp"></ion-icon></ion-button>
</div>

<!-- SEARCH BOX -->
<div *ngIf="searched && searched[item.key]?.actived" class="search-box">
<div class="searched-title">{{ item.value.title }}&nbsp;&nbsp;</div>
Expand All @@ -182,7 +181,7 @@ <h3>{{ subheader | titlecase | translate }}&nbsp;</h3>
<div *ngIf="item.value.bsonType!='bool'" class="search-ops">
<ion-button [color]="searched[item.key].op == 'contains' ? 'primary' : 'light'" size="small"
(click)="set_searchItemOp(item.key, 'contains')">
in
{{ 'in' | translate }}
</ion-button>
<ion-button [color]="searched[item.key].op == 'eq' ? 'primary' : 'light'" size="small"
(click)="set_searchItemOp(item.key, 'eq')">
Expand Down Expand Up @@ -227,9 +226,11 @@ <h3>{{ subheader | titlecase | translate }}&nbsp;</h3>
</ion-input>
</div>
<ion-button size="small" (click)="doSearch(item.key, searched[item.key].kw)">
<ion-icon name="search"></ion-icon>
{{ 'Search' | translate }}
</ion-button>
<ion-button color="light" size="small" (click)="doResetSearchItem(item.key)">
<ion-icon name="close"></ion-icon>
{{ 'Cancel' | translate }}
</ion-button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion pwa/src/app/pages/collection/collection.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class CollectionPage implements OnInit {
refresh_data(p: number) {
return new Promise((resolve, reject) => {
this.is_loaded = this.is_selected = false;
this.data = [];
// this.data = [];
this.schemavis_ = false;
this.storage.get("LSSEARCHED_" + this.id).then((LSSEARCHED_: any) => {
this.searched = LSSEARCHED_ ? LSSEARCHED_ : null;
Expand Down
36 changes: 23 additions & 13 deletions pwa/src/assets/css/shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ ion-note {

.data-sq-button ion-icon,
.data-sq-button ion-spinner {
width: 24px !important;
height: 24px !important;
margin-bottom: 4px !important;
width: 28px !important;
height: 28px !important;
margin-bottom: 2px !important;
color: var(--ion-color-primary);
}

Expand Down Expand Up @@ -1171,8 +1171,23 @@ sup {
font-size: 9px;
}

.filter-icon {
font-size: 12px;
.filtered-btn {
--background: var(--ion-color-primary) !important;
--padding: 0px !important;
--border-width: 0px !important;
margin-bottom: -2px;
}

.unfiltered-btn {
--color: var(--ion-color-primary) !important;
--background: none !important;
--padding-start: 0px;
--border-width: 0px !important;
margin-bottom: -2px;
}

.filtered-btn ion-icon,
.unfiltered-btn ion-icon {
margin-left: 8px;
}

Expand Down Expand Up @@ -1784,8 +1799,8 @@ ion-checkbox {
width: 240px;
height: auto;
margin-left: -7px;
margin-top: 1px;
border: 1px solid var(--ion-color-dark);
margin-top: 6px;
border: 2px solid var(--ion-color-primary);
z-index: 999999 !important;
background-color: #fff;
cursor: default;
Expand Down Expand Up @@ -1949,19 +1964,14 @@ ion-checkbox {
}

.data-table th {
padding-bottom: 0rem !important;
border-bottom: 2px solid var(--ion-color-primary);
}

.data-table tr:not(:first-child):hover {
background-color: #eee;
cursor: pointer;
}

.data-table tr:first-child {
border-bottom: 2px solid var(--ion-color-dark);
cursor: pointer;
}

.data-grid {
margin-top: 10px;
}
Expand Down
4 changes: 3 additions & 1 deletion pwa/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"Save Query": "Abfrage speichern",
"Save Schema": "Schema speichern",
"Saving": "Speichern",
"Search": "Suche",
"Security": "Sicherheit",
"Security Settings": "Sicherheitseinstellungen",
"Serials": "Serien",
Expand Down Expand Up @@ -191,8 +192,9 @@
"You can edit the query or get help from the Administrators": "Sie können die Abfrage bearbeiten oder die Hilfe des Administrators in Anspruch nehmen",
"Your OTP has been sent by E-mail": "Ihr Verifizierungscode wurde jetzt per E-Mail versandt",
"and": "und",
"in": "enthalten",
"live": "live",
"records are displayed": "Datensatz wird angezeigt",
"records were filtered": "Datensätze wurden gefiltert",
"test": "Test"
}
}
4 changes: 3 additions & 1 deletion pwa/src/assets/i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"Save Query": "Sorguyu Kaydet",
"Save Schema": "Şemayı Kaydet",
"Saving": "Kaydediliyor",
"Search": "Ara",
"Security": "Güvenlik",
"Security Settings": "Güvenlik Ayarları",
"Serials": "Seri Numaraları",
Expand Down Expand Up @@ -191,8 +192,9 @@
"You can edit the query or get help from the Administrators": "Sorguyu düzenleyebilir ya da Yöneticiden yardım isteyebilirsiniz",
"Your OTP has been sent by E-mail": "Doğrulama kodunuz şimdi E-posta ile gönderildi",
"and": "ve",
"in": "içerir",
"live": "Canlı",
"records are displayed": "kayıt gösterilmektedir",
"records were filtered": "kayıt filtrelendi",
"test": "Test"
}
}

0 comments on commit bf20c83

Please sign in to comment.