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

source-academy / backend / c8061aaf54ca884032005179c5d9e7356fcacdb4-PR-1022

13 Jun 2025 10:21AM UTC coverage: 92.748% (-0.09%) from 92.838%
c8061aaf54ca884032005179c5d9e7356fcacdb4-PR-1022

Pull #1022

github

web-flow
Merge branch 'master' into dependabot/hex/ex_aws_s3-2.5.2
Pull Request #1022: Bump ex_aws_s3 from 2.4.0 to 2.5.2

3108 of 3351 relevant lines covered (92.75%)

1053.53 hits per line

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

95.45
/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
10
    course_reg = conn.assigns.course_reg
3✔
11

12
    case Assets.list_assets(Courses.assets_prefix(course_reg.course), foldername) do
3✔
13
      {:error, {status, message}} -> conn |> put_status(status) |> text(message)
1✔
14
      assets -> render(conn, "index.json", assets: assets)
2✔
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
20
    course_reg = conn.assigns.course_reg
5✔
21
    filename = Enum.join(filename, "/")
5✔
22

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

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

37
    case Assets.upload_to_s3(
6✔
38
           upload_params,
39
           Courses.assets_prefix(course_reg.course),
6✔
40
           foldername,
41
           filename
42
         ) do
43
      {:error, {status, message}} -> conn |> put_status(status) |> text(message)
3✔
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

© 2026 Coveralls, Inc