Skip to content

Commit

Permalink
Remove become user feature (jitsucom#922)
Browse files Browse the repository at this point in the history
* removed become user feature
* typo fix
  • Loading branch information
Flyover-ArtSk authored May 16, 2022
1 parent df68a5f commit 4aa4e74
Show file tree
Hide file tree
Showing 13 changed files with 2 additions and 115 deletions.
1 change: 0 additions & 1 deletion benchmark/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"default_s3_bucket": true,
"support_tracking_domains": true,
"telemetry_usage_disabled": false,
"show_become_user": true,
"docker_hub_id": "jitsu",
"createDemoDatabase": true,
"enableCustomDomains": true,
Expand Down
20 changes: 0 additions & 20 deletions configurator/backend/authorization/firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,6 @@ func (fb *Firebase) AutoSignUp(ctx context.Context, email string, _ *string) (st
return createdUser.UID, nil
}

func (fb *Firebase) SignInAs(ctx context.Context, email string) (*openapi.TokenResponse, error) {
user, err := fb.authClient.GetUserByEmail(ctx, email)
if err != nil {
return nil, middleware.ReadableError{
Description: "Failed to get user from Firebase",
Cause: err,
}
}

token, err := fb.authClient.CustomToken(ctx, user.UID)
if err != nil {
return nil, middleware.ReadableError{
Description: "Failed to generate custom user token via Firebase",
Cause: err,
}
}

return &openapi.TokenResponse{Token: token}, nil
}

func isProvidedByGoogle(info []*auth.UserInfo) bool {
for _, info := range info {
if info.ProviderID == "google.com" {
Expand Down
4 changes: 1 addition & 3 deletions configurator/backend/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ type LocalAuthorizator interface {
GetUserIDByEmail(ctx context.Context, userEmail string) (string, error)
}

type CloudAuthorizator interface {
SignInAs(ctx context.Context, email string) (*openapi.TokenResponse, error)
}
type CloudAuthorizator interface {}

type SSOProvider interface {
Name() string
Expand Down
21 changes: 0 additions & 21 deletions configurator/backend/handlers/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,6 @@ func (oa *OpenAPI) GenerateDefaultProjectApiKey(ctx *gin.Context) {
}
}

func (oa *OpenAPI) BecomeAnotherCloudUser(ctx *gin.Context, params openapi.BecomeAnotherCloudUserParams) {
if ctx.IsAborted() {
return
}

if authorizator, err := oa.Authorizator.Cloud(); err != nil {
mw.Unsupported(ctx, err)
} else if authority, err := mw.GetAuthority(ctx); err != nil {
mw.Unauthorized(ctx, err)
} else if !authority.IsAdmin {
mw.Forbidden(ctx, "Only admins can use this API method")
} else if params.UserId == "" {
mw.RequiredField(ctx, "user_id")
} else if token, err := authorizator.SignInAs(ctx, params.UserId); err != nil {
mw.BadRequest(ctx, "sign in failed", err)
} else {
ctx.JSON(http.StatusOK, token)
}
}

func (oa *OpenAPI) CreateFreeTierPostgresDatabase(ctx *gin.Context) {
if ctx.IsAborted() {
return
Expand Down Expand Up @@ -445,7 +425,6 @@ func (oa *OpenAPI) GetSystemConfiguration(ctx *gin.Context) {
DefaultS3Bucket: !oa.SystemConfig.SelfHosted,
SupportTrackingDomains: !oa.SystemConfig.SelfHosted,
TelemetryUsageDisabled: telemetryUsageDisabled,
ShowBecomeUser: !oa.SystemConfig.SelfHosted,
DockerHubID: oa.SystemConfig.DockerHUBID,
OnlyAdminCanChangeUserEmail: oa.SystemConfig.SelfHosted,
Tag: oa.SystemConfig.Tag,
Expand Down
22 changes: 0 additions & 22 deletions configurator/frontend/main/src/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import { ReactComponent as KeyIcon } from "icons/key.svg"
import { ReactComponent as DownloadIcon } from "icons/download.svg"
import { ReactComponent as GlobeIcon } from "icons/globe.svg"
import classNames from "classnames"
// @Model
import { Permission } from "lib/services/model"
// @Utils
import { reloadPage } from "lib/commons/utils"
// @Services
Expand Down Expand Up @@ -235,20 +233,6 @@ export const DropdownMenu: React.FC<{ user: User; plan: CurrentSubscription; hid

const showSettings = React.useCallback<() => void>(() => history.push("/user/settings"), [history])

const becomeUser = async () => {
let email = prompt("Please enter e-mail of the user", "")
if (!email) {
return
}
try {
AnalyticsBlock.blockAll()
await services.userService.becomeUser(email)
} catch (e) {
handleError(e, "Can't login as other user")
AnalyticsBlock.unblockAll()
}
}

return (
<div>
<div className="py-5 border-b px-5 flex flex-col items-center">
Expand Down Expand Up @@ -292,12 +276,6 @@ export const DropdownMenu: React.FC<{ user: User; plan: CurrentSubscription; hid
<Button type="text" className="text-left" key="settings" icon={<SettingOutlined />} onClick={showSettings}>
Settings
</Button>
{(services.userService.getUser().email === "[email protected]" ||
services.userService.getUser().email.endsWith("@jitsu.com")) && (
<Button className="text-left" type="text" key="become" icon={<UserSwitchOutlined />} onClick={becomeUser}>
Become User
</Button>
)}
<Button
className="text-left"
type="text"
Expand Down
2 changes: 0 additions & 2 deletions configurator/frontend/main/src/lib/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ export interface UserService {

createUser(signup: SignupRequest): Promise<void>

becomeUser(email: string): Promise<void>

supportsLoginViaLink(): boolean

sendLoginLink(email: string): Promise<void>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ export class BackendUserService implements UserService {
})
}

//isn't supported (without google authorization)
async becomeUser(email: string): Promise<void> {
let response = await this.backendApi.get(`/become`, { urlParams: { user_id: email } })
this.setTokens(response["access_token"], response["refresh_token"])
reloadPage()
}

getLoginFeatures(): LoginFeatures {
return { oauth: false, password: true, signupEnabled: false }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,6 @@ export class FirebaseUserService implements UserService {
throw new Error("Not Available")
}

async becomeUser(email: string): Promise<void> {
let token = (await this.backendApi.get(`/become`, { urlParams: { user_id: email } }))["token"]
await signInWithCustomToken(getAuth(), token)
reloadPage()
}

getLoginFeatures(): LoginFeatures {
return { oauth: true, password: true, signupEnabled: true }
}
Expand Down
2 changes: 1 addition & 1 deletion configurator/frontend/main/src/lib/services/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function defaultExecutors(execs: AnalyticsExecutors): AnalyticsExecutors {
}

/**
* Allows to block all calls to any analytics service. For become user feature
* Allows to block all calls to any analytics service
*/
export const AnalyticsBlock = {
blockAll: () => {
Expand Down
4 changes: 0 additions & 4 deletions configurator/frontend/main/src/lib/services/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export type SuggestedUserInfo = {
companyName?: string
}

export enum Permission {
BECOME_OTHER_USER,
}

/**
* User internal representation. This class is here for backward compatibility
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const mockConfiguration = process.env.FIREBASE_CONFIG
default_s3_bucket: true,
support_tracking_domains: true,
telemetry_usage_disabled: false,
show_become_user: true,
docker_hub_id: "jitsucom",
} as const)
: ({
Expand All @@ -20,7 +19,6 @@ export const mockConfiguration = process.env.FIREBASE_CONFIG
default_s3_bucket: false,
support_tracking_domains: false,
telemetry_usage_disabled: false,
show_become_user: false,
docker_hub_id: "jitsu",
} as const)

Expand Down
25 changes: 0 additions & 25 deletions openapi/configurator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1191,28 +1191,3 @@ paths:
$ref: '#/components/responses/AnyObjectResponse'
default:
$ref: '#/components/responses/Error'

/api/v1/become:
parameters:
- in: query
name: user_id
description: ID of desirable user
required: true
schema:
type: string
get:
tags:
- configuration-management
operationId: 'Become another cloud user'
description: Authorize as another user. Method can only be used by admins and it is only available on cloud.jitsu.com.
security:
- configurationManagementAuth: [ ]
responses:
'200':
description: "Access token for desired user authorization"
content:
"application/json":
schema:
$ref: "#/components/schemas/TokenResponse"
default:
$ref: '#/components/responses/Error'
1 change: 0 additions & 1 deletion server/system/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type Configuration struct {
DefaultS3Bucket bool `json:"default_s3_bucket"`
SupportTrackingDomains bool `json:"support_tracking_domains"`
TelemetryUsageDisabled bool `json:"telemetry_usage_disabled"`
ShowBecomeUser bool `json:"show_become_user"`
DockerHubID string `json:"docker_hub_id"`
OnlyAdminCanChangeUserEmail bool `json:"only_admin_can_change_user_email"`
PluginScript string `json:"plugin_script"`
Expand Down

0 comments on commit 4aa4e74

Please sign in to comment.