mirror of https://github.com/Chocobozzz/PeerTube
				
				
				
			Format video blacklist
							parent
							
								
									32502eda29
								
							
						
					
					
						commit
						ab683a8e0d
					
				| 
						 | 
				
			
			@ -152,8 +152,8 @@ export class VideoService {
 | 
			
		|||
 | 
			
		||||
  blacklistVideo(id: string) {
 | 
			
		||||
    return this.authHttp.post(VideoService.BASE_VIDEO_URL + id + '/blacklist', {})
 | 
			
		||||
			.map(this.restExtractor.extractDataBool)
 | 
			
		||||
			.catch((res) => this.restExtractor.handleError(res));
 | 
			
		||||
                        .map(this.restExtractor.extractDataBool)
 | 
			
		||||
                        .catch((res) => this.restExtractor.handleError(res));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private setVideoRate(id: string, rateType: RateType) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,17 +79,17 @@
 | 
			
		|||
            </a>
 | 
			
		||||
          </li>
 | 
			
		||||
 | 
			
		||||
	  <li *ngIf="isVideoRemovable()" role="menuitem">
 | 
			
		||||
	    <a class="dropdown-item" title="Delete this video" href="#" (click)="removeVideo($event)">
 | 
			
		||||
	      <span class="glyphicon glyphicon-remove"></span> Delete
 | 
			
		||||
	    </a>
 | 
			
		||||
	  </li>
 | 
			
		||||
          <li *ngIf="isVideoRemovable()" role="menuitem">
 | 
			
		||||
            <a class="dropdown-item" title="Delete this video" href="#" (click)="removeVideo($event)">
 | 
			
		||||
              <span class="glyphicon glyphicon-remove"></span> Delete
 | 
			
		||||
            </a>
 | 
			
		||||
          </li>
 | 
			
		||||
 | 
			
		||||
	  <li *ngIf="isVideoBlacklistable()" role="menuitem">
 | 
			
		||||
	    <a class="dropdown-item" title="Blacklist this video" href="#" (click)="blacklistVideo($event)">
 | 
			
		||||
	      <span class="glyphicon glyphicon-eye-close"></span> Blacklist
 | 
			
		||||
	    </a>
 | 
			
		||||
	  </li>
 | 
			
		||||
          <li *ngIf="isVideoBlacklistable()" role="menuitem">
 | 
			
		||||
            <a class="dropdown-item" title="Blacklist this video" href="#" (click)="blacklistVideo($event)">
 | 
			
		||||
              <span class="glyphicon glyphicon-eye-close"></span> Blacklist
 | 
			
		||||
            </a>
 | 
			
		||||
          </li>
 | 
			
		||||
        </ul>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -171,41 +171,43 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
 | 
			
		|||
 | 
			
		||||
  removeVideo(event: Event) {
 | 
			
		||||
    event.preventDefault();
 | 
			
		||||
 | 
			
		||||
    this.confirmService.confirm('Do you really want to delete this video?', 'Delete').subscribe(
 | 
			
		||||
      res => {
 | 
			
		||||
        if (res === false) return;
 | 
			
		||||
 | 
			
		||||
        this.videoService.removeVideo(this.video.id)
 | 
			
		||||
			 .subscribe(
 | 
			
		||||
			   status => {
 | 
			
		||||
			     this.notificationsService.success('Success', `Video ${this.video.name} deleted.`)
 | 
			
		||||
			     // Go back to the video-list.
 | 
			
		||||
			     this.router.navigate(['/videos/list'])
 | 
			
		||||
			   },
 | 
			
		||||
                         .subscribe(
 | 
			
		||||
                           status => {
 | 
			
		||||
                             this.notificationsService.success('Success', `Video ${this.video.name} deleted.`);
 | 
			
		||||
                             // Go back to the video-list.
 | 
			
		||||
                             this.router.navigate(['/videos/list']);
 | 
			
		||||
                           },
 | 
			
		||||
 | 
			
		||||
			   error => this.notificationsService.error('Error', error.text)
 | 
			
		||||
        );
 | 
			
		||||
                           error => this.notificationsService.error('Error', error.text)
 | 
			
		||||
                          );
 | 
			
		||||
      }
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  blacklistVideo(event: Event) {
 | 
			
		||||
    event.preventDefault()
 | 
			
		||||
    event.preventDefault();
 | 
			
		||||
 | 
			
		||||
    this.confirmService.confirm('Do you really want to blacklist this video ?', 'Blacklist').subscribe(
 | 
			
		||||
      res => {
 | 
			
		||||
	if (res === false) return;
 | 
			
		||||
        if (res === false) return;
 | 
			
		||||
 | 
			
		||||
	this.videoService.blacklistVideo(this.video.id)
 | 
			
		||||
			 .subscribe(
 | 
			
		||||
			   status => {
 | 
			
		||||
			     this.notificationsService.success('Success', `Video ${this.video.name} had been blacklisted.`)
 | 
			
		||||
			     this.router.navigate(['/videos/list'])
 | 
			
		||||
			   },
 | 
			
		||||
        this.videoService.blacklistVideo(this.video.id)
 | 
			
		||||
                         .subscribe(
 | 
			
		||||
                           status => {
 | 
			
		||||
                             this.notificationsService.success('Success', `Video ${this.video.name} had been blacklisted.`);
 | 
			
		||||
                             this.router.navigate(['/videos/list']);
 | 
			
		||||
                           },
 | 
			
		||||
 | 
			
		||||
			   error => this.notificationsService.error('Error', error.text)
 | 
			
		||||
	)
 | 
			
		||||
                           error => this.notificationsService.error('Error', error.text)
 | 
			
		||||
                         );
 | 
			
		||||
      }
 | 
			
		||||
    )
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  showReportModal(event: Event) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -635,10 +635,11 @@ function reportVideoAbuse (req, res, finalCallback) {
 | 
			
		|||
function addVideoToBlacklist (req, res, next) {
 | 
			
		||||
  const videoInstance = res.locals.video
 | 
			
		||||
 | 
			
		||||
  db.BlacklistedVideo.create({
 | 
			
		||||
  const toCreate = {
 | 
			
		||||
    videoId: videoInstance.id
 | 
			
		||||
  })
 | 
			
		||||
  .asCallback(function (err) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  db.BlacklistedVideo.create(toCreate).asCallback(function (err) {
 | 
			
		||||
    if (err) {
 | 
			
		||||
      logger.error('Errors when blacklisting video ', { error: err })
 | 
			
		||||
      return next(err)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
'use strict'
 | 
			
		||||
 | 
			
		||||
const constants = require('../initializers/constants')
 | 
			
		||||
const logger = require('../helpers/logger')
 | 
			
		||||
 | 
			
		||||
const adminMiddleware = {
 | 
			
		||||
| 
						 | 
				
			
			@ -9,7 +8,7 @@ const adminMiddleware = {
 | 
			
		|||
 | 
			
		||||
function ensureIsAdmin (req, res, next) {
 | 
			
		||||
  const user = res.locals.oauth.token.user
 | 
			
		||||
  if (user.role !== constants.USER_ROLES.ADMIN) {
 | 
			
		||||
  if (user.isAdmin() === false) {
 | 
			
		||||
    logger.info('A non admin user is trying to access to an admin content.')
 | 
			
		||||
    return res.sendStatus(403)
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -137,6 +137,18 @@ function videoRate (req, res, next) {
 | 
			
		|||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function videosBlacklist (req, res, next) {
 | 
			
		||||
  req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
 | 
			
		||||
 | 
			
		||||
  logger.debug('Checking videosBlacklist parameters', { parameters: req.params })
 | 
			
		||||
 | 
			
		||||
  checkErrors(req, res, function () {
 | 
			
		||||
    checkVideoExists(req.params.id, res, function () {
 | 
			
		||||
      checkVideoIsBlacklistable(req, res, next)
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ---------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
module.exports = validatorsVideos
 | 
			
		||||
| 
						 | 
				
			
			@ -166,8 +178,8 @@ function checkUserCanDeleteVideo (userId, res, callback) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    // Check if the user can delete the video
 | 
			
		||||
    //  The user can delete it if s/he an admin
 | 
			
		||||
    //  Or if s/he is the video's author
 | 
			
		||||
    // The user can delete it if s/he is an admin
 | 
			
		||||
    // Or if s/he is the video's author
 | 
			
		||||
    if (user.isAdmin() === false) {
 | 
			
		||||
      if (res.locals.video.isOwned() === false) {
 | 
			
		||||
        return res.status(403).send('Cannot remove video of another pod')
 | 
			
		||||
| 
						 | 
				
			
			@ -185,20 +197,8 @@ function checkUserCanDeleteVideo (userId, res, callback) {
 | 
			
		|||
 | 
			
		||||
function checkVideoIsBlacklistable (req, res, callback) {
 | 
			
		||||
  if (res.locals.video.isOwned() === true) {
 | 
			
		||||
        return res.status(403).send('Cannot blacklist a local video')
 | 
			
		||||
    return res.status(403).send('Cannot blacklist a local video')
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  callback()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function videosBlacklist (req, res, next) {
 | 
			
		||||
  req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
 | 
			
		||||
 | 
			
		||||
  logger.debug('Checking videosBlacklist parameters', { parameters: req.params })
 | 
			
		||||
 | 
			
		||||
  checkErrors(req, res, function () {
 | 
			
		||||
    checkVideoExists(req.params.id, res, function() {
 | 
			
		||||
      checkVideoIsBlacklistable(req, res, next)
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -770,7 +770,6 @@ function removeFromBlacklist (video, callback) {
 | 
			
		|||
    // If an error occured, stop here
 | 
			
		||||
    if (err) {
 | 
			
		||||
      logger.error('Error when fetching video from blacklist.', { error: err })
 | 
			
		||||
 | 
			
		||||
      return callback(err)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue