Skip to content

Commit

Permalink
Fix analytics privacy mode bugs
Browse files Browse the repository at this point in the history
Re-enable privacy mode selector in client
Hook up privacy mode in client to server
Add casbin to server (for upcoming perms update)
  • Loading branch information
NavidK0 committed Feb 12, 2021
1 parent b5afbe6 commit ff95f8b
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 54 deletions.
26 changes: 20 additions & 6 deletions client/components/profile/UserProfileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@
{{ profile.subtitle }}
</h3>

<a v-for="link in links" :key="link.id" :id="'sl-item-'+link.id" :href="api_url + '/analytics/link/' + link.id" class="w-full" target="_blank">
<a
v-for="link in links"
:id="'sl-item-'+link.id"
:key="link.id"
:href="createLink(link)"
class="w-full"
target="_blank"
>
<div
class="rounded shadow bg-white p-4 w-full font-medium mb-3 nc-link sl-item flex items-center justify-center flex-col"
:style="link.customCss"
Expand Down Expand Up @@ -121,7 +128,10 @@ export default Vue.extend({
imageUrl: null,
headline: null,
subtitle: null,
showWatermark: true
showWatermark: true,
metadata: {
privacyMode: false
}
},
user: {
name: null,
Expand All @@ -139,10 +149,6 @@ export default Vue.extend({
},
async fetch() {
if (process.server) {
console.log("Updating profile data");
}
if (this.authenticated) {
await this.getAuthenticatedProfile();
} else {
Expand Down Expand Up @@ -195,6 +201,14 @@ export default Vue.extend({
}
this.loaded = true;
},
createLink(link: Link) {
if (this.profile.metadata.privacyMode) {
return link.url;
} else {
return this.api_url + '/analytics/link/' + link.id;
}
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion client/layouts/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
<n-link to="/dashboard/settings" v-if="profile_visibility=='unpublished'" class="absolute flex flex-row items-center text-sm text-center justify-center bg-indigo-600 text-white p-2 px-4 rounded-lg" style="bottom: 20px; left:20px; width: calc(100% - 40px);">
<span class="font-semibold pr-1">Warning:</span>
<span>Your profile is currently hidden!</span>
<div class="hidden visibility-alert bg-indigo-500 rounded-lg font-medium hover:bg-indigo-400 px-2 py-1" style="margin-left:auto !important;">Goto settings</div>
<div class="hidden visibility-alert bg-indigo-500 rounded-lg font-medium hover:bg-indigo-400 px-2 py-1" style="margin-left:auto !important;">Go to settings</div>
</n-link>

</section>
Expand Down
90 changes: 74 additions & 16 deletions client/pages/dashboard/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,16 @@
type="text"
placeholder="e.g. https://uifaces.co/our-content/donated/rSuiu_Hr.jpg"
>
<div v-if="!profile_valid" class="py-3 px-4 rounded-lg bg-red-200 border border-red-400 text-red-500 flex flex-col items-start mt-2 text-sm">
<div
v-if="!profile_valid"
class="py-3 px-4 rounded-lg bg-red-200 border border-red-400 text-red-500 flex flex-col items-start mt-2 text-sm"
>
<span class="font-semibold">Warning!</span>
<span class="text-xs font-medium">Your profile picture is improperly formatted! Ensure your image is loaded via an SSL and ends in .gif, .png, .jpg, .jpeg, or another supported file extension.<a href="https://www.notion.so/neutroncreative/Troubleshooting-9a162db4a8ce482d89b3d3e1bc9825ba" target="_blank" class="ml-2 font-semibold underline hover:text-red-700">Learn more</a></span>
<span class="text-xs font-medium">Your profile picture is improperly formatted! Ensure your image is loaded via an SSL and ends in .gif, .png, .jpg, .jpeg, or another supported file extension.<a
href="https://www.notion.so/neutroncreative/Troubleshooting-9a162db4a8ce482d89b3d3e1bc9825ba"
target="_blank"
class="ml-2 font-semibold underline hover:text-red-700"
>Learn more</a></span>
</div>
</div>

Expand All @@ -115,7 +122,11 @@
class="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out"
>

<label for="themeGlobal" class="ml-4 flex font-medium text-sm leading-5 text-gray-600 w-full lg:w-auto flex-col" style="max-width:calc(100% - 32px)">
<label
for="themeGlobal"
class="ml-4 flex font-medium text-sm leading-5 text-gray-600 w-full lg:w-auto flex-col"
style="max-width:calc(100% - 32px)"
>
Display Watermark ("Proudly built with {{ app_name }}!")
<br>
<span
Expand All @@ -128,17 +139,19 @@
</div>

<!-- Privacy mode toggle -->
<!--<div class="flex flex-row w-full mb-6 items-start">
<div class="flex flex-row w-full mb-6 items-start">
<input
v-model="user.activeProfile.metadata.privacyMode"
type="checkbox"
style="margin-top:3px;"
class="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out"
aria-label="privacy mode"
>

<label class="ml-4 block text-sm leading-5 text-gray-600">
Privacy mode (Disables profile analytics & discovery)
</label>
</div>-->
</div>

<button
type="button"
Expand Down Expand Up @@ -255,6 +268,9 @@ export default Vue.extend({
customDomain: '',
visibility: '',
showWatermark: false,
metadata: {
privacyMode: false
},
}
},
error: '',
Expand All @@ -267,6 +283,24 @@ export default Vue.extend({
};
},
computed: {
profile_valid() {
if (!this.user.activeProfile.imageUrl) {
return true;
}
if (!this.user.activeProfile.imageUrl.match(/.(jpg|jpeg|png|gif)$/i)) {
return false;
}
if (!this.user.activeProfile.imageUrl.includes('https://')) {
return false;
}
return true;
}
},
watch: {
'user.activeProfile.showWatermark': {
handler(val) {
Expand All @@ -280,15 +314,6 @@ export default Vue.extend({
this.loaded = true;
},
computed: {
profile_valid() {
if(!this.user.activeProfile.imageUrl) return true;
if(!this.user.activeProfile.imageUrl.match(/.(jpg|jpeg|png|gif)$/i) ) return false;
if(this.user.activeProfile.imageUrl.indexOf('https://')<0) return false;
return true;
}
},
methods: {
async getUserData() {
Expand All @@ -314,6 +339,8 @@ export default Vue.extend({
this.user.activeProfile.visibility = profileResponse.visibility;
this.user.activeProfile.showWatermark = profileResponse.showWatermark;
this.user.activeProfile.metadata.privacyMode = profileResponse.metadata.privacyMode;
this.$set(this.user.activeProfile, 'user.activeProfile', profileResponse);
this.originalHandle = this.user.activeProfile.handle;
Expand All @@ -324,6 +351,7 @@ export default Vue.extend({
},
async saveChanges() {
// Update profile
try {
await this.$axios.$post('/profile/update', {
token: this.$store.getters['auth/getToken'],
Expand Down Expand Up @@ -356,6 +384,33 @@ export default Vue.extend({
throw err;
}
// Update privacy mode
const privacyMode = this.user.activeProfile.metadata.privacyMode;
try {
const request = await this.$axios.post('/profile/set-privacy-mode', {
token: this.$store.getters['auth/getToken'],
privacyMode
});
if (request.status && request.status === 200) {
this.passwordError = '';
}
} catch (err) {
console.error(err);
if (err.response) {
if (err.response.status === StatusCodes.NOT_FOUND) {
// This should be impossible under normal circumstances
this.error = "The profile couldn't be found, please make sure it's correct.";
}
return;
}
throw err;
}
},
setPasswordModalActive(active: boolean) {
Expand Down Expand Up @@ -425,7 +480,7 @@ export default Vue.extend({
throw err;
}
}
},
}
});
</script>
Expand All @@ -438,5 +493,8 @@ export default Vue.extend({
.fade-enter, .fade-leave-to {
opacity: 0;
}
* { outline: none !important; }
* {
outline: none !important;
}
</style>
44 changes: 36 additions & 8 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"aws-sdk": "^2.796.0",
"axios": "^0.21.1",
"bcrypt": "^5.0.0",
"casbin": "^5.4.0",
"fastify": "^3.8.0",
"fastify-cors": "^4.1.0",
"fastify-favicon": "^3.0.0",
Expand Down
Loading

0 comments on commit ff95f8b

Please sign in to comment.