Skip to content

Commit d4d2aaf

Browse files
authored
Merge pull request #1403 from guardian/fp/remove-subtitles-permission
Remove subtitles permission
2 parents 35e804b + 1440e79 commit d4d2aaf

File tree

6 files changed

+64
-87
lines changed

6 files changed

+64
-87
lines changed

app/controllers/UploadController.scala

Lines changed: 63 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -142,93 +142,80 @@ class UploadController(
142142
assetVersion: Int
143143
): Action[MultipartFormData[Files.TemporaryFile]] =
144144
LookupPermissions(parse.multipartFormData) { implicit req =>
145-
if (!req.permissions.addSubtitles) {
146-
Unauthorized(
147-
s"User ${req.user.email} is not authorised to upload subtitle asset"
148-
)
149-
} else {
150-
log.info(
151-
s"Request to upload subtitle file under atom=$atomId assetVersion=$assetVersion"
152-
)
153-
val result = for {
154-
file <- req.body.file("subtitle-file")
155-
upload <- uploadDecorator.getUpload(s"$atomId-$assetVersion")
156-
} yield try {
157-
val subtitleSource = SubtitleFileUploadCommand(
158-
upload,
159-
file,
160-
stores,
161-
req.user,
162-
awsConfig
163-
).process()
164-
165-
// add subtitle file to upload asset's list of sources
166-
val rerunUpload =
167-
UploadBuilder.buildForSubtitleChange(upload, Some(subtitleSource))
168-
169-
// reprocessing will also save the upload to the DB, but saving it here first improves UI responsiveness
170-
saveUploadToDb(rerunUpload)
171-
172-
processSubtitleChange(rerunUpload)
173-
174-
log.info(
175-
s"Upload being reprocessed after subtitle upload ${upload.id}"
176-
)
177-
Ok(Json.toJson(rerunUpload))
178-
} catch {
179-
commandExceptionAsResult
180-
}
145+
log.info(
146+
s"Request to upload subtitle file under atom=$atomId assetVersion=$assetVersion"
147+
)
148+
val result = for {
149+
file <- req.body.file("subtitle-file")
150+
upload <- uploadDecorator.getUpload(s"$atomId-$assetVersion")
151+
} yield try {
152+
val subtitleSource = SubtitleFileUploadCommand(
153+
upload,
154+
file,
155+
stores,
156+
req.user,
157+
awsConfig
158+
).process()
159+
160+
// add subtitle file to upload asset's list of sources
161+
val rerunUpload =
162+
UploadBuilder.buildForSubtitleChange(upload, Some(subtitleSource))
163+
164+
// reprocessing will also save the upload to the DB, but saving it here first improves UI responsiveness
165+
saveUploadToDb(rerunUpload)
166+
167+
processSubtitleChange(rerunUpload)
181168

182-
result.getOrElse(
183-
BadRequest
169+
log.info(
170+
s"Upload being reprocessed after subtitle upload ${upload.id}"
184171
)
172+
Ok(Json.toJson(rerunUpload))
173+
} catch {
174+
commandExceptionAsResult
185175
}
176+
177+
result.getOrElse(
178+
BadRequest
179+
)
186180
}
187181

188182
def deleteSubtitleFile(
189183
atomId: String,
190184
assetVersion: Int
191185
): Action[AnyContent] =
192186
LookupPermissions { implicit req =>
193-
if (!req.permissions.addSubtitles) {
194-
Unauthorized(
195-
s"User ${req.user.email} is not authorised to upload subtitle asset"
196-
)
197-
} else {
198-
log.info(
199-
s"Request to delete subtitle file under atom=$atomId assetVersion=$assetVersion"
200-
)
201-
uploadDecorator.getUpload(s"$atomId-$assetVersion") match {
202-
case Some(upload) =>
203-
try {
204-
SubtitleFileDeleteCommand(
205-
upload,
206-
stores,
207-
req.user,
208-
awsConfig
209-
).process()
210-
211-
// remove subtitle files from upload asset's list of sources
212-
val rerunUpload =
213-
UploadBuilder.buildForSubtitleChange(upload, None)
214-
215-
// reprocessing will also save the upload to the DB, but saving it here first improves UI responsiveness
216-
saveUploadToDb(rerunUpload)
217-
218-
processSubtitleChange(rerunUpload)
219-
220-
log.info(
221-
s"Upload being reprocessed after subtitle deletion ${upload.id}"
222-
)
223-
Ok(Json.toJson(rerunUpload))
224-
} catch {
225-
commandExceptionAsResult
226-
}
227-
case _ =>
228-
NotFound
229-
}
187+
log.info(
188+
s"Request to delete subtitle file under atom=$atomId assetVersion=$assetVersion"
189+
)
190+
uploadDecorator.getUpload(s"$atomId-$assetVersion") match {
191+
case Some(upload) =>
192+
try {
193+
SubtitleFileDeleteCommand(
194+
upload,
195+
stores,
196+
req.user,
197+
awsConfig
198+
).process()
199+
200+
// remove subtitle files from upload asset's list of sources
201+
val rerunUpload =
202+
UploadBuilder.buildForSubtitleChange(upload, None)
203+
204+
// reprocessing will also save the upload to the DB, but saving it here first improves UI responsiveness
205+
saveUploadToDb(rerunUpload)
206+
207+
processSubtitleChange(rerunUpload)
208+
209+
log.info(
210+
s"Upload being reprocessed after subtitle deletion ${upload.id}"
211+
)
212+
Ok(Json.toJson(rerunUpload))
213+
} catch {
214+
commandExceptionAsResult
215+
}
216+
case _ =>
217+
NotFound
230218
}
231-
232219
}
233220

234221
@tailrec

common/src/main/scala/com/gu/media/Permissions.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.gu.permissions.PermissionDefinition
1111
case class Permissions(
1212
deleteAtom: Boolean = false,
1313
addSelfHostedAsset: Boolean = false,
14-
addSubtitles: Boolean = false,
1514
setVideosOnAllChannelsPublic: Boolean = false,
1615
pinboard: Boolean = false,
1716
videoPlayerFormat: Boolean = false
@@ -23,7 +22,6 @@ object Permissions {
2322
val basicAccess = PermissionDefinition("media_atom_maker_access", app)
2423
val deleteAtom = PermissionDefinition("delete_atom", app)
2524
val addSelfHostedAsset = PermissionDefinition("add_self_hosted_asset", app)
26-
val addSubtitles = PermissionDefinition("add_subtitles", app)
2725
val setVideosOnAllChannelsPublic =
2826
PermissionDefinition("set_videos_on_all_channels_public", app)
2927
val pinboard = PermissionDefinition("pinboard", "pinboard")
@@ -44,7 +42,6 @@ class MediaAtomMakerPermissionsProvider(
4442
def getAll(user: PandaUser): Permissions = Permissions(
4543
deleteAtom = hasPermission(deleteAtom, user),
4644
addSelfHostedAsset = hasPermission(addSelfHostedAsset, user),
47-
addSubtitles = hasPermission(addSubtitles, user),
4845
setVideosOnAllChannelsPublic =
4946
hasPermission(setVideosOnAllChannelsPublic, user),
5047
pinboard = hasPermission(pinboard, user),

public/video-ui/src/components/VideoUpload/VideoAsset.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const defaultProps = {
1717
deleteAsset: jest.fn(),
1818
startSubtitleFileUpload: jest.fn(),
1919
deleteSubtitle: jest.fn(),
20-
permissions: {},
2120
activatingAssetNumber: undefined as number
2221
};
2322

public/video-ui/src/components/VideoUpload/VideoAsset.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,13 @@ export function Asset({
263263
isActive,
264264
selectAsset,
265265
deleteAsset,
266-
permissions,
267266
activatingAssetNumber
268267
}: {
269268
videoId: string;
270269
upload: Upload;
271270
isActive: boolean;
272271
selectAsset: { (): void };
273272
deleteAsset: { (): void };
274-
permissions: Record<string, boolean>;
275273
activatingAssetNumber: number;
276274
}) {
277275
const dispatch = useDispatch<AppDispatch>();
@@ -285,7 +283,7 @@ export function Asset({
285283
const isSelfHosted = asset && asset.sources;
286284
const subtitleFilename = metadata?.subtitleFilename;
287285

288-
const subtitlePanel = isSelfHosted && permissions?.addSubtitles && (
286+
const subtitlePanel = isSelfHosted && (
289287
<div className="video-trail__item__subtitles">
290288
<div className="subtitle__container">
291289
<SubtitlesIcon />

public/video-ui/src/components/VideoUpload/VideoTrail.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ type Props = {
1212
video: Video;
1313
uploads: Upload[];
1414
setAsset: (version: number) => void;
15-
permissions: Record<string, boolean>;
1615
activatingAssetNumber: number;
1716
};
1817

1918
export const VideoTrail = ({
2019
video,
2120
uploads,
2221
setAsset,
23-
permissions,
2422
activatingAssetNumber
2523
}: Props) => {
2624
const dispatch = useDispatch<AppDispatch>();
@@ -78,7 +76,6 @@ export const VideoTrail = ({
7876
isActive={parseInt(upload.id) === video.activeVersion}
7977
selectAsset={() => setAsset(parseInt(upload.id))}
8078
deleteAsset={() => deleteAssetsInUpload(upload.asset)}
81-
permissions={permissions}
8279
activatingAssetNumber={activatingAssetNumber}
8380
/>
8481
))}

public/video-ui/src/pages/Upload/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ export const VideoUpload = (props: { params: { id: string } }) => {
108108
video={store.video}
109109
uploads={store.uploads}
110110
setAsset={setAsset}
111-
permissions={store.config.permissions}
112111
activatingAssetNumber={store.activatingAssetNumber}
113112
/>
114113
</div>

0 commit comments

Comments
 (0)