Skip to content

Commit dbd4f45

Browse files
authored
Merge pull request #46 from hypersign-protocol/implement/didupdate
Implement/didupdate
2 parents 6353925 + ee3d6b6 commit dbd4f45

File tree

6 files changed

+427
-68
lines changed

6 files changed

+427
-68
lines changed

src/App.vue

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@
8787
<b-collapse id="nav-collapse" is-nav v-if="parseAuthToken">
8888
<b-navbar-nav class="ml-auto">
8989

90-
<b-nav-item v-if="user.accessAccount?.email" class="center">
90+
<b-nav-item v-if="user.accessAccount?.email && user.accessAccount.userId !== user.userId" class="center">
9191
<a href="#">
92-
Accessing Account Of: <b-badge variant="dark"> {{ user.accessAccount.email }}</b-badge>
92+
Accessing Account Of: <b-badge variant="dark"> {{ loggedInUserEmailId }}</b-badge>
93+
<b-icon icon="box-arrow-in-right" class="ml-2" @click="switchBackToAdminAccount"></b-icon>
9394
</a>
9495
</b-nav-item>
9596

@@ -339,6 +340,7 @@ export default {
339340
schema_page: 1,
340341
authRoutes: ["register", "PKIIdLogin"],
341342
user: {},
343+
loggedInUserEmailId:"",
342344
parseAuthToken: null
343345
};
344346
},
@@ -362,6 +364,7 @@ export default {
362364
if (localStorage.getItem("user")) {
363365
const usrStr = localStorage.getItem("user");
364366
this.user = JSON.parse(usrStr);
367+
this.loggedInUserEmailId=this.user?.accessAccount?.email
365368
// this.showIcon = true;
366369
this.setIsLoggedOut(true)
367370
}
@@ -383,7 +386,7 @@ export default {
383386
})
384387
},
385388
methods: {
386-
...mapActions("mainStore", ["fetchAppsListFromServer", "fetchServicesList"]),
389+
...mapActions("mainStore", ["fetchAppsListFromServer", "fetchServicesList",'switchToAdmin']),
387390
...mapMutations("mainStore", ["resetMainStore", "setIsLoggedOut"]),
388391
...mapActions("playgroundStore", [
389392
"insertAschema",
@@ -655,6 +658,36 @@ export default {
655658
if (appName == "" || appName == undefined) appName = "No app name";
656659
return this.truncate(appName, 25);
657660
},
661+
async switchBackToAdminAccount(){
662+
try{
663+
this.isLoding= true
664+
await this.switchToAdmin({
665+
adminId: this.userDetails.userId
666+
})
667+
this.isLoading = false
668+
this.notifySuccess('Succefully switch to admin account')
669+
await this.fetchLoggedInUser()
670+
if (this.$route.path !== "/studio/dashboard") {
671+
this.$router.push("dashboard").then(() => { this.$router.go(0) })
672+
} else {
673+
await this.fetchLoggedInUser()
674+
this.$forceUpdate();
675+
this.$router.go(0);
676+
}
677+
} catch (e) {
678+
this.notifyErr(e.message)
679+
this.isLoading = false
680+
}
681+
},
682+
async fetchLoggedInUser(){
683+
if (localStorage.getItem("user")) {
684+
const usrStr = localStorage.getItem("user");
685+
this.user = JSON.parse(usrStr);
686+
this.loggedInUserEmailId=this.user?.accessAccount?.email
687+
this.setIsLoggedOut(true)
688+
}
689+
690+
},
658691
},
659692
mixins: [UtilsMixin],
660693
};

src/components/element/HfSelectDropDown.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:text-field="textField"
88
:value-field="valueField"
99
:options="options"
10+
:disabled="computedDisabled"
1011
></b-form-select>
1112
</div>
1213

@@ -38,6 +39,15 @@ export default {
3839
type: String,
3940
require: false,
4041
},
42+
disabled: {
43+
type: Boolean,
44+
default: null,
45+
}
46+
},
47+
computed: {
48+
computedDisabled() {
49+
return this.disabled === null ? false : this.disabled;
50+
}
4151
},
4252
mounted(){
4353
EventBus.$on("resetForFresh",()=>{

src/store/mainStore.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,16 +1591,25 @@ const mainStore = {
15911591

15921592
updateDIDsForAService({ getters, }, payload) {
15931593
return new Promise(function (resolve, reject) {
1594-
const body = {
1595-
"didDocument": payload.didDocument,
1596-
"verificationMethodId": payload.verificationMethodId,
1597-
"deactivate": payload.deactivate
1594+
let body;
1595+
if (payload.didDocument) {
1596+
body = {
1597+
"didDocument": payload.didDocument,
1598+
"verificationMethodId": payload.verificationMethodId,
1599+
"deactivate": payload.deactivate
1600+
}
1601+
} else {
1602+
if (!payload.name || payload.name == '') {
1603+
return reject(new Error('Please Provide name for the did'))
1604+
}
1605+
body = { ...payload }
15981606
}
15991607
//fetct all dids
16001608
{
16011609
if (!getters.getSelectedService || !getters.getSelectedService.tenantUrl) {
16021610
return reject(new Error('Tenant url is null or empty, service is not selected'))
16031611
}
1612+
// const url = `http://ent-2af45c1.localhost:4001/api/v1/did/`;
16041613
const url = `${sanitizeUrl(getters.getSelectedService.tenantUrl)}/api/v1/did/`;
16051614
const options = {
16061615
method: "PATCH",
@@ -2249,6 +2258,39 @@ const mainStore = {
22492258
})
22502259

22512260
},
2261+
updateCredentialForAService({ getters }, payload) {
2262+
return new Promise(function (resolve, reject) {
2263+
{
2264+
if (!getters.getSelectedService || !getters.getSelectedService.tenantUrl) {
2265+
return reject(new Error('Tenant url is null or empty, service is not selected'))
2266+
}
2267+
const url = `${sanitizeUrl(getters.getSelectedService.tenantUrl)}/api/v1/credential/status/${payload.credentialId}`;
2268+
const options = {
2269+
method: "PATCH",
2270+
body: JSON.stringify(payload),
2271+
headers: {
2272+
"Content-Type": "application/json",
2273+
"Authorization": `Bearer ${getters.getSelectedService.access_token}`,
2274+
"Origin": '*'
2275+
}
2276+
}
2277+
fetch(url, {
2278+
...options
2279+
})
2280+
.then(response => response.json())
2281+
.then(async json => {
2282+
if (json && !json.error) {
2283+
window.location.reload();
2284+
} else {
2285+
reject(new Error('Could not update credential'))
2286+
}
2287+
}).catch(e => {
2288+
reject(e)
2289+
})
2290+
}
2291+
})
2292+
2293+
},
22522294
}
22532295
}
22542296

src/store/playgroundStore.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const playgroundStore = {
1717
name: '',
1818
email: '',
1919
did: '',
20+
userId: ""
2021
},
2122
count: {
2223
credentialsCount: 0,
@@ -100,6 +101,7 @@ const playgroundStore = {
100101
name: '',
101102
email: '',
102103
did: '',
104+
userId: ''
103105
},
104106
count: {
105107
credentialsCount: 0,
@@ -135,7 +137,9 @@ const playgroundStore = {
135137
addUserDetailsToProfile(state, payload) {
136138
state.userProfile.details.name = payload.name;
137139
state.userProfile.details.email = payload.email;
138-
state.userProfile.details.did = payload.id
140+
state.userProfile.details.did = payload.id;
141+
state.userProfile.details.userId = payload.userId;
142+
139143
},
140144
addCountDataToProfile(state, payload) {
141145
state.userProfile.count = { ...payload }

0 commit comments

Comments
 (0)