def conversions(request): """/conversions - Show and edit the list of base=>source code URL maps.""" rules = models_chromium.UrlMap.query().order( models_chromium.UrlMap.base_url_template).fetch() if request.method != 'POST': return responses.respond(request, 'conversions.html', { 'rules': rules}) if not models_chromium.UrlMap.user_can_edit(request.user): # TODO(vbendeb) this domain name should be a configuration item. Or maybe # only admins should be allowed to modify the conversions table. warning = 'You are not authorized to modify the conversions table.' return responses.respond(request, 'conversions.html', { 'warning': warning, 'rules': rules, }) for key, _ in request.POST.iteritems(): if key.startswith('del '): del_key = key[4:] urlmap_query = models_chromium.UrlMap.query( models_chromium.UrlMap.base_url_template == del_key) urlmap = urlmap_query.fetch(keys_only=True) if not urlmap: logging.error('No map for %s found' % del_key) continue ndb.delete_multi(urlmap) base_url = request.POST.get('base_url_template') src_url = request.POST.get('source_code_url_template') if base_url and src_url: warning = '' try: re.compile(r'%s' % base_url) except re.error, err: warning = 'Regex error "%s"' % err if not warning: urlmap_query = models_chromium.UrlMap.query( models_chromium.UrlMap.base_url_template == base_url) if urlmap_query.count(): warning = 'Attempt to add a duplicate Base Url' if warning: rules = models_chromium.UrlMap.query().order( models_chromium.UrlMap.base_url_template).fetch() return responses.respond(request, 'conversions.html', { 'warning': warning, 'rules': rules, 'base_url': base_url, 'src_url': src_url }) new_map = models_chromium.UrlMap( base_url_template=base_url, source_code_url_template=src_url) logging.info(new_map) new_map.put()
def edit_flags(request): """/<issue>/edit_flags - Edit issue's flags.""" last_patchset = models.PatchSet.query(ancestor=request.issue.key).order( -models.PatchSet.created).get() if not last_patchset: return HttpResponseForbidden('Can only modify flags on last patchset', content_type='text/plain') if request.issue.closed: return HttpResponseForbidden('Can not modify flags for a closed issue', content_type='text/plain') if request.method == 'GET': # TODO(maruel): Have it set per project. initial_builders = 'win_rel, mac_rel, linux_rel' form = EditFlagsForm(initial={ 'last_patchset': last_patchset.key.id(), 'commit': request.issue.commit, 'builders': initial_builders}) return responses.respond(request, 'edit_flags.html', {'issue': request.issue, 'form': form}) form = EditFlagsForm(request.POST) if not form.is_valid(): return HttpResponseBadRequest('Invalid POST arguments', content_type='text/plain') if (form.cleaned_data['last_patchset'] != last_patchset.key.id()): return HttpResponseForbidden('Can only modify flags on last patchset', content_type='text/plain') if 'commit' in request.POST: if request.issue.private and form.cleaned_data['commit'] : return HttpResponseBadRequest( 'Cannot set commit on private issues', content_type='text/plain') if not request.issue.is_cq_available and form.cleaned_data['commit']: return HttpResponseBadRequest( 'Cannot set commit on an issue that does not have a commit queue', content_type='text/plain') request.issue.commit = form.cleaned_data['commit'] request.issue.cq_dry_run = form.cleaned_data['cq_dry_run'] user_email = request.user.email().lower() if user_email == views.CQ_SERVICE_ACCOUNT: user_email = views.CQ_COMMIT_BOT_EMAIL if (request.issue.commit and # Add as reviewer if setting, not clearing. user_email != request.issue.owner.email() and user_email not in request.issue.reviewers and user_email not in request.issue.collaborator_emails()): request.issue.reviewers.append(request.user.email()) # Update the issue with the checking/unchecking of the CQ box but reduce # spam by not emailing users. action = 'checked' if request.issue.commit else 'unchecked' commit_checked_msg = 'The CQ bit was %s by %s' % (action, user_email) if request.issue.cq_dry_run: commit_checked_msg += ' to run a CQ dry run' request.issue.cq_dry_run_last_triggered_by = user_email logging.info('CQ dry run has been triggered by %s for %d/%d', user_email, request.issue.key.id(), last_patchset.key.id()) # Mail just the owner and only if the CQ bit was unchecked by someone other # than the owner or CQ itself. More details in # https://code.google.com/p/skia/issues/detail?id=3093 send_mail = (user_email != request.issue.owner.email() and user_email != views.CQ_COMMIT_BOT_EMAIL and not request.issue.commit) views.make_message(request, request.issue, commit_checked_msg, send_mail=send_mail, auto_generated=True, email_to=[request.issue.owner.email()]).put() request.issue.put() if request.issue.commit and not request.issue.cq_dry_run: views.notify_approvers_of_new_patchsets(request, request.issue) if 'builders' in request.POST: new_builders = filter(None, map(unicode.strip, form.cleaned_data['builders'].split(','))) if request.issue.private and new_builders: return HttpResponseBadRequest( 'Cannot add trybots on private issues', content_type='text/plain') builds = [] for b in new_builders: bucket, builder = b.split(':', 1) builds.append({ 'bucket': bucket, 'builder': builder, }) buildbucket.schedule(request.issue, last_patchset.key.id(), builds) return HttpResponse('OK', content_type='text/plain')
def edit_flags(request): """/<issue>/edit_flags - Edit issue's flags.""" last_patchset = models.PatchSet.query(ancestor=request.issue.key).order( -models.PatchSet.created).get() if not last_patchset: return HttpResponseForbidden('Can only modify flags on last patchset', content_type='text/plain') if request.issue.closed: return HttpResponseForbidden('Can not modify flags for a closed issue', content_type='text/plain') if request.method == 'GET': # TODO(maruel): Have it set per project. initial_builders = 'win_rel, mac_rel, linux_rel' form = EditFlagsForm(initial={ 'last_patchset': last_patchset.key.id(), 'commit': request.issue.commit, 'builders': initial_builders}) return responses.respond(request, 'edit_flags.html', {'issue': request.issue, 'form': form}) form = EditFlagsForm(request.POST) if not form.is_valid(): return HttpResponseBadRequest('Invalid POST arguments', content_type='text/plain') if (form.cleaned_data['last_patchset'] != last_patchset.key.id()): return HttpResponseForbidden('Can only modify flags on last patchset', content_type='text/plain') if 'commit' in request.POST: if request.issue.private and form.cleaned_data['commit'] : return HttpResponseBadRequest( 'Cannot set commit on private issues', content_type='text/plain') request.issue.commit = form.cleaned_data['commit'] request.issue.cq_dry_run = form.cleaned_data['cq_dry_run'] user_email = request.user.email().lower() if user_email == views.CQ_SERVICE_ACCOUNT: user_email = views.CQ_COMMIT_BOT_EMAIL if (request.issue.commit and # Add as reviewer if setting, not clearing. user_email != request.issue.owner.email() and user_email not in request.issue.reviewers and user_email not in request.issue.collaborator_emails()): request.issue.reviewers.append(request.user.email()) # Update the issue with the checking/unchecking of the CQ box but reduce # spam by not emailing users. action = 'checked' if request.issue.commit else 'unchecked' commit_checked_msg = 'The CQ bit was %s by %s' % (action, user_email) if request.issue.cq_dry_run: commit_checked_msg += ' to run a CQ dry run' request.issue.cq_dry_run_last_triggered_by = user_email logging.info('CQ dry run has been triggered by %s for %d/%d', user_email, request.issue.key.id(), last_patchset.key.id()) # Mail just the owner if the CQ bit was unchecked by someone other than the # owner. More details in # https://code.google.com/p/skia/issues/detail?id=3093 unchecked_by_non_owner = (user_email != request.issue.owner.email() and not request.issue.commit) views.make_message(request, request.issue, commit_checked_msg, send_mail=unchecked_by_non_owner, auto_generated=True, email_to=[request.issue.owner.email()]).put() request.issue.put() if request.issue.commit and not request.issue.cq_dry_run: views.notify_approvers_of_new_patchsets(request, request.issue) if 'builders' in request.POST: new_builders = filter(None, map(unicode.strip, form.cleaned_data['builders'].split(','))) if request.issue.private and new_builders: return HttpResponseBadRequest( 'Cannot add trybots on private issues', content_type='text/plain') buildbucket.schedule( request.issue, last_patchset.key.id(), [b.split(':', 1) for b in new_builders]) return HttpResponse('OK', content_type='text/plain')