Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE public."organizations" DROP COLUMN "displayName";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE public."organizations" ADD COLUMN "displayName" text;

update organizations set "displayName" = "name";
7 changes: 7 additions & 0 deletions backend/src/database/models/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export default (sequelize) => {
type: DataTypes.TEXT,
allowNull: false,
},
displayName: {
type: DataTypes.TEXT,
allowNull: false,
validate: {
notEmpty: true,
},
},
website: {
type: DataTypes.TEXT,
allowNull: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ describe('MemberRepository tests', () => {
delete member1Returned.noMerge
delete member1Returned.tags
delete member1Returned.activities
delete member1Returned.organizations
delete member1Returned.notes
delete member1Returned.tasks
delete member1Returned.lastActive
Expand Down Expand Up @@ -1257,11 +1256,13 @@ describe('MemberRepository tests', () => {

const crowd = await mockIRepositoryOptions.database.organization.create({
name: 'crowd.dev',
displayName: 'crowd.dev',
url: 'https://crowd.dev',
tenantId: mockIRepositoryOptions.currentTenant.id,
})
const pp = await mockIRepositoryOptions.database.organization.create({
name: 'pied piper',
displayName: 'pied piper',
url: 'https://piedpiper.com',
tenantId: mockIRepositoryOptions.currentTenant.id,
})
Expand Down Expand Up @@ -2299,11 +2300,13 @@ describe('MemberRepository tests', () => {

const crowd = await mockIRepositoryOptions.database.organization.create({
name: 'crowd.dev',
displayName: 'crowd.dev',
url: 'https://crowd.dev',
tenantId: mockIRepositoryOptions.currentTenant.id,
})
const pp = await mockIRepositoryOptions.database.organization.create({
name: 'pied piper',
displayName: 'pied piper',
url: 'https://piedpiper.com',
tenantId: mockIRepositoryOptions.currentTenant.id,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const db = null

const toCreate = {
name: 'crowd.dev',
displayName: 'crowd.dev',
url: 'https://crowd.dev',
description: 'Community-led Growth for Developer-first Companies.\nJoin our private beta',
emails: ['hello@crowd.dev', 'jonathan@crow.dev'],
Expand Down
30 changes: 29 additions & 1 deletion backend/src/database/repositories/memberRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,35 @@ class MemberRepository {
return this._populateRelations(records[0], options)
}

return records[0].get({ plain: true })
const plainMember = records[0].get({ plain: true })

plainMember.organizations = await this.getOrganizationIds(records[0].id, options)

return plainMember
}

static async getOrganizationIds(id: string, options: IRepositoryOptions) {
const transaction = SequelizeRepository.getTransaction(options)

const results = await options.database.sequelize.query(
`
select array_agg(mo."organizationId") as "organizationIds" from "memberOrganizations" mo
where mo."memberId" = :memberId
group by mo."memberId";`,
{
type: Sequelize.QueryTypes.SELECT,
replacements: {
memberId: id,
},
transaction,
},
)

if (results.length > 0) {
return results[0].organizationIds
}

return []
}

static async update(id, data, options: IRepositoryOptions, doPopulateRelations = true) {
Expand Down
25 changes: 21 additions & 4 deletions backend/src/database/repositories/organizationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class OrganizationRepository {
SELECT org.id "id"
,cach.id "cachId"
,org."name"
,org."displayName"
,org."location"
,org."website"
,org."lastEnrichedAt"
Expand Down Expand Up @@ -76,10 +77,15 @@ class OrganizationRepository {

const transaction = SequelizeRepository.getTransaction(options)

if (!data.displayName) {
data.displayName = data.name
}

const record = await options.database.organization.create(
{
...lodash.pick(data, [
'name',
'displayName',
'url',
'description',
'parentUrl',
Expand Down Expand Up @@ -168,6 +174,7 @@ class OrganizationRepository {
{
...lodash.pick(data, [
'name',
'displayName',
'url',
'description',
'parentUrl',
Expand Down Expand Up @@ -528,6 +535,14 @@ class OrganizationRepository {
})
}

if (filter.displayName) {
advancedFilter.and.push({
displayName: {
textContains: filter.displayName,
},
})
}

if (filter.url) {
advancedFilter.and.push({
url: {
Expand Down Expand Up @@ -701,6 +716,7 @@ class OrganizationRepository {
[
'id',
'name',
'displayName',
'url',
'description',
'parentUrl',
Expand Down Expand Up @@ -776,6 +792,7 @@ class OrganizationRepository {
[
'id',
'name',
'displayName',
'url',
'description',
'parentUrl',
Expand Down Expand Up @@ -849,7 +866,7 @@ class OrganizationRepository {
[Op.or]: [
{ id: SequelizeFilterUtils.uuid(query) },
{
[Op.and]: SequelizeFilterUtils.ilikeIncludes('organization', 'name', query),
[Op.and]: SequelizeFilterUtils.ilikeIncludes('organization', 'displayName', query),
},
],
})
Expand All @@ -858,15 +875,15 @@ class OrganizationRepository {
const where = { [Op.and]: whereAnd }

const records = await options.database.organization.findAll({
attributes: ['id', 'name', 'logo'],
attributes: ['id', 'displayName', 'logo'],
where,
limit: limit ? Number(limit) : undefined,
order: [['name', 'ASC']],
order: [['displayName', 'ASC']],
})

return records.map((record) => ({
id: record.id,
label: record.name,
label: record.displayName,
logo: record.logo,
}))
}
Expand Down
6 changes: 4 additions & 2 deletions backend/src/services/__tests__/memberService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ describe('MemberService tests', () => {
expect(o1).toStrictEqual({
id: organization.id,
name: 'crowd.dev',
displayName: 'crowd.dev',
url: null,
github: null,
location: null,
Expand Down Expand Up @@ -527,6 +528,7 @@ describe('MemberService tests', () => {
expect(o1).toStrictEqual({
id: organization.id,
name: 'crowd.dev',
displayName: 'crowd.dev',
url: 'https://crowd.dev',
github: null,
location: null,
Expand Down Expand Up @@ -600,6 +602,7 @@ describe('MemberService tests', () => {
expect(o1).toStrictEqual({
id: organization.id,
name: 'crowd.dev',
displayName: 'crowd.dev',
url: null,
github: null,
location: null,
Expand Down Expand Up @@ -672,6 +675,7 @@ describe('MemberService tests', () => {
expect(o1).toStrictEqual({
id: organization.id,
name: 'crowd.dev',
displayName: 'crowd.dev',
url: 'crowd.dev',
github: null,
location: null,
Expand Down Expand Up @@ -2027,7 +2031,6 @@ describe('MemberService tests', () => {
delete returnedMember1.noMerge
delete returnedMember1.tags
delete returnedMember1.activities
delete returnedMember1.organizations
delete returnedMember1.tasks
delete returnedMember1.notes
delete returnedMember1.activityCount
Expand Down Expand Up @@ -2125,7 +2128,6 @@ describe('MemberService tests', () => {
delete returnedMember1.noMerge
delete returnedMember1.tags
delete returnedMember1.activities
delete returnedMember1.organizations
delete returnedMember1.tasks
delete returnedMember1.notes
delete returnedMember1.activityCount
Expand Down
6 changes: 5 additions & 1 deletion backend/src/services/organizationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ export default class OrganizationService extends LoggerBase {
if (existingByName) {
record = await this.update(existingByName.id, cache)
} else {
record = await OrganizationRepository.create(cache, {
const organization = {
...cache,
displayName: cache.name,
}
record = await OrganizationRepository.create(organization, {
...this.options,
transaction,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<h6
class="text-xs leading-5 font-medium text-gray-900 hover:text-brand-500 transition"
>
{{ organization.name }}
{{ organization.displayName }}
</h6>
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const createOrganizationFn = (value) => OrganizationService.create({
})
.then((newOrganization) => ({
id: newOrganization.id,
label: newOrganization.name,
label: newOrganization.displayName,
}))
.catch(() => null);
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<p
class="text-gray-900 text-sm text-ellipsis truncate hover:text-brand-500 transition leading-relaxed"
>
{{ organization.name || '-' }}
{{ organization.displayName || '-' }}
</p>
</div>
</router-link>
Expand Down Expand Up @@ -89,7 +89,7 @@
class="w-3.5"
/>
<span class="text-xs">{{
organization.name || '-'
organization.displayName || '-'
}}</span>
</router-link>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<h6>Organization details</h6>
<div class="col-span-2 organization-details-form">
<el-form-item
:label="fields.name.label"
:prop="fields.name.name"
:label="fields.displayName.label"
:prop="fields.displayName.name"
required
>
<el-input v-model="model[fields.name.name]" />
<el-input v-model="model[fields.displayName.name]" />
<template #error>
<div class="el-form-item__error">
Name is required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
<div class="overflow-hidden mr-6">
<el-tooltip
:content="organization.name"
:content="organization.displayName"
effect="dark"
placement="top"
:disabled="!showTooltip"
Expand All @@ -33,7 +33,7 @@
@mouseover="handleOnMouseOver"
@mouseleave="handleOnMouseLeave"
>
{{ organization.name }}
{{ organization.displayName }}
</div>
</el-tooltip>
<app-organization-badge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<app-avatar
:entity="{
avatar: organization.logo,
displayName: organization.name?.replace('@', ''),
displayName: organization.displayName?.replace('@', ''),
}"
size="xl"
class="mr-4"
/>
<div>
<div class="flex">
<h5>{{ organization.name }}</h5>
<h5>{{ organization.displayName }}</h5>
<app-organization-badge
class="ml-2"
:organization="organization"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/organization/organization-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ i18nInit();

const fields = {
id: new IdField('id', label('id')),
name: new StringField('name', label('name'), {
displayName: new StringField('displayName', label('name'), {
required: true,
}),
description: new StringField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const props = defineProps({

const { fields } = OrganizationModel;
const formSchema = new FormSchema([
fields.name,
fields.displayName,
fields.headline,
fields.description,
fields.website,
Expand Down Expand Up @@ -182,7 +182,7 @@ function getInitialModel(record) {
return JSON.parse(
JSON.stringify(
formSchema.initialValues({
name: record ? record.name : '',
displayName: record ? record.displayName : '',
headline: record ? record.headline : '',
description: record ? record.description : '',
joinedAt: record ? record.joinedAt : '',
Expand Down Expand Up @@ -355,6 +355,8 @@ async function onSubmit() {
const data = {

...formModel.value,
name: isEditPage.value === false ? formModel.value.displayName : undefined,
displayName: isEditPage.value === true ? formModel.value.displayName : undefined,
emails: formModel.value.emails.reduce((acc, item) => {
if (item !== '') {
acc.push(item);
Expand Down