def get(self): """Request handler for GET operations.""" try: dashboard_id = http_util.GetIntegerParam(self.request, fields.ID) row = dashboard_model.Dashboard.GetDashboard(dashboard_id) data = row.GetDashboardData() filename = http_util.GetStringParam(self.request, 'filename', required=False) self.RenderJson(data, filename=filename) except Exception as err: self.RenderJson(data={error_fields.MESSAGE: err.message}, status=400)
def get(self): """Request handler for POST operations.""" try: dashboard_id = http_util.GetIntegerParam(self.request, fields.ID) title = http_util.GetStringParam(self.request, fields.TITLE, False) new_id = dashboard_model.Dashboard.CopyDashboard( dashboard_id, title) self.RenderJson(data={fields.ID: new_id}) except (base.InitializeError, dashboard_model.InitializeError, http_util.ParameterError) as err: self.RenderJson(data={error_fields.MESSAGE: err.message}, status=400)
def get(self): """Request handler for POST operations.""" try: dashboard_id = http_util.GetIntegerParam(self.request, fields.ID) row = dashboard_model.Dashboard.GetDashboard(dashboard_id) if not (row.isOwner()): msg = ('This dashboard is owned by {owner}, and cannot be ' 'modified.'.format(owner=row.created_by.email())) self.RenderJson(data={error_fields.MESSAGE: msg}, status=403) return row.key.delete() except (base.InitializeError, dashboard_model.InitializeError, http_util.ParameterError) as err: self.RenderJson(data={error_fields.MESSAGE: err.message}, status=400)
def get(self): """Request handler for POST operations.""" dashboard_id = http_util.GetIntegerParam(self.request, fields.ID) row = dashboard_model.Dashboard.GetDashboard(dashboard_id) if (not row.canEdit()): msg = ('You are not an owner or writer for this dashboard, and ' 'cannot modify it. Contact {owner} for access.'.format( owner=row.created_by.email())) self.RenderJson(data={error_fields.MESSAGE: msg}, status=403) return try: title = http_util.GetStringParam(self.request, fields.TITLE) dashboard_model.Dashboard.RenameDashboard(dashboard_id, title) except (base.InitializeError, dashboard_model.InitializeError, http_util.ParameterError) as err: self.RenderJson(data={error_fields.MESSAGE: err.message}, status=400)
def get(self): """Request handler for POST operations.""" try: dashboard_id = http_util.GetIntegerParam(self.request, fields.ID) row = dashboard_model.Dashboard.GetDashboard(dashboard_id) if (not row.isOwner()): msg = ('You are not an owner of this dashboard, and cannot ' 'transfer ownership. Contact {owner} for ' 'reassignment if this is in error.'.format( owner=row.created_by.email())) self.RenderJson(data={error_fields.MESSAGE: msg}, status=403) return email = http_util.GetStringParam(self.request, fields.EMAIL) dashboard_model.Dashboard.EditDashboardOwner(dashboard_id, email) except (base.InitializeError, dashboard_model.InitializeError, http_util.ParameterError) as err: logging.error('EditDashboardOwnerHandler() failed:') logging.error(err) self.RenderJson(data={error_fields.MESSAGE: err.message}, status=400)
def post(self): """Request handler for POST operations.""" current_owner_email = None try: dashboard_id = http_util.GetIntegerParam(self.request, fields.ID) row = dashboard_model.Dashboard.GetDashboard(dashboard_id) if (not row.canEdit()): msg = ('You are not an owner or writer for this dashboard, ' 'and cannot modify it. Contact {owner} for access.'. format(owner=row.created_by.email())) self.RenderJson(data={error_fields.MESSAGE: msg}, status=403) return data = http_util.GetJsonParam(self.request, fields.DATA) title = dashboard_model.Dashboard.GetDashboardTitle(data) if fields.OWNER in data: current_owner_email = data[fields.OWNER] try: new_owner = dashboard_model.Dashboard.GetDashboardOwner( current_owner_email) except users.UserNotFoundError: new_owner = users.get_current_user() data[fields.OWNER] = new_owner.email() warning = ( 'The user {current} does not exist. Owner set to {new}.'. format(current=current_owner_email, new=new_owner.email())) logging.error(warning) data[error_fields.WARNINGS] = [warning] if 'writers' not in data: data['writers'] = [] new_writers = data.get('writers') writers_changed = row.writersChanged(data.get('writers')) owners_changed = (data[fields.OWNER] != new_owner.email()) if owners_changed or writers_changed: if (not row.isOwner()): msg = ('You are not an owner of this dashboard, and cannot' 'transfer ownership. Contact {owner} for ' 'reassignment if this is in error.'.format( owner=row.created_by.email())) self.RenderJson(data={error_fields.MESSAGE: msg}, status=403) return if owners_changed: data[fields.OWNER] = new_owner.email() if writers_changed: row.writers = [writer['email'] for writer in new_writers] row.data = json.dumps(data) row.title = title row.owner = new_owner row.modified_by = users.get_current_user() row.put() self.RenderJson(data) except (base.InitializeError, dashboard_model.InitializeError, http_util.ParameterError) as err: self.RenderJson(data={error_fields.MESSAGE: err.message}, status=400)