Permalink
Browse files

Merge branch 'master' of git://github.com/flavour/eden

  • Loading branch information...
2 parents d8a929d + d532d89 commit 1b3ac5649f4c2a0ad5450d48459bf4ecfe41a465 @flavour committed Oct 8, 2012
@@ -609,7 +609,7 @@ def submitted_repr(id):
Return the initial of the first name and the complete last name
"""
if not id:
- repr_text = current.messages.NONE
+ repr_text = T("Imported data")
else:
table = db.pr_person
row = db(table.id == id).select(table.first_name,
@@ -626,8 +626,11 @@ def approved_repr(id):
"""
Return the initials of the first and the last name
"""
- if not id:
+
+ if id is None:
repr_text = T("Approval pending")
+ elif id == 0:
+ repr_text = T("Approved")
else:
table = db.pr_person
row = db(table.id == id).select(table.first_name,
@@ -646,11 +649,12 @@ def action_repr(id):
"""
Return the action button for this row
"""
- if not id:
+
+ if id is None:
repr_text = current.messages.NONE
else:
row = s3db.stats_group[id]
- if row.approved_by:
+ if row.approved_by != None:
repr_text = A(T("View"),
_id = id,
_class = "viewButton",
@@ -966,6 +970,7 @@ def approveReport(id):
query = (s3db.stats_data.group_id == id)
resource = s3db.resource("stats_data", filter=query, unapproved=True)
resource.approve()
+ s3task.async("stats_group_clean")
return True
rec_instance = record.stats_group_instance
if rec_instance == "doc_image":
@@ -974,6 +979,12 @@ def approveReport(id):
resource = s3db.resource("doc_image", filter=query, unapproved=True)
resource.approve()
return True
+ elif rec_instance == "doc_document":
+ query = (sgtable.id == id) &\
+ (s3db.doc_document.source_id == sgtable.source_id)
+ resource = s3db.resource("doc_document", filter=query, unapproved=True)
+ resource.approve()
+ return True
return False
# -----------------------------------------------------------------------------
@@ -1025,12 +1036,18 @@ def report():
reportDetails = getReportDetails(id, buttonsRequired=buttonsRequired)
data = json.dumps(reportDetails)
elif request.args(0) == "approve":
- id = request.post_vars.id
- if approveReport(id):
- report = reportDataTable(request)
- data = json.dumps(report)
+ # Check authorization
+ permitted = current.auth.s3_has_permission
+ authorised = permitted("approve", "stats_group")
+ if not authorised:
+ data = json.dumps(str(T("You are not permitted to approve documents")))
else:
- data = json.dumps(str(T("Failed to approve")))
+ id = request.post_vars.id
+ if approveReport(id):
+ report = reportDataTable(request)
+ data = json.dumps(report)
+ else:
+ data = json.dumps(str(T("Failed to approve")))
elif request.args(0) == "decline":
id = request.post_vars.id
if declineReport(id):
@@ -1127,8 +1144,17 @@ def import_vul_part1():
response.headers["Content-Type"] = "application/json"
return json({"Error": str(T("Error File missing"))})
+ # Check authorization
+ permitted = current.auth.s3_has_permission
+ authorised = permitted("create", "vulnerability_data")
+ if not authorised:
+ response.headers["Content-Type"] = "application/json"
+ return json({"Error": str(T("You are not permitted to upload files"))})
+
from lxml import etree
+ from datetime import datetime
+ creator = auth.s3_logged_in_person()
output = s3_rest_controller("vulnerability", "data",
csv_stylesheet="data.xsl")
upload_id = output[0]
@@ -1174,8 +1200,8 @@ def import_vul_part1():
row = group[0]
group_dict = {}
group_dict["group"] = key
- group_dict["date"] = row["date"]
- group_dict["created_by"] = row["created_by"]
+ group_dict["date"] = datetime.strptime(row["date"], "%Y-%m-%d").strftime("%d-%b-%y")
+ group_dict["created_by"] = creator
loc = row["location_id"][1][12:] # strip location L#: from the tuid
loc = "%s %s" % (loc, loc_label)
group_dict["location"] = loc
View
@@ -175,6 +175,20 @@ def msg_search_subscription_notifications(frequency):
# -----------------------------------------------------------------------------
if settings.has_module("stats"):
+ def stats_group_clean(user_id=None):
+ """
+ Update the stats_aggregate table by calculating all the stats_group
+ records which have the dirty flag set to True
+ """
+ if user_id:
+ # Authenticate
+ auth.s3_impersonate(user_id)
+ # Run the Task
+ result = s3db.stats_group_clean()
+ return result
+
+ tasks["stats_group_clean"] = stats_group_clean
+
def stats_update_time_aggregate(data_id=None, user_id=None):
"""
Update the stats_aggregate table for the given stats_data record
Oops, something went wrong.

0 comments on commit 1b3ac56

Please sign in to comment.