-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add latest changes from gitlab-org/gitlab@master
- Loading branch information
GitLab Bot
committed
Jan 22, 2021
1 parent
7e81076
commit 852877d
Showing
50 changed files
with
1,061 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
app/assets/javascripts/admin/users/components/user_actions.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<script> | ||
import { | ||
GlButton, | ||
GlDropdown, | ||
GlDropdownItem, | ||
GlDropdownSectionHeader, | ||
GlDropdownDivider, | ||
} from '@gitlab/ui'; | ||
import { s__, __ } from '~/locale'; | ||
import { convertArrayToCamelCase } from '~/lib/utils/common_utils'; | ||
import { generateUserPaths } from '../utils'; | ||
export default { | ||
components: { | ||
GlButton, | ||
GlDropdown, | ||
GlDropdownItem, | ||
GlDropdownSectionHeader, | ||
GlDropdownDivider, | ||
}, | ||
props: { | ||
user: { | ||
type: Object, | ||
required: true, | ||
}, | ||
paths: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
userActions() { | ||
return convertArrayToCamelCase(this.user.actions); | ||
}, | ||
dropdownActions() { | ||
return this.userActions.filter((a) => a !== 'edit'); | ||
}, | ||
dropdownDeleteActions() { | ||
return this.dropdownActions.filter((a) => a.includes('delete')); | ||
}, | ||
dropdownSafeActions() { | ||
return this.dropdownActions.filter((a) => !this.dropdownDeleteActions.includes(a)); | ||
}, | ||
hasDropdownActions() { | ||
return this.dropdownActions.length > 0; | ||
}, | ||
hasDeleteActions() { | ||
return this.dropdownDeleteActions.length > 0; | ||
}, | ||
hasEditAction() { | ||
return this.userActions.includes('edit'); | ||
}, | ||
userPaths() { | ||
return generateUserPaths(this.paths, this.user.username); | ||
}, | ||
}, | ||
methods: { | ||
isLdapAction(action) { | ||
return action === 'ldapBlocked'; | ||
}, | ||
}, | ||
i18n: { | ||
edit: __('Edit'), | ||
settings: __('Settings'), | ||
unlock: __('Unlock'), | ||
block: s__('AdminUsers|Block'), | ||
unblock: s__('AdminUsers|Unblock'), | ||
approve: s__('AdminUsers|Approve'), | ||
reject: s__('AdminUsers|Reject'), | ||
deactivate: s__('AdminUsers|Deactivate'), | ||
activate: s__('AdminUsers|Activate'), | ||
ldapBlocked: s__('AdminUsers|Cannot unblock LDAP blocked users'), | ||
delete: s__('AdminUsers|Delete user'), | ||
deleteWithContributions: s__('AdminUsers|Delete user and contributions'), | ||
}, | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div class="gl-display-flex gl-justify-content-end"> | ||
<gl-button v-if="hasEditAction" data-testid="edit" :href="userPaths.edit">{{ | ||
$options.i18n.edit | ||
}}</gl-button> | ||
|
||
<gl-dropdown | ||
v-if="hasDropdownActions" | ||
data-testid="actions" | ||
right | ||
class="gl-ml-2" | ||
icon="settings" | ||
> | ||
<gl-dropdown-section-header>{{ $options.i18n.settings }}</gl-dropdown-section-header> | ||
|
||
<template v-for="action in dropdownSafeActions"> | ||
<gl-dropdown-item v-if="isLdapAction(action)" :key="action" :data-testid="action"> | ||
{{ $options.i18n.ldap }} | ||
</gl-dropdown-item> | ||
<gl-dropdown-item v-else :key="action" :href="userPaths[action]" :data-testid="action"> | ||
{{ $options.i18n[action] }} | ||
</gl-dropdown-item> | ||
</template> | ||
|
||
<gl-dropdown-divider v-if="hasDeleteActions" /> | ||
|
||
<gl-dropdown-item | ||
v-for="action in dropdownDeleteActions" | ||
:key="action" | ||
:href="userPaths[action]" | ||
:data-testid="`delete-${action}`" | ||
> | ||
<span class="gl-text-red-500">{{ $options.i18n[action] }}</span> | ||
</gl-dropdown-item> | ||
</gl-dropdown> | ||
</div> | ||
</template> |
29 changes: 29 additions & 0 deletions
29
app/assets/javascripts/admin/users/components/user_date.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script> | ||
import { formatDate } from '~/lib/utils/datetime_utility'; | ||
import { __ } from '~/locale'; | ||
import { SHORT_DATE_FORMAT } from '../constants'; | ||
export default { | ||
props: { | ||
date: { | ||
type: String, | ||
required: false, | ||
default: null, | ||
}, | ||
}, | ||
computed: { | ||
formattedDate() { | ||
const { date } = this; | ||
if (date === null) { | ||
return __('Never'); | ||
} | ||
return formatDate(new Date(date), SHORT_DATE_FORMAT); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
<template> | ||
<span> | ||
{{ formattedDate }} | ||
</span> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const USER_AVATAR_SIZE = 32; | ||
|
||
export const SHORT_DATE_FORMAT = 'd mmm, yyyy'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const generateUserPaths = (paths, id) => { | ||
return Object.fromEntries( | ||
Object.entries(paths).map(([action, genericPath]) => { | ||
return [action, genericPath.replace('id', id)]; | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/services/ci/pipeline_artifacts/create_quality_report_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
module Ci | ||
module PipelineArtifacts | ||
class CreateQualityReportService | ||
def execute(pipeline) | ||
return unless pipeline.can_generate_codequality_reports? | ||
return if pipeline.has_codequality_reports? | ||
|
||
file = build_carrierwave_file(pipeline) | ||
|
||
pipeline.pipeline_artifacts.create!( | ||
project_id: pipeline.project_id, | ||
file_type: :code_quality, | ||
file_format: :raw, | ||
size: file["tempfile"].size, | ||
file: file, | ||
expire_at: Ci::PipelineArtifact::EXPIRATION_DATE.from_now | ||
) | ||
end | ||
|
||
private | ||
|
||
def build_carrierwave_file(pipeline) | ||
CarrierWaveStringFile.new_file( | ||
file_content: pipeline.codequality_reports.to_json, | ||
filename: Ci::PipelineArtifact::DEFAULT_FILE_NAMES.fetch(:code_quality), | ||
content_type: 'application/json' | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
module Pages | ||
class MigrateFromLegacyStorageService | ||
def initialize(logger, migration_threads, batch_size) | ||
@logger = logger | ||
@migration_threads = migration_threads | ||
@batch_size = batch_size | ||
|
||
@migrated = 0 | ||
@errored = 0 | ||
@counters_lock = Mutex.new | ||
end | ||
|
||
def execute | ||
@queue = SizedQueue.new(1) | ||
|
||
threads = start_migration_threads | ||
|
||
ProjectPagesMetadatum.only_on_legacy_storage.each_batch(of: @batch_size) do |batch| | ||
@queue.push(batch) | ||
end | ||
|
||
@queue.close | ||
|
||
@logger.info("Waiting for threads to finish...") | ||
threads.each(&:join) | ||
|
||
{ migrated: @migrated, errored: @errored } | ||
end | ||
|
||
def start_migration_threads | ||
Array.new(@migration_threads) do | ||
Thread.new do | ||
while batch = @queue.pop | ||
process_batch(batch) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def process_batch(batch) | ||
batch.with_project_route_and_deployment.each do |metadatum| | ||
project = metadatum.project | ||
|
||
migrate_project(project) | ||
end | ||
|
||
@logger.info("#{@migrated} projects are migrated successfully, #{@errored} projects failed to be migrated") | ||
end | ||
|
||
def migrate_project(project) | ||
result = nil | ||
time = Benchmark.realtime do | ||
result = ::Pages::MigrateLegacyStorageToDeploymentService.new(project).execute | ||
end | ||
|
||
if result[:status] == :success | ||
@logger.info("project_id: #{project.id} #{project.pages_path} has been migrated in #{time} seconds") | ||
@counters_lock.synchronize { @migrated += 1 } | ||
else | ||
@logger.error("project_id: #{project.id} #{project.pages_path} failed to be migrated in #{time} seconds: #{result[:message]}") | ||
@counters_lock.synchronize { @errored += 1 } | ||
end | ||
rescue => e | ||
@counters_lock.synchronize { @errored += 1 } | ||
@logger.error("#{e.message} project_id: #{project&.id}") | ||
Gitlab::ErrorTracking.track_exception(e, project_id: project&.id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.