Merge branch 'master' into fix-seed-db

remotes/1693045480750635534/spooky-22
atrc445 2021-08-03 23:23:55 +02:00
commit 8b3ea17bf1
7 changed files with 41 additions and 62 deletions

View File

@ -606,7 +606,6 @@ def admin_title_change(user_id, v):
new_name=request.form.get("title").strip()
user.customtitleplain=new_name
new_name=new_name.replace('_','\_')
new_name = sanitize(new_name, linkgen=True)
user=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=user.id).first()
@ -937,7 +936,7 @@ def admin_toggle_ban_domain(v):
reason=request.form.get("reason", "").strip()
d = g.db.query(BannedDomain).filter_by(domain=domain.replace("_","\_")).first()
d = g.db.query(BannedDomain).filter_by(domain=domain).first()
if d: g.db.delete(d)
else:
d = BannedDomain(domain=domain, reason=reason)

View File

@ -206,4 +206,20 @@ def admin_apps_list(v):
apps = g.db.query(OauthApp).all()
return render_template("admin/apps.html", v=v, apps=apps)
return render_template("admin/apps.html", v=v, apps=apps)
@app.post("/oauth/reroll/<aid>")
@auth_required
def reroll_oauth_tokens(aid, v):
aid = aid
a = g.db.query(OauthApp).filter_by(id=aid).first()
if a.author_id != v.id: abort(403)
a.client_id = secrets.token_urlsafe(64)[:64]
g.db.add(a)
return {"message": "Client ID Rerolled", "id": a.client_id}

View File

@ -619,11 +619,13 @@ def submit_post(v):
embed = requests.get("https://graph.facebook.com/v9.0/instagram_oembed", params={"url":url,"access_token":environ.get("FACEBOOK_TOKEN","").strip(),"omitscript":'true'}, headers={"User-Agent":"Instagram embedder for Drama"}).json()["html"]
elif app.config['SERVER_NAME'] in domain:
matches = re.match(re.compile(f"^.*{domain}/post/+\w+/(\w+)(/\w+/(\w+))?"), url)
post_id = matches.group(1)
comment_id = matches.group(3)
if comment_id: embed = f"https://{app.config['SERVER_NAME']}/embed/comment/{comment_id}"
else: embed = f"https://{app.config['SERVER_NAME']}/embed/post/{post_id}"
try:
matches = re.match(re.compile(f"^.*{domain}/post/+\w+/(\w+)(/\w+/(\w+))?"), url)
post_id = matches.group(1)
comment_id = matches.group(3)
if comment_id: embed = f"https://{app.config['SERVER_NAME']}/embed/comment/{comment_id}"
else: embed = f"https://{app.config['SERVER_NAME']}/embed/post/{post_id}"
except: embed = None
else: embed = None

View File

@ -275,7 +275,6 @@ def searchusers(v):
term=term.replace('\\','')
term=term.replace('_','\_')
now=int(time.time())
users=g.db.query(User).filter(User.username.ilike(f'%{term}%'))
users=users.order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc())

View File

@ -684,7 +684,6 @@ def settings_title_change(v):
error="You didn't change anything")
v.customtitleplain = new_name
new_name = new_name.replace('_','\_')
new_name = sanitize(new_name, flair=True)
v = g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=v.id).first()

View File

@ -29,6 +29,14 @@
<input type="hidden" name="formkey" value="{{v.formkey}}">
<label for="edit-{{app.id}}-name" class="mb-0 w-lg-25">App Name</label>
<input id="edit-{{app.id}}-name" class="form-control" type="text" name="name" value="{{app.app_name}}">
{% if app.client_id %}
<label for="edit-{{app.id}}-client-id" class="mb-0 w-lg-25">Client ID</label>
<input id="edit-{{app.id}}-client-id" class="form-control copy-link" type="text" name="name" value="{{app.client_id}}" data-clipboard-text="{{app.client_id}}" role="button" readonly="readonly">
{% endif %}
<label for="edit-{{app.id}}-redirect" class="mb-0 w-lg-25">Redirect URI</label>
<input id="edit-{{app.id}}-redirect" class="form-control" type="text" name="redirect_uri" value="{{app.redirect_uri}}">
<label for="edit-{{app.id}}-desc" class="mb-0 w-lg-25">Description</label>
@ -37,7 +45,7 @@
</div>
<div class="footer">
<div class="d-flex">
<a href="javascript:void(0)" class="btn btn-secondary ml-auto" onclick="post_toast('/oauth/reroll/{{app.id}}', callback=function(xhr){document.getElementById('edit-{{app.id}}-client-id').value=JSON.parse(xhr.response)['id'];document.getElementById('edit-{{app.id}}-client-secret').value=JSON.parse(xhr.response)['secret'];})">Reroll Tokens</a>
<a href="javascript:void(0)" class="btn btn-secondary ml-auto" onclick="post_toast('/oauth/reroll/{{app.id}}', callback=function(xhr){document.getElementById('edit-{{app.id}}-client-id').value=JSON.parse(xhr.response)['id'];document.getElementById('edit-{{app.id}}-client-secret').value=JSON.parse(xhr.response)['secret'];})">Reroll Client ID</a>
<input type="submit" class="btn btn-primary ml-2" value="Save Changes">
</div>
</div>
@ -62,6 +70,12 @@
<input type="hidden" name="formkey" value="{{v.formkey}}">
<label for="edit-{{app.id}}-name" class="mb-0 w-lg-25">App Name</label>
<input id="edit-{{app.id}}-name" class="form-control" type="text" name="name" value="{{app.app_name}}">
{% if app.client_id %}
<label for="edit-{{app.id}}-client-id" class="mb-0 w-lg-25">Client ID</label>
<input id="edit-{{app.id}}-client-id" class="form-control copy-link" type="text" name="name" value="{{app.client_id}}" data-clipboard-text="{{app.client_id}}" role="button" readonly="readonly">
{% endif %}
<label for="edit-{{app.id}}-redirect" class="mb-0 w-lg-25">Redirect URI</label>
<input id="edit-{{app.id}}-redirect" class="form-control" type="text" name="redirect_uri" value="{{app.redirect_uri}}">
<label for="edit-{{app.id}}-desc" class="mb-0 w-lg-25">Description</label>
@ -91,7 +105,6 @@
</div>
<div class="body w-lg-100">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<label class="mb-0 w-lg-25">Permissions</label>
<label class="mb-0 w-lg-25">Description</label>
<textarea class="form-control" name="description" maxlength="256" readonly="readonly">{{auth.application.description}}</textarea>
</div>

View File

@ -501,17 +501,8 @@ CREATE TABLE public.client_auths (
id integer NOT NULL,
user_id integer,
oauth_client integer,
scope_identity boolean,
scope_create boolean,
scope_read boolean,
scope_update boolean,
scope_delete boolean,
scope_vote boolean,
scope_guildmaster boolean,
access_token character(128),
refresh_token character(128),
oauth_code character(128),
access_token_expire_utc integer
access_token character(128)
);
@ -889,11 +880,9 @@ ALTER SEQUENCE public.notifications_id_seq OWNED BY public.notifications.id;
CREATE TABLE public.oauth_apps (
id integer NOT NULL,
client_id character(64),
client_secret character(128),
app_name character varying(50),
redirect_uri character varying(4096),
author_id integer,
is_banned boolean,
description character varying(256)
);
@ -1681,14 +1670,6 @@ ALTER TABLE ONLY public.client_auths
ADD CONSTRAINT unique_access UNIQUE (access_token);
--
-- Name: client_auths unique_code; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.client_auths
ADD CONSTRAINT unique_code UNIQUE (oauth_code);
--
-- Name: oauth_apps unique_id; Type: CONSTRAINT; Schema: public; Owner: postgres
--
@ -1697,22 +1678,6 @@ ALTER TABLE ONLY public.oauth_apps
ADD CONSTRAINT unique_id UNIQUE (client_id);
--
-- Name: client_auths unique_refresh; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.client_auths
ADD CONSTRAINT unique_refresh UNIQUE (refresh_token);
--
-- Name: oauth_apps unique_secret; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.oauth_apps
ADD CONSTRAINT unique_secret UNIQUE (client_secret);
--
-- Name: badges user_badge_constraint; Type: CONSTRAINT; Schema: public; Owner: postgres
--
@ -1906,20 +1871,6 @@ CREATE INDEX block_user_idx ON public.userblocks USING btree (user_id);
CREATE INDEX cflag_user_idx ON public.commentflags USING btree (user_id);
--
-- Name: client_access_token_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX client_access_token_idx ON public.client_auths USING btree (access_token, access_token_expire_utc);
--
-- Name: client_refresh_token_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX client_refresh_token_idx ON public.client_auths USING btree (refresh_token);
--
-- Name: comment_body_idx; Type: INDEX; Schema: public; Owner: postgres
--