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

source-academy / backend / 410d0308186c400f57ab0fc2b05beda552c8fdd2-PR-1180

13 Oct 2024 12:16PM UTC coverage: 91.971% (-2.2%) from 94.22%
410d0308186c400f57ab0fc2b05beda552c8fdd2-PR-1180

Pull #1180

github

josh1248
Update error messages for users
Pull Request #1180: Transfer groundControl (and admin panel) from staff to admin route

13 of 15 new or added lines in 5 files covered. (86.67%)

73 existing lines in 7 files now uncovered.

3024 of 3288 relevant lines covered (91.97%)

1043.67 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
  use PhoenixSwagger
4
  alias Cadet.Assets.Assets
5
  alias Cadet.Courses
6

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

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

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

UNCOV
21
    case Assets.delete_object(Courses.assets_prefix(course_reg.course), foldername, filename) do
×
UNCOV
22
      {:error, {status, message}} -> conn |> put_status(status) |> text(message)
×
NEW
23
      _ -> conn |> put_status(204) |> text(~c"")
×
24
    end
25
  end
26

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

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

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

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

74
    summary("Get a list of all assets in a folder")
75

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

80
    security([%{JWT: []}])
81

82
    produces("application/json")
83

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

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

92
    summary("Delete a file from an asset folder")
93

94
    parameters do
95
      folderName(:path, :string, "Folder name", required: true)
96

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

105
    security([%{JWT: []}])
106

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

113
  swagger_path :upload do
1✔
114
    post("/courses/{course_id}/admin/assets/{folderName}/{fileName}")
115

116
    summary("Upload a file to an asset folder")
117

118
    parameters do
119
      folderName(:path, :string, "Folder name", required: true)
120

121
      fileName(
122
        :path,
123
        :string,
124
        "File path in folder, which may contain subfolders",
125
        required: true
126
      )
127
    end
128

129
    security([%{JWT: []}])
130

131
    produces("application/json")
132

133
    response(200, "OK", :AssetURL)
134
    response(400, "Invalid folder name, file name or file type")
135
    response(403, "User is not allowed to manage assets")
136
  end
137
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