FOSSology  4.4.0
Open Source License Compliance by Open Source Software
AjaxReuseReport.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2022 Rohit Pandey <rohit.pandey4900@gmail.com>
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 namespace Fossology\UI\Ajax;
8 
12 use Symfony\Component\HttpFoundation\Request;
13 use Symfony\Component\HttpFoundation\Response;
14 use Symfony\Component\HttpFoundation\JsonResponse;
16 
18 {
19  const NAME = "ajax_reuse_report";
20 
22  private $uploadDao;
24  private $reuseReportProcessor;
25 
26  function __construct()
27  {
28  parent::__construct(self::NAME,
29  array(
30  self::PERMISSION => Auth::PERM_READ
31  ));
32  $this->uploadDao = $this->getObject('dao.upload');
33  $this->reuseReportProcessor = $this->getObject('businessrules.reusereportprocessor');
34  }
35 
41  public function handle(Request $request)
42  {
43  $upload = intval($request->get("upload"));
44  $groupId = Auth::getGroupId();
45  if (!$this->uploadDao->isAccessible($upload, $groupId)) {
46  throw new \Exception("Permission Denied");
47  }
48  $vars = $this->reuseReportProcessor->getReuseSummary($upload);
49  return new JsonResponse([
50  "data" =>[
51  [
52  "title" => _("Edited Results"),
53  "value" => $vars['clearedLicense']
54  ],
55  [
56  "title" => _("Decleared licenses"),
57  "value" => $vars['declearedLicense']
58  ],
59  [
60  "title" => _("Used licenses"),
61  "value" => $vars['usedLicense']
62  ],
63  [
64  "title" => _("Unused licenses"),
65  "value" => $vars['unusedLicense']
66  ],
67  [
68  "title" => _("Missing licenses"),
69  "value" => $vars['missingLicense']
70  ]
71  ]
72  ]);
73  }
74 }
75 
76 register_plugin(new AjaxReuseReport());
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
static getGroupId()
Get the current user's group id.
Definition: Auth.php:80