Skip to content

Commit

Permalink
Adds experimental toggle to User model, and front-end toggle, for fea…
Browse files Browse the repository at this point in the history
…ture flag
  • Loading branch information
wssheldon committed Sep 28, 2023
1 parent 38f05dd commit 13e7305
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/dispatch/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DispatchUser(Base, TimeStampMixin):
email = Column(String, unique=True)
password = Column(LargeBinary, nullable=False)
last_mfa_time = Column(DateTime, nullable=True)
experimental_features = Column(Boolean, default=False)

# relationships
events = relationship("Event", backref="dispatch_user")
Expand Down Expand Up @@ -157,13 +158,15 @@ class UserLoginResponse(DispatchBase):
class UserRead(UserBase):
id: PrimaryKey
role: Optional[str] = Field(None, nullable=True)
experimental_features: Optional[bool]


class UserUpdate(DispatchBase):
id: PrimaryKey
password: Optional[str] = Field(None, nullable=True)
projects: Optional[List[UserProject]]
organizations: Optional[List[UserOrganization]]
experimental_features: Optional[bool]
role: Optional[str] = Field(None, nullable=True)

@validator("password", pre=True)
Expand Down
3 changes: 3 additions & 0 deletions src/dispatch/auth/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ def update(*, db_session, user: DispatchUser, user_in: UserUpdate) -> DispatchUs
)
)

if experimental_features := user_in.experimental_features:
user.experimental_features = experimental_features

db_session.commit()
return user

Expand Down
13 changes: 13 additions & 0 deletions src/dispatch/static/dispatch/src/auth/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const state = {
email: "",
projects: [],
role: null,
experimental_features: false,
},
selected: {
...getDefaultSelectedState(),
Expand Down Expand Up @@ -148,6 +149,15 @@ const actions = {
commit("SET_USER_LOGOUT")
router.go()
},
getExperimentalFeatures({ commit }) {
UserApi.getUserInfo()
.then((response) => {
commit("SET_EXPERIMENTAL_FEATURES", response.data.experimental_features)
})
.catch((error) => {
console.error("Error occurred while updating experimental features: ", error)
})
},
createExpirationCheck({ state, commit }) {
// expiration time minus 10 min
let expire_at = subMinutes(fromUnixTime(state.currentUser.exp), 10)
Expand Down Expand Up @@ -195,6 +205,9 @@ const mutations = {
}
localStorage.setItem("token", token)
},
SET_EXPERIMENTAL_FEATURES(state, value) {
state.currentUser.experimental_features = value
},
SET_USER_LOGOUT(state) {
state.currentUser = { loggedIn: false }
},
Expand Down
24 changes: 23 additions & 1 deletion src/dispatch/static/dispatch/src/components/AppToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@
</v-list-item-action>
</v-list-item>
<v-divider />
<v-subheader>Experimental Features</v-subheader>
<v-switch

Check warning on line 116 in src/dispatch/static/dispatch/src/components/AppToolbar.vue

View workflow job for this annotation

GitHub Actions / build

Require self-closing on Vue.js custom components (<v-switch>)
v-model="currentUser().experimental_features"
inset
class="ml-4"
@change="updateExperimentalFeatures()"
:label="currentUser().experimental_features ? 'Enabled' : 'Disabled'"
></v-switch>
<v-divider />
<v-subheader>Organizations</v-subheader>
<v-list-item v-for="(item, i) in organizations" :key="i">
<v-list-item-content>
Expand Down Expand Up @@ -159,6 +168,7 @@ import { mapActions, mapGetters, mapMutations, mapState } from "vuex"
import Util from "@/util"
import OrganizationApi from "@/organization/api"
import OrganizationCreateEditDialog from "@/organization/CreateEditDialog.vue"
import UserApi from "@/auth/api"
export default {
name: "AppToolbar",
Expand All @@ -181,6 +191,16 @@ export default {
},
},
methods: {
updateExperimentalFeatures() {
UserApi.getUserInfo()
.then((response) => {
let userId = response.data.id
UserApi.update(userId, { id: userId, experimental_features: this.experimental_features })
})
.catch((error) => {
console.error("Error occurred while updating experimental features: ", error)
})
},
handleDrawerToggle() {
this.$store.dispatch("app/toggleDrawer")
},
Expand All @@ -203,7 +223,7 @@ export default {
},
...mapState("auth", ["currentUser"]),
...mapState("app", ["currentVersion"]),
...mapActions("auth", ["logout"]),
...mapActions("auth", ["logout", "getExperimentalFeatures"]),
...mapActions("search", ["setQuery"]),
...mapActions("organization", ["showCreateEditDialog"]),
...mapActions("app", ["showCommitMessage"]),
Expand Down Expand Up @@ -233,6 +253,8 @@ export default {
this.organizations = response.data.items
this.loading = false
})
this.getExperimentalFeatures()
},
}
</script>

0 comments on commit 13e7305

Please sign in to comment.