def inner_leaving_critical_section_event(self, _):
     self.critical_section = None
     self.paint_queue.put({"type": DrawingQueueEvent.BOARD_OPEN})
     if self.sending_queue:
         self.sending_queue.put(
             events.LeavingCriticalSectionEvent(
                 helpers.get_current_timestamp(), self.uuid))
         self.sending_queue.put(events.TokenPassEvent(self.last_token))
     else:
         self.event_queue.put(
             events.LeavingCriticalSectionEvent(
                 helpers.get_current_timestamp(), self.uuid))
         self.event_queue.put(events.TokenPassEvent(self.last_token))
    def handle_token_pass_event(self, event):
        token = event.data['token'] + 1
        self.last_token = token

        if self.critical_section:
            # If we have received the token and the critical section exists we unvalidate critical secion info
            self.critical_section = None
            self.paint_queue.put({'type': DrawingQueueEvent.BOARD_OPEN})

        if self.want_to_enter_critical_section:
            timestamp = helpers.get_current_timestamp()
            self.critical_section = {
                'timestamp': timestamp,
                'client_uuid': self.uuid
            }
            leave_critical_section_deamon = CriticalSectionLeaver(
                self.event_queue)
            leave_critical_section_deamon.start()
            self.want_to_enter_critical_section = False
            self.paint_queue.put({'type': DrawingQueueEvent.BOARD_CONTROLLED})
            self.sending_queue.put(
                events.EnteredCriticalSectionEvent(timestamp, self.uuid))
        else:
            if self.sending_queue:
                self.sending_queue.put(events.TokenPassEvent(token))
Example #3
0
def create_new_submission():
    verify_jwt_in_request()
    data = get_user_data_from_cookies(user_request=request)

    form = SubmitForm(request.form)
    # validates input and csrf token
    if form.validate_on_submit():

        submissions_table.put_item(
            Item={
                'Uid': str(uuid4()),
                'CreatedBy': data['username'],
                'CreatedAt': get_current_timestamp(),
                'Title': form.title.data,
                'Content': form.content.data,
                'Reviewed': False,
                'ReviewedBy': "",
                'ReviewedAt': "",
                'Deleted': False
            })
        if request.form['submit'] == "Submit":
            return redirect('/')
        elif request.form['submit'] == "Submit and create another":
            return redirect('/submit')
        else:
            return redirect('/')
    return render_template('submit_new.html', form=form, data=data)
Example #4
0
def review_submission(Uid, CreatedBy):
    verify_jwt_in_request()
    data = get_user_data_from_cookies(user_request=request)

    form = PublishForm(request.form)

    item = get_submission_item(Uid, CreatedBy)
    item_created_at = item['CreatedAt']
    item['CreatedAt'] = get_real_datetime_from_timestamp(item['CreatedAt'])

    if form.validate_on_submit():
        tags = request.form['tags'].split(",")

        current_time = get_current_timestamp()

        findings_table.put_item(
            Item={
                'Uid': Uid,
                'CreatedBy': CreatedBy,
                'CreatedAt': item_created_at,
                'firstReviewedBy': data['username'],
                'firstReviewedAt': current_time,
                'secondReviewedBy': "",
                'secondReviewedAt': "",
                'LastEditAt': "",
                'LastEditBy': "",
                'Approved': False,
                'Title': form.title.data,
                'Description': form.finding_description.data,
                'Probability': form.risk_probability.data,
                'Severity': form.risk_severity.data,
                'OverallRisk': form.risk_level.data,
                'RiskDetails': form.risk_description.data,
                'Recommendations': form.risk_recommendations.data,
                'Published': True,
                'Deleted': False,
                'Tags': tags
            })
        submissions_table.update_item(
            Key={
                'Uid': Uid,
                'CreatedBy': CreatedBy
            },
            UpdateExpression=
            "SET Reviewed = :val1, ReviewedAt = :val2, ReviewedBy = :val3",
            ExpressionAttributeValues={
                ':val1': True,
                ':val2': current_time,
                ':val3': data['username']
            })
        item = get_finding_item(Uid, CreatedBy)
        create_docx_from_item(item=item)
        return redirect('/findings/view/finding=' + Uid + "by=" + CreatedBy)

    return render_template("review_submission.html",
                           item=item,
                           form=form,
                           tags=tag_list,
                           data=data)
 def motion(self, event=None):
     if event is not None and self.left_but == 'down':
         # Make sure x and y have a value
         # if self.x_pos is not None and self.y_pos is not None:
         color = 0 if self.drawing_color == 'white' else 1
         if self.x_pos is not None and self.y_pos is not None:
             points = self.line(self.x_pos, self.y_pos, event.x, event.y)
             points = points + [(self.x_pos, self.y_pos)]
             self.master_queue.put(InnerDrawingInformationEvent(helpers.get_current_timestamp(), points, color))
         self.x_pos = event.x
         self.y_pos = event.y
        def draw_points(event):
            color = event.data['color']
            points = event.data['points']
            try:
                for point in points:
                    x, y = point
                    self.board_state[x][y] = color
            except IndexError as e:
                return

            self.paint_queue.put({
                'type': DrawingQueueEvent.DRAWING,
                'data': (points, color)
            })
            if (self.sending_queue):
                self.sending_queue.put(
                    events.DrawingInformationEvent(
                        self.uuid, helpers.get_current_timestamp(), points,
                        color))
Example #7
0
def second_review_finding(Uid, CreatedBy):
    verify_jwt_in_request()
    data = get_user_data_from_cookies(user_request=request)

    form = PublishForm(request.form)

    item = get_finding_item(Uid, CreatedBy)

    if form.validate_on_submit():
        tags = request.form['tags'].split(",")

        findings_table.update_item(
            Key={
                'Uid': Uid,
                'CreatedBy': CreatedBy
            },
            UpdateExpression=
            "SET Title = :val1, Description = :val2, RiskDetails = :val3, Probability = :val4, "
            "Severity = :val5, OverallRisk = :val6, Recommendations = :val7, Tags = :val8,"
            "Approved = :val9, secondReviewedAt = :val10, secondReviewedBy = :val11, "
            "LastEditAt = :val10, LastEditBy = :val11",
            ExpressionAttributeValues={
                ':val1': form.title.data,
                ':val2': form.finding_description.data,
                ':val3': form.risk_description.data,
                ':val4': form.risk_probability.data,
                ':val5': form.risk_severity.data,
                ':val6': form.risk_level.data,
                ':val7': form.risk_recommendations.data,
                ':val8': tags,
                ':val9': True,
                ':val10': get_current_timestamp(),
                ':val11': data['username']
            })
        item = get_finding_item(Uid, CreatedBy)
        create_docx_from_item(item=item)
        return redirect('/findings/view/finding=' + Uid + 'by=' + CreatedBy)

    return render_template("second_review_finding.html",
                           item=item,
                           form=form,
                           tags=tag_list,
                           data=data)