Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Experimental Features toggle for built-in feature flags #3818

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Adds last_mfa_time to DispatchUser

Revision ID: 5c60513d6e5e
Revises: 3dd4d12844dc
Create Date: 2023-09-27 15:17:00.450716

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "5c60513d6e5e"
down_revision = "3dd4d12844dc"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("dispatch_user", sa.Column("experimental_features", sa.Boolean(), default=False))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("dispatch_user", "experimental_features")
# ### end Alembic commands ###
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
25 changes: 24 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,16 @@
</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-5"
color="blue"
@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 +169,7 @@
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 +192,16 @@
},
},
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 +224,7 @@
},
...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 +254,8 @@
this.organizations = response.data.items
this.loading = false
})

this.getExperimentalFeatures()
},
}
</script>
Loading