Skip to content

Commit

Permalink
[NEW] Community Edition Watermark (#25844)
Browse files Browse the repository at this point in the history
<!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. -->

<!-- Your Pull Request name should start with one of the following tags
  [NEW] For new features
  [IMPROVE] For an improvement (performance or little improvements) in existing features
  [FIX] For bug fixes that affect the end-user
  [BREAK] For pull requests including breaking changes
  Chore: For small tasks
  Doc: For documentation
-->

<!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code. 
  - I have read the Contributing Guide - https://github.com/RocketChat/Rocket.Chat/blob/develop/.github/CONTRIBUTING.md#contributing-to-rocketchat doc
  - I have signed the CLA - https://cla-assistant.io/RocketChat/Rocket.Chat
  - Lint and unit tests pass locally with my changes
  - I have added tests that prove my fix is effective or that my feature works (if applicable)
  - I have added necessary documentation (if applicable)
  - Any dependent changes have been merged and published in downstream modules
-->

## Proposed changes (including videos or screenshots)
<!-- CHANGELOG -->
<!--
  Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
  If it fixes a bug or resolves a feature request, be sure to link to that issue below.
  This description will appear in the release notes if we accept the contribution.
-->

<!-- END CHANGELOG -->

## Issue(s)
<!-- Link the issues being closed by or related to this PR. For example, you can use #594 if this PR closes issue number 594 -->

## Steps to test or reproduce
<!-- Mention how you would reproduce the bug if not mentioned on the issue page already. Also mention which screens are going to have the changes if applicable -->

## Further comments
<!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -->
  • Loading branch information
hugocostadev committed Jun 29, 2022
1 parent a7f3789 commit 0f40989
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 17 deletions.
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 { Device } from '@rocket.chat/ui-contexts';
import { createContext, useContext, useMemo } from 'react';
Expand Down Expand Up @@ -87,6 +87,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 @@ -3961,6 +3962,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 };
};
};

0 comments on commit 0f40989

Please sign in to comment.