Skip to content

Commit 22c0624

Browse files
committed
Improve bit setting
1 parent bc2e461 commit 22c0624

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

OpenFlow/src/DatabaseConnection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class DatabaseConnection {
118118
console.log("Running in multi tenant mode, skip adding permissions for " + item.name);
119119
} else if (arr[0]._type == "user") {
120120
var u: User = User.assign(arr[0]);
121-
if (u.getRight(item._id) == null) {
121+
if (!u.hasRight(item._id, Rights.read)) {
122122
console.log("Assigning " + item.name + " read permission to " + u.name);
123123
u.addRight(item._id, item.name, [Rights.read], false);
124124

@@ -131,7 +131,7 @@ export class DatabaseConnection {
131131
var r: Role = Role.assign(arr[0]);
132132
if (r._id == WellknownIds.admins || r._id == WellknownIds.users) {
133133
}
134-
if (r.getRight(item._id) == null) {
134+
if (!r.hasRight(item._id, Rights.read)) {
135135
console.log("Assigning " + item.name + " read permission to " + r.name);
136136
r.addRight(item._id, item.name, [Rights.read], false);
137137
await this.db.collection("users").updateOne({ _id: r._id }, { $set: { _acl: r._acl } });
@@ -157,7 +157,7 @@ export class DatabaseConnection {
157157
console.log("Running in multi tenant mode, skip removing permissions for " + item.name);
158158
} else if (arr[0]._type == "user") {
159159
var u: User = User.assign(arr[0]);
160-
if (u.getRight(item._id) != null) {
160+
if (u.hasRight(item._id, Rights.read)) {
161161
console.log("Removing " + item.name + " read permissions from " + u.name);
162162
u.removeRight(item._id, [Rights.read]);
163163
// await this.db.collection("users").save(u);
@@ -167,7 +167,7 @@ export class DatabaseConnection {
167167
}
168168
} else if (arr[0]._type == "role") {
169169
var r: Role = Role.assign(arr[0]);
170-
if (r.getRight(item._id) != null) {
170+
if (r.hasRight(item._id, Rights.read)) {
171171
console.log("Removing " + item.name + " read permissions from " + r.name);
172172
r.removeRight(item._id, [Rights.read]);
173173
// await this.db.collection("users").save(r);

OpenFlow/src/base.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,17 @@ export class Base implements IBase {
123123
if (!right) { return; }
124124
rights.forEach(bit => {
125125
if (bit == Rights.full_control) { this._acl = this._acl.filter(x => x._id != _id); } else { right.unsetBit(bit); }
126-
127126
});
128127
this.setRight(right);
128+
var view = right.getview();
129+
var posetiv = view.filter(x => x > 0);
130+
if (posetiv.length == 0) {
131+
this._acl = this._acl.filter(x => x._id != _id);
132+
}
133+
}
134+
hasRight(_id: string, bit: number, deny: boolean = false): boolean {
135+
var ace = this.getRight(_id, deny);
136+
if (ace == null) return false;
137+
return ace.getBit(bit);
129138
}
130139
}

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.410
1+
0.0.411

0 commit comments

Comments
 (0)