def manager_change_status(self, type, number, req): db = self.env.get_db_cnx() dbBack = dbBackend(db) review = dbBack.getCodeReviewsByID(number) review.Status = type review.save(db) req.redirect(req.hdf['trac.href.peerReviewView'] + "?Review=" + number)
def vote(self, type, number, req): db = self.env.get_db_cnx() dbBack = dbBackend(db) reviewEntry = dbBack.getReviewerEntry(number, req.hdf['myname']) if reviewEntry != None: reviewEntry.Vote = type reviewEntry.save(db) reviewID = req.args.get('Review') review = dbBack.getCodeReviewsByID(reviewID) voteyes = dbBack.getVotesByID("1", reviewID) voteno = dbBack.getVotesByID("0", reviewID) notvoted = dbBack.getVotesByID("-1", reviewID) total_votes_possible = float(voteyes) + float(voteno) + float(notvoted) threshold = float(dbBack.getThreshold())/100 # recalculate vote ratio, while preventing divide by zero tests, and change status if necessary if total_votes_possible != 0: vote_ratio = float(voteyes)/float(total_votes_possible) if (vote_ratio >= threshold): review.Status = "Reviewed" else: review.Status = "Open for review" review.save(db) req.redirect(req.hdf['trac.href.peerReviewView'] + "?Review=" + reviewID)
def submit_for_inclusion(self, number, req): db = self.env.get_db_cnx() dbBack = dbBackend(db) review = dbBack.getCodeReviewsByID(number) if review.Author == util.get_reporter_id(req): if review.Status == "Reviewed": review.Status = "Ready for inclusion" review.save(db) req.redirect(req.hdf['trac.href.peerReviewView'] + "?Review=" + number)
def process_request(self, req): #check permissions req.perm.assert_permission('CODE_REVIEW_MGR') req.hdf['manager'] = 1 # set up the dynamic links req.hdf['trac.href.peerReviewMain'] = self.env.href.peerReviewMain() req.hdf['trac.href.peerReviewNew'] = self.env.href.peerReviewNew() req.hdf['trac.href.peerReviewSearch'] = self.env.href.peerReviewSearch( ) req.hdf[ 'trac.href.peerReviewOptions'] = self.env.href.peerReviewOptions() req.hdf['main'] = "no" req.hdf['create'] = "no" req.hdf['search'] = "no" req.hdf['options'] = "yes" db = self.env.get_db_cnx() dbBack = dbBackend(db) newThreshold = req.args.get('percentage') #Set the new threshold value if (newThreshold != None): req.hdf['success'] = 1 dbBack.setThreshold(newThreshold) newThreshold = float(newThreshold) / 100 openArray = dbBack.getCodeReviewsByStatus("Open for review") for struct in openArray: voteyes = float(dbBack.getVotesByID("1", struct.IDReview)) voteno = float(dbBack.getVotesByID("0", struct.IDReview)) notvoted = float(dbBack.getVotesByID("-1", struct.IDReview)) total_votes_possible = voteyes + voteno + notvoted if total_votes_possible != 0: vote_ratio = voteyes / total_votes_possible # calculate vote ratio, while preventing divide by zero tests if (vote_ratio >= newThreshold): struct.Status = "Reviewed" struct.save(db) reviewArray = dbBack.getCodeReviewsByStatus("Reviewed") for struct in reviewArray: voteyes = float(dbBack.getVotesByID("1", struct.IDReview)) voteno = float(dbBack.getVotesByID("0", struct.IDReview)) notvoted = float(dbBack.getVotesByID("-1", struct.IDReview)) total_votes_possible = voteyes + voteno + notvoted if total_votes_possible != 0: vote_ratio = voteyes / total_votes_possible # calculate vote ratio, while preventing divide by zero tests if (vote_ratio < newThreshold): struct.Status = "Open for review" struct.save(db) #Get the threshold value req.hdf['percentage'] = dbBack.getThreshold() return 'peerReviewOptions.cs', None
def close_review(self, number, req): db = self.env.get_db_cnx() dbBack = dbBackend(db) review = dbBack.getCodeReviewsByID(number) # this option available if you are the author or manager of this code review if review.Author == util.get_reporter_id(req) or req.hdf('Manager') == '1': review.Status = "Closed" review.save(db) req.redirect(req.hdf['trac.href.peerReviewView'] + "?Review=" + number)
def process_request(self, req): # check permissions req.perm.assert_permission("CODE_REVIEW_MGR") req.hdf["manager"] = 1 # set up the dynamic links req.hdf["trac.href.peerReviewMain"] = self.env.href.peerReviewMain() req.hdf["trac.href.peerReviewNew"] = self.env.href.peerReviewNew() req.hdf["trac.href.peerReviewSearch"] = self.env.href.peerReviewSearch() req.hdf["trac.href.peerReviewOptions"] = self.env.href.peerReviewOptions() req.hdf["main"] = "no" req.hdf["create"] = "no" req.hdf["search"] = "no" req.hdf["options"] = "yes" db = self.env.get_db_cnx() dbBack = dbBackend(db) newThreshold = req.args.get("percentage") # Set the new threshold value if newThreshold != None: req.hdf["success"] = 1 dbBack.setThreshold(newThreshold) newThreshold = float(newThreshold) / 100 openArray = dbBack.getCodeReviewsByStatus("Open for review") for struct in openArray: voteyes = float(dbBack.getVotesByID("1", struct.IDReview)) voteno = float(dbBack.getVotesByID("0", struct.IDReview)) notvoted = float(dbBack.getVotesByID("-1", struct.IDReview)) total_votes_possible = voteyes + voteno + notvoted if total_votes_possible != 0: vote_ratio = voteyes / total_votes_possible # calculate vote ratio, while preventing divide by zero tests if vote_ratio >= newThreshold: struct.Status = "Reviewed" struct.save(db) reviewArray = dbBack.getCodeReviewsByStatus("Reviewed") for struct in reviewArray: voteyes = float(dbBack.getVotesByID("1", struct.IDReview)) voteno = float(dbBack.getVotesByID("0", struct.IDReview)) notvoted = float(dbBack.getVotesByID("-1", struct.IDReview)) total_votes_possible = voteyes + voteno + notvoted if total_votes_possible != 0: vote_ratio = voteyes / total_votes_possible # calculate vote ratio, while preventing divide by zero tests if vote_ratio < newThreshold: struct.Status = "Open for review" struct.save(db) # Get the threshold value req.hdf["percentage"] = dbBack.getThreshold() return "peerReviewOptions.cs", None
def process_request(self, req): #check permissions if req.perm.has_permission('CODE_REVIEW_MGR'): req.hdf['manager'] = 1 else: req.perm.assert_permission('CODE_REVIEW_DEV') req.hdf['manager'] = 0 #if the doSearch parameter is 'yes', perform the search #this parameter is set when someone searches if(req.args.get('doSearch') == 'yes'): results = self.performSearch(req); #if there are no results - fill the return array #with blank data. if(len(results) == 0): noValResult = [] noValResult.append("No results match query.") noValResult.append("") noValResult.append("") noValResult.append("") noValResult.append("") results.append(noValResult) req.hdf['results'] = results; req.hdf['doSearch'] = 'yes'; #sets links for ClearSilver req.hdf['trac.href.peerReviewView'] = self.env.href.peerReviewView() req.hdf['trac.href.peerReviewMain'] = self.env.href.peerReviewMain() req.hdf['trac.href.peerReviewNew'] = self.env.href.peerReviewNew() req.hdf['trac.href.peerReviewSearch'] = self.env.href.peerReviewSearch() req.hdf['trac.href.peerReviewOptions'] = self.env.href.peerReviewOptions() #for the top-right nav links req.hdf['main'] = "no" req.hdf['create'] = "no" req.hdf['search'] = "yes" req.hdf['options'] = "no" #get the database db = self.env.get_db_cnx() dbBack = dbBackend(db) users = dbBack.getPossibleUsers() #sets the possible users for the user combo-box req.hdf['users'] = users #creates a year array containing the last 10 #years - for the year combo-box now = datetime.datetime.now() year = now.year; years = [] for i in 0,1,2,3,4,5,6,7,8,9,10: years.append(year - i) req.hdf['years'] = years return 'peerReviewSearch.cs', None
def process_request(self, req): data = {} #check permissions req.perm.assert_permission('CODE_REVIEW_MGR') data['manager'] = 1 # set up the dynamic links data['main'] = "no" data['create'] = "no" data['search'] = "no" data['option'] = "yes" db = self.env.get_db_cnx() dbBack = dbBackend(db) newThreshold = req.args.get('percentage') #Set the new threshold value if (newThreshold != None): data['success'] = 1 dbBack.setThreshold(newThreshold) newThreshold = float(newThreshold)/100 openArray = dbBack.getCodeReviewsByStatus("Open for review") for struct in openArray: voteyes = float(dbBack.getVotesByID("1", struct.IDReview)) voteno = float(dbBack.getVotesByID("0", struct.IDReview)) notvoted = float(dbBack.getVotesByID("-1", struct.IDReview)) total_votes_possible = voteyes + voteno + notvoted if total_votes_possible != 0: vote_ratio = voteyes/total_votes_possible # calculate vote ratio, while preventing divide by zero tests if (vote_ratio >= newThreshold): struct.Status = "Reviewed" struct.save(db) reviewArray = dbBack.getCodeReviewsByStatus("Reviewed") for struct in reviewArray: voteyes = float(dbBack.getVotesByID("1", struct.IDReview)) voteno = float(dbBack.getVotesByID("0", struct.IDReview)) notvoted = float(dbBack.getVotesByID("-1", struct.IDReview)) total_votes_possible = voteyes + voteno + notvoted if total_votes_possible != 0: vote_ratio = voteyes/total_votes_possible # calculate vote ratio, while preventing divide by zero tests if (vote_ratio < newThreshold): struct.Status = "Open for review" struct.save(db) #Get the threshold value data['percentage'] = dbBack.getThreshold() return 'peerReviewOptions.html', data, None
def get_timeline_events(self, req, start, stop, filters): if 'codereview' in filters: codereview_realm = Resource('codereview') db = self.env.get_db_cnx() dbBack = dbBackend(db) codeReviewDetails = dbBack.getCodeReviewsInPeriod(to_timestamp(start), to_timestamp(stop)) for codeReview in codeReviewDetails: codereview_page = codereview_realm(id=codeReview.IDReview) reviewers = dbBack.getReviewers(codeReview.IDReview) reviewersList = '' for reviewer in reviewers: reviewersList = reviewersList + reviewer.Reviewer + ',' yield('codereview', codeReview.DateCreate, codeReview.Author, (codereview_page, codeReview.Name, codeReview.Notes, reviewersList))
def getCommentTree(self, req): IDFile = req.args.get('IDFile') LineNum = req.args.get('LineNum') if (IDFile == None) or (LineNum == None): req.hdf['invalid'] = 1 return db = self.env.get_db_cnx() dbBack = dbBackend(db) comments = dbBack.getCommentsByFileIDAndLine(IDFile, LineNum) commentHtml = "" first = True keys = comments.keys() keys.sort(); for key in keys: if not comments.has_key(comments[key].IDParent): commentHtml += self.buildCommentHTML(comments[key], 0, LineNum, IDFile, first) first = False; if commentHtml == "": commentHtml = "No Comments on this Line" req.hdf['lineNum'] = LineNum req.hdf['fileID'] = IDFile req.hdf['commentHTML'] = Markup(commentHtml)
def getCommentTree(self, req, data): IDFile = req.args.get('IDFile') LineNum = req.args.get('LineNum') if (IDFile == None) or (LineNum == None): data['invalid'] = 1 return db = self.env.get_db_cnx() dbBack = dbBackend(db) comments = dbBack.getCommentsByFileIDAndLine(IDFile, LineNum) commentHtml = "" first = True keys = comments.keys() keys.sort(); for key in keys: if not comments.has_key(comments[key].IDParent): commentHtml += self.buildCommentHTML(comments[key], 0, LineNum, IDFile, first) first = False; if commentHtml == "": commentHtml = "No Comments on this Line" data['lineNum'] = LineNum data['fileID'] = IDFile data['commentHTML'] = Markup(commentHtml)
def getCommentTree(self, req): IDFile = req.args.get("IDFile") LineNum = req.args.get("LineNum") if (IDFile == None) or (LineNum == None): req.hdf["invalid"] = 1 return db = self.env.get_db_cnx() dbBack = dbBackend(db) comments = dbBack.getCommentsByFileIDAndLine(IDFile, LineNum) commentHtml = "" first = True keys = comments.keys() keys.sort() for key in keys: if not comments.has_key(comments[key].IDParent): commentHtml += self.buildCommentHTML(comments[key], 0, LineNum, IDFile, first) first = False if commentHtml == "": commentHtml = "No Comments on this Line" req.hdf["lineNum"] = LineNum req.hdf["fileID"] = IDFile req.hdf["commentHTML"] = Markup(commentHtml)
def process_request(self, req): data = {} if req.perm.has_permission('CODE_REVIEW_MGR'): data['manager'] = 1 else: req.perm.assert_permission('CODE_REVIEW_DEV') data['manager'] = 0 #for top-right navigation links data['main'] = "no" data['create'] = "no" data['search'] = "no" data['options'] = "no" #get the fileID from the request arguments idFile = req.args.get('IDFile') self.fileID = idFile #if the file id is not set - display an error message if idFile == None: data['error.type'] = "TracError" data['error.title'] = "File ID Error" data['error.message'] = "No file ID given - unable to load page." return 'error.cs', data, None #get the database db = self.env.get_db_cnx() dbBack = dbBackend(db) #get all the comments for this file self.comments = dbBack.getCommentDictForFile(idFile) #get the file properties from the database resultFile = dbBack.getReviewFile(idFile) #make the thumbtac image global so the line annotator has access to it self.imagePath = self.env.href.chrome() + '/hw/images/thumbtac11x11.gif' #if the file is not found in the database - display an error message if resultFile == None: data['error.type'] = "TracError" data['error.title'] = "File ID Error" data['error.message'] = "Unable to locate given file ID in database." return 'error.cs', data, None #get the respository repos = self.env.get_repository(req.authname) #get the file attributes data['review_path'] = resultFile.Path data['review_version'] = resultFile.Version data['review_lineStart'] = resultFile.LineStart data['review_lineEnd'] = resultFile.LineEnd data['review_reviewID'] = resultFile.IDReview #make these global for the line annotator self.lineEnd = resultFile.LineEnd self.lineStart = resultFile.LineStart #if the repository can't be found - display an error message if(repos == None): data['error.type'] = "TracError" data['error.title'] = "Subversion Repository Error" data['error.message'] = "Unable to acquire subversion repository." return 'error.cs', data, None #get the correct location - using revision number and repository path try: node = get_existing_node(self.env, repos, resultFile.Path, resultFile.Version) except: youngest_rev = repos.youngest_rev node = get_existing_node(self.env, repos, resultFile.Path, youngest_rev) #if the node can't be found - display error message if(node == None): data['error.type'] = "TracError" data['error.title'] = "Subversion Node Error" data['error.message'] = "Unable to locate subversion node for this file." return 'error.cs', data, None # Generate HTML preview - this code take from Trac - refer to their documentation mime_type = node.content_type if not mime_type or mime_type == 'application/octet-stream': mime_type = get_mimetype(node.name) or mime_type or 'text/plain' ctpos = mime_type.find('charset=') if ctpos >= 0: charset = mime_type[ctpos + 8:] else: charset = None mimeview = Mimeview(self.env) path = req.args.get('path', '/') rev = None content = node.get_content().read(mimeview.max_preview_size) if not is_binary(content): if mime_type != 'text/plain': plain_href = self.env.href.peerReviewBrowser(node.path, rev=rev and node.rev, format='txt') add_link(req, 'alternate', plain_href, 'Plain Text', 'text/plain') #assign the preview to a variable for clearsilver context = Context.from_request(req, 'source', path, node.created_rev) preview_data = mimeview.preview_data(context, content, len(content), mime_type, node.created_path, None, annotations=['performCodeReview']) data['file'] = preview_data['rendered']; add_stylesheet(req, 'common/css/browser.css') add_stylesheet(req, 'common/css/code.css') return 'peerReviewPerform.html', data, None
def process_request(self, req): # test whether this user is a manager or not if req.perm.has_permission('CODE_REVIEW_MGR'): req.hdf['author'] = "manager" req.hdf['manager'] = 1 else: req.perm.assert_permission('CODE_REVIEW_DEV') req.hdf['author'] = "notmanager" req.hdf['manager'] = 0 # set up dynamic links req.hdf['trac.href.peerReviewMain'] = self.env.href.peerReviewMain() req.hdf['trac.href.peerReviewNew'] = self.env.href.peerReviewNew() req.hdf['trac.href.peerReviewSearch'] = self.env.href.peerReviewSearch( ) req.hdf[ 'trac.href.peerReviewOptions'] = self.env.href.peerReviewOptions() req.hdf['main'] = "yes" req.hdf['create'] = "no" req.hdf['search'] = "no" req.hdf['options'] = "no" req.hdf['trac.href.peerReviewView'] = self.env.href.peerReviewView() req.hdf['username'] = util.get_reporter_id(req) db = self.env.get_db_cnx() codeReview = CodeReviewStruct(None) dbBack = dbBackend(db) codeReviewArray = dbBack.getMyCodeReviews(util.get_reporter_id(req)) assignedReviewArray = dbBack.getCodeReviews(util.get_reporter_id(req)) managerReviewArray = dbBack.getCodeReviewsByStatus( "Ready for inclusion") reviewReturnArray = [] assignedReturnArray = [] managerReturnArray = [] dataArray = [] # fill the table of currently open reviews for struct in codeReviewArray: if struct.Status != "Closed": dataArray.append(struct.IDReview) dataArray.append(struct.Author) dataArray.append(struct.Status) dataArray.append(util.format_date(struct.DateCreate)) dataArray.append(struct.Name) reviewReturnArray.append(dataArray) dataArray = [] dataArray = [] # fill the table of code reviews currently assigned to you for struct in assignedReviewArray: if struct.Status != "Closed" and struct.Status != "Ready for inclusion": dataArray.append(struct.IDReview) dataArray.append(struct.Author) dataArray.append(struct.Name) dataArray.append(util.format_date(struct.DateCreate)) reviewstruct = dbBack.getReviewerEntry( struct.IDReview, util.get_reporter_id(req)) if reviewstruct.Vote == "-1": dataArray.append('Not voted') elif reviewstruct.Vote == "0": dataArray.append('Rejected') elif reviewstruct.Vote == "1": dataArray.append('Accepted') assignedReturnArray.append(dataArray) dataArray = [] dataArray = [] # fill the table of reviews assigned to you in a manager role for struct in managerReviewArray: if struct.Status != "Closed": dataArray.append(struct.IDReview) dataArray.append(struct.Author) dataArray.append(struct.Name) dataArray.append(util.format_date(struct.DateCreate)) managerReturnArray.append(dataArray) dataArray = [] req.hdf['reviewReturnArrayLength'] = len(reviewReturnArray) req.hdf['assignedReturnArrayLength'] = len(assignedReturnArray) req.hdf['managerReviewArrayLength'] = len(managerReviewArray) req.hdf['myCodeReviews'] = reviewReturnArray req.hdf['assignedReviews'] = assignedReturnArray req.hdf['managerReviews'] = managerReturnArray add_stylesheet(req, 'common/css/code.css') add_stylesheet(req, 'common/css/browser.css') return 'peerReviewMain.cs', None
def performSearch(self, req): #create a code review struct to hold the search parameters crStruct = CodeReviewStruct(None) #get the search parameters from POST author = req.args.get('Author') name = req.args.get('CodeReviewName') status = req.args.get('Status') month = req.args.get('DateMonth') day = req.args.get('DateDay') year = req.args.get('DateYear') #check for entered date values, if none are set #default to 0 if(month == None): month = '0'; if(day == None): day = '0'; if(year == None): year = '0'; #store date values for ClearSilver - used to reset values to #search parameters after a search is performed req.hdf['searchValues.month'] = month; req.hdf['searchValues.day'] = day; req.hdf['searchValues.year'] = year; req.hdf['searchValues.status'] = status; req.hdf['searchValues.author'] = author; req.hdf['searchValues.name'] = name; #dates are ints in TRAC - convert search date to int fromdate = "-1"; if((month != '0') and (day != '0') and (year != '0')): t = time.strptime(month + '/' + day + '/' + year[2] + year[3], '%x') #I have no idea what this is doing - obtained from TRAC source fromdate = time.mktime((t[0], t[1], t[2], 23, 59, 59, t[6], t[7], t[8])) #convert to string for database lookup fromdate = `fromdate` selectString = 'Select...' req.hdf['dateSelected'] = fromdate; #if user has not selected parameter - leave #value in struct NULL if(author != selectString): crStruct.Author = author if(name != selectString): crStruct.Name = name; if(status != selectString): crStruct.Status = status crStruct.DateCreate = fromdate; #get the database db = self.env.get_db_cnx() dbBack = dbBackend(db) #perform search results = dbBack.searchCodeReviews(crStruct) returnArray = [] tempArray = [] if(results == None): return returnArray #fill ClearSilver friendly array with #search results for struct in results: tempArray.append(struct.IDReview) tempArray.append(struct.Author) tempArray.append(struct.Status) tempArray.append(format_date(struct.DateCreate)) tempArray.append(struct.Name) returnArray.append(tempArray) tempArray = [] return returnArray;
def process_request(self, req): if req.perm.has_permission('CODE_REVIEW_MGR'): req.hdf['manager'] = 1 else: req.perm.assert_permission('CODE_REVIEW_DEV') req.hdf['manager'] = 0 #get some link locations for the template req.hdf['trac.href.peerReviewMain'] = self.env.href.peerReviewMain() req.hdf['trac.href.peerReviewNew'] = self.env.href.peerReviewNew() req.hdf['trac.href.peerReviewSearch'] = self.env.href.peerReviewSearch( ) req.hdf[ 'trac.href.peerReviewOptions'] = self.env.href.peerReviewOptions() #for top-right navigation links req.hdf['main'] = "no" req.hdf['create'] = "no" req.hdf['search'] = "no" req.hdf['options'] = "no" #get the fileID from the request arguments idFile = req.args.get('IDFile') self.fileID = idFile #if the file id is not set - display an error message if idFile == None: req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "File ID Error" req.hdf[ 'error.message'] = "No file ID given - unable to load page." return 'error.cs', None #get the database db = self.env.get_db_cnx() dbBack = dbBackend(db) #get all the comments for this file self.comments = dbBack.getCommentDictForFile(idFile) #get the file properties from the database resultFile = dbBack.getReviewFile(idFile) #make the thumbtac image global so the line annotator has access to it self.imagePath = self.env.href.chrome( ) + '/hw/images/thumbtac11x11.gif' #get image and link locations req.hdf[ 'trac.href.peerReviewCommentCallback'] = self.env.href.peerReviewCommentCallback( ) req.hdf['trac.href.peerReviewView'] = self.env.href.peerReviewView() req.hdf['trac.htdocs.thumbtac'] = self.imagePath req.hdf['trac.htdocs.plus'] = self.env.href.chrome( ) + '/hw/images/plus.gif' req.hdf['trac.htdocs.minus'] = self.env.href.chrome( ) + '/hw/images/minus.gif' #if the file is not found in the database - display an error message if resultFile == None: req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "File ID Error" req.hdf[ 'error.message'] = "Unable to locate given file ID in database." return 'error.cs', None #get the respository repos = self.env.get_repository(req.authname) #get the file attributes req.hdf['review.path'] = resultFile.Path req.hdf['review.version'] = resultFile.Version req.hdf['review.lineStart'] = resultFile.LineStart req.hdf['review.lineEnd'] = resultFile.LineEnd req.hdf['review.reviewID'] = resultFile.IDReview #make these global for the line annotator self.lineEnd = resultFile.LineEnd self.lineStart = resultFile.LineStart #if the repository can't be found - display an error message if (repos == None): req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "Subversion Repository Error" req.hdf[ 'error.message'] = "Unable to acquire subversion repository." return 'error.cs', None #get the correct location - using revision number and repository path node = get_existing_node(self.env, repos, resultFile.Path, resultFile.Version) #if the node can't be found - display error message if (node == None): req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "Subversion Node Error" req.hdf[ 'error.message'] = "Unable to locate subversion node for this file." return 'error.cs', None # Generate HTML preview - this code take from Trac - refer to their documentation mime_type = node.content_type if not mime_type or mime_type == 'application/octet-stream': mime_type = get_mimetype(node.name) or mime_type or 'text/plain' ctpos = mime_type.find('charset=') if ctpos >= 0: charset = mime_type[ctpos + 8:] else: charset = None mimeview = Mimeview(self.env) rev = None content = node.get_content().read(mimeview.max_preview_size) if not is_binary(content): if mime_type != 'text/plain': plain_href = self.env.href.peerReviewBrowser(node.path, rev=rev and node.rev, format='txt') add_link(req, 'alternate', plain_href, 'Plain Text', 'text/plain') #assign the preview to a variable for clearsilver req.hdf['file'] = mimeview.preview_to_hdf( req, content, len(content), mime_type, node.created_path, None, annotations=['performCodeReview']) add_stylesheet(req, 'common/css/code.css') add_stylesheet(req, 'common/css/browser.css') return 'peerReviewPerform.cs', None
def process_request(self, req): # test whether this user is a manager or not if req.perm.has_permission('CODE_REVIEW_MGR'): req.hdf['author'] = "manager" req.hdf['manager'] = 1 else: req.perm.assert_permission('CODE_REVIEW_DEV') req.hdf['author'] = "notmanager" req.hdf['manager'] = 0 # set up dynamic links req.hdf['trac.href.peerReviewMain'] = self.env.href.peerReviewMain() req.hdf['trac.href.peerReviewNew'] = self.env.href.peerReviewNew() req.hdf['trac.href.peerReviewSearch'] = self.env.href.peerReviewSearch() req.hdf['trac.href.peerReviewOptions'] = self.env.href.peerReviewOptions() req.hdf['main'] = "yes" req.hdf['create'] = "no" req.hdf['search'] = "no" req.hdf['options'] = "no" req.hdf['trac.href.peerReviewView'] = self.env.href.peerReviewView() req.hdf['username'] = util.get_reporter_id(req) db = self.env.get_db_cnx() codeReview = CodeReviewStruct(None) dbBack = dbBackend(db) codeReviewArray = dbBack.getMyCodeReviews(util.get_reporter_id(req)) assignedReviewArray = dbBack.getCodeReviews(util.get_reporter_id(req)) managerReviewArray = dbBack.getCodeReviewsByStatus("Ready for inclusion") reviewReturnArray = [] assignedReturnArray = [] managerReturnArray = [] dataArray = [] # fill the table of currently open reviews for struct in codeReviewArray: if struct.Status != "Closed": dataArray.append(struct.IDReview) dataArray.append(struct.Author) dataArray.append(struct.Status) dataArray.append(util.format_date(struct.DateCreate)) dataArray.append(struct.Name) reviewReturnArray.append(dataArray) dataArray = [] dataArray = [] # fill the table of code reviews currently assigned to you for struct in assignedReviewArray: if struct.Status != "Closed" and struct.Status != "Ready for inclusion": dataArray.append(struct.IDReview) dataArray.append(struct.Author) dataArray.append(struct.Name) dataArray.append(util.format_date(struct.DateCreate)) reviewstruct = dbBack.getReviewerEntry(struct.IDReview, util.get_reporter_id(req)) if reviewstruct.Vote == "-1": dataArray.append('Not voted') elif reviewstruct.Vote == "0": dataArray.append('Rejected') elif reviewstruct.Vote == "1": dataArray.append('Accepted') assignedReturnArray.append(dataArray) dataArray = [] dataArray = [] # fill the table of reviews assigned to you in a manager role for struct in managerReviewArray: if struct.Status != "Closed": dataArray.append(struct.IDReview) dataArray.append(struct.Author) dataArray.append(struct.Name) dataArray.append(util.format_date(struct.DateCreate)) managerReturnArray.append(dataArray) dataArray = [] req.hdf['reviewReturnArrayLength'] = len(reviewReturnArray) req.hdf['assignedReturnArrayLength'] = len(assignedReturnArray) req.hdf['managerReviewArrayLength'] = len(managerReviewArray) req.hdf['myCodeReviews'] = reviewReturnArray req.hdf['assignedReviews'] = assignedReturnArray req.hdf['managerReviews'] = managerReturnArray add_stylesheet(req, 'common/css/code.css') add_stylesheet(req, 'common/css/browser.css') return 'peerReviewMain.cs', None
def process_request(self, req): if req.perm.has_permission('CODE_REVIEW_MGR'): req.hdf['manager'] = 1 else: req.perm.assert_permission('CODE_REVIEW_DEV') req.hdf['manager'] = 0 # set up the dynamic links req.hdf['trac.href.peerReviewMain'] = self.env.href.peerReviewMain() req.hdf['trac.href.peerReviewNew'] = self.env.href.peerReviewNew() req.hdf['trac.href.peerReviewSearch'] = self.env.href.peerReviewSearch() req.hdf['trac.href.peerReviewOptions'] = self.env.href.peerReviewOptions() req.hdf['main'] = "no" req.hdf['create'] = "yes" req.hdf['search'] = "no" req.hdf['options'] = "no" db = self.env.get_db_cnx() dbBack = dbBackend(db) allUsers = dbBack.getPossibleUsers() reviewID = req.args.get('resubmit') req.hdf['oldid'] = -1 # if we tried resubmitting and the reviewID is not a valid number or not a valid code review, error if reviewID != None and (not reviewID.isdigit() or dbBack.getCodeReviewsByID(reviewID) == None): req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "Resubmit ID error" req.hdf['error.message'] = "Invalid resubmit ID supplied - unable to load page correctly." return 'error.cs', None # if we are resubmitting a code review and we are the author or the manager if reviewID != None and (dbBack.getCodeReviewsByID(reviewID).Author == util.get_reporter_id(req) or req.perm.has_permission('CODE_REVIEW_MGR')): review = dbBack.getCodeReviewsByID(reviewID) req.hdf['new'] = "no" req.hdf['oldid'] = reviewID # get code review data and populate userStructs = dbBack.getReviewers(reviewID) returnUsers = "" popUsers = [] for struct in userStructs: returnUsers+=struct.Reviewer + "#" popUsers.append(struct.Reviewer) files = dbBack.getReviewFiles(reviewID) returnFiles = "" popFiles = [] # Set up the file information for struct in files: returnFiles+=struct.Path + "," + struct.Version + "," + struct.LineStart + "," + struct.LineEnd + "#" tempFiles = [] tempFiles.append(struct.Path) tempFiles.append(struct.Version) tempFiles.append(struct.LineStart) tempFiles.append(struct.LineEnd) popFiles.append(tempFiles); req.hdf['files'] = returnFiles req.hdf['name'] = review.Name req.hdf['notes'] = review.Notes req.hdf['reviewers'] = returnUsers req.hdf['prevUsers'] = popUsers req.hdf['prevFiles'] = popFiles # Figure out the users that were not included # in the previous code review so that they can be # added to the dropdown to select more users # (only check if all users were not included in previous code review) notUsers = [] if len(popUsers) != len(allUsers): for user in allUsers: match = "no" for candidate in popUsers: if candidate == user: match = "yes" break if match == "no": notUsers.append(user) req.hdf['notPrevUsers'] = notUsers req.hdf['emptyList'] = 0 else: req.hdf['notPrevUsers'] = [] req.hdf['emptyList'] = 1 #if we resubmitting a code review, and are neiter the author and the manager elif reviewID != None and not dbBack.getCodeReviewsByID(reviewID).Author == util.get_reporter_id(req) and not req.perm.has_permission('CODE_REVIEW_MGR'): req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "Access error" req.hdf['error.message'] = "You need to be a manager or the author of this code review to resubmit it." return 'error.cs', None #if we are not resubmitting else: if req.args.get('reqAction') == 'createCodeReview': oldid = req.args.get('oldid') if oldid != None: review = dbBack.getCodeReviewsByID(oldid) review.Status = "Closed" review.save(db) returnid = self.createCodeReview(req); #If no errors then redirect to the viewCodeReview page req.redirect(self.env.href.peerReviewView() + '?Review=' + returnid) else: req.hdf['new'] = "yes" req.hdf['users'] = allUsers req.hdf['trac.href.peerReviewBrowser'] = self.env.href.peerReviewBrowser() add_stylesheet(req, 'common/css/code.css') add_stylesheet(req, 'common/css/browser.css') return 'peerReviewNew.cs', None
def process_request(self, req): # check to see if the user is a manager of this page or not if req.perm.has_permission('CODE_REVIEW_MGR'): req.hdf['manager'] = 1 else: req.perm.assert_permission('CODE_REVIEW_DEV') req.hdf['manager'] = 0 # set up dynamic links req.hdf['trac.href.peerReviewMain'] = self.env.href.peerReviewMain() req.hdf['trac.href.peerReviewNew'] = self.env.href.peerReviewNew() req.hdf['trac.href.peerReviewSearch'] = self.env.href.peerReviewSearch() req.hdf['trac.href.peerReviewPerform'] = self.env.href.peerReviewPerform() req.hdf['trac.href.peerReviewView'] = self.env.href.peerReviewView() req.hdf['trac.href.peerReviewOptions'] = self.env.href.peerReviewOptions() # reviewID argument checking reviewID = req.args.get('Review') if reviewID == None or not reviewID.isdigit(): req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "Review ID error" req.hdf['error.message'] = "Invalid review ID supplied - unable to load page." return 'error.cs', None req.hdf['main'] = "no" req.hdf['create'] = "no" req.hdf['search'] = "no" req.hdf['options'] = "no" # set up to display the files that are in this review db = self.env.get_db_cnx() dbBack = dbBackend(db) files = dbBack.getReviewFiles(reviewID) returnfiles = [] newfile = [] for struct in files: newfile.append(struct.IDFile) newfile.append(struct.IDReview) newfile.append(struct.Path) newfile.append(struct.LineStart) newfile.append(struct.LineEnd) newfile.append(struct.Version) returnfiles.append(newfile) newfile = [] req.hdf['files'] = returnfiles req.hdf['filesLength'] = len(returnfiles) req.hdf['reviewID'] = reviewID req.hdf['users'] = dbBack.getPossibleUsers() review = dbBack.getCodeReviewsByID(reviewID) # error if review id does not exist in the database if review == None: req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "Review error" req.hdf['error.message'] = "Review does not exist in database - unable to load page." return 'error.cs', None # set up the fields that will be displayed on the page req.hdf['name'] = review.Name req.hdf['notes'] = review.Notes req.hdf['status'] = review.Status req.hdf['author'] = review.Author req.hdf['myname'] = util.get_reporter_id(req) req.hdf['datecreate'] = util.format_date(review.DateCreate) req.hdf['voteyes'] = dbBack.getVotesByID("1", reviewID) req.hdf['voteno'] = dbBack.getVotesByID("0", reviewID) req.hdf['notvoted'] = dbBack.getVotesByID("-1", reviewID) req.hdf['total_votes_possible'] = float(req.hdf['voteyes']) + float(req.hdf['voteno']) + float(req.hdf['notvoted']) req.hdf['threshold'] = float(dbBack.getThreshold())/100 # figure out whether I can vote on this review or not entry = dbBack.getReviewerEntry(reviewID, req.hdf['myname']) if entry != None: req.hdf['canivote'] = 1 req.hdf['myvote'] = entry.Vote else: req.hdf['canivote'] = 0 #display vote summary only if I have voted or am the author/manager, or if the review is "Ready for inclusion" or "Closed req.hdf['viewvotesummary'] = 0 if req.hdf['author'] == req.hdf['myname'] or req.hdf['manager'] == '1' or (dbBack.getReviewerEntry(reviewID, req.hdf['myname']) != None and dbBack.getReviewerEntry(reviewID, req.hdf['myname']).Vote != '-1') or req.hdf['status']=="Closed" or req.hdf['status']=="Ready for inclusion": req.hdf['viewvotesummary'] = 1 else: req.hdf['viewvotesummary'] = 0 rvs = [] # reviewer/vote pairs reviewers = dbBack.getReviewers(reviewID) newrvpair = [] # if we are the manager, list who has voted and what their vote was. # if we are the author, list who has voted and who has not. # if we are neither, list the users who are participating in this review. if req.hdf['manager'] == '1': for reviewer in reviewers: newrvpair.append(reviewer.Reviewer) if reviewer.Vote == '-1': newrvpair.append("Not voted") elif reviewer.Vote == '0': newrvpair.append("No") elif reviewer.Vote == '1': newrvpair.append("Yes") rvs.append(newrvpair) newrvpair = [] elif review.Author == util.get_reporter_id(req): for reviewer in reviewers: newrvpair.append(reviewer.Reviewer) if reviewer.Vote == '-1': newrvpair.append("Not voted") else: newrvpair.append("Voted") rvs.append(newrvpair) newrvpair = [] else: for reviewer in reviewers: newrvpair.append(reviewer.Reviewer) rvs.append(newrvpair) newrvpair = [] req.hdf['rvs'] = rvs req.hdf['rvsLength'] = len(rvs) # execute based on URL arguments if req.args.get('Vote') == 'yes': self.vote("1", reviewID, req) if req.args.get('Vote') == 'no': self.vote("0", reviewID, req) # process state (Open for review, ready for inclusion, etc.) change by manager mc = req.args.get('ManagerChoice') if mc == "Open for review" or mc == "Reviewed" or mc == "Ready for inclusion" or mc == "Closed": self.manager_change_status(mc, reviewID, req) if req.args.get('Close') == '1': self.close_review(reviewID, req) if req.args.get('Inclusion') == '1': self.submit_for_inclusion(reviewID, req) add_stylesheet(req, 'common/css/code.css') add_stylesheet(req, 'common/css/browser.css') return 'peerReviewView.cs', None
def process_request(self, req): if req.perm.has_permission('CODE_REVIEW_MGR'): req.hdf['manager'] = 1 else: req.perm.assert_permission('CODE_REVIEW_DEV') req.hdf['manager'] = 0 #get some link locations for the template req.hdf['trac.href.peerReviewMain'] = self.env.href.peerReviewMain() req.hdf['trac.href.peerReviewNew'] = self.env.href.peerReviewNew() req.hdf['trac.href.peerReviewSearch'] = self.env.href.peerReviewSearch() req.hdf['trac.href.peerReviewOptions'] = self.env.href.peerReviewOptions() #for top-right navigation links req.hdf['main'] = "no" req.hdf['create'] = "no" req.hdf['search'] = "no" req.hdf['options'] = "no" #get the fileID from the request arguments idFile = req.args.get('IDFile') self.fileID = idFile #if the file id is not set - display an error message if idFile == None: req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "File ID Error" req.hdf['error.message'] = "No file ID given - unable to load page." return 'error.cs', None #get the database db = self.env.get_db_cnx() dbBack = dbBackend(db) #get all the comments for this file self.comments = dbBack.getCommentDictForFile(idFile) #get the file properties from the database resultFile = dbBack.getReviewFile(idFile) #make the thumbtac image global so the line annotator has access to it self.imagePath = self.env.href.chrome() + '/hw/images/thumbtac11x11.gif' #get image and link locations req.hdf['trac.href.peerReviewCommentCallback'] = self.env.href.peerReviewCommentCallback() req.hdf['trac.href.peerReviewView'] = self.env.href.peerReviewView() req.hdf['trac.htdocs.thumbtac'] = self.imagePath req.hdf['trac.htdocs.plus'] = self.env.href.chrome() + '/hw/images/plus.gif' req.hdf['trac.htdocs.minus'] = self.env.href.chrome() + '/hw/images/minus.gif' #if the file is not found in the database - display an error message if resultFile == None: req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "File ID Error" req.hdf['error.message'] = "Unable to locate given file ID in database." return 'error.cs', None #get the respository repos = self.env.get_repository(req.authname) #get the file attributes req.hdf['review.path'] = resultFile.Path req.hdf['review.version'] = resultFile.Version req.hdf['review.lineStart'] = resultFile.LineStart req.hdf['review.lineEnd'] = resultFile.LineEnd req.hdf['review.reviewID'] = resultFile.IDReview #make these global for the line annotator self.lineEnd = string.atoi(resultFile.LineEnd) self.lineStart = string.atoi(resultFile.LineStart) #if the repository can't be found - display an error message if(repos == None): req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "Subversion Repository Error" req.hdf['error.message'] = "Unable to acquire subversion repository." return 'error.cs', None #get the correct location - using revision number and repository path node = get_existing_node(self.env, repos, resultFile.Path, resultFile.Version) #if the node can't be found - display error message if(node == None): req.hdf['error.type'] = "TracError" req.hdf['error.title'] = "Subversion Node Error" req.hdf['error.message'] = "Unable to locate subversion node for this file." return 'error.cs', None # Generate HTML preview - this code take from Trac - refer to their documentation mime_type = node.content_type if not mime_type or mime_type == 'application/octet-stream': mime_type = get_mimetype(node.name) or mime_type or 'text/plain' ctpos = mime_type.find('charset=') if ctpos >= 0: charset = mime_type[ctpos + 8:] else: charset = None mimeview = Mimeview(self.env) rev = None content = node.get_content().read(mimeview.max_preview_size()) if not is_binary(content): if mime_type != 'text/plain': plain_href = self.env.href.peerReviewBrowser(node.path, rev=rev and node.rev, format='txt') add_link(req, 'alternate', plain_href, 'Plain Text', 'text/plain') #assign the preview to a variable for clearsilver req.hdf['file'] = mimeview.preview_to_hdf(req, mime_type, charset, content, node.name, node.rev, annotations=['performCodeReview']) add_stylesheet(req, 'common/css/code.css') add_stylesheet(req, 'common/css/browser.css') return 'peerReviewPerform.cs', None