Skip to content

Commit f824dc5

Browse files
authored
Merge pull request openiap#6 from skadefro/master
bug fixes and adding coc
2 parents 2bc196c + 5d713ab commit f824dc5

9 files changed

Lines changed: 155 additions & 81 deletions

File tree

CODE_OF_CONDUCT.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at team@nodered.org. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [http://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: http://contributor-covenant.org
74+
[version]: http://contributor-covenant.org/version/1/4/

OpenFlow/src/Config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class Config {
1010
public static db:DatabaseConnection = null;
1111
public static auto_create_users:boolean = Config.parseBoolean(Config.getEnv("auto_create_users", "false"));
1212
public static auto_create_domains:string[] = Config.parseArray(Config.getEnv("auto_create_domains", ""));
13+
public static allow_user_registration:boolean = Config.parseBoolean(Config.getEnv("allow_user_registration", "false"));
1314

1415
public static api_bypass_perm_check:boolean = Config.parseBoolean(Config.getEnv("api_bypass_perm_check", "false"));
1516
public static websocket_package_size:number = parseInt(Config.getEnv("websocket_package_size", "1024"), 10);

OpenFlow/src/Messages/Message.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { MapReduceMessage } from "./MapReduceMessage";
2020
import { CloseQueueMessage } from "./CloseQueueMessage";
2121
import { RegisterQueueMessage } from "./RegisterQueueMessage";
2222
import { QueueMessage } from "./QueueMessage";
23+
import { RegisterUserMessage } from "./RegisterUserMessage";
2324

2425
export class Message {
2526
public id: string;
@@ -95,6 +96,9 @@ export class Message {
9596
case "signin":
9697
this.Signin(cli);
9798
break;
99+
case "registeruser":
100+
this.RegisterUser(cli);
101+
break;
98102
case "mapreduce":
99103
this.MapReduce(cli);
100104
break;
@@ -407,6 +411,30 @@ export class Message {
407411
}
408412
this.Send(cli);
409413
}
414+
private async RegisterUser(cli: WebSocketClient): Promise<void> {
415+
this.Reply();
416+
var msg: RegisterUserMessage;
417+
var user:User;
418+
try {
419+
msg = RegisterUserMessage.assign(this.data);
420+
if(msg.name == null || msg.name == undefined || msg.name == "") { throw new Error("Name cannot be null"); }
421+
if(msg.username == null || msg.username == undefined || msg.username == "") { throw new Error("Username cannot be null"); }
422+
if(msg.password == null || msg.password == undefined || msg.password == "") { throw new Error("Password cannot be null"); }
423+
user = await User.FindByUsername(msg.username);
424+
if(user!==null && user !== undefined) { throw new Error("Illegal username"); }
425+
user = await User.ensureUser(msg.name, msg.username, msg.password, null);
426+
msg.user = new TokenUser(user);
427+
} catch (error) {
428+
msg.error = error.toString();
429+
}
430+
try {
431+
this.data = JSON.stringify(msg);
432+
} catch (error) {
433+
this.data = "";
434+
msg.error = error.toString();
435+
}
436+
this.Send(cli);
437+
}
410438
}
411439

412440
export class JSONfn {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Base } from "../base";
2+
import { TokenUser } from "../TokenUser";
3+
4+
export class RegisterUserMessage implements IReplyMessage {
5+
public error: string;
6+
public jwt:any;
7+
8+
public user:TokenUser;
9+
public name:string;
10+
public username:string;
11+
public password:string;
12+
static assign(o:any):RegisterUserMessage {
13+
if (typeof o === "string" || o instanceof String) {
14+
return Object.assign(new RegisterUserMessage(), JSON.parse(o.toString()));
15+
}
16+
return Object.assign(new RegisterUserMessage(), o);
17+
}
18+
}

OpenFlow/src/User.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,18 @@ export class User extends Base {
112112
});
113113
}
114114
}
115+
116+
public static async ensureUser(name:string, username:string, password:string, id:string):Promise<User> {
117+
var user:User = await User.FindByUsernameOrId(username, id);
118+
if(user!==null && (user._id === id || id === null)) { return user; }
119+
if(user!==null && id !== null ) { await Config.db.DeleteOne(user._id, "users", TokenUser.rootToken()); }
120+
user = new User(); user._id = id; user.name = name; user.username = username;
121+
if(password===null || password===undefined || password === "") { password = Math.random().toString(36).substr(2, 9); }
122+
await user.SetPassword(password);
123+
user = await Config.db.InsertOne(user, "users", TokenUser.rootToken());
124+
user = User.assign(user);
125+
return user;
126+
}
127+
115128
}
116129

OpenFlow/src/WebSocketClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,18 @@ export class WebSocketClient {
155155
var first: SocketMessage = msgs[0];
156156
if(first.count === msgs.length) {
157157
if(msgs.length === 1) {
158+
this._receiveQueue = this._receiveQueue.filter(function (msg: SocketMessage):boolean { return msg.id!==id;});
158159
var singleresult: Message = Message.frommessage(first, first.data);
159160
singleresult.Process(this);
160161
} else {
161162
var buffer: string = "";
162163
msgs.forEach(msg => {
163164
if(msg.data!==null && msg.data !== undefined) { buffer += msg.data; }
164165
});
166+
this._receiveQueue = this._receiveQueue.filter(function (msg: SocketMessage):boolean { return msg.id!==id;});
165167
var result: Message = Message.frommessage(first, buffer);
166168
result.Process(this);
167169
}
168-
this._receiveQueue = this._receiveQueue.filter(function (msg: SocketMessage):boolean { return msg.id!==id;});
169170
}
170171
});
171172
this._sendQueue.forEach(msg => {

OpenFlow/src/public/Controllers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,13 @@ module openflow {
442442
this.loadData();
443443
});
444444
}
445+
async DeleteOne(model: any):Promise<any> {
446+
this.loading = true;
447+
await this.api.Delete(this.collection, model);
448+
this.models = this.models.filter(function (m: any):boolean { return m._id!==model._id;});
449+
this.loading = false;
450+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
451+
}
445452
async DeleteMany():Promise<void> {
446453
this.loading = true;
447454
var Promises:Promise<DeleteOneMessage>[] = [];

OpenFlowNodeRED/src/nodered/nodes/api.html

Lines changed: 11 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</div>
3737
</script>
3838
<script type="text/x-red" data-help-name="api get jwt">
39-
Request a JWT token for talking with API. Leave config blank to impersonate root
39+
Request a JWT token for talking with API. Leave config blank to impersonate root.
4040
</script>
4141
<script type="text/javascript">
4242
RED.nodes.registerType('api get jwt', {
@@ -430,7 +430,7 @@
430430
</div>
431431
</script>
432432
<script type="text/x-red" data-help-name="grant permission">
433-
<p>Delete payload as new entity in collection</p>
433+
<p>Grants a role (or user if set by msg.targetid) a specific permission on the entity/entities in payload.</p>
434434
</script>
435435
<script type="text/javascript">
436436
RED.nodes.registerType('grant permission', {
@@ -508,7 +508,7 @@
508508
</div>
509509
</script>
510510
<script type="text/x-red" data-help-name="revoke permission">
511-
<p>Delete payload as new entity in collection</p>
511+
<p>Revoke a specific permission for a role (or user if set by msg.targetid) on the entity/entities in payload.</p>
512512
</script>
513513
<script type="text/javascript">
514514
RED.nodes.registerType('revoke permission', {
@@ -563,81 +563,6 @@
563563

564564

565565

566-
<script type="text/x-red" data-template-name="grant permission">
567-
<div class="form-row">
568-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
569-
<input type="text" id="node-input-name" placeholder="Name">
570-
</div>
571-
<div class="form-row">
572-
<label for="node-input-targetid"><i class="fa fa-tasks"></i> Target</label>
573-
<select id="node-input-targetid-select">
574-
</select>
575-
<input id="node-input-targetid" type="hidden">
576-
</div>
577-
<div class="form-row">
578-
<label for="node-input-typed-entities"><i class="fa fa-list"></i> Entities</label>
579-
<input id="node-input-typed-entities" type="text" style="width: 70%">
580-
<input id="node-input-entities" type="hidden">
581-
</div>
582-
<div class="form-row">
583-
<label><i class="fa fa-tag"></i> Bitsexplained </label>
584-
(F:-1, R:2, U:3, D:4, I:5)
585-
</div>
586-
<div class="form-row">
587-
<label for="node-input-bits"><i class="fa fa-tag"></i> Bits </label>
588-
<input type="text" id="node-input-bits" placeholder="Bits seperated by comma,">
589-
</div>
590-
</script>
591-
<script type="text/x-red" data-help-name="grant permission">
592-
<p>Delete payload as new entity in collection</p>
593-
</script>
594-
<script type="text/javascript">
595-
RED.nodes.registerType('grant permission', {
596-
category: 'api',
597-
color: "#a6bbcf",
598-
defaults: {
599-
name: { value: "" },
600-
targetid: { value: "result._id", required: true },
601-
entities: { value: "payload", required: true },
602-
bits: { value: "", required: true }
603-
},
604-
inputs: 1,
605-
outputs: 1,
606-
icon: "bridge.png",
607-
label: function () {
608-
return this.name || "grant permission";
609-
},
610-
labelStyle: function () {
611-
return this.name ? "node_label_italic" : "";
612-
},
613-
614-
oneditprepare: function () {
615-
$("#node-input-typed-entities").typedInput({ types: ['msg'] });
616-
$("#node-input-typed-entities").typedInput('value', this.entities);
617-
618-
619-
$.getJSON('api_roles',function(data) {
620-
$.each(data, function(i, ele) {
621-
$('#node-input-targetid-select').append($('<option>', {
622-
value: ele._id,
623-
text : ele.name
624-
}));
625-
});
626-
$('#node-input-targetid-select').val($('#node-input-targetid').val());
627-
});
628-
629-
},
630-
oneditsave: function () {
631-
$('#node-input-targetid').val($('#node-input-targetid-select').val());
632-
$("#node-input-entities").val($("#node-input-typed-entities").typedInput('value'));
633-
}
634-
635-
});
636-
</script>
637-
638-
639-
640-
641566

642567

643568

@@ -699,7 +624,14 @@
699624

700625
</script>
701626
<script type="text/x-red" data-help-name="map reduce">
702-
<p>Delete payload as new entity in collection</p>
627+
<p>
628+
Run a mapreduce on a collection.
629+
If output is set for inline, the result will be returned in payload, for all else, you can get the result in the receiving collection.<br>
630+
Finalize is optional, and can be left blank if not needed.<br>
631+
Be carefull to keep _acl on all reduced objects, so you have permission to read the result.<br>
632+
<a href="https://docs.mongodb.com/manual/tutorial/map-reduce-examples/index.html">map-reduce-examples</a><br>
633+
<a href="https://docs.mongodb.com/manual/reference/method/db.collection.mapReduce/#db.collection.mapReduce">dokumentation</a>
634+
</p>
703635
</script>
704636
<script type="text/javascript">
705637
RED.nodes.registerType('map reduce', {

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.73
1+
0.0.75

0 commit comments

Comments
 (0)