• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / backend / 18dc689a4df4836fc6967bf0f74dc252964bd175-PR-1180

08 Sep 2024 06:14PM UTC coverage: 79.088% (-15.3%) from 94.372%
18dc689a4df4836fc6967bf0f74dc252964bd175-PR-1180

Pull #1180

github

josh1248
Change appropriate routes into admin scope
Pull Request #1180: Transfer groundControl (and admin panel) from staff to admin route

7 of 12 new or added lines in 1 file covered. (58.33%)

499 existing lines in 25 files now uncovered.

2602 of 3290 relevant lines covered (79.09%)

1023.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

31.82
/lib/cadet_web/admin_controllers/admin_assets_controller.ex
1
defmodule CadetWeb.AdminAssetsController do
2
  use CadetWeb, :controller
3

4
  use PhoenixSwagger
5

6
  alias Cadet.Assets.Assets
7
  alias Cadet.Courses
8

9
  def index(conn, _params = %{"foldername" => foldername}) do
UNCOV
10
    course_reg = conn.assigns.course_reg
×
11

UNCOV
12
    case Assets.list_assets(Courses.assets_prefix(course_reg.course), foldername) do
×
UNCOV
13
      {:error, {status, message}} -> conn |> put_status(status) |> text(message)
×
UNCOV
14
      assets -> render(conn, "index.json", assets: assets)
×
15
    end
16
  end
17

18
  @spec delete(Plug.Conn.t(), map) :: Plug.Conn.t()
19
  def delete(conn, _params = %{"foldername" => foldername, "filename" => filename}) do
UNCOV
20
    course_reg = conn.assigns.course_reg
×
UNCOV
21
    filename = Enum.join(filename, "/")
×
22

UNCOV
23
    case Assets.delete_object(Courses.assets_prefix(course_reg.course), foldername, filename) do
×
UNCOV
24
      {:error, {status, message}} -> conn |> put_status(status) |> text(message)
×
UNCOV
25
      _ -> conn |> put_status(204) |> text('')
×
26
    end
27
  end
28

29
  def upload(conn, %{
30
        "upload" => upload_params,
31
        "filename" => filename,
32
        "foldername" => foldername
33
      }) do
UNCOV
34
    course_reg = conn.assigns.course_reg
×
UNCOV
35
    filename = Enum.join(filename, "/")
×
36

UNCOV
37
    case Assets.upload_to_s3(
×
38
           upload_params,
UNCOV
39
           Courses.assets_prefix(course_reg.course),
×
40
           foldername,
41
           filename
42
         ) do
UNCOV
43
      {:error, {status, message}} -> conn |> put_status(status) |> text(message)
×
UNCOV
44
      resp -> render(conn, "show.json", resp: resp)
×
45
    end
46
  end
47

48
  def swagger_definitions do
49
    %{
1✔
50
      Asset:
51
        swagger_schema do
1✔
52
          title("Asset")
53
          description("A path to an asset")
54
          example("assets/hello.png")
55
        end,
56
      Assets:
57
        swagger_schema do
1✔
58
          title("Assets")
59
          description("An array of asset paths")
60
          type(:array)
61
          items(PhoenixSwagger.Schema.ref(:Asset))
62
        end,
63
      AssetURL:
64
        swagger_schema do
1✔
65
          title("Asset URL")
66
          description("A URL to an uploaded asset")
67
          type(:string)
68
          example("https://bucket-name.s3.amazonaws.com/assets/hello.png")
69
        end
70
    }
71
  end
72

73
  swagger_path :index do
1✔
74
    get("/courses/{course_id}/admin/assets/{folderName}")
75

76
    summary("Get a list of all assets in a folder")
77

78
    parameters do
79
      folderName(:path, :string, "Folder name", required: true)
80
    end
81

82
    security([%{JWT: []}])
83

84
    produces("application/json")
85

86
    response(200, "OK", :Assets)
87
    response(400, "Invalid folder name")
88
    response(403, "User is not allowed to manage assets")
89
  end
90

91
  swagger_path :delete do
1✔
92
    PhoenixSwagger.Path.delete("/courses/{course_id}/admin/assets/{folderName}/{fileName}")
93

94
    summary("Delete a file from an asset folder")
95

96
    parameters do
97
      folderName(:path, :string, "Folder name", required: true)
98

99
      fileName(:path, :string, "File path in folder, which may contain subfolders", required: true)
100
    end
101

102
    security([%{JWT: []}])
103

104
    response(204, "OK")
105
    response(400, "Invalid folder name, file name or file type")
106
    response(403, "User is not allowed to manage assets")
107
    response(404, "File not found")
108
  end
109

110
  swagger_path :upload do
1✔
111
    post("/courses/{course_id}/admin/assets/{folderName}/{fileName}")
112

113
    summary("Upload a file to an asset folder")
114

115
    parameters do
116
      folderName(:path, :string, "Folder name", required: true)
117

118
      fileName(:path, :string, "File path in folder, which may contain subfolders", required: true)
119
    end
120

121
    security([%{JWT: []}])
122

123
    produces("application/json")
124

125
    response(200, "OK", :AssetURL)
126
    response(400, "Invalid folder name, file name or file type")
127
    response(403, "User is not allowed to manage assets")
128
  end
129
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc