Skip to content

Commit 34aab21

Browse files
mariobalcaepipav
andauthored
Hide bot activity (#465)
Co-authored-by: anilb <epipav@gmail.com>
1 parent f66f504 commit 34aab21

8 files changed

Lines changed: 105 additions & 9 deletions

File tree

backend/src/database/attributes/member/default.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ export const DefaultMemberAttributes: Attribute[] = [
3838
canDelete: false,
3939
show: false,
4040
},
41+
{
42+
name: MemberAttributes[MemberAttributeName.IS_BOT].name,
43+
label: MemberAttributes[MemberAttributeName.IS_BOT].label,
44+
type: AttributeType.BOOLEAN,
45+
canDelete: false,
46+
show: false,
47+
},
4148
]

backend/src/database/attributes/member/enums.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum MemberAttributeName {
1313
JOB_TITLE = 'jobTitle',
1414
IS_TEAM_MEMBER = 'isTeamMember',
1515
IS_ORGANIZATION = 'isOrganization',
16+
IS_BOT = 'isBot',
1617
TIMEZONE = 'timezone',
1718
KARMA = 'karma',
1819
}
@@ -74,6 +75,10 @@ export const MemberAttributes = {
7475
name: MemberAttributeName.IS_ORGANIZATION,
7576
label: 'is Organization',
7677
},
78+
[MemberAttributeName.IS_BOT]: {
79+
name: MemberAttributeName.IS_BOT,
80+
label: 'is Bot',
81+
},
7782
[MemberAttributeName.KARMA]: {
7883
name: MemberAttributeName.KARMA,
7984
label: 'Karma',
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import TenantService from '../../../services/tenantService'
2+
import getUserContext from '../../utils/getUserContext'
3+
import MemberAttributeSettingsService from '../../../services/memberAttributeSettingsService'
4+
import { DefaultMemberAttributes } from '../../attributes/member/default'
5+
6+
const addIsBotToMemberAttributes = async () => {
7+
const tenants = await TenantService._findAndCountAllForEveryUser({})
8+
const isBotAttributes = DefaultMemberAttributes.find((a) => a.name === 'isBot')
9+
10+
// for each tenant
11+
for (const tenant of tenants.rows) {
12+
const userContext = await getUserContext(tenant.id)
13+
const memberAttributeSettingsService = new MemberAttributeSettingsService(userContext)
14+
15+
console.log(`Creating isBot member attribute for tenant ${tenant.id}`)
16+
await memberAttributeSettingsService.create({
17+
name: isBotAttributes.name,
18+
label: isBotAttributes.label,
19+
type: isBotAttributes.type,
20+
canDelete: isBotAttributes.canDelete,
21+
show: isBotAttributes.show,
22+
})
23+
}
24+
}
25+
26+
addIsBotToMemberAttributes()

backend/src/services/__tests__/tenantService.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ describe('TenantService tests', () => {
188188

189189
expect(defaultAttributes.rows.map((i) => i.name).sort()).toEqual([
190190
MemberAttributeName.BIO,
191+
MemberAttributeName.IS_BOT,
191192
MemberAttributeName.IS_TEAM_MEMBER,
192193
MemberAttributeName.JOB_TITLE,
193194
MemberAttributeName.LOCATION,

frontend/src/assets/scss/badge.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
@apply bg-gray-400 text-white;
3434
}
3535

36+
&--gray-dark {
37+
@apply bg-gray-600 text-white;
38+
}
39+
3640
&--red {
3741
@apply bg-red-100 text-red-900;
3842
}

frontend/src/modules/activity/activity-service.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export class ActivityService {
9191
: filter
9292
builtFilter = {
9393
...builtFilter,
94-
member: { isTeamMember: { not: true } }
94+
member: {
95+
isTeamMember: { not: true },
96+
isBot: { not: true }
97+
}
9598
}
9699

97100
const body = {

frontend/src/modules/member/components/member-badge.vue

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div
3-
v-if="isNew || isTeam"
3+
v-if="isNew || isTeam || isBot"
44
class="member-badge flex items-center ml-1"
55
>
66
<el-tooltip
@@ -19,6 +19,13 @@
1919
>
2020
<div :class="computedBadgeClass('team')">Team</div>
2121
</el-tooltip>
22+
<el-tooltip
23+
v-if="isBot"
24+
placement="top"
25+
:content="computedTooltipContent('bot')"
26+
>
27+
<div :class="computedBadgeClass('bot')">Bot</div>
28+
</el-tooltip>
2229
</div>
2330
</template>
2431

@@ -43,6 +50,10 @@ const isTeam = computed(() => {
4350
return props.member.attributes.isTeamMember
4451
})
4552
53+
const isBot = computed(() => {
54+
return props.member.attributes.isBot
55+
})
56+
4657
const isNew = computed(() => {
4758
return (
4859
moment().diff(moment(props.member.joinedAt), 'days') <=
@@ -60,18 +71,24 @@ const computedBadgeClass = function (badge) {
6071
classes += ' mr-1'
6172
}
6273
} else if (badge === 'team') {
74+
classes += ' badge--gray-dark'
75+
} else if (badge === 'bot') {
6376
classes += ' badge--gray'
6477
}
6578
6679
return classes
6780
}
6881
6982
const computedTooltipContent = function (tooltip) {
70-
return tooltip === 'new'
71-
? `Member since ${moment(props.member.joinedAt).format(
72-
'MMM DD, YYYY'
73-
)}`
74-
: `Team member`
83+
if (tooltip === 'new') {
84+
return `Member since ${moment(
85+
props.member.joinedAt
86+
).format('MMM DD, YYYY')}`
87+
} else if (tooltip === 'team') {
88+
return 'Team member'
89+
} else {
90+
return 'Bot'
91+
}
7592
}
7693
</script>
7794

frontend/src/modules/member/components/member-dropdown.vue

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
></el-dropdown-item
6969
>
7070
<el-dropdown-item
71-
v-if="!member.team"
71+
v-if="!member.attributes.isTeamMember?.default"
7272
class="h-10"
7373
:command="{
7474
action: 'memberMarkAsTeamMember',
@@ -80,6 +80,18 @@
8080
>Mark as team member</span
8181
></el-dropdown-item
8282
>
83+
<el-dropdown-item
84+
v-if="!member.attributes.isBot?.default"
85+
class="h-10"
86+
:command="{
87+
action: 'memberMarkAsBot',
88+
member: member
89+
}"
90+
><i class="ri-robot-line text-base mr-2" /><span
91+
class="text-xs text-gray-900"
92+
>Mark as bot</span
93+
></el-dropdown-item
94+
>
8395
<el-divider class="border-gray-200" />
8496
<el-dropdown-item
8597
class="h-10"
@@ -251,7 +263,28 @@ export default {
251263
attributes: {
252264
...command.member.attributes,
253265
isTeamMember: {
254-
crowd: true,
266+
default: true
267+
}
268+
}
269+
})
270+
await this.doFetch({
271+
filter: {},
272+
keepPagination: false
273+
})
274+
Message.success('Member updated successfully')
275+
if (this.$route.name === 'member') {
276+
this.doFetch({
277+
filter: {},
278+
keepPagination: true
279+
})
280+
} else {
281+
this.doFind(command.member.id)
282+
}
283+
} else if (command.action === 'memberMarkAsBot') {
284+
await MemberService.update(command.member.id, {
285+
attributes: {
286+
...command.member.attributes,
287+
isBot: {
255288
default: true
256289
}
257290
}

0 commit comments

Comments
 (0)