|
@@ -178,32 +178,57 @@ def edit_project(projectid):
|
|
|
elif (sess_token is None or (datetime.utcnow() - sess_token).total_seconds() > MAX_TOKEN_AGE):
|
|
|
return redirect(url_for('.gen_edit_token', projectid=isp.id))
|
|
|
|
|
|
- if isp.is_local:
|
|
|
- form = forms.ProjectForm.edit_json(isp)
|
|
|
- if form.validate_on_submit():
|
|
|
- isp.name = form.name.data
|
|
|
- isp.shortname = form.shortname.data or None
|
|
|
- isp.json = form.to_json(isp.json)
|
|
|
- isp.tech_email = form.tech_email.data
|
|
|
-
|
|
|
- db.session.add(isp)
|
|
|
- db.session.commit()
|
|
|
- flash(_(u'Project modified'), 'info')
|
|
|
- return redirect(url_for('.project', projectid=isp.id))
|
|
|
- return render_template('edit_project_form.html', form=form)
|
|
|
- else:
|
|
|
- form = forms.ProjectJSONForm(obj=isp)
|
|
|
- if form.validate_on_submit():
|
|
|
- isp.tech_email = form.tech_email.data
|
|
|
- url = utils.make_ispjson_url(form.json_url.data)
|
|
|
- isp.json_url = url
|
|
|
-
|
|
|
- db.session.add(isp)
|
|
|
- db.session.commit()
|
|
|
- flash(_(u'Project modified'), 'info')
|
|
|
- return redirect(url_for('.project', projectid=isp.id))
|
|
|
- return render_template('edit_project_json_form.html', form=form)
|
|
|
+ form = forms.ProjectForm.edit_json(isp)
|
|
|
+ if form.validate_on_submit():
|
|
|
+ isp.name = form.name.data
|
|
|
+ isp.shortname = form.shortname.data or None
|
|
|
+ isp.json = form.to_json(isp.json)
|
|
|
+ isp.tech_email = form.tech_email.data
|
|
|
+ isp.json_url = None
|
|
|
+
|
|
|
+ db.session.add(isp)
|
|
|
+ db.session.commit()
|
|
|
+ flash(_(u'Project modified'), 'info')
|
|
|
+ return redirect(url_for('.project', projectid=isp.id))
|
|
|
+ return render_template('edit_project_form.html', form=form, isp=isp)
|
|
|
+
|
|
|
|
|
|
+@ispdb.route('/isp/<projectid>/edit_json_url', methods=['GET', 'POST'])
|
|
|
+def edit_project_auto_update(projectid):
|
|
|
+ MAX_TOKEN_AGE = 3600
|
|
|
+ isp = ISP.query.filter_by(id=projectid, is_disabled=False).first_or_404()
|
|
|
+ sess_token = session.get('edit_tokens', {}).get(isp.id)
|
|
|
+
|
|
|
+ if 'token' in request.args:
|
|
|
+ s = itsdangerous.URLSafeTimedSerializer(current_app.secret_key, salt='edit')
|
|
|
+ try:
|
|
|
+ r = s.loads(request.args['token'], max_age=MAX_TOKEN_AGE,
|
|
|
+ return_timestamp=True)
|
|
|
+ except:
|
|
|
+ abort(403)
|
|
|
+
|
|
|
+ if r[0] != isp.id:
|
|
|
+ abort(403)
|
|
|
+
|
|
|
+ tokens = session.setdefault('edit_tokens', {})
|
|
|
+ session.modified = True # ITS A TARP
|
|
|
+ tokens[r[0]] = r[1]
|
|
|
+ # refresh page, without the token in the url
|
|
|
+ return redirect(url_for('.edit_project', projectid=r[0]))
|
|
|
+ elif (sess_token is None or (datetime.utcnow() - sess_token).total_seconds() > MAX_TOKEN_AGE):
|
|
|
+ return redirect(url_for('.gen_edit_token', projectid=isp.id))
|
|
|
+
|
|
|
+ form = forms.ProjectJSONForm(obj=isp)
|
|
|
+ if form.validate_on_submit():
|
|
|
+ isp.tech_email = form.tech_email.data
|
|
|
+ url = utils.make_ispjson_url(form.json_url.data)
|
|
|
+ isp.json_url = url
|
|
|
+
|
|
|
+ db.session.add(isp)
|
|
|
+ db.session.commit()
|
|
|
+ flash(_(u'Project modified'), 'info')
|
|
|
+ return redirect(url_for('.project', projectid=isp.id))
|
|
|
+ return render_template('edit_project_json_form.html', form=form, isp=isp)
|
|
|
|
|
|
@ispdb.route('/isp/<projectid>/gen_edit_token', methods=['GET', 'POST'])
|
|
|
def gen_edit_token(projectid):
|