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

[NEW] Community Edition Watermark #25844

Merged
merged 17 commits into from
Jun 29, 2022
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
12 changes: 11 additions & 1 deletion apps/meteor/client/contexts/CallContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IVoipRoom } from '@rocket.chat/core-typings';
import type { CallStates, IVoipRoom } from '@rocket.chat/core-typings';
import { ICallerInfo, VoIpCallerInfo } from '@rocket.chat/core-typings';
import { createContext, useContext, useMemo } from 'react';
import { useSyncExternalStore } from 'use-sync-external-store/shim';
Expand Down Expand Up @@ -83,6 +83,16 @@ export const useCallActions = (): CallActionsType => {
return context.actions;
};

export const useCallerStatus = (): CallStates => {
const context = useContext(CallContext);

if (isCallContextReady(context)) {
return context.voipClient.callState;
}

return 'INITIAL';
};

export const useCallerInfo = (): VoIpCallerInfo => {
const context = useContext(CallContext);

Expand Down
31 changes: 28 additions & 3 deletions apps/meteor/client/sidebar/footer/SidebarFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { CallStates } from '@rocket.chat/core-typings';
import { css } from '@rocket.chat/css-in-js';
import { Box, SidebarFooter as Footer } from '@rocket.chat/fuselage';
import { Box, Divider, SidebarFooter as Footer } from '@rocket.chat/fuselage';
import colors from '@rocket.chat/fuselage-tokens/colors.json';
import { useEndpoint, useTranslation } from '@rocket.chat/ui-contexts';
import React, { ReactElement } from 'react';
import { useQuery } from 'react-query';

import { settings } from '../../../app/settings/client';
import { useIsCallEnabled, useIsCallReady } from '../../contexts/CallContext';
import { useCallerStatus, useIsCallEnabled, useIsCallReady } from '../../contexts/CallContext';
import { VoipFooter } from './voip';

const SidebarFooter = (): ReactElement => {
Expand All @@ -20,15 +23,25 @@ const SidebarFooter = (): ReactElement => {
}
`;

const t = useTranslation();

const isEnterpriseEdition = useEndpoint('GET', '/v1/licenses.isEnterprise');
const { data, isSuccess } = useQuery(['licences'], () => isEnterpriseEdition());
const isCommunityEdition = isSuccess && !data?.isEnterprise;

const isCallEnabled = useIsCallEnabled();
const ready = useIsCallReady();
const callerStatus = useCallerStatus();

const activeCallStatus: CallStates[] = ['OFFER_RECEIVED', 'IN_CALL', 'ON_HOLD', 'ANSWER_SENT'];

if (isCallEnabled && ready) {
if (activeCallStatus.includes(callerStatus) && isCallEnabled && ready) {
return <VoipFooter />;
}

return (
<Footer>
<Divider mbs={-2} mbe={0} borderColor={`${colors.n900}40`} />
<Box
is='footer'
pb='x12'
Expand All @@ -38,6 +51,18 @@ const SidebarFooter = (): ReactElement => {
className={sidebarFooterStyle}
dangerouslySetInnerHTML={{ __html: String(settings.get('Layout_Sidenav_Footer')).trim() }}
/>
{isCommunityEdition && (
<Box pi='x16' pbe='x8'>
<Box fontSize='x10' fontWeight={700} color={colors.n600} pbe='x4'>
<a href='https://rocket.chat/' target='_blank' rel='noopener noreferrer' style={{ textDecoration: 'none', color: 'inherit' }}>
{t('Powered_by_RocketChat')}
</a>
</Box>
<Box fontSize='x10' fontWeight={700} color={colors.n100} pbe='x4'>
{t('Free_Edition')}
</Box>
</Box>
)}
</Footer>
);
};
Expand Down
13 changes: 12 additions & 1 deletion apps/meteor/ee/server/api/licenses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { check } from 'meteor/check';

import { getLicenses, validateFormat, flatModules, getMaxActiveUsers } from '../../app/license/server/license';
import { getLicenses, validateFormat, flatModules, getMaxActiveUsers, isEnterprise } from '../../app/license/server/license';
import { Settings, Users } from '../../../app/models/server';
import { API } from '../../../app/api/server/api';
import { hasPermission } from '../../../app/authorization/server';
Expand Down Expand Up @@ -68,3 +68,14 @@ API.v1.addRoute(
},
},
);

API.v1.addRoute(
'licenses.isEnterprise',
{ authRequired: true },
{
get() {
const isEnterpriseEdtion = isEnterprise();
return API.v1.success({ isEnterprise: isEnterpriseEdtion });
},
},
);
2 changes: 2 additions & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@
"Comment": "Comment",
"Common_Access": "Common Access",
"Community": "Community",
"Free_Edition": "Free edition",
"Compact": "Compact",
"Composer_not_available_phone_calls": "Messages are not available on phone calls",
"Condensed": "Condensed",
Expand Down Expand Up @@ -3957,6 +3958,7 @@
"seconds": "seconds",
"Secret_token": "Secret Token",
"Security": "Security",
"Powered_by_RocketChat": "Powered by Rocket.Chat",
"See_full_profile": "See full profile",
"Select_a_department": "Select a department",
"Select_a_room": "Select a room",
Expand Down
56 changes: 44 additions & 12 deletions apps/meteor/tests/end-to-end/api/20-licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ describe('licenses', function () {
this.retries(0);

before((done) => getCredentials(done));
let unauthorizedUserCredentials;

describe('[/licenses.add]', () => {
let unauthorizedUserCredentials;
before(async () => {
const createdUser = await createUser();
unauthorizedUserCredentials = await doLogin(createdUser.username, password);
});
before(async () => {
const createdUser = await createUser();
unauthorizedUserCredentials = await doLogin(createdUser.username, password);
});

describe('[/licenses.add]', () => {
it('should fail if not logged in', (done) => {
request
.post(api('licenses.add'))
Expand Down Expand Up @@ -65,12 +65,6 @@ describe('licenses', function () {
});

describe('[/licenses.get]', () => {
let unauthorizedUserCredentials;
before(async () => {
const createdUser = await createUser();
unauthorizedUserCredentials = await doLogin(createdUser.username, password);
});

it('should fail if not logged in', (done) => {
request
.get(api('licenses.get'))
Expand Down Expand Up @@ -109,4 +103,42 @@ describe('licenses', function () {
.end(done);
});
});

describe('[/licenses.isEnterprise]', () => {
it('should fail if not logged in', (done) => {
request
.get(api('licenses.isEnterprise'))
.expect('Content-Type', 'application/json')
.expect(401)
.expect((res) => {
expect(res.body).to.have.property('status', 'error');
expect(res.body).to.have.property('message');
})
.end(done);
});

it('should pass if user has user role', (done) => {
request
.get(api('licenses.isEnterprise'))
.set(unauthorizedUserCredentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('isEnterprise', false);
})
.end(done);
});

it('should pass if user has admin role', (done) => {
request
.get(api('licenses.isEnterprise'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('isEnterprise', false);
})
.end(done);
});
});
});
3 changes: 3 additions & 0 deletions packages/rest-typings/src/v1/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ export type LicensesEndpoints = {
'/v1/licenses.requestSeatsLink': {
GET: () => { url: string };
};
'/v1/licenses.isEnterprise': {
GET: () => { isEnterprise: boolean };
};
};