Handle permission userinfo using new logic

This commit is contained in:
Ajay
2022-08-14 00:14:59 -04:00
parent fdbcf47149
commit 99c5375c6a
3 changed files with 12 additions and 5 deletions

View File

@@ -406,7 +406,10 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
)];
for (const category of (this.props.categoryList ?? CompileConfig.categoryList)) {
if (category === "chapter" && !Config.config.canSubmitChapter) break;
// If permission not loaded, treat it like we have permission except chapter
const defaultBlockCategories = ["chapter"];
const permission = Config.config.permissions[category as Category];
if ((defaultBlockCategories.includes(category) || permission !== undefined) && !permission) continue;
elements.push(
<option value={category}

View File

@@ -3,10 +3,14 @@ import * as invidiousList from "../ci/invidiouslist.json";
import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, PreviewBarOption, SponsorTime, StorageChangesObject, Keybind, HashedValue, VideoID, SponsorHideType } from "./types";
import { keybindEquals } from "./utils/configUtils";
export interface Permission {
canSubmit: boolean;
}
interface SBConfig {
userID: string,
isVip: boolean,
canSubmitChapter: boolean,
permissions: Record<Category, Permission>,
/* Contains unsubmitted segments that the user has created. */
unsubmittedSegments: Record<string, SponsorTime[]>,
defaultCategory: Category,
@@ -133,7 +137,7 @@ const Config: SBObject = {
syncDefaults: {
userID: null,
isVip: false,
canSubmitChapter: false,
permissions: {},
unsubmittedSegments: {},
defaultCategory: "chooseACategory" as Category,
renderSegmentsAsChapters: true,

View File

@@ -255,7 +255,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.showNoticeAgain.style.display = "unset";
}
utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&value=vip&value=canSubmitChapter&userID="
utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&value=vip&value=permissions&userID="
+ Config.config.userID, (res) => {
if (res.status === 200) {
const userInfo = JSON.parse(res.responseText);
@@ -285,7 +285,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
}
Config.config.isVip = userInfo.vip;
Config.config.canSubmitChapter = userInfo.canSubmitChapter;
Config.config.permissions = userInfo.permissions;
}
});